Validate Telemetry Data Freshness
mainBecause telemetry is provided via shared memory, you should validate the age of the data using the timestamp_us field (microseconds since epoch) provided in every data structure. This ensures you are not acting on stale data if the service or hardware stops updating.
Example logic to check if data is less than 100ms old:
auto battery = client.getBattery();
if (battery) {
auto age_ms = (getCurrentTimestamp() - battery->timestamp_us) / 1000;
if (age_ms < 100) {
// Data is fresh
}
}auto battery = client.getBattery();
if (battery) {
auto age_ms = (getCurrentTimestamp() - battery->timestamp_us) / 1000;
if (age_ms < 100) { // Data is fresh (< 100ms old)
// Use battery data
}
}