Commit 86418cf3b790801fe714ff5448b701a34966da84
1 parent
a0c660fe
Comments, naming and minor
Showing
1 changed file
with
13 additions
and
12 deletions
src/modbus.c
| ... | ... | @@ -479,7 +479,7 @@ static int send_msg(modbus_t *ctx, uint8_t *req, int req_length) |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | /* Computes the length of the header following the function code */ |
| 482 | -static uint8_t compute_req_length_header(int function) | |
| 482 | +static uint8_t compute_request_length_header(int function) | |
| 483 | 483 | { |
| 484 | 484 | int length; |
| 485 | 485 | |
| ... | ... | @@ -500,7 +500,7 @@ static uint8_t compute_req_length_header(int function) |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /* Computes the length of the data to write in the request */ |
| 503 | -static int compute_req_length_data(modbus_t *ctx, uint8_t *msg) | |
| 503 | +static int compute_request_length_data(modbus_t *ctx, uint8_t *msg) | |
| 504 | 504 | { |
| 505 | 505 | int function = msg[TAB_HEADER_LENGTH[ctx->type_com]]; |
| 506 | 506 | int length; |
| ... | ... | @@ -558,7 +558,7 @@ static int compute_req_length_data(modbus_t *ctx, uint8_t *msg) |
| 558 | 558 | } \ |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | -/* Waits a reply from a modbus server or a request from a modbus client. | |
| 561 | +/* Waits a response from a modbus server or a request from a modbus client. | |
| 562 | 562 | This function blocks if there is no replies (3 timeouts). |
| 563 | 563 | |
| 564 | 564 | The argument msg_length_computed must be set to MSG_LENGTH_UNDEFINED if |
| ... | ... | @@ -581,7 +581,7 @@ static int receive_msg(modbus_t *ctx, int msg_length_computed, uint8_t *msg) |
| 581 | 581 | struct timeval tv; |
| 582 | 582 | int length_to_read; |
| 583 | 583 | uint8_t *p_msg; |
| 584 | - enum { FUNCTION, BYTE, COMPLETE }; | |
| 584 | + enum { FUNCTION, DATA, COMPLETE }; | |
| 585 | 585 | int state; |
| 586 | 586 | int msg_length = 0; |
| 587 | 587 | |
| ... | ... | @@ -604,7 +604,8 @@ static int receive_msg(modbus_t *ctx, int msg_length_computed, uint8_t *msg) |
| 604 | 604 | |
| 605 | 605 | /* The message length is undefined (request receiving) so we need to |
| 606 | 606 | * analyse the message step by step. At the first step, we want to |
| 607 | - * reach the function code because all packets have that information. */ | |
| 607 | + * reach the function code because all packets contains this | |
| 608 | + * information. */ | |
| 608 | 609 | state = FUNCTION; |
| 609 | 610 | msg_length_computed = TAB_HEADER_LENGTH[ctx->type_com] + 1; |
| 610 | 611 | } else { |
| ... | ... | @@ -660,16 +661,16 @@ static int receive_msg(modbus_t *ctx, int msg_length_computed, uint8_t *msg) |
| 660 | 661 | switch (state) { |
| 661 | 662 | case FUNCTION: |
| 662 | 663 | /* Function code position */ |
| 663 | - length_to_read = compute_req_length_header( | |
| 664 | + length_to_read = compute_request_length_header( | |
| 664 | 665 | msg[TAB_HEADER_LENGTH[ctx->type_com]]); |
| 665 | 666 | msg_length_computed += length_to_read; |
| 666 | 667 | /* It's useless to check the value of |
| 667 | 668 | msg_length_computed in this case (only |
| 668 | 669 | defined values are used). */ |
| 669 | - state = BYTE; | |
| 670 | + state = DATA; | |
| 670 | 671 | break; |
| 671 | - case BYTE: | |
| 672 | - length_to_read = compute_req_length_data(ctx, msg); | |
| 672 | + case DATA: | |
| 673 | + length_to_read = compute_request_length_data(ctx, msg); | |
| 673 | 674 | msg_length_computed += length_to_read; |
| 674 | 675 | if (msg_length_computed > TAB_MAX_ADU_LENGTH[ctx->type_com]) { |
| 675 | 676 | errno = EMBBADDATA; |
| ... | ... | @@ -717,8 +718,8 @@ static int receive_msg(modbus_t *ctx, int msg_length_computed, uint8_t *msg) |
| 717 | 718 | etablished with the master device in argument or -1 to use the internal one |
| 718 | 719 | of modbus_t. |
| 719 | 720 | |
| 720 | - The receive_msg_req function shall return the request received and its | |
| 721 | - byte length if successul. Otherwise, it shall return -1 and errno is set. */ | |
| 721 | + The function shall return the request received and its byte length if | |
| 722 | + successul. Otherwise, it shall return -1 and errno is set. */ | |
| 722 | 723 | int modbus_receive(modbus_t *ctx, int sockfd, uint8_t *req) |
| 723 | 724 | { |
| 724 | 725 | if (sockfd != -1) { |
| ... | ... | @@ -1438,7 +1439,7 @@ int modbus_report_slave_id(modbus_t *ctx, uint8_t *data_dest) |
| 1438 | 1439 | additional data */ |
| 1439 | 1440 | rc = receive_msg_req(ctx, req, rsp); |
| 1440 | 1441 | if (rc == -1) |
| 1441 | - return rc; | |
| 1442 | + return -1; | |
| 1442 | 1443 | |
| 1443 | 1444 | offset = TAB_HEADER_LENGTH[ctx->type_com] - 1; |
| 1444 | 1445 | offset_end = offset + rc; | ... | ... |