1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

gcs uavtalk: Add full state-level debug logs

These logs are disabled by default, and can be
turned on at compile time by defining:
  UAVTALK_DEBUG
at the top of uavtalk.cpp.

These logs proved very helpful in diagnosing a
serial comms issue.
This commit is contained in:
Stacey Sheldon 2011-12-30 13:02:42 -05:00
parent fa9702db97
commit bd9f3569db

View File

@ -28,6 +28,11 @@
#include <QtEndian> #include <QtEndian>
#include <QDebug> #include <QDebug>
//#define UAVTALK_DEBUG
#ifdef UAVTALK_DEBUG
#include "qxtlogger.h"
#endif
#define SYNC_VAL 0x3C #define SYNC_VAL 0x3C
const quint8 UAVTalk::crc_table[256] = { const quint8 UAVTalk::crc_table[256] = {
@ -207,7 +212,12 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
case STATE_SYNC: case STATE_SYNC:
if (rxbyte != SYNC_VAL) if (rxbyte != SYNC_VAL)
{
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: Sync->Sync (" + QString::number(rxbyte) + " " + QString("0x%1").arg(rxbyte,2,16) + ")");
#endif
break; break;
}
// Initialize and update CRC // Initialize and update CRC
rxCS = updateCRC(0, rxbyte); rxCS = updateCRC(0, rxbyte);
@ -215,6 +225,9 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
rxPacketLength = 1; rxPacketLength = 1;
rxState = STATE_TYPE; rxState = STATE_TYPE;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: Sync->Type");
#endif
break; break;
case STATE_TYPE: case STATE_TYPE:
@ -225,6 +238,9 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
if ((rxbyte & TYPE_MASK) != TYPE_VER) if ((rxbyte & TYPE_MASK) != TYPE_VER)
{ {
rxState = STATE_SYNC; rxState = STATE_SYNC;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: Type->Sync");
#endif
break; break;
} }
@ -233,6 +249,9 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
packetSize = 0; packetSize = 0;
rxState = STATE_SIZE; rxState = STATE_SIZE;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: Type->Size");
#endif
rxCount = 0; rxCount = 0;
break; break;
@ -245,6 +264,9 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
{ {
packetSize += rxbyte; packetSize += rxbyte;
rxCount++; rxCount++;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: Size->Size");
#endif
break; break;
} }
@ -253,11 +275,17 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
if (packetSize < MIN_HEADER_LENGTH || packetSize > MAX_HEADER_LENGTH + MAX_PAYLOAD_LENGTH) if (packetSize < MIN_HEADER_LENGTH || packetSize > MAX_HEADER_LENGTH + MAX_PAYLOAD_LENGTH)
{ // incorrect packet size { // incorrect packet size
rxState = STATE_SYNC; rxState = STATE_SYNC;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: Size->Sync");
#endif
break; break;
} }
rxCount = 0; rxCount = 0;
rxState = STATE_OBJID; rxState = STATE_OBJID;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: Size->ObjID");
#endif
break; break;
case STATE_OBJID: case STATE_OBJID:
@ -267,7 +295,12 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
rxTmpBuffer[rxCount++] = rxbyte; rxTmpBuffer[rxCount++] = rxbyte;
if (rxCount < 4) if (rxCount < 4)
{
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: ObjID->ObjID");
#endif
break; break;
}
// Search for object, if not found reset state machine // Search for object, if not found reset state machine
rxObjId = (qint32)qFromLittleEndian<quint32>(rxTmpBuffer); rxObjId = (qint32)qFromLittleEndian<quint32>(rxTmpBuffer);
@ -277,6 +310,9 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
{ {
stats.rxErrors++; stats.rxErrors++;
rxState = STATE_SYNC; rxState = STATE_SYNC;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: ObjID->Sync (badtype)");
#endif
break; break;
} }
@ -297,6 +333,9 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
{ {
stats.rxErrors++; stats.rxErrors++;
rxState = STATE_SYNC; rxState = STATE_SYNC;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: ObjID->Sync (oversize)");
#endif
break; break;
} }
@ -305,6 +344,9 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
{ // packet error - mismatched packet size { // packet error - mismatched packet size
stats.rxErrors++; stats.rxErrors++;
rxState = STATE_SYNC; rxState = STATE_SYNC;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: ObjID->Sync (length mismatch)");
#endif
break; break;
} }
@ -314,6 +356,9 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
// This is a non-existing object, just skip to checksum // This is a non-existing object, just skip to checksum
// and we'll send a NACK next. // and we'll send a NACK next.
rxState = STATE_CS; rxState = STATE_CS;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: ObjID->CSum (no obj)");
#endif
rxInstId = 0; rxInstId = 0;
rxCount = 0; rxCount = 0;
} }
@ -321,15 +366,28 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
{ {
// If there is a payload get it, otherwise receive checksum // If there is a payload get it, otherwise receive checksum
if (rxLength > 0) if (rxLength > 0)
{
rxState = STATE_DATA; rxState = STATE_DATA;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: ObjID->Data (needs data)");
#endif
}
else else
{
rxState = STATE_CS; rxState = STATE_CS;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: ObjID->Checksum");
#endif
}
rxInstId = 0; rxInstId = 0;
rxCount = 0; rxCount = 0;
} }
else else
{ {
rxState = STATE_INSTID; rxState = STATE_INSTID;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: ObjID->InstID");
#endif
rxCount = 0; rxCount = 0;
} }
} }
@ -343,7 +401,12 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
rxTmpBuffer[rxCount++] = rxbyte; rxTmpBuffer[rxCount++] = rxbyte;
if (rxCount < 2) if (rxCount < 2)
{
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: InstID->InstID");
#endif
break; break;
}
rxInstId = (qint16)qFromLittleEndian<quint16>(rxTmpBuffer); rxInstId = (qint16)qFromLittleEndian<quint16>(rxTmpBuffer);
@ -351,10 +414,19 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
// If there is a payload get it, otherwise receive checksum // If there is a payload get it, otherwise receive checksum
if (rxLength > 0) if (rxLength > 0)
{
rxState = STATE_DATA; rxState = STATE_DATA;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: InstID->Data");
#endif
}
else else
{
rxState = STATE_CS; rxState = STATE_CS;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: InstID->CSum");
#endif
}
break; break;
case STATE_DATA: case STATE_DATA:
@ -364,9 +436,17 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
rxBuffer[rxCount++] = rxbyte; rxBuffer[rxCount++] = rxbyte;
if (rxCount < rxLength) if (rxCount < rxLength)
{
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: Data->Data");
#endif
break; break;
}
rxState = STATE_CS; rxState = STATE_CS;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: Data->CSum");
#endif
rxCount = 0; rxCount = 0;
break; break;
@ -379,6 +459,9 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
{ // packet error - faulty CRC { // packet error - faulty CRC
stats.rxErrors++; stats.rxErrors++;
rxState = STATE_SYNC; rxState = STATE_SYNC;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: CSum->Sync (badcrc)");
#endif
break; break;
} }
@ -386,6 +469,9 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
{ // packet error - mismatched packet size { // packet error - mismatched packet size
stats.rxErrors++; stats.rxErrors++;
rxState = STATE_SYNC; rxState = STATE_SYNC;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: CSum->Sync (length mismatch)");
#endif
break; break;
} }
@ -396,11 +482,17 @@ bool UAVTalk::processInputByte(quint8 rxbyte)
mutex->unlock(); mutex->unlock();
rxState = STATE_SYNC; rxState = STATE_SYNC;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: CSum->Sync (OK)");
#endif
break; break;
default: default:
rxState = STATE_SYNC; rxState = STATE_SYNC;
stats.rxErrors++; stats.rxErrors++;
#ifdef UAVTALK_DEBUG
qxtLog->debug("UAVTalk: ???->Sync");
#endif
} }
// Done // Done