-
Notifications
You must be signed in to change notification settings - Fork 22
Fix rtu request pdu length calculation #20
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
base: master
Are you sure you want to change the base?
Conversation
|
Currently, I have neither a device to test this nor the time to look into the specifications. |
1ad8054 to
50578af
Compare
|
Sorry for the late response. The branch should be rebased on the latest changes now. I've added some tests in the same style as existing tests. |
src/error.rs
Outdated
| /// Protocol not Modbus | ||
| ProtocolNotModbus(u16), | ||
| /// Length Mismatch | ||
| QuantityBytesMismatch(u16, u8, u16), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of this:
enum Error {
// ..
QuantityBytesMismatch {
quantity: u16,
bytes: u16,
bytes_expected: u16
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the named variables are a great call.
Is it on purpose that bytes is a u16? I can change that as well, but it would need to be cast from u8 for all current instantiations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the named variables are a great call.
yes, we should change it also in the other variants.
Is it on purpose that
bytesis au16?
Well, the data type used for counting bytes should be the same (In this case, probably u8 after all.)
Unfortunately, I'm very busy right now, but I'll take a closer look at your PR soon.
| if adu_buf.len() > 4 { | ||
| Some(6 + adu_buf[4] as usize) | ||
| 0x0F => { | ||
| if adu_buf.len() > 6 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we can do
let number_of_bytes = adu_buf.get(6)?;
PR to fix the request PDU length calculation mentioned in #12.
My application doesn't use coils but I've attempted to implement the fix for FC 0x0F as well. I have not looked at the TCP implementation at all (I have no experience with it). An error was also added for when the quantity and bytes fields don't match up.