annotate trau-decode/dump-1bit.c @ 27:f508dacf2cf9

trau-decode: new programs dump-1bit and trau-sync8
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 18 Aug 2024 06:26:23 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program reads a 64 kbit/s timeslot recording file, focuses on one
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * bit out of the eight (a single 8 kbit/s subslot) and prints a dump
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * that shows just this one bit out of each byte. It is an aid for
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * development and debugging of frame sync tools for 8 kbit/s submultiplexing.
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 */
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 main(argc, argv)
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 char **argv;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 FILE *inf;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 int subslot, right_shift;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 unsigned file_offset, mod16;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 int inb;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (argc != 3) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 fprintf(stderr, "usage: %s binfile subslot\n", argv[0]);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 exit(1);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 }
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 inf = fopen(argv[1], "r");
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 if (!inf) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 perror(argv[1]);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 exit(1);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 subslot = atoi(argv[2]);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (subslot < 0 || subslot > 7) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 fprintf(stderr, "error: invalid subslot argument\n");
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 exit(1);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 right_shift = 7 - subslot;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 for (file_offset = 0; ; file_offset++) {
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 inb = getc(inf);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (inb < 0)
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 break;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 mod16 = file_offset & 15;
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (mod16 == 0)
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 printf("%08X:", file_offset);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (mod16 == 0 || mod16 == 4 || mod16 == 8 || mod16 == 12)
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 putchar(' ');
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 printf(" %u", (inb >> right_shift) & 1);
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (mod16 == 15)
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 putchar('\n');
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
f508dacf2cf9 trau-decode: new programs dump-1bit and trau-sync8
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }