comparison uptools/atcmd/smsend_main.c @ 367:ed1ecc249eb3

fcup-smsend: prep for adding concat SMS support
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 08 Mar 2018 07:27:45 +0000
parents 9f856f843620
children 3cc79e260066
comparison
equal deleted inserted replaced
366:9f856f843620 367:ed1ecc249eb3
8 #include <string.h> 8 #include <string.h>
9 #include <strings.h> 9 #include <strings.h>
10 #include <unistd.h> 10 #include <unistd.h>
11 #include "../../rvinterf/include/exitcodes.h" 11 #include "../../rvinterf/include/exitcodes.h"
12 12
13 #define MAX_MSG_CHARS 160 13 #define MAX_MSG_CHARS (153*255)
14 14
15 int sms_write_mode, text_mode, utf8_input; 15 int sms_write_mode, text_mode, utf8_input, concat_enable;
16 u_char dest_addr[12]; 16 u_char dest_addr[12];
17 char msgtext[MAX_MSG_CHARS*2+2]; 17 char msgtext[MAX_MSG_CHARS*2+2];
18 u_char msgtext_gsm7[MAX_MSG_CHARS]; 18 u_char msgtext_gsm7[MAX_MSG_CHARS];
19 unsigned msgtext_gsmlen; 19 unsigned msgtext_gsmlen;
20 20
22 char **argv; 22 char **argv;
23 { 23 {
24 int c; 24 int c;
25 extern int optind; 25 extern int optind;
26 26
27 while ((c = getopt(argc, argv, "B:np:RtuwWX:")) != EOF) { 27 while ((c = getopt(argc, argv, "B:cnp:RtuwWX:")) != EOF) {
28 if (atinterf_cmdline_opt(c)) 28 if (atinterf_cmdline_opt(c))
29 continue; 29 continue;
30 switch (c) { 30 switch (c) {
31 case 'c':
32 concat_enable = 1;
33 continue;
31 case 't': 34 case 't':
32 text_mode = 1; 35 text_mode = 1;
33 continue; 36 continue;
34 case 'u': 37 case 'u':
35 utf8_input = 1; 38 utf8_input = 1;
42 continue; 45 continue;
43 default: 46 default:
44 /* error msg already printed */ 47 /* error msg already printed */
45 exit(ERROR_USAGE); 48 exit(ERROR_USAGE);
46 } 49 }
50 }
51 if (concat_enable && text_mode) {
52 fprintf(stderr, "%s error: -c and -t are mutually exclusive\n",
53 argv[0]);
54 exit(ERROR_USAGE);
47 } 55 }
48 if (argc > optind + 2) { 56 if (argc > optind + 2) {
49 fprintf(stderr, "usage: %s [options] dest-addr [message]\n", 57 fprintf(stderr, "usage: %s [options] dest-addr [message]\n",
50 argv[0]); 58 argv[0]);
51 exit(ERROR_USAGE); 59 exit(ERROR_USAGE);
108 while (cp > msgtext && cp[-1] == '\n') 116 while (cp > msgtext && cp[-1] == '\n')
109 cp--; 117 cp--;
110 *cp = '\0'; 118 *cp = '\0';
111 } 119 }
112 120
121 common_init()
122 {
123 atinterf_init();
124 /* enable verbose error messages */
125 atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0);
126 }
127
113 main(argc, argv) 128 main(argc, argv)
114 char **argv; 129 char **argv;
115 { 130 {
116 int rc; 131 int rc;
117 132
127 fprintf(stderr, 142 fprintf(stderr,
128 "error: multiline messages not supported in text mode\n"); 143 "error: multiline messages not supported in text mode\n");
129 exit(ERROR_USAGE); 144 exit(ERROR_USAGE);
130 } 145 }
131 if (strlen(msgtext) > 160) { 146 if (strlen(msgtext) > 160) {
132 toolong: fprintf(stderr, "error: message exceeds 160 chars\n"); 147 too_long_for_one_sms: fprintf(stderr, "error: message exceeds 160 chars\n");
133 exit(ERROR_USAGE); 148 exit(ERROR_USAGE);
134 } 149 }
135 } else { 150 common_init();
136 rc = latin1_to_gsm7(msgtext, msgtext_gsm7, 160,
137 &msgtext_gsmlen);
138 if (rc == -1) {
139 fprintf(stderr,
140 "error: message not valid for GSM7 charset\n");
141 exit(ERROR_USAGE);
142 }
143 if (rc == -2)
144 goto toolong;
145 }
146 /* get to work */
147 atinterf_init();
148 /* enable verbose error messages */
149 atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0);
150 if (text_mode) {
151 prep_for_text_mode(); 151 prep_for_text_mode();
152 send_in_text_mode(dest_addr, msgtext); 152 send_in_text_mode(dest_addr, msgtext);
153 } else { 153 if (sms_write_mode == 1)
154 sendafterwr_process();
155 exit(0);
156 }
157 rc = latin1_to_gsm7(msgtext, msgtext_gsm7, MAX_MSG_CHARS,
158 &msgtext_gsmlen);
159 if (rc == -1) {
160 fprintf(stderr, "error: message not valid for GSM7 charset\n");
161 exit(ERROR_USAGE);
162 }
163 if (rc == -2) {
164 fprintf(stderr, "error: message too long for max concat SMS\n");
165 exit(ERROR_USAGE);
166 }
167 if (msgtext_gsmlen <= 160) {
168 common_init();
154 prep_for_pdu_mode(); 169 prep_for_pdu_mode();
155 send_in_pdu_mode(dest_addr, msgtext_gsm7, msgtext_gsmlen, 0, 0); 170 send_in_pdu_mode(dest_addr, msgtext_gsm7, msgtext_gsmlen, 0, 0);
171 if (sms_write_mode == 1)
172 sendafterwr_process();
173 if (concat_enable)
174 printf("Message sent as single SMS\n");
175 exit(0);
156 } 176 }
157 if (sms_write_mode == 1) 177 if (!concat_enable)
158 sendafterwr_process(); 178 goto too_long_for_one_sms;
159 exit(0); 179
180 fprintf(stderr, "concat SMS not yet implemented\n");
181 exit(ERROR_BUG);
160 } 182 }