yaacov / ArduinoModbusSlave

Modbus slave library for Arduino
ISC License
204 stars 74 forks source link

fix #61: Don't respond to bogus frames #66

Closed dgoo2308 closed 4 years ago

dgoo2308 commented 4 years ago

as per @IanAber (#61) prevent sending STATUS_ILLEGAL_FUNCTION on a bogus frame:

Some extras for extra snappy performance optimalisations:

yaacov commented 4 years ago

:green_heart:

falahati commented 4 years ago

Calculating CRC is costly; should have it after every other validation that might narrow the execution cost down. That was why we put it down in the execution path after address check and length check. Especially on a busy network, it will push every device to the limit.

falahati commented 4 years ago

Maybe just store the STATUS_ILLEGAL_FUNCTION in a variable and send it back if the CRC is also correct? This allows the device to skip CRC check for valid or invalid requests not targetted toward it and fixes the issue in question without adding additional performance cost to the function.

dgoo2308 commented 4 years ago

@falahati noted, will look into that possibility, I see now the reason behind it, thanks!