altos: flush pending output when terminating packet mode
[fw/altos] / src / ao_packet_master.c
index a499ce59d055e672580dd08136cf5a513a8554b7..5e13a91adecb3889727688e172e0f9a957458fb3 100644 (file)
@@ -18,7 +18,7 @@
 #include "ao.h"
 
 static char
-ao_packet_getchar(void)
+ao_packet_getchar(void) __critical
 {
        char c;
        while ((c = ao_packet_pollchar()) == AO_READ_AGAIN)
@@ -77,12 +77,14 @@ ao_packet_master(void)
 {
        uint8_t status;
 
+       ao_config_get();
        ao_radio_set_packet();
        ao_tx_packet.addr = ao_serial_number;
        ao_tx_packet.len = AO_PACKET_SYN;
        ao_packet_master_time = ao_time();
        ao_packet_master_delay = AO_PACKET_MASTER_DELAY_SHORT;
        while (ao_packet_enable) {
+               memcpy(ao_tx_packet.callsign, ao_config.callsign, AO_MAX_CALLSIGN);
                ao_packet_send();
                if (ao_tx_packet.len)
                        ao_packet_master_busy();
@@ -119,6 +121,10 @@ ao_packet_forward(void) __reentrant
                if (c == '\r') c = '\n';
                ao_packet_putchar(c);
        }
+
+       /* Wait for a second if there is any pending data */
+       for (c = 0; (ao_packet_tx_used || ao_tx_packet.len) && c < 10; c++)
+               ao_delay(AO_MS_TO_TICKS(100));
        ao_packet_enable = 0;
        ao_radio_abort();
        while (ao_packet_echo_task.wchan || ao_packet_task.wchan) {