changeset 384:3eb92855f7b9

fcup-smsendpdu program written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 09 Mar 2018 03:29:40 +0000
parents f8c693d16978
children ce3b57b8920b
files .hgignore uptools/atcmd/Makefile uptools/atcmd/smsend_pduin.c
diffstat 3 files changed, 124 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Mar 09 02:56:09 2018 +0000
+++ b/.hgignore	Fri Mar 09 03:29:40 2018 +0000
@@ -64,5 +64,6 @@
 ^uptools/atcmd/fcup-smdump$
 ^uptools/atcmd/fcup-smsend$
 ^uptools/atcmd/fcup-smsendmult$
+^uptools/atcmd/fcup-smsendpdu$
 ^uptools/atinterf/fcup-atinterf$
 ^uptools/sms-pdu-decode/sms-pdu-decode$
--- a/uptools/atcmd/Makefile	Fri Mar 09 02:56:09 2018 +0000
+++ b/uptools/atcmd/Makefile	Fri Mar 09 03:29:40 2018 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	fcup-at fcup-smdump fcup-smsend fcup-smsendmult
+PROGS=	fcup-at fcup-smdump fcup-smsend fcup-smsendmult fcup-smsendpdu
 INSTBIN=/opt/freecalypso/bin
 
 LIBCODING=	../libcoding/libcoding.a
@@ -16,6 +16,9 @@
 SMSENDM_OBJS=	atinterf.o resp_parse.o smsend_cmgw.o smsend_multmain.o \
 		smsend_pdugen.o smsend_pduout.o smsend_text.o ${LIBCODING}
 
+SMSENDP_OBJS=	atinterf.o resp_parse.o smsend_cmgw.o smsend_pduin.o \
+		smsend_pduout.o ${LIBCODING}
+
 all:	${PROGS}
 
 fcup-at:	${ATCMD_OBJS}
@@ -30,6 +33,9 @@
 fcup-smsendmult:	${SMSENDM_OBJS}
 	${CC} ${CFLAGS} -o $@ ${SMSENDM_OBJS}
 
+fcup-smsendpdu:	${SMSENDP_OBJS}
+	${CC} ${CFLAGS} -o $@ ${SMSENDP_OBJS}
+
 install:	${PROGS}
 	mkdir -p ${INSTBIN}
 	install -c ${PROGS} ${INSTBIN}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uptools/atcmd/smsend_pduin.c	Fri Mar 09 03:29:40 2018 +0000
@@ -0,0 +1,116 @@
+/*
+ * This is the main module for the fcup-smsendpdu utility.
+ */
+
+#include <sys/types.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+#include "../../rvinterf/include/exitcodes.h"
+
+int sms_write_mode;
+char input_line[176*2+2];
+int lineno;
+int initdone, cmms_done;
+
+process_cmdline(argc, argv)
+	char **argv;
+{
+	int c;
+	extern int optind;
+
+	while ((c = getopt(argc, argv, "B:np:RwWX:")) != EOF) {
+		if (atinterf_cmdline_opt(c))
+			continue;
+		switch (c) {
+		case 'w':
+			sms_write_mode = 1;
+			continue;
+		case 'W':
+			sms_write_mode = 2;
+			continue;
+		default:
+			/* error msg already printed */
+			exit(ERROR_USAGE);
+		}
+	}
+	if (argc != optind) {
+		fprintf(stderr, "usage: %s [options]\n", argv[0]);
+		exit(ERROR_USAGE);
+	}
+	return(0);
+}
+
+more_input()
+{
+	int c;
+
+	c = getc(stdin);
+	if (c == EOF)
+		return(0);
+	ungetc(c, stdin);
+	return(1);
+}
+
+init_send_process()
+{
+	if (initdone)
+		return(0);
+	atinterf_init();
+	/* enable verbose error messages */
+	atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0);
+	/* set PDU mode */
+	prep_for_pdu_mode();
+	if (sms_write_mode == 0 && more_input()) {
+		atinterf_exec_cmd_needok("AT+CMMS=1", 0, 0);
+		cmms_done = 1;
+	}
+	initdone = 1;
+	return(1);
+}
+
+process_line()
+{
+	char *cp;
+	u_char pdubin[176];
+	int cc, scalen;
+
+	cp = index(input_line, '\n');
+	if (!cp) {
+		fprintf(stderr, "input line %d: too long or unterminated\n",
+			lineno);
+		exit(ERROR_USAGE);
+	}
+	*cp = '\0';
+	cc = decode_hex_line(input_line, pdubin, sizeof pdubin);
+	if (cc < 1) {
+inv:		fprintf(stderr, "input line %d: not a valid PDU\n", lineno);
+		exit(ERROR_USAGE);
+	}
+	if (pdubin[0] == 1 || pdubin[0] > 11)
+		goto inv;
+	scalen = pdubin[0] + 1;
+	if (cc < scalen + 1)
+		goto inv;
+	/* good to go */
+	init_send_process();
+	send_pdu_out(input_line, cc - scalen);
+}
+
+main(argc, argv)
+	char **argv;
+{
+	process_cmdline(argc, argv);
+	for (lineno = 1; fgets(input_line, sizeof input_line, stdin); lineno++)
+		process_line();
+	if (!initdone)
+		exit(0);
+	if (cmms_done)
+		atinterf_exec_cmd_needok("AT+CMMS=0", 0, 0);
+	if (sms_write_mode == 1)
+		sendafterwr_process();
+	exit(0);
+}