summaryrefslogtreecommitdiff
path: root/util/spkmodem_recv/spkmodem-recv.c
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-06-05 01:36:06 +0100
committerLeah Rowe <leah@libreboot.org>2023-06-05 01:37:06 +0100
commit3fb99a017dda30aa8607a85fb8613ab10be69158 (patch)
tree5edc6f53b790fb813b4375ecfd4f6a4e90bb86b6 /util/spkmodem_recv/spkmodem-recv.c
parent264a31b95dd5e2c7790368b2b53e44d067a27c01 (diff)
util/spkmodem-recv: make debug a runtime option
it's currently a build-time option make it a runtime option instead, so that every user can optionally make use of it, on all builds 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.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/util/spkmodem_recv/spkmodem-recv.c b/util/spkmodem_recv/spkmodem-recv.c
index 2485943a..5fa98a76 100644
--- a/util/spkmodem_recv/spkmodem-recv.c
+++ b/util/spkmodem_recv/spkmodem-recv.c
@@ -19,11 +19,10 @@
#define FREQ_DATA_MAX 60
#define THRESHOLD 500
-#define DEBUG 0
#define ERR() (errno = errno ? errno : ECANCELED)
signed short frame[2 * SAMPLES_PER_FRAME], pulse[2 * SAMPLES_PER_FRAME];
-int freq_data, freq_separator, sample_count, ascii_bit = 7;
+int debug, freq_data, freq_separator, sample_count, ascii_bit = 7;
char ascii = 0;
void handle_audio(void);
@@ -40,6 +39,11 @@ main(int argc, char *argv[])
if (pledge("stdio", NULL) == -1)
err(ERR(), "pledge");
#endif
+ while ((c = getopt(argc, argv, "d")) != -1) {
+ if (c != 'd')
+ err(errno = EINVAL, NULL);
+ debug = 1;
+ }
setvbuf(stdout, NULL, _IONBF, 0);
while (!feof(stdin))
handle_audio();
@@ -97,13 +101,13 @@ read_frame(int ringpos)
int
set_ascii_bit(void)
{
-#if DEBUG
- long stdin_pos = 0;
- 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));
-#endif
+ if (debug) {
+ long stdin_pos = 0;
+ 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));
+ }
if (freq_data < FREQ_DATA_THRESHOLD)
ascii |= (1 << ascii_bit);
return ascii_bit;
@@ -112,11 +116,10 @@ set_ascii_bit(void)
void
print_char(void)
{
-#if DEBUG
- printf("<%c, %x>", ascii, ascii);
-#else
- printf("%c", ascii);
-#endif
+ if (debug)
+ printf("<%c, %x>", ascii, ascii);
+ else
+ printf("%c", ascii);
ascii_bit = 7;
ascii = 0;
}