diff --git a/src/modbus-rtu.c b/src/modbus-rtu.c index 58a2c05..430a0e1 100644 --- a/src/modbus-rtu.c +++ b/src/modbus-rtu.c @@ -171,7 +171,8 @@ static int _modbus_rtu_send_msg_pre(uint8_t *req, int req_length) * while win32_ser_read() only consumes the receive buffer. */ -static void win32_ser_init(struct win32_ser *ws) { +static void win32_ser_init(struct win32_ser *ws) +{ /* Clear everything */ memset(ws, 0x00, sizeof(struct win32_ser)); @@ -181,7 +182,8 @@ static void win32_ser_init(struct win32_ser *ws) { /* FIXME Try to remove length_to_read -> max_len argument, only used by win32 */ static int win32_ser_select(struct win32_ser *ws, int max_len, - const struct timeval *tv) { + const struct timeval *tv) +{ COMMTIMEOUTS comm_to; unsigned int msec = 0; @@ -231,7 +233,8 @@ static int win32_ser_select(struct win32_ser *ws, int max_len, } static int win32_ser_read(struct win32_ser *ws, uint8_t *p_msg, - unsigned int max_len) { + unsigned int max_len) +{ unsigned int n = ws->n_bytes; if (max_len < n) { @@ -594,7 +597,7 @@ static int _modbus_rtu_connect(modbus_t *ctx) } /* Save */ - tcgetattr(ctx->s, &(ctx_rtu->old_tios)); + tcgetattr(ctx->s, &ctx_rtu->old_tios); memset(&tios, 0, sizeof(struct termios)); @@ -1042,7 +1045,7 @@ static void _modbus_rtu_close(modbus_t *ctx) } #else if (ctx->s != -1) { - tcsetattr(ctx->s, TCSANOW, &(ctx_rtu->old_tios)); + tcsetattr(ctx->s, TCSANOW, &ctx_rtu->old_tios); close(ctx->s); ctx->s = -1; } @@ -1061,11 +1064,11 @@ static int _modbus_rtu_flush(modbus_t *ctx) } static int _modbus_rtu_select(modbus_t *ctx, fd_set *rset, - struct timeval *tv, int length_to_read) + struct timeval *tv, int length_to_read) { int s_rc; #if defined(_WIN32) - s_rc = win32_ser_select(&(((modbus_rtu_t*)ctx->backend_data)->w_ser), + s_rc = win32_ser_select(&((modbus_rtu_t *)ctx->backend_data)->w_ser, length_to_read, tv); if (s_rc == 0) { errno = ETIMEDOUT; @@ -1135,7 +1138,7 @@ modbus_t* modbus_new_rtu(const char *device, modbus_rtu_t *ctx_rtu; /* Check device argument */ - if (device == NULL || (*device) == 0) { + if (device == NULL || *device == 0) { fprintf(stderr, "The device string is empty\n"); errno = EINVAL; return NULL; @@ -1148,15 +1151,15 @@ modbus_t* modbus_new_rtu(const char *device, return NULL; } - ctx = (modbus_t *) malloc(sizeof(modbus_t)); + ctx = (modbus_t *)malloc(sizeof(modbus_t)); _modbus_init_common(ctx); ctx->backend = &_modbus_rtu_backend; - ctx->backend_data = (modbus_rtu_t *) malloc(sizeof(modbus_rtu_t)); + ctx->backend_data = (modbus_rtu_t *)malloc(sizeof(modbus_rtu_t)); ctx_rtu = (modbus_rtu_t *)ctx->backend_data; ctx_rtu->device = NULL; /* Device name and \0 */ - ctx_rtu->device = (char *) malloc((strlen(device) + 1) * sizeof(char)); + ctx_rtu->device = (char *)malloc((strlen(device) + 1) * sizeof(char)); strcpy(ctx_rtu->device, device); ctx_rtu->baud = baud; diff --git a/src/modbus-rtu.h b/src/modbus-rtu.h index 50a3e00..bb0b913 100644 --- a/src/modbus-rtu.h +++ b/src/modbus-rtu.h @@ -17,7 +17,7 @@ MODBUS_BEGIN_DECLS #define MODBUS_RTU_MAX_ADU_LENGTH 256 MODBUS_API modbus_t* modbus_new_rtu(const char *device, int baud, char parity, - int data_bit, int stop_bit); + int data_bit, int stop_bit); #define MODBUS_RTU_RS232 0 #define MODBUS_RTU_RS485 1 diff --git a/src/modbus-tcp.c b/src/modbus-tcp.c index 2f5c1ec..3fd0ebe 100644 --- a/src/modbus-tcp.c +++ b/src/modbus-tcp.c @@ -162,7 +162,7 @@ static ssize_t _modbus_tcp_send(modbus_t *ctx, const uint8_t *req, int req_lengt Requests not to send SIGPIPE on errors on stream oriented sockets when the other end breaks the connection. The EPIPE error is still returned. */ - return send(ctx->s, (const char*)req, req_length, MSG_NOSIGNAL); + return send(ctx->s, (const char *)req, req_length, MSG_NOSIGNAL); } static int _modbus_tcp_receive(modbus_t *ctx, uint8_t *req) { @@ -497,7 +497,7 @@ int modbus_tcp_listen(modbus_t *ctx, int nb_connection) yes = 1; if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR, - (char *) &yes, sizeof(yes)) == -1) { + (char *)&yes, sizeof(yes)) == -1) { close(new_s); return -1; } @@ -589,7 +589,7 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection) int s; s = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, - ai_ptr->ai_protocol); + ai_ptr->ai_protocol); if (s < 0) { if (ctx->debug) { perror("socket"); @@ -598,7 +598,7 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection) } else { int yes = 1; rc = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, - (void *) &yes, sizeof (yes)); + (void *)&yes, sizeof (yes)); if (rc != 0) { close(s); if (ctx->debug) { @@ -793,15 +793,15 @@ modbus_t* modbus_new_tcp(const char *ip, int port) } #endif - ctx = (modbus_t *) malloc(sizeof(modbus_t)); + ctx = (modbus_t *)malloc(sizeof(modbus_t)); _modbus_init_common(ctx); /* Could be changed after to reach a remote serial Modbus device */ ctx->slave = MODBUS_TCP_SLAVE; - ctx->backend = &(_modbus_tcp_backend); + ctx->backend = &_modbus_tcp_backend; - ctx->backend_data = (modbus_tcp_t *) malloc(sizeof(modbus_tcp_t)); + ctx->backend_data = (modbus_tcp_t *)malloc(sizeof(modbus_tcp_t)); ctx_tcp = (modbus_tcp_t *)ctx->backend_data; if (ip != NULL) { @@ -837,15 +837,15 @@ modbus_t* modbus_new_tcp_pi(const char *node, const char *service) size_t dest_size; size_t ret_size; - ctx = (modbus_t *) malloc(sizeof(modbus_t)); + ctx = (modbus_t *)malloc(sizeof(modbus_t)); _modbus_init_common(ctx); /* Could be changed after to reach a remote serial Modbus device */ ctx->slave = MODBUS_TCP_SLAVE; - ctx->backend = &(_modbus_tcp_pi_backend); + ctx->backend = &_modbus_tcp_pi_backend; - ctx->backend_data = (modbus_tcp_pi_t *) malloc(sizeof(modbus_tcp_pi_t)); + ctx->backend_data = (modbus_tcp_pi_t *)malloc(sizeof(modbus_tcp_pi_t)); ctx_tcp_pi = (modbus_tcp_pi_t *)ctx->backend_data; if (node == NULL) {