-
Notifications
You must be signed in to change notification settings - Fork 87
readBin() is not "type-length-safe" #38
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
Comments
I fixed this issue by myself in my fork and so it is included in pull #37. |
If I try to send a string as a binary argument to the PC app, it works fine. The other way around, though, does not. I have a void OnRecieve() on the arduino that echoes back the argument. I used it to test sending binary chars, ints, etc from the PC side. Everything works, except string. It just print a ClRf. Im guesssing this was the issue. Thank you for your contribution. |
Changes applied from: <https://github.com/sigmaeo/Arduino-CmdMessenger/tree/eb8e413f1313dbf5012ae6b751a6246b41a4e5ad> - Fix startCommand was not initialized not a problem on arduino, but with C++-Builder on Windows - Add missing unescape() are missing (issue thijse#39) - Make readBin() safe for less received bytes (see issue thijse#38) - Replace Serial.print() with comms->print()
If you use:
uint32_t ui32 = cm.readBinArg();
Then readBinArg() or readBin() will read 4 Bytes from the receiving buffer, ignoring the real length of what is sent and any seperator that may come earlier.
If you send (with ID=1):
(with A=0x41, B=0x42, C=0x43, D=0x44) you will get as expected:
0x44434241 = 1145258561.
But if you send:
you don't get 0x41 = 65, instead you will get a random value with 0x41 as LSB, 0x00 after it and 2 more "random" bytes from memory.
And ArgOk is not updated.
This should be enhanced with a test if the length (that slpit_r() sees) is big enough, but for this some more changes are needed.
The text was updated successfully, but these errors were encountered: