FreeCalypso > hg > freecalypso-tools
comparison uptools/atcmd/smwrite.c @ 385:ce3b57b8920b
fcup-smwrite program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 09 Mar 2018 20:43:53 +0000 |
parents | |
children | dc2fd8e6f42c |
comparison
equal
deleted
inserted
replaced
384:3eb92855f7b9 | 385:ce3b57b8920b |
---|---|
1 /* | |
2 * This program is a debug and development aid - it uses the AT+CMGW command | |
3 * in PDU mode to write messages into SIM or ME SMS storage, simulating | |
4 * arbitrary received or sent messages. This trick may come in useful | |
5 * in the development and testing of SMS handling in phone handset UI firmware. | |
6 */ | |
7 | |
8 #include <sys/types.h> | |
9 #include <ctype.h> | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 #include <string.h> | |
13 #include <strings.h> | |
14 #include <unistd.h> | |
15 #include "../../rvinterf/include/exitcodes.h" | |
16 | |
17 extern char at_response[]; | |
18 | |
19 char input_line[176*2+2]; | |
20 int lineno; | |
21 | |
22 process_cmdline(argc, argv) | |
23 char **argv; | |
24 { | |
25 int c; | |
26 extern int optind; | |
27 | |
28 while ((c = getopt(argc, argv, "B:np:RX:")) != EOF) | |
29 if (!atinterf_cmdline_opt(c)) { | |
30 /* error msg already printed */ | |
31 exit(ERROR_USAGE); | |
32 } | |
33 if (argc != optind) { | |
34 fprintf(stderr, "usage: %s [options]\n", argv[0]); | |
35 exit(ERROR_USAGE); | |
36 } | |
37 return(0); | |
38 } | |
39 | |
40 get_input_line() | |
41 { | |
42 char *nl; | |
43 | |
44 if (!fgets(input_line, sizeof input_line, stdin)) | |
45 return(0); | |
46 lineno++; | |
47 nl = index(input_line, '\n'); | |
48 if (!nl) { | |
49 fprintf(stderr, "input line %d: too long or unterminated\n", | |
50 lineno); | |
51 exit(ERROR_USAGE); | |
52 } | |
53 *nl = '\0'; | |
54 return(1); | |
55 } | |
56 | |
57 get_input_line_noeof() | |
58 { | |
59 int rc; | |
60 | |
61 rc = get_input_line(); | |
62 if (!rc) { | |
63 fprintf(stderr, "error: premature EOF in input\n"); | |
64 exit(ERROR_USAGE); | |
65 } | |
66 } | |
67 | |
68 cmgw_callback() | |
69 { | |
70 /* skip empty lines */ | |
71 if (at_response[1]) | |
72 puts(at_response+1); | |
73 } | |
74 | |
75 process_record() | |
76 { | |
77 int msgstat; | |
78 u_char pdubin[176]; | |
79 int cc, scalen; | |
80 char send_cmd[32]; | |
81 | |
82 if (!get_input_line()) | |
83 return(0); | |
84 if (!strcmp(input_line, "Received unread message:")) | |
85 msgstat = 0; | |
86 else if (!strcmp(input_line, "Received message:")) | |
87 msgstat = 1; | |
88 else if (!strcmp(input_line, "Stored unsent message:")) | |
89 msgstat = 2; | |
90 else if (!strcmp(input_line, "Sent message:")) | |
91 msgstat = 3; | |
92 else { | |
93 fprintf(stderr, | |
94 "input line %d: expected beginning of message record\n", | |
95 lineno); | |
96 exit(ERROR_USAGE); | |
97 } | |
98 for (;;) { | |
99 get_input_line_noeof(); | |
100 if (!isupper(input_line[0])) | |
101 break; | |
102 if (!index(input_line, ':')) | |
103 break; | |
104 } | |
105 cc = decode_hex_line(input_line, pdubin, sizeof pdubin); | |
106 if (cc < 1) { | |
107 inv: fprintf(stderr, "input line %d: not a valid PDU\n", lineno); | |
108 exit(ERROR_USAGE); | |
109 } | |
110 scalen = pdubin[0] + 1; | |
111 if (cc < scalen + 1) | |
112 goto inv; | |
113 /* good to go */ | |
114 sprintf(send_cmd, "AT+CMGW=%u,%d", cc - scalen, msgstat); | |
115 atinterf_exec_cmd_needok(send_cmd, input_line, cmgw_callback); | |
116 /* expect blank line after each PDU */ | |
117 get_input_line_noeof(); | |
118 if (input_line[0]) { | |
119 fprintf(stderr, | |
120 "input line %d: expected blank line after PDU\n", | |
121 lineno); | |
122 exit(ERROR_USAGE); | |
123 } | |
124 return(1); | |
125 } | |
126 | |
127 main(argc, argv) | |
128 char **argv; | |
129 { | |
130 process_cmdline(argc, argv); | |
131 atinterf_init(); | |
132 /* enable verbose error messages */ | |
133 atinterf_exec_cmd_needok("AT+CMEE=2", 0, 0); | |
134 /* set PDU mode */ | |
135 atinterf_exec_cmd_needok("AT+CMGF=0", 0, 0); | |
136 /* process stdin */ | |
137 while (process_record()) | |
138 ; | |
139 exit(0); | |
140 } |