mirror of https://github.com/g4klx/MMDVM.git
Simplify the serial repeater code.
This commit is contained in:
parent
3e079f58ad
commit
6b3a811ae7
|
@ -142,10 +142,8 @@ m_buffer(),
|
||||||
m_ptr(0U),
|
m_ptr(0U),
|
||||||
m_len(0U),
|
m_len(0U),
|
||||||
m_debug(false),
|
m_debug(false),
|
||||||
m_serialData(),
|
|
||||||
m_lastSerialAvail(0),
|
m_lastSerialAvail(0),
|
||||||
m_lastSerialAvailCount(0U),
|
m_lastSerialAvailCount(0U)
|
||||||
m_i2CData()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -956,20 +954,6 @@ void CSerialPort::process()
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(SERIAL_REPEATER)
|
#if defined(SERIAL_REPEATER)
|
||||||
// Write any outgoing serial data
|
|
||||||
uint16_t serialSpace = m_serialData.getData();
|
|
||||||
if (serialSpace > 0U) {
|
|
||||||
int avail = availableForWriteInt(3U);
|
|
||||||
if (avail < serialSpace)
|
|
||||||
serialSpace = avail;
|
|
||||||
|
|
||||||
for (uint16_t i = 0U; i < serialSpace; i++) {
|
|
||||||
uint8_t c = 0U;
|
|
||||||
m_serialData.get(c);
|
|
||||||
writeInt(3U, &c, 1U);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read any incoming serial data, and send out in batches
|
// Read any incoming serial data, and send out in batches
|
||||||
int serialAvail = availableForReadInt(3U);
|
int serialAvail = availableForReadInt(3U);
|
||||||
if ((serialAvail > 0 && serialAvail == m_lastSerialAvail && m_lastSerialAvailCount >= MAX_SERIAL_COUNT) || (serialAvail >= MAX_SERIAL_DATA)) {
|
if ((serialAvail > 0 && serialAvail == m_lastSerialAvail && m_lastSerialAvailCount >= MAX_SERIAL_COUNT) || (serialAvail >= MAX_SERIAL_DATA)) {
|
||||||
|
@ -987,22 +971,6 @@ void CSerialPort::process()
|
||||||
m_lastSerialAvailCount = 0U;
|
m_lastSerialAvailCount = 0U;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(I2C_REPEATER)
|
|
||||||
// Write any outgoing serial data
|
|
||||||
uint16_t i2CSpace = m_i2CData.getData();
|
|
||||||
if (i2CSpace > 0U) {
|
|
||||||
int avail = availableForWriteInt(10U);
|
|
||||||
if (avail < i2CSpace)
|
|
||||||
i2CSpace = avail;
|
|
||||||
|
|
||||||
for (uint16_t i = 0U; i < i2CSpace; i++) {
|
|
||||||
uint8_t c = 0U;
|
|
||||||
m_i2CData.get(c);
|
|
||||||
writeInt(10U, &c, 1U);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t length)
|
void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t length)
|
||||||
|
@ -1410,18 +1378,14 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if defined(SERIAL_REPEATER)
|
#if defined(SERIAL_REPEATER)
|
||||||
case MMDVM_SERIAL_DATA: {
|
case MMDVM_SERIAL_DATA:
|
||||||
for (uint16_t i = 0U; i < length; i++)
|
writeInt(3U, buffer, length);
|
||||||
m_serialData.put(buffer[i]);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(I2C_REPEATER)
|
#if defined(I2C_REPEATER)
|
||||||
case MMDVM_I2C_DATA: {
|
case MMDVM_I2C_DATA:
|
||||||
for (uint16_t i = 0U; i < length; i++)
|
writeInt(10U, buffer, length);
|
||||||
m_i2CData.put(buffer[i]);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -106,10 +106,8 @@ private:
|
||||||
uint16_t m_ptr;
|
uint16_t m_ptr;
|
||||||
uint16_t m_len;
|
uint16_t m_len;
|
||||||
bool m_debug;
|
bool m_debug;
|
||||||
CRingBuffer<uint8_t> m_serialData;
|
|
||||||
int m_lastSerialAvail;
|
int m_lastSerialAvail;
|
||||||
uint16_t m_lastSerialAvailCount;
|
uint16_t m_lastSerialAvailCount;
|
||||||
CRingBuffer<uint8_t> m_i2CData;
|
|
||||||
|
|
||||||
void sendACK(uint8_t type);
|
void sendACK(uint8_t type);
|
||||||
void sendNAK(uint8_t type, uint8_t err);
|
void sendNAK(uint8_t type, uint8_t err);
|
||||||
|
|
Loading…
Reference in New Issue