Commit 70a14990f44ecf9f2417d81d541068e508a8dbee
Committed by
Stéphane Raimbault
1 parent
72de18bc
Make error_print() globally accessible
Renamed error_print() to _error_print() in order to indicate it's a private method and make it globally accessible so functions in modbus-rtu.c and modbus-tcp.c can make use of it as well. Signed-off-by: Stéphane Raimbault <stephane.raimbault@gmail.com>
Showing
2 changed files
with
8 additions
and
7 deletions
src/modbus-private.h
| @@ -102,6 +102,7 @@ struct _modbus { | @@ -102,6 +102,7 @@ struct _modbus { | ||
| 102 | }; | 102 | }; |
| 103 | 103 | ||
| 104 | void _modbus_init_common(modbus_t *ctx); | 104 | void _modbus_init_common(modbus_t *ctx); |
| 105 | +void _error_print(modbus_t *ctx, const char *context); | ||
| 105 | 106 | ||
| 106 | MODBUS_END_DECLS | 107 | MODBUS_END_DECLS |
| 107 | 108 |
src/modbus.c
| @@ -86,7 +86,7 @@ const char *modbus_strerror(int errnum) { | @@ -86,7 +86,7 @@ const char *modbus_strerror(int errnum) { | ||
| 86 | } | 86 | } |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | -static void error_print(modbus_t *ctx, const char *context) | 89 | +void _error_print(modbus_t *ctx, const char *context) |
| 90 | { | 90 | { |
| 91 | if (ctx->debug) { | 91 | if (ctx->debug) { |
| 92 | fprintf(stderr, "ERROR %s", modbus_strerror(errno)); | 92 | fprintf(stderr, "ERROR %s", modbus_strerror(errno)); |
| @@ -158,7 +158,7 @@ static int send_msg(modbus_t *ctx, uint8_t *req, int req_length) | @@ -158,7 +158,7 @@ static int send_msg(modbus_t *ctx, uint8_t *req, int req_length) | ||
| 158 | do { | 158 | do { |
| 159 | rc = ctx->backend->send(ctx->s, req, req_length); | 159 | rc = ctx->backend->send(ctx->s, req, req_length); |
| 160 | if (rc == -1) { | 160 | if (rc == -1) { |
| 161 | - error_print(ctx, NULL); | 161 | + _error_print(ctx, NULL); |
| 162 | if (ctx->error_recovery && | 162 | if (ctx->error_recovery && |
| 163 | (errno == EBADF || errno == ECONNRESET || errno == EPIPE)) { | 163 | (errno == EBADF || errno == ECONNRESET || errno == EPIPE)) { |
| 164 | modbus_close(ctx); | 164 | modbus_close(ctx); |
| @@ -247,7 +247,7 @@ static int compute_data_length(modbus_t *ctx, uint8_t *msg) | @@ -247,7 +247,7 @@ static int compute_data_length(modbus_t *ctx, uint8_t *msg) | ||
| 247 | FD_ZERO(&rfds); \ | 247 | FD_ZERO(&rfds); \ |
| 248 | FD_SET(ctx->s, &rfds); \ | 248 | FD_SET(ctx->s, &rfds); \ |
| 249 | } else { \ | 249 | } else { \ |
| 250 | - error_print(ctx, "select"); \ | 250 | + _error_print(ctx, "select"); \ |
| 251 | if (ctx->error_recovery && (errno == EBADF)) { \ | 251 | if (ctx->error_recovery && (errno == EBADF)) { \ |
| 252 | modbus_close(ctx); \ | 252 | modbus_close(ctx); \ |
| 253 | modbus_connect(ctx); \ | 253 | modbus_connect(ctx); \ |
| @@ -270,7 +270,7 @@ static int compute_data_length(modbus_t *ctx, uint8_t *msg) | @@ -270,7 +270,7 @@ static int compute_data_length(modbus_t *ctx, uint8_t *msg) | ||
| 270 | errno = EMBUNKEXC; \ | 270 | errno = EMBUNKEXC; \ |
| 271 | } else { \ | 271 | } else { \ |
| 272 | errno = ETIMEDOUT; \ | 272 | errno = ETIMEDOUT; \ |
| 273 | - error_print(ctx, "select"); \ | 273 | + _error_print(ctx, "select"); \ |
| 274 | } \ | 274 | } \ |
| 275 | return -1; \ | 275 | return -1; \ |
| 276 | } \ | 276 | } \ |
| @@ -353,7 +353,7 @@ static int receive_msg(modbus_t *ctx, int msg_length_computed, | @@ -353,7 +353,7 @@ static int receive_msg(modbus_t *ctx, int msg_length_computed, | ||
| 353 | } | 353 | } |
| 354 | 354 | ||
| 355 | if (read_rc == -1) { | 355 | if (read_rc == -1) { |
| 356 | - error_print(ctx, "read"); | 356 | + _error_print(ctx, "read"); |
| 357 | if (ctx->error_recovery && (errno == ECONNRESET || | 357 | if (ctx->error_recovery && (errno == ECONNRESET || |
| 358 | errno == ECONNREFUSED)) { | 358 | errno == ECONNREFUSED)) { |
| 359 | modbus_close(ctx); | 359 | modbus_close(ctx); |
| @@ -396,7 +396,7 @@ static int receive_msg(modbus_t *ctx, int msg_length_computed, | @@ -396,7 +396,7 @@ static int receive_msg(modbus_t *ctx, int msg_length_computed, | ||
| 396 | msg_length_computed += length_to_read; | 396 | msg_length_computed += length_to_read; |
| 397 | if (msg_length_computed > ctx->backend->max_adu_length) { | 397 | if (msg_length_computed > ctx->backend->max_adu_length) { |
| 398 | errno = EMBBADDATA; | 398 | errno = EMBBADDATA; |
| 399 | - error_print(ctx, "too many data"); | 399 | + _error_print(ctx, "too many data"); |
| 400 | return -1; | 400 | return -1; |
| 401 | } | 401 | } |
| 402 | state = COMPLETE; | 402 | state = COMPLETE; |
| @@ -540,7 +540,7 @@ static int receive_msg_req(modbus_t *ctx, uint8_t *req, uint8_t *rsp) | @@ -540,7 +540,7 @@ static int receive_msg_req(modbus_t *ctx, uint8_t *req, uint8_t *rsp) | ||
| 540 | } else { | 540 | } else { |
| 541 | errno = EMBBADEXC; | 541 | errno = EMBBADEXC; |
| 542 | } | 542 | } |
| 543 | - error_print(ctx, NULL); | 543 | + _error_print(ctx, NULL); |
| 544 | return -1; | 544 | return -1; |
| 545 | } | 545 | } |
| 546 | } | 546 | } |