Skip to content

Commit ccb56bf

Browse files
JTrantowJTrantow
andauthored
Issue#3849 fix backported to 2.9 (#3857)
* Issue#3849 fix backported to 2.9 Fixes calc_ifdelay() for baud > 19200 that was setting bit timing delays incorrectly leading to a variety of communication problems. Fixes ENOMSG error handling that was locking up modbus communication. * Back to original voodoo caused by conflating modbus timing calculation with pktuart hardware implementation. (175u * baudrate + 99999u) / 100000u; could be implemented as (7u * baudrate + 3999(/4000; which would improve the calculation range but doesn't matter because already screening out large baud rates. * Fix msg and reverse (baudrate > 19200). --------- Co-authored-by: JTrantow <jerry.trantow@cumuluspd.com>
1 parent 7b019a6 commit ccb56bf

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/hal/drivers/mesa-hostmot2/hm2_modbus.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,10 @@ static unsigned calc_ifdelay(hm2_modbus_inst_t *inst, unsigned baudrate, unsigne
387387
}
388388

389389
// calculation works for baudrates less than ~24 Mbit/s
390-
if(baudrate <= 19200)
390+
if(baudrate > 19200)
391391
return (175u * baudrate + 99999u) / 100000u;
392392
unsigned bits = 1 + 8 + (parity ? 1 : 0) + (stopbits > 1 ? 2 : 1);
393-
return (bits * 35 + 9) / 10; // Bit-times * 3.5 rounded up
393+
return (bits * 35 + 9) / 10; // Ceil of bits in 3.5 characters.
394394
}
395395

396396
//
@@ -1049,12 +1049,10 @@ static void process(void *arg, long period)
10491049
break;
10501050
}
10511051
if(inst->maxicharbits && HM2_PKTUART_RCR_ICHARBITS_VAL(frsize) > inst->maxicharbits) {
1052-
MSG_WARN("%s: warning: reply to command %u had too long inter-character delay (%u > %u), dropping\n",
1052+
MSG_WARN("%s: warning: reply to command %u had too long inter-character delay (%u > %u), trying to interpret\n",
10531053
inst->name, inst->cmdidx,
10541054
HM2_PKTUART_RCR_ICHARBITS_VAL(frsize), inst->maxicharbits);
10551055
set_error(inst, ENOMSG);
1056-
force_resend(inst);
1057-
break;
10581056
}
10591057
inst->rxdata[0] = 0; // This will fail the parse packet if the read did not resolve
10601058
r = hm2_pktuart_queue_read_data(inst->uart, inst->rxdata, HM2_PKTUART_RCR_NBYTES_VAL(frsize));

0 commit comments

Comments
 (0)