Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 5 additions & 2 deletions zephyr/samples/profiles/b-asc/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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());
}

Expand Down
7 changes: 5 additions & 2 deletions zephyr/samples/profiles/b-ld/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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());
}

Expand Down
7 changes: 5 additions & 2 deletions zephyr/samples/profiles/b-ls/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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());
}

Expand Down
10 changes: 6 additions & 4 deletions zephyr/samples/profiles/b-sa/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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());
}

Expand All @@ -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)) {
Expand All @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions zephyr/samples/profiles/b-ss/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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());
}

Expand All @@ -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);
}
Expand Down
9 changes: 6 additions & 3 deletions zephyr/subsys/bacnet_osif/bacnet_reinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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);
}