altos: Add EasyMotor logging support
authorKeith Packard <keithp@keithp.com>
Sun, 2 Aug 2020 20:06:01 +0000 (13:06 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 22 Oct 2020 04:33:58 +0000 (21:33 -0700)
Log EasyMotor sensor data.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/kernel/ao_log.h
src/kernel/ao_log_motor.c

index 26ff444088f52f2805a3d2b4b496e1a3893ff1ce..12eefe74621a2261decfab7dbba290b5b2ac8f0c 100644 (file)
@@ -502,6 +502,36 @@ struct ao_log_gps {
        } u;
 };
 
+struct ao_log_motor {
+       char                    type;                   /* 0 */
+       uint8_t                 csum;                   /* 1 */
+       uint16_t                tick;                   /* 2 */
+       union {                                         /* 4 */
+               /* AO_LOG_FLIGHT */
+               struct {
+                       uint16_t        flight;                 /* 4 */
+                       int16_t         ground_accel;           /* 6 */
+                       int16_t         ground_accel_along;     /* 8 */
+                       int16_t         ground_accel_across;    /* 10 */
+                       int16_t         ground_accel_through;   /* 12 */
+               } flight;
+               /* AO_LOG_STATE */
+               struct {
+                       uint16_t        state;                  /* 4 */
+                       uint16_t        reason;                 /* 6 */
+               } state;
+               /* AO_LOG_SENSOR */
+               struct {
+                       uint16_t        pressure;               /* 4 */
+                       uint16_t        v_batt;                 /* 6 */
+                       int16_t         accel;                  /* 8 */
+                       int16_t         accel_across;           /* 10 */
+                       int16_t         accel_along;            /* 12 */
+                       int16_t         accel_through;          /* 14 */
+               } sensor;                                       /* 16 */
+       } u;
+};
+
 #if AO_LOG_FORMAT == AO_LOG_FOMAT_TELEMEGA_OLD || AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMEGA || AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMEGA_3 || AO_LOG_FORMAT == AO_LOG_FORMAT_EASYMEGA_2 || AO_LOG_FORMAT == AO_LOG_FORMAT_TELEMEGA_4
 typedef struct ao_log_mega ao_log_type;
 #endif
index 6d42c77cb2a5ed0b9b3d13695da503adf9a7ad37..7ce75b6ac5c49b5b5ce2eebf6e8e9e04b6555229 100644 (file)
@@ -36,8 +36,7 @@ typedef uint8_t check_log_size[1-(256 % sizeof(struct ao_log_mega))] ;
 void
 ao_log(void)
 {
-       uint16_t        next_sensor, next_other;
-       uint8_t                 i;
+       uint16_t        next_sensor;
 
        ao_storage_setup();
 
@@ -46,22 +45,17 @@ ao_log(void)
        while (!ao_log_running)
                ao_sleep(&ao_log_running);
 
-#if HAS_FLIGHT
        ao_log_data.type = AO_LOG_FLIGHT;
        ao_log_data.tick = ao_sample_tick;
-#if HAS_ACCEL
        ao_log_data.u.flight.ground_accel = ao_ground_accel;
-#endif
-       ao_log_data.u.flight.ground_pres = ao_ground_pres;
        ao_log_data.u.flight.flight = ao_flight_number;
        ao_log_write(&ao_log_data);
-#endif
 
        /* Write the whole contents of the ring to the log
         * when starting up.
         */
        ao_log_data_pos = ao_data_ring_next(ao_data_head);
-       next_other = next_sensor = ao_data_ring[ao_log_data_pos].tick;
+       next_sensor = ao_data_ring[ao_log_data_pos].tick;
        ao_log_state = ao_flight_startup;
        for (;;) {
                /* Write samples to EEPROM */
@@ -70,21 +64,15 @@ ao_log(void)
                        if ((int16_t) (ao_log_data.tick - next_sensor) >= 0) {
                                ao_log_data.type = AO_LOG_SENSOR;
                                ao_log_data.u.sensor.accel = ao_data_accel(&ao_data_ring[ao_log_data_pos]);
+                               ao_log_data.u.sensor.accel_across = ao_data_across(&ao_data_ring[ao_log_data_pos]);
+                               ao_log_data.u.sensor.accel_along = ao_data_along(&ao_data_ring[ao_log_data_pos]);
+                               ao_log_data.u.sensor.accel_through = ao_data_through(&ao_data_ring[ao_log_data_pos]);
                                ao_log_write(&ao_log_data);
                                if (ao_log_state <= ao_flight_coast)
                                        next_sensor = ao_log_data.tick + AO_SENSOR_INTERVAL_ASCENT;
                                else
                                        next_sensor = ao_log_data.tick + AO_SENSOR_INTERVAL_DESCENT;
                        }
-                       if ((int16_t) (ao_log_data.tick - next_other) >= 0) {
-                               ao_log_data.type = AO_LOG_TEMP_VOLT;
-                               ao_log_data.u.volt.v_batt = ao_data_ring[ao_log_data_pos].adc.v_batt;
-                               ao_log_data.u.volt.n_sense = AO_ADC_NUM_SENSE;
-                               for (i = 0; i < AO_ADC_NUM_SENSE; i++)
-                                       ao_log_data.u.volt.sense[i] = ao_data_ring[ao_log_data_pos].adc.sense[i];
-                               ao_log_write(&ao_log_data);
-                               next_other = ao_log_data.tick + AO_OTHER_INTERVAL;
-                       }
                        ao_log_data_pos = ao_data_ring_next(ao_log_data_pos);
                }
 #if HAS_FLIGHT