diff --git a/misc/tooth_log_converter/.gitignore b/misc/tooth_log_converter/.gitignore new file mode 100644 index 0000000000..36dd5a9d2a --- /dev/null +++ b/misc/tooth_log_converter/.gitignore @@ -0,0 +1,3 @@ +*.teeth +*.csv +log_convert diff --git a/misc/tooth_log_converter/build.sh b/misc/tooth_log_converter/build.sh new file mode 100755 index 0000000000..739e820806 --- /dev/null +++ b/misc/tooth_log_converter/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +g++ -O2 -lstdc++ log_convert.cpp -o log_convert diff --git a/misc/tooth_log_converter/log_convert.cpp b/misc/tooth_log_converter/log_convert.cpp new file mode 100644 index 0000000000..375c539e3a --- /dev/null +++ b/misc/tooth_log_converter/log_convert.cpp @@ -0,0 +1,46 @@ +#include +#include +#include + +typedef struct __attribute__ ((packed)) { + // the whole order of all packet bytes is reversed, not just the 'endian-swap' integers + uint32_t timestamp; + // unfortunately all these fields are required by TS... + bool priLevel : 1; + bool secLevel : 1; + bool trigger : 1; + bool sync : 1; + bool coil : 1; + bool injector : 1; +} composite_logger_s; + +static_assert(sizeof(composite_logger_s) == 5); + +static inline uint32_t SWAP_UINT32(uint32_t x) +{ + return (((x >> 24) & 0x000000ff) | ((x << 8) & 0x00ff0000) | + ((x >> 8) & 0x0000ff00) | ((x << 24) & 0xff000000)); +} + +static constexpr double ticksPerSecond = 1e6; + +int main(int argc, char** argv) +{ + std::ifstream src(argv[1], std::ios::binary); + std::ofstream dst(argv[2], std::ios::binary); + + dst << std::setprecision(10); + + dst << "timestamp,pri,sec" << std::endl; + + while (!src.eof()) + { + composite_logger_s entry; + + src.read(reinterpret_cast(&entry), sizeof(composite_logger_s)); + + double sec = SWAP_UINT32(entry.timestamp) / ticksPerSecond; + + dst << sec << "," << entry.priLevel << "," << entry.secLevel << std::endl; + } +} diff --git a/misc/tooth_log_converter/readme.md b/misc/tooth_log_converter/readme.md new file mode 100644 index 0000000000..1edf156ddc --- /dev/null +++ b/misc/tooth_log_converter/readme.md @@ -0,0 +1,11 @@ +# SD Tooth Log Converter + +This program converts SD stored tooth logs to csv for analysis or replay as part of a unit test. + +Create a log by setting "SD logger mode" to "trigger", then restart the ECU with an SD card present (but without USB connected), then crank/run/etc the engine to save a log. Restart again with USB to pull the log off. + +# Usage + +`./build.sh` + +`./log_convert myToothLog.teeth convertedCsv.csv`