Skip to content
Snippets Groups Projects
Commit 3dc92fc3 authored by Leah Rowe's avatar Leah Rowe
Browse files

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: default avatarLeah Rowe <leah@libreboot.org>
parent d53d88f7
No related merge requests found
...@@ -27,54 +27,60 @@ int amplitude = 0; ...@@ -27,54 +27,60 @@ int amplitude = 0;
int lp = 0; int lp = 0;
void read_sample(void); void read_sample(void);
void print_chars(void);
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int ascii_bit = 7;
char ascii = 0;
int i;
int llp = 0;
(void)argc; (void)argv; (void)argc; (void)argv;
while (!feof(stdin)) { while (!feof(stdin))
if (lp > 3 * SAMPLES_PER_FRAME) { print_chars();
ascii_bit = 7;
ascii = 0; return 0;
lp = 0; }
llp++;
} void
if (llp == FLUSH_TIMEOUT) print_chars(void)
fflush(stdout); {
static int ascii_bit = 7;
static char ascii = 0;
static int llp = 0;
if (f2 <= FREQ_SEP_MIN || f2 >= FREQ_SEP_MAX if (lp > 3 * SAMPLES_PER_FRAME) {
|| f1 <= FREQ_DATA_MIN || f1 >= FREQ_DATA_MAX) { ascii_bit = 7;
read_sample(); ascii = 0;
continue; 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 #if DEBUG
printf ("%d %d %d @%d\n", f1, f2, FREQ_DATA_THRESHOLD, printf ("%d %d %d @%d\n", f1, f2, FREQ_DATA_THRESHOLD,
ftell(stdin) - sizeof(frame)); ftell(stdin) - sizeof(frame));
#endif #endif
if (f1 < FREQ_DATA_THRESHOLD) if (f1 < FREQ_DATA_THRESHOLD)
ascii |= (1 << ascii_bit); ascii |= (1 << ascii_bit);
ascii_bit--; ascii_bit--;
if (ascii_bit < 0) { if (ascii_bit < 0) {
#if DEBUG #if DEBUG
printf("<%c, %x>", ascii, ascii); printf("<%c, %x>", ascii, ascii);
#else #else
printf("%c", ascii); printf("%c", ascii);
#endif #endif
ascii_bit = 7; ascii_bit = 7;
ascii = 0; ascii = 0;
}
lp = 0;
llp = 0;
for (i = 0; i < SAMPLES_PER_FRAME; i++)
read_sample();
} }
return 0; lp = 0;
llp = 0;
for (int i = 0; i < SAMPLES_PER_FRAME; i++)
read_sample();
} }
void void
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment