firmware: expand sensor telemetry
This commit is contained in:
@@ -22,7 +22,7 @@ void initRs485(HardwareSerial& serial) {
|
||||
}
|
||||
|
||||
void publishSensorStatus(HardwareSerial& serial, const ImuState& imu, const GpsState& gps) {
|
||||
StaticJsonDocument<1024> doc;
|
||||
StaticJsonDocument<2048> doc;
|
||||
doc["type"] = "sensor_status"; doc["schema_version"] = SENSOR_NODE_SCHEMA_VERSION;
|
||||
doc["node_id"] = SENSOR_NODE_NAME; doc["firmware_version"] = SENSOR_NODE_FIRMWARE_VERSION;
|
||||
doc["uptime_ms"] = millis();
|
||||
@@ -31,6 +31,17 @@ void publishSensorStatus(HardwareSerial& serial, const ImuState& imu, const GpsS
|
||||
i["accuracy"] = imu.accuracy;
|
||||
JsonObject q = i.createNestedObject("quaternion"); q["i"] = imu.i; q["j"] = imu.j; q["k"] = imu.k; q["real"] = imu.real;
|
||||
i["yaw_degrees"] = imu.yawDegrees; i["pitch_degrees"] = imu.pitchDegrees; i["roll_degrees"] = imu.rollDegrees;
|
||||
i["age_ms"] = imu.lastUpdateMs ? millis() - imu.lastUpdateMs : -1;
|
||||
auto addVector = [&](const char* name, const Vector3State& v) {
|
||||
JsonObject o = i.createNestedObject(name);
|
||||
o["x"] = v.x; o["y"] = v.y; o["z"] = v.z; o["accuracy"] = v.accuracy;
|
||||
o["age_ms"] = v.lastUpdateMs ? millis() - v.lastUpdateMs : -1;
|
||||
};
|
||||
addVector("linear_acceleration_mps2", imu.linearAcceleration);
|
||||
addVector("angular_velocity_rads", imu.angularVelocity);
|
||||
addVector("gravity_mps2", imu.gravity);
|
||||
i["stability"] = imu.stability; i["stability_code"] = imu.stabilityCode;
|
||||
i["stability_age_ms"] = imu.stabilityLastUpdateMs ? millis() - imu.stabilityLastUpdateMs : -1;
|
||||
JsonObject level = i.createNestedObject("level_calibration");
|
||||
level["valid"] = levelCalibration.valid; level["active"] = levelCalibration.active;
|
||||
level["pitch_offset_degrees"] = levelCalibration.pitchOffsetDegrees;
|
||||
@@ -40,6 +51,9 @@ void publishSensorStatus(HardwareSerial& serial, const ImuState& imu, const GpsS
|
||||
JsonObject g = doc.createNestedObject("gps");
|
||||
g["online"] = gps.online; g["fix"] = gps.fix; g["satellites"] = gps.satellites;
|
||||
g["baud"] = gps.baud;
|
||||
if (gps.hdopValid) g["hdop"] = gps.hdop; else g["hdop"] = nullptr;
|
||||
g["location_age_ms"] = gps.locationAgeMs == ULONG_MAX ? -1 : (long)gps.locationAgeMs;
|
||||
g["time_age_ms"] = gps.timeAgeMs == ULONG_MAX ? -1 : (long)gps.timeAgeMs;
|
||||
JsonObject nmea = g.createNestedObject("nmea");
|
||||
nmea["characters"] = gps.charactersProcessed;
|
||||
nmea["sentences_passed"] = gps.sentencesPassed;
|
||||
|
||||
Reference in New Issue
Block a user