FreeCalypso > hg > ice1-trau-tester
annotate pcm/pcm_tx.c @ 9:e3d16d490ce2
pcm: implement dmw-on and dmw-off commands
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 23 Jun 2024 19:34:08 +0000 |
parents | 70aa8cbdbde9 |
children | 5cf7818a7d08 |
rev | line source |
---|---|
7
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement PCM Tx toward the TRAU. |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
8
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
5 #include <ctype.h> |
7
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdint.h> |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdbool.h> |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <unistd.h> |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <osmocom/core/select.h> |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "globals.h" |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 static const uint8_t dmw_alaw[8] = |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 {0x34, 0x21, 0x21, 0x34, 0xB4, 0xA1, 0xA1, 0xB4}; |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 static uint8_t pcm_fill_octet = 0x54; |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 static bool dmw_active; |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 static uint8_t *play_buffer; |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 static unsigned play_buf_nframes, play_buf_ptr; |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 static void fill_with_dmw(uint8_t *buf) |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 { |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 unsigned n; |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 for (n = 0; n < 20; n++) { |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 memcpy(buf, dmw_alaw, 8); |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 buf += 8; |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 } |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 static void fill_with_play(uint8_t *outbuf) |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 { |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 memcpy(outbuf, play_buffer + play_buf_ptr * 160, 160); |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 play_buf_ptr++; |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 if (play_buf_ptr < play_buf_nframes) |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 return; |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 free(play_buffer); |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 play_buffer = 0; |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 printf("file play finished\n"); |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 void transmit_pcm_20ms(void) |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 { |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 uint8_t buf[160]; |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (play_buffer) |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 fill_with_play(buf); |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 else if (dmw_active) |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 fill_with_dmw(buf); |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 else |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 memset(buf, pcm_fill_octet, 160); |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 write(ts_fd, buf, 160); |
ca351324187a
pcm: implement Tx on the E1 timeslot
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
8
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
58 |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
59 void cmd_pcm_fill(int argc, char **argv) |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
60 { |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
61 u_long val; |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
62 char *cp; |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
63 |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
64 if (argc != 2) { |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
65 printf("error: pcm-fill command needs 1 argument\n"); |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
66 return; |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
67 } |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
68 if (!isxdigit(argv[1][0])) { |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
69 inv_arg: printf("error: argument is not a valid hex octet\n"); |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
70 return; |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
71 } |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
72 val = strtoul(argv[1], &cp, 16); |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
73 if (*cp) |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
74 goto inv_arg; |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
75 if (val > 0xFF) |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
76 goto inv_arg; |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
77 pcm_fill_octet = val; |
70aa8cbdbde9
pcm: implement pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
78 } |
9
e3d16d490ce2
pcm: implement dmw-on and dmw-off commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
79 |
e3d16d490ce2
pcm: implement dmw-on and dmw-off commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
80 void cmd_dmw_on(int argc, char **argv) |
e3d16d490ce2
pcm: implement dmw-on and dmw-off commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
81 { |
e3d16d490ce2
pcm: implement dmw-on and dmw-off commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
82 dmw_active = true; |
e3d16d490ce2
pcm: implement dmw-on and dmw-off commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
83 } |
e3d16d490ce2
pcm: implement dmw-on and dmw-off commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
84 |
e3d16d490ce2
pcm: implement dmw-on and dmw-off commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
85 void cmd_dmw_off(int argc, char **argv) |
e3d16d490ce2
pcm: implement dmw-on and dmw-off commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
86 { |
e3d16d490ce2
pcm: implement dmw-on and dmw-off commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
87 dmw_active = false; |
e3d16d490ce2
pcm: implement dmw-on and dmw-off commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
88 } |