FreeCalypso > hg > freecalypso-tools
comparison uptools/atcmd/smsend_multmain.c @ 382:88131632ce48
fcup-smsendmult: preparations for adding UCS-2 support
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 09 Mar 2018 02:48:41 +0000 |
parents | 1fa4dcbb1c87 |
children | f8c693d16978 |
comparison
equal
deleted
inserted
replaced
381:40b1498ec39d | 382:88131632ce48 |
---|---|
9 #include <string.h> | 9 #include <string.h> |
10 #include <strings.h> | 10 #include <strings.h> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 #include "../../rvinterf/include/exitcodes.h" | 12 #include "../../rvinterf/include/exitcodes.h" |
13 | 13 |
14 int sms_write_mode, text_mode, utf8_input; | 14 int sms_write_mode, text_mode, utf8_input, ucs2_mode; |
15 u_char dest_addr[12]; | 15 u_char dest_addr[12]; |
16 int dest_addr_global; | 16 int dest_addr_global; |
17 char input_line[21+5+1+320+2], *msgtext; | 17 char input_line[21+5+1+320+2], *msgtext; |
18 int lineno; | 18 int lineno; |
19 u_char msgtext_gsm7[160]; | 19 int initdone; |
20 unsigned msgtext_gsmlen; | |
21 | 20 |
22 process_cmdline(argc, argv) | 21 process_cmdline(argc, argv) |
23 char **argv; | 22 char **argv; |
24 { | 23 { |
25 int c; | 24 int c; |
26 extern int optind; | 25 extern int optind; |
27 | 26 |
28 while ((c = getopt(argc, argv, "B:np:RtuwWX:")) != EOF) { | 27 while ((c = getopt(argc, argv, "B:np:RtuUwWX:")) != EOF) { |
29 if (atinterf_cmdline_opt(c)) | 28 if (atinterf_cmdline_opt(c)) |
30 continue; | 29 continue; |
31 switch (c) { | 30 switch (c) { |
32 case 't': | 31 case 't': |
33 text_mode = 1; | 32 text_mode = 1; |
34 continue; | 33 continue; |
35 case 'u': | 34 case 'u': |
36 utf8_input = 1; | 35 utf8_input = 1; |
36 continue; | |
37 case 'U': | |
38 ucs2_mode = 1; | |
37 continue; | 39 continue; |
38 case 'w': | 40 case 'w': |
39 sms_write_mode = 1; | 41 sms_write_mode = 1; |
40 continue; | 42 continue; |
41 case 'W': | 43 case 'W': |
43 continue; | 45 continue; |
44 default: | 46 default: |
45 /* error msg already printed */ | 47 /* error msg already printed */ |
46 exit(ERROR_USAGE); | 48 exit(ERROR_USAGE); |
47 } | 49 } |
50 } | |
51 if (ucs2_mode && text_mode) { | |
52 fprintf(stderr, "%s error: UCS-2 not supported in text mode\n", | |
53 argv[0]); | |
54 exit(ERROR_USAGE); | |
48 } | 55 } |
49 if (argc > optind + 1) { | 56 if (argc > optind + 1) { |
50 fprintf(stderr, "usage: %s [options] [dest-addr]\n", | 57 fprintf(stderr, "usage: %s [options] [dest-addr]\n", |
51 argv[0]); | 58 argv[0]); |
52 exit(ERROR_USAGE); | 59 exit(ERROR_USAGE); |
93 cp++; | 100 cp++; |
94 msgtext = cp; | 101 msgtext = cp; |
95 return(1); | 102 return(1); |
96 } | 103 } |
97 | 104 |
98 preen_message() | 105 init_send_process() |
99 { | 106 { |
107 if (initdone) | |
108 return(0); | |
109 atinterf_init(); | |
110 /* enable verbose error messages */ | |
111 atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0); | |
112 if (text_mode) | |
113 prep_for_text_mode(); | |
114 else | |
115 prep_for_pdu_mode(); | |
116 if (sms_write_mode == 0) | |
117 atinterf_exec_cmd_needok("AT+CMMS=1", 0, 0); | |
118 initdone = 1; | |
119 return(1); | |
120 } | |
121 | |
122 process_msg_gsm7() | |
123 { | |
124 u_char msgtext_gsm7[160]; | |
125 unsigned msgtext_gsmlen; | |
100 int rc; | 126 int rc; |
101 | 127 |
102 if (utf8_input && utf8_to_latin1(msgtext) < 0) { | 128 if (utf8_input && utf8_to_latin1(msgtext) < 0) { |
103 fprintf(stderr, "input line %d: invalid UTF-8 message\n", | 129 fprintf(stderr, "input line %d: invalid UTF-8 message\n", |
104 lineno); | 130 lineno); |
109 toolong: fprintf(stderr, | 135 toolong: fprintf(stderr, |
110 "input line %d: message exceeds 160 chars\n", | 136 "input line %d: message exceeds 160 chars\n", |
111 lineno); | 137 lineno); |
112 exit(ERROR_USAGE); | 138 exit(ERROR_USAGE); |
113 } | 139 } |
140 init_send_process(); | |
141 send_in_text_mode(dest_addr, msgtext); | |
114 return(0); | 142 return(0); |
115 } | 143 } |
116 rc = latin1_to_gsm7(msgtext, msgtext_gsm7, 160, &msgtext_gsmlen); | 144 rc = latin1_to_gsm7(msgtext, msgtext_gsm7, 160, &msgtext_gsmlen); |
117 if (rc == -1) { | 145 if (rc == -1) { |
118 fprintf(stderr, | 146 fprintf(stderr, |
120 lineno); | 148 lineno); |
121 exit(ERROR_USAGE); | 149 exit(ERROR_USAGE); |
122 } | 150 } |
123 if (rc == -2) | 151 if (rc == -2) |
124 goto toolong; | 152 goto toolong; |
153 init_send_process(); | |
154 send_in_pdu_mode(dest_addr, msgtext_gsm7, msgtext_gsmlen, 0, 0); | |
125 return(0); | 155 return(0); |
126 } | |
127 | |
128 init_send_process() | |
129 { | |
130 atinterf_init(); | |
131 /* enable verbose error messages */ | |
132 atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0); | |
133 if (text_mode) | |
134 prep_for_text_mode(); | |
135 else | |
136 prep_for_pdu_mode(); | |
137 if (sms_write_mode == 0) | |
138 atinterf_exec_cmd_needok("AT+CMMS=1", 0, 0); | |
139 } | 156 } |
140 | 157 |
141 main(argc, argv) | 158 main(argc, argv) |
142 char **argv; | 159 char **argv; |
143 { | 160 { |
144 int initdone = 0; | |
145 | |
146 process_cmdline(argc, argv); | 161 process_cmdline(argc, argv); |
147 for (lineno = 1; fgets(input_line, sizeof input_line, stdin); lineno++){ | 162 for (lineno = 1; fgets(input_line, sizeof input_line, stdin); lineno++){ |
148 preen_input_line(); | 163 preen_input_line(); |
149 preen_message(); | 164 process_msg_gsm7(); |
150 if (!initdone) { | |
151 init_send_process(); | |
152 initdone = 1; | |
153 } | |
154 if (text_mode) | |
155 send_in_text_mode(dest_addr, msgtext); | |
156 else | |
157 send_in_pdu_mode(dest_addr, msgtext_gsm7, | |
158 msgtext_gsmlen, 0, 0); | |
159 } | 165 } |
160 if (!initdone) | 166 if (!initdone) |
161 exit(0); | 167 exit(0); |
162 if (sms_write_mode == 0) | 168 if (sms_write_mode == 0) |
163 atinterf_exec_cmd_needok("AT+CMMS=0", 0, 0); | 169 atinterf_exec_cmd_needok("AT+CMMS=0", 0, 0); |