diff options
author | Leah Rowe <leah@libreboot.org> | 2023-05-16 10:50:35 +0100 |
---|---|---|
committer | Leah Rowe <leah@libreboot.org> | 2023-05-16 23:11:35 +0100 |
commit | 179323819b009278b9655d9c1359304205fba5f2 (patch) | |
tree | 260ec0f9e4a99862c91c093cd8df5c0b4429caa6 /util/spkmodem_recv/spkmodem-recv.c | |
parent | 3d5542944339dda7da74b1fdf3f08a28c834ad17 (diff) |
util/spkmodem_recv: Move logic out of main
Main should only be a skeletal structure.
Actual logic should always be handled externally.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/spkmodem_recv/spkmodem-recv.c')
-rw-r--r-- | util/spkmodem_recv/spkmodem-recv.c | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/util/spkmodem_recv/spkmodem-recv.c b/util/spkmodem_recv/spkmodem-recv.c index 0e98d884..ae0b03d5 100644 --- a/util/spkmodem_recv/spkmodem-recv.c +++ b/util/spkmodem_recv/spkmodem-recv.c @@ -27,54 +27,60 @@ int amplitude = 0; int lp = 0; void read_sample(void); +void print_chars(void); int main(int argc, char *argv[]) { - int ascii_bit = 7; - char ascii = 0; - int i; - int llp = 0; - (void)argc; (void)argv; - while (!feof(stdin)) { - if (lp > 3 * SAMPLES_PER_FRAME) { - ascii_bit = 7; - ascii = 0; - lp = 0; - llp++; - } - if (llp == FLUSH_TIMEOUT) - fflush(stdout); + while (!feof(stdin)) + print_chars(); + + return 0; +} + +void +print_chars(void) +{ + static int ascii_bit = 7; + static char ascii = 0; + static int llp = 0; - if (f2 <= FREQ_SEP_MIN || f2 >= FREQ_SEP_MAX - || f1 <= FREQ_DATA_MIN || f1 >= FREQ_DATA_MAX) { - read_sample(); - continue; - } + if (lp > 3 * SAMPLES_PER_FRAME) { + ascii_bit = 7; + ascii = 0; + lp = 0; + llp++; + } + if (llp == FLUSH_TIMEOUT) + fflush(stdout); + + if (f2 <= FREQ_SEP_MIN || f2 >= FREQ_SEP_MAX + || f1 <= FREQ_DATA_MIN || f1 >= FREQ_DATA_MAX) { + read_sample(); + return; + } #if DEBUG - printf ("%d %d %d @%d\n", f1, f2, FREQ_DATA_THRESHOLD, - ftell(stdin) - sizeof(frame)); + printf ("%d %d %d @%d\n", f1, f2, FREQ_DATA_THRESHOLD, + ftell(stdin) - sizeof(frame)); #endif - if (f1 < FREQ_DATA_THRESHOLD) - ascii |= (1 << ascii_bit); - ascii_bit--; - if (ascii_bit < 0) { + if (f1 < FREQ_DATA_THRESHOLD) + ascii |= (1 << ascii_bit); + ascii_bit--; + if (ascii_bit < 0) { #if DEBUG - printf("<%c, %x>", ascii, ascii); + printf("<%c, %x>", ascii, ascii); #else - printf("%c", ascii); + printf("%c", ascii); #endif - ascii_bit = 7; - ascii = 0; - } - lp = 0; - llp = 0; - for (i = 0; i < SAMPLES_PER_FRAME; i++) - read_sample(); + ascii_bit = 7; + ascii = 0; } - return 0; + lp = 0; + llp = 0; + for (int i = 0; i < SAMPLES_PER_FRAME; i++) + read_sample(); } void |