diff frtest/cvt-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 b7ea278390eb
children
line wrap: on
line diff
--- 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;