FreeCalypso > hg > freecalypso-tools
comparison uptools/atcmd/smsend_main.c @ 368:3cc79e260066
fcup-smsend: implemented concat SMS sending with user-given refno
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 08 Mar 2018 16:28:26 +0000 |
parents | ed1ecc249eb3 |
children | 06cf82710cca |
comparison
equal
deleted
inserted
replaced
367:ed1ecc249eb3 | 368:3cc79e260066 |
---|---|
15 int sms_write_mode, text_mode, utf8_input, concat_enable; | 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 u_char concat_refno; | |
20 | 21 |
21 process_cmdline(argc, argv) | 22 process_cmdline(argc, argv) |
22 char **argv; | 23 char **argv; |
23 { | 24 { |
24 int c; | 25 int c; |
25 extern int optind; | 26 extern int optind; |
26 | 27 extern char *optarg; |
27 while ((c = getopt(argc, argv, "B:cnp:RtuwWX:")) != EOF) { | 28 |
29 while ((c = getopt(argc, argv, "B:C:np:RtuwWX:")) != EOF) { | |
28 if (atinterf_cmdline_opt(c)) | 30 if (atinterf_cmdline_opt(c)) |
29 continue; | 31 continue; |
30 switch (c) { | 32 switch (c) { |
31 case 'c': | 33 case 'C': |
32 concat_enable = 1; | 34 concat_enable = 1; |
35 concat_refno = strtoul(optarg, 0, 0); | |
33 continue; | 36 continue; |
34 case 't': | 37 case 't': |
35 text_mode = 1; | 38 text_mode = 1; |
36 continue; | 39 continue; |
37 case 'u': | 40 case 'u': |
47 /* error msg already printed */ | 50 /* error msg already printed */ |
48 exit(ERROR_USAGE); | 51 exit(ERROR_USAGE); |
49 } | 52 } |
50 } | 53 } |
51 if (concat_enable && text_mode) { | 54 if (concat_enable && text_mode) { |
52 fprintf(stderr, "%s error: -c and -t are mutually exclusive\n", | 55 fprintf(stderr, |
56 "%s error: cannot send concat SMS in text mode\n", | |
53 argv[0]); | 57 argv[0]); |
54 exit(ERROR_USAGE); | 58 exit(ERROR_USAGE); |
55 } | 59 } |
56 if (argc > optind + 2) { | 60 if (argc > optind + 2) { |
57 fprintf(stderr, "usage: %s [options] dest-addr [message]\n", | 61 fprintf(stderr, "usage: %s [options] dest-addr [message]\n", |
127 | 131 |
128 main(argc, argv) | 132 main(argc, argv) |
129 char **argv; | 133 char **argv; |
130 { | 134 { |
131 int rc; | 135 int rc; |
136 unsigned nparts, n; | |
137 u_char udh[5]; | |
138 unsigned pos, remain, chunk; | |
132 | 139 |
133 if (!process_cmdline(argc, argv)) | 140 if (!process_cmdline(argc, argv)) |
134 read_msgtext_from_stdin(); | 141 read_msgtext_from_stdin(); |
135 if (utf8_input && utf8_to_latin1(msgtext) < 0) { | 142 if (utf8_input && utf8_to_latin1(msgtext) < 0) { |
136 fprintf(stderr, "error: invalid UTF-8 message\n"); | 143 fprintf(stderr, "error: invalid UTF-8 message\n"); |
174 printf("Message sent as single SMS\n"); | 181 printf("Message sent as single SMS\n"); |
175 exit(0); | 182 exit(0); |
176 } | 183 } |
177 if (!concat_enable) | 184 if (!concat_enable) |
178 goto too_long_for_one_sms; | 185 goto too_long_for_one_sms; |
179 | 186 nparts = (msgtext_gsmlen + 152) / 153; |
180 fprintf(stderr, "concat SMS not yet implemented\n"); | 187 udh[0] = 0x00; |
181 exit(ERROR_BUG); | 188 udh[1] = 0x03; |
182 } | 189 udh[2] = concat_refno; |
190 udh[3] = nparts; | |
191 common_init(); | |
192 prep_for_pdu_mode(); | |
193 if (sms_write_mode == 0) | |
194 atinterf_exec_cmd_needok("AT+CMMS=1", 0, 0); | |
195 pos = 0; | |
196 remain = msgtext_gsmlen; | |
197 for (n = 1; n <= nparts; n++) { | |
198 udh[4] = n; | |
199 chunk = 153; | |
200 if (chunk > remain) | |
201 chunk = remain; | |
202 send_in_pdu_mode(dest_addr, msgtext_gsm7 + pos, chunk, udh, 5); | |
203 pos += chunk; | |
204 remain -= chunk; | |
205 } | |
206 if (sms_write_mode == 0) | |
207 atinterf_exec_cmd_needok("AT+CMMS=0", 0, 0); | |
208 if (sms_write_mode == 1) | |
209 sendafterwr_process(); | |
210 printf("Message sent as %u SMS segments\n", nparts); | |
211 exit(0); | |
212 } |