annotate test-fsk/modem_rx.c @ 10:3c5734b88c20

sipout-test-v22 put together
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 07 Mar 2024 02:33:49 -0800
parents 6d832abad660
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement modem Rx handling, revolving around
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * FSK demodulation via SpanDSP.
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdint.h>
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <spandsp.h>
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "../include/pstn_defs.h"
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern int fsk_mode_rx;
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
7
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
17 #define MAX_TEXT_LINE 80
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
18
6
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 static fsk_rx_state_t *fsk_rx_state;
7
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
20 static u_char rx_line_buf[MAX_TEXT_LINE];
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
21 static unsigned rx_buf_fill;
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
22
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
23 static void
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
24 safe_print_char(c)
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
25 {
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
26 if (c >= ' ' && c <= '~') {
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
27 putchar(c);
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
28 return;
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
29 }
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
30 switch (c) {
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
31 case '\t':
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
32 putchar(c);
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
33 return;
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
34 case '\n':
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
35 return;
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
36 case '\r':
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
37 putchar('\\');
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
38 putchar('r');
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
39 return;
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
40 case '\b':
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
41 putchar('\\');
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
42 putchar('b');
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
43 return;
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
44 case '\f':
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
45 putchar('\\');
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
46 putchar('f');
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
47 return;
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
48 }
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
49 printf("\\x%02X", c);
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
50 }
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
51
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
52 static void
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
53 print_rx_line()
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
54 {
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
55 u_char *dp, *endp;
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
56 int c;
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
57
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
58 fputs("MRx:\t", stdout);
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
59 dp = rx_line_buf;
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
60 endp = rx_line_buf + rx_buf_fill;
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
61 while (dp < endp) {
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
62 c = *dp++;
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
63 safe_print_char(c);
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
64 }
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
65 if (c != '\n')
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
66 putchar('\\');
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
67 putchar('\n');
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
68 }
6
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 static void
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 byte_rx_func(user_data, byte)
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 void *user_data;
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 int byte;
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 {
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 if (byte < 0) {
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 printf("Modem state change: %s\n", signal_status_to_str(byte));
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 return;
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
7
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
79 rx_line_buf[rx_buf_fill++] = byte;
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
80 if (byte == '\n' || rx_buf_fill >= MAX_TEXT_LINE) {
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
81 print_rx_line();
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
82 rx_buf_fill = 0;
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
83 }
6
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 void
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 init_modem_rx()
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 {
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 fsk_rx_state = fsk_rx_init(NULL, &preset_fsk_specs[fsk_mode_rx],
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 FSK_FRAME_MODE_FRAMED, byte_rx_func, NULL);
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 if (!fsk_rx_state) {
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 fprintf(stderr, "error: fsk_rx_init() failed!\n");
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 exit(1);
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 }
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 }
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 void
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 process_rx_frame(samples)
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 int16_t *samples;
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 {
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 fsk_rx(fsk_rx_state, samples, FRAME_20MS);
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 }