FreeCalypso > hg > gsm-codec-lib
changeset 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 | 68215020852b |
children | 5efc377326da |
files | frtest/Makefile frtest/cvt-dlcap.c libtest/Makefile libtest/parse_dlcap.c |
diffstat | 4 files changed, 63 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/frtest/Makefile Tue Dec 13 06:32:25 2022 +0000 +++ b/frtest/Makefile Tue Dec 13 07:03:55 2022 +0000 @@ -11,8 +11,8 @@ all: ${PROGS} -gsmfr-cvt-dlcap: ${CVT_OBJS} - ${CC} ${CFLAGS} -o $@ ${CVT_OBJS} +gsmfr-cvt-dlcap: ${CVT_OBJS} ${LIBTEST} + ${CC} ${CFLAGS} -o $@ ${CVT_OBJS} ${LIBTEST} gsmfr-decode: decode.o ${LIBDEC} ${CC} ${CFLAGS} -o $@ decode.o ${LIBDEC} -lgsm
--- a/frtest/cvt-dlcap.c Tue Dec 13 06:32:25 2022 +0000 +++ b/frtest/cvt-dlcap.c Tue Dec 13 07:03:55 2022 +0000 @@ -1,70 +1,25 @@ /* - * This program reads a TCH downlink capture produced with FreeCalypso tools + * This program reads a TCH/FS downlink capture produced with FreeCalypso tools * (fw version with TCH downlink sniffing feature and fc-shell tch record) * and converts it into our extended-libgsm binary format, to be further * fed to gsmfr-decode. */ -#include <sys/types.h> #include <ctype.h> #include <stdio.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> #include <strings.h> -static -decode_hex_digit(ch) -{ - if (isdigit(ch)) - return(ch - '0'); - else if (isupper(ch)) - return(ch - 'A' + 10); - else - return(ch - 'a' + 10); -} - -static -parse_classic_part(line, status_words, tidsp_bytes) - char *line; - u_short *status_words; - u_char *tidsp_bytes; -{ - char *cp; - int i; - - /* grok DSP status words */ - cp = line; - for (i = 0; i < 3; i++) { - if (!isxdigit(cp[0]) || !isxdigit(cp[1]) || - !isxdigit(cp[2]) || !isxdigit(cp[3])) - return -1; - status_words[i] = (decode_hex_digit(cp[0]) << 12) | - (decode_hex_digit(cp[1]) << 8) | - (decode_hex_digit(cp[2]) << 4) | - decode_hex_digit(cp[3]); - cp += 4; - if (*cp++ != ' ') - return -1; - } - /* read the frame bits */ - for (i = 0; i < 33; i++) { - if (!isxdigit(cp[0]) || !isxdigit(cp[1])) - return -1; - tidsp_bytes[i] = (decode_hex_digit(cp[0]) << 4) | - decode_hex_digit(cp[1]); - cp += 2; - } - return 0; -} - main(argc, argv) char **argv; { FILE *inf, *outf; char linebuf[128]; int lineno, rc; - u_short status_words[3]; - u_char tidsp_bytes[33], libgsm_bytes[33], bfi[2]; + uint16_t status_words[3]; + uint8_t tidsp_bytes[33], libgsm_bytes[33], bfi[2]; unsigned fn_mod_104; if (argc != 3) { @@ -85,7 +40,7 @@ /* support both old and new formats */ if (isxdigit(linebuf[0]) && isxdigit(linebuf[1]) && isxdigit(linebuf[2]) && isxdigit(linebuf[3])) { - rc = parse_classic_part(linebuf, status_words, + rc = parse_dlcap_common(linebuf, status_words, tidsp_bytes); if (rc < 0) { invalid: fprintf(stderr, @@ -95,7 +50,7 @@ } fn_mod_104 = 0; /* won't have TAF */ } else if (!strncmp(linebuf, "FR ", 3)) { - rc = parse_classic_part(linebuf + 3, status_words, + rc = parse_dlcap_common(linebuf + 3, status_words, tidsp_bytes); if (rc < 0) goto invalid;
--- a/libtest/Makefile Tue Dec 13 06:32:25 2022 +0000 +++ b/libtest/Makefile Tue Dec 13 07:03:55 2022 +0000 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -OBJS= binreader.o pcmwrite.o wavrdhelp.o wavreader.o wavwriter.o +OBJS= binreader.o parse_dlcap.o pcmwrite.o wavrdhelp.o wavreader.o wavwriter.o LIB= libtest.a all: ${LIB}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtest/parse_dlcap.c Tue Dec 13 07:03:55 2022 +0000 @@ -0,0 +1,54 @@ +/* + * All TCH/F downlink capture files produced by fc-shell tch record + * (both FR and EFR, both old and new formats) include the same + * 81-character block in each line: 3 DSP status words followed by + * 33 bytes of frame data. Here we are factoring out the function + * for parsing this common part. + */ + +#include <ctype.h> +#include <stdint.h> + +static +decode_hex_digit(ch) +{ + if (isdigit(ch)) + return(ch - '0'); + else if (isupper(ch)) + return(ch - 'A' + 10); + else + return(ch - 'a' + 10); +} + +parse_dlcap_common(line, status_words, tidsp_bytes) + char *line; + uint16_t *status_words; + uint8_t *tidsp_bytes; +{ + char *cp; + int i; + + /* grok DSP status words */ + cp = line; + for (i = 0; i < 3; i++) { + if (!isxdigit(cp[0]) || !isxdigit(cp[1]) || + !isxdigit(cp[2]) || !isxdigit(cp[3])) + return -1; + status_words[i] = (decode_hex_digit(cp[0]) << 12) | + (decode_hex_digit(cp[1]) << 8) | + (decode_hex_digit(cp[2]) << 4) | + decode_hex_digit(cp[3]); + cp += 4; + if (*cp++ != ' ') + return -1; + } + /* read the frame bits */ + for (i = 0; i < 33; i++) { + if (!isxdigit(cp[0]) || !isxdigit(cp[1])) + return -1; + tidsp_bytes[i] = (decode_hex_digit(cp[0]) << 4) | + decode_hex_digit(cp[1]); + cp += 2; + } + return 0; +}