Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for v2.0.1 #85

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Fixes for v2.0.1 #85

wants to merge 5 commits into from

Conversation

nomis
Copy link

@nomis nomis commented Mar 11, 2017

Some fixes for v2.01 based on testing with a slave device:

  • Don't include util/*.h files from ModbusMaster.h as it makes it difficult to enable all compiler warnings
  • Add callback functions to log sent/received messages otherwise it's impossible to debug communication
  • Fix potential buffer overflow receiving messages
  • Check that Stream::read() has not returned -1 (no data available)

nomis and others added 5 commits March 11, 2017 13:15
These files contain static functions that will cause unused function
warnings when ModbusMaster.h is included by applications.
The library only returns an error code with no other explanation so
it's impossible to debug unexpected errors in communication such as:
- Receiving continuous noise on the line (missing ground wire)
- Receiving additional zero bytes (missing bias resistors)

Allow callback functions to be specified so that messages can be
logged for debugging.
A slave device could indicate that there are 255 bytes in the response
here:
  u8BytesLeft = u8ModbusADU[2];

There are only 256 bytes of space in ModbusADU so the additional 255
bytes would overflow the buffer.

Increase the size of ModbusADUSize so that it is large enough to
handle the byte at index 255 without wrapping around to 0, and use it
to check that there is enough space for the response. When we run out
of space, return a new error type ku8MBResponseTooLarge (0xE4).
If Stream::read() returns -1 then 0xFF will be added to the buffer.

Check the return value before using it as data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants