ao-tools/lib: Add cc_telemetry_unparse
[fw/altos] / ao-tools / lib / cc-telemetry.h
index 5a66b971df0e032987c27823cb062e311a4b9ce6..9a5be49f9a76d2e9cd2122e951838cf9d5e2eed7 100644 (file)
@@ -29,7 +29,9 @@ struct ao_telemetry_generic {
        uint16_t        tick;           /* 2 */
        uint8_t         type;           /* 4 */
        uint8_t         payload[27];    /* 5 */
-       /* 32 */
+       uint8_t         rssi;           /* 32 */
+       uint8_t         status;         /* 33 */
+       /* 34 */
 };
 
 #define AO_TELEMETRY_SENSOR_TELEMETRUM 0x01
@@ -148,6 +150,57 @@ struct ao_telemetry_companion {
        /* 32 */
 };
        
+#define AO_TELEMETRY_MEGA_SENSOR       0x08
+
+struct ao_telemetry_mega_sensor {
+       uint16_t        serial;         /*  0 */
+       uint16_t        tick;           /*  2 */
+       uint8_t         type;           /*  4 */
+
+       uint8_t         pad5;           /*  5 */
+       int16_t         accel;          /*  6 Z axis */
+
+       int32_t         pres;           /*  8 Pa * 10 */
+       int16_t         temp;           /* 12 °C * 100 */
+
+       int16_t         accel_x;        /* 14 */
+       int16_t         accel_y;        /* 16 */
+       int16_t         accel_z;        /* 18 */
+
+       int16_t         gyro_x;         /* 20 */
+       int16_t         gyro_y;         /* 22 */
+       int16_t         gyro_z;         /* 24 */
+
+       int16_t         mag_x;          /* 26 */
+       int16_t         mag_y;          /* 28 */
+       int16_t         mag_z;          /* 30 */
+       /* 32 */
+};
+       
+#define AO_TELEMETRY_MEGA_DATA         0x09
+
+struct ao_telemetry_mega_data {
+       uint16_t        serial;         /*  0 */
+       uint16_t        tick;           /*  2 */
+       uint8_t         type;           /*  4 */
+
+       uint8_t         state;          /*  5 flight state */
+
+       int16_t         v_batt;         /*  6 battery voltage */
+       int16_t         v_pyro;         /*  8 pyro battery voltage */
+       int8_t          sense[6];       /* 10 continuity sense */
+
+       int32_t         ground_pres;    /* 16 average pres on pad */
+       int16_t         ground_accel;   /* 20 average accel on pad */
+       int16_t         accel_plus_g;   /* 22 accel calibration at +1g */
+       int16_t         accel_minus_g;  /* 24 accel calibration at -1g */
+
+       int16_t         acceleration;   /* 26 m/s² * 16 */
+       int16_t         speed;          /* 28 m/s * 16 */
+       int16_t         height;         /* 30 m */
+       /* 32 */
+};
+
 /* #define AO_SEND_ALL_BARO */
 
 #define AO_TELEMETRY_BARO              0x80
@@ -179,10 +232,24 @@ union ao_telemetry_all {
        struct ao_telemetry_location            location;
        struct ao_telemetry_satellite           satellite;
        struct ao_telemetry_companion           companion;
+       struct ao_telemetry_mega_sensor         mega_sensor;
+       struct ao_telemetry_mega_data           mega_data;
        struct ao_telemetry_baro                baro;
 };
 
+#define CC_TELEMETRY_HEADER    "TELEM"
+
+/* "TELEM " 1 byte length 32 data bytes 1 rssi 1 status 1 checksum 1 null */
+
+#define CC_TELEMETRY_BUFSIZE   (6 + (1 + 32 + 3) * 2 + 1)
+
 int
 cc_telemetry_parse(const char *input_line, union ao_telemetry_all *telemetry);
 
+uint8_t
+cc_telemetry_cksum(const union ao_telemetry_all *telemetry);
+
+void
+cc_telemetry_unparse(const union ao_telemetry_all *telemetry, char output_line[CC_TELEMETRY_BUFSIZE]);
+
 #endif