# HG changeset patch # User Mychaela Falconia # Date 1520492977 0 # Node ID 9f856f8436203860b512f27d59304a15001fca7a # Parent 4378d70b146b91e69e4ef0cd7c857205742ca941 uptools/atcmd: smsend_basic.c renamed to smsend_main.c diff -r 4378d70b146b -r 9f856f843620 uptools/atcmd/Makefile --- a/uptools/atcmd/Makefile Thu Mar 08 07:04:06 2018 +0000 +++ b/uptools/atcmd/Makefile Thu Mar 08 07:09:37 2018 +0000 @@ -9,7 +9,7 @@ SMDUMP_OBJS= atinterf.o resp_parse.o smdump.o ${LIBCODING} -SMSEND_OBJS= atinterf.o resp_parse.o smsend_basic.o smsend_cmgw.o \ +SMSEND_OBJS= atinterf.o resp_parse.o smsend_cmgw.o smsend_main.o \ smsend_pdu.o smsend_text.o ${LIBCODING} all: ${PROGS} diff -r 4378d70b146b -r 9f856f843620 uptools/atcmd/smsend_basic.c --- a/uptools/atcmd/smsend_basic.c Thu Mar 08 07:04:06 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,160 +0,0 @@ -/* - * This is the main module for the basic fcup-smsend utility. - */ - -#include -#include -#include -#include -#include -#include -#include "../../rvinterf/include/exitcodes.h" - -#define MAX_MSG_CHARS 160 - -int sms_write_mode, text_mode, utf8_input; -u_char dest_addr[12]; -char msgtext[MAX_MSG_CHARS*2+2]; -u_char msgtext_gsm7[MAX_MSG_CHARS]; -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 + 2) { - fprintf(stderr, "usage: %s [options] dest-addr [message]\n", - argv[0]); - exit(ERROR_USAGE); - } - if (!argv[optind] || !argv[optind][0]) { - if (sms_write_mode == 2) { - dest_addr[0] = 0; - dest_addr[1] = 0x80; - } else { - fprintf(stderr, - "error: destination address must be specified\n"); - exit(ERROR_USAGE); - } - } else if (parse_and_encode_dest_addr(argv[optind], dest_addr) < 0) { - fprintf(stderr, - "error: destination address argument is invalid\n"); - exit(ERROR_USAGE); - } - if (!argv[optind+1]) - return(0); - if (strlen(argv[optind+1]) > MAX_MSG_CHARS*2) { - fprintf(stderr, "error: message argument is too long\n"); - exit(ERROR_USAGE); - } - strcpy(msgtext, argv[optind+1]); - return(1); -} - -read_msgtext_from_stdin() -{ - unsigned pos, remain; - int cc; - - pos = 0; - remain = sizeof(msgtext); - for (;;) { - if (!remain) { - fprintf(stderr, - "error: message on stdin is too long\n"); - exit(ERROR_USAGE); - } - cc = read(0, msgtext + pos, remain); - if (cc < 0) { - fprintf(stderr, "error reading message from stdin\n"); - exit(ERROR_USAGE); - } - if (cc == 0) - break; - pos += cc; - remain -= cc; - } - msgtext[pos] = '\0'; -} - -trim_trailing_newlines() -{ - char *cp; - - cp = index(msgtext, '\0'); - while (cp > msgtext && cp[-1] == '\n') - cp--; - *cp = '\0'; -} - -main(argc, argv) - char **argv; -{ - int rc; - - if (!process_cmdline(argc, argv)) - read_msgtext_from_stdin(); - if (utf8_input && utf8_to_latin1(msgtext) < 0) { - fprintf(stderr, "error: invalid UTF-8 message\n"); - exit(ERROR_USAGE); - } - trim_trailing_newlines(); - if (text_mode) { - if (index(msgtext, '\n')) { - fprintf(stderr, - "error: multiline messages not supported in text mode\n"); - exit(ERROR_USAGE); - } - if (strlen(msgtext) > 160) { -toolong: fprintf(stderr, "error: message exceeds 160 chars\n"); - exit(ERROR_USAGE); - } - } else { - rc = latin1_to_gsm7(msgtext, msgtext_gsm7, 160, - &msgtext_gsmlen); - if (rc == -1) { - fprintf(stderr, - "error: message not valid for GSM7 charset\n"); - exit(ERROR_USAGE); - } - if (rc == -2) - goto toolong; - } - /* get to work */ - atinterf_init(); - /* enable verbose error messages */ - atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0); - if (text_mode) { - prep_for_text_mode(); - send_in_text_mode(dest_addr, msgtext); - } else { - prep_for_pdu_mode(); - send_in_pdu_mode(dest_addr, msgtext_gsm7, msgtext_gsmlen, 0, 0); - } - if (sms_write_mode == 1) - sendafterwr_process(); - exit(0); -} diff -r 4378d70b146b -r 9f856f843620 uptools/atcmd/smsend_main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uptools/atcmd/smsend_main.c Thu Mar 08 07:09:37 2018 +0000 @@ -0,0 +1,160 @@ +/* + * This is the main module for the basic fcup-smsend utility. + */ + +#include +#include +#include +#include +#include +#include +#include "../../rvinterf/include/exitcodes.h" + +#define MAX_MSG_CHARS 160 + +int sms_write_mode, text_mode, utf8_input; +u_char dest_addr[12]; +char msgtext[MAX_MSG_CHARS*2+2]; +u_char msgtext_gsm7[MAX_MSG_CHARS]; +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 + 2) { + fprintf(stderr, "usage: %s [options] dest-addr [message]\n", + argv[0]); + exit(ERROR_USAGE); + } + if (!argv[optind] || !argv[optind][0]) { + if (sms_write_mode == 2) { + dest_addr[0] = 0; + dest_addr[1] = 0x80; + } else { + fprintf(stderr, + "error: destination address must be specified\n"); + exit(ERROR_USAGE); + } + } else if (parse_and_encode_dest_addr(argv[optind], dest_addr) < 0) { + fprintf(stderr, + "error: destination address argument is invalid\n"); + exit(ERROR_USAGE); + } + if (!argv[optind+1]) + return(0); + if (strlen(argv[optind+1]) > MAX_MSG_CHARS*2) { + fprintf(stderr, "error: message argument is too long\n"); + exit(ERROR_USAGE); + } + strcpy(msgtext, argv[optind+1]); + return(1); +} + +read_msgtext_from_stdin() +{ + unsigned pos, remain; + int cc; + + pos = 0; + remain = sizeof(msgtext); + for (;;) { + if (!remain) { + fprintf(stderr, + "error: message on stdin is too long\n"); + exit(ERROR_USAGE); + } + cc = read(0, msgtext + pos, remain); + if (cc < 0) { + fprintf(stderr, "error reading message from stdin\n"); + exit(ERROR_USAGE); + } + if (cc == 0) + break; + pos += cc; + remain -= cc; + } + msgtext[pos] = '\0'; +} + +trim_trailing_newlines() +{ + char *cp; + + cp = index(msgtext, '\0'); + while (cp > msgtext && cp[-1] == '\n') + cp--; + *cp = '\0'; +} + +main(argc, argv) + char **argv; +{ + int rc; + + if (!process_cmdline(argc, argv)) + read_msgtext_from_stdin(); + if (utf8_input && utf8_to_latin1(msgtext) < 0) { + fprintf(stderr, "error: invalid UTF-8 message\n"); + exit(ERROR_USAGE); + } + trim_trailing_newlines(); + if (text_mode) { + if (index(msgtext, '\n')) { + fprintf(stderr, + "error: multiline messages not supported in text mode\n"); + exit(ERROR_USAGE); + } + if (strlen(msgtext) > 160) { +toolong: fprintf(stderr, "error: message exceeds 160 chars\n"); + exit(ERROR_USAGE); + } + } else { + rc = latin1_to_gsm7(msgtext, msgtext_gsm7, 160, + &msgtext_gsmlen); + if (rc == -1) { + fprintf(stderr, + "error: message not valid for GSM7 charset\n"); + exit(ERROR_USAGE); + } + if (rc == -2) + goto toolong; + } + /* get to work */ + atinterf_init(); + /* enable verbose error messages */ + atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0); + if (text_mode) { + prep_for_text_mode(); + send_in_text_mode(dest_addr, msgtext); + } else { + prep_for_pdu_mode(); + send_in_pdu_mode(dest_addr, msgtext_gsm7, msgtext_gsmlen, 0, 0); + } + if (sms_write_mode == 1) + sendafterwr_process(); + exit(0); +}