|
|
Once we have logger all our data in a `.log` binary file, we need to translate it in a human-readable format. This is usually the `CSV` (Comam Separated Values) format.
|
|
|
Once we have logged all our data in a `.log` binary file, we need to translate it in a human-readable format. This is usually the `CSV` (_Comam Separated Values_) format.
|
|
|
|
|
|
To do so, a _C++_ program called **LogDecoder** is used. The main sources are located in `skyward-boardcore\todo\` while more specific files are stored in each project's repo (eg `r2a-hermes`).
|
|
|
To do so, a _C++_ program called **LogDecoder** is used. The main source is located in `skyward-boardcore/src/shared/logger/decoder/logdecoder.cpp`.
|
|
|
There is a little setup required before being able to use **LogDecoder** to decode our logs:
|
|
|
|
|
|
#### 1. Add decoding functions to each logged struct
|
|
|
Every data type (usually structs) logged in the binary file must have two functions needed to convert binary data to CSV:
|
|
|
1. `static void header(std::ostream& os)`
|
|
|
Writes the header of the CSV file (first row containing column names) on the output stream.
|
|
|
2. `void print(std::ostream& os)`
|
|
|
Writes a row of the CSV file, filled with the data currently stored in the instance of the struct.
|
|
|
1. `static void header(std::ostream& os)`: writes the header of the CSV file (first row containing column names) on the output stream.
|
|
|
2. `void print(std::ostream& os)`: writes a row of the CSV file, filled with the data currently stored in the instance of the struct.
|
|
|
|
|
|
For example:
|
|
|
```cpp
|
... | ... | @@ -38,11 +37,11 @@ struct GyroscopeData |
|
|
Important things to keep in mind:
|
|
|
- Don't forget commas between columns
|
|
|
- Don't forget to add a newline at the end of each row (including the header)
|
|
|
- Char-type variables like `int8_t` and `uint8_t` need to be casted to `int` before printing in the output stream, in order to avoid printing special characters that could cause problems in some text editors or data processing tools. (eg: if flag == 0 it would print the first character in the ASCII table: `'\0'`)
|
|
|
- Char-type variables like `int8_t` and `uint8_t` need to be casted to `int` before printing in the output stream, in order to avoid printing special characters that could cause problems in some text editors or data processing tools. (e.g. if flag == 0 it would print the first character in the ASCII table: `'\0'`)
|
|
|
|
|
|
#### 2. Register all logged data types in the deserializer
|
|
|
#### 2. Register logged data types
|
|
|
The deserializer needs to know each and every data type that is being logged in order to be able decode it.
|
|
|
To do this, we need to modify the file `LogTypes.h` and add a new line for each struct in the `registerTypes(...)` function.
|
|
|
To do this, we need to create/modify the `LogTypes.h` file and add a new line for each struct in the `registerTypes(...)` function. An example can be found [here](https://github.com/skyward-er/on-board-software/tree/master/src/entrypoints/death-stack-x-decoder).
|
|
|
The line to be added it's the same for each data type, changing only the name:
|
|
|
|
|
|
```cpp
|
... | ... | @@ -76,15 +75,16 @@ The only caveat is that it needs to be compiled on a Linux machine, as Linux has |
|
|
To compile LogDecoder, just run `make` in its directory.
|
|
|
|
|
|
#### 4. Decoding logs
|
|
|
|
|
|
Move the logs in the same folder as the LogDecoder executable, then run
|
|
|
|
|
|
`> logdecoder logXX.dat`
|
|
|
To decode just one log
|
|
|
To decode just one log in the directory in which the binary log file is placed:
|
|
|
```
|
|
|
logdecoder path/to/logXX.dat
|
|
|
```
|
|
|
|
|
|
or
|
|
|
`> logdecoder -a`
|
|
|
to decode all the logs in the directory (it will decode only logs with file name in the form `logXX.dat`, with `XX` from 0 to 99)
|
|
|
```
|
|
|
logdecoder -a
|
|
|
```
|
|
|
to decode all the logs in the current directory (it will decode only logs with file name in the form `logXX.dat`, with `XX` from 0 to 99)
|
|
|
|
|
|
If the decoding process finishes with no errors, one `.csv` file for each data type logged will be created.
|
|
|
If there are problems, the log may be corrupted or, most probably, you forgot to register some data types in step #2. |
|
|
\ No newline at end of file |
|
|
If there are problems, the log may be corrupted or, most probably, you forgot to register some data types in step [2](#2.-Register-logged-data-types). |
|
|
\ No newline at end of file |