altos: Bring up basic TeleTerra v0.2 UI
[fw/altos] / src / core / ao_monitor.c
index 56d7604d7793c3d743f23904b491d5b7125d2109..f7795fe41259d6b6b772fbefe5a4352af15a750a 100644 (file)
 #error Must define HAS_MONITOR to 1
 #endif
 
+#ifndef LEGACY_MONITOR
+#error Must define LEGACY_MONITOR
+#endif
+
+#ifndef HAS_MONITOR_PUT
+#define HAS_MONIOTOR_PUT 1
+#endif
+
 __data uint8_t ao_monitoring;
 __pdata uint8_t ao_monitor_led;
 
@@ -39,12 +47,14 @@ ao_monitor_get(void)
                case 0:
                        ao_sleep(DATA_TO_XDATA(&ao_monitoring));
                        continue;
+#if LEGACY_MONITOR
                case AO_MONITORING_ORIG:
                        size = sizeof (struct ao_telemetry_orig_recv);
                        break;
                case AO_MONITORING_TINY:
                        size = sizeof (struct ao_telemetry_tiny_recv);
                        break;
+#endif
                default:
                        if (ao_monitoring > AO_MAX_TELEMETRY)
                                ao_monitoring = AO_MAX_TELEMETRY;
@@ -67,15 +77,17 @@ ao_monitor_blink(void)
        }
 }
 
+#if HAS_MONITOR_PUT
 void
 ao_monitor_put(void)
 {
+#if LEGACY_MONITOR
        __xdata char callsign[AO_MAX_CALLSIGN+1];
-
+       int16_t rssi;
+#endif
        uint8_t ao_monitor_tail;
        uint8_t state;
        uint8_t sum, byte;
-       int16_t rssi;
        __xdata union ao_monitor        *m;
 
 #define recv_raw       ((m->raw))
@@ -89,12 +101,13 @@ ao_monitor_put(void)
                m = &ao_monitor_ring[ao_monitor_tail];
                ao_monitor_tail = ao_monitor_ring_next(ao_monitor_tail);
                switch (ao_monitoring) {
+#if LEGACY_MONITOR
                case AO_MONITORING_ORIG:
                        state = recv_orig.telemetry_orig.flight_state;
 
                        /* Typical RSSI offset for 38.4kBaud at 433 MHz is 74 */
                        rssi = (int16_t) (recv_orig.rssi >> 1) - 74;
-                       memcpy(callsign, recv_orig.telemetry_orig.callsign, AO_MAX_CALLSIGN);
+                       ao_xmemcpy(callsign, recv_orig.telemetry_orig.callsign, AO_MAX_CALLSIGN);
                        if (state > ao_flight_invalid)
                                state = ao_flight_invalid;
                        if (recv_orig.status & PKT_APPEND_STATUS_1_CRC_OK) {
@@ -171,7 +184,7 @@ ao_monitor_put(void)
 
                        /* Typical RSSI offset for 38.4kBaud at 433 MHz is 74 */
                        rssi = (int16_t) (recv_tiny.rssi >> 1) - 74;
-                       memcpy(callsign, recv_tiny.telemetry_tiny.callsign, AO_MAX_CALLSIGN);
+                       ao_xmemcpy(callsign, recv_tiny.telemetry_tiny.callsign, AO_MAX_CALLSIGN);
                        if (state > ao_flight_invalid)
                                state = ao_flight_invalid;
                        if (recv_tiny.status & PKT_APPEND_STATUS_1_CRC_OK) {
@@ -231,6 +244,7 @@ ao_monitor_put(void)
                                printf("CRC INVALID RSSI %3d\n", rssi);
                        }
                        break;
+#endif /* LEGACY_MONITOR */
                default:
                        printf ("TELEM %02x", ao_monitoring + 2);
                        sum = 0x5a;
@@ -251,9 +265,10 @@ ao_monitor_put(void)
                ao_usb_flush();
        }
 }
+__xdata struct ao_task ao_monitor_put_task;
+#endif
 
 __xdata struct ao_task ao_monitor_get_task;
-__xdata struct ao_task ao_monitor_put_task;
 __xdata struct ao_task ao_monitor_blink_task;
 
 void
@@ -284,7 +299,9 @@ ao_monitor_init(uint8_t monitor_led, uint8_t monitoring) __reentrant
        ao_monitoring = monitoring;
        ao_cmd_register(&ao_monitor_cmds[0]);
        ao_add_task(&ao_monitor_get_task, ao_monitor_get, "monitor_get");
+#if HAS_MONITOR_PUT
        ao_add_task(&ao_monitor_put_task, ao_monitor_put, "monitor_put");
+#endif
        if (ao_monitor_led)
                ao_add_task(&ao_monitor_blink_task, ao_monitor_blink, "monitor_blink");
 }