Commit 852d7825e1695aa83b7e21cab5272cbd9df41e0d
1 parent
1faf5c3a
Rename [gs]et_timeout_[begin|end] to [gs]et_[response|byte]_timeout
The following functions have been renamed: - modbus_get_timeout_begin -> modbus_get_response_timeout - modbus_set_timeout_begin -> modbus_set_response_timeout - modbus_get_timeout_end -> modbus_get_byte_timeout - modbus_set_timeout_end -> modbus_set_byte_timeout The meaning of these timeout intervals is now clearer. The documentation has been updated.
Showing
9 changed files
with
92 additions
and
93 deletions
doc/Makefile.am
| ... | ... | @@ -5,8 +5,8 @@ MAN3 = \ |
| 5 | 5 | modbus_free.3 \ |
| 6 | 6 | modbus_get_header_length.3 \ |
| 7 | 7 | modbus_get_socket.3 \ |
| 8 | - modbus_get_timeout_begin.3 \ | |
| 9 | - modbus_get_timeout_end.3 \ | |
| 8 | + modbus_get_response_timeout.3 \ | |
| 9 | + modbus_get_byte_timeout.3 \ | |
| 10 | 10 | modbus_new_rtu.3 \ |
| 11 | 11 | modbus_new_tcp_pi.3 \ |
| 12 | 12 | modbus_new_tcp.3 \ |
| ... | ... | @@ -21,8 +21,8 @@ MAN3 = \ |
| 21 | 21 | modbus_set_error_recovery.3 \ |
| 22 | 22 | modbus_set_slave.3 \ |
| 23 | 23 | modbus_set_socket.3 \ |
| 24 | - modbus_set_timeout_begin.3 \ | |
| 25 | - modbus_set_timeout_end.3 \ | |
| 24 | + modbus_set_response_timeout.3 \ | |
| 25 | + modbus_set_byte_timeout.3 \ | |
| 26 | 26 | modbus_strerror.3 \ |
| 27 | 27 | modbus_write_bits.3 \ |
| 28 | 28 | modbus_write_bit.3 \ | ... | ... |
doc/modbus_get_timeout_end.txt renamed to doc/modbus_get_byte_timeout.txt
| 1 | -modbus_get_timeout_end(3) | |
| 2 | -=========================== | |
| 1 | +modbus_get_byte_timeout(3) | |
| 2 | +========================== | |
| 3 | 3 | |
| 4 | 4 | |
| 5 | 5 | NAME |
| 6 | 6 | ---- |
| 7 | -modbus_get_timeout_end - get timeout of end of message | |
| 7 | +modbus_get_byte_timeout - get timeout between bytes | |
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | SYNOPSIS |
| 11 | 11 | -------- |
| 12 | -*void modbus_get_timeout_end(*modbus_t 'ctx', struct timeval *'timeout');* | |
| 12 | +*void modbus_get_byte_timeout(*modbus_t 'ctx', struct timeval *'timeout');* | |
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | DESCRIPTION |
| 16 | 16 | ----------- |
| 17 | -The _modbus_get_timeout_end()_ function shall store the current timeout between | |
| 18 | -the begin and the end of message in the 'timeout' argument. | |
| 17 | +The _modbus_get_byte_timeout()_ function shall store the timeout interval | |
| 18 | +between two consecutive bytes of the same message in the 'timeout' argument. | |
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | RETURN VALUE |
| ... | ... | @@ -27,18 +27,18 @@ EXAMPLE |
| 27 | 27 | ------- |
| 28 | 28 | [source,c] |
| 29 | 29 | ------------------- |
| 30 | -struct timeval timeout_end; | |
| 30 | +struct timeval byte_timeout; | |
| 31 | 31 | |
| 32 | 32 | /* Save original timeout */ |
| 33 | -modbus_get_timeout_end(ctx, &timeout_end); | |
| 33 | +modbus_get_byte_timeout(ctx, &byte_timeout); | |
| 34 | 34 | ------------------- |
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | SEE ALSO |
| 38 | 38 | -------- |
| 39 | -linkmb:modbus_get_timeout_begin[3] | |
| 40 | -linkmb:modbus_set_timeout_begin[3] | |
| 41 | -linkmb:modbus_set_timeout_end[3] | |
| 39 | +linkmb:modbus_get_response_timeout[3] | |
| 40 | +linkmb:modbus_set_response_timeout[3] | |
| 41 | +linkmb:modbus_set_byte_timeout[3] | |
| 42 | 42 | |
| 43 | 43 | |
| 44 | 44 | AUTHORS | ... | ... |
doc/modbus_get_timeout_begin.txt renamed to doc/modbus_get_response_timeout.txt
| 1 | -modbus_get_timeout_begin(3) | |
| 2 | -=========================== | |
| 1 | +modbus_get_response_timeout(3) | |
| 2 | +============================== | |
| 3 | 3 | |
| 4 | 4 | |
| 5 | 5 | NAME |
| 6 | 6 | ---- |
| 7 | -modbus_get_timeout_begin - get timeout of begin of message | |
| 7 | +modbus_get_response_timeout - get timeout for response | |
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | SYNOPSIS |
| 11 | 11 | -------- |
| 12 | -*void modbus_get_timeout_begin(*modbus_t 'ctx', struct timeval *'timeout');* | |
| 12 | +*void modbus_get_response_timeout(*modbus_t 'ctx', struct timeval *'timeout');* | |
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | DESCRIPTION |
| 16 | 16 | ----------- |
| 17 | -The _modbus_get_timeout_begin()_ function shall store the current timeout of | |
| 18 | -begin of message in the 'timeout' argument. | |
| 17 | +The _modbus_get_response_timeout()_ function shall store the timeout interval | |
| 18 | +used to wait for a response in the 'timeout' argument. | |
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | RETURN VALUE |
| ... | ... | @@ -27,24 +27,24 @@ EXAMPLE |
| 27 | 27 | ------- |
| 28 | 28 | [source,c] |
| 29 | 29 | ------------------- |
| 30 | -struct timeval timeout_begin_old; | |
| 31 | -struct timeval timeout_begin_new; | |
| 30 | +struct timeval old_response_timeout; | |
| 31 | +struct timeval response_timeout; | |
| 32 | 32 | |
| 33 | 33 | /* Save original timeout */ |
| 34 | -modbus_get_timeout_begin(ctx, &timeout_begin_old); | |
| 34 | +modbus_get_response_timeout(ctx, &old_response_timeout); | |
| 35 | 35 | |
| 36 | 36 | /* Define a new and too short timeout! */ |
| 37 | -timeout_begin_new.tv_sec = 0; | |
| 38 | -timeout_begin_new.tv_usec = 0; | |
| 39 | -modbus_set_timeout_begin(ctx, &timeout_begin_new); | |
| 37 | +response_timeout.tv_sec = 0; | |
| 38 | +response_timeout.tv_usec = 0; | |
| 39 | +modbus_set_response_timeout(ctx, &response_timeout); | |
| 40 | 40 | ------------------- |
| 41 | 41 | |
| 42 | 42 | |
| 43 | 43 | SEE ALSO |
| 44 | 44 | -------- |
| 45 | -linkmb:modbus_set_timeout_begin[3] | |
| 46 | -linkmb:modbus_get_timeout_end[3] | |
| 47 | -linkmb:modbus_set_timeout_end[3] | |
| 45 | +linkmb:modbus_set_response_timeout[3] | |
| 46 | +linkmb:modbus_get_byte_timeout[3] | |
| 47 | +linkmb:modbus_set_byte_timeout[3] | |
| 48 | 48 | |
| 49 | 49 | |
| 50 | 50 | AUTHORS | ... | ... |
doc/modbus_set_timeout_end.txt renamed to doc/modbus_set_byte_timeout.txt
| 1 | -modbus_set_timeout_end(3) | |
| 2 | -=========================== | |
| 1 | +modbus_set_byte_timeout(3) | |
| 2 | +========================== | |
| 3 | 3 | |
| 4 | 4 | |
| 5 | 5 | NAME |
| 6 | 6 | ---- |
| 7 | -modbus_set_timeout_end - set timeout of end of message | |
| 7 | +modbus_set_byte_timeout - set timeout between bytes | |
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | SYNOPSIS |
| 11 | 11 | -------- |
| 12 | -*void modbus_set_timeout_end(*modbus_t 'ctx', struct timeval *'timeout');* | |
| 12 | +*void modbus_set_byte_timeout(*modbus_t 'ctx', struct timeval *'timeout');* | |
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | DESCRIPTION |
| 16 | 16 | ----------- |
| 17 | -The _modbus_set_timeout_end()_ function shall set the timeout of end of | |
| 18 | -message. If the delay between the begin and the end of message is longer than | |
| 17 | +The _modbus_set_byte_timeout()_ function shall set the timeout interval between | |
| 18 | +two consecutive bytes of the same message. If the delay between is longer than | |
| 19 | 19 | the given timeout, an error will be raised. |
| 20 | 20 | |
| 21 | 21 | |
| ... | ... | @@ -26,9 +26,9 @@ There is no return values. |
| 26 | 26 | |
| 27 | 27 | SEE ALSO |
| 28 | 28 | -------- |
| 29 | -linkmb:modbus_get_timeout_begin[3] | |
| 30 | -linkmb:modbus_set_timeout_begin[3] | |
| 31 | -linkmb:modbus_get_timeout_end[3] | |
| 29 | +linkmb:modbus_get_byte_timeout[3] | |
| 30 | +linkmb:modbus_get_response_timeout[3] | |
| 31 | +linkmb:modbus_set_response_timeout[3] | |
| 32 | 32 | |
| 33 | 33 | |
| 34 | 34 | AUTHORS | ... | ... |
doc/modbus_set_timeout_begin.txt renamed to doc/modbus_set_response_timeout.txt
| 1 | -modbus_set_timeout_begin(3) | |
| 2 | -=========================== | |
| 1 | +modbus_set_response_timeout(3) | |
| 2 | +============================== | |
| 3 | 3 | |
| 4 | 4 | |
| 5 | 5 | NAME |
| 6 | 6 | ---- |
| 7 | -modbus_set_timeout_begin - set timeout of begin of message | |
| 7 | +modbus_set_response_timeout - set timeout for response | |
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | SYNOPSIS |
| 11 | 11 | -------- |
| 12 | -*void modbus_set_timeout_begin(*modbus_t 'ctx', struct timeval *'timeout');* | |
| 12 | +*void modbus_set_response_timeout(*modbus_t 'ctx', struct timeval *'timeout');* | |
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | DESCRIPTION |
| 16 | 16 | ----------- |
| 17 | -The _modbus_set_timeout_begin()_ function shall set the timeout of begin of | |
| 18 | -message. If the waiting before receiving a message is longer than the given | |
| 19 | -timeout, an error will be raised. | |
| 17 | +The _modbus_set_response_timeout()_ function shall set the timeout interval used | |
| 18 | +to wait for a response. If the waiting before receiving the response is longer than | |
| 19 | +the given timeout, an error will be raised. | |
| 20 | 20 | |
| 21 | 21 | |
| 22 | 22 | RETURN VALUE |
| ... | ... | @@ -28,24 +28,24 @@ EXAMPLE |
| 28 | 28 | ------- |
| 29 | 29 | [source,c] |
| 30 | 30 | ------------------- |
| 31 | -struct timeval timeout_begin_old; | |
| 32 | -struct timeval timeout_begin_new; | |
| 31 | +struct timeval old_response_timeout; | |
| 32 | +struct timeval response_timeout; | |
| 33 | 33 | |
| 34 | 34 | /* Save original timeout */ |
| 35 | -modbus_get_timeout_begin(ctx, &timeout_begin_old); | |
| 35 | +modbus_get_response_timeout(ctx, &old_response_timeout); | |
| 36 | 36 | |
| 37 | 37 | /* Define a new and too short timeout! */ |
| 38 | -timeout_begin_new.tv_sec = 0; | |
| 39 | -timeout_begin_new.tv_usec = 0; | |
| 40 | -modbus_set_timeout_begin(ctx, &timeout_begin_new); | |
| 38 | +response_timeout.tv_sec = 0; | |
| 39 | +response_timeout.tv_usec = 0; | |
| 40 | +modbus_set_response_timeout(ctx, &response_timeout); | |
| 41 | 41 | ------------------- |
| 42 | 42 | |
| 43 | 43 | |
| 44 | 44 | SEE ALSO |
| 45 | 45 | -------- |
| 46 | -linkmb:modbus_get_timeout_begin[3] | |
| 47 | -linkmb:modbus_get_timeout_end[3] | |
| 48 | -linkmb:modbus_set_timeout_end[3] | |
| 46 | +linkmb:modbus_get_response_timeout[3] | |
| 47 | +linkmb:modbus_get_byte_timeout[3] | |
| 48 | +linkmb:modbus_set_byte_timeout[3] | |
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | AUTHORS | ... | ... |
src/modbus-private.h
| ... | ... | @@ -45,9 +45,9 @@ MODBUS_BEGIN_DECLS |
| 45 | 45 | |
| 46 | 46 | #define _MODBUS_EXCEPTION_RSP_LENGTH 5 |
| 47 | 47 | |
| 48 | -/* Time out between messages in microsecond */ | |
| 49 | -#define _TIME_OUT_BEGIN_OF_MESSAGE 500000 | |
| 50 | -#define _TIME_OUT_END_OF_MESSAGE 500000 | |
| 48 | +/* Timeouts in microsecond (0.5 s) */ | |
| 49 | +#define _RESPONSE_TIMEOUT 500000 | |
| 50 | +#define _BYTE_TIMEOUT 500000 | |
| 51 | 51 | |
| 52 | 52 | /* Function codes */ |
| 53 | 53 | #define _FC_READ_COILS 0x01 |
| ... | ... | @@ -104,8 +104,8 @@ struct _modbus { |
| 104 | 104 | int s; |
| 105 | 105 | int debug; |
| 106 | 106 | int error_recovery; |
| 107 | - struct timeval timeout_begin; | |
| 108 | - struct timeval timeout_end; | |
| 107 | + struct timeval response_timeout; | |
| 108 | + struct timeval byte_timeout; | |
| 109 | 109 | const modbus_backend_t *backend; |
| 110 | 110 | void *backend_data; |
| 111 | 111 | }; | ... | ... |
src/modbus.c
| ... | ... | @@ -331,8 +331,8 @@ static int receive_msg(modbus_t *ctx, uint8_t *msg, msg_type_t msg_type) |
| 331 | 331 | tv.tv_sec = 60; |
| 332 | 332 | tv.tv_usec = 0; |
| 333 | 333 | } else { |
| 334 | - tv.tv_sec = ctx->timeout_begin.tv_sec; | |
| 335 | - tv.tv_usec = ctx->timeout_begin.tv_usec; | |
| 334 | + tv.tv_sec = ctx->response_timeout.tv_sec; | |
| 335 | + tv.tv_usec = ctx->response_timeout.tv_usec; | |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | while (length_to_read != 0) { |
| ... | ... | @@ -398,10 +398,11 @@ static int receive_msg(modbus_t *ctx, uint8_t *msg, msg_type_t msg_type) |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | if (length_to_read > 0) { |
| 401 | - /* If no character at the buffer wait | |
| 402 | - TIME_OUT_END_OF_MESSAGE before raising an error. */ | |
| 403 | - tv.tv_sec = ctx->timeout_end.tv_sec; | |
| 404 | - tv.tv_usec = ctx->timeout_end.tv_usec; | |
| 401 | + /* If there is no character in the buffer, the allowed timeout | |
| 402 | + interval between two consecutive bytes is defined by | |
| 403 | + byte_timeout */ | |
| 404 | + tv.tv_sec = ctx->byte_timeout.tv_sec; | |
| 405 | + tv.tv_usec = ctx->byte_timeout.tv_usec; | |
| 405 | 406 | } |
| 406 | 407 | } |
| 407 | 408 | |
| ... | ... | @@ -1311,11 +1312,11 @@ void _modbus_init_common(modbus_t *ctx) |
| 1311 | 1312 | ctx->debug = FALSE; |
| 1312 | 1313 | ctx->error_recovery = FALSE; |
| 1313 | 1314 | |
| 1314 | - ctx->timeout_begin.tv_sec = 0; | |
| 1315 | - ctx->timeout_begin.tv_usec = _TIME_OUT_BEGIN_OF_MESSAGE; | |
| 1315 | + ctx->response_timeout.tv_sec = 0; | |
| 1316 | + ctx->response_timeout.tv_usec = _RESPONSE_TIMEOUT; | |
| 1316 | 1317 | |
| 1317 | - ctx->timeout_end.tv_sec = 0; | |
| 1318 | - ctx->timeout_end.tv_usec = _TIME_OUT_END_OF_MESSAGE; | |
| 1318 | + ctx->byte_timeout.tv_sec = 0; | |
| 1319 | + ctx->byte_timeout.tv_usec = _BYTE_TIMEOUT; | |
| 1319 | 1320 | } |
| 1320 | 1321 | |
| 1321 | 1322 | /* Define the slave number */ |
| ... | ... | @@ -1346,28 +1347,26 @@ int modbus_get_socket(modbus_t *ctx) |
| 1346 | 1347 | return ctx->s; |
| 1347 | 1348 | } |
| 1348 | 1349 | |
| 1349 | -/* Get the timeout of begin of message */ | |
| 1350 | -void modbus_get_timeout_begin(modbus_t *ctx, struct timeval *timeout) | |
| 1350 | +/* Get the timeout interval used to wait for a response */ | |
| 1351 | +void modbus_get_response_timeout(modbus_t *ctx, struct timeval *timeout) | |
| 1351 | 1352 | { |
| 1352 | - *timeout = ctx->timeout_begin; | |
| 1353 | + *timeout = ctx->response_timeout; | |
| 1353 | 1354 | } |
| 1354 | 1355 | |
| 1355 | -/* Set timeout when waiting the beginning of a message */ | |
| 1356 | -void modbus_set_timeout_begin(modbus_t *ctx, const struct timeval *timeout) | |
| 1356 | +void modbus_set_response_timeout(modbus_t *ctx, const struct timeval *timeout) | |
| 1357 | 1357 | { |
| 1358 | - ctx->timeout_begin = *timeout; | |
| 1358 | + ctx->response_timeout = *timeout; | |
| 1359 | 1359 | } |
| 1360 | 1360 | |
| 1361 | -/* Get the timeout of end of message */ | |
| 1362 | -void modbus_get_timeout_end(modbus_t *ctx, struct timeval *timeout) | |
| 1361 | +/* Get the timeout interval between two consecutive bytes of a message */ | |
| 1362 | +void modbus_get_byte_timeout(modbus_t *ctx, struct timeval *timeout) | |
| 1363 | 1363 | { |
| 1364 | - *timeout = ctx->timeout_end; | |
| 1364 | + *timeout = ctx->byte_timeout; | |
| 1365 | 1365 | } |
| 1366 | 1366 | |
| 1367 | -/* Set timeout when waiting the end of a message */ | |
| 1368 | -void modbus_set_timeout_end(modbus_t *ctx, const struct timeval *timeout) | |
| 1367 | +void modbus_set_byte_timeout(modbus_t *ctx, const struct timeval *timeout) | |
| 1369 | 1368 | { |
| 1370 | - ctx->timeout_end = *timeout; | |
| 1369 | + ctx->byte_timeout = *timeout; | |
| 1371 | 1370 | } |
| 1372 | 1371 | |
| 1373 | 1372 | int modbus_get_header_length(modbus_t *ctx) | ... | ... |
src/modbus.h
| ... | ... | @@ -139,11 +139,11 @@ int modbus_set_error_recovery(modbus_t *ctx, int enabled); |
| 139 | 139 | void modbus_set_socket(modbus_t *ctx, int socket); |
| 140 | 140 | int modbus_get_socket(modbus_t *ctx); |
| 141 | 141 | |
| 142 | -void modbus_get_timeout_begin(modbus_t *ctx, struct timeval *timeout); | |
| 143 | -void modbus_set_timeout_begin(modbus_t *ctx, const struct timeval *timeout); | |
| 142 | +void modbus_get_response_timeout(modbus_t *ctx, struct timeval *timeout); | |
| 143 | +void modbus_set_response_timeout(modbus_t *ctx, const struct timeval *timeout); | |
| 144 | 144 | |
| 145 | -void modbus_get_timeout_end(modbus_t *ctx, struct timeval *timeout); | |
| 146 | -void modbus_set_timeout_end(modbus_t *ctx, const struct timeval *timeout); | |
| 145 | +void modbus_get_byte_timeout(modbus_t *ctx, struct timeval *timeout); | |
| 146 | +void modbus_set_byte_timeout(modbus_t *ctx, const struct timeval *timeout); | |
| 147 | 147 | |
| 148 | 148 | int modbus_get_header_length(modbus_t *ctx); |
| 149 | 149 | ... | ... |
tests/unit-test-client.c
| ... | ... | @@ -42,8 +42,8 @@ int main(int argc, char *argv[]) |
| 42 | 42 | int nb_points; |
| 43 | 43 | int rc; |
| 44 | 44 | float real; |
| 45 | - struct timeval timeout_begin_old; | |
| 46 | - struct timeval timeout_begin_new; | |
| 45 | + struct timeval old_response_timeout; | |
| 46 | + struct timeval response_timeout; | |
| 47 | 47 | int use_backend; |
| 48 | 48 | |
| 49 | 49 | if (argc > 1) { |
| ... | ... | @@ -549,12 +549,12 @@ int main(int argc, char *argv[]) |
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | /* Save original timeout */ |
| 552 | - modbus_get_timeout_begin(ctx, &timeout_begin_old); | |
| 552 | + modbus_get_response_timeout(ctx, &old_response_timeout); | |
| 553 | 553 | |
| 554 | 554 | /* Define a new and too short timeout */ |
| 555 | - timeout_begin_new.tv_sec = 0; | |
| 556 | - timeout_begin_new.tv_usec = 0; | |
| 557 | - modbus_set_timeout_begin(ctx, &timeout_begin_new); | |
| 555 | + response_timeout.tv_sec = 0; | |
| 556 | + response_timeout.tv_usec = 0; | |
| 557 | + modbus_set_response_timeout(ctx, &response_timeout); | |
| 558 | 558 | |
| 559 | 559 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, |
| 560 | 560 | UT_REGISTERS_NB, tab_rp_registers); |
| ... | ... | @@ -567,7 +567,7 @@ int main(int argc, char *argv[]) |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | /* Restore original timeout */ |
| 570 | - modbus_set_timeout_begin(ctx, &timeout_begin_old); | |
| 570 | + modbus_set_response_timeout(ctx, &old_response_timeout); | |
| 571 | 571 | |
| 572 | 572 | /* Wait for data before flushing */ |
| 573 | 573 | usleep(250000); | ... | ... |