mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
util/spkmodem_recv: general code cleanup
Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
/* Forked from coreboot's version, at util/spkmodem_recv/ in coreboot.git,
|
||||
* revision 5c2b5fcf2f9c9259938fd03cfa3ea06b36a007f0 as of 3 January 2022.
|
||||
* This version is heavily modified, re-written based on OpenBSD Kernel Source
|
||||
* File Style Guide (KNF); this change is Copyright 2023 Leah Rowe. */
|
||||
* File Style Guide (KNF); this change is Copyright 2023,2026 Leah Rowe. */
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
@@ -25,28 +25,24 @@
|
||||
|
||||
#define ERR() (errno = errno ? errno : ECANCELED)
|
||||
#define reset_char() ascii = 0, ascii_bit = 7
|
||||
#define err_if(x) if (x) err(ERR(), NULL)
|
||||
|
||||
signed short frame[MAX_SAMPLES], pulse[MAX_SAMPLES];
|
||||
int ringpos, debug, freq_data, freq_separator, sample_count, ascii_bit = 7;
|
||||
char ascii = 0;
|
||||
|
||||
void handle_audio(void);
|
||||
void decode_pulse(void);
|
||||
int set_ascii_bit(void);
|
||||
void print_char(void);
|
||||
void print_stats(void);
|
||||
void handle_audio(void), decode_pulse(void), print_char(void),
|
||||
print_stats(void);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
#ifdef __OpenBSD__
|
||||
if (pledge("stdio", NULL) == -1)
|
||||
err(ERR(), "pledge");
|
||||
err_if (pledge("stdio", NULL) == -1);
|
||||
#endif
|
||||
while ((c = getopt(argc, argv, "d")) != -1)
|
||||
if (!(debug = (c == 'd')))
|
||||
err(errno = EINVAL, NULL);
|
||||
for (int c; (c = getopt(argc, argv, "d")) != -1;)
|
||||
err_if (!(debug = (c == 'd')));
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
while (!feof(stdin))
|
||||
handle_audio();
|
||||
@@ -65,7 +61,6 @@ handle_audio(void)
|
||||
decode_pulse();
|
||||
return;
|
||||
}
|
||||
|
||||
if (set_ascii_bit() < 0)
|
||||
print_char();
|
||||
sample_count = 0;
|
||||
@@ -85,9 +80,8 @@ decode_pulse(void)
|
||||
if (ferror(stdin) != 0)
|
||||
err(ERR(), "Could not read from frame.");
|
||||
|
||||
if ((pulse[ringpos] = (abs(frame[ringpos]) > THRESHOLD) ? 1 : 0))
|
||||
++freq_separator;
|
||||
++ringpos;
|
||||
pulse[ringpos] = (abs(frame[ringpos]) > THRESHOLD) ? 1 : 0;
|
||||
freq_separator += pulse[ringpos++];
|
||||
ringpos %= MAX_SAMPLES;
|
||||
++sample_count;
|
||||
}
|
||||
@@ -103,6 +97,15 @@ set_ascii_bit(void)
|
||||
return ascii_bit;
|
||||
}
|
||||
|
||||
void
|
||||
print_stats(void)
|
||||
{
|
||||
long stdin_pos;
|
||||
err_if ((stdin_pos = ftell(stdin)) == -1);
|
||||
printf ("%d %d %d @%ld\n", freq_data, freq_separator,
|
||||
FREQ_DATA_THRESHOLD, stdin_pos - sizeof(frame));
|
||||
}
|
||||
|
||||
void
|
||||
print_char(void)
|
||||
{
|
||||
@@ -112,13 +115,3 @@ print_char(void)
|
||||
printf("%c", ascii);
|
||||
reset_char();
|
||||
}
|
||||
|
||||
void
|
||||
print_stats(void)
|
||||
{
|
||||
long stdin_pos;
|
||||
if ((stdin_pos = ftell(stdin)) == -1)
|
||||
err(ERR(), NULL);
|
||||
printf ("%d %d %d @%ld\n", freq_data, freq_separator,
|
||||
FREQ_DATA_THRESHOLD, stdin_pos - sizeof(frame));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user