Skip to content

Commit d71e71c

Browse files
committed
fix to catch boot msgs and display unknowns better
1 parent d8747e6 commit d71e71c

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

core/USBInterface/USBInterface.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,26 +219,34 @@ void USBPort::handle()
219219
{
220220
// error, discard data
221221
// display bad msg
222-
if (findhash < (sizeof(cbuf)-100))
223-
{
224-
char cbuf[1024];
225-
char hexbuf[512]; // make sure it's at least 2× the buffer size + 1
226-
222+
// if (findhash < (sizeof(cbuf)-100))
223+
char errbuf[1024];
224+
char errbuf2[1024];
225+
char hexbuf[1024];
226+
char charbuf[1024];
227227
int hexlen = 0;
228+
int charlen = 0;
229+
228230
for (int i = 0; i < m_unprocessedSize && hexlen < (int)sizeof(hexbuf) - 3; ++i)
229231
{
230232
hexlen += snprintf(hexbuf + hexlen, sizeof(hexbuf) - hexlen, "%02X ", (unsigned char)m_inBufferUnprocessed[i]);
233+
charlen += snprintf(charbuf + charlen, sizeof(charbuf) - charlen, "%c", isprint(m_inBufferUnprocessed[i]) ? m_inBufferUnprocessed[i] : '.');
231234
}
232-
snprintf(cbuf,sizeof(cbuf), "%s: Receive ERROR: bad msg format: fh= %d br= %d %.*s", m_port_name.c_str(), (int)findhash, m_unprocessedSize, m_unprocessedSize, hexbuf);
233-
}
234-
else
235-
{
236-
snprintf(cbuf,sizeof(cbuf),"%s: Receive ERROR: bad msg format: MESSAGE OVERSIZE, CAN'T BE DISPLAYED", m_port_name.c_str());
237-
}
238-
239-
if (m_log) m_log->error(cbuf, __FILENAME__,__LINE__);
240-
m_unprocessedSize = 0;
241-
235+
snprintf(errbuf,sizeof(errbuf), "%s: Receive ERROR: bad msg format: len= %d %.*s", m_port_name.c_str(), m_unprocessedSize, 3 *m_unprocessedSize, hexbuf);
236+
snprintf(errbuf2,sizeof(errbuf2), "%.*s", m_unprocessedSize, charbuf);
237+
// check for boot messages from ESP32
238+
if (charbuf[0] == ':' || charbuf[0] == 'D' || charbuf[0] == 'd' || charbuf[0] == 'e' || charbuf[0] == 'S')
239+
{
240+
// these are boot messages from ESP32
241+
if (m_log) m_log->info(errbuf2, __FILENAME__,__LINE__);
242+
if (m_log) m_log->info(errbuf);
243+
}
244+
else {
245+
// unknown messages
246+
if (m_log) m_log->error(errbuf2, __FILENAME__,__LINE__);
247+
if (m_log) m_log->error(errbuf);
248+
}
249+
m_unprocessedSize = 0;
242250
}
243251
}
244252
// adjust the data in inbuf

0 commit comments

Comments
 (0)