FreeCalypso > hg > freecalypso-tools
changeset 385:ce3b57b8920b
fcup-smwrite program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 09 Mar 2018 20:43:53 +0000 |
parents | 3eb92855f7b9 |
children | bae0fd7285dd |
files | .hgignore uptools/atcmd/Makefile uptools/atcmd/smwrite.c |
diffstat | 3 files changed, 148 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Fri Mar 09 03:29:40 2018 +0000 +++ b/.hgignore Fri Mar 09 20:43:53 2018 +0000 @@ -65,5 +65,6 @@ ^uptools/atcmd/fcup-smsend$ ^uptools/atcmd/fcup-smsendmult$ ^uptools/atcmd/fcup-smsendpdu$ +^uptools/atcmd/fcup-smwrite$ ^uptools/atinterf/fcup-atinterf$ ^uptools/sms-pdu-decode/sms-pdu-decode$
--- a/uptools/atcmd/Makefile Fri Mar 09 03:29:40 2018 +0000 +++ b/uptools/atcmd/Makefile Fri Mar 09 20:43:53 2018 +0000 @@ -1,6 +1,7 @@ CC= gcc CFLAGS= -O2 -PROGS= fcup-at fcup-smdump fcup-smsend fcup-smsendmult fcup-smsendpdu +PROGS= fcup-at fcup-smdump fcup-smsend fcup-smsendmult fcup-smsendpdu \ + fcup-smwrite INSTBIN=/opt/freecalypso/bin LIBCODING= ../libcoding/libcoding.a @@ -19,6 +20,8 @@ SMSENDP_OBJS= atinterf.o resp_parse.o smsend_cmgw.o smsend_pduin.o \ smsend_pduout.o ${LIBCODING} +SMWRITE_OBJS= atinterf.o smwrite.o ${LIBCODING} + all: ${PROGS} fcup-at: ${ATCMD_OBJS} @@ -36,6 +39,9 @@ fcup-smsendpdu: ${SMSENDP_OBJS} ${CC} ${CFLAGS} -o $@ ${SMSENDP_OBJS} +fcup-smwrite: ${SMWRITE_OBJS} + ${CC} ${CFLAGS} -o $@ ${SMWRITE_OBJS} + install: ${PROGS} mkdir -p ${INSTBIN} install -c ${PROGS} ${INSTBIN}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uptools/atcmd/smwrite.c Fri Mar 09 20:43:53 2018 +0000 @@ -0,0 +1,140 @@ +/* + * This program is a debug and development aid - it uses the AT+CMGW command + * in PDU mode to write messages into SIM or ME SMS storage, simulating + * arbitrary received or sent messages. This trick may come in useful + * in the development and testing of SMS handling in phone handset UI firmware. + */ + +#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" + +extern char at_response[]; + +char input_line[176*2+2]; +int lineno; + +process_cmdline(argc, argv) + char **argv; +{ + int c; + extern int optind; + + while ((c = getopt(argc, argv, "B:np:RX:")) != EOF) + if (!atinterf_cmdline_opt(c)) { + /* error msg already printed */ + exit(ERROR_USAGE); + } + if (argc != optind) { + fprintf(stderr, "usage: %s [options]\n", argv[0]); + exit(ERROR_USAGE); + } + return(0); +} + +get_input_line() +{ + char *nl; + + if (!fgets(input_line, sizeof input_line, stdin)) + return(0); + lineno++; + nl = index(input_line, '\n'); + if (!nl) { + fprintf(stderr, "input line %d: too long or unterminated\n", + lineno); + exit(ERROR_USAGE); + } + *nl = '\0'; + return(1); +} + +get_input_line_noeof() +{ + int rc; + + rc = get_input_line(); + if (!rc) { + fprintf(stderr, "error: premature EOF in input\n"); + exit(ERROR_USAGE); + } +} + +cmgw_callback() +{ + /* skip empty lines */ + if (at_response[1]) + puts(at_response+1); +} + +process_record() +{ + int msgstat; + u_char pdubin[176]; + int cc, scalen; + char send_cmd[32]; + + if (!get_input_line()) + return(0); + if (!strcmp(input_line, "Received unread message:")) + msgstat = 0; + else if (!strcmp(input_line, "Received message:")) + msgstat = 1; + else if (!strcmp(input_line, "Stored unsent message:")) + msgstat = 2; + else if (!strcmp(input_line, "Sent message:")) + msgstat = 3; + else { + fprintf(stderr, + "input line %d: expected beginning of message record\n", + lineno); + exit(ERROR_USAGE); + } + for (;;) { + get_input_line_noeof(); + if (!isupper(input_line[0])) + break; + if (!index(input_line, ':')) + break; + } + 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); + } + scalen = pdubin[0] + 1; + if (cc < scalen + 1) + goto inv; + /* good to go */ + sprintf(send_cmd, "AT+CMGW=%u,%d", cc - scalen, msgstat); + atinterf_exec_cmd_needok(send_cmd, input_line, cmgw_callback); + /* expect blank line after each PDU */ + get_input_line_noeof(); + if (input_line[0]) { + fprintf(stderr, + "input line %d: expected blank line after PDU\n", + lineno); + exit(ERROR_USAGE); + } + return(1); +} + +main(argc, argv) + char **argv; +{ + process_cmdline(argc, argv); + atinterf_init(); + /* enable verbose error messages */ + atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0); + /* set PDU mode */ + atinterf_exec_cmd_needok("AT+CMGF=0", 0, 0); + /* process stdin */ + while (process_record()) + ; + exit(0); +}