Formatting
This commit is contained in:
parent
c654babb52
commit
98814d2a66
@ -23,8 +23,8 @@ int client_connection = -1;
|
|||||||
|
|
||||||
void* connect_tcp(const char* address, const char* port) {
|
void* connect_tcp(const char* address, const char* port) {
|
||||||
struct addrinfo ainfo = {0};
|
struct addrinfo ainfo = {0};
|
||||||
struct addrinfo *results;
|
struct addrinfo* results;
|
||||||
struct addrinfo *rp;
|
struct addrinfo* rp;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
ainfo.ai_family = AF_INET;
|
ainfo.ai_family = AF_INET;
|
||||||
@ -68,8 +68,8 @@ void close_server_on_exit(int sig) {
|
|||||||
|
|
||||||
int create_tcp_server(const char* address, const char* port) {
|
int create_tcp_server(const char* address, const char* port) {
|
||||||
struct addrinfo ainfo = {0};
|
struct addrinfo ainfo = {0};
|
||||||
struct addrinfo *results;
|
struct addrinfo* results;
|
||||||
struct addrinfo *rp;
|
struct addrinfo* rp;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
|
|
||||||
ainfo.ai_family = AF_INET;
|
ainfo.ai_family = AF_INET;
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
nmbs_bitfield server_coils = {0};
|
nmbs_bitfield server_coils = {0};
|
||||||
uint16_t server_registers[REGS_ADDR_MAX] = {0};
|
uint16_t server_registers[REGS_ADDR_MAX] = {0};
|
||||||
|
|
||||||
nmbs_error handle_read_coils(uint16_t address, uint16_t quantity, nmbs_bitfield coils_out, void *arg) {
|
nmbs_error handle_read_coils(uint16_t address, uint16_t quantity, nmbs_bitfield coils_out, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
|
||||||
if (address + quantity > COILS_ADDR_MAX + 1)
|
if (address + quantity > COILS_ADDR_MAX + 1)
|
||||||
@ -43,7 +43,7 @@ nmbs_error handle_read_coils(uint16_t address, uint16_t quantity, nmbs_bitfield
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error handle_write_multiple_coils(uint16_t address, uint16_t quantity, const nmbs_bitfield coils, void *arg) {
|
nmbs_error handle_write_multiple_coils(uint16_t address, uint16_t quantity, const nmbs_bitfield coils, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
|
||||||
if (address + quantity > COILS_ADDR_MAX + 1)
|
if (address + quantity > COILS_ADDR_MAX + 1)
|
||||||
@ -58,7 +58,7 @@ nmbs_error handle_write_multiple_coils(uint16_t address, uint16_t quantity, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error handler_read_holding_registers(uint16_t address, uint16_t quantity, uint16_t* registers_out, void *arg) {
|
nmbs_error handler_read_holding_registers(uint16_t address, uint16_t quantity, uint16_t* registers_out, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
|
||||||
if (address + quantity > REGS_ADDR_MAX + 1)
|
if (address + quantity > REGS_ADDR_MAX + 1)
|
||||||
@ -72,7 +72,7 @@ nmbs_error handler_read_holding_registers(uint16_t address, uint16_t quantity, u
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error handle_write_multiple_registers(uint16_t address, uint16_t quantity, const uint16_t* registers, void *arg) {
|
nmbs_error handle_write_multiple_registers(uint16_t address, uint16_t quantity, const uint16_t* registers, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
|
||||||
if (address + quantity > REGS_ADDR_MAX + 1)
|
if (address + quantity > REGS_ADDR_MAX + 1)
|
||||||
|
|||||||
17
nanomodbus.c
17
nanomodbus.c
@ -50,43 +50,44 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static uint8_t get_1(nmbs_t *nmbs) {
|
static uint8_t get_1(nmbs_t* nmbs) {
|
||||||
uint8_t result = nmbs->msg.buf[nmbs->msg.buf_idx];
|
uint8_t result = nmbs->msg.buf[nmbs->msg.buf_idx];
|
||||||
nmbs->msg.buf_idx++;
|
nmbs->msg.buf_idx++;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void put_1(nmbs_t *nmbs, uint8_t data) {
|
static void put_1(nmbs_t* nmbs, uint8_t data) {
|
||||||
nmbs->msg.buf[nmbs->msg.buf_idx] = data;
|
nmbs->msg.buf[nmbs->msg.buf_idx] = data;
|
||||||
nmbs->msg.buf_idx++;
|
nmbs->msg.buf_idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void discard_1(nmbs_t *nmbs) {
|
static void discard_1(nmbs_t* nmbs) {
|
||||||
nmbs->msg.buf_idx++;
|
nmbs->msg.buf_idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NMBS_BIG_ENDIAN
|
#ifdef NMBS_BIG_ENDIAN
|
||||||
|
|
||||||
static uint16_t get_2(nmbs_t *m) {
|
static uint16_t get_2(nmbs_t* m) {
|
||||||
uint16_t result = (*(uint16_t*) (m->msg.buf + m->msg.buf_idx));
|
uint16_t result = (*(uint16_t*) (m->msg.buf + m->msg.buf_idx));
|
||||||
m->msg.buf_idx += 2;
|
m->msg.buf_idx += 2;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void put_2(nmbs_t *m, uint16_t w) {
|
static void put_2(nmbs_t* m, uint16_t w) {
|
||||||
(*(uint16_t*) (m->msg.buf + m->msg.buf_idx)) = w;
|
(*(uint16_t*) (m->msg.buf + m->msg.buf_idx)) = w;
|
||||||
m->msg.buf_idx += 2;
|
m->msg.buf_idx += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static uint16_t get_2(nmbs_t *nmbs) {
|
static uint16_t get_2(nmbs_t* nmbs) {
|
||||||
uint16_t result = ((uint16_t) (nmbs->msg.buf[nmbs->msg.buf_idx + 1])) | (((uint16_t) nmbs->msg.buf[nmbs->msg.buf_idx] << 8));
|
uint16_t result =
|
||||||
|
((uint16_t) (nmbs->msg.buf[nmbs->msg.buf_idx + 1])) | (((uint16_t) nmbs->msg.buf[nmbs->msg.buf_idx] << 8));
|
||||||
nmbs->msg.buf_idx += 2;
|
nmbs->msg.buf_idx += 2;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void put_2(nmbs_t *nmbs, uint16_t data) {
|
static void put_2(nmbs_t* nmbs, uint16_t data) {
|
||||||
nmbs->msg.buf[nmbs->msg.buf_idx] = ((uint8_t) ((((uint16_t) (data)) & 0xFF00) >> 8));
|
nmbs->msg.buf[nmbs->msg.buf_idx] = ((uint8_t) ((((uint16_t) (data)) & 0xFF00) >> 8));
|
||||||
nmbs->msg.buf[nmbs->msg.buf_idx + 1] = ((uint8_t) (((uint16_t) (data)) & 0x00FF));
|
nmbs->msg.buf[nmbs->msg.buf_idx + 1] = ((uint8_t) (((uint16_t) (data)) & 0x00FF));
|
||||||
nmbs->msg.buf_idx += 2;
|
nmbs->msg.buf_idx += 2;
|
||||||
|
|||||||
@ -252,7 +252,8 @@ nmbs_error nmbs_server_create(nmbs_t* nmbs, uint8_t address_rtu, const nmbs_plat
|
|||||||
|
|
||||||
/** Set the request/response timeout.
|
/** Set the request/response timeout.
|
||||||
* If the target instance is a server, sets the timeout of the nmbs_server_poll() function.
|
* If the target instance is a server, sets the timeout of the nmbs_server_poll() function.
|
||||||
* If the target instance is a client, sets the response timeout after sending a request. In case of timeout, the called method will return NMBS_ERROR_TIMEOUT.
|
* If the target instance is a client, sets the response timeout after sending a request. In case of timeout,
|
||||||
|
* the called method will return NMBS_ERROR_TIMEOUT.
|
||||||
* @param nmbs pointer to the nmbs_t instance
|
* @param nmbs pointer to the nmbs_t instance
|
||||||
* @param timeout_ms timeout in milliseconds. If < 0, the timeout is disabled.
|
* @param timeout_ms timeout in milliseconds. If < 0, the timeout is disabled.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -155,7 +155,7 @@ void test_server_receive_base(nmbs_transport transport) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error read_discrete(uint16_t address, uint16_t quantity, nmbs_bitfield coils_out, void *arg) {
|
nmbs_error read_discrete(uint16_t address, uint16_t quantity, nmbs_bitfield coils_out, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
@ -324,7 +324,7 @@ void test_fc2(nmbs_transport transport) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error read_registers(uint16_t address, uint16_t quantity, uint16_t* registers_out, void *arg) {
|
nmbs_error read_registers(uint16_t address, uint16_t quantity, uint16_t* registers_out, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
@ -456,7 +456,7 @@ void test_fc4(nmbs_transport transport) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error write_coil(uint16_t address, bool value, void *arg) {
|
nmbs_error write_coil(uint16_t address, bool value, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
@ -523,7 +523,7 @@ void test_fc5(nmbs_transport transport) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error write_register(uint16_t address, uint16_t value, void *arg) {
|
nmbs_error write_register(uint16_t address, uint16_t value, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
@ -583,7 +583,7 @@ void test_fc6(nmbs_transport transport) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error write_coils(uint16_t address, uint16_t quantity, const nmbs_bitfield coils, void *arg) {
|
nmbs_error write_coils(uint16_t address, uint16_t quantity, const nmbs_bitfield coils, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
@ -699,7 +699,7 @@ void test_fc15(nmbs_transport transport) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error write_registers(uint16_t address, uint16_t quantity, const uint16_t* registers, void *arg) {
|
nmbs_error write_registers(uint16_t address, uint16_t quantity, const uint16_t* registers, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user