That said, it can be a very annoying issue with multiple mods installed and longer game load times. Manually closing and re-opening the port in game does not fix the issue when this occurs.
After some debugging I've found that, for some reason, the Arduino is sending several messages containing nothing but a single byte value:
The screenshot above demonstrates the contents of 3 incoming messages, followed by a properly formed Handshake. The initial 3 messages contain nothing but the byte 0x47
In my debugging I've seen 3 possible values: 0x7, 0x47, and 0x83. After a quick glance at https://github.com/Simpit-team/KerbalSimpitRevamped-Arduino/ I found no obvious cause for this data spam or significance behind the listed byte values.
In these instances KSPSerialPort::RecievedDataEvent never receives a 0x0 byte and thus the overflow is allowed to happen.
Currently, a newly opened port never resets the CurrentBytesRead value, which prevents simply closing/re-opening the port from resolving the issue.
Changes in this PR will:
Ensure CurrentBytesRead gets reset each time a port is opened
Reset CurrentBytesRead in the event of a PayloadBuffer overflow, discarding all remaining message contents at that time
Running https://github.com/Simpit-team/KerbalSimpitRevamped-Arduino/blob/main/examples/KerbalSimpitHelloWorld/KerbalSimpitHelloWorld.ino#L34 I often get an IndexOutOfRange exception on handshake and the port status hangs on WAITING_HANDSHAKE. This does not occur every time, and often only once per Arduino power cycle. Relaunching KSP often fixes it.
That said, it can be a very annoying issue with multiple mods installed and longer game load times. Manually closing and re-opening the port in game does not fix the issue when this occurs.
After some debugging I've found that, for some reason, the Arduino is sending several messages containing nothing but a single byte value: The screenshot above demonstrates the contents of 3 incoming messages, followed by a properly formed Handshake. The initial 3 messages contain nothing but the byte 0x47
In my debugging I've seen 3 possible values: 0x7, 0x47, and 0x83. After a quick glance at https://github.com/Simpit-team/KerbalSimpitRevamped-Arduino/ I found no obvious cause for this data spam or significance behind the listed byte values.
In these instances KSPSerialPort::RecievedDataEvent never receives a 0x0 byte and thus the overflow is allowed to happen.
Currently, a newly opened port never resets the
CurrentBytesRead
value, which prevents simply closing/re-opening the port from resolving the issue.Changes in this PR will: