# HG changeset patch # User Mychaela Falconia # Date 1520494065 0 # Node ID ed1ecc249eb366a47d59c4bb604269e621e5f5d0 # Parent 9f856f8436203860b512f27d59304a15001fca7a fcup-smsend: prep for adding concat SMS support diff -r 9f856f843620 -r ed1ecc249eb3 uptools/atcmd/smsend_main.c --- a/uptools/atcmd/smsend_main.c Thu Mar 08 07:09:37 2018 +0000 +++ b/uptools/atcmd/smsend_main.c Thu Mar 08 07:27:45 2018 +0000 @@ -10,9 +10,9 @@ #include #include "../../rvinterf/include/exitcodes.h" -#define MAX_MSG_CHARS 160 +#define MAX_MSG_CHARS (153*255) -int sms_write_mode, text_mode, utf8_input; +int sms_write_mode, text_mode, utf8_input, concat_enable; u_char dest_addr[12]; char msgtext[MAX_MSG_CHARS*2+2]; u_char msgtext_gsm7[MAX_MSG_CHARS]; @@ -24,10 +24,13 @@ int c; extern int optind; - while ((c = getopt(argc, argv, "B:np:RtuwWX:")) != EOF) { + while ((c = getopt(argc, argv, "B:cnp:RtuwWX:")) != EOF) { if (atinterf_cmdline_opt(c)) continue; switch (c) { + case 'c': + concat_enable = 1; + continue; case 't': text_mode = 1; continue; @@ -45,6 +48,11 @@ exit(ERROR_USAGE); } } + if (concat_enable && text_mode) { + fprintf(stderr, "%s error: -c and -t are mutually exclusive\n", + argv[0]); + exit(ERROR_USAGE); + } if (argc > optind + 2) { fprintf(stderr, "usage: %s [options] dest-addr [message]\n", argv[0]); @@ -110,6 +118,13 @@ *cp = '\0'; } +common_init() +{ + atinterf_init(); + /* enable verbose error messages */ + atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0); +} + main(argc, argv) char **argv; { @@ -129,32 +144,39 @@ 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"); +too_long_for_one_sms: fprintf(stderr, "error: message exceeds 160 chars\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) { + common_init(); prep_for_text_mode(); send_in_text_mode(dest_addr, msgtext); - } else { + if (sms_write_mode == 1) + sendafterwr_process(); + exit(0); + } + rc = latin1_to_gsm7(msgtext, msgtext_gsm7, MAX_MSG_CHARS, + &msgtext_gsmlen); + if (rc == -1) { + fprintf(stderr, "error: message not valid for GSM7 charset\n"); + exit(ERROR_USAGE); + } + if (rc == -2) { + fprintf(stderr, "error: message too long for max concat SMS\n"); + exit(ERROR_USAGE); + } + if (msgtext_gsmlen <= 160) { + common_init(); prep_for_pdu_mode(); send_in_pdu_mode(dest_addr, msgtext_gsm7, msgtext_gsmlen, 0, 0); + if (sms_write_mode == 1) + sendafterwr_process(); + if (concat_enable) + printf("Message sent as single SMS\n"); + exit(0); } - if (sms_write_mode == 1) - sendafterwr_process(); - exit(0); + if (!concat_enable) + goto too_long_for_one_sms; + + fprintf(stderr, "concat SMS not yet implemented\n"); + exit(ERROR_BUG); }