Allow serial data to be sent back to the host.

This commit is contained in:
Jonathan Naylor 2020-11-13 12:09:10 +00:00
parent 3503e0cc2a
commit c5b542f438
6 changed files with 55 additions and 12 deletions

View File

@ -43,7 +43,7 @@ void CSerialPort::beginInt(uint8_t n, int speed)
} }
} }
int CSerialPort::availableInt(uint8_t n) int CSerialPort::availableForReadInt(uint8_t n)
{ {
switch (n) { switch (n) {
case 1U: case 1U:

View File

@ -81,7 +81,7 @@ const uint8_t MMDVM_FM_EOT = 0x67U;
const uint8_t MMDVM_ACK = 0x70U; const uint8_t MMDVM_ACK = 0x70U;
const uint8_t MMDVM_NAK = 0x7FU; const uint8_t MMDVM_NAK = 0x7FU;
const uint8_t MMDVM_SERIAL = 0x80U; const uint8_t MMDVM_SERIAL_DATA = 0x80U;
const uint8_t MMDVM_TRANSPARENT = 0x90U; const uint8_t MMDVM_TRANSPARENT = 0x90U;
const uint8_t MMDVM_QSO_INFO = 0x91U; const uint8_t MMDVM_QSO_INFO = 0x91U;
@ -122,13 +122,18 @@ const char HARDWARE[] = concat(HW_TYPE, VERSION, TCXO, __TIME__, __DATE__);
const uint8_t PROTOCOL_VERSION = 2U; const uint8_t PROTOCOL_VERSION = 2U;
// Parameters for batching serial data
const int MAX_SERIAL_DATA = 250;
const uint16_t MAX_SERIAL_COUNT = 100U;
CSerialPort::CSerialPort() : CSerialPort::CSerialPort() :
m_buffer(), m_buffer(),
m_ptr(0U), m_ptr(0U),
m_len(0U), m_len(0U),
m_debug(false), m_debug(false),
m_repeat() m_repeat(),
m_lastAvail(0),
m_lastAvailCount(0U)
{ {
} }
@ -849,7 +854,7 @@ void CSerialPort::start()
void CSerialPort::process() void CSerialPort::process()
{ {
while (availableInt(1U)) { while (availableForReadInt(1U)) {
uint8_t c = readInt(1U); uint8_t c = readInt(1U);
if (m_ptr == 0U) { if (m_ptr == 0U) {
@ -912,9 +917,22 @@ void CSerialPort::process()
} }
} }
// Read any incoming serial data // Read any incoming serial data, and send out in batches
while (availableInt(3U)) int avail = availableForReadInt(3U);
readInt(3U); if ((avail > 0 && avail == m_lastAvail && m_lastAvailCount >= MAX_SERIAL_COUNT) || (avail >= MAX_SERIAL_DATA)) {
uint8_t buffer[MAX_SERIAL_DATA];
for (int i = 0; i < avail && i < MAX_SERIAL_DATA; i++) {
buffer[i] = readInt(3U);
m_lastAvail--;
}
writeSerialData(buffer, avail - m_lastAvail);
m_lastAvailCount = 0U;
} else if (avail > 0U && avail == m_lastAvail) {
m_lastAvailCount++;
} else {
m_lastAvail = avail;
m_lastAvailCount = 0U;
}
#endif #endif
} }
@ -1284,7 +1302,7 @@ void CSerialPort::processMessage(const uint8_t* buffer, uint16_t length)
break; break;
#if defined(SERIAL_REPEATER) #if defined(SERIAL_REPEATER)
case MMDVM_SERIAL: { case MMDVM_SERIAL_DATA: {
for (uint8_t i = 3U; i < m_len; i++) for (uint8_t i = 3U; i < m_len; i++)
m_repeat.put(m_buffer[i]); m_repeat.put(m_buffer[i]);
} }
@ -1718,6 +1736,25 @@ void CSerialPort::writeAX25Data(const uint8_t* data, uint16_t length)
} }
#endif #endif
#if defined(SERIAL_REPEATER)
void CSerialPort::writeSerialData(const uint8_t* data, uint8_t length)
{
uint8_t reply[255U];
reply[0U] = MMDVM_FRAME_START;
reply[1U] = 0U;
reply[2U] = MMDVM_SERIAL_DATA;
uint8_t count = 3U;
for (uint8_t i = 0U; i < length; i++, count++)
reply[count] = data[i];
reply[1U] = count;
writeInt(1U, reply, count);
}
#endif
void CSerialPort::writeCalData(const uint8_t* data, uint8_t length) void CSerialPort::writeCalData(const uint8_t* data, uint8_t length)
{ {
if (m_modemState != STATE_DSTARCAL) if (m_modemState != STATE_DSTARCAL)

View File

@ -79,6 +79,10 @@ public:
void writeFMEOT(); void writeFMEOT();
#endif #endif
#if defined(SERIAL_REPEATER)
void writeSerialData(const uint8_t* data, uint8_t length);
#endif
void writeCalData(const uint8_t* data, uint8_t length); void writeCalData(const uint8_t* data, uint8_t length);
void writeRSSIData(const uint8_t* data, uint8_t length); void writeRSSIData(const uint8_t* data, uint8_t length);
@ -94,6 +98,8 @@ private:
uint16_t m_len; uint16_t m_len;
bool m_debug; bool m_debug;
CRingBuffer<uint8_t> m_repeat; CRingBuffer<uint8_t> m_repeat;
int m_lastAvail;
uint16_t m_lastAvailCount;
void sendACK(); void sendACK();
void sendNAK(uint8_t err); void sendNAK(uint8_t err);
@ -113,7 +119,7 @@ private:
// Hardware versions // Hardware versions
void beginInt(uint8_t n, int speed); void beginInt(uint8_t n, int speed);
int availableInt(uint8_t n); int availableForReadInt(uint8_t n);
int availableForWriteInt(uint8_t n); int availableForWriteInt(uint8_t n);
uint8_t readInt(uint8_t n); uint8_t readInt(uint8_t n);
void writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool flush = false); void writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool flush = false);

View File

@ -327,7 +327,7 @@ void CSerialPort::beginInt(uint8_t n, int speed)
} }
} }
int CSerialPort::availableInt(uint8_t n) int CSerialPort::availableForReadInt(uint8_t n)
{ {
switch (n) { switch (n) {
case 1U: case 1U:

View File

@ -118,7 +118,7 @@ void CSerialPort::beginInt(uint8_t n, int speed)
} }
} }
int CSerialPort::availableInt(uint8_t n) int CSerialPort::availableForReadInt(uint8_t n)
{ {
switch (n) { switch (n) {
case 1U: case 1U:

View File

@ -182,7 +182,7 @@ void CSerialPort::beginInt(uint8_t n, int speed)
} }
} }
int CSerialPort::availableInt(uint8_t n) int CSerialPort::availableForReadInt(uint8_t n)
{ {
switch (n) { switch (n) {
case 1U: case 1U: