mirror of
https://github.com/juribeparada/MMDVM_HS.git
synced 2025-12-06 07:12:08 +01:00
Improve the modem serial repeat
This commit is contained in:
parent
06e02d54f9
commit
c305359ce5
|
|
@ -85,7 +85,6 @@ m_buffer(),
|
||||||
m_ptr(0U),
|
m_ptr(0U),
|
||||||
m_len(0U),
|
m_len(0U),
|
||||||
m_serial_buffer(),
|
m_serial_buffer(),
|
||||||
m_serial_ptr(0U),
|
|
||||||
m_serial_len(0U),
|
m_serial_len(0U),
|
||||||
m_debug(false),
|
m_debug(false),
|
||||||
m_firstCal(false)
|
m_firstCal(false)
|
||||||
|
|
@ -871,55 +870,50 @@ void CSerialPort::process()
|
||||||
// Check for any incoming serial data from a device/screen on UART2
|
// 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.
|
// !!Notice!! on powerup the Nextion screen dumps FF FF FF 88 FF FF FF to the serial port.
|
||||||
while (availableInt(3U))
|
while (availableInt(3U))
|
||||||
{
|
{
|
||||||
uint8_t ch = readInt(3U);
|
|
||||||
// read UART2
|
// read UART2
|
||||||
|
m_serial_buffer[m_serial_len++] = readInt(3U);
|
||||||
|
|
||||||
m_serial_buffer[m_serial_ptr] = ch;
|
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))
|
||||||
m_serial_ptr++;
|
{
|
||||||
// fill the buffer one char at a time
|
if (m_serial_len > 3)
|
||||||
|
serial.writeSerialRpt(m_serial_buffer, m_serial_len);
|
||||||
|
|
||||||
if (m_serial_len > 128)
|
// 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;
|
m_serial_len = 0U;
|
||||||
// if length is > 128 reset it
|
continue;
|
||||||
else
|
|
||||||
m_serial_len++;
|
|
||||||
// increase length
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((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 == sizeof(m_serial_buffer))
|
||||||
{
|
{
|
||||||
serial.writeSerialRpt(m_serial_buffer, m_serial_len);
|
// buffer overflow
|
||||||
// if the last 3 bytes are FF's then the screen is done sending data so send the m_serial_buffer to serial.writeSerialRpt()
|
m_serial_len = 0U;
|
||||||
|
continue;
|
||||||
m_serial_ptr = 0U;
|
}
|
||||||
m_serial_len = 0U;
|
}
|
||||||
// set ptr and reset length of buffer data since last message was valid and get ready for new data
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(SERIAL_REPEATER) || defined(SERIAL_REPEATER_USART1)
|
#if defined(SERIAL_REPEATER) || defined(SERIAL_REPEATER_USART1)
|
||||||
void CSerialPort::writeSerialRpt(const uint8_t* data, uint8_t length)
|
void CSerialPort::writeSerialRpt(const uint8_t* data, uint8_t length)
|
||||||
{
|
{
|
||||||
if (m_modemState != STATE_IDLE)
|
if (length == 0 || length > 127)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint8_t reply[131U];
|
uint8_t reply[131U];
|
||||||
|
|
||||||
reply[0U] = MMDVM_FRAME_START;
|
reply[0U] = MMDVM_FRAME_START;
|
||||||
reply[1U] = 0U;
|
reply[1U] = length + 3;
|
||||||
reply[2U] = MMDVM_SERIAL;
|
reply[2U] = MMDVM_SERIAL;
|
||||||
|
|
||||||
uint8_t count = 3U;
|
for (uint8_t i = 0U; i < length; i++)
|
||||||
for (uint8_t i = 0U; i < length; i++, count++)
|
reply[i+3] = data[i];
|
||||||
reply[count] = data[i];
|
|
||||||
|
|
||||||
reply[1U] = count;
|
writeInt(1U, reply, length + 3);
|
||||||
|
|
||||||
writeInt(1U, reply, count);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,6 @@ private:
|
||||||
uint8_t m_ptr;
|
uint8_t m_ptr;
|
||||||
uint8_t m_len;
|
uint8_t m_len;
|
||||||
uint8_t m_serial_buffer[128U];
|
uint8_t m_serial_buffer[128U];
|
||||||
uint8_t m_serial_ptr;
|
|
||||||
uint8_t m_serial_len;
|
uint8_t m_serial_len;
|
||||||
|
|
||||||
bool m_debug;
|
bool m_debug;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue