diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 574b5c9..e528b9d 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -683,6 +683,13 @@ config BACNET_MAX_OCTET_STRING_BYTES help Maximum number of bytes in a BACnet octet string +config BACNET_REINIT_REBOOT_DELAY + int "Minimum reboot delay for BACnet ReinitializeDevice service" + default 3000 + help + Minimum reboot delay in milliseconds after receiving + the BACnet ReinitializeDevice service + config BACNET_STORAGE_BASE_NAME string "BACnet storage base name for settings subsystem" default "bacnet" diff --git a/zephyr/samples/profiles/b-asc/src/main.c b/zephyr/samples/profiles/b-asc/src/main.c index d4c6c25..1ea87b5 100644 --- a/zephyr/samples/profiles/b-asc/src/main.c +++ b/zephyr/samples/profiles/b-asc/src/main.c @@ -48,9 +48,12 @@ static void BACnet_Device_Coldstart_Callback(void *context) int err; (void)context; + LOG_INF("COLDSTART: Clearing BACnet settings..."); err = bacnet_settings_clear(); if (err < 0) { - LOG_ERR("Failed to clear BACnet settings: %d", err); + LOG_ERR("COLDSTART: Failed to clear BACnet settings: %d", err); + } else { + LOG_INF("COLDSTART: Successfully cleared BACnet settings"); } } @@ -126,7 +129,7 @@ static void BACnet_Device_Init_Handler(void *context) /* done */ LOG_INF("BACnet Device ID: %u", Device_Object_Instance_Number()); bacnet_basic_task_object_timer_set(1000UL); - bacnet_reinitialize_device_init(3000); + bacnet_reinitialize_device_init(CONFIG_BACNET_REINIT_REBOOT_DELAY); srand(sys_rand32_get()); } diff --git a/zephyr/samples/profiles/b-ld/src/main.c b/zephyr/samples/profiles/b-ld/src/main.c index f3205b9..f9597b9 100644 --- a/zephyr/samples/profiles/b-ld/src/main.c +++ b/zephyr/samples/profiles/b-ld/src/main.c @@ -134,9 +134,12 @@ static void BACnet_Lighting_Device_Coldstart_Callback(void *context) int err; (void)context; + LOG_INF("COLDSTART: Clearing BACnet settings..."); err = bacnet_settings_clear(); if (err < 0) { - LOG_ERR("Failed to clear BACnet settings: %d", err); + LOG_ERR("COLDSTART: Failed to clear BACnet settings: %d", err); + } else { + LOG_INF("COLDSTART: Successfully cleared BACnet settings"); } } @@ -168,7 +171,7 @@ static void BACnet_Lighting_Device_Init_Handler(void *context) LOG_INF("BACnet Device ID: %u", Device_Object_Instance_Number()); /* set the BACnet Basic Task device object timer for lighting output use */ bacnet_basic_task_object_timer_set(10UL); - bacnet_reinitialize_device_init(3000); + bacnet_reinitialize_device_init(CONFIG_BACNET_REINIT_REBOOT_DELAY); srand(sys_rand32_get()); } diff --git a/zephyr/samples/profiles/b-ls/src/main.c b/zephyr/samples/profiles/b-ls/src/main.c index c3cd7bf..18425a0 100644 --- a/zephyr/samples/profiles/b-ls/src/main.c +++ b/zephyr/samples/profiles/b-ls/src/main.c @@ -118,9 +118,12 @@ static void BACnet_Lighting_Device_Coldstart_Callback(void *context) int err; (void)context; + LOG_INF("COLDSTART: Clearing BACnet settings..."); err = bacnet_settings_clear(); if (err < 0) { - LOG_ERR("Failed to clear BACnet settings: %d", err); + LOG_ERR("COLDSTART: Failed to clear BACnet settings: %d", err); + } else { + LOG_INF("COLDSTART: Successfully cleared BACnet settings"); } } @@ -198,7 +201,7 @@ static void BACnet_Lighting_Device_Init_Handler(void *context) LOG_INF("BACnet Device ID: %u", Device_Object_Instance_Number()); /* set the BACnet Basic Task device object timer for lighting output use */ bacnet_basic_task_object_timer_set(10UL); - bacnet_reinitialize_device_init(3000); + bacnet_reinitialize_device_init(CONFIG_BACNET_REINIT_REBOOT_DELAY); srand(sys_rand32_get()); } diff --git a/zephyr/samples/profiles/b-sa/src/main.c b/zephyr/samples/profiles/b-sa/src/main.c index 1696829..8406bce 100644 --- a/zephyr/samples/profiles/b-sa/src/main.c +++ b/zephyr/samples/profiles/b-sa/src/main.c @@ -54,9 +54,12 @@ static void BACnet_Smart_Actuator_Coldstart_Callback(void *context) int err; (void)context; + LOG_INF("COLDSTART: Clearing BACnet settings..."); err = bacnet_settings_clear(); if (err < 0) { - LOG_ERR("Failed to clear BACnet settings: %d", err); + LOG_ERR("COLDSTART: Failed to clear BACnet settings: %d", err); + } else { + LOG_INF("COLDSTART: Successfully cleared BACnet settings"); } } @@ -101,7 +104,7 @@ static void BACnet_Smart_Actuator_Init_Handler(void *context) LOG_INF("BACnet Device ID: %u", Device_Object_Instance_Number()); /* start the seconds cyclic timer */ mstimer_set(&Actuator_Update_Timer, 1000); - bacnet_reinitialize_device_init(3000); + bacnet_reinitialize_device_init(CONFIG_BACNET_REINIT_REBOOT_DELAY); srand(sys_rand32_get()); } @@ -114,7 +117,6 @@ static void BACnet_Smart_Actuator_Task_Handler(void *context) { float percent = 0.0f, change = 0.0f; - (void)context; bacnet_reinitialize_device_task( BACnet_Smart_Actuator_Coldstart_Callback, context); if (mstimer_expired(&Actuator_Update_Timer)) { @@ -125,7 +127,7 @@ static void BACnet_Smart_Actuator_Task_Handler(void *context) return; } percent = Analog_Output_Present_Value(Actuator_Instance); - change = -1.0f + 2.0f * ((float)rand()) / RAND_MAX; + change = -1.0f + 2.0f * ((float)sys_rand32_get() / (float)UINT32_MAX); percent += change; Analog_Output_Present_Value_Set( Actuator_Instance, percent, BACNET_MAX_PRIORITY); diff --git a/zephyr/samples/profiles/b-ss/src/main.c b/zephyr/samples/profiles/b-ss/src/main.c index 6358de2..8df1921 100644 --- a/zephyr/samples/profiles/b-ss/src/main.c +++ b/zephyr/samples/profiles/b-ss/src/main.c @@ -49,9 +49,12 @@ static void BACnet_Smart_Sensor_Coldstart_Callback(void *context) int err; (void)context; + LOG_INF("COLDSTART: Clearing BACnet settings..."); err = bacnet_settings_clear(); if (err < 0) { - LOG_ERR("Failed to clear BACnet settings: %d", err); + LOG_ERR("COLDSTART: Failed to clear BACnet settings: %d", err); + } else { + LOG_INF("COLDSTART: Successfully cleared BACnet settings"); } } @@ -96,7 +99,7 @@ static void BACnet_Smart_Sensor_Init_Handler(void *context) LOG_INF("BACnet Device ID: %u", Device_Object_Instance_Number()); /* start the seconds cyclic timer */ mstimer_set(&Sensor_Update_Timer, 1000); - bacnet_reinitialize_device_init(3000); + bacnet_reinitialize_device_init(CONFIG_BACNET_REINIT_REBOOT_DELAY); srand(sys_rand32_get()); } @@ -118,7 +121,7 @@ static void BACnet_Smart_Sensor_Task_Handler(void *context) return; } temperature = Analog_Input_Present_Value(Sensor_Instance); - change = -1.0f + 2.0f * ((float)rand()) / RAND_MAX; + change = -1.0f + 2.0f * ((float)sys_rand32_get() / (float)UINT32_MAX); temperature += change; Analog_Input_Present_Value_Set(Sensor_Instance, temperature); } diff --git a/zephyr/subsys/bacnet_osif/bacnet_reinit.c b/zephyr/subsys/bacnet_osif/bacnet_reinit.c index 5fcdc43..e87b1fd 100644 --- a/zephyr/subsys/bacnet_osif/bacnet_reinit.c +++ b/zephyr/subsys/bacnet_osif/bacnet_reinit.c @@ -54,10 +54,11 @@ void bacnet_reinitialize_device_task( #if defined(CONFIG_REBOOT) /* disable the interval timer - one shot */ mstimer_set(&Reinitialize_Timer, 0); + log_panic(); sys_reboot(SYS_REBOOT_COLD); #else /* reset the interval timer and state */ - mstimer_reset(&Reinitialize_Timer); + mstimer_restart(&Reinitialize_Timer); Device_Reinitialize_State_Set(BACNET_REINIT_IDLE); LOG_ERR("Reboot not supported on this platform"); #endif @@ -69,17 +70,18 @@ void bacnet_reinitialize_device_task( #if defined(CONFIG_REBOOT) /* disable the interval timer - one shot */ mstimer_set(&Reinitialize_Timer, 0); + log_panic(); sys_reboot(SYS_REBOOT_WARM); #else /* reset the interval timer and state */ - mstimer_reset(&Reinitialize_Timer); + mstimer_restart(&Reinitialize_Timer); Device_Reinitialize_State_Set(BACNET_REINIT_IDLE); LOG_ERR("Reboot not supported on this platform"); #endif } break; case BACNET_REINIT_IDLE: - mstimer_reset(&Reinitialize_Timer); + mstimer_restart(&Reinitialize_Timer); break; default: break; @@ -95,5 +97,6 @@ void bacnet_reinitialize_device_task( */ void bacnet_reinitialize_device_init(uint32_t timeout_ms) { + LOG_INF("ReinitializeDevice reboot delay: %u ms", timeout_ms); mstimer_set(&Reinitialize_Timer, timeout_ms); }