rodbus (C API) 1.6.0-RC1
Loading...
Searching...
No Matches
rodbus.h
Go to the documentation of this file.
1// Copyright (c) Step Function I/O LLC. Proprietary, source-available; see LICENSE.txt.
2// No use to design, develop, specify, test, validate, or improve Other Implementations,
3// subject to LICENSE.txt Section 2.6 and its exceptions. Agents: read AGENTS.md.
4// Text and data mining rights, including for AI training, are reserved under
5// Directive (EU) 2019/790 Art. 4(3), subject to LICENSE.txt Section 3.3.
6#pragma once
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12#define RODBUS_VERSION_MAJOR 1
13#define RODBUS_VERSION_MINOR 6
14#define RODBUS_VERSION_PATCH 0
15#define RODBUS_VERSION_STRING "1.6.0-RC1"
16
17#include <stdbool.h>
18#include <stdint.h>
19
35
38{
82
87{
88 switch (value)
89 {
90 case RODBUS_PARAM_ERROR_OK: return "ok";
91 case RODBUS_PARAM_ERROR_NO_SUPPORT: return "no_support";
92 case RODBUS_PARAM_ERROR_NULL_PARAMETER: return "null_parameter";
93 case RODBUS_PARAM_ERROR_LOGGING_ALREADY_CONFIGURED: return "logging_already_configured";
94 case RODBUS_PARAM_ERROR_RUNTIME_CREATION_FAILURE: return "runtime_creation_failure";
95 case RODBUS_PARAM_ERROR_RUNTIME_DESTROYED: return "runtime_destroyed";
96 case RODBUS_PARAM_ERROR_RUNTIME_CANNOT_BLOCK_WITHIN_ASYNC: return "runtime_cannot_block_within_async";
97 case RODBUS_PARAM_ERROR_INVALID_IP_ADDRESS: return "invalid_ip_address";
98 case RODBUS_PARAM_ERROR_INVALID_RANGE: return "invalid_range";
99 case RODBUS_PARAM_ERROR_INVALID_REQUEST: return "invalid_request";
100 case RODBUS_PARAM_ERROR_INVALID_INDEX: return "invalid_index";
101 case RODBUS_PARAM_ERROR_SERVER_BIND_ERROR: return "server_bind_error";
102 case RODBUS_PARAM_ERROR_INVALID_UNIT_ID: return "invalid_unit_id";
103 case RODBUS_PARAM_ERROR_INVALID_PEER_CERTIFICATE: return "invalid_peer_certificate";
104 case RODBUS_PARAM_ERROR_INVALID_LOCAL_CERTIFICATE: return "invalid_local_certificate";
105 case RODBUS_PARAM_ERROR_INVALID_PRIVATE_KEY: return "invalid_private_key";
106 case RODBUS_PARAM_ERROR_INVALID_DNS_NAME: return "invalid_dns_name";
107 case RODBUS_PARAM_ERROR_BAD_TLS_CONFIG: return "bad_tls_config";
108 case RODBUS_PARAM_ERROR_SHUTDOWN: return "shutdown";
109 case RODBUS_PARAM_ERROR_INVALID_UTF8: return "invalid_utf8";
110 case RODBUS_PARAM_ERROR_TOO_MANY_REQUESTS: return "too_many_requests";
111 default: return "unknown param_error value";
112 }
113}
114
115
118{
122
127{
128 switch (value)
129 {
130 case RODBUS_NOTHING_NOTHING: return "nothing";
131 default: return "unknown nothing value";
132 }
133}
134
139{
149
154{
155 switch (value)
156 {
157 case RODBUS_APP_DECODE_LEVEL_NOTHING: return "nothing";
158 case RODBUS_APP_DECODE_LEVEL_FUNCTION_CODE: return "function_code";
159 case RODBUS_APP_DECODE_LEVEL_DATA_HEADERS: return "data_headers";
160 case RODBUS_APP_DECODE_LEVEL_DATA_VALUES: return "data_values";
161 default: return "unknown app_decode_level value";
162 }
163}
164
171{
179
184{
185 switch (value)
186 {
187 case RODBUS_FRAME_DECODE_LEVEL_NOTHING: return "nothing";
188 case RODBUS_FRAME_DECODE_LEVEL_HEADER: return "header";
189 case RODBUS_FRAME_DECODE_LEVEL_PAYLOAD: return "payload";
190 default: return "unknown frame_decode_level value";
191 }
192}
193
196{
204
209{
210 switch (value)
211 {
212 case RODBUS_PHYS_DECODE_LEVEL_NOTHING: return "nothing";
213 case RODBUS_PHYS_DECODE_LEVEL_LENGTH: return "length";
214 case RODBUS_PHYS_DECODE_LEVEL_DATA: return "data";
215 default: return "unknown phys_decode_level value";
216 }
217}
218
220
223{
231
238{
239 rodbus_decode_level_t _return_value = {
240 app,
241 frame,
242 physical
243 };
244 return _return_value;
245}
246
256{
257 rodbus_decode_level_t _return_value = {
261 };
262 return _return_value;
263}
264
265
267
271typedef struct rodbus_bit_value_t
272{
274 uint16_t index;
276 bool value;
278
283static rodbus_bit_value_t rodbus_bit_value_init(uint16_t index, bool value)
284{
285 rodbus_bit_value_t _return_value = {
286 index,
287 value
288 };
289 return _return_value;
290}
291
292
294
299{
301 uint16_t index;
303 uint16_t value;
305
310static rodbus_register_value_t rodbus_register_value_init(uint16_t index, uint16_t value)
311{
312 rodbus_register_value_t _return_value = {
313 index,
314 value
315 };
316 return _return_value;
317}
318
319
322
324
327{
333
341{
342 rodbus_runtime_config_t _return_value = {
343 0
344 };
345 return _return_value;
346}
347
348
356
362
371
372
377{
419
424{
425 switch (value)
426 {
427 case RODBUS_REQUEST_ERROR_OK: return "ok";
428 case RODBUS_REQUEST_ERROR_SHUTDOWN: return "shutdown";
429 case RODBUS_REQUEST_ERROR_NO_CONNECTION: return "no_connection";
430 case RODBUS_REQUEST_ERROR_RESPONSE_TIMEOUT: return "response_timeout";
431 case RODBUS_REQUEST_ERROR_BAD_REQUEST: return "bad_request";
432 case RODBUS_REQUEST_ERROR_BAD_RESPONSE: return "bad_response";
433 case RODBUS_REQUEST_ERROR_IO_ERROR: return "io_error";
434 case RODBUS_REQUEST_ERROR_BAD_FRAMING: return "bad_framing";
435 case RODBUS_REQUEST_ERROR_INTERNAL_ERROR: return "internal_error";
436 case RODBUS_REQUEST_ERROR_BAD_ARGUMENT: return "bad_argument";
437 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ILLEGAL_FUNCTION: return "modbus_exception_illegal_function";
438 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS: return "modbus_exception_illegal_data_address";
439 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE: return "modbus_exception_illegal_data_value";
440 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_SERVER_DEVICE_FAILURE: return "modbus_exception_server_device_failure";
441 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ACKNOWLEDGE: return "modbus_exception_acknowledge";
442 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_SERVER_DEVICE_BUSY: return "modbus_exception_server_device_busy";
443 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_MEMORY_PARITY_ERROR: return "modbus_exception_memory_parity_error";
444 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_GATEWAY_PATH_UNAVAILABLE: return "modbus_exception_gateway_path_unavailable";
445 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND: return "modbus_exception_gateway_target_device_failed_to_respond";
446 case RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_UNKNOWN: return "modbus_exception_unknown";
447 default: return "unknown request_error value";
448 }
449}
450
451
453
456{
458 uint16_t start;
460 uint16_t count;
462
467static rodbus_address_range_t rodbus_address_range_init(uint16_t start, uint16_t count)
468{
469 rodbus_address_range_t _return_value = {
470 start,
471 count
472 };
473 return _return_value;
474}
475
476
478
481{
483 uint8_t unit_id;
486 uint64_t timeout;
488
493static rodbus_request_param_t rodbus_request_param_init(uint8_t unit_id, uint64_t timeout)
494{
495 rodbus_request_param_t _return_value = {
496 unit_id,
497 timeout
498 };
499 return _return_value;
500}
501
502
505
510
511
514
519
520
523{
545
550{
551 switch (value)
552 {
553 case RODBUS_MODBUS_EXCEPTION_ILLEGAL_FUNCTION: return "illegal_function";
554 case RODBUS_MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS: return "illegal_data_address";
555 case RODBUS_MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE: return "illegal_data_value";
556 case RODBUS_MODBUS_EXCEPTION_SERVER_DEVICE_FAILURE: return "server_device_failure";
557 case RODBUS_MODBUS_EXCEPTION_ACKNOWLEDGE: return "acknowledge";
558 case RODBUS_MODBUS_EXCEPTION_SERVER_DEVICE_BUSY: return "server_device_busy";
559 case RODBUS_MODBUS_EXCEPTION_MEMORY_PARITY_ERROR: return "memory_parity_error";
560 case RODBUS_MODBUS_EXCEPTION_GATEWAY_PATH_UNAVAILABLE: return "gateway_path_unavailable";
561 case RODBUS_MODBUS_EXCEPTION_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND: return "gateway_target_device_failed_to_respond";
562 case RODBUS_MODBUS_EXCEPTION_UNKNOWN: return "unknown";
563 default: return "unknown modbus_exception value";
564 }
565}
566
569{
579
584{
585 switch (value)
586 {
587 case RODBUS_DATA_BITS_FIVE: return "five";
588 case RODBUS_DATA_BITS_SIX: return "six";
589 case RODBUS_DATA_BITS_SEVEN: return "seven";
590 case RODBUS_DATA_BITS_EIGHT: return "eight";
591 default: return "unknown data_bits value";
592 }
593}
594
597{
605
610{
611 switch (value)
612 {
613 case RODBUS_FLOW_CONTROL_NONE: return "none";
614 case RODBUS_FLOW_CONTROL_SOFTWARE: return "software";
615 case RODBUS_FLOW_CONTROL_HARDWARE: return "hardware";
616 default: return "unknown flow_control value";
617 }
618}
619
621typedef enum rodbus_parity_t
622{
630
635{
636 switch (value)
637 {
638 case RODBUS_PARITY_NONE: return "none";
639 case RODBUS_PARITY_ODD: return "odd";
640 case RODBUS_PARITY_EVEN: return "even";
641 default: return "unknown parity value";
642 }
643}
644
647{
653
658{
659 switch (value)
660 {
661 case RODBUS_STOP_BITS_ONE: return "one";
662 case RODBUS_STOP_BITS_TWO: return "two";
663 default: return "unknown stop_bits value";
664 }
665}
666
668
671{
675 uint32_t baud_rate;
685
697{
698 rodbus_serial_port_settings_t _return_value = {
699 9600,
704 };
705 return _return_value;
706}
707
708
711{
719
724{
725 switch (value)
726 {
727 case RODBUS_MIN_TLS_VERSION_V12: return "v12";
728 case RODBUS_MIN_TLS_VERSION_V13: return "v13";
729 default: return "unknown min_tls_version value";
730 }
731}
732
737{
749
754{
755 switch (value)
756 {
757 case RODBUS_CERTIFICATE_MODE_AUTHORITY_BASED: return "authority_based";
758 case RODBUS_CERTIFICATE_MODE_SELF_SIGNED: return "self_signed";
759 default: return "unknown certificate_mode value";
760 }
761}
762
764
769{
772 uint64_t min_delay;
775 uint64_t max_delay;
777
786{
787 rodbus_retry_strategy_t _return_value = {
788 1000,
789 10000
790 };
791 return _return_value;
792}
793
794
799{
811
816{
817 switch (value)
818 {
819 case RODBUS_LOG_LEVEL_ERROR: return "error";
820 case RODBUS_LOG_LEVEL_WARN: return "warn";
821 case RODBUS_LOG_LEVEL_INFO: return "info";
822 case RODBUS_LOG_LEVEL_DEBUG: return "debug";
823 case RODBUS_LOG_LEVEL_TRACE: return "trace";
824 default: return "unknown log_level value";
825 }
826}
827
829
832{
838
843{
844 switch (value)
845 {
846 case RODBUS_LOG_OUTPUT_FORMAT_TEXT: return "text";
847 case RODBUS_LOG_OUTPUT_FORMAT_JSON: return "json";
848 default: return "unknown log_output_format value";
849 }
850}
851
854{
862
867{
868 switch (value)
869 {
870 case RODBUS_TIME_FORMAT_NONE: return "none";
871 case RODBUS_TIME_FORMAT_RFC_3339: return "rfc_3339";
872 case RODBUS_TIME_FORMAT_SYSTEM: return "system";
873 default: return "unknown time_format value";
874 }
875}
876
879{
891
903{
904 rodbus_logging_config_t _return_value = {
908 true,
909 false
910 };
911 return _return_value;
912}
913
914
916typedef struct rodbus_logger_t
917{
918
923 void (*on_message)(rodbus_log_level_t, const char*, void*);
926 void (*on_destroy)(void* arg);
928 void* ctx;
930
940
941
946
948
951{
953 const char* dns_name;
955 const char* peer_cert_path;
957 const char* local_cert_path;
959 const char* private_key_path;
965 const char* password;
973
987static rodbus_tls_client_config_t rodbus_tls_client_config_init(const char* dns_name, const char* peer_cert_path, const char* local_cert_path, const char* private_key_path, const char* password)
988{
989 rodbus_tls_client_config_t _return_value = {
990 dns_name,
991 peer_cert_path,
992 local_cert_path,
993 private_key_path,
994 password,
997 false
998 };
999 return _return_value;
1000}
1001
1002
1007{
1021
1026{
1027 switch (value)
1028 {
1029 case RODBUS_CLIENT_STATE_DISABLED: return "disabled";
1030 case RODBUS_CLIENT_STATE_CONNECTING: return "connecting";
1031 case RODBUS_CLIENT_STATE_CONNECTED: return "connected";
1032 case RODBUS_CLIENT_STATE_WAIT_AFTER_FAILED_CONNECT: return "wait_after_failed_connect";
1033 case RODBUS_CLIENT_STATE_WAIT_AFTER_DISCONNECT: return "wait_after_disconnect";
1034 case RODBUS_CLIENT_STATE_SHUTDOWN: return "shutdown";
1035 default: return "unknown client_state value";
1036 }
1037}
1038
1041{
1042
1049 void (*on_destroy)(void* arg);
1051 void* ctx;
1053
1058{
1068
1073{
1074 switch (value)
1075 {
1076 case RODBUS_PORT_STATE_DISABLED: return "disabled";
1077 case RODBUS_PORT_STATE_WAIT: return "wait";
1078 case RODBUS_PORT_STATE_OPEN: return "open";
1079 case RODBUS_PORT_STATE_SHUTDOWN: return "shutdown";
1080 default: return "unknown port_state value";
1081 }
1082}
1083
1086{
1087
1094 void (*on_destroy)(void* arg);
1096 void* ctx;
1098
1111rodbus_param_error_t rodbus_client_channel_create_tcp(rodbus_runtime_t* runtime, const char* host, uint16_t port, uint16_t max_queued_requests, rodbus_retry_strategy_t retry_strategy, rodbus_decode_level_t decode_level, rodbus_client_state_listener_t listener, rodbus_client_channel_t** out);
1112
1126
1140rodbus_param_error_t rodbus_client_channel_create_tls(rodbus_runtime_t* runtime, const char* host, uint16_t port, uint16_t max_queued_requests, rodbus_retry_strategy_t retry_strategy, rodbus_tls_client_config_t tls_config, rodbus_decode_level_t decode_level, rodbus_client_state_listener_t listener, rodbus_client_channel_t** out);
1141
1145
1150{
1151
1156
1163 void (*on_destroy)(void* arg);
1165 void* ctx;
1167
1172{
1173
1178
1185 void (*on_destroy)(void* arg);
1187 void* ctx;
1189
1192{
1193
1198
1205 void (*on_destroy)(void* arg);
1207 void* ctx;
1209
1217
1225
1233
1241
1249
1257
1260
1265
1269
1273void rodbus_bit_list_add(rodbus_bit_list_t* instance, bool value);
1274
1275
1284
1287
1292
1296
1300void rodbus_register_list_add(rodbus_register_list_t* instance, uint16_t value);
1301
1302
1311
1317
1324
1331
1332
1335
1341bool rodbus_database_add_coil(rodbus_database_t* instance, uint16_t index, bool value);
1342
1348bool rodbus_database_add_discrete_input(rodbus_database_t* instance, uint16_t index, bool value);
1349
1355bool rodbus_database_add_holding_register(rodbus_database_t* instance, uint16_t index, uint16_t value);
1356
1362bool rodbus_database_add_input_register(rodbus_database_t* instance, uint16_t index, uint16_t value);
1363
1370
1377
1384
1391
1397bool rodbus_database_update_coil(rodbus_database_t* instance, uint16_t index, bool value);
1398
1404bool rodbus_database_update_discrete_input(rodbus_database_t* instance, uint16_t index, bool value);
1405
1411bool rodbus_database_update_holding_register(rodbus_database_t* instance, uint16_t index, uint16_t value);
1412
1418bool rodbus_database_update_input_register(rodbus_database_t* instance, uint16_t index, uint16_t value);
1419
1424bool rodbus_database_delete_coil(rodbus_database_t* instance, uint16_t index);
1425
1431
1437
1443
1444
1447{
1448
1452 void (*callback)(rodbus_database_t*, void*);
1455 void (*on_destroy)(void* arg);
1457 void* ctx;
1459
1461
1468{
1476
1486{
1487 rodbus_write_result_t _return_value = {
1488 true,
1490 0
1491 };
1492 return _return_value;
1493}
1494
1504{
1505 rodbus_write_result_t _return_value = {
1506 false,
1507 exception,
1508 0
1509 };
1510 return _return_value;
1511}
1512
1522{
1523 rodbus_write_result_t _return_value = {
1524 false,
1526 raw_exception
1527 };
1528 return _return_value;
1529}
1530
1531
1534{
1535
1543
1551
1559
1569 void (*on_destroy)(void* arg);
1571 void* ctx;
1573
1576
1580
1584
1592
1593
1595
1598{
1600 const char* peer_cert_path;
1602 const char* local_cert_path;
1604 const char* private_key_path;
1610 const char* password;
1616
1628static rodbus_tls_server_config_t rodbus_tls_server_config_init(const char* peer_cert_path, const char* local_cert_path, const char* private_key_path, const char* password)
1629{
1630 rodbus_tls_server_config_t _return_value = {
1631 peer_cert_path,
1632 local_cert_path,
1633 private_key_path,
1634 password,
1637 };
1638 return _return_value;
1639}
1640
1641
1644{
1650
1655{
1656 switch (value)
1657 {
1658 case RODBUS_AUTHORIZATION_ALLOW: return "allow";
1659 case RODBUS_AUTHORIZATION_DENY: return "deny";
1660 default: return "unknown authorization value";
1661 }
1662}
1663
1666{
1667
1675
1683
1691
1699
1706 rodbus_authorization_t (*write_single_coil)(uint8_t, uint16_t, const char*, void*);
1707
1714 rodbus_authorization_t (*write_single_register)(uint8_t, uint16_t, const char*, void*);
1715
1723
1733 void (*on_destroy)(void* arg);
1735 void* ctx;
1737
1740
1744
1756
1764
1768
1769
1772
1787rodbus_param_error_t rodbus_server_create_tcp(rodbus_runtime_t* runtime, const char* address, uint16_t port, rodbus_address_filter_t* filter, uint16_t max_sessions, rodbus_device_map_t* endpoints, rodbus_decode_level_t decode_level, rodbus_server_t** out);
1788
1799
1818rodbus_param_error_t rodbus_server_create_tls_with_authz(rodbus_runtime_t* runtime, const char* address, uint16_t port, rodbus_address_filter_t* filter, uint16_t max_sessions, rodbus_device_map_t* endpoints, rodbus_tls_server_config_t tls_config, rodbus_authorization_handler_t authorization_handler, rodbus_decode_level_t decode_level, rodbus_server_t** out);
1819
1835rodbus_param_error_t rodbus_server_create_tls(rodbus_runtime_t* runtime, const char* address, uint16_t port, rodbus_address_filter_t* filter, uint16_t max_sessions, rodbus_device_map_t* endpoints, rodbus_tls_server_config_t tls_config, rodbus_decode_level_t decode_level, rodbus_server_t** out);
1836
1840
1847
1853
1854
1857const char* rodbus_version();
1858
1859#ifdef __cplusplus
1860}
1861#endif
static rodbus_bit_value_t rodbus_bit_value_init(uint16_t index, bool value)
Fully construct rodbus_bit_value_t specifying the value of each field.
Definition: rodbus.h:283
static const char * rodbus_request_error_to_string(rodbus_request_error_t value)
Converts the enum to a string.
Definition: rodbus.h:423
rodbus_param_error_t rodbus_server_create_tls(rodbus_runtime_t *runtime, const char *address, uint16_t port, rodbus_address_filter_t *filter, uint16_t max_sessions, rodbus_device_map_t *endpoints, rodbus_tls_server_config_t tls_config, rodbus_decode_level_t decode_level, rodbus_server_t **out)
Create a TLS server that does NOT require the client role extension.
rodbus_port_state_t
State of the serial port.
Definition: rodbus.h:1058
@ RODBUS_PORT_STATE_OPEN
Port is open.
Definition: rodbus.h:1064
@ RODBUS_PORT_STATE_DISABLED
Disabled until enabled.
Definition: rodbus.h:1060
@ RODBUS_PORT_STATE_WAIT
Waiting to perform an open retry.
Definition: rodbus.h:1062
@ RODBUS_PORT_STATE_SHUTDOWN
Task has been shut down.
Definition: rodbus.h:1066
rodbus_register_list_t * rodbus_register_list_create(uint32_t reserve_size)
Creates an instance of the collection.
rodbus_log_output_format_t
Describes how each log event is formatted.
Definition: rodbus.h:832
@ RODBUS_LOG_OUTPUT_FORMAT_TEXT
A simple text-based format.
Definition: rodbus.h:834
@ RODBUS_LOG_OUTPUT_FORMAT_JSON
Output formatted as JSON.
Definition: rodbus.h:836
void rodbus_register_list_add(rodbus_register_list_t *instance, uint16_t value)
Add a value to the collection.
rodbus_param_error_t rodbus_client_channel_write_multiple_registers(rodbus_client_channel_t *instance, rodbus_request_param_t param, uint16_t start, rodbus_register_list_t *items, rodbus_write_callback_t callback)
Write multiple registers.
void rodbus_runtime_destroy(rodbus_runtime_t *instance)
Destroy a runtime.
bool rodbus_database_update_holding_register(rodbus_database_t *instance, uint16_t index, uint16_t value)
Update the current value of a holding register in the database.
static const char * rodbus_certificate_mode_to_string(rodbus_certificate_mode_t value)
Converts the enum to a string.
Definition: rodbus.h:753
rodbus_min_tls_version_t
Minimum TLS version to allow.
Definition: rodbus.h:711
@ RODBUS_MIN_TLS_VERSION_V13
Allow only TLS 1.3.
Definition: rodbus.h:717
@ RODBUS_MIN_TLS_VERSION_V12
Allow TLS 1.2 and TLS 1.3.
Definition: rodbus.h:713
static rodbus_address_range_t rodbus_address_range_init(uint16_t start, uint16_t count)
Fully construct rodbus_address_range_t specifying the value of each field.
Definition: rodbus.h:467
rodbus_param_error_t rodbus_client_channel_read_coils(rodbus_client_channel_t *instance, rodbus_request_param_t param, rodbus_address_range_t range, rodbus_bit_read_callback_t callback)
Start an asynchronous request to read coils.
rodbus_param_error_t rodbus_configure_logging(rodbus_logging_config_t config, rodbus_logger_t logger)
Set the callback that will receive all the log messages.
static const char * rodbus_modbus_exception_to_string(rodbus_modbus_exception_t value)
Converts the enum to a string.
Definition: rodbus.h:549
static rodbus_request_param_t rodbus_request_param_init(uint8_t unit_id, uint64_t timeout)
Fully construct rodbus_request_param_t specifying the value of each field.
Definition: rodbus.h:493
rodbus_param_error_t rodbus_client_channel_write_single_register(rodbus_client_channel_t *instance, rodbus_request_param_t param, rodbus_register_value_t value, rodbus_write_callback_t callback)
Write a single register.
struct rodbus_runtime_t rodbus_runtime_t
Handle to the underlying runtime.
Definition: rodbus.h:321
void rodbus_bit_list_add(rodbus_bit_list_t *instance, bool value)
Add a value to the collection.
void rodbus_runtime_set_shutdown_timeout(rodbus_runtime_t *instance, uint64_t timeout)
By default, when the runtime shuts down, it does so without a timeout and waits indefinitely for all ...
static const char * rodbus_data_bits_to_string(rodbus_data_bits_t value)
Converts the enum to a string.
Definition: rodbus.h:583
rodbus_flow_control_t
Flow control modes.
Definition: rodbus.h:597
@ RODBUS_FLOW_CONTROL_SOFTWARE
Flow control using XON/XOFF bytes.
Definition: rodbus.h:601
@ RODBUS_FLOW_CONTROL_HARDWARE
Flow control using RTS/CTS signals.
Definition: rodbus.h:603
@ RODBUS_FLOW_CONTROL_NONE
No flow control.
Definition: rodbus.h:599
static rodbus_write_result_t rodbus_write_result_exception_init(rodbus_modbus_exception_t exception)
Initialize a rodbus_write_result_t to indicate a standard Modbus exception.
Definition: rodbus.h:1503
rodbus_param_error_t rodbus_database_get_coil(rodbus_database_t *instance, uint16_t index, bool *out)
Get the current coil value of the database.
void rodbus_bit_list_destroy(rodbus_bit_list_t *instance)
Destroys an instance of the collection.
rodbus_param_error_t rodbus_database_get_input_register(rodbus_database_t *instance, uint16_t index, uint16_t *out)
Get the current input register value of the database.
rodbus_bit_list_t * rodbus_bit_list_create(uint32_t reserve_size)
Creates an instance of the collection.
rodbus_frame_decode_level_t
Controls how the transmitted and received frames are decoded at the INFO log level.
Definition: rodbus.h:171
@ RODBUS_FRAME_DECODE_LEVEL_PAYLOAD
Decode the header and the raw payload as hexadecimal.
Definition: rodbus.h:177
@ RODBUS_FRAME_DECODE_LEVEL_NOTHING
Log nothing.
Definition: rodbus.h:173
@ RODBUS_FRAME_DECODE_LEVEL_HEADER
Decode the header.
Definition: rodbus.h:175
bool rodbus_database_add_coil(rodbus_database_t *instance, uint16_t index, bool value)
Add a new coil to the database.
struct rodbus_server_t rodbus_server_t
Handle to the running server. The server runs on a background task until this class is destroyed.
Definition: rodbus.h:1771
rodbus_param_error_t rodbus_client_channel_write_multiple_coils(rodbus_client_channel_t *instance, rodbus_request_param_t param, uint16_t start, rodbus_bit_list_t *items, rodbus_write_callback_t callback)
Write multiple coils.
static const char * rodbus_parity_to_string(rodbus_parity_t value)
Converts the enum to a string.
Definition: rodbus.h:634
static const char * rodbus_flow_control_to_string(rodbus_flow_control_t value)
Converts the enum to a string.
Definition: rodbus.h:609
static rodbus_decode_level_t rodbus_decode_level_build(rodbus_app_decode_level_t app, rodbus_frame_decode_level_t frame, rodbus_phys_decode_level_t physical)
Fully construct rodbus_decode_level_t specifying the value of each field.
Definition: rodbus.h:237
bool rodbus_database_delete_coil(rodbus_database_t *instance, uint16_t index)
Remove a coil address from the database.
static const char * rodbus_frame_decode_level_to_string(rodbus_frame_decode_level_t value)
Converts the enum to a string.
Definition: rodbus.h:183
bool rodbus_database_add_holding_register(rodbus_database_t *instance, uint16_t index, uint16_t value)
Add a new holding register to the database.
rodbus_request_error_t
Error information returned from asynchronous functions calls.
Definition: rodbus.h:377
@ RODBUS_REQUEST_ERROR_NO_CONNECTION
The channel had no connection (or open serial port) for the request: it was disabled,...
Definition: rodbus.h:383
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_UNKNOWN
The status code is not defined in the Modbus specification, refer to the raw exception code to see wh...
Definition: rodbus.h:417
@ RODBUS_REQUEST_ERROR_BAD_REQUEST
The request was invalid.
Definition: rodbus.h:387
@ RODBUS_REQUEST_ERROR_OK
Success, i.e. no error occurred.
Definition: rodbus.h:379
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_SERVER_DEVICE_FAILURE
An unrecoverable error occurred while the server was attempting to perform the requested action.
Definition: rodbus.h:405
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_MEMORY_PARITY_ERROR
Specialized use in conjunction with function codes 20 and 21 and reference type 6,...
Definition: rodbus.h:411
@ RODBUS_REQUEST_ERROR_SHUTDOWN
The channel was shutdown before the operation could complete.
Definition: rodbus.h:381
@ RODBUS_REQUEST_ERROR_RESPONSE_TIMEOUT
No valid response was received before the timeout.
Definition: rodbus.h:385
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_SERVER_DEVICE_BUSY
Specialized use in conjunction with programming commands. The server is engaged in processing a long-...
Definition: rodbus.h:409
@ RODBUS_REQUEST_ERROR_BAD_ARGUMENT
An invalid argument was supplied and the request could not be performed.
Definition: rodbus.h:397
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ILLEGAL_FUNCTION
The data address received in the query is not an allowable address for the server.
Definition: rodbus.h:399
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ACKNOWLEDGE
Specialized use in conjunction with programming commands. The server has accepted the request and is ...
Definition: rodbus.h:407
@ RODBUS_REQUEST_ERROR_BAD_RESPONSE
The response from the server was received but was improperly formatted.
Definition: rodbus.h:389
@ RODBUS_REQUEST_ERROR_INTERNAL_ERROR
An unspecified internal error occurred while performing the request.
Definition: rodbus.h:395
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND
Specialized use in conjunction with gateways, indicates that no response was obtained from the target...
Definition: rodbus.h:415
@ RODBUS_REQUEST_ERROR_IO_ERROR
An I/O error occurred on the underlying stream while performing the request.
Definition: rodbus.h:391
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS
The data address received in the query is not an allowable address for the server.
Definition: rodbus.h:401
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_GATEWAY_PATH_UNAVAILABLE
Specialized use in conjunction with gateways, indicates that the gateway was unable to allocate an in...
Definition: rodbus.h:413
@ RODBUS_REQUEST_ERROR_BAD_FRAMING
A framing error was detected while performing the request.
Definition: rodbus.h:393
@ RODBUS_REQUEST_ERROR_MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE
A value contained in the request is not an allowable value for server.
Definition: rodbus.h:403
struct rodbus_address_filter_t rodbus_address_filter_t
Filter used to restrict which IP addresses may communicate with a server.
Definition: rodbus.h:1739
static rodbus_tls_client_config_t rodbus_tls_client_config_init(const char *dns_name, const char *peer_cert_path, const char *local_cert_path, const char *private_key_path, const char *password)
Initialize a TLS client configuration.
Definition: rodbus.h:987
static rodbus_tls_server_config_t rodbus_tls_server_config_init(const char *peer_cert_path, const char *local_cert_path, const char *private_key_path, const char *password)
Initialize a TLS server configuration.
Definition: rodbus.h:1628
rodbus_param_error_t rodbus_client_channel_write_single_coil(rodbus_client_channel_t *instance, rodbus_request_param_t param, rodbus_bit_value_t value, rodbus_write_callback_t callback)
Write a single coil.
rodbus_param_error_t rodbus_server_create_rtu(rodbus_runtime_t *runtime, const char *path, rodbus_serial_port_settings_t serial_params, rodbus_retry_strategy_t retry, rodbus_device_map_t *endpoints, rodbus_decode_level_t decode_level, rodbus_server_t **out)
Launch a RTU server.
bool rodbus_database_update_coil(rodbus_database_t *instance, uint16_t index, bool value)
Update the current value of a coil in the database.
bool rodbus_database_update_discrete_input(rodbus_database_t *instance, uint16_t index, bool value)
Update the current value of a discrete input in the database.
struct rodbus_client_channel_t rodbus_client_channel_t
Abstract representation of a client communication channel.
Definition: rodbus.h:945
rodbus_register_value_t * rodbus_register_value_iterator_next(rodbus_register_value_iterator_t *iter)
returns a pointer to the next value or NULL
bool rodbus_database_delete_holding_register(rodbus_database_t *instance, uint16_t index)
Remove a holding register address from the database.
rodbus_param_error_t rodbus_client_channel_create_tls(rodbus_runtime_t *runtime, const char *host, uint16_t port, uint16_t max_queued_requests, rodbus_retry_strategy_t retry_strategy, rodbus_tls_client_config_t tls_config, rodbus_decode_level_t decode_level, rodbus_client_state_listener_t listener, rodbus_client_channel_t **out)
Create a new TLS channel instance.
static rodbus_serial_port_settings_t rodbus_serial_port_settings_init()
Initialize a serial port configuration.
Definition: rodbus.h:696
rodbus_param_error_t rodbus_client_channel_enable(rodbus_client_channel_t *instance)
Enable channel communications.
rodbus_param_error_t rodbus_server_update_database(rodbus_server_t *instance, uint8_t unit_id, rodbus_database_callback_t transaction)
Update the database associated with a particular unit id. If the unit id exists, lock the database an...
bool rodbus_database_delete_discrete_input(rodbus_database_t *instance, uint16_t index)
Remove a discrete input address from the database.
rodbus_param_error_t rodbus_client_channel_disable(rodbus_client_channel_t *instance)
Disable channel communications.
rodbus_param_error_t rodbus_client_channel_read_holding_registers(rodbus_client_channel_t *instance, rodbus_request_param_t param, rodbus_address_range_t range, rodbus_register_read_callback_t callback)
Start an asynchronous request to read holding registers.
void rodbus_client_channel_destroy(rodbus_client_channel_t *instance)
Shutdown a rodbus_client_channel_t and release all resources.
rodbus_param_error_t rodbus_server_create_tcp(rodbus_runtime_t *runtime, const char *address, uint16_t port, rodbus_address_filter_t *filter, uint16_t max_sessions, rodbus_device_map_t *endpoints, rodbus_decode_level_t decode_level, rodbus_server_t **out)
Launch a TCP server.
static const char * rodbus_param_error_to_string(rodbus_param_error_t value)
Converts the enum to a string.
Definition: rodbus.h:86
rodbus_stop_bits_t
Number of stop bits.
Definition: rodbus.h:647
@ RODBUS_STOP_BITS_TWO
Two stop bits.
Definition: rodbus.h:651
@ RODBUS_STOP_BITS_ONE
One stop bit.
Definition: rodbus.h:649
static rodbus_write_result_t rodbus_write_result_success_init()
Initialize a rodbus_write_result_t to indicate a successful write operation.
Definition: rodbus.h:1485
static rodbus_register_value_t rodbus_register_value_init(uint16_t index, uint16_t value)
Fully construct rodbus_register_value_t specifying the value of each field.
Definition: rodbus.h:310
rodbus_parity_t
Parity checking modes.
Definition: rodbus.h:622
@ RODBUS_PARITY_ODD
Parity bit sets odd number of 1 bits.
Definition: rodbus.h:626
@ RODBUS_PARITY_NONE
No parity bit.
Definition: rodbus.h:624
@ RODBUS_PARITY_EVEN
Parity bit sets even number of 1 bits.
Definition: rodbus.h:628
rodbus_data_bits_t
Number of bits per character.
Definition: rodbus.h:569
@ RODBUS_DATA_BITS_FIVE
5 bits per character
Definition: rodbus.h:571
@ RODBUS_DATA_BITS_SEVEN
7 bits per character
Definition: rodbus.h:575
@ RODBUS_DATA_BITS_SIX
6 bits per character
Definition: rodbus.h:573
@ RODBUS_DATA_BITS_EIGHT
8 bits per character
Definition: rodbus.h:577
bool rodbus_database_delete_input_register(rodbus_database_t *instance, uint16_t index)
Remove a input register address from the database.
rodbus_bit_value_t * rodbus_bit_value_iterator_next(rodbus_bit_value_iterator_t *iter)
returns a pointer to the next value or NULL
void rodbus_server_destroy(rodbus_server_t *instance)
Shutdown and release all resources of a running server.
bool rodbus_database_add_discrete_input(rodbus_database_t *instance, uint16_t index, bool value)
Add a new discrete input to the database.
rodbus_param_error_t rodbus_client_channel_create_tcp(rodbus_runtime_t *runtime, const char *host, uint16_t port, uint16_t max_queued_requests, rodbus_retry_strategy_t retry_strategy, rodbus_decode_level_t decode_level, rodbus_client_state_listener_t listener, rodbus_client_channel_t **out)
Create a new TCP channel instance.
rodbus_param_error_t rodbus_client_channel_set_decode_level(rodbus_client_channel_t *instance, rodbus_decode_level_t level)
Set the decoding level for the channel.
static rodbus_decode_level_t rodbus_decode_level_nothing()
Initialize log levels to defaults which is to decode nothing.
Definition: rodbus.h:255
rodbus_param_error_t rodbus_address_filter_create(const char *address, rodbus_address_filter_t **out)
Create an address filter that matches one or more IP addresses. Ipv4 or IPv6 addresses are allowed.
rodbus_time_format_t
Describes if and how the time will be formatted in log messages.
Definition: rodbus.h:854
@ RODBUS_TIME_FORMAT_RFC_3339
Format the time using RFC 3339.
Definition: rodbus.h:858
@ RODBUS_TIME_FORMAT_NONE
Don't format the timestamp as part of the message.
Definition: rodbus.h:856
@ RODBUS_TIME_FORMAT_SYSTEM
Format the time in a human readable format e.g. 'Jun 25 14:27:12.955'.
Definition: rodbus.h:860
rodbus_param_error_t rodbus_address_filter_add(rodbus_address_filter_t *instance, const char *address)
Add an allowed IP address to the filter.
struct rodbus_device_map_t rodbus_device_map_t
Maps endpoint handlers to Modbus address.
Definition: rodbus.h:1575
static const char * rodbus_time_format_to_string(rodbus_time_format_t value)
Converts the enum to a string.
Definition: rodbus.h:866
static rodbus_runtime_config_t rodbus_runtime_config_init()
Initialize the configuration to default values.
Definition: rodbus.h:340
struct rodbus_bit_value_iterator_t rodbus_bit_value_iterator_t
Iterator of bit_value.
Definition: rodbus.h:504
struct rodbus_database_t rodbus_database_t
Class used to add, remove, update, and retrieve values.
Definition: rodbus.h:1334
static const char * rodbus_app_decode_level_to_string(rodbus_app_decode_level_t value)
Converts the enum to a string.
Definition: rodbus.h:153
rodbus_param_error_t rodbus_client_channel_create_rtu(rodbus_runtime_t *runtime, const char *path, rodbus_serial_port_settings_t serial_params, uint16_t max_queued_requests, rodbus_retry_strategy_t retry_strategy, rodbus_decode_level_t decode_level, rodbus_port_state_listener_t listener, rodbus_client_channel_t **out)
Create a new RTU channel instance.
rodbus_client_state_t
State of the client connection.
Definition: rodbus.h:1007
@ RODBUS_CLIENT_STATE_WAIT_AFTER_FAILED_CONNECT
Failed to establish a connection, waiting before retrying.
Definition: rodbus.h:1015
@ RODBUS_CLIENT_STATE_WAIT_AFTER_DISCONNECT
Client was disconnected, waiting before retrying.
Definition: rodbus.h:1017
@ RODBUS_CLIENT_STATE_CONNECTED
Client is connected to the remote device.
Definition: rodbus.h:1013
@ RODBUS_CLIENT_STATE_DISABLED
Client is disabled and idle until enabled.
Definition: rodbus.h:1009
@ RODBUS_CLIENT_STATE_SHUTDOWN
Client is shutting down.
Definition: rodbus.h:1019
@ RODBUS_CLIENT_STATE_CONNECTING
Client is trying to establish a connection to the remote device.
Definition: rodbus.h:1011
static const char * rodbus_port_state_to_string(rodbus_port_state_t value)
Converts the enum to a string.
Definition: rodbus.h:1072
bool rodbus_database_update_input_register(rodbus_database_t *instance, uint16_t index, uint16_t value)
Update the current value of a input register in the database.
rodbus_param_error_t rodbus_runtime_create(rodbus_runtime_config_t config, rodbus_runtime_t **out)
Creates a new runtime for running the protocol stack.
struct rodbus_register_list_t rodbus_register_list_t
Collection of register_list.
Definition: rodbus.h:1286
rodbus_param_error_t rodbus_server_create_tls_with_authz(rodbus_runtime_t *runtime, const char *address, uint16_t port, rodbus_address_filter_t *filter, uint16_t max_sessions, rodbus_device_map_t *endpoints, rodbus_tls_server_config_t tls_config, rodbus_authorization_handler_t authorization_handler, rodbus_decode_level_t decode_level, rodbus_server_t **out)
Create a Modbus Security (TLS) server.
static const char * rodbus_nothing_to_string(rodbus_nothing_t value)
Converts the enum to a string.
Definition: rodbus.h:126
struct rodbus_bit_list_t rodbus_bit_list_t
Collection of bit_list.
Definition: rodbus.h:1259
static const char * rodbus_log_level_to_string(rodbus_log_level_t value)
Converts the enum to a string.
Definition: rodbus.h:815
static const char * rodbus_phys_decode_level_to_string(rodbus_phys_decode_level_t value)
Converts the enum to a string.
Definition: rodbus.h:208
static const char * rodbus_min_tls_version_to_string(rodbus_min_tls_version_t value)
Converts the enum to a string.
Definition: rodbus.h:723
static const char * rodbus_authorization_to_string(rodbus_authorization_t value)
Converts the enum to a string.
Definition: rodbus.h:1654
bool rodbus_device_map_add_endpoint(rodbus_device_map_t *instance, uint8_t unit_id, rodbus_write_handler_t handler, rodbus_database_callback_t configure)
Add an endpoint to the map.
rodbus_param_error_t rodbus_client_channel_read_discrete_inputs(rodbus_client_channel_t *instance, rodbus_request_param_t param, rodbus_address_range_t range, rodbus_bit_read_callback_t callback)
Start an asynchronous request to read discrete inputs.
void rodbus_device_map_destroy(rodbus_device_map_t *instance)
Destroy a previously created device map.
rodbus_param_error_t rodbus_database_get_discrete_input(rodbus_database_t *instance, uint16_t index, bool *out)
Get the current discrete input value of the database.
static rodbus_retry_strategy_t rodbus_retry_strategy_init()
Initialize a retry strategy to defaults.
Definition: rodbus.h:785
rodbus_address_filter_t * rodbus_address_filter_any()
Create an address filter that accepts any IP address.
rodbus_param_error_t rodbus_client_channel_read_input_registers(rodbus_client_channel_t *instance, rodbus_request_param_t param, rodbus_address_range_t range, rodbus_register_read_callback_t callback)
Start an asynchronous request to read input registers.
rodbus_modbus_exception_t
Error information returned during asynchronous API calls.
Definition: rodbus.h:523
@ RODBUS_MODBUS_EXCEPTION_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND
Specialized use in conjunction with gateways, indicates that no response was obtained from the target...
Definition: rodbus.h:541
@ RODBUS_MODBUS_EXCEPTION_UNKNOWN
The status code is not defined in the Modbus specification, refer to the raw exception code to see wh...
Definition: rodbus.h:543
@ RODBUS_MODBUS_EXCEPTION_SERVER_DEVICE_BUSY
Specialized use in conjunction with programming commands. The server is engaged in processing a long-...
Definition: rodbus.h:535
@ RODBUS_MODBUS_EXCEPTION_MEMORY_PARITY_ERROR
Specialized use in conjunction with function codes 20 and 21 and reference type 6,...
Definition: rodbus.h:537
@ RODBUS_MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE
A value contained in the request is not an allowable value for server.
Definition: rodbus.h:529
@ RODBUS_MODBUS_EXCEPTION_ACKNOWLEDGE
Specialized use in conjunction with programming commands. The server has accepted the request and is ...
Definition: rodbus.h:533
@ RODBUS_MODBUS_EXCEPTION_SERVER_DEVICE_FAILURE
An unrecoverable error occurred while the server was attempting to perform the requested action.
Definition: rodbus.h:531
@ RODBUS_MODBUS_EXCEPTION_ILLEGAL_FUNCTION
The data address received in the query is not an allowable address for the server.
Definition: rodbus.h:525
@ RODBUS_MODBUS_EXCEPTION_GATEWAY_PATH_UNAVAILABLE
Specialized use in conjunction with gateways, indicates that the gateway was unable to allocate an in...
Definition: rodbus.h:539
@ RODBUS_MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS
The data address received in the query is not an allowable address for the server.
Definition: rodbus.h:527
rodbus_authorization_t
Authorization result used by rodbus_authorization_handler_t.
Definition: rodbus.h:1644
@ RODBUS_AUTHORIZATION_DENY
Client is NOT authorized to perform the operation.
Definition: rodbus.h:1648
@ RODBUS_AUTHORIZATION_ALLOW
Client is authorized to perform the operation.
Definition: rodbus.h:1646
static const char * rodbus_client_state_to_string(rodbus_client_state_t value)
Converts the enum to a string.
Definition: rodbus.h:1025
rodbus_phys_decode_level_t
Controls how data transmitted at the physical layer (TCP, serial, etc) is logged.
Definition: rodbus.h:196
@ RODBUS_PHYS_DECODE_LEVEL_DATA
Log the length and the actual data that is sent and received.
Definition: rodbus.h:202
@ RODBUS_PHYS_DECODE_LEVEL_LENGTH
Log only the length of data that is sent and received.
Definition: rodbus.h:200
@ RODBUS_PHYS_DECODE_LEVEL_NOTHING
Log nothing.
Definition: rodbus.h:198
rodbus_device_map_t * rodbus_device_map_create()
Create a device map that will be used to bind devices to a server endpoint.
rodbus_param_error_t rodbus_database_get_holding_register(rodbus_database_t *instance, uint16_t index, uint16_t *out)
Get the current holding register value of the database.
bool rodbus_database_add_input_register(rodbus_database_t *instance, uint16_t index, uint16_t value)
Add a new input register to the database.
void rodbus_register_list_destroy(rodbus_register_list_t *instance)
Destroys an instance of the collection.
static rodbus_write_result_t rodbus_write_result_raw_exception_init(uint8_t raw_exception)
Initialize a rodbus_write_result_t to indicate a non-standard Modbus exception.
Definition: rodbus.h:1521
const char * rodbus_version()
Get the version of the library as a string.
rodbus_param_error_t rodbus_server_set_decode_level(rodbus_server_t *instance, rodbus_decode_level_t level)
Set the decoding level for the server.
rodbus_param_error_t
Error type that indicates a bad parameter or bad programmer logic.
Definition: rodbus.h:38
@ RODBUS_PARAM_ERROR_OK
Success, i.e. no error occurred.
Definition: rodbus.h:40
@ RODBUS_PARAM_ERROR_INVALID_UTF8
String argument was not valid UTF-8.
Definition: rodbus.h:78
@ RODBUS_PARAM_ERROR_RUNTIME_CANNOT_BLOCK_WITHIN_ASYNC
Runtime cannot execute blocking call within asynchronous context.
Definition: rodbus.h:52
@ RODBUS_PARAM_ERROR_INVALID_RANGE
Invalid Modbus address range.
Definition: rodbus.h:56
@ RODBUS_PARAM_ERROR_INVALID_LOCAL_CERTIFICATE
Invalid local certificate file.
Definition: rodbus.h:68
@ RODBUS_PARAM_ERROR_INVALID_REQUEST
Invalid Modbus request.
Definition: rodbus.h:58
@ RODBUS_PARAM_ERROR_INVALID_INDEX
Invalid index.
Definition: rodbus.h:60
@ RODBUS_PARAM_ERROR_INVALID_PRIVATE_KEY
Invalid private key file.
Definition: rodbus.h:70
@ RODBUS_PARAM_ERROR_SERVER_BIND_ERROR
Server failed to bind to the specified port.
Definition: rodbus.h:62
@ RODBUS_PARAM_ERROR_RUNTIME_CREATION_FAILURE
Failed to create Tokio runtime.
Definition: rodbus.h:48
@ RODBUS_PARAM_ERROR_INVALID_DNS_NAME
Invalid DNS name.
Definition: rodbus.h:72
@ RODBUS_PARAM_ERROR_INVALID_IP_ADDRESS
Invalid IP address.
Definition: rodbus.h:54
@ RODBUS_PARAM_ERROR_NULL_PARAMETER
Null parameter.
Definition: rodbus.h:44
@ RODBUS_PARAM_ERROR_SHUTDOWN
The task has been shutdown.
Definition: rodbus.h:76
@ RODBUS_PARAM_ERROR_BAD_TLS_CONFIG
Bad TLS configuration.
Definition: rodbus.h:74
@ RODBUS_PARAM_ERROR_INVALID_PEER_CERTIFICATE
Invalid peer certificate file.
Definition: rodbus.h:66
@ RODBUS_PARAM_ERROR_TOO_MANY_REQUESTS
Number of requests exceeds configured limit.
Definition: rodbus.h:80
@ RODBUS_PARAM_ERROR_LOGGING_ALREADY_CONFIGURED
Logging can only be configured once.
Definition: rodbus.h:46
@ RODBUS_PARAM_ERROR_RUNTIME_DESTROYED
Runtime was already disposed of.
Definition: rodbus.h:50
@ RODBUS_PARAM_ERROR_NO_SUPPORT
The FFI library was compiled without support for this feature.
Definition: rodbus.h:42
@ RODBUS_PARAM_ERROR_INVALID_UNIT_ID
The specified unit id is not associated to this server.
Definition: rodbus.h:64
static const char * rodbus_stop_bits_to_string(rodbus_stop_bits_t value)
Converts the enum to a string.
Definition: rodbus.h:657
void rodbus_address_filter_destroy(rodbus_address_filter_t *instance)
Destroy an address filter.
static const char * rodbus_log_output_format_to_string(rodbus_log_output_format_t value)
Converts the enum to a string.
Definition: rodbus.h:842
rodbus_log_level_t
Log level.
Definition: rodbus.h:799
@ RODBUS_LOG_LEVEL_ERROR
Error log level.
Definition: rodbus.h:801
@ RODBUS_LOG_LEVEL_INFO
Information log level.
Definition: rodbus.h:805
@ RODBUS_LOG_LEVEL_TRACE
Trace log level.
Definition: rodbus.h:809
@ RODBUS_LOG_LEVEL_DEBUG
Debugging log level.
Definition: rodbus.h:807
@ RODBUS_LOG_LEVEL_WARN
Warning log level.
Definition: rodbus.h:803
rodbus_certificate_mode_t
Determines how the certificate(s) presented by the peer are validated.
Definition: rodbus.h:737
@ RODBUS_CERTIFICATE_MODE_SELF_SIGNED
Validates that the peer presents a single certificate which is a byte-for-byte match against the conf...
Definition: rodbus.h:747
@ RODBUS_CERTIFICATE_MODE_AUTHORITY_BASED
Validates the peer certificate against one or more configured trust anchors.
Definition: rodbus.h:743
static rodbus_logging_config_t rodbus_logging_config_init()
Initialize the configuration to default values.
Definition: rodbus.h:902
rodbus_nothing_t
A single value enum which is used as a placeholder for futures that don't return a value.
Definition: rodbus.h:118
@ RODBUS_NOTHING_NOTHING
the only value this enum has
Definition: rodbus.h:120
rodbus_app_decode_level_t
Controls how transmitted and received message at the application layer are decoded at the INFO log le...
Definition: rodbus.h:139
@ RODBUS_APP_DECODE_LEVEL_DATA_VALUES
Decode the function code, the general description of the data and the actual data values.
Definition: rodbus.h:147
@ RODBUS_APP_DECODE_LEVEL_NOTHING
Decode nothing.
Definition: rodbus.h:141
@ RODBUS_APP_DECODE_LEVEL_FUNCTION_CODE
Decode the function code only.
Definition: rodbus.h:143
@ RODBUS_APP_DECODE_LEVEL_DATA_HEADERS
Decode the function code and the general description of the data.
Definition: rodbus.h:145
struct rodbus_register_value_iterator_t rodbus_register_value_iterator_t
Iterator of register_value.
Definition: rodbus.h:513
Range of 16-bit addresses sent in a request from the client to the server.
Definition: rodbus.h:456
uint16_t start
Starting address of the range.
Definition: rodbus.h:458
uint16_t count
Number of addresses in the range.
Definition: rodbus.h:460
User implemented interface defines which request and roles are allowed for different functions when i...
Definition: rodbus.h:1666
rodbus_authorization_t(* write_single_coil)(uint8_t, uint16_t, const char *, void *)
Authorize a Write Single Coil request.
Definition: rodbus.h:1706
rodbus_authorization_t(* write_multiple_registers)(uint8_t, rodbus_address_range_t, const char *, void *)
Authorize a Write Multiple Registers request.
Definition: rodbus.h:1730
rodbus_authorization_t(* read_input_registers)(uint8_t, rodbus_address_range_t, const char *, void *)
Authorize a Read Input Registers request.
Definition: rodbus.h:1698
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1733
rodbus_authorization_t(* read_coils)(uint8_t, rodbus_address_range_t, const char *, void *)
Authorize a Read Coils request.
Definition: rodbus.h:1674
rodbus_authorization_t(* read_holding_registers)(uint8_t, rodbus_address_range_t, const char *, void *)
Authorize a Read Holding Registers request.
Definition: rodbus.h:1690
void * ctx
Context data.
Definition: rodbus.h:1735
rodbus_authorization_t(* write_single_register)(uint8_t, uint16_t, const char *, void *)
Authorize a Write Single Register request.
Definition: rodbus.h:1714
rodbus_authorization_t(* write_multiple_coils)(uint8_t, rodbus_address_range_t, const char *, void *)
Authorize a Write Multiple Coils request.
Definition: rodbus.h:1722
rodbus_authorization_t(* read_discrete_inputs)(uint8_t, rodbus_address_range_t, const char *, void *)
Authorize a Read Discrete Inputs request.
Definition: rodbus.h:1682
Callbacks received when reading coils or discrete inputs.
Definition: rodbus.h:1150
void(* on_complete)(rodbus_bit_value_iterator_t *, void *)
Invoked when the asynchronous operation completes successfully.
Definition: rodbus.h:1155
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1163
void * ctx
Context data.
Definition: rodbus.h:1165
void(* on_failure)(rodbus_request_error_t, void *)
Invoked when the asynchronous operation fails.
Definition: rodbus.h:1160
Bit value and its address.
Definition: rodbus.h:272
bool value
Value of the bit.
Definition: rodbus.h:276
uint16_t index
Address of the bit.
Definition: rodbus.h:274
Callback for monitoring the state of a TCP/TLS connection state.
Definition: rodbus.h:1041
void(* on_change)(rodbus_client_state_t, void *)
Called when the client state changed.
Definition: rodbus.h:1046
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1049
void * ctx
Context data.
Definition: rodbus.h:1051
Callback used to access the internal database while it is locked.
Definition: rodbus.h:1447
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1455
void(* callback)(rodbus_database_t *, void *)
callback function
Definition: rodbus.h:1452
void * ctx
Context data.
Definition: rodbus.h:1457
Controls the decoding of transmitted and received data at the application, frame, and physical layer.
Definition: rodbus.h:223
rodbus_app_decode_level_t app
Controls decoding of the application layer (PDU)
Definition: rodbus.h:225
rodbus_frame_decode_level_t frame
Controls decoding of frames (MBAP / Serial PDU)
Definition: rodbus.h:227
rodbus_phys_decode_level_t physical
Controls the logging of physical layer read/write.
Definition: rodbus.h:229
Logging interface that receives the log messages and writes them somewhere.
Definition: rodbus.h:917
void(* on_message)(rodbus_log_level_t, const char *, void *)
Called when a log message was received and should be logged.
Definition: rodbus.h:923
void * ctx
Context data.
Definition: rodbus.h:928
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:926
Logging configuration options.
Definition: rodbus.h:879
bool print_module_info
optionally print the underlying Rust module information to the message string
Definition: rodbus.h:889
rodbus_time_format_t time_format
optional time format
Definition: rodbus.h:885
rodbus_log_output_format_t output_format
output formatting options
Definition: rodbus.h:883
rodbus_log_level_t level
logging level
Definition: rodbus.h:881
bool print_level
optionally print the log level as part to the message string
Definition: rodbus.h:887
Callback interface for receiving updates about the state of a serial port.
Definition: rodbus.h:1086
void(* on_change)(rodbus_port_state_t, void *)
Invoked when the serial port changes state.
Definition: rodbus.h:1091
void * ctx
Context data.
Definition: rodbus.h:1096
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1094
Callbacks received when reading holding or input registers.
Definition: rodbus.h:1172
void(* on_complete)(rodbus_register_value_iterator_t *, void *)
Invoked when the asynchronous operation completes successfully.
Definition: rodbus.h:1177
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1185
void * ctx
Context data.
Definition: rodbus.h:1187
void(* on_failure)(rodbus_request_error_t, void *)
Invoked when the asynchronous operation fails.
Definition: rodbus.h:1182
Register value and its address.
Definition: rodbus.h:299
uint16_t index
Address of the register.
Definition: rodbus.h:301
uint16_t value
Value of the register.
Definition: rodbus.h:303
Address and timeout parameters for requests.
Definition: rodbus.h:481
uint64_t timeout
Response timeout for the request. It covers sending the request and receiving the response....
Definition: rodbus.h:486
uint8_t unit_id
Modbus address for the request.
Definition: rodbus.h:483
Retry strategy configuration.
Definition: rodbus.h:769
uint64_t max_delay
Maximum delay between two retries.
Definition: rodbus.h:775
uint64_t min_delay
Minimum delay between two retries.
Definition: rodbus.h:772
Runtime configuration.
Definition: rodbus.h:327
uint16_t num_core_threads
Number of runtime threads to spawn. For a guess of the number of CPU cores, use 0.
Definition: rodbus.h:331
Serial port settings.
Definition: rodbus.h:671
rodbus_stop_bits_t stop_bits
Number of bits to use to signal the end of a character.
Definition: rodbus.h:683
rodbus_data_bits_t data_bits
Number of bits used to represent a character sent on the line.
Definition: rodbus.h:677
rodbus_flow_control_t flow_control
Type of signalling to use for controlling data transfer.
Definition: rodbus.h:679
uint32_t baud_rate
Baud rate (in symbols-per-second)
Definition: rodbus.h:675
rodbus_parity_t parity
Type of parity to use for error checking.
Definition: rodbus.h:681
TLS client configuration.
Definition: rodbus.h:951
bool allow_server_name_wildcard
If set to true, a '*' may be used for rodbus_tls_client_config_t::dns_name to bypass server name vali...
Definition: rodbus.h:971
rodbus_certificate_mode_t certificate_mode
Certificate validation mode.
Definition: rodbus.h:969
const char * peer_cert_path
Path to the PEM-encoded trusted CA certificate(s) in RODBUS_CERTIFICATE_MODE_AUTHORITY_BASED mode,...
Definition: rodbus.h:955
rodbus_min_tls_version_t min_tls_version
Minimum TLS version allowed.
Definition: rodbus.h:967
const char * dns_name
Name expected to be in the presented certificate (only in RODBUS_CERTIFICATE_MODE_AUTHORITY_BASED)
Definition: rodbus.h:953
const char * private_key_path
Path to the PEM-encoded private key.
Definition: rodbus.h:959
const char * local_cert_path
Path to the PEM-encoded local certificate.
Definition: rodbus.h:957
const char * password
Optional password if the private key file is encrypted.
Definition: rodbus.h:965
TLS server configuration.
Definition: rodbus.h:1598
const char * password
Optional password if the private key file is encrypted.
Definition: rodbus.h:1610
rodbus_certificate_mode_t certificate_mode
Certificate validation mode.
Definition: rodbus.h:1614
const char * private_key_path
Path to the PEM-encoded private key.
Definition: rodbus.h:1604
const char * local_cert_path
Path to the PEM-encoded local certificate.
Definition: rodbus.h:1602
const char * peer_cert_path
Path to the PEM-encoded trusted CA certificate(s) in RODBUS_CERTIFICATE_MODE_AUTHORITY_BASED mode,...
Definition: rodbus.h:1600
rodbus_min_tls_version_t min_tls_version
Minimum TLS version allowed.
Definition: rodbus.h:1612
Callback methods received from asynchronous write operations.
Definition: rodbus.h:1192
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1205
void * ctx
Context data.
Definition: rodbus.h:1207
void(* on_failure)(rodbus_request_error_t, void *)
Invoked when the asynchronous operation fails.
Definition: rodbus.h:1202
void(* on_complete)(rodbus_nothing_t, void *)
Invoked when the asynchronous operation completes successfully.
Definition: rodbus.h:1197
Interface used to handle write requests received from the client.
Definition: rodbus.h:1534
rodbus_write_result_t(* write_single_coil)(uint16_t, bool, rodbus_database_t *, void *)
Write a single coil received from the client.
Definition: rodbus.h:1542
void * ctx
Context data.
Definition: rodbus.h:1571
rodbus_write_result_t(* write_multiple_registers)(uint16_t, rodbus_register_value_iterator_t *, rodbus_database_t *, void *)
Write multiple registers received from the client.
Definition: rodbus.h:1566
rodbus_write_result_t(* write_multiple_coils)(uint16_t, rodbus_bit_value_iterator_t *, rodbus_database_t *, void *)
Write multiple coils received from the client.
Definition: rodbus.h:1558
rodbus_write_result_t(* write_single_register)(uint16_t, uint16_t, rodbus_database_t *, void *)
write a single register received from the client
Definition: rodbus.h:1550
void(* on_destroy)(void *arg)
Callback when the underlying owner doesn't need the interface anymore.
Definition: rodbus.h:1569
Describes to the server if a write operation was successful or not.
Definition: rodbus.h:1468
uint8_t raw_exception
Raw exception value when rodbus_write_result_t::exception field is RODBUS_MODBUS_EXCEPTION_UNKNOWN.
Definition: rodbus.h:1474
rodbus_modbus_exception_t exception
Exception enumeration. If RODBUS_MODBUS_EXCEPTION_UNKNOWN, look at the raw value.
Definition: rodbus.h:1472
bool success
true if the operation was successful, false otherwise. Error details found in the exception field.
Definition: rodbus.h:1470