From 852d7825e1695aa83b7e21cab5272cbd9df41e0d Mon Sep 17 00:00:00 2001 From: Stéphane Raimbault Date: Fri, 6 May 2011 08:54:04 +0200 Subject: [PATCH] Rename [gs]et_timeout_[begin|end] to [gs]et_[response|byte]_timeout --- doc/Makefile.am | 8 ++++---- doc/modbus_get_byte_timeout.txt | 47 +++++++++++++++++++++++++++++++++++++++++++++++ doc/modbus_get_response_timeout.txt | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/modbus_get_timeout_begin.txt | 53 ----------------------------------------------------- doc/modbus_get_timeout_end.txt | 47 ----------------------------------------------- doc/modbus_set_byte_timeout.txt | 37 +++++++++++++++++++++++++++++++++++++ doc/modbus_set_response_timeout.txt | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/modbus_set_timeout_begin.txt | 54 ------------------------------------------------------ doc/modbus_set_timeout_end.txt | 37 ------------------------------------- src/modbus-private.h | 10 +++++----- src/modbus.c | 43 +++++++++++++++++++++---------------------- src/modbus.h | 8 ++++---- tests/unit-test-client.c | 14 +++++++------- 13 files changed, 232 insertions(+), 233 deletions(-) create mode 100644 doc/modbus_get_byte_timeout.txt create mode 100644 doc/modbus_get_response_timeout.txt delete mode 100644 doc/modbus_get_timeout_begin.txt delete mode 100644 doc/modbus_get_timeout_end.txt create mode 100644 doc/modbus_set_byte_timeout.txt create mode 100644 doc/modbus_set_response_timeout.txt delete mode 100644 doc/modbus_set_timeout_begin.txt delete mode 100644 doc/modbus_set_timeout_end.txt diff --git a/doc/Makefile.am b/doc/Makefile.am index b1ba218..82ef6ec 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -5,8 +5,8 @@ MAN3 = \ modbus_free.3 \ modbus_get_header_length.3 \ modbus_get_socket.3 \ - modbus_get_timeout_begin.3 \ - modbus_get_timeout_end.3 \ + modbus_get_response_timeout.3 \ + modbus_get_byte_timeout.3 \ modbus_new_rtu.3 \ modbus_new_tcp_pi.3 \ modbus_new_tcp.3 \ @@ -21,8 +21,8 @@ MAN3 = \ modbus_set_error_recovery.3 \ modbus_set_slave.3 \ modbus_set_socket.3 \ - modbus_set_timeout_begin.3 \ - modbus_set_timeout_end.3 \ + modbus_set_response_timeout.3 \ + modbus_set_byte_timeout.3 \ modbus_strerror.3 \ modbus_write_bits.3 \ modbus_write_bit.3 \ diff --git a/doc/modbus_get_byte_timeout.txt b/doc/modbus_get_byte_timeout.txt new file mode 100644 index 0000000..4ce9dd1 --- /dev/null +++ b/doc/modbus_get_byte_timeout.txt @@ -0,0 +1,47 @@ +modbus_get_byte_timeout(3) +========================== + + +NAME +---- +modbus_get_byte_timeout - get timeout between bytes + + +SYNOPSIS +-------- +*void modbus_get_byte_timeout(*modbus_t 'ctx', struct timeval *'timeout');* + + +DESCRIPTION +----------- +The _modbus_get_byte_timeout()_ function shall store the timeout interval +between two consecutive bytes of the same message in the 'timeout' argument. + + +RETURN VALUE +------------ +There is no return values. + + +EXAMPLE +------- +[source,c] +------------------- +struct timeval byte_timeout; + +/* Save original timeout */ +modbus_get_byte_timeout(ctx, &byte_timeout); +------------------- + + +SEE ALSO +-------- +linkmb:modbus_get_response_timeout[3] +linkmb:modbus_set_response_timeout[3] +linkmb:modbus_set_byte_timeout[3] + + +AUTHORS +------- +The libmodbus documentation was written by Stéphane Raimbault + diff --git a/doc/modbus_get_response_timeout.txt b/doc/modbus_get_response_timeout.txt new file mode 100644 index 0000000..0e5138a --- /dev/null +++ b/doc/modbus_get_response_timeout.txt @@ -0,0 +1,53 @@ +modbus_get_response_timeout(3) +============================== + + +NAME +---- +modbus_get_response_timeout - get timeout for response + + +SYNOPSIS +-------- +*void modbus_get_response_timeout(*modbus_t 'ctx', struct timeval *'timeout');* + + +DESCRIPTION +----------- +The _modbus_get_response_timeout()_ function shall store the timeout interval +used to wait for a response in the 'timeout' argument. + + +RETURN VALUE +------------ +There is no return values. + + +EXAMPLE +------- +[source,c] +------------------- +struct timeval old_response_timeout; +struct timeval response_timeout; + +/* Save original timeout */ +modbus_get_response_timeout(ctx, &old_response_timeout); + +/* Define a new and too short timeout! */ +response_timeout.tv_sec = 0; +response_timeout.tv_usec = 0; +modbus_set_response_timeout(ctx, &response_timeout); +------------------- + + +SEE ALSO +-------- +linkmb:modbus_set_response_timeout[3] +linkmb:modbus_get_byte_timeout[3] +linkmb:modbus_set_byte_timeout[3] + + +AUTHORS +------- +The libmodbus documentation was written by Stéphane Raimbault + diff --git a/doc/modbus_get_timeout_begin.txt b/doc/modbus_get_timeout_begin.txt deleted file mode 100644 index c40d692..0000000 --- a/doc/modbus_get_timeout_begin.txt +++ /dev/null @@ -1,53 +0,0 @@ -modbus_get_timeout_begin(3) -=========================== - - -NAME ----- -modbus_get_timeout_begin - get timeout of begin of message - - -SYNOPSIS --------- -*void modbus_get_timeout_begin(*modbus_t 'ctx', struct timeval *'timeout');* - - -DESCRIPTION ------------ -The _modbus_get_timeout_begin()_ function shall store the current timeout of -begin of message in the 'timeout' argument. - - -RETURN VALUE ------------- -There is no return values. - - -EXAMPLE -------- -[source,c] -------------------- -struct timeval timeout_begin_old; -struct timeval timeout_begin_new; - -/* Save original timeout */ -modbus_get_timeout_begin(ctx, &timeout_begin_old); - -/* Define a new and too short timeout! */ -timeout_begin_new.tv_sec = 0; -timeout_begin_new.tv_usec = 0; -modbus_set_timeout_begin(ctx, &timeout_begin_new); -------------------- - - -SEE ALSO --------- -linkmb:modbus_set_timeout_begin[3] -linkmb:modbus_get_timeout_end[3] -linkmb:modbus_set_timeout_end[3] - - -AUTHORS -------- -The libmodbus documentation was written by Stéphane Raimbault - diff --git a/doc/modbus_get_timeout_end.txt b/doc/modbus_get_timeout_end.txt deleted file mode 100644 index fe4214b..0000000 --- a/doc/modbus_get_timeout_end.txt +++ /dev/null @@ -1,47 +0,0 @@ -modbus_get_timeout_end(3) -=========================== - - -NAME ----- -modbus_get_timeout_end - get timeout of end of message - - -SYNOPSIS --------- -*void modbus_get_timeout_end(*modbus_t 'ctx', struct timeval *'timeout');* - - -DESCRIPTION ------------ -The _modbus_get_timeout_end()_ function shall store the current timeout between -the begin and the end of message in the 'timeout' argument. - - -RETURN VALUE ------------- -There is no return values. - - -EXAMPLE -------- -[source,c] -------------------- -struct timeval timeout_end; - -/* Save original timeout */ -modbus_get_timeout_end(ctx, &timeout_end); -------------------- - - -SEE ALSO --------- -linkmb:modbus_get_timeout_begin[3] -linkmb:modbus_set_timeout_begin[3] -linkmb:modbus_set_timeout_end[3] - - -AUTHORS -------- -The libmodbus documentation was written by Stéphane Raimbault - diff --git a/doc/modbus_set_byte_timeout.txt b/doc/modbus_set_byte_timeout.txt new file mode 100644 index 0000000..50da367 --- /dev/null +++ b/doc/modbus_set_byte_timeout.txt @@ -0,0 +1,37 @@ +modbus_set_byte_timeout(3) +========================== + + +NAME +---- +modbus_set_byte_timeout - set timeout between bytes + + +SYNOPSIS +-------- +*void modbus_set_byte_timeout(*modbus_t 'ctx', struct timeval *'timeout');* + + +DESCRIPTION +----------- +The _modbus_set_byte_timeout()_ function shall set the timeout interval between +two consecutive bytes of the same message. If the delay between is longer than +the given timeout, an error will be raised. + + +RETURN VALUE +------------ +There is no return values. + + +SEE ALSO +-------- +linkmb:modbus_get_byte_timeout[3] +linkmb:modbus_get_response_timeout[3] +linkmb:modbus_set_response_timeout[3] + + +AUTHORS +------- +The libmodbus documentation was written by Stéphane Raimbault + diff --git a/doc/modbus_set_response_timeout.txt b/doc/modbus_set_response_timeout.txt new file mode 100644 index 0000000..82b3387 --- /dev/null +++ b/doc/modbus_set_response_timeout.txt @@ -0,0 +1,54 @@ +modbus_set_response_timeout(3) +============================== + + +NAME +---- +modbus_set_response_timeout - set timeout for response + + +SYNOPSIS +-------- +*void modbus_set_response_timeout(*modbus_t 'ctx', struct timeval *'timeout');* + + +DESCRIPTION +----------- +The _modbus_set_response_timeout()_ function shall set the timeout interval used +to wait for a response. If the waiting before receiving the response is longer than +the given timeout, an error will be raised. + + +RETURN VALUE +------------ +There is no return values. + + +EXAMPLE +------- +[source,c] +------------------- +struct timeval old_response_timeout; +struct timeval response_timeout; + +/* Save original timeout */ +modbus_get_response_timeout(ctx, &old_response_timeout); + +/* Define a new and too short timeout! */ +response_timeout.tv_sec = 0; +response_timeout.tv_usec = 0; +modbus_set_response_timeout(ctx, &response_timeout); +------------------- + + +SEE ALSO +-------- +linkmb:modbus_get_response_timeout[3] +linkmb:modbus_get_byte_timeout[3] +linkmb:modbus_set_byte_timeout[3] + + +AUTHORS +------- +The libmodbus documentation was written by Stéphane Raimbault + diff --git a/doc/modbus_set_timeout_begin.txt b/doc/modbus_set_timeout_begin.txt deleted file mode 100644 index 10a211a..0000000 --- a/doc/modbus_set_timeout_begin.txt +++ /dev/null @@ -1,54 +0,0 @@ -modbus_set_timeout_begin(3) -=========================== - - -NAME ----- -modbus_set_timeout_begin - set timeout of begin of message - - -SYNOPSIS --------- -*void modbus_set_timeout_begin(*modbus_t 'ctx', struct timeval *'timeout');* - - -DESCRIPTION ------------ -The _modbus_set_timeout_begin()_ function shall set the timeout of begin of -message. If the waiting before receiving a message is longer than the given -timeout, an error will be raised. - - -RETURN VALUE ------------- -There is no return values. - - -EXAMPLE -------- -[source,c] -------------------- -struct timeval timeout_begin_old; -struct timeval timeout_begin_new; - -/* Save original timeout */ -modbus_get_timeout_begin(ctx, &timeout_begin_old); - -/* Define a new and too short timeout! */ -timeout_begin_new.tv_sec = 0; -timeout_begin_new.tv_usec = 0; -modbus_set_timeout_begin(ctx, &timeout_begin_new); -------------------- - - -SEE ALSO --------- -linkmb:modbus_get_timeout_begin[3] -linkmb:modbus_get_timeout_end[3] -linkmb:modbus_set_timeout_end[3] - - -AUTHORS -------- -The libmodbus documentation was written by Stéphane Raimbault - diff --git a/doc/modbus_set_timeout_end.txt b/doc/modbus_set_timeout_end.txt deleted file mode 100644 index 1f5a08f..0000000 --- a/doc/modbus_set_timeout_end.txt +++ /dev/null @@ -1,37 +0,0 @@ -modbus_set_timeout_end(3) -=========================== - - -NAME ----- -modbus_set_timeout_end - set timeout of end of message - - -SYNOPSIS --------- -*void modbus_set_timeout_end(*modbus_t 'ctx', struct timeval *'timeout');* - - -DESCRIPTION ------------ -The _modbus_set_timeout_end()_ function shall set the timeout of end of -message. If the delay between the begin and the end of message is longer than -the given timeout, an error will be raised. - - -RETURN VALUE ------------- -There is no return values. - - -SEE ALSO --------- -linkmb:modbus_get_timeout_begin[3] -linkmb:modbus_set_timeout_begin[3] -linkmb:modbus_get_timeout_end[3] - - -AUTHORS -------- -The libmodbus documentation was written by Stéphane Raimbault - diff --git a/src/modbus-private.h b/src/modbus-private.h index ade0b4c..395282f 100644 --- a/src/modbus-private.h +++ b/src/modbus-private.h @@ -45,9 +45,9 @@ MODBUS_BEGIN_DECLS #define _MODBUS_EXCEPTION_RSP_LENGTH 5 -/* Time out between messages in microsecond */ -#define _TIME_OUT_BEGIN_OF_MESSAGE 500000 -#define _TIME_OUT_END_OF_MESSAGE 500000 +/* Timeouts in microsecond (0.5 s) */ +#define _RESPONSE_TIMEOUT 500000 +#define _BYTE_TIMEOUT 500000 /* Function codes */ #define _FC_READ_COILS 0x01 @@ -104,8 +104,8 @@ struct _modbus { int s; int debug; int error_recovery; - struct timeval timeout_begin; - struct timeval timeout_end; + struct timeval response_timeout; + struct timeval byte_timeout; const modbus_backend_t *backend; void *backend_data; }; diff --git a/src/modbus.c b/src/modbus.c index 0e496e2..8f210ce 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -331,8 +331,8 @@ static int receive_msg(modbus_t *ctx, uint8_t *msg, msg_type_t msg_type) tv.tv_sec = 60; tv.tv_usec = 0; } else { - tv.tv_sec = ctx->timeout_begin.tv_sec; - tv.tv_usec = ctx->timeout_begin.tv_usec; + tv.tv_sec = ctx->response_timeout.tv_sec; + tv.tv_usec = ctx->response_timeout.tv_usec; } while (length_to_read != 0) { @@ -398,10 +398,11 @@ static int receive_msg(modbus_t *ctx, uint8_t *msg, msg_type_t msg_type) } if (length_to_read > 0) { - /* If no character at the buffer wait - TIME_OUT_END_OF_MESSAGE before raising an error. */ - tv.tv_sec = ctx->timeout_end.tv_sec; - tv.tv_usec = ctx->timeout_end.tv_usec; + /* If there is no character in the buffer, the allowed timeout + interval between two consecutive bytes is defined by + byte_timeout */ + tv.tv_sec = ctx->byte_timeout.tv_sec; + tv.tv_usec = ctx->byte_timeout.tv_usec; } } @@ -1311,11 +1312,11 @@ void _modbus_init_common(modbus_t *ctx) ctx->debug = FALSE; ctx->error_recovery = FALSE; - ctx->timeout_begin.tv_sec = 0; - ctx->timeout_begin.tv_usec = _TIME_OUT_BEGIN_OF_MESSAGE; + ctx->response_timeout.tv_sec = 0; + ctx->response_timeout.tv_usec = _RESPONSE_TIMEOUT; - ctx->timeout_end.tv_sec = 0; - ctx->timeout_end.tv_usec = _TIME_OUT_END_OF_MESSAGE; + ctx->byte_timeout.tv_sec = 0; + ctx->byte_timeout.tv_usec = _BYTE_TIMEOUT; } /* Define the slave number */ @@ -1346,28 +1347,26 @@ int modbus_get_socket(modbus_t *ctx) return ctx->s; } -/* Get the timeout of begin of message */ -void modbus_get_timeout_begin(modbus_t *ctx, struct timeval *timeout) +/* Get the timeout interval used to wait for a response */ +void modbus_get_response_timeout(modbus_t *ctx, struct timeval *timeout) { - *timeout = ctx->timeout_begin; + *timeout = ctx->response_timeout; } -/* Set timeout when waiting the beginning of a message */ -void modbus_set_timeout_begin(modbus_t *ctx, const struct timeval *timeout) +void modbus_set_response_timeout(modbus_t *ctx, const struct timeval *timeout) { - ctx->timeout_begin = *timeout; + ctx->response_timeout = *timeout; } -/* Get the timeout of end of message */ -void modbus_get_timeout_end(modbus_t *ctx, struct timeval *timeout) +/* Get the timeout interval between two consecutive bytes of a message */ +void modbus_get_byte_timeout(modbus_t *ctx, struct timeval *timeout) { - *timeout = ctx->timeout_end; + *timeout = ctx->byte_timeout; } -/* Set timeout when waiting the end of a message */ -void modbus_set_timeout_end(modbus_t *ctx, const struct timeval *timeout) +void modbus_set_byte_timeout(modbus_t *ctx, const struct timeval *timeout) { - ctx->timeout_end = *timeout; + ctx->byte_timeout = *timeout; } int modbus_get_header_length(modbus_t *ctx) diff --git a/src/modbus.h b/src/modbus.h index 5691b9a..f686094 100644 --- a/src/modbus.h +++ b/src/modbus.h @@ -139,11 +139,11 @@ int modbus_set_error_recovery(modbus_t *ctx, int enabled); void modbus_set_socket(modbus_t *ctx, int socket); int modbus_get_socket(modbus_t *ctx); -void modbus_get_timeout_begin(modbus_t *ctx, struct timeval *timeout); -void modbus_set_timeout_begin(modbus_t *ctx, const struct timeval *timeout); +void modbus_get_response_timeout(modbus_t *ctx, struct timeval *timeout); +void modbus_set_response_timeout(modbus_t *ctx, const struct timeval *timeout); -void modbus_get_timeout_end(modbus_t *ctx, struct timeval *timeout); -void modbus_set_timeout_end(modbus_t *ctx, const struct timeval *timeout); +void modbus_get_byte_timeout(modbus_t *ctx, struct timeval *timeout); +void modbus_set_byte_timeout(modbus_t *ctx, const struct timeval *timeout); int modbus_get_header_length(modbus_t *ctx); diff --git a/tests/unit-test-client.c b/tests/unit-test-client.c index 16ba4c0..8f0d0cd 100644 --- a/tests/unit-test-client.c +++ b/tests/unit-test-client.c @@ -42,8 +42,8 @@ int main(int argc, char *argv[]) int nb_points; int rc; float real; - struct timeval timeout_begin_old; - struct timeval timeout_begin_new; + struct timeval old_response_timeout; + struct timeval response_timeout; int use_backend; if (argc > 1) { @@ -549,12 +549,12 @@ int main(int argc, char *argv[]) } /* Save original timeout */ - modbus_get_timeout_begin(ctx, &timeout_begin_old); + modbus_get_response_timeout(ctx, &old_response_timeout); /* Define a new and too short timeout */ - timeout_begin_new.tv_sec = 0; - timeout_begin_new.tv_usec = 0; - modbus_set_timeout_begin(ctx, &timeout_begin_new); + response_timeout.tv_sec = 0; + response_timeout.tv_usec = 0; + modbus_set_response_timeout(ctx, &response_timeout); rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, UT_REGISTERS_NB, tab_rp_registers); @@ -567,7 +567,7 @@ int main(int argc, char *argv[]) } /* Restore original timeout */ - modbus_set_timeout_begin(ctx, &timeout_begin_old); + modbus_set_response_timeout(ctx, &old_response_timeout); /* Wait for data before flushing */ usleep(250000); -- libgit2 0.21.4