annotate test-fsk/modem_rx.c @ 6:ba66d297fe57

test-fsk: first attempt at modem Rx
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 04 Mar 2024 23:21:07 -0800
parents
children 6d832abad660
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
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static fsk_rx_state_t *fsk_rx_state;
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 static void
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 byte_rx_func(user_data, byte)
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 void *user_data;
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int byte;
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 if (byte < 0) {
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 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
26 return;
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 printf("Rx byte: 0x%02X\n", byte);
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 void
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 init_modem_rx()
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 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
35 FSK_FRAME_MODE_FRAMED, byte_rx_func, NULL);
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (!fsk_rx_state) {
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 fprintf(stderr, "error: fsk_rx_init() failed!\n");
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 exit(1);
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 void
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 process_rx_frame(samples)
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 int16_t *samples;
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 {
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 fsk_rx(fsk_rx_state, samples, FRAME_20MS);
ba66d297fe57 test-fsk: first attempt at modem Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }