求大神帮忙将EspSoftwareSerial库数据从起始位标识计算
最近在使用EspSoftwareSerial这个软串口库的时候发现该库没有将起始位计算在内,导致我从串口读出来的数据少了一个byte。void SoftwareSerial::rxBits(const uint32_t& isrCycle) {
bool level = (m_isrLastCycle & 1) ^ m_invert; //测试奇数还是偶数 返回0,1
// error introduced by edge value in LSB of isrCycle is negligible
int32_t cycles = isrCycle - m_isrLastCycle;
m_isrLastCycle = isrCycle;
uint8_t bits = cycles / m_bitCycles;
if (cycles % m_bitCycles > (m_bitCycles >> 1)) ++bits;
while (bits > 0) {
// start bit detection起始位检测
if (m_rxCurBit >= (m_pduBits - 1)) {
// leading edge of start bit 起始位的前沿
if (level) break;
m_rxCurBit = -1;
--bits;
continue;
}
// data bits 数据位
if (m_rxCurBit >= -1 && m_rxCurBit < (m_dataBits - 1)) {
int8_t dataBits = min(bits, static_cast<uint8_t>(m_dataBits - 1 - m_rxCurBit));
m_rxCurBit += dataBits;
bits -= dataBits;
m_rxCurByte >>= dataBits;
if (level) { m_rxCurByte |= (BYTE_ALL_BITS_SET << (8 - dataBits)); }
continue;
}
// parity bit 奇偶校验位
if (m_parityMode && m_rxCurBit == (m_dataBits - 1)) {
++m_rxCurBit;
--bits;
m_rxCurParity = level;
continue;
}
// stop bits
if (m_rxCurBit < (m_pduBits - m_stopBits - 1)) {
++m_rxCurBit;
--bits;
continue;
}
if (m_rxCurBit == (m_pduBits - m_stopBits - 1)) {
// Store the received value in the buffer unless we have an overflow
// if not high stop bit level, discard word
if (level)
{
m_rxCurByte >>= (sizeof(uint8_t) * 8 - m_dataBits);
if (!m_buffer->push(m_rxCurByte)) {
m_overflow = true;
}
else {
if (m_parityBuffer)
{
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;
}
}
}
}
m_rxCurBit = m_pduBits;
// reset to 0 is important for masked bit logic
m_rxCurByte = 1;
m_rxCurParity = false;
break;
}
break;
}
}
丢失的一个byte是一个检测芯片状态的寄存器,其他的数据都对,唯独丢失了这个byte导致我无法判断其他数据有没有溢出。
页:
[1]