changeset 600:31e219088cd6

uptools/sms-pdu-decode: pcm-sms-decode utility added
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 08 Feb 2020 02:47:43 +0000
parents 18bfc10ba20e
children 4c58e09578d0
files .hgignore uptools/sms-pdu-decode/Makefile uptools/sms-pdu-decode/pcm-sms-decode.c
diffstat 3 files changed, 79 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sat Feb 08 01:20:45 2020 +0000
+++ b/.hgignore	Sat Feb 08 02:47:43 2020 +0000
@@ -70,4 +70,5 @@
 ^uptools/atcmd/fcup-smsendpdu$
 ^uptools/atcmd/fcup-smwrite$
 ^uptools/atinterf/fcup-atinterf$
+^uptools/sms-pdu-decode/pcm-sms-decode$
 ^uptools/sms-pdu-decode/sms-pdu-decode$
--- a/uptools/sms-pdu-decode/Makefile	Sat Feb 08 01:20:45 2020 +0000
+++ b/uptools/sms-pdu-decode/Makefile	Sat Feb 08 02:47:43 2020 +0000
@@ -1,8 +1,9 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	sms-pdu-decode
+PROGS=	pcm-sms-decode sms-pdu-decode
 LIB=	../libcoding/libcoding.a
 
+OBJS0=	pcm-sms-decode.o pdu-common.o ${LIB}
 OBJS1=	pdu-common.o sms-pdu-decode.o ${LIB}
 
 INSTALL_PREFIX=	/opt/freecalypso
@@ -11,6 +12,9 @@
 
 all:	${PROGS}
 
+pcm-sms-decode:	${OBJS0}
+	${CC} ${CFLAGS} -o $@ ${OBJS0}
+
 sms-pdu-decode:	${OBJS1}
 	${CC} ${CFLAGS} -o $@ ${OBJS1}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uptools/sms-pdu-decode/pcm-sms-decode.c	Sat Feb 08 02:47:43 2020 +0000
@@ -0,0 +1,73 @@
+#include <sys/types.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+
+extern int ascii_ext_mode, global_hexdump_mode;
+extern u_char pdu[176];
+extern unsigned pdu_length;
+
+static char *infname;
+static FILE *inf;
+
+static char *msgtype[4] = {"received", "received unread", "sent",
+			   "stored unsent"};
+
+static
+process_cmdline(argc, argv)
+	char **argv;
+{
+	int c;
+	extern int optind;
+
+	while ((c = getopt(argc, argv, "ehu")) != EOF)
+		switch (c) {
+		case 'e':
+			ascii_ext_mode = 1;
+			continue;
+		case 'h':
+			global_hexdump_mode = 1;
+			continue;
+		case 'u':
+			ascii_ext_mode = 2;
+			continue;
+		default:
+			fprintf(stderr, "%s: invalid option\n", argv[0]);
+			exit(1);
+		}
+	if (argc != optind + 1) {
+		fprintf(stderr, "usage: %s [options] pcm-sms-binfile\n",
+			argv[0]);
+		exit(1);
+	}
+	infname = argv[optind];
+}
+
+main(argc, argv)
+	char **argv;
+{
+	u_char record[176];
+	unsigned recno;
+
+	process_cmdline(argc, argv);
+	inf = fopen(infname, "r");
+	if (!inf) {
+		perror(infname);
+		exit(1);
+	}
+	pdu_length = 176;
+	for (recno = 0; fread(record, sizeof record, 1, inf); recno++) {
+		if (record[0] & 1) {
+			printf("Record #%u is %s message:\n", recno,
+				msgtype[(record[0] >> 1) & 3]);
+			bcopy(record + 1, pdu, 175);
+			process_pdu(0);
+			putchar('\n');
+		} else
+			printf("Record #%u is empty\n\n", recno);
+	}
+	exit(0);
+}