Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
debevv committed Dec 28, 2022
1 parent c654bab commit 98814d2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
8 changes: 4 additions & 4 deletions examples/linux/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ int client_connection = -1;

void* connect_tcp(const char* address, const char* port) {
struct addrinfo ainfo = {0};
struct addrinfo *results;
struct addrinfo *rp;
struct addrinfo* results;
struct addrinfo* rp;
int fd;

ainfo.ai_family = AF_INET;
Expand Down Expand Up @@ -68,8 +68,8 @@ void close_server_on_exit(int sig) {

int create_tcp_server(const char* address, const char* port) {
struct addrinfo ainfo = {0};
struct addrinfo *results;
struct addrinfo *rp;
struct addrinfo* results;
struct addrinfo* rp;
int fd = -1;

ainfo.ai_family = AF_INET;
Expand Down
8 changes: 4 additions & 4 deletions examples/linux/server-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
nmbs_bitfield server_coils = {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);

if (address + quantity > COILS_ADDR_MAX + 1)
Expand All @@ -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);

if (address + quantity > COILS_ADDR_MAX + 1)
Expand All @@ -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);

if (address + quantity > REGS_ADDR_MAX + 1)
Expand All @@ -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);

if (address + quantity > REGS_ADDR_MAX + 1)
Expand Down
17 changes: 9 additions & 8 deletions nanomodbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,43 +50,44 @@
#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];
nmbs->msg.buf_idx++;
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_idx++;
}

static void discard_1(nmbs_t *nmbs) {
static void discard_1(nmbs_t* nmbs) {
nmbs->msg.buf_idx++;
}

#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));
m->msg.buf_idx += 2;
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;
m->msg.buf_idx += 2;
}

#else

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));
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));
nmbs->msg.buf_idx += 2;
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 + 1] = ((uint8_t) (((uint16_t) (data)) & 0x00FF));
nmbs->msg.buf_idx += 2;
Expand Down
3 changes: 2 additions & 1 deletion nanomodbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ nmbs_error nmbs_server_create(nmbs_t* nmbs, uint8_t address_rtu, const nmbs_plat

/** 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 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 timeout_ms timeout in milliseconds. If < 0, the timeout is disabled.
*/
Expand Down
12 changes: 6 additions & 6 deletions tests/nanomodbus_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

if (address == 1)
Expand Down Expand Up @@ -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);

if (address == 1)
Expand Down Expand Up @@ -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);

if (address == 1)
Expand Down Expand Up @@ -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);

if (address == 1)
Expand Down Expand Up @@ -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);

if (address == 1)
Expand Down Expand Up @@ -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);

if (address == 1)
Expand Down

0 comments on commit 98814d2

Please sign in to comment.