25 #include "unit-test.h" 33 int main(
int argc,
char*argv[])
45 if (strcmp(argv[1],
"tcp") == 0) {
47 }
else if (strcmp(argv[1],
"tcppi") == 0) {
49 }
else if (strcmp(argv[1],
"rtu") == 0) {
52 printf(
"Usage:\n %s [tcp|tcppi|rtu] - Modbus server for unit testing\n\n", argv[0]);
60 if (use_backend ==
TCP) {
63 }
else if (use_backend ==
TCP_PI) {
76 UT_BITS_ADDRESS + UT_BITS_NB,
77 UT_INPUT_BITS_ADDRESS + UT_INPUT_BITS_NB,
78 UT_REGISTERS_ADDRESS + UT_REGISTERS_NB,
79 UT_INPUT_REGISTERS_ADDRESS + UT_INPUT_REGISTERS_NB);
80 if (mb_mapping == NULL) {
81 fprintf(stderr,
"Failed to allocate the mapping: %s\n",
92 UT_INPUT_BITS_ADDRESS, UT_INPUT_BITS_NB,
96 for (i=0; i < UT_INPUT_REGISTERS_NB; i++) {
98 UT_INPUT_REGISTERS_TAB[i];;
101 if (use_backend ==
TCP) {
104 }
else if (use_backend ==
TCP_PI) {
124 if (query[header_length] == 0x03) {
126 == UT_REGISTERS_NB_SPECIAL) {
127 printf(
"Set an incorrect number of values\n");
129 UT_REGISTERS_NB_SPECIAL - 1);
131 == UT_REGISTERS_ADDRESS_SPECIAL) {
132 printf(
"Reply to this special register address by an exception\n");
147 if (use_backend ==
TCP) {
modbus_mapping_t * modbus_mapping_new(int nb_coil_status, int nb_input_status, int nb_holding_registers, int nb_input_registers)
int modbus_reply_exception(modbus_t *ctx, const uint8_t *req, unsigned int exception_code)
#define MODBUS_RTU_MAX_ADU_LENGTH
int main(int argc, char *argv[])
int modbus_receive(modbus_t *ctx, uint8_t *req)
#define MODBUS_TCP_MAX_ADU_LENGTH
void modbus_free(modbus_t *ctx)
#define MODBUS_SET_INT16_TO_INT8(tab_int8, index, value)
void modbus_set_debug(modbus_t *ctx, int boolean)
int modbus_set_slave(modbus_t *ctx, int slave)
int modbus_reply(modbus_t *ctx, const uint8_t *req, int req_length, modbus_mapping_t *mb_mapping)
int modbus_tcp_accept(modbus_t *ctx, int *socket)
#define MODBUS_GET_INT16_FROM_INT8(tab_int8, index)
int modbus_tcp_pi_accept(modbus_t *ctx, int *socket)
int modbus_tcp_listen(modbus_t *ctx, int nb_connection)
const char * modbus_strerror(int errnum)
int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection)
void modbus_set_bits_from_bytes(uint8_t *dest, int index, unsigned int nb_bits, const uint8_t *tab_byte)
uint16_t * tab_input_registers
int modbus_get_header_length(modbus_t *ctx)
void modbus_mapping_free(modbus_mapping_t *mb_mapping)
modbus_t * modbus_new_rtu(const char *device, int baud, char parity, int data_bit, int stop_bit)
modbus_t * modbus_new_tcp_pi(const char *node, const char *service)
int modbus_connect(modbus_t *ctx)
modbus_mapping_t * mb_mapping
modbus_t * modbus_new_tcp(const char *ip_address, int port)