altos: Add 'send all baro' compile-time option
authorKeith Packard <keithp@keithp.com>
Tue, 2 Aug 2011 05:44:13 +0000 (22:44 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 27 Aug 2011 19:12:41 +0000 (12:12 -0700)
This option creates a new packet type that delivers full sensor-rate
barometer telemetry data to allow for off-line analysis of flight
algorithms using all of the data, rather than the slower rate provided
either over telemetry or stored in the eeprom file.

Define AO_SEND_ALL_BARO and this will get built in. Perhaps this could
be a run-time option...

Signed-off-by: Keith Packard <keithp@keithp.com>
src/core/ao.h
src/core/ao_telemetry.c

index c926c00152ed28986ea7f8713b4433d6f1eb74d2..0cff0436e5758e43791b90f16e606ffe14f9a718 100644 (file)
@@ -1118,6 +1118,30 @@ struct ao_telemetry_companion {
        /* 32 */
 };
        
+/* #define AO_SEND_ALL_BARO */
+
+#define AO_TELEMETRY_BARO              0x80
+
+/*
+ * This packet allows the full sampling rate baro
+ * data to be captured over the RF link so that the
+ * flight software can be tested using 'real' data.
+ *
+ * Along with this telemetry packet, the flight
+ * code is modified to send full-rate telemetry all the time
+ * and never send an RDF tone; this ensure that the full radio
+ * link is available.
+ */
+struct ao_telemetry_baro {
+       uint16_t                                serial;         /*  0 */
+       uint16_t                                tick;           /*  2 */
+       uint8_t                                 type;           /*  4 */
+       uint8_t                                 samples;        /*  5 number samples */
+
+       int16_t                                 baro[12];       /* 6 samples */
+       /* 32 */
+};
+
 union ao_telemetry_all {
        struct ao_telemetry_generic             generic;
        struct ao_telemetry_sensor              sensor;
@@ -1125,6 +1149,7 @@ union ao_telemetry_all {
        struct ao_telemetry_location            location;
        struct ao_telemetry_satellite           satellite;
        struct ao_telemetry_companion           companion;
+       struct ao_telemetry_baro                baro;
 };
 
 /*
@@ -1258,9 +1283,15 @@ struct ao_telemetry_raw_recv {
 
 /* Set delay between telemetry reports (0 to disable) */
 
+#ifdef AO_SEND_ALL_BARO
+#define AO_TELEMETRY_INTERVAL_PAD      AO_MS_TO_TICKS(100)
+#define AO_TELEMETRY_INTERVAL_FLIGHT   AO_MS_TO_TICKS(100)
+#define AO_TELEMETRY_INTERVAL_RECOVER  AO_MS_TO_TICKS(100)
+#else
 #define AO_TELEMETRY_INTERVAL_PAD      AO_MS_TO_TICKS(1000)
 #define AO_TELEMETRY_INTERVAL_FLIGHT   AO_MS_TO_TICKS(100)
 #define AO_TELEMETRY_INTERVAL_RECOVER  AO_MS_TO_TICKS(1000)
+#endif
 
 void
 ao_telemetry_set_interval(uint16_t interval);
index c7338a581f64cef7e1dd73ac2c4dd94e274d9209..de669ce16a5683bb3fd9e603a6cb97eeb4fdadaa 100644 (file)
@@ -94,6 +94,30 @@ ao_send_sensor(void)
        ao_radio_send(&telemetry, sizeof (telemetry));
 }
 
+static uint8_t         ao_baro_sample;
+
+#ifdef AO_SEND_ALL_BARO
+static void
+ao_send_baro(void)
+{
+       uint8_t         sample = ao_sample_adc;
+       uint8_t         samples = (sample - ao_baro_sample) & (AO_ADC_RING - 1);
+
+       if (samples > 12) {
+               ao_baro_sample = (ao_baro_sample + (samples - 12)) & (AO_ADC_RING - 1);
+               samples = 12;
+       }
+       telemetry.generic.tick = ao_adc_ring[sample].tick;
+       telemetry.generic.type = AO_TELEMETRY_BARO;
+       telemetry.baro.samples = samples;
+       for (sample = 0; sample < samples; sample++) {
+               telemetry.baro.baro[sample] = ao_adc_ring[ao_baro_sample].pres;
+               ao_baro_sample = ao_adc_ring_next(ao_baro_sample);
+       }
+       ao_radio_send(&telemetry, sizeof (telemetry));
+}
+#endif
+
 static void
 ao_send_configuration(void)
 {
@@ -193,6 +217,9 @@ ao_telemetry(void)
                while (ao_telemetry_interval) {
 
 
+#ifdef AO_SEND_ALL_BARO
+                       ao_send_baro();
+#endif
                        ao_send_sensor();
 #if HAS_COMPANION
                        if (ao_companion_running)
@@ -203,12 +230,14 @@ ao_telemetry(void)
                        ao_send_location();
                        ao_send_satellite();
 #endif
+#ifndef AO_SEND_ALL_BARO
                        if (ao_rdf &&
                            (int16_t) (ao_time() - ao_rdf_time) >= 0)
                        {
                                ao_rdf_time = ao_time() + AO_RDF_INTERVAL_TICKS;
                                ao_radio_rdf(AO_RDF_LENGTH_MS);
                        }
+#endif
                        time += ao_telemetry_interval;
                        delay = time - ao_time();
                        if (delay > 0)