This issue takes place in the process() function of the Encoder class.
If a byte is begun with a stuffed bit, bitPosition is not incremented. This leads to the next byte being loaded before the current byte has been transmitted.
In other words, if bytePosition % 8 == 0 and a bit-stuff occurs, currentByte will be overwritten on the next iteration since the algorithm thinks the byte has finished.
A simple solution would be to introduce a flag that when raised prevents entry into the if(bitPosition == 0) block. It is lowered on each loop before currentBit is set, and raised when a bit-stuff occurs.
This issue takes place in the process() function of the Encoder class.
If a byte is begun with a stuffed bit, bitPosition is not incremented. This leads to the next byte being loaded before the current byte has been transmitted.
In other words, if bytePosition % 8 == 0 and a bit-stuff occurs, currentByte will be overwritten on the next iteration since the algorithm thinks the byte has finished.
A simple solution would be to introduce a flag that when raised prevents entry into the if(bitPosition == 0) block. It is lowered on each loop before currentBit is set, and raised when a bit-stuff occurs.