# HG changeset patch # User Mychaela Falconia # Date 1520563721 0 # Node ID 88131632ce48e615b21e938e20764471b72d30d4 # Parent 40b1498ec39d16d862f8e010212a1dc076b7b9d9 fcup-smsendmult: preparations for adding UCS-2 support diff -r 40b1498ec39d -r 88131632ce48 uptools/atcmd/smsend_multmain.c --- a/uptools/atcmd/smsend_multmain.c Fri Mar 09 02:31:15 2018 +0000 +++ b/uptools/atcmd/smsend_multmain.c Fri Mar 09 02:48:41 2018 +0000 @@ -11,13 +11,12 @@ #include #include "../../rvinterf/include/exitcodes.h" -int sms_write_mode, text_mode, utf8_input; +int sms_write_mode, text_mode, utf8_input, ucs2_mode; 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; +int initdone; process_cmdline(argc, argv) char **argv; @@ -25,7 +24,7 @@ int c; extern int optind; - while ((c = getopt(argc, argv, "B:np:RtuwWX:")) != EOF) { + while ((c = getopt(argc, argv, "B:np:RtuUwWX:")) != EOF) { if (atinterf_cmdline_opt(c)) continue; switch (c) { @@ -35,6 +34,9 @@ case 'u': utf8_input = 1; continue; + case 'U': + ucs2_mode = 1; + continue; case 'w': sms_write_mode = 1; continue; @@ -46,6 +48,11 @@ exit(ERROR_USAGE); } } + if (ucs2_mode && text_mode) { + fprintf(stderr, "%s error: UCS-2 not supported in text mode\n", + argv[0]); + exit(ERROR_USAGE); + } if (argc > optind + 1) { fprintf(stderr, "usage: %s [options] [dest-addr]\n", argv[0]); @@ -95,8 +102,27 @@ return(1); } -preen_message() +init_send_process() { + if (initdone) + return(0); + 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); + initdone = 1; + return(1); +} + +process_msg_gsm7() +{ + u_char msgtext_gsm7[160]; + unsigned msgtext_gsmlen; int rc; if (utf8_input && utf8_to_latin1(msgtext) < 0) { @@ -111,6 +137,8 @@ lineno); exit(ERROR_USAGE); } + init_send_process(); + send_in_text_mode(dest_addr, msgtext); return(0); } rc = latin1_to_gsm7(msgtext, msgtext_gsm7, 160, &msgtext_gsmlen); @@ -122,40 +150,18 @@ } if (rc == -2) goto toolong; + init_send_process(); + send_in_pdu_mode(dest_addr, msgtext_gsm7, msgtext_gsmlen, 0, 0); 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); + process_msg_gsm7(); } if (!initdone) exit(0);