FreeCalypso > hg > gsm-codec-lib
comparison frtest/cvt-dlcap.c @ 19:7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 20 Nov 2022 06:11:16 +0000 |
| parents | |
| children | b7ea278390eb |
comparison
equal
deleted
inserted
replaced
| 18:39dbaccc349d | 19:7960744ba19c |
|---|---|
| 1 /* | |
| 2 * This program reads a TCH 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 <sys/types.h> | |
| 9 #include <ctype.h> | |
| 10 #include <stdio.h> | |
| 11 #include <stdlib.h> | |
| 12 | |
| 13 static const char bfi_marker[2] = {0xBF, 0x00}; | |
| 14 | |
| 15 static | |
| 16 decode_hex_digit(ch) | |
| 17 { | |
| 18 if (isdigit(ch)) | |
| 19 return(ch - '0'); | |
| 20 else if (isupper(ch)) | |
| 21 return(ch - 'A' + 10); | |
| 22 else | |
| 23 return(ch - 'a' + 10); | |
| 24 } | |
| 25 | |
| 26 main(argc, argv) | |
| 27 char **argv; | |
| 28 { | |
| 29 FILE *inf, *outf; | |
| 30 char linebuf[128]; | |
| 31 int lineno; | |
| 32 char *cp; | |
| 33 int i; | |
| 34 u_short status_words[3]; | |
| 35 u_char tidsp_bytes[33], libgsm_bytes[33]; | |
| 36 | |
| 37 if (argc != 3) { | |
| 38 fprintf(stderr, "usage: %s infile outfile\n", argv[0]); | |
| 39 exit(1); | |
| 40 } | |
| 41 inf = fopen(argv[1], "r"); | |
| 42 if (!inf) { | |
| 43 perror(argv[1]); | |
| 44 exit(1); | |
| 45 } | |
| 46 outf = fopen(argv[2], "w"); | |
| 47 if (!outf) { | |
| 48 perror(argv[2]); | |
| 49 exit(1); | |
| 50 } | |
| 51 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { | |
| 52 /* grok DSP status words */ | |
| 53 cp = linebuf; | |
| 54 for (i = 0; i < 3; i++) { | |
| 55 if (!isxdigit(cp[0]) || !isxdigit(cp[1]) || | |
| 56 !isxdigit(cp[2]) || !isxdigit(cp[3])) { | |
| 57 invalid: fprintf(stderr, | |
| 58 "error: %s is not in the expected format\n", | |
| 59 argv[1]); | |
| 60 exit(1); | |
| 61 } | |
| 62 status_words[i] = (decode_hex_digit(cp[0]) << 12) | | |
| 63 (decode_hex_digit(cp[1]) << 8) | | |
| 64 (decode_hex_digit(cp[2]) << 4) | | |
| 65 decode_hex_digit(cp[3]); | |
| 66 cp += 4; | |
| 67 if (*cp++ != ' ') | |
| 68 goto invalid; | |
| 69 } | |
| 70 /* read the frame bits */ | |
| 71 for (i = 0; i < 33; i++) { | |
| 72 if (!isxdigit(cp[0]) || !isxdigit(cp[1])) | |
| 73 goto invalid; | |
| 74 tidsp_bytes[i] = (decode_hex_digit(cp[0]) << 4) | | |
| 75 decode_hex_digit(cp[1]); | |
| 76 cp += 2; | |
| 77 } | |
| 78 /* bit 2 of status word 0 is BFI */ | |
| 79 if (status_words[0] & 0x0004) | |
| 80 fwrite(bfi_marker, 1, 2, outf); | |
| 81 else { | |
| 82 gsm0610_tidsp_to_libgsm(tidsp_bytes, libgsm_bytes); | |
| 83 fwrite(libgsm_bytes, 1, 33, outf); | |
| 84 } | |
| 85 } | |
| 86 exit(0); | |
| 87 } |
