Fix the incoming serial data from the screen.

This commit is contained in:
Jonathan Naylor 2023-10-05 19:54:35 +01:00
parent 29bb3cf352
commit 7ff74ed1ba
2 changed files with 35 additions and 45 deletions

View file

@ -88,12 +88,16 @@ const uint8_t PROTOCOL_VERSION = 1U;
char UDID[] = "00000000000000000000000000000000";
#endif
// Parameters for batching serial data
const int MAX_SERIAL_DATA = 250;
const uint16_t MAX_SERIAL_COUNT = 100U;
CSerialPort::CSerialPort() :
m_buffer(),
m_ptr(0U),
m_len(0U),
m_serial_buffer(),
m_serial_len(0U),
m_lastSerialAvail(0),
m_lastSerialAvailCount(0U),
m_debug(false),
m_firstCal(false)
{
@ -479,9 +483,9 @@ uint8_t CSerialPort::setFreq(const uint8_t* data, uint8_t length)
pocsag_freq_tx |= data[11U] << 8;
pocsag_freq_tx |= data[12U] << 16;
pocsag_freq_tx |= data[13U] << 24;
}
else
} else {
pocsag_freq_tx = freq_tx;
}
return io.setFreq(freq_rx, freq_tx, rf_power, pocsag_freq_tx);
}
@ -613,8 +617,7 @@ void CSerialPort::process()
m_buffer[0U] = c;
m_ptr = 1U;
m_len = 0U;
}
else {
} else {
m_ptr = 0U;
m_len = 0U;
}
@ -964,32 +967,20 @@ void CSerialPort::process()
#if defined(SERIAL_REPEATER) || defined(SERIAL_REPEATER_USART1)
// Check for any incoming serial data from a device/screen on UART2
// !!Notice!! on powerup the Nextion screen dumps FF FF FF 88 FF FF FF to the serial port.
while (availableInt(3U))
{
// read UART2
m_serial_buffer[m_serial_len++] = readInt(3U);
if (m_serial_len >=3 && (m_serial_buffer[m_serial_len - 3] == 0xFF) && (m_serial_buffer[m_serial_len - 2] == 0xFF) && (m_serial_buffer[m_serial_len - 1] == 0xFF))
{
if (m_serial_len > 3)
serial.writeSerialRpt(m_serial_buffer, m_serial_len);
// if the last 3 bytes are FF's then the screen is done sending data so send the m_serial_buffer to serial.writeSerialRpt()
//
// TODO - BG5HHP
// modem serial data repeat should be generic instead of coupling with the nextion protocol.
//
m_serial_len = 0U;
continue;
}
if (m_serial_len == sizeof(m_serial_buffer))
{
// buffer overflow
m_serial_len = 0U;
continue;
int serialAvail = availableInt(3U);
if ((serialAvail > 0 && serialAvail == m_lastSerialAvail && m_lastSerialAvailCount >= MAX_SERIAL_COUNT) || (serialAvail >= MAX_SERIAL_DATA)) {
uint8_t buffer[MAX_SERIAL_DATA];
for (int i = 0; i < serialAvail && i < MAX_SERIAL_DATA; i++) {
buffer[i] = readInt(3U);
m_lastSerialAvail--;
}
serial.writeSerialRpt(buffer, serialAvail - m_lastSerialAvail);
m_lastSerialAvailCount = 0U;
} else if (serialAvail > 0 && serialAvail == m_lastSerialAvail) {
m_lastSerialAvailCount++;
} else {
m_lastSerialAvail = serialAvail;
m_lastSerialAvailCount = 0U;
}
#endif
}
@ -1010,7 +1001,6 @@ void CSerialPort::writeSerialRpt(const uint8_t* data, uint8_t length)
}
#endif
void CSerialPort::writeDStarHeader(const uint8_t* header, uint8_t length)
{
if (m_modemState != STATE_DSTAR && m_modemState != STATE_IDLE)

View file

@ -74,8 +74,8 @@ private:
uint8_t m_buffer[256U];
uint8_t m_ptr;
uint8_t m_len;
uint8_t m_serial_buffer[128U];
uint8_t m_serial_len;
int m_lastSerialAvail;
uint16_t m_lastSerialAvailCount;
bool m_debug;
bool m_firstCal;