altos: add 'report' to telebt
authorKeith Packard <keithp@keithp.com>
Sun, 28 Aug 2011 23:39:41 +0000 (16:39 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 28 Aug 2011 23:39:41 +0000 (16:39 -0700)
This beeps out flight state changes and max altitude at landing, just
like the altimeter.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/core/ao.h
src/core/ao_log_telem.c
src/core/ao_monitor.c
src/drivers/ao_btm.c
src/product/Makefile.telebt
src/product/ao_telebt.c

index 8b978272349607e8c9dc493fcd29cfa1d81fe9c3..f2e40fc6ceae467094f7cb2ea41eb8b1e12ea183 100644 (file)
@@ -1360,6 +1360,7 @@ extern __xdata union ao_monitor ao_monitor_ring[AO_MONITOR_RING];
 
 #define ao_monitor_ring_next(n)        (((n) + 1) & (AO_MONITOR_RING - 1))
 
+extern __data uint8_t ao_monitoring;
 extern __data uint8_t ao_monitor_head;
 
 void
index af0e8e6b62717db326515ca942cb415b45a67c23..9afa13b21abd9c6bd83a4995a8eba62c552ffc80 100644 (file)
 
 __code uint8_t ao_log_format = AO_LOG_FORMAT_TELEMETRY;
 
-static __data uint8_t  ao_log_monitor_pos;
+static __data uint8_t                  ao_log_monitor_pos;
+__pdata enum ao_flight_state           ao_flight_state;
+__pdata int16_t                                ao_max_height;  /* max of ao_height */
 
+static void
+ao_log_telem_track() {
+       if (ao_monitoring == sizeof (union ao_telemetry_all)) {
+               switch (ao_log_single_write_data.telemetry.generic.type) {
+               case AO_TELEMETRY_SENSOR_TELEMETRUM:
+               case AO_TELEMETRY_SENSOR_TELEMINI:
+               case AO_TELEMETRY_SENSOR_TELENANO:
+                       if (ao_log_single_write_data.telemetry.sensor.height > ao_max_height) {
+                               ao_max_height = ao_log_single_write_data.telemetry.sensor.height;
+                       }
+                       if (ao_log_single_write_data.telemetry.sensor.state != ao_flight_state) {
+                               ao_flight_state = ao_log_single_write_data.telemetry.sensor.state;
+                               if (ao_flight_state == ao_flight_pad)
+                                       ao_max_height = 0;
+                               ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
+                       }
+               }
+       }
+}
 void
 ao_log_single(void)
 {
@@ -33,6 +54,7 @@ ao_log_single(void)
 
        ao_log_running = 1;
        ao_log_single_restart();
+       ao_flight_state = ao_flight_startup;
        for (;;) {
                while (!ao_log_running)
                        ao_sleep(&ao_log_running);
@@ -46,6 +68,7 @@ ao_log_single(void)
                                       AO_LOG_SINGLE_SIZE);
                                ao_log_single_write();
                                ao_log_monitor_pos = ao_monitor_ring_next(ao_log_monitor_pos);
+                               ao_log_telem_track();
                        }
                        /* Wait for more telemetry data to arrive */
                        ao_sleep(DATA_TO_XDATA(&ao_monitor_head));
index 382af8a2a2b101426aaea54d3af82eb0a74fc3f7..56d7604d7793c3d743f23904b491d5b7125d2109 100644 (file)
@@ -22,7 +22,7 @@
 #error Must define HAS_MONITOR to 1
 #endif
 
-__xdata uint8_t ao_monitoring;
+__data uint8_t ao_monitoring;
 __pdata uint8_t ao_monitor_led;
 
 __xdata union ao_monitor ao_monitor_ring[AO_MONITOR_RING];
@@ -37,7 +37,7 @@ ao_monitor_get(void)
        for (;;) {
                switch (ao_monitoring) {
                case 0:
-                       ao_sleep(&ao_monitoring);
+                       ao_sleep(DATA_TO_XDATA(&ao_monitoring));
                        continue;
                case AO_MONITORING_ORIG:
                        size = sizeof (struct ao_telemetry_orig_recv);
@@ -262,7 +262,7 @@ ao_set_monitor(uint8_t monitoring)
        if (ao_monitoring)
                ao_radio_recv_abort();
        ao_monitoring = monitoring;
-       ao_wakeup(&ao_monitoring);
+       ao_wakeup(DATA_TO_XDATA(&ao_monitoring));
 }
 
 static void
index e70e3048efe70b0e3c3437f4e30a1f4773d05f41..5eb788156ad4f893e025a95d4b583e56b76bef41 100644 (file)
@@ -249,10 +249,6 @@ ao_btm(void)
         */
        ao_delay(AO_SEC_TO_TICKS(3));
 
-#if HAS_BEEP
-       ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200));
-#endif
-
        /*
         * The first time we connect, the BTM-180 comes up at 19200 baud.
         * After that, it will remember and come up at 57600 baud. So, see
index 46c87db0865782f393497c0baa35296d3badc552..04dd044ef212e1b412f15088796633beadfc40ad 100644 (file)
@@ -26,6 +26,7 @@ CORE_SRC = \
        ao_monitor.c \
        ao_mutex.c \
        ao_panic.c \
+       ao_report.c \
        ao_state.c \
        ao_stdio.c \
        ao_task.c
index 9154f4be6ccbbf19f69081ccb08affbdc5211bd4..6fe18a4d36b4b1954bd54d9adb9e0762b49ff492 100644 (file)
@@ -37,7 +37,8 @@ main(void)
        ao_storage_init();
 #endif
        ao_usb_init();
-       ao_monitor_init(AO_LED_RED, TRUE);
+       ao_monitor_init(AO_LED_RED, sizeof (union ao_telemetry_all));
+       ao_report_init();
        ao_radio_init();
        ao_packet_master_init();
        ao_btm_init();