Prototyping the Adaptable Emergency System on an C027 board.
Dependencies: C027_Support mbed
Fork of c027_prototyping by
sms_lib.cpp@10:b9ca12e9bb34, 2014-09-30 (annotated)
- Committer:
- philemonf
- Date:
- Tue Sep 30 18:20:12 2014 +0000
- Revision:
- 10:b9ca12e9bb34
- Parent:
- 6:58d48b90c9f7
- Child:
- 14:d1f114749b3c
remove new from sms_lib.[hc]
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aroulin | 4:f1708f6ec905 | 1 | #include "sms_lib.h" |
aroulin | 4:f1708f6ec905 | 2 | |
aroulin | 4:f1708f6ec905 | 3 | DigitalOut myled(LED); |
aroulin | 4:f1708f6ec905 | 4 | |
philemonf | 5:6d0cdd715100 | 5 | static MDMSerial *mdm; |
philemonf | 10:b9ca12e9bb34 | 6 | |
philemonf | 10:b9ca12e9bb34 | 7 | int init_sms_features(MDMSerial *_mdm) |
aroulin | 4:f1708f6ec905 | 8 | { |
philemonf | 10:b9ca12e9bb34 | 9 | mdm = _mdm; |
philemonf | 5:6d0cdd715100 | 10 | |
aroulin | 4:f1708f6ec905 | 11 | static const char *SIMPIN = "5554"; |
aroulin | 4:f1708f6ec905 | 12 | |
aroulin | 4:f1708f6ec905 | 13 | MDMParser::DevStatus devStatus = {}; |
aroulin | 4:f1708f6ec905 | 14 | MDMParser::NetStatus netStatus = {}; |
philemonf | 6:58d48b90c9f7 | 15 | bool mdmOk = mdm->init(SIMPIN, &devStatus); |
philemonf | 6:58d48b90c9f7 | 16 | mdm->dumpDevStatus(&devStatus); |
aroulin | 4:f1708f6ec905 | 17 | |
aroulin | 4:f1708f6ec905 | 18 | if (mdmOk) { |
philemonf | 6:58d48b90c9f7 | 19 | mdmOk &= mdm->registerNet(&netStatus); |
philemonf | 6:58d48b90c9f7 | 20 | mdm->dumpNetStatus(&netStatus); |
aroulin | 4:f1708f6ec905 | 21 | } |
aroulin | 4:f1708f6ec905 | 22 | |
philemonf | 5:6d0cdd715100 | 23 | return mdmOk; |
philemonf | 5:6d0cdd715100 | 24 | } |
philemonf | 5:6d0cdd715100 | 25 | |
philemonf | 6:58d48b90c9f7 | 26 | int send_sms(struct sms_data_t *sms) |
philemonf | 5:6d0cdd715100 | 27 | { |
philemonf | 5:6d0cdd715100 | 28 | |
philemonf | 6:58d48b90c9f7 | 29 | if (!sms || !(sms->phone_num) || !(sms->msg_buf) || !mdm) { |
philemonf | 5:6d0cdd715100 | 30 | return 0; |
aroulin | 4:f1708f6ec905 | 31 | } |
philemonf | 5:6d0cdd715100 | 32 | |
philemonf | 5:6d0cdd715100 | 33 | return mdm->smsSend(sms->phone_num, sms->msg_buf); |
philemonf | 5:6d0cdd715100 | 34 | } |
philemonf | 5:6d0cdd715100 | 35 | |
philemonf | 5:6d0cdd715100 | 36 | |
philemonf | 6:58d48b90c9f7 | 37 | int read_sms(struct sms_data_t *sms) |
philemonf | 5:6d0cdd715100 | 38 | { |
philemonf | 6:58d48b90c9f7 | 39 | if (!sms || !(sms->phone_num) || !(sms->msg_buf) || !mdm) { |
philemonf | 5:6d0cdd715100 | 40 | return 0; |
philemonf | 5:6d0cdd715100 | 41 | } |
philemonf | 5:6d0cdd715100 | 42 | |
philemonf | 5:6d0cdd715100 | 43 | int ix[1]; |
philemonf | 6:58d48b90c9f7 | 44 | int numReceivedSMS = mdm->smsList("REC UNREAD", ix, 1); |
philemonf | 5:6d0cdd715100 | 45 | |
philemonf | 6:58d48b90c9f7 | 46 | if (numReceivedSMS > 1 && mdm->smsRead(ix[0], sms->phone_num, sms->msg_buf, sizeof(sms->msg_buf))) { |
philemonf | 6:58d48b90c9f7 | 47 | mdm->smsDelete(ix[0]); |
philemonf | 5:6d0cdd715100 | 48 | return 1; |
philemonf | 5:6d0cdd715100 | 49 | } |
philemonf | 5:6d0cdd715100 | 50 | |
philemonf | 5:6d0cdd715100 | 51 | return 0; |
aroulin | 4:f1708f6ec905 | 52 | } |