@@ -154,17 +154,20 @@ int run_server(rodbus_server_t* server)
154154 }
155155 else if (strcmp (cbuf , "uc\n" ) == 0 ) {
156156 // ANCHOR: update_coil
157- rodbus_server_update_database (server , 1 , rodbus_database_callback_init (update_coil , NULL , & state ));
157+ rodbus_server_update_database (server , 1 , (rodbus_database_callback_t ) {
158+ .callback = update_coil ,
159+ .ctx = & state ,
160+ });
158161 // ANCHOR_END: update_coil
159162 }
160163 else if (strcmp (cbuf , "udi\n" ) == 0 ) {
161- rodbus_server_update_database (server , 1 , rodbus_database_callback_init ( update_discrete_input , NULL , & state ) );
164+ rodbus_server_update_database (server , 1 , ( rodbus_database_callback_t ){. callback = update_discrete_input , . ctx = & state } );
162165 }
163166 else if (strcmp (cbuf , "uhr\n" ) == 0 ) {
164- rodbus_server_update_database (server , 1 , rodbus_database_callback_init ( update_holding_register , NULL , & state ) );
167+ rodbus_server_update_database (server , 1 , ( rodbus_database_callback_t ){. callback = update_holding_register , . ctx = & state } );
165168 }
166169 else if (strcmp (cbuf , "uir\n" ) == 0 ) {
167- rodbus_server_update_database (server , 1 , rodbus_database_callback_init ( update_input_register , NULL , & state ) );
170+ rodbus_server_update_database (server , 1 , ( rodbus_database_callback_t ){. callback = update_input_register , . ctx = & state } );
168171 }
169172 else {
170173 printf ("Unknown command\n" );
@@ -179,14 +182,17 @@ int run_server(rodbus_server_t* server)
179182rodbus_device_map_t * build_device_map ()
180183{
181184 // ANCHOR: device_map_init
182- rodbus_write_handler_t write_handler =
183- rodbus_write_handler_init (& on_write_single_coil , & on_write_single_register , & on_write_multiple_coils , & on_write_multiple_registers , NULL , NULL );
184-
185+ rodbus_write_handler_t write_handler = {
186+ .write_single_coil = on_write_single_coil ,
187+ .write_single_register = on_write_single_register ,
188+ .write_multiple_coils = on_write_multiple_coils ,
189+ .write_multiple_registers = on_write_multiple_registers ,
190+ };
185191 rodbus_device_map_t * map = rodbus_device_map_create ();
186192 rodbus_device_map_add_endpoint (map ,
187193 1 , // Unit ID
188194 write_handler , // Handler for write requests
189- rodbus_database_callback_init ( configure_db , NULL , NULL ) // Callback for the initial state of the database
195+ ( rodbus_database_callback_t ){. callback = configure_db } // Callback for the initial state of the database
190196 );
191197 // ANCHOR_END: device_map_init
192198
@@ -234,11 +240,16 @@ int run_rtu_channel(rodbus_runtime_t* runtime)
234240rodbus_authorization_handler_t get_auth_handler ()
235241{
236242 // ANCHOR: auth_handler_init
237- rodbus_authorization_handler_t auth_handler = rodbus_authorization_handler_init (
238- & auth_read , & auth_read , & auth_read , & auth_read ,
239- & auth_single_write , & auth_single_write , & auth_multiple_writes , & auth_multiple_writes ,
240- NULL , NULL
241- );
243+ rodbus_authorization_handler_t auth_handler = {
244+ .read_coils = auth_read ,
245+ .read_discrete_inputs = auth_read ,
246+ .read_holding_registers = auth_read ,
247+ .read_input_registers = auth_read ,
248+ .write_single_coil = auth_single_write ,
249+ .write_single_register = auth_single_write ,
250+ .write_multiple_coils = auth_multiple_writes ,
251+ .write_multiple_registers = auth_multiple_writes ,
252+ };
242253 // ANCHOR_END: auth_handler_init
243254
244255 return auth_handler ;
@@ -324,7 +335,7 @@ int create_and_run_channel(int argc, char *argv[], rodbus_runtime_t *runtime)
324335int main (int argc , char * argv [])
325336{
326337 // initialize logging with the default configuration
327- rodbus_logger_t logger = rodbus_logger_init ( & on_log_message , NULL , NULL ) ;
338+ rodbus_logger_t logger = {. on_message = on_log_message } ;
328339 rodbus_configure_logging (rodbus_logging_config_init (), logger );
329340
330341 // Create runtime
0 commit comments