tooth log converter (#4960)

This commit is contained in:
Matthew Kennedy 2023-01-10 11:07:22 -08:00 committed by GitHub
parent 67624ee960
commit b3b5944058
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 0 deletions

3
misc/tooth_log_converter/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.teeth
*.csv
log_convert

View File

@ -0,0 +1,3 @@
#!/bin/bash
g++ -O2 -lstdc++ log_convert.cpp -o log_convert

View File

@ -0,0 +1,46 @@
#include <iostream>
#include <fstream>
#include <iomanip>
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<char*>(&entry), sizeof(composite_logger_s));
double sec = SWAP_UINT32(entry.timestamp) / ticksPerSecond;
dst << sec << "," << entry.priLevel << "," << entry.secLevel << std::endl;
}
}

View File

@ -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`