Commit 9e6120058841fe6c096776441f3eba63b588fb74
Committed by
Stéphane Raimbault
1 parent
09807f14
Fix some coding style nitpicks
Signed-off-by: Michael Heimpold <mhei@heimpold.de>
Showing
3 changed files
with
25 additions
and
22 deletions
src/modbus-rtu.c
| ... | ... | @@ -171,7 +171,8 @@ static int _modbus_rtu_send_msg_pre(uint8_t *req, int req_length) |
| 171 | 171 | * while win32_ser_read() only consumes the receive buffer. |
| 172 | 172 | */ |
| 173 | 173 | |
| 174 | -static void win32_ser_init(struct win32_ser *ws) { | |
| 174 | +static void win32_ser_init(struct win32_ser *ws) | |
| 175 | +{ | |
| 175 | 176 | /* Clear everything */ |
| 176 | 177 | memset(ws, 0x00, sizeof(struct win32_ser)); |
| 177 | 178 | |
| ... | ... | @@ -181,7 +182,8 @@ static void win32_ser_init(struct win32_ser *ws) { |
| 181 | 182 | |
| 182 | 183 | /* FIXME Try to remove length_to_read -> max_len argument, only used by win32 */ |
| 183 | 184 | static int win32_ser_select(struct win32_ser *ws, int max_len, |
| 184 | - const struct timeval *tv) { | |
| 185 | + const struct timeval *tv) | |
| 186 | +{ | |
| 185 | 187 | COMMTIMEOUTS comm_to; |
| 186 | 188 | unsigned int msec = 0; |
| 187 | 189 | |
| ... | ... | @@ -231,7 +233,8 @@ static int win32_ser_select(struct win32_ser *ws, int max_len, |
| 231 | 233 | } |
| 232 | 234 | |
| 233 | 235 | static int win32_ser_read(struct win32_ser *ws, uint8_t *p_msg, |
| 234 | - unsigned int max_len) { | |
| 236 | + unsigned int max_len) | |
| 237 | +{ | |
| 235 | 238 | unsigned int n = ws->n_bytes; |
| 236 | 239 | |
| 237 | 240 | if (max_len < n) { |
| ... | ... | @@ -594,7 +597,7 @@ static int _modbus_rtu_connect(modbus_t *ctx) |
| 594 | 597 | } |
| 595 | 598 | |
| 596 | 599 | /* Save */ |
| 597 | - tcgetattr(ctx->s, &(ctx_rtu->old_tios)); | |
| 600 | + tcgetattr(ctx->s, &ctx_rtu->old_tios); | |
| 598 | 601 | |
| 599 | 602 | memset(&tios, 0, sizeof(struct termios)); |
| 600 | 603 | |
| ... | ... | @@ -1042,7 +1045,7 @@ static void _modbus_rtu_close(modbus_t *ctx) |
| 1042 | 1045 | } |
| 1043 | 1046 | #else |
| 1044 | 1047 | if (ctx->s != -1) { |
| 1045 | - tcsetattr(ctx->s, TCSANOW, &(ctx_rtu->old_tios)); | |
| 1048 | + tcsetattr(ctx->s, TCSANOW, &ctx_rtu->old_tios); | |
| 1046 | 1049 | close(ctx->s); |
| 1047 | 1050 | ctx->s = -1; |
| 1048 | 1051 | } |
| ... | ... | @@ -1061,11 +1064,11 @@ static int _modbus_rtu_flush(modbus_t *ctx) |
| 1061 | 1064 | } |
| 1062 | 1065 | |
| 1063 | 1066 | static int _modbus_rtu_select(modbus_t *ctx, fd_set *rset, |
| 1064 | - struct timeval *tv, int length_to_read) | |
| 1067 | + struct timeval *tv, int length_to_read) | |
| 1065 | 1068 | { |
| 1066 | 1069 | int s_rc; |
| 1067 | 1070 | #if defined(_WIN32) |
| 1068 | - s_rc = win32_ser_select(&(((modbus_rtu_t*)ctx->backend_data)->w_ser), | |
| 1071 | + s_rc = win32_ser_select(&((modbus_rtu_t *)ctx->backend_data)->w_ser, | |
| 1069 | 1072 | length_to_read, tv); |
| 1070 | 1073 | if (s_rc == 0) { |
| 1071 | 1074 | errno = ETIMEDOUT; |
| ... | ... | @@ -1135,7 +1138,7 @@ modbus_t* modbus_new_rtu(const char *device, |
| 1135 | 1138 | modbus_rtu_t *ctx_rtu; |
| 1136 | 1139 | |
| 1137 | 1140 | /* Check device argument */ |
| 1138 | - if (device == NULL || (*device) == 0) { | |
| 1141 | + if (device == NULL || *device == 0) { | |
| 1139 | 1142 | fprintf(stderr, "The device string is empty\n"); |
| 1140 | 1143 | errno = EINVAL; |
| 1141 | 1144 | return NULL; |
| ... | ... | @@ -1148,15 +1151,15 @@ modbus_t* modbus_new_rtu(const char *device, |
| 1148 | 1151 | return NULL; |
| 1149 | 1152 | } |
| 1150 | 1153 | |
| 1151 | - ctx = (modbus_t *) malloc(sizeof(modbus_t)); | |
| 1154 | + ctx = (modbus_t *)malloc(sizeof(modbus_t)); | |
| 1152 | 1155 | _modbus_init_common(ctx); |
| 1153 | 1156 | ctx->backend = &_modbus_rtu_backend; |
| 1154 | - ctx->backend_data = (modbus_rtu_t *) malloc(sizeof(modbus_rtu_t)); | |
| 1157 | + ctx->backend_data = (modbus_rtu_t *)malloc(sizeof(modbus_rtu_t)); | |
| 1155 | 1158 | ctx_rtu = (modbus_rtu_t *)ctx->backend_data; |
| 1156 | 1159 | ctx_rtu->device = NULL; |
| 1157 | 1160 | |
| 1158 | 1161 | /* Device name and \0 */ |
| 1159 | - ctx_rtu->device = (char *) malloc((strlen(device) + 1) * sizeof(char)); | |
| 1162 | + ctx_rtu->device = (char *)malloc((strlen(device) + 1) * sizeof(char)); | |
| 1160 | 1163 | strcpy(ctx_rtu->device, device); |
| 1161 | 1164 | |
| 1162 | 1165 | ctx_rtu->baud = baud; | ... | ... |
src/modbus-rtu.h
| ... | ... | @@ -17,7 +17,7 @@ MODBUS_BEGIN_DECLS |
| 17 | 17 | #define MODBUS_RTU_MAX_ADU_LENGTH 256 |
| 18 | 18 | |
| 19 | 19 | MODBUS_API modbus_t* modbus_new_rtu(const char *device, int baud, char parity, |
| 20 | - int data_bit, int stop_bit); | |
| 20 | + int data_bit, int stop_bit); | |
| 21 | 21 | |
| 22 | 22 | #define MODBUS_RTU_RS232 0 |
| 23 | 23 | #define MODBUS_RTU_RS485 1 | ... | ... |
src/modbus-tcp.c
| ... | ... | @@ -162,7 +162,7 @@ static ssize_t _modbus_tcp_send(modbus_t *ctx, const uint8_t *req, int req_lengt |
| 162 | 162 | Requests not to send SIGPIPE on errors on stream oriented |
| 163 | 163 | sockets when the other end breaks the connection. The EPIPE |
| 164 | 164 | error is still returned. */ |
| 165 | - return send(ctx->s, (const char*)req, req_length, MSG_NOSIGNAL); | |
| 165 | + return send(ctx->s, (const char *)req, req_length, MSG_NOSIGNAL); | |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | 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) |
| 497 | 497 | |
| 498 | 498 | yes = 1; |
| 499 | 499 | if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR, |
| 500 | - (char *) &yes, sizeof(yes)) == -1) { | |
| 500 | + (char *)&yes, sizeof(yes)) == -1) { | |
| 501 | 501 | close(new_s); |
| 502 | 502 | return -1; |
| 503 | 503 | } |
| ... | ... | @@ -589,7 +589,7 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection) |
| 589 | 589 | int s; |
| 590 | 590 | |
| 591 | 591 | s = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, |
| 592 | - ai_ptr->ai_protocol); | |
| 592 | + ai_ptr->ai_protocol); | |
| 593 | 593 | if (s < 0) { |
| 594 | 594 | if (ctx->debug) { |
| 595 | 595 | perror("socket"); |
| ... | ... | @@ -598,7 +598,7 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection) |
| 598 | 598 | } else { |
| 599 | 599 | int yes = 1; |
| 600 | 600 | rc = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, |
| 601 | - (void *) &yes, sizeof (yes)); | |
| 601 | + (void *)&yes, sizeof (yes)); | |
| 602 | 602 | if (rc != 0) { |
| 603 | 603 | close(s); |
| 604 | 604 | if (ctx->debug) { |
| ... | ... | @@ -793,15 +793,15 @@ modbus_t* modbus_new_tcp(const char *ip, int port) |
| 793 | 793 | } |
| 794 | 794 | #endif |
| 795 | 795 | |
| 796 | - ctx = (modbus_t *) malloc(sizeof(modbus_t)); | |
| 796 | + ctx = (modbus_t *)malloc(sizeof(modbus_t)); | |
| 797 | 797 | _modbus_init_common(ctx); |
| 798 | 798 | |
| 799 | 799 | /* Could be changed after to reach a remote serial Modbus device */ |
| 800 | 800 | ctx->slave = MODBUS_TCP_SLAVE; |
| 801 | 801 | |
| 802 | - ctx->backend = &(_modbus_tcp_backend); | |
| 802 | + ctx->backend = &_modbus_tcp_backend; | |
| 803 | 803 | |
| 804 | - ctx->backend_data = (modbus_tcp_t *) malloc(sizeof(modbus_tcp_t)); | |
| 804 | + ctx->backend_data = (modbus_tcp_t *)malloc(sizeof(modbus_tcp_t)); | |
| 805 | 805 | ctx_tcp = (modbus_tcp_t *)ctx->backend_data; |
| 806 | 806 | |
| 807 | 807 | if (ip != NULL) { |
| ... | ... | @@ -837,15 +837,15 @@ modbus_t* modbus_new_tcp_pi(const char *node, const char *service) |
| 837 | 837 | size_t dest_size; |
| 838 | 838 | size_t ret_size; |
| 839 | 839 | |
| 840 | - ctx = (modbus_t *) malloc(sizeof(modbus_t)); | |
| 840 | + ctx = (modbus_t *)malloc(sizeof(modbus_t)); | |
| 841 | 841 | _modbus_init_common(ctx); |
| 842 | 842 | |
| 843 | 843 | /* Could be changed after to reach a remote serial Modbus device */ |
| 844 | 844 | ctx->slave = MODBUS_TCP_SLAVE; |
| 845 | 845 | |
| 846 | - ctx->backend = &(_modbus_tcp_pi_backend); | |
| 846 | + ctx->backend = &_modbus_tcp_pi_backend; | |
| 847 | 847 | |
| 848 | - ctx->backend_data = (modbus_tcp_pi_t *) malloc(sizeof(modbus_tcp_pi_t)); | |
| 848 | + ctx->backend_data = (modbus_tcp_pi_t *)malloc(sizeof(modbus_tcp_pi_t)); | |
| 849 | 849 | ctx_tcp_pi = (modbus_tcp_pi_t *)ctx->backend_data; |
| 850 | 850 | |
| 851 | 851 | if (node == NULL) { | ... | ... |