annotate test-v22/modem_func.c @ 18:f7321b25195e default tip

new build system for ThemWi sw components
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 14 May 2024 18:08:35 -0800
parents 3c5734b88c20
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 /*
10
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
2 * In this module we implement our interface to SpanDSP V.22 engine.
6
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
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 #include <sys/types.h>
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <spandsp.h>
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "../include/pstn_defs.h"
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
10
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
14 extern int v22_bitrate;
6
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
7
6d832abad660 test-fsk: gather and print full line of modem Rx characters
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
16 #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
17
10
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
18 static v22bis_state_t *modem_state;
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
19 static async_rx_state_t *async_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
10
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
86 static int
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
87 supply_bit()
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
88 {
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
89 return 1;
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
90 }
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
91
6
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 void
10
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
93 init_modem_func()
6
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 {
10
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
95 async_state = async_rx_init(NULL, 8, ASYNC_PARITY_NONE, 1, true,
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
96 byte_rx_func, NULL);
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
97 if (!async_state) {
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
98 fprintf(stderr, "error: async_rx_init() failed!\n");
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
99 exit(1);
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
100 }
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
101 modem_state = v22bis_init(NULL, v22_bitrate, V22BIS_GUARD_TONE_NONE,
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
102 true, supply_bit, NULL, async_rx_put_bit,
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
103 async_state);
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
104 if (!modem_state) {
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
105 fprintf(stderr, "error: v22bis_init() failed!\n");
6
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 exit(1);
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 }
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 void
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 process_rx_frame(samples)
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 int16_t *samples;
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 {
10
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
114 v22bis_rx(modem_state, samples, FRAME_20MS);
6
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 }
10
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
116
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
117 void
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
118 fill_tx_frame(samples)
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
119 int16_t *samples;
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
120 {
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
121 v22bis_tx(modem_state, samples, FRAME_20MS);
3c5734b88c20 sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
122 }