altera2015 / usbserial

Flutter Android USB Serial plugin
BSD 3-Clause "New" or "Revised" License
121 stars 83 forks source link

MagicHeaderAndLengthByteTransformer work unnormal when header is [null] #42

Closed tiantian1645 closed 3 years ago

tiantian1645 commented 3 years ago

Hello,I found when header is [null] the pack will not add to controller in https://github.com/altera2015/usbserial/blob/890f290b0bd388af455adae8a8332970202de7b6/lib/transformers.dart#L352

I send a pack [18, 52, 86, 120] and set the header to [null], the len will be 52. So it will failed in https://github.com/altera2015/usbserial/blob/890f290b0bd388af455adae8a8332970202de7b6/lib/transformers.dart#L353

Thank you

altera2015 commented 3 years ago

Magic Header and Length Byte expects that the first byte is the magic byte and the second the header. If you set the "Magic Header" to null it will match any first byte and read the length from the second byte. So sending [18,52,86,120] will mean that the Transformer waits for another 50 bytes to arrive as this packet indicates that there will be 52 bytes of data following the header.

I've added a test for header [null] and it appears to work as intended. If not can you please explain what you expected this to do. (feel free to reopen comment if you disagree)