Add RDF beacon and callsign to telemetry
authorKeith Packard <keithp@keithp.com>
Sat, 25 Apr 2009 21:42:20 +0000 (14:42 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 25 Apr 2009 21:42:20 +0000 (14:42 -0700)
ao.h
ao_monitor.c
ao_telemetry.c

diff --git a/ao.h b/ao.h
index 6b861de..338a40b 100644 (file)
--- a/ao.h
+++ b/ao.h
@@ -29,7 +29,7 @@
 /* Stack runs from above the allocated __data space to 0xfe, which avoids
  * writing to 0xff as that triggers the stack overflow indicator
  */
-#define AO_STACK_START 0x7e
+#define AO_STACK_START 0x80
 #define AO_STACK_END   0xfe
 #define AO_STACK_SIZE  (AO_STACK_END - AO_STACK_START + 1)
 
@@ -702,13 +702,27 @@ ao_gps_init(void);
  * ao_telemetry.c
  */
 
+#define AO_MAX_CALLSIGN                8
+
 struct ao_telemetry {
        uint8_t                 addr;
        uint8_t                 flight_state;
        struct ao_adc           adc;
        struct ao_gps_data      gps;
+       char                    callsign[AO_MAX_CALLSIGN];
 };
 
+/* Set delay between telemetry reports (0 to disable) */
+
+#define AO_TELEMETRY_INTERVAL_FLIGHT   AO_MS_TO_TICKS(50)
+#define AO_TELEMETRY_INTERVAL_RECOVER  AO_MS_TO_TICKS(1000)
+
+void
+ao_telemetry_set_interval(uint16_t interval);
+
+void
+ao_rdf_set(uint8_t rdf);
+
 void
 ao_telemetry_init(void);
 
@@ -721,7 +735,7 @@ ao_radio_send(__xdata struct ao_telemetry *telemetry) __reentrant;
 
 struct ao_radio_recv {
        struct ao_telemetry     telemetry;
-       uint8_t                 rssi;
+       int8_t                  rssi;
        uint8_t                 status;
 };
 
index 15b56f0..d62f69d 100644 (file)
@@ -29,6 +29,7 @@ void
 ao_monitor(void)
 {
        __xdata struct ao_radio_recv recv;
+       __xdata char callsign[AO_MAX_CALLSIGN+1];
        uint8_t state;
 
        for (;;) {
@@ -36,10 +37,13 @@ ao_monitor(void)
                        ao_sleep(&ao_monitoring);
                ao_radio_recv(&recv);
                state = recv.telemetry.flight_state;
+               memcpy(callsign, recv.telemetry.callsign, AO_MAX_CALLSIGN);
                if (state > ao_flight_invalid)
                        state = ao_flight_invalid;
-               printf ("SERIAL %3d RSSI %3d STATUS %02x STATE %s ",
-                       recv.telemetry.addr, recv.rssi, recv.status,
+               printf ("CALL %s SERIAL %3d RSSI %3d STATUS %02x STATE %s ",
+                       callsign,
+                       recv.telemetry.addr,
+                       (int) recv.rssi - 74, recv.status,
                        ao_state_names[state]);
                if (!(recv.status & PKT_APPEND_STATUS_1_CRC_OK))
                        printf("CRC INVALID ");
index 752c714..ffee9be 100644 (file)
 
 /* XXX make serial numbers real */
 
-uint8_t        ao_serial_number = 2;
+__xdata uint8_t        ao_serial_number = 2;
+
+/* XXX make callsigns real */
+__xdata char ao_callsign[AO_MAX_CALLSIGN] = "KD7SQG";
+
+__xdata uint16_t ao_telemetry_interval = 0;
+__xdata uint8_t ao_rdf = 0;
+__xdata uint16_t ao_rdf_time;
+
+#define AO_RDF_INTERVAL        AO_SEC_TO_TICKS(3)
 
 void
 ao_telemetry(void)
 {
        static __xdata struct ao_telemetry telemetry;
-       static uint8_t state;
-
-       while (ao_flight_state == ao_flight_startup || ao_flight_state == ao_flight_idle)
-               ao_sleep(DATA_TO_XDATA(&ao_flight_state));
 
+       telemetry.addr = ao_serial_number;
+       memcpy(telemetry.callsign, ao_callsign, AO_MAX_CALLSIGN);
+       ao_rdf_time = ao_time();
        for (;;) {
-               telemetry.addr = ao_serial_number;
+               while (ao_telemetry_interval == 0)
+                       ao_sleep(&ao_telemetry_interval);
                telemetry.flight_state = ao_flight_state;
                ao_adc_get(&telemetry.adc);
                ao_mutex_get(&ao_gps_mutex);
                memcpy(&telemetry.gps, &ao_gps_data, sizeof (struct ao_gps_data));
                ao_mutex_put(&ao_gps_mutex);
                ao_radio_send(&telemetry);
-               ao_delay(AO_MS_TO_TICKS(100));
+               ao_delay(ao_telemetry_interval);
+               if (ao_rdf &&
+                   (int16_t) (ao_time() - ao_rdf_time) >= 0)
+               {
+                       ao_rdf_time = ao_time() + AO_RDF_INTERVAL;
+                       ao_radio_rdf();
+               }
        }
 }
 
+void
+ao_telemetry_set_interval(uint16_t interval)
+{
+       ao_telemetry_interval = interval;
+       ao_wakeup(&ao_telemetry_interval);
+}
+
+void
+ao_rdf_set(uint8_t rdf)
+{
+       ao_rdf = rdf;
+       if (rdf == 0)
+               ao_radio_rdf_abort();
+}
+
 __xdata struct ao_task ao_telemetry_task;
 
 void