Commit ef3e8740fc5303205cca8a445f5936ac19ab7589

Authored by Stéphane Raimbault
1 parent 2e9da98c

Fix swapped test in compute_header_length (1d4241dff)

Showing 1 changed file with 3 additions and 5 deletions
src/modbus.c
... ... @@ -500,22 +500,20 @@ static uint8_t compute_header_length(int function, msg_type_t msg_type)
500 500 {
501 501 int length;
502 502  
503   - if (msg_type == MSG_INDICATION) {
  503 + if (msg_type == MSG_CONFIRMATION) {
504 504 if (function == FC_REPORT_SLAVE_ID) {
505   - length = 0;
  505 + length = 1;
506 506 } else {
507 507 /* Should never happen, the other header lengths are precomputed */
508 508 abort();
509 509 }
510   - } else /* MSG_CONFIRMATION */ {
  510 + } else /* MSG_INDICATION */ {
511 511 if (function <= FC_WRITE_SINGLE_COIL ||
512 512 function == FC_WRITE_SINGLE_REGISTER) {
513 513 length = 4;
514 514 } else if (function == FC_WRITE_MULTIPLE_COILS ||
515 515 function == FC_WRITE_MULTIPLE_REGISTERS) {
516 516 length = 5;
517   - } else if (function == FC_REPORT_SLAVE_ID) {
518   - length = 1;
519 517 } else if (function == FC_READ_AND_WRITE_REGISTERS) {
520 518 length = 9;
521 519 } else {
... ...