FreeCalypso > hg > sipout-test-utils
comparison test-v22/modem_func.c @ 10:3c5734b88c20
sipout-test-v22 put together
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 07 Mar 2024 02:33:49 -0800 |
parents | test-fsk/modem_rx.c@6d832abad660 |
children |
comparison
equal
deleted
inserted
replaced
9:ff535725e01f | 10:3c5734b88c20 |
---|---|
1 /* | |
2 * In this module we implement our interface to SpanDSP V.22 engine. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <stdint.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include <spandsp.h> | |
12 #include "../include/pstn_defs.h" | |
13 | |
14 extern int v22_bitrate; | |
15 | |
16 #define MAX_TEXT_LINE 80 | |
17 | |
18 static v22bis_state_t *modem_state; | |
19 static async_rx_state_t *async_state; | |
20 static u_char rx_line_buf[MAX_TEXT_LINE]; | |
21 static unsigned rx_buf_fill; | |
22 | |
23 static void | |
24 safe_print_char(c) | |
25 { | |
26 if (c >= ' ' && c <= '~') { | |
27 putchar(c); | |
28 return; | |
29 } | |
30 switch (c) { | |
31 case '\t': | |
32 putchar(c); | |
33 return; | |
34 case '\n': | |
35 return; | |
36 case '\r': | |
37 putchar('\\'); | |
38 putchar('r'); | |
39 return; | |
40 case '\b': | |
41 putchar('\\'); | |
42 putchar('b'); | |
43 return; | |
44 case '\f': | |
45 putchar('\\'); | |
46 putchar('f'); | |
47 return; | |
48 } | |
49 printf("\\x%02X", c); | |
50 } | |
51 | |
52 static void | |
53 print_rx_line() | |
54 { | |
55 u_char *dp, *endp; | |
56 int c; | |
57 | |
58 fputs("MRx:\t", stdout); | |
59 dp = rx_line_buf; | |
60 endp = rx_line_buf + rx_buf_fill; | |
61 while (dp < endp) { | |
62 c = *dp++; | |
63 safe_print_char(c); | |
64 } | |
65 if (c != '\n') | |
66 putchar('\\'); | |
67 putchar('\n'); | |
68 } | |
69 | |
70 static void | |
71 byte_rx_func(user_data, byte) | |
72 void *user_data; | |
73 int byte; | |
74 { | |
75 if (byte < 0) { | |
76 printf("Modem state change: %s\n", signal_status_to_str(byte)); | |
77 return; | |
78 } | |
79 rx_line_buf[rx_buf_fill++] = byte; | |
80 if (byte == '\n' || rx_buf_fill >= MAX_TEXT_LINE) { | |
81 print_rx_line(); | |
82 rx_buf_fill = 0; | |
83 } | |
84 } | |
85 | |
86 static int | |
87 supply_bit() | |
88 { | |
89 return 1; | |
90 } | |
91 | |
92 void | |
93 init_modem_func() | |
94 { | |
95 async_state = async_rx_init(NULL, 8, ASYNC_PARITY_NONE, 1, true, | |
96 byte_rx_func, NULL); | |
97 if (!async_state) { | |
98 fprintf(stderr, "error: async_rx_init() failed!\n"); | |
99 exit(1); | |
100 } | |
101 modem_state = v22bis_init(NULL, v22_bitrate, V22BIS_GUARD_TONE_NONE, | |
102 true, supply_bit, NULL, async_rx_put_bit, | |
103 async_state); | |
104 if (!modem_state) { | |
105 fprintf(stderr, "error: v22bis_init() failed!\n"); | |
106 exit(1); | |
107 } | |
108 } | |
109 | |
110 void | |
111 process_rx_frame(samples) | |
112 int16_t *samples; | |
113 { | |
114 v22bis_rx(modem_state, samples, FRAME_20MS); | |
115 } | |
116 | |
117 void | |
118 fill_tx_frame(samples) | |
119 int16_t *samples; | |
120 { | |
121 v22bis_tx(modem_state, samples, FRAME_20MS); | |
122 } |