@@ -71,6 +71,7 @@ const uint32_t SETTING_CLIENT_DEVICE_INSTANCE = 389002;
7171const uint16_t SETTING_DOWNSTREAM_DEVICE_PORT = SETTING_BACNET_IP_PORT;
7272const uint32_t SETTING_DOWNSTREAM_DEVICE_INSTANCE = 389999 ;
7373const std::string SETTING_DEFAULT_DOWNSTREAM_DEVICE_IP_ADDRESS = " 192.168.2.217" ;
74+ const std::string SETTING_DEFAULT_DEVICE_PASSWORD = " 12345" ;
7475
7576// Downstream IP Initialization
7677// =======================================
@@ -128,6 +129,9 @@ void ExampleWriteProperty();
128129void ExampleSubscribeCOV ();
129130void ExampleSubscribeCOVProperty ();
130131void ExampleConfirmedTextMessage ();
132+ void ExampleTimeSynchronizationMessage ();
133+ void ExampleReinitializeDevice ();
134+ void ExampleDeviceCommunicationControl (bool enable);
131135
132136int main (int argc, char ** argv )
133137{
@@ -288,18 +292,35 @@ bool DoUserInput()
288292 ExampleWriteProperty ();
289293 break ;
290294 }
291- case ' c ' : {
295+ case ' s ' : {
292296 ExampleSubscribeCOV ();
293297 break ;
294298 }
295299 case ' p' : {
296300 ExampleSubscribeCOVProperty ();
297301 break ;
298302 }
299- case ' t ' : {
303+ case ' m ' : {
300304 ExampleConfirmedTextMessage ();
301305 break ;
302306 }
307+ case ' t' : {
308+ ExampleTimeSynchronizationMessage ();
309+ break ;
310+ }
311+ case ' i' : {
312+ ExampleReinitializeDevice ();
313+ break ;
314+ }
315+ case ' d' : {
316+ ExampleDeviceCommunicationControl (false );
317+ break ;
318+ }
319+ case ' e' : {
320+ ExampleDeviceCommunicationControl (true );
321+ break ;
322+ }
323+ case ' h' :
303324 default : {
304325 // Print the Help
305326 std::cout << std::endl << std::endl;
@@ -310,12 +331,18 @@ bool DoUserInput()
310331 std::cout << " Example: BACnetClient 192.168.1.126" << std::endl << std::endl;
311332
312333 std::cout << " Help: " << std::endl;
313- std::cout << " - Q - Quit" << std::endl;
314334 std::cout << " - W - Send WhoIs message" << std::endl;
315- std::cout << " - R - Send Read property messages" << std::endl;
316- std::cout << " - U - Send Write property messages" << std::endl;
317- std::cout << " - C - Send Subscribe COV Request" << std::endl;
318- std::cout << " - T - Send Confirmed Text Message Request" << std::endl;
335+ std::cout << " - R - Send ReadProperty messages" << std::endl;
336+ std::cout << " - U - Send WriteProperty messages" << std::endl;
337+ std::cout << " - S - Send SubscribeCOV Request" << std::endl;
338+ std::cout << " - P - Send SubscribeCOVProperty Request" << std::endl;
339+ std::cout << " - M - Send ConfirmedTextMessage Request" << std::endl;
340+ std::cout << " - T - Send TimeSynchronization Request" << std::endl;
341+ std::cout << " - R - Send ReinitializedDevice Request" << std::endl;
342+ std::cout << " - D - Send DeviceCommunicationControl Request to Disable" << std::endl;
343+ std::cout << " - E - Send DeviceCommunicationControl Request to Enable" << std::endl;
344+ std::cout << " - H - Display Help information" << std::endl;
345+ std::cout << " - Q - Quit" << std::endl;
319346 std::cout << std::endl;
320347 break ;
321348 }
@@ -481,6 +508,59 @@ void ExampleConfirmedTextMessage() {
481508 WaitForResponse ();
482509}
483510
511+ void ExampleTimeSynchronizationMessage () {
512+ // Time Synchronization Settings
513+ uint8_t year = 2024 - 1900 ;
514+ uint8_t month = 8 ;
515+ uint8_t day = 15 ;
516+ uint8_t weekday = 3 ;
517+ uint8_t hour = 8 ;
518+ uint8_t minute = 8 ;
519+ uint8_t seconds = 8 ;
520+ uint8_t hundrethSeconds = 0 ;
521+
522+ // Send TimeSynchronization request
523+ // C++ server example configured to handle
524+ std::cout << " Sending TimeSynchronization Message" ;
525+ fpSendTimeSynchronization (year, month, day, weekday, hour, minute, seconds, hundrethSeconds, downstreamConnectionString, 6 , 0 , false , 0 , NULL , 0 );
526+
527+ WaitForResponse ();
528+ // Note: TimeSynchronization is an unconfirmed request, which means the downstream device will not response.
529+ // The WaitForResponse is called here just to wait for some cycles before continuing.
530+
531+ // Send UtcTimeSynchronization request
532+ // C++ server example configured to handle
533+ std::cout << " Sending UTCTimeSynchronization Message" ;
534+ fpSendUTCTimeSynchronization (year, month, day, weekday, hour, minute, seconds, hundrethSeconds, downstreamConnectionString, 6 , 0 , false , 0 , NULL , 0 );
535+
536+ WaitForResponse ();
537+ }
538+
539+ void ExampleReinitializeDevice () {
540+ // ReinitializeDevice Settings
541+ uint8_t reinitializedState = CASBACnetStackExampleConstants::REINITIALIZED_STATE_ACTIVATE_CHANGES;
542+
543+ // Send ReinitializeDevice request
544+ // C++ server example configured to handle
545+ std::cout << " Sending ReinitializeDevice Message to activate changes" ;
546+ fpSendReinitializeDevice (&invokeId, reinitializedState, SETTING_DEFAULT_DEVICE_PASSWORD.c_str (), SETTING_DEFAULT_DEVICE_PASSWORD.length (), downstreamConnectionString, 6 , 0 , 0 , NULL , 0 );
547+ }
548+
549+ void ExampleDeviceCommunicationControl (bool enable) {
550+ if (enable) {
551+ // Send DeviceCommunicationControl request
552+ // C++ server example configured to handle
553+ std::cout << " Sending DeviceCommunicationControl Message to enable BACnet communication" ;
554+ fpSendDeviceCommunicationControl (&invokeId, CASBACnetStackExampleConstants::ENABLEDISABLE_ENABLE, false , 0 , SETTING_DEFAULT_DEVICE_PASSWORD.c_str (), SETTING_DEFAULT_DEVICE_PASSWORD.length (), downstreamConnectionString, 6 , 0 , 0 , NULL , 0 );
555+ }
556+ else {
557+ // Send DeviceCommunicationControl request
558+ // C++ server example configured to handle
559+ std::cout << " Sending DeviceCommunicationControl Message to disable BACnet communication" ;
560+ fpSendDeviceCommunicationControl (&invokeId, CASBACnetStackExampleConstants::ENABLEDISABLE_DISABLE, false , 0 , SETTING_DEFAULT_DEVICE_PASSWORD.c_str (), SETTING_DEFAULT_DEVICE_PASSWORD.length (), downstreamConnectionString, 6 , 0 , 0 , NULL , 0 );
561+ }
562+ }
563+
484564
485565// ================================================================================================
486566// Callbacks
0 commit comments