FreeCalypso > hg > sipout-test-utils
changeset 7:6d832abad660
test-fsk: gather and print full line of modem Rx characters
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 05 Mar 2024 10:57:45 -0800 |
parents | ba66d297fe57 |
children | eaf0e8f81a22 |
files | test-fsk/modem_rx.c |
diffstat | 1 files changed, 56 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/test-fsk/modem_rx.c Mon Mar 04 23:21:07 2024 -0800 +++ b/test-fsk/modem_rx.c Tue Mar 05 10:57:45 2024 -0800 @@ -14,7 +14,58 @@ extern int fsk_mode_rx; +#define MAX_TEXT_LINE 80 + static fsk_rx_state_t *fsk_rx_state; +static u_char rx_line_buf[MAX_TEXT_LINE]; +static unsigned rx_buf_fill; + +static void +safe_print_char(c) +{ + if (c >= ' ' && c <= '~') { + putchar(c); + return; + } + switch (c) { + case '\t': + putchar(c); + return; + case '\n': + return; + case '\r': + putchar('\\'); + putchar('r'); + return; + case '\b': + putchar('\\'); + putchar('b'); + return; + case '\f': + putchar('\\'); + putchar('f'); + return; + } + printf("\\x%02X", c); +} + +static void +print_rx_line() +{ + u_char *dp, *endp; + int c; + + fputs("MRx:\t", stdout); + dp = rx_line_buf; + endp = rx_line_buf + rx_buf_fill; + while (dp < endp) { + c = *dp++; + safe_print_char(c); + } + if (c != '\n') + putchar('\\'); + putchar('\n'); +} static void byte_rx_func(user_data, byte) @@ -25,7 +76,11 @@ printf("Modem state change: %s\n", signal_status_to_str(byte)); return; } - printf("Rx byte: 0x%02X\n", byte); + rx_line_buf[rx_buf_fill++] = byte; + if (byte == '\n' || rx_buf_fill >= MAX_TEXT_LINE) { + print_rx_line(); + rx_buf_fill = 0; + } } void