Skip to content

Commit

Permalink
Add more info to runtime tests output (#605)
Browse files Browse the repository at this point in the history
* Added more debug info to Realtime test output

* Restore code
  • Loading branch information
waltjohnson authored Apr 14, 2024
1 parent 30b0305 commit 8fbbe20
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 21 deletions.
64 changes: 46 additions & 18 deletions tests/runtime/device_runtime_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "protocol_nmea.h"

Check failure on line 7 in tests/runtime/device_runtime_tests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

tests/runtime/device_runtime_tests.cpp:7:10 [clang-diagnostic-error]

'protocol_nmea.h' file not found

Check failure on line 7 in tests/runtime/device_runtime_tests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

tests/runtime/device_runtime_tests.cpp:7:10 [clang-diagnostic-error]

'protocol_nmea.h' file not found
#include "device_runtime_tests.h"
#include "ISFileManager.h"
#include "ISDataMappings.h"


#define LOG_DIRECTORY "realtime_logs"

Check warning on line 13 in tests/runtime/device_runtime_tests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

tests/runtime/device_runtime_tests.cpp:13:9 [cppcoreguidelines-macro-usage]

macro 'LOG_DIRECTORY' used to declare a constant; consider using a 'constexpr' constant

Check warning on line 13 in tests/runtime/device_runtime_tests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

tests/runtime/device_runtime_tests.cpp:13:9 [cppcoreguidelines-macro-usage]

macro 'LOG_DIRECTORY' used to declare a constant; consider using a 'constexpr' constant
Expand All @@ -17,7 +18,7 @@
*/
DeviceRuntimeTests::DeviceRuntimeTests()

Check warning on line 19 in tests/runtime/device_runtime_tests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

tests/runtime/device_runtime_tests.cpp:19:1 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: m_gps1Pos

Check warning on line 19 in tests/runtime/device_runtime_tests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

tests/runtime/device_runtime_tests.cpp:19:1 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: m_gps1Pos
{
m_hist.gps1Pos.leapS = C_GPS_LEAP_SECONDS;
m_gps1Pos.leapS = C_GPS_LEAP_SECONDS;

ISFileManager::CreateDirectory(LOG_DIRECTORY);
m_filename = CreateLogFilename(LOG_DIRECTORY);
Expand Down Expand Up @@ -60,21 +61,26 @@ std::string charArrayToHex(uint8_t* arr, int arrSize)

void DeviceRuntimeTests::ProcessParseError(is_comm_instance_t &comm)
{
int size = comm.rxBuf.scanPrior - comm.rxBuf.head;

std::string parser;
switch (comm.rxBuf.head[0])
{
case PSC_ISB_PREAMBLE_BYTE1: parser = "ISB"; break;
case PSC_NMEA_START_BYTE: parser = "NMEA"; break;
case UBLOX_START_BYTE1: parser = "UBX"; break;
case RTCM3_START_BYTE: parser = "RTCM3"; break;
case SPARTN_START_BYTE: parser = "SPARTN"; break;
case SONY_START_BYTE: parser = "SONY"; break;
case PSC_ISB_PREAMBLE_BYTE1:
parser = std::string("ISB id ") + std::to_string(comm.rxPkt.dataHdr.id) + " " + std::string(cISDataMappings::GetDataSetName(comm.rxPkt.dataHdr.id));
parser += ", size " + std::to_string(comm.rxPkt.dataHdr.size);
break;
case PSC_NMEA_START_BYTE: parser = std::string("NMEA ") + std::string((char*)comm.rxBuf.head, _MIN(size, MAX_MSG_LENGTH_NMEA)); break;
case UBLOX_START_BYTE1: parser = std::string("UBX"); break;
case RTCM3_START_BYTE: parser = std::string("RTCM3"); break;
case SPARTN_START_BYTE: parser = std::string("SPARTN"); break;
case SONY_START_BYTE: parser = std::string("SONY"); break;
// default: parser = charArrayToHex(comm.rxBuf.head, 4); break;
default: parser = "Unknown"; break;
default: parser = std::string("Unknown"); break;
}

m_errorCount.parse = comm.rxErrorCount;
LogEvent("Parse error #%d: %s, size %d", comm.rxErrorCount, parser.c_str(), comm.rxBuf.scanPrior - comm.rxBuf.head);
LogEvent("Parse Error #%d, size %d: %s", comm.rxErrorCount, size, parser.c_str());
}

void DeviceRuntimeTests::ProcessISB(const p_data_hdr_t &dataHdr, const uint8_t *dataBuf)
Expand All @@ -97,10 +103,26 @@ void DeviceRuntimeTests::ProcessISB(const p_data_hdr_t &dataHdr, const uint8_t *
}
}
break;
case DID_GPS1_POS: copyDataPToStructP2(&m_hist.gps1Pos, &dataHdr, dataBuf, sizeof(gps_pos_t)); break;

case DID_GPS1_POS: TestIsbGps(dataHdr, dataBuf); break;
}
}

void DeviceRuntimeTests::TestIsbGps(const p_data_hdr_t &dataHdr, const uint8_t *dataBuf)
{
msg_history_t &hist = m_hist.isb.gps1Pos;

copyDataPToStructP2(&m_gps1Pos, &dataHdr, dataBuf, sizeof(gps_pos_t));

// printf("ISB GpsPos1 (%d ms, %d wkday): %.*s", m_gps1Pos.timeOfWeekMs, utcWeekday, msgSize, msg);

CheckGpsDuplicate ("ISB GpsPos1 Error", m_errorCount.nmeaGgaTime, m_gps1Pos.timeOfWeekMs, m_gps1Pos.week, NULL, 0, hist);
CheckGpsTimeReverse("ISB GpsPos1 Error", m_errorCount.nmeaGgaTime, m_gps1Pos.timeOfWeekMs, m_gps1Pos.week, NULL, 0, hist);

// Update history
hist.update(m_gps1Pos.timeOfWeekMs, m_gps1Pos.week, NULL, 0);
}

void DeviceRuntimeTests::ProcessNMEA(const uint8_t* msg, int msgSize)
{
if (!m_enable)
Expand All @@ -124,13 +146,13 @@ void DeviceRuntimeTests::TestNmeaGga(const uint8_t* msg, int msgSize)
gps_pos_t gpsPos = {};

utc_time_t t;
int utcWeekday = gpsTowMsToUtcWeekday(gpsPos.timeOfWeekMs, m_hist.gps1Pos.leapS);
int utcWeekday = gpsTowMsToUtcWeekday(gpsPos.timeOfWeekMs, m_gps1Pos.leapS);
nmea_parse_gga((const char *)msg, msgSize, gpsPos, t, utcWeekday);

// printf("NMEA GGA (%d ms, %d wkday): %.*s", gpsPos.timeOfWeekMs, utcWeekday, msgSize, msg);

CheckGpsDuplicate("NEA GGA Error", m_errorCount.nmeaGgaTime, gpsPos.timeOfWeekMs, gpsPos.week, msg, msgSize, hist);
CheckGpsTimeReverse("NEA GGA Error", m_errorCount.nmeaGgaTime, gpsPos.timeOfWeekMs, gpsPos.week, msg, msgSize, hist);
CheckGpsDuplicate ("NMEA GGA Error", m_errorCount.nmeaGgaTime, gpsPos.timeOfWeekMs, gpsPos.week, msg, msgSize, hist);
CheckGpsTimeReverse("NMEA GGA Error", m_errorCount.nmeaGgaTime, gpsPos.timeOfWeekMs, gpsPos.week, msg, msgSize, hist);

// Update history
hist.update(gpsPos.timeOfWeekMs, gpsPos.week, (uint8_t*)msg, msgSize);
Expand All @@ -147,7 +169,7 @@ void DeviceRuntimeTests::TestNmeaZda(const uint8_t* msg, int msgSize)

printf("NMEA ZDA (%d ms): %.*s", gpsTowMs, msgSize, msg);

CheckGpsDuplicate("NMEA ZDA Error", m_errorCount.nmeaZdaTime, gpsTowMs, gpsWeek, msg, msgSize, hist);
CheckGpsDuplicate ("NMEA ZDA Error", m_errorCount.nmeaZdaTime, gpsTowMs, gpsWeek, msg, msgSize, hist);
CheckGpsTimeReverse("NMEA ZDA Error", m_errorCount.nmeaZdaTime, gpsTowMs, gpsWeek, msg, msgSize, hist);

// Update history
Expand Down Expand Up @@ -189,8 +211,11 @@ bool DeviceRuntimeTests::CheckGpsDuplicate(const char* description, int &count,
if (toyMs == histToyMs)
{ // Duplicate time
LogEvent("NMEA Error: %s: Duplicate time (#%d): %d ms %d week >> %d ms %d week", description, ++count, hist.gpsTowMs, hist.gpsWeek, towMs, gpsWeek);
LogEvent(" 1: %.*s", hist.msgSize-2, (char*)hist.msg);
LogEvent(" 2: %.*s", msgSize-2, (char*)msg);
if (msg)
{
LogEvent(" 1: %.*s", hist.msgSize-2, (char*)hist.msg);
LogEvent(" 2: %.*s", msgSize-2, (char*)msg);
}
return true;
}

Expand All @@ -205,8 +230,11 @@ bool DeviceRuntimeTests::CheckGpsTimeReverse(const char* description, int &count
if (toyMs < histToyMs)
{ // Reversed time
LogEvent("NMEA Error: %s: Reversed time (#%d): %d ms %d week >> %d ms %d week", description, ++count, hist.gpsTowMs, hist.gpsWeek, towMs, gpsWeek);
LogEvent(" 1: %.*s", hist.msgSize-2, (char*)hist.msg);
LogEvent(" 2: %.*s", msgSize-2, (char*)msg);
if (msg)
{
LogEvent(" 1: %.*s", hist.msgSize-2, (char*)hist.msg);
LogEvent(" 2: %.*s", msgSize-2, (char*)msg);
}
return true;
}

Expand Down
22 changes: 19 additions & 3 deletions tests/runtime/device_runtime_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@ class DeviceRuntimeTests
{
gpsTowMs = gpsTowMs_;
gpsWeek = gpsWeek_;
memcpy(msg, msg_, _MIN(msgSize_, MAX_MSG_LENGTH_NMEA));
msgSize = msgSize_;
memset(&dataHdr, 0, sizeof(p_data_hdr_t));
memcpy(msg, msg_, _MIN(msgSize_, MAX_MSG_LENGTH_NMEA));
}
void update(uint32_t gpsTowMs_, uint32_t gpsWeek_, p_data_hdr_t &dataHdr_, const uint8_t *dataBuf_)
{
gpsTowMs = gpsTowMs_;
gpsWeek = gpsWeek_;
msgSize = 0;
dataHdr = dataHdr_;
memcpy(msg, dataBuf_, _MIN(dataHdr.size, MAX_MSG_LENGTH_NMEA));
}

utc_date_t date;
Expand All @@ -34,6 +43,7 @@ class DeviceRuntimeTests
uint32_t gpsWeek;
uint8_t msg[MAX_MSG_LENGTH_NMEA];
int msgSize;
p_data_hdr_t dataHdr;
} msg_history_t;

public:
Expand Down Expand Up @@ -65,6 +75,7 @@ class DeviceRuntimeTests
} m_errorCount = {};

private:
void TestIsbGps(const p_data_hdr_t &dataHdr, const uint8_t *dataBuf);
void TestNmeaGga(const uint8_t* msg, int msgSize);
void TestNmeaZda(const uint8_t* msg, int msgSize);
bool CheckGpsDuplicate(const char* description, int &count, uint32_t towMs, uint32_t gpsWeek, const uint8_t* msg, int msgSize, msg_history_t &hist);
Expand All @@ -84,10 +95,15 @@ class DeviceRuntimeTests
RuntimeTest m_testGgaTimeReverse{"GGA Time Reverse"};
RuntimeTest m_testZdaTimeReverse{"ZDA Time Reverse"};

gps_pos_t m_gps1Pos;

struct
{
gps_pos_t gps1Pos;

struct
{
msg_history_t gps1Pos;
} isb;

struct
{
msg_history_t zda;
Expand Down

0 comments on commit 8fbbe20

Please sign in to comment.