FreeCalypso > hg > freecalypso-tools
comparison uptools/atcmd/smsend_main.c @ 380:a8abaa85c378
fcup-smsend: preparations for adding UCS-2 support
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 09 Mar 2018 00:43:36 +0000 |
| parents | 0bd06f481223 |
| children | 40b1498ec39d |
comparison
equal
deleted
inserted
replaced
| 379:a38805b5b6d4 | 380:a8abaa85c378 |
|---|---|
| 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 (153*255) | 13 #define MAX_MSG_CHARS (153*255) |
| 14 | 14 #define MAX_MSG_UNI (67*255) |
| 15 int sms_write_mode, text_mode, utf8_input; | 15 |
| 16 int sms_write_mode, text_mode, utf8_input, ucs2_mode; | |
| 16 int concat_enable, concat_refno_set, concat_quiet; | 17 int concat_enable, concat_refno_set, concat_quiet; |
| 17 u_char dest_addr[12]; | 18 u_char dest_addr[12]; |
| 18 char msgtext[MAX_MSG_CHARS*2+2]; | 19 char msgtext[MAX_MSG_CHARS*2+2]; |
| 19 u_char msgtext_gsm7[MAX_MSG_CHARS]; | 20 u_char msgtext_gsm7[MAX_MSG_CHARS]; |
| 20 unsigned msgtext_gsmlen; | 21 u_short msgtext_uni[MAX_MSG_UNI]; |
| 22 unsigned msgtext_gsmlen, msgtext_unilen; | |
| 21 u_char concat_refno; | 23 u_char concat_refno; |
| 22 | 24 |
| 23 process_cmdline(argc, argv) | 25 process_cmdline(argc, argv) |
| 24 char **argv; | 26 char **argv; |
| 25 { | 27 { |
| 26 int c; | 28 int c; |
| 27 extern int optind; | 29 extern int optind; |
| 28 extern char *optarg; | 30 extern char *optarg; |
| 29 | 31 |
| 30 while ((c = getopt(argc, argv, "B:cC:np:qRtuwWX:")) != EOF) { | 32 while ((c = getopt(argc, argv, "B:cC:np:qRtuUwWX:")) != EOF) { |
| 31 if (atinterf_cmdline_opt(c)) | 33 if (atinterf_cmdline_opt(c)) |
| 32 continue; | 34 continue; |
| 33 switch (c) { | 35 switch (c) { |
| 34 case 'c': | 36 case 'c': |
| 35 concat_enable = 1; | 37 concat_enable = 1; |
| 46 text_mode = 1; | 48 text_mode = 1; |
| 47 continue; | 49 continue; |
| 48 case 'u': | 50 case 'u': |
| 49 utf8_input = 1; | 51 utf8_input = 1; |
| 50 continue; | 52 continue; |
| 53 case 'U': | |
| 54 ucs2_mode = 1; | |
| 55 continue; | |
| 51 case 'w': | 56 case 'w': |
| 52 sms_write_mode = 1; | 57 sms_write_mode = 1; |
| 53 continue; | 58 continue; |
| 54 case 'W': | 59 case 'W': |
| 55 sms_write_mode = 2; | 60 sms_write_mode = 2; |
| 61 } | 66 } |
| 62 } | 67 } |
| 63 if (concat_enable && text_mode) { | 68 if (concat_enable && text_mode) { |
| 64 fprintf(stderr, | 69 fprintf(stderr, |
| 65 "%s error: cannot send concat SMS in text mode\n", | 70 "%s error: cannot send concat SMS in text mode\n", |
| 71 argv[0]); | |
| 72 exit(ERROR_USAGE); | |
| 73 } | |
| 74 if (ucs2_mode && text_mode) { | |
| 75 fprintf(stderr, "%s error: UCS-2 not supported in text mode\n", | |
| 66 argv[0]); | 76 argv[0]); |
| 67 exit(ERROR_USAGE); | 77 exit(ERROR_USAGE); |
| 68 } | 78 } |
| 69 if (argc > optind + 2) { | 79 if (argc > optind + 2) { |
| 70 fprintf(stderr, "usage: %s [options] dest-addr [message]\n", | 80 fprintf(stderr, "usage: %s [options] dest-addr [message]\n", |
| 136 atinterf_init(); | 146 atinterf_init(); |
| 137 /* enable verbose error messages */ | 147 /* enable verbose error messages */ |
| 138 atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0); | 148 atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0); |
| 139 } | 149 } |
| 140 | 150 |
| 141 main(argc, argv) | 151 gsm7_mode_main() |
| 142 char **argv; | |
| 143 { | 152 { |
| 144 int rc; | 153 int rc; |
| 145 unsigned nparts, n; | 154 unsigned nparts, n; |
| 146 u_char udh[5]; | 155 u_char udh[5]; |
| 147 unsigned pos, remain, chunk; | 156 unsigned pos, remain, chunk; |
| 148 | 157 |
| 149 if (!process_cmdline(argc, argv)) | |
| 150 read_msgtext_from_stdin(); | |
| 151 if (utf8_input && utf8_to_latin1(msgtext) < 0) { | 158 if (utf8_input && utf8_to_latin1(msgtext) < 0) { |
| 152 fprintf(stderr, "error: invalid UTF-8 message\n"); | 159 fprintf(stderr, "error: invalid UTF-8 message\n"); |
| 153 exit(ERROR_USAGE); | 160 exit(ERROR_USAGE); |
| 154 } | 161 } |
| 155 trim_trailing_newlines(); | |
| 156 if (text_mode) { | 162 if (text_mode) { |
| 157 if (index(msgtext, '\n')) { | 163 if (index(msgtext, '\n')) { |
| 158 fprintf(stderr, | 164 fprintf(stderr, |
| 159 "error: multiline messages not supported in text mode\n"); | 165 "error: multiline messages not supported in text mode\n"); |
| 160 exit(ERROR_USAGE); | 166 exit(ERROR_USAGE); |
| 220 sendafterwr_process(); | 226 sendafterwr_process(); |
| 221 if (!concat_quiet) | 227 if (!concat_quiet) |
| 222 printf("Message sent as %u SMS segments\n", nparts); | 228 printf("Message sent as %u SMS segments\n", nparts); |
| 223 exit(0); | 229 exit(0); |
| 224 } | 230 } |
| 231 | |
| 232 main(argc, argv) | |
| 233 char **argv; | |
| 234 { | |
| 235 if (!process_cmdline(argc, argv)) | |
| 236 read_msgtext_from_stdin(); | |
| 237 trim_trailing_newlines(); | |
| 238 gsm7_mode_main(); | |
| 239 } |
