@@ -43,25 +43,27 @@ static const uint32_t Lighting_Instance = 1;
4343 * @param object-instance [in] The object-instance number of the object
4444 * @param old_value [in] The value to track
4545 */
46- void BACnet_Lighting_Output_Tracking_Value_Handler (uint32_t object_instance , float old_value ,
47- float value )
46+ void BACnet_Lighting_Output_Tracking_Value_Handler (
47+ uint32_t object_instance , float old_value , float value )
4848{
49- uint16_t steps = 0 ;
49+ uint16_t steps = 0 ;
5050
51- (void )old_value ;
52- if (object_instance != Lighting_Instance ) {
53- return ;
54- }
55- /* Tracking value are 0.0 and 1.0-100.0 normalized */
56- if (isgreaterequal (value , 1.0 ) && islessequal (value , 100.0 )) {
57- steps = linear_interpolate (1.0 , value , 100.0 , 1 , UINT16_MAX );
58- } else if (isgreater (value , 100.0 )) {
59- steps = UINT16_MAX ;
60- } else {
61- steps = 0 ;
62- }
63- LOG_INF ("Lighting Output[%lu]: value=%f step=%u/%u" , (unsigned long )object_instance ,
64- (double )value , (unsigned )steps , (unsigned )UINT16_MAX );
51+ (void )old_value ;
52+ if (object_instance != Lighting_Instance ) {
53+ return ;
54+ }
55+ /* Tracking value are 0.0 and 1.0-100.0 normalized */
56+ if (isgreaterequal (value , 1.0 ) && islessequal (value , 100.0 )) {
57+ steps = linear_interpolate (1.0 , value , 100.0 , 1 , UINT16_MAX );
58+ } else if (isgreater (value , 100.0 )) {
59+ steps = UINT16_MAX ;
60+ } else {
61+ steps = 0 ;
62+ }
63+ LOG_INF (
64+ "Lighting Output[%lu]: value=%f step=%u/%u" ,
65+ (unsigned long )object_instance , (double )value , (unsigned )steps ,
66+ (unsigned )UINT16_MAX );
6567}
6668
6769/**
@@ -70,18 +72,19 @@ void BACnet_Lighting_Output_Tracking_Value_Handler(uint32_t object_instance, flo
7072 * @param context The context to pass to the WriteProperty function
7173 * @return true if the WriteProperty succeeded
7274 */
73- static bool Settings_Restore_Callback (BACNET_WRITE_PROPERTY_DATA * wp_data , void * context )
75+ static bool
76+ Settings_Restore_Callback (BACNET_WRITE_PROPERTY_DATA * wp_data , void * context )
7477{
75- (void )context ;
76- if (wp_data == NULL ) {
77- return false;
78- }
79- if ((wp_data -> object_type == OBJECT_DEVICE ) &&
80- (wp_data -> object_instance == BACNET_MAX_INSTANCE )) {
81- wp_data -> object_instance = Device_Object_Instance_Number ();
82- }
78+ (void )context ;
79+ if (wp_data == NULL ) {
80+ return false;
81+ }
82+ if ((wp_data -> object_type == OBJECT_DEVICE ) &&
83+ (wp_data -> object_instance == BACNET_MAX_INSTANCE )) {
84+ wp_data -> object_instance = Device_Object_Instance_Number ();
85+ }
8386
84- return Device_Write_Property (wp_data );
87+ return Device_Write_Property (wp_data );
8588}
8689
8790/**
@@ -91,28 +94,28 @@ static bool Settings_Restore_Callback(BACNET_WRITE_PROPERTY_DATA *wp_data, void
9194 */
9295static void BACnet_Lighting_Device_Init_Handler (void * context )
9396{
94- (void )context ;
95- LOG_INF ("BACnet Stack Initialized" );
96- /* initialize objects with default values for this basic sample */
97- Device_Set_Object_Instance_Number (Device_Instance );
98- Device_Object_Name_ANSI_Init (Device_Name );
99- /* lighting output object */
100- Lighting_Output_Create (Lighting_Instance );
101- Lighting_Output_Name_Set (Lighting_Instance , "Light-1" );
102- /* restore any property values previously stored via WriteProperty */
103- bacnet_settings_init ();
104- bacnet_settings_write_property_restore (& Settings_Restore_Callback , NULL );
105- /* writable property values are stored with WriteProperty.
106- Set this callback after restore to prevent recursion. */
107- bacnet_basic_store_callback_set (bacnet_settings_basic_store );
108- /* lighting output callbacks */
109- Lighting_Output_Write_Present_Value_Callback_Set (
110- BACnet_Lighting_Output_Tracking_Value_Handler );
111- /* done */
112- LOG_INF ("BACnet Device ID: %u" , Device_Object_Instance_Number ());
113- /* set the BACnet Basic Task device object timer for lighting output use */
114- bacnet_basic_task_object_timer_set (10UL );
115- srand (sys_rand32_get ());
97+ (void )context ;
98+ LOG_INF ("BACnet Stack Initialized" );
99+ /* initialize objects with default values for this basic sample */
100+ Device_Set_Object_Instance_Number (Device_Instance );
101+ Device_Object_Name_ANSI_Init (Device_Name );
102+ /* lighting output object */
103+ Lighting_Output_Create (Lighting_Instance );
104+ Lighting_Output_Name_Set (Lighting_Instance , "Light-1" );
105+ /* restore any property values previously stored via WriteProperty */
106+ bacnet_settings_init ();
107+ bacnet_settings_write_property_restore (& Settings_Restore_Callback , NULL );
108+ /* writable property values are stored with WriteProperty.
109+ Set this callback after restore to prevent recursion. */
110+ bacnet_basic_store_callback_set (bacnet_settings_basic_store );
111+ /* lighting output callbacks */
112+ Lighting_Output_Write_Present_Value_Callback_Set (
113+ BACnet_Lighting_Output_Tracking_Value_Handler );
114+ /* done */
115+ LOG_INF ("BACnet Device ID: %u" , Device_Object_Instance_Number ());
116+ /* set the BACnet Basic Task device object timer for lighting output use */
117+ bacnet_basic_task_object_timer_set (10UL );
118+ srand (sys_rand32_get ());
116119}
117120
118121/**
@@ -122,28 +125,28 @@ static void BACnet_Lighting_Device_Init_Handler(void *context)
122125 */
123126static void BACnet_Lighting_Device_Task_Handler (void * context )
124127{
125- (void )context ;
128+ (void )context ;
126129}
127130
128131int main (void )
129132{
130- bool port_initialized = false;
133+ bool port_initialized = false;
131134
132- LOG_INF ("BACnet Device: %s" , Device_Name );
133- LOG_INF ("BACnet Stack Version " BACNET_VERSION_TEXT );
134- LOG_INF ("BACnet Stack Max APDU: %d" , MAX_APDU );
135- bacnet_basic_init_callback_set (BACnet_Lighting_Device_Init_Handler , NULL );
136- bacnet_basic_task_callback_set (BACnet_Lighting_Device_Task_Handler , NULL );
137- bacnet_basic_init ();
138- for (;;) {
139- k_sleep (K_MSEC (CONFIG_BACNET_BASIC_SERVER_KSLEEP ));
140- bacnet_basic_task ();
141- if (port_initialized ) {
142- bacnet_port_task ();
143- } else {
144- port_initialized = bacnet_port_init ();
145- }
146- }
135+ LOG_INF ("BACnet Device: %s" , Device_Name );
136+ LOG_INF ("BACnet Stack Version " BACNET_VERSION_TEXT );
137+ LOG_INF ("BACnet Stack Max APDU: %d" , MAX_APDU );
138+ bacnet_basic_init_callback_set (BACnet_Lighting_Device_Init_Handler , NULL );
139+ bacnet_basic_task_callback_set (BACnet_Lighting_Device_Task_Handler , NULL );
140+ bacnet_basic_init ();
141+ for (;;) {
142+ k_sleep (K_MSEC (CONFIG_BACNET_BASIC_SERVER_KSLEEP ));
143+ bacnet_basic_task ();
144+ if (port_initialized ) {
145+ bacnet_port_task ();
146+ } else {
147+ port_initialized = bacnet_port_init ();
148+ }
149+ }
147150
148- return 0 ;
151+ return 0 ;
149152}
0 commit comments