annotate v110/v110-dump16.c @ 61:ffbbce856ac7

utils/gen-hex-lines: import from vband-misc repository
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 25 Sep 2024 18:48:17 +0000
parents 796cc2d94204
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
2 * This program reads a 64 kbit/s timeslot recording file, examines it
40
796cc2d94204 new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
3 * as V.110 with 16 kbit/s intermediate rate, locates 80-bit V.110 frames
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
4 * and dumps them in a mostly raw form.
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
7 #include <sys/types.h>
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
8 #include <sys/file.h>
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
9 #include <sys/stat.h>
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
10 #include <sys/mman.h>
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdio.h>
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdint.h>
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <stdlib.h>
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <string.h>
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <strings.h>
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
16 #include <unistd.h>
28
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
17
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
18 static const uint8_t *filebuf;
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
19 static unsigned total_size;
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 static void
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
22 read_ts_file(filename)
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
23 char *filename;
2
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
24 {
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
25 int fd;
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
26 struct stat st;
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
28 fd = open(filename, O_RDONLY);
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
29 if (fd < 0) {
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
30 perror(filename);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
31 exit(1);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
32 }
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
33 fstat(fd, &st);
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
34 if (!S_ISREG(st.st_mode)) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
35 fprintf(stderr, "error: %s is not a regular file\n", filename);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
36 exit(1);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
37 }
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
38 total_size = st.st_size;
40
796cc2d94204 new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
39 if (total_size < 40) {
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
40 fprintf(stderr, "error: %s is too short\n", filename);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
41 exit(1);
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
43 filebuf = mmap(NULL, total_size, PROT_READ, MAP_PRIVATE, fd, 0);
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
44 if (filebuf == MAP_FAILED) {
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
45 perror("mmap");
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
46 exit(1);
2
b2ef2c80fef1 trau-parse: add FR decoding
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
47 }
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
48 close(fd);
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 static int
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
52 check_sync(pos)
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
53 unsigned pos;
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 {
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
55 const uint8_t *cand = filebuf + pos;
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
56 unsigned n;
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57
40
796cc2d94204 new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
58 for (n = 0; n < 4; n++) {
796cc2d94204 new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
59 if (cand[n] & 0xC0)
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return 0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
62 for (n = 1; n < 10; n++) {
40
796cc2d94204 new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
63 if (!(cand[n * 4] & 0x80))
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 return 0;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 return 1;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
69 static unsigned
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
70 extract_data_byte(pos)
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
71 unsigned pos;
28
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
72 {
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
73 const uint8_t *src = filebuf + pos;
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
74 unsigned accum;
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
75 unsigned n;
28
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
76
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
77 accum = 0;
40
796cc2d94204 new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
78 for (n = 0; n < 4; n++) {
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
79 accum <<= 1;
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
80 if (*src & 0x80)
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
81 accum |= 1;
40
796cc2d94204 new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
82 accum <<= 1;
796cc2d94204 new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
83 if (*src & 0x40)
796cc2d94204 new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
84 accum |= 1;
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
85 src++;
28
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
86 }
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
87 return accum;
28
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
88 }
9bcdb091c24d trau-decode: new program trau-hr-dump
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
89
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 static void
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
91 process_frame(pos)
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
92 unsigned pos;
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 {
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
94 unsigned nb;
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
95
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
96 printf("Frame at 0x%x:", pos);
40
796cc2d94204 new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
97 pos += 4;
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
98 for (nb = 0; nb < 9; nb++) {
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
99 printf(" %02X", extract_data_byte(pos));
40
796cc2d94204 new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
100 pos += 4;
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
101 }
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
102 putchar('\n');
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 static void
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
106 process_filebuf()
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 {
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
108 unsigned p, endp;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
109 int sync = 0, match;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
110
40
796cc2d94204 new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
111 endp = total_size - 40;
796cc2d94204 new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
112 for (p = 0; p <= endp; ) {
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
113 match = check_sync(p);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
114 if (match != sync) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
115 printf("# %s frame sync at file offset 0x%x\n",
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
116 match ? "Acquired" : "Lost", p);
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 }
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
118 if (match) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
119 process_frame(p);
40
796cc2d94204 new program v110-dump16
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
120 p += 40;
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
121 } else
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
122 p++;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
123 sync = match;
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 }
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 main(argc, argv)
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 char **argv;
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 {
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
130 if (argc != 2) {
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
131 fprintf(stderr, "usage: %s binfile\n", argv[0]);
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 exit(1);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 }
39
957c20852c7c new program v110-dump8
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
134 read_ts_file(argv[1]);
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents: 10
diff changeset
135 process_filebuf();
0
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 exit(0);
131e0f1972bb beginning of trau-parse program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 }