FreeCalypso > hg > freecalypso-tools
comparison uptools/atcmd/smsend_cmgw.c @ 362:89fe66cb60f6
fcup-smsend program put together, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 05 Mar 2018 01:47:18 +0000 |
parents | |
children | dc2fd8e6f42c |
comparison
equal
deleted
inserted
replaced
361:ae2556e256a4 | 362:89fe66cb60f6 |
---|---|
1 /* | |
2 * The handling of +CMGW responses and send-after-write for fcup-smsend | |
3 * family is implemented here. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include "../../rvinterf/include/exitcodes.h" | |
12 #include "resp_parse.h" | |
13 | |
14 extern char at_response[]; | |
15 extern int sms_write_mode; | |
16 | |
17 struct saw_rec { | |
18 unsigned msgid; | |
19 struct saw_rec *next; | |
20 }; | |
21 | |
22 struct saw_rec *sendafterwr_head, **sendafterwr_tail = &sendafterwr_head; | |
23 | |
24 add_sendafterwr_record(msgid) | |
25 unsigned msgid; | |
26 { | |
27 struct saw_rec *rec; | |
28 | |
29 rec = malloc(sizeof(struct saw_rec)); | |
30 if (!rec) { | |
31 perror("malloc for send-after-write record"); | |
32 exit(ERROR_UNIX); | |
33 } | |
34 rec->msgid = msgid; | |
35 rec->next = 0; | |
36 *sendafterwr_tail = rec; | |
37 sendafterwr_tail = &rec->next; | |
38 } | |
39 | |
40 cmgw_callback() | |
41 { | |
42 struct resp_field fields[1]; | |
43 int cc; | |
44 | |
45 /* skip empty lines */ | |
46 if (!at_response[1]) | |
47 return; | |
48 /* if not empty, it MUST be +CMGW */ | |
49 if (strncmp(at_response+1, "+CMGW: ", 7)) { | |
50 fprintf(stderr, "error: response from target is not +CMGW\n"); | |
51 exit(ERROR_TARGET); | |
52 } | |
53 if (sms_write_mode == 2) { | |
54 puts(at_response+1); | |
55 return; | |
56 } | |
57 if (parse_structured_response(at_response+8, fields, 1) != 1) { | |
58 malformed: fprintf(stderr, "error: malformed +CMGW response\n"); | |
59 exit(ERROR_TARGET); | |
60 } | |
61 if (fields[0].type != RESP_FIELD_NUMBER) | |
62 goto malformed; | |
63 add_sendafterwr_record(fields[0].num); | |
64 } | |
65 | |
66 sendafterwr_process() | |
67 { | |
68 struct saw_rec *rec; | |
69 char cmss_cmd[32]; | |
70 | |
71 if (!sendafterwr_head) { | |
72 fprintf(stderr, | |
73 "error: no +CMGW response received from target\n"); | |
74 exit(ERROR_TARGET); | |
75 } | |
76 if (sendafterwr_head->next) | |
77 atinterf_exec_cmd_needok("AT+CMMS=1", 0, 0); | |
78 for (rec = sendafterwr_head; rec; rec = rec->next) { | |
79 sprintf(cmss_cmd, "AT+CMSS=%u", rec->msgid); | |
80 atinterf_exec_cmd_needok(cmss_cmd, 0, 0); | |
81 } | |
82 if (sendafterwr_head->next) | |
83 atinterf_exec_cmd_needok("AT+CMMS=0", 0, 0); | |
84 } |