FreeCalypso > hg > gsm-codec-lib
comparison frtest/dlcap-gsmx.c @ 165:ef3ea52a190f
rename gsmfr-cvt-dlcap to gsmfr-dlcap-gsmx
for consistency with EFR version
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 16 Dec 2022 04:09:03 +0000 |
| parents | frtest/cvt-dlcap.c@be57e06bed84 |
| children | 500f3e93964f |
comparison
equal
deleted
inserted
replaced
| 164:5f23cb3f0f8d | 165:ef3ea52a190f |
|---|---|
| 1 /* | |
| 2 * This program reads a TCH/FS downlink capture produced with FreeCalypso tools | |
| 3 * (fw version with TCH downlink sniffing feature and fc-shell tch record) | |
| 4 * and converts it into our extended-libgsm binary format, to be further | |
| 5 * fed to gsmfr-decode. | |
| 6 */ | |
| 7 | |
| 8 #include <ctype.h> | |
| 9 #include <stdio.h> | |
| 10 #include <stdint.h> | |
| 11 #include <stdlib.h> | |
| 12 #include <string.h> | |
| 13 #include <strings.h> | |
| 14 | |
| 15 main(argc, argv) | |
| 16 char **argv; | |
| 17 { | |
| 18 FILE *inf, *outf; | |
| 19 char linebuf[128]; | |
| 20 int lineno, rc; | |
| 21 uint16_t status_words[3]; | |
| 22 uint8_t tidsp_bytes[33], libgsm_bytes[33], bfi[2]; | |
| 23 unsigned fn_mod_104; | |
| 24 | |
| 25 if (argc != 3) { | |
| 26 fprintf(stderr, "usage: %s infile outfile\n", argv[0]); | |
| 27 exit(1); | |
| 28 } | |
| 29 inf = fopen(argv[1], "r"); | |
| 30 if (!inf) { | |
| 31 perror(argv[1]); | |
| 32 exit(1); | |
| 33 } | |
| 34 outf = fopen(argv[2], "w"); | |
| 35 if (!outf) { | |
| 36 perror(argv[2]); | |
| 37 exit(1); | |
| 38 } | |
| 39 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { | |
| 40 /* support both old and new formats */ | |
| 41 if (isxdigit(linebuf[0]) && isxdigit(linebuf[1]) && | |
| 42 isxdigit(linebuf[2]) && isxdigit(linebuf[3])) { | |
| 43 rc = parse_dlcap_common(linebuf, status_words, | |
| 44 tidsp_bytes); | |
| 45 if (rc < 0) { | |
| 46 invalid: fprintf(stderr, | |
| 47 "error: %s is not in the expected format\n", | |
| 48 argv[1]); | |
| 49 exit(1); | |
| 50 } | |
| 51 fn_mod_104 = 0; /* won't have TAF */ | |
| 52 } else if (!strncmp(linebuf, "FR ", 3)) { | |
| 53 rc = parse_dlcap_common(linebuf + 3, status_words, | |
| 54 tidsp_bytes); | |
| 55 if (rc < 0) | |
| 56 goto invalid; | |
| 57 if (linebuf[84] != ' ') | |
| 58 goto invalid; | |
| 59 if (!isdigit(linebuf[85])) | |
| 60 goto invalid; | |
| 61 fn_mod_104 = strtoul(linebuf + 85, 0, 10); | |
| 62 } else | |
| 63 goto invalid; | |
| 64 /* | |
| 65 * Bit 15 of status word 0 is buffer validity flag, | |
| 66 * bit 2 is BFI. | |
| 67 */ | |
| 68 if (!(status_words[0] & 0x8000) || (status_words[0] & 0x0004)) { | |
| 69 bfi[0] = 0xBF; | |
| 70 bfi[1] = fn_mod_104 == 60; | |
| 71 fwrite(bfi, 1, 2, outf); | |
| 72 } else { | |
| 73 gsm0610_tidsp_to_libgsm(tidsp_bytes, libgsm_bytes); | |
| 74 fwrite(libgsm_bytes, 1, 33, outf); | |
| 75 } | |
| 76 } | |
| 77 exit(0); | |
| 78 } |
