Skip to content

Commit

Permalink
Parity bug fix: overflow condition caused data and parity to get out …
Browse files Browse the repository at this point in the history
…of sync permanently.
  • Loading branch information
dok-net committed Dec 20, 2019
1 parent 53569bf commit fc5ff0d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/loopback/loopback.ino
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void loop() {
+ rxErrors + " errors (" + 100.0 * rxErrors / (!rxErrors ? 1 : rxCount) + "%)");
if (0 != (swSerialConfig & 070))
{
logger.print(" ("); logger.print(rxParityErrors) + logger.println(" parity errors)");
logger.print(" ("); logger.print(rxParityErrors); logger.println(" parity errors)");
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion examples/repeater/repeater.ino
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void loop() {
#ifndef HWLOOPBACK
if (0 != (swSerialConfig & 070))
{
logger.print(" ("); logger.print(parityErrors) + logger.println(" parity errors)");
logger.print(" ("); logger.print(parityErrors); logger.print(" parity errors)");
}
else
#endif
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "EspSoftwareSerial",
"version": "6.5.2",
"version": "6.5.3",
"keywords": [
"serial", "io", "softwareserial"
],
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=EspSoftwareSerial
version=6.5.2
version=6.5.3
author=Peter Lerup, Dirk Kaar
maintainer=Peter Lerup <[email protected]>
sentence=Implementation of the Arduino software serial for ESP8266/ESP32.
Expand Down
30 changes: 17 additions & 13 deletions src/SoftwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,22 +466,26 @@ void SoftwareSerial::rxBits(const uint32_t & isrCycle) {
if (level)
{
m_rxCurByte >>= (sizeof(uint8_t) * 8 - m_dataBits);
if (m_parityBuffer)
{
if (m_rxCurParity) {
m_parityBuffer->pushpeek() |= m_parityInPos;
}
else {
m_parityBuffer->pushpeek() &= ~m_parityInPos;
}
m_parityInPos <<= 1;
if (!m_parityInPos)
if (!m_buffer->push(m_rxCurByte)) {
m_overflow = true;
}
else {
if (m_parityBuffer)
{
m_parityBuffer->push();
m_parityInPos = 1;
if (m_rxCurParity) {
m_parityBuffer->pushpeek() |= m_parityInPos;
}
else {
m_parityBuffer->pushpeek() &= ~m_parityInPos;
}
m_parityInPos <<= 1;
if (!m_parityInPos)
{
m_parityBuffer->push();
m_parityInPos = 1;
}
}
}
if (!m_buffer->push(m_rxCurByte)) m_overflow = true;
}
m_rxCurBit = m_pduBits;
// reset to 0 is important for masked bit logic
Expand Down

0 comments on commit fc5ff0d

Please sign in to comment.