Enable radio monitor by default in teleterra, teledongle and tidongle
[fw/altos] / ao_monitor.c
index 1c2d127457ebc8a5fba5cc220b42ec571a45a5e1..6aed581a69b1f6d71a1b597923860f31428c728e 100644 (file)
@@ -1,73 +1,90 @@
 /*
- * $Id: $
+ * Copyright © 2009 Keith Packard <keithp@keithp.com>
  *
- * Copyright © 2009 Keith Packard
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
  *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Keith Packard not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  Keith Packard makes no
- * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
  *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
 #include "ao.h"
 
-const char const * const ao_state_names[] = {
-       "startup", "idle", "pad", "boost", "coast",
-       "apogee", "drogue", "main", "landed", "invalid"
-};
+__xdata uint8_t ao_monitoring;
+__pdata uint8_t ao_monitor_led;
 
 void
 ao_monitor(void)
 {
        __xdata struct ao_radio_recv recv;
+       __xdata char callsign[AO_MAX_CALLSIGN+1];
        uint8_t state;
 
        for (;;) {
+               __critical while (!ao_monitoring)
+                       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,
-                       ao_state_names[state]);
-               if (!(recv.status & PKT_APPEND_STATUS_1_CRC_OK))
-                       printf("CRC INVALID ");
-               switch (recv.telemetry.type) {
-               case AO_TELEMETRY_SENSOR:
-                       printf("%5u a: %d p: %d t: %d v: %d d: %d m: %d\n",
-                              recv.telemetry.u.adc.tick,
-                              recv.telemetry.u.adc.accel,
-                              recv.telemetry.u.adc.pres,
-                              recv.telemetry.u.adc.temp,
-                              recv.telemetry.u.adc.v_batt,
-                              recv.telemetry.u.adc.sense_d,
-                              recv.telemetry.u.adc.sense_m);
-                       break;
-               case AO_TELEMETRY_GPS:
-                       ao_gps_print(&recv.telemetry.u.gps);
-                       break;
+               if (recv.status & PKT_APPEND_STATUS_1_CRC_OK) {
+                       printf ("CALL %s SERIAL %3d RSSI %3d STATUS %02x STATE %7s ",
+                               callsign,
+                               recv.telemetry.addr,
+                               (int) recv.rssi - 74, recv.status,
+                               ao_state_names[state]);
+                       printf("%5u a: %5d p: %5d t: %5d v: %5d d: %5d m: %5d ",
+                              recv.telemetry.adc.tick,
+                              recv.telemetry.adc.accel,
+                              recv.telemetry.adc.pres,
+                              recv.telemetry.adc.temp,
+                              recv.telemetry.adc.v_batt,
+                              recv.telemetry.adc.sense_d,
+                              recv.telemetry.adc.sense_m);
+                       ao_gps_print(&recv.telemetry.gps);
+                       ao_rssi_set((int) recv.rssi - 74);
+               } else {
+                       printf("CRC INVALID RSSI %3d\n", (int) recv.rssi - 74);
                }
                ao_usb_flush();
+               ao_led_toggle(ao_monitor_led);
        }
 }
 
 __xdata struct ao_task ao_monitor_task;
 
 void
-ao_monitor_init(void)
+ao_set_monitor(uint8_t monitoring)
+{
+       ao_monitoring = monitoring;
+       ao_wakeup(&ao_monitoring);
+}
+
+static void
+set_monitor(void)
+{
+       ao_cmd_hex();
+       ao_set_monitor(ao_cmd_lex_i != 0);
+}
+
+__code struct ao_cmds ao_monitor_cmds[] = {
+       { 'm',  set_monitor,    "m <0 off, 1 on>                    Enable/disable radio monitoring" },
+       { 0,    set_monitor,    NULL },
+};
+
+void
+ao_monitor_init(uint8_t monitor_led, uint8_t monitoring) __reentrant
 {
+       ao_monitor_led = monitor_led;
+       ao_monitoring = monitoring;
+       ao_cmd_register(&ao_monitor_cmds[0]);
        ao_add_task(&ao_monitor_task, ao_monitor, "monitor");
 }