FreeCalypso > hg > gsm-codec-lib
comparison libtest/parse_dlcap.c @ 139:be57e06bed84
factor out common part of gsmfr-cvt-dlcap, in prep for EFR
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Tue, 13 Dec 2022 07:03:55 +0000 |
| parents | frtest/cvt-dlcap.c@b7ea278390eb |
| children |
comparison
equal
deleted
inserted
replaced
| 138:68215020852b | 139:be57e06bed84 |
|---|---|
| 1 /* | |
| 2 * All TCH/F downlink capture files produced by fc-shell tch record | |
| 3 * (both FR and EFR, both old and new formats) include the same | |
| 4 * 81-character block in each line: 3 DSP status words followed by | |
| 5 * 33 bytes of frame data. Here we are factoring out the function | |
| 6 * for parsing this common part. | |
| 7 */ | |
| 8 | |
| 9 #include <ctype.h> | |
| 10 #include <stdint.h> | |
| 11 | |
| 12 static | |
| 13 decode_hex_digit(ch) | |
| 14 { | |
| 15 if (isdigit(ch)) | |
| 16 return(ch - '0'); | |
| 17 else if (isupper(ch)) | |
| 18 return(ch - 'A' + 10); | |
| 19 else | |
| 20 return(ch - 'a' + 10); | |
| 21 } | |
| 22 | |
| 23 parse_dlcap_common(line, status_words, tidsp_bytes) | |
| 24 char *line; | |
| 25 uint16_t *status_words; | |
| 26 uint8_t *tidsp_bytes; | |
| 27 { | |
| 28 char *cp; | |
| 29 int i; | |
| 30 | |
| 31 /* grok DSP status words */ | |
| 32 cp = line; | |
| 33 for (i = 0; i < 3; i++) { | |
| 34 if (!isxdigit(cp[0]) || !isxdigit(cp[1]) || | |
| 35 !isxdigit(cp[2]) || !isxdigit(cp[3])) | |
| 36 return -1; | |
| 37 status_words[i] = (decode_hex_digit(cp[0]) << 12) | | |
| 38 (decode_hex_digit(cp[1]) << 8) | | |
| 39 (decode_hex_digit(cp[2]) << 4) | | |
| 40 decode_hex_digit(cp[3]); | |
| 41 cp += 4; | |
| 42 if (*cp++ != ' ') | |
| 43 return -1; | |
| 44 } | |
| 45 /* read the frame bits */ | |
| 46 for (i = 0; i < 33; i++) { | |
| 47 if (!isxdigit(cp[0]) || !isxdigit(cp[1])) | |
| 48 return -1; | |
| 49 tidsp_bytes[i] = (decode_hex_digit(cp[0]) << 4) | | |
| 50 decode_hex_digit(cp[1]); | |
| 51 cp += 2; | |
| 52 } | |
| 53 return 0; | |
| 54 } |
