# HG changeset patch # User Mychaela Falconia # Date 1670915035 0 # Node ID be57e06bed84cbfeaa4853743280da67a146bf38 # Parent 68215020852b35a2b5d22b66ae5800ab7c43ba23 factor out common part of gsmfr-cvt-dlcap, in prep for EFR diff -r 68215020852b -r be57e06bed84 frtest/Makefile --- 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 diff -r 68215020852b -r be57e06bed84 frtest/cvt-dlcap.c --- 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 #include #include +#include #include #include #include -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; diff -r 68215020852b -r be57e06bed84 libtest/Makefile --- 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} diff -r 68215020852b -r be57e06bed84 libtest/parse_dlcap.c --- /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 +#include + +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; +}