Fixes the issue of getting garbage when back to back Serial.read()s are performed. If you Serial.read() before it's "ready" you run the risk of reading garbage values.
Steps for Testing
Note: I tested using an Arduino Nano. I don't know what happens with a teensy. Also you need some code that links to and uses the internal comms library found in robot/rover/internal_comms/
In robot/rover/internal_comms/src/CommandCenter.cpp replace all instances of waitForSerial() with Serial.read()
Serial.print the two bytes inside readArgSize()
Compile and upload your program.
Run it, send in some bytes and you should see that you get corrupted values. In other words you don't get the same as the bytes you sent in.
Undo changes from 1
Run the experiment again. You should get the values you sent in this time
Additional info
It's not trivial to use the Arduino IDE for the testing steps above so I had to do everything from the commandline. Here's how:
Compiling
Use the provided Cmakelists.txt. These generate elf files
Uploading
The arduino ide will only upload a binary it compiled itself so we need to manually upload with avrdude. My command looked like the following avrdude -C/home/bionic/arduino-1.8.12/hardware/tools/avr/etc/avrdude.conf -v -patmega328p -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:bin/PDS2.elf:e. Just remember to change the device from /dev/ttyUSB0 to whatever your device is and the path to avrdude.conf to the path on your system. Also put the path to your elf file in the last part : -Uflash:w:<path/to/elf.elf>:e
Sending bytes
The Arduino IDE's serial monitor only allows you to send ascii as far as I can tell. So I used python to send in raw bytes.
Basically in one terminal you should have tail -f <device> so for example tail -f /dev/ttyUSB0.
In another terminal you can run something like: python3 -c "import sys; sys.stdout.buffer.write(b'\x36\x00\x02\x00\x02\x06\x64\x00')" > /dev/ttyUSB0 and you should see any results in the first terminal. If you don't see anything despite having some prints. Try sending data via the Serial monitor first and then retry this method.
closes nothing
The approval from all software team leads is necessary before merging.
Reviewer Section
Aside from local testing and the General Integration Test it is implied that static analysis should be included in the verification process.
Assignee Section
Description
Fixes the issue of getting garbage when back to back
Serial.read()
s are performed. If youSerial.read()
before it's "ready" you run the risk of reading garbage values.Steps for Testing
Note: I tested using an Arduino Nano. I don't know what happens with a teensy. Also you need some code that links to and uses the internal comms library found in
robot/rover/internal_comms/
robot/rover/internal_comms/src/CommandCenter.cpp
replace all instances ofwaitForSerial()
withSerial.read()
readArgSize()
Additional info
It's not trivial to use the Arduino IDE for the testing steps above so I had to do everything from the commandline. Here's how:
Compiling
Use the provided Cmakelists.txt. These generate elf files
Uploading
The arduino ide will only upload a binary it compiled itself so we need to manually upload with avrdude. My command looked like the following
avrdude -C/home/bionic/arduino-1.8.12/hardware/tools/avr/etc/avrdude.conf -v -patmega328p -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:bin/PDS2.elf:e
. Just remember to change the device from/dev/ttyUSB0
to whatever your device is and the path to avrdude.conf to the path on your system. Also put the path to your elf file in the last part :-Uflash:w:<path/to/elf.elf>:e
Sending bytes
The Arduino IDE's serial monitor only allows you to send ascii as far as I can tell. So I used python to send in raw bytes. Basically in one terminal you should have
tail -f <device>
so for exampletail -f /dev/ttyUSB0
. In another terminal you can run something like:python3 -c "import sys; sys.stdout.buffer.write(b'\x36\x00\x02\x00\x02\x06\x64\x00')" > /dev/ttyUSB0
and you should see any results in the first terminal. If you don't see anything despite having some prints. Try sending data via the Serial monitor first and then retry this method.closes nothing
The approval from all software team leads is necessary before merging.
Reviewer Section
Aside from local testing and the General Integration Test it is implied that static analysis should be included in the verification process.
For Pull Requests that do not include code changes, it is not required to perform the tests above.