altos: Keep telemetry and command output from interleaving
authorKeith Packard <keithp@keithp.com>
Wed, 27 Jul 2016 19:24:27 +0000 (12:24 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 27 Jul 2016 19:24:27 +0000 (12:24 -0700)
When monitoring telemetry, the frame needs to be sent together on one
line, not split with the output of a command (like 'a') mixed in.

Use a mutex for products with monitoring to keep command output and
telemetry output each on separate lines.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/kernel/ao.h
src/kernel/ao_cmd.c
src/kernel/ao_monitor.c

index 0f878df5be68f4aff61ba9c39247f333e6e5e243..56945bf5f513edb1a1576b7ba19873255ab59f58 100644 (file)
@@ -667,6 +667,7 @@ extern __xdata union ao_monitor ao_monitor_ring[AO_MONITOR_RING];
 #define ao_monitor_ring_next(n)        (((n) + 1) & (AO_MONITOR_RING - 1))
 #define ao_monitor_ring_prev(n)        (((n) - 1) & (AO_MONITOR_RING - 1))
 
+extern __data uint8_t ao_monitoring_mutex;
 extern __data uint8_t ao_monitoring;
 extern __data uint8_t ao_monitor_head;
 
index 605a2f205e58c69411b931cd2f273ac5197cdedd..10716afd5e8e0ffe9fab17fb459874a6dfa748d5 100644 (file)
@@ -394,11 +394,17 @@ ao_cmd(void)
                        if (func)
                                break;
                }
+#if HAS_MONITOR
+               ao_mutex_get(&ao_monitoring_mutex);
+#endif
                if (func)
                        (*func)();
                else
                        ao_cmd_status = ao_cmd_syntax_error;
                report();
+#if HAS_MONITOR
+               ao_mutex_put(&ao_monitoring_mutex);
+#endif
        }
 }
 
index 8a5a04ba55d22bf8adf1288f8d98c5fb154f46e7..9912161b9ea6d72ffad3290fdcfeee39f98557ac 100644 (file)
@@ -36,6 +36,7 @@
 #error Must define AO_MONITOR_LED
 #endif
 
+__data uint8_t ao_monitoring_mutex;
 __data uint8_t ao_monitoring;
 static __data uint8_t ao_monitor_disabled;
 static __data uint8_t ao_internal_monitoring;
@@ -241,6 +242,7 @@ ao_monitor_put(void)
                        printf ("rx cleanup: %d\n", ao_rx_done_tick - ao_fec_decode_end);
                }
 #endif
+                       ao_mutex_get(&ao_monitoring_mutex);
                        printf("TELEM ");
                        hex((uint8_t) (ao_monitoring + 2));
                        sum = 0x5a;
@@ -251,6 +253,7 @@ ao_monitor_put(void)
                        }
                        hex(sum);
                        putchar ('\n');
+                       ao_mutex_put(&ao_monitoring_mutex);
 #if HAS_RSSI
                        if (recv_raw.packet[ao_monitoring + 1] & AO_RADIO_STATUS_CRC_OK) {
                                rssi = AO_RSSI_FROM_RADIO(recv_raw.packet[ao_monitoring]);