A simple C++ program for simulating and decoding 64-byte packed binary telemetry data with integrity validation.
- Pragma Packing - ensures zero-padding for binary compatability and packet size assurance
- Checksum Validation - 64-byte summation algorithm to detect data corruption
- Fixed-point Conversion - Translating centi-Celsius and milli-Volts into human-readable units
- TTP (Telemetry Transmission Protocol) implementation (see the documentation).
- Requires C++20 and CMake 3.20+
- Step 1. Build and run
generator.cppfirst to generatetelemetry.datinside the build folder. - Step 2. Run
decoder.cppto validate and output the data.
# create and enter build directory
mkdir build && cd build
# configure and compile both targets
cmake ..
cmake --build .
# execute generator first
./generator
# then execute decoder
./decoder
Data integrity validated...
Temperature 20°C
Voltage 3V
This directive forces the compiler to remove any padding around variables. This ensures the length of the telemetry data file is constant. By ensuring the frame is exactly 64 bytes long, it allows us to implement checksum logic for data validation and ensures consistency across hardware architectures, which is vital in the case of cross-platform binary communication.
Since we know the frame is guaranteed to be 64 bytes long and the checksum field is of type uint16_t (i.e. 2 bytes), by using sizeof(frame) - 2, it allows us to loop over every byte of data in the file, minus the checksum, so we can test the data for validity.
Values such as temperature and voltage are stored as integers using centi-Celsius and milli-Volts as it will allow for greater accuracy over storing floating point directly. If we used a 16-bit signed floating point number (half-precision floating point), we could store nearly the same range as with an unsigned integer. However, using a 16-bit unsigned integer will allow for the benefit of Linear Precision. Unlike the floating point representation, where precision decreases as the value increases, fixed-point integers maintain a constant resolution, leading to no data discrepancies between ground and space-based systems.