comparison uptools/atcmd/smsend_main.c @ 381:40b1498ec39d

fcup-smsend: UCS-2 send mode implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 09 Mar 2018 02:31:15 +0000
parents a8abaa85c378
children ed9b67e7e741
comparison
equal deleted inserted replaced
380:a8abaa85c378 381:40b1498ec39d
15 15
16 int sms_write_mode, text_mode, utf8_input, ucs2_mode; 16 int sms_write_mode, text_mode, utf8_input, ucs2_mode;
17 int concat_enable, concat_refno_set, concat_quiet; 17 int concat_enable, concat_refno_set, concat_quiet;
18 u_char dest_addr[12]; 18 u_char dest_addr[12];
19 char msgtext[MAX_MSG_CHARS*2+2]; 19 char msgtext[MAX_MSG_CHARS*2+2];
20 u_char msgtext_gsm7[MAX_MSG_CHARS];
21 u_short msgtext_uni[MAX_MSG_UNI];
22 unsigned msgtext_gsmlen, msgtext_unilen;
23 u_char concat_refno; 20 u_char concat_refno;
24 21
25 process_cmdline(argc, argv) 22 process_cmdline(argc, argv)
26 char **argv; 23 char **argv;
27 { 24 {
148 atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0); 145 atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0);
149 } 146 }
150 147
151 gsm7_mode_main() 148 gsm7_mode_main()
152 { 149 {
150 u_char msgtext_gsm7[MAX_MSG_CHARS];
151 unsigned msgtext_gsmlen;
153 int rc; 152 int rc;
154 unsigned nparts, n; 153 unsigned nparts, n;
155 u_char udh[5]; 154 u_char udh[5];
156 unsigned pos, remain, chunk; 155 unsigned pos, remain, chunk;
157 156
227 if (!concat_quiet) 226 if (!concat_quiet)
228 printf("Message sent as %u SMS segments\n", nparts); 227 printf("Message sent as %u SMS segments\n", nparts);
229 exit(0); 228 exit(0);
230 } 229 }
231 230
231 ucs2_mode_main()
232 {
233 u_short msgtext_uni[MAX_MSG_UNI];
234 unsigned msgtext_unilen;
235 int rc;
236 unsigned nparts, n;
237 u_char udh[5];
238 unsigned pos, remain, chunk;
239
240 rc = utf8_to_ucs2(msgtext, msgtext_uni, MAX_MSG_UNI, &msgtext_unilen);
241 if (rc == -1) {
242 fprintf(stderr, "error: invalid UTF-8 message\n");
243 exit(ERROR_USAGE);
244 }
245 if (rc == -2) {
246 fprintf(stderr, "error: message too long for max concat SMS\n");
247 exit(ERROR_USAGE);
248 }
249 if (msgtext_unilen <= 70) {
250 common_init();
251 prep_for_pdu_mode();
252 send_pdu_ucs2(dest_addr, msgtext_uni, msgtext_unilen, 0, 0);
253 if (sms_write_mode == 1)
254 sendafterwr_process();
255 if (concat_enable && !concat_quiet)
256 printf("Message sent as single SMS\n");
257 exit(0);
258 }
259 if (!concat_enable) {
260 fprintf(stderr, "error: message exceeds 70 UCS-2 chars\n");
261 exit(ERROR_USAGE);
262 }
263 if (!concat_refno_set)
264 concat_refno = get_concsms_refno_from_host_fs();
265 nparts = (msgtext_unilen + 66) / 67;
266 udh[0] = 0x00;
267 udh[1] = 0x03;
268 udh[2] = concat_refno;
269 udh[3] = nparts;
270 common_init();
271 prep_for_pdu_mode();
272 if (sms_write_mode == 0)
273 atinterf_exec_cmd_needok("AT+CMMS=1", 0, 0);
274 pos = 0;
275 remain = msgtext_unilen;
276 for (n = 1; n <= nparts; n++) {
277 udh[4] = n;
278 chunk = 67;
279 if (chunk > remain)
280 chunk = remain;
281 send_pdu_ucs2(dest_addr, msgtext_uni + pos, chunk, udh, 5);
282 pos += chunk;
283 remain -= chunk;
284 }
285 if (sms_write_mode == 0)
286 atinterf_exec_cmd_needok("AT+CMMS=0", 0, 0);
287 if (sms_write_mode == 1)
288 sendafterwr_process();
289 if (!concat_quiet)
290 printf("Message sent as %u SMS segments\n", nparts);
291 exit(0);
292 }
293
232 main(argc, argv) 294 main(argc, argv)
233 char **argv; 295 char **argv;
234 { 296 {
235 if (!process_cmdline(argc, argv)) 297 if (!process_cmdline(argc, argv))
236 read_msgtext_from_stdin(); 298 read_msgtext_from_stdin();
237 trim_trailing_newlines(); 299 trim_trailing_newlines();
238 gsm7_mode_main(); 300 if (ucs2_mode)
239 } 301 ucs2_mode_main();
302 else
303 gsm7_mode_main();
304 }