openlcb / OpenLCB_Java

A git-managed copy of the SVN-based Java prototype implementation of OpenLCB. This implementation operates inside JMRI.
6 stars 9 forks source link

ProtocolInformationReply messages can be incorrectly parsed if not 8 bytes #210

Closed rm5248 closed 1 year ago

rm5248 commented 1 year ago

When sending a ProtocolSupportReply message over the LCC bus, if the payload is not 8 bytes long it is not parsed correctly(more information).

In JMRI, the following is displayed in the traffic monitor when only one byte of data is sent back:

[[196685f7] 02 F7 D4 18 20 00 00 00]  R: 02.01.57.10.05.80 - 02.01.12.FE.6C.0F ProtocolSupportReply with payload D4 18 20 00 00 00
[[19668a5d] 02 F7 80               ]  R: 04.00.32.40.50.01 - 02.01.12.FE.6C.0F ProtocolSupportReply with payload 00 00 00 00 00 80

It appears that when the data is parsed in OpenLCB, it assumes that the data is a long. It seems that because there is not enough data to parse, the fact that it is assuming a 6-byte protocol support causes the resulting output to be incorrect.

bobjacobsen commented 1 year ago

The parsing happens at can.MessageBuilder#265. One way to fix this would be to add and use a paddedDataAsLong method in CanFrame that handles the necessary padding.