modbusd
modbus master daemon
|
modbus tcp functions More...
#include "mb.h"
Functions | |
bool | mbtcp_init_handle (mbtcp_handle_s **ptr_handle, char *ip, char *port) |
Init mbtcp handle (to hashtable) and try to connect. More... | |
bool | mbtcp_get_handle (mbtcp_handle_s **ptr_handle, char *ip, char *port) |
Get mbtcp handle from hashtable. More... | |
void | mbtcp_list_handles () |
List all handles in mbtcp hash table. More... | |
bool | mbtcp_do_connect (mbtcp_handle_s *handle, char **reason) |
Connect to mbtcp slave via mbtcp hashed handle. More... | |
bool | mbtcp_get_connection_status (mbtcp_handle_s *handle) |
Get mbtcp handle's connection status. More... | |
char * | mbtcp_cmd_hanlder (uint8_t fc, cJSON *req, mbtcp_fc ptr_handler) |
Generic mbtcp command handler. More... | |
char * | mbtcp_set_response_timeout (char *tid, long timeout) |
Set mbtcp response timeout in usec. More... | |
char * | mbtcp_get_response_timeout (char *tid) |
Get mbtcp response timeout. More... | |
char * | mbtcp_read_bit_req_fn (uint8_t fc, mbtcp_handle_s *handle, cJSON *req) |
Help function. More... | |
char * | mbtcp_read_reg_req_fn (uint8_t fc, mbtcp_handle_s *handle, cJSON *req) |
Help function. More... | |
char * | mbtcp_single_write_req_fn (uint8_t fc, mbtcp_handle_s *handle, cJSON *req) |
Help function. More... | |
char * | mbtcp_multi_write_req_fn (uint8_t fc, mbtcp_handle_s *handle, cJSON *req) |
Help function. More... | |
Variables | |
int | enable_syslog |
long | tcp_conn_timeout_usec = 200000 |
modbus tcp functions
Generic mbtcp command handler.
fc | function code |
req | cJSON request object. |
ptr_handler | Function pointer to modbus tcp fc handler. |
References BEGIN, mbtcp_handle_s::ctx, enable_syslog, json_get_char(), json_get_int(), LOG, and set_modbus_fail_resp_str().
Referenced by main().
bool mbtcp_do_connect | ( | mbtcp_handle_s * | handle, |
char ** | reason | ||
) |
Connect to mbtcp slave via mbtcp hashed handle.
handle | Mbtcp handle. |
reason | Fail reason string. |
References BEGIN, mbtcp_handle_s::connected, mbtcp_handle_s::ctx, enable_syslog, ERR, mbtcp_key_s::ip, mbtcp_handle_s::key, LOG, and mbtcp_key_s::port.
Referenced by mbtcp_init_handle(), and test_init_tcp_handle_and_connect().
bool mbtcp_get_connection_status | ( | mbtcp_handle_s * | handle | ) |
Get mbtcp handle's connection status.
handle | Mbtcp handle. |
References BEGIN, mbtcp_handle_s::connected, enable_syslog, ERR, mbtcp_key_s::ip, mbtcp_handle_s::key, LOG, and mbtcp_key_s::port.
Referenced by test_init_tcp_handle_and_connect().
bool mbtcp_get_handle | ( | mbtcp_handle_s ** | ptr_handle, |
char * | ip, | ||
char * | port | ||
) |
Get mbtcp handle from hashtable.
ptr_handle | Pointer to mbtcp handle. |
ip | IP address string. |
port | Modbus TCP server port string or service name. |
References BEGIN, enable_syslog, ERR, HASH_FIND, mbtcp_key_s::ip, mbtcp_handle_s::key, LOG, and mbtcp_key_s::port.
Referenced by test_init_tcp_handle_and_connect().
char* mbtcp_get_response_timeout | ( | char * | tid | ) |
Get mbtcp response timeout.
tid | Transaction ID. |
References BEGIN, cJSON_AddNumberToObject, cJSON_AddStringToObject, cJSON_CreateObject(), cJSON_Delete(), cJSON_PrintUnformatted(), enable_syslog, END, LOG, and tcp_conn_timeout_usec.
Referenced by main().
bool mbtcp_init_handle | ( | mbtcp_handle_s ** | ptr_handle, |
char * | ip, | ||
char * | port | ||
) |
Init mbtcp handle (to hashtable) and try to connect.
ptr_handle | Pointer to mbtcp handle. |
ip | IP address string. |
port | Modbus TCP server port string. |
References BEGIN, mbtcp_handle_s::connected, mbtcp_handle_s::ctx, enable_syslog, ERR, HASH_ADD, mbtcp_key_s::ip, mbtcp_handle_s::key, LOG, mbtcp_do_connect(), mbtcp_key_s::port, and tcp_conn_timeout_usec.
Referenced by test_init_tcp_handle_and_connect().
void mbtcp_list_handles | ( | ) |
List all handles in mbtcp hash table.
References BEGIN, enable_syslog, END, mbtcp_handle_s::hh, mbtcp_key_s::ip, mbtcp_handle_s::key, LOG, UT_hash_handle::next, and mbtcp_key_s::port.
char* mbtcp_multi_write_req_fn | ( | uint8_t | fc, |
mbtcp_handle_s * | handle, | ||
cJSON * | req | ||
) |
Help function.
FC15, FC16 request handler
Function code 15 and 16 only.
handle | Mbtcp handle. |
req | cJSON request object. |
References BEGIN, cJSON_GetArrayItem(), cJSON_GetArraySize(), cJSON_GetObjectItem(), mbtcp_handle_s::ctx, enable_syslog, json_get_char(), json_get_int(), LOG, set_modbus_fail_resp_str(), set_modbus_fail_resp_str_with_errno(), set_modbus_success_resp_str(), and cJSON::valueint.
Referenced by main().
char* mbtcp_read_bit_req_fn | ( | uint8_t | fc, |
mbtcp_handle_s * | handle, | ||
cJSON * | req | ||
) |
Help function.
FC1, FC2 request handler
Function code 1 and 2 only.
handle | Mbtcp handle. |
req | cJSON request object. |
References BEGIN, cJSON_CreateUInt8Array(), mbtcp_handle_s::ctx, enable_syslog, json_get_char(), json_get_int(), LOG, set_modbus_fail_resp_str(), set_modbus_fail_resp_str_with_errno(), and set_modbus_success_resp_str_with_data().
Referenced by main().
char* mbtcp_read_reg_req_fn | ( | uint8_t | fc, |
mbtcp_handle_s * | handle, | ||
cJSON * | req | ||
) |
Help function.
FC3, FC4 request handler
Function code 3 and 4 only.
handle | Mbtcp handle. |
req | cJSON request object. |
References BEGIN, cJSON_CreateUInt16Array(), mbtcp_handle_s::ctx, enable_syslog, json_get_char(), json_get_int(), LOG, set_modbus_fail_resp_str(), set_modbus_fail_resp_str_with_errno(), and set_modbus_success_resp_str_with_data().
Referenced by main().
char* mbtcp_set_response_timeout | ( | char * | tid, |
long | timeout | ||
) |
Set mbtcp response timeout in usec.
tid | Transaction ID. |
timeout | Timeout in usec. |
References BEGIN, cJSON_AddStringToObject, cJSON_CreateObject(), cJSON_Delete(), cJSON_PrintUnformatted(), enable_syslog, END, LOG, and tcp_conn_timeout_usec.
Referenced by main().
char* mbtcp_single_write_req_fn | ( | uint8_t | fc, |
mbtcp_handle_s * | handle, | ||
cJSON * | req | ||
) |
Help function.
FC5, FC6 request handler
Function code 5 and 6 only.
handle | Mbtcp handle. |
req | cJSON request object. |
References BEGIN, mbtcp_handle_s::ctx, enable_syslog, json_get_char(), json_get_int(), set_modbus_fail_resp_str(), set_modbus_fail_resp_str_with_errno(), and set_modbus_success_resp_str().
Referenced by main().
int enable_syslog |
Referenced by main(), mbtcp_cmd_hanlder(), mbtcp_do_connect(), mbtcp_get_connection_status(), mbtcp_get_handle(), mbtcp_get_response_timeout(), mbtcp_init_handle(), mbtcp_list_handles(), mbtcp_multi_write_req_fn(), mbtcp_read_bit_req_fn(), mbtcp_read_reg_req_fn(), mbtcp_set_response_timeout(), mbtcp_single_write_req_fn(), test_init_tcp_handle_and_connect(), test_multiple_add_find(), and test_single_add_find().
long tcp_conn_timeout_usec = 200000 |
Referenced by mbtcp_get_response_timeout(), mbtcp_init_handle(), and mbtcp_set_response_timeout().