changeset 373:1fa4dcbb1c87

fcup-smsendmult program written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 08 Mar 2018 19:47:40 +0000
parents 1e7c6fcb9abe
children d1fa771abeb8
files .hgignore uptools/atcmd/Makefile uptools/atcmd/smsend_multmain.c
diffstat 3 files changed, 175 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Thu Mar 08 18:13:38 2018 +0000
+++ b/.hgignore	Thu Mar 08 19:47:40 2018 +0000
@@ -63,5 +63,6 @@
 ^uptools/atcmd/fcup-at$
 ^uptools/atcmd/fcup-smdump$
 ^uptools/atcmd/fcup-smsend$
+^uptools/atcmd/fcup-smsendmult$
 ^uptools/atinterf/fcup-atinterf$
 ^uptools/sms-pdu-decode/sms-pdu-decode$
--- a/uptools/atcmd/Makefile	Thu Mar 08 18:13:38 2018 +0000
+++ b/uptools/atcmd/Makefile	Thu Mar 08 19:47:40 2018 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	fcup-at fcup-smdump fcup-smsend
+PROGS=	fcup-at fcup-smdump fcup-smsend fcup-smsendmult
 INSTBIN=/opt/freecalypso/bin
 
 LIBCODING=	../libcoding/libcoding.a
@@ -12,6 +12,9 @@
 SMSEND_OBJS=	atinterf.o resp_parse.o smsend_cmgw.o smsend_concat.o \
 		smsend_main.o smsend_pduout.o smsend_text.o ${LIBCODING}
 
+SMSENDM_OBJS=	atinterf.o resp_parse.o smsend_cmgw.o smsend_multmain.o \
+		smsend_pduout.o smsend_text.o ${LIBCODING}
+
 all:	${PROGS}
 
 fcup-at:	${ATCMD_OBJS}
@@ -23,6 +26,9 @@
 fcup-smsend:	${SMSEND_OBJS}
 	${CC} ${CFLAGS} -o $@ ${SMSEND_OBJS}
 
+fcup-smsendmult:	${SMSENDM_OBJS}
+	${CC} ${CFLAGS} -o $@ ${SMSENDM_OBJS}
+
 install:	${PROGS}
 	mkdir -p ${INSTBIN}
 	install -c ${PROGS} ${INSTBIN}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uptools/atcmd/smsend_multmain.c	Thu Mar 08 19:47:40 2018 +0000
@@ -0,0 +1,167 @@
+/*
+ * This is the main module for the fcup-smsendmult 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, text_mode, utf8_input;
+u_char dest_addr[12];
+int dest_addr_global;
+char input_line[21+5+1+320+2], *msgtext;
+int lineno;
+u_char msgtext_gsm7[160];
+unsigned msgtext_gsmlen;
+
+process_cmdline(argc, argv)
+	char **argv;
+{
+	int c;
+	extern int optind;
+
+	while ((c = getopt(argc, argv, "B:np:RtuwWX:")) != EOF) {
+		if (atinterf_cmdline_opt(c))
+			continue;
+		switch (c) {
+		case 't':
+			text_mode = 1;
+			continue;
+		case 'u':
+			utf8_input = 1;
+			continue;
+		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 + 1) {
+		fprintf(stderr, "usage: %s [options] [dest-addr]\n",
+			argv[0]);
+		exit(ERROR_USAGE);
+	}
+	if (argv[optind]) {
+		dest_addr_global = 1;
+		if (parse_and_encode_dest_addr(argv[optind], dest_addr) < 0) {
+			fprintf(stderr,
+			"error: destination address argument is invalid\n");
+			exit(ERROR_USAGE);
+		}
+	} else
+		dest_addr_global = 0;
+	return(0);
+}
+
+preen_input_line()
+{
+	char *cp;
+
+	cp = index(input_line, '\n');
+	if (!cp) {
+		fprintf(stderr, "input line %d: too long or unterminated\n",
+			lineno);
+		exit(ERROR_USAGE);
+	}
+	*cp = '\0';
+	if (dest_addr_global) {
+		msgtext = input_line;
+		return(0);
+	}
+	if (!input_line[0] || isspace(input_line[0])) {
+inv:		fprintf(stderr, "input line %d: invalid syntax\n", lineno);
+		exit(ERROR_USAGE);
+	}
+	for (cp = input_line; *cp && !isspace(*cp); cp++)
+		;
+	if (!*cp)
+		goto inv;
+	*cp++ = '\0';
+	if (parse_and_encode_dest_addr(input_line, dest_addr) < 0)
+		goto inv;
+	while (isspace(*cp))
+		cp++;
+	msgtext = cp;
+	return(1);
+}
+
+preen_message()
+{
+	int rc;
+
+	if (utf8_input && utf8_to_latin1(msgtext) < 0) {
+		fprintf(stderr, "input line %d: invalid UTF-8 message\n",
+			lineno);
+		exit(ERROR_USAGE);
+	}
+	if (text_mode) {
+		if (strlen(msgtext) > 160) {
+toolong:		fprintf(stderr,
+				"input line %d: message exceeds 160 chars\n",
+				lineno);
+			exit(ERROR_USAGE);
+		}
+		return(0);
+	}
+	rc = latin1_to_gsm7(msgtext, msgtext_gsm7, 160, &msgtext_gsmlen);
+	if (rc == -1) {
+		fprintf(stderr,
+			"input line %d: message not valid for GSM7 charset\n",
+			lineno);
+		exit(ERROR_USAGE);
+	}
+	if (rc == -2)
+		goto toolong;
+	return(0);
+}
+
+init_send_process()
+{
+	atinterf_init();
+	/* enable verbose error messages */
+	atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0);
+	if (text_mode)
+		prep_for_text_mode();
+	else
+		prep_for_pdu_mode();
+	if (sms_write_mode == 0)
+		atinterf_exec_cmd_needok("AT+CMMS=1", 0, 0);
+}
+
+main(argc, argv)
+	char **argv;
+{
+	int initdone = 0;
+
+	process_cmdline(argc, argv);
+	for (lineno = 1; fgets(input_line, sizeof input_line, stdin); lineno++){
+		preen_input_line();
+		preen_message();
+		if (!initdone) {
+			init_send_process();
+			initdone = 1;
+		}
+		if (text_mode)
+			send_in_text_mode(dest_addr, msgtext);
+		else
+			send_in_pdu_mode(dest_addr, msgtext_gsm7,
+					 msgtext_gsmlen, 0, 0);
+	}
+	if (!initdone)
+		exit(0);
+	if (sms_write_mode == 0)
+		atinterf_exec_cmd_needok("AT+CMMS=0", 0, 0);
+	if (sms_write_mode == 1)
+		sendafterwr_process();
+	exit(0);
+}