Prototyping the Adaptable Emergency System on an C027 board.

Dependencies:   C027_Support mbed

Fork of c027_prototyping by Philémon Favrod

Committer:
aroulin
Date:
Sun Oct 05 12:38:04 2014 +0000
Revision:
17:726bbc1b73ee
Parent:
14:d1f114749b3c
PIN in argument of sms_init;

Who changed what in which revision?

UserRevisionLine numberNew 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
aroulin 17:726bbc1b73ee 7 int init_sms_features(MDMSerial *_mdm, char* SIMPIN)
aroulin 4:f1708f6ec905 8 {
philemonf 10:b9ca12e9bb34 9 mdm = _mdm;
philemonf 5:6d0cdd715100 10
aroulin 4:f1708f6ec905 11 MDMParser::DevStatus devStatus = {};
aroulin 4:f1708f6ec905 12 MDMParser::NetStatus netStatus = {};
philemonf 6:58d48b90c9f7 13 bool mdmOk = mdm->init(SIMPIN, &devStatus);
philemonf 6:58d48b90c9f7 14 mdm->dumpDevStatus(&devStatus);
aroulin 4:f1708f6ec905 15
aroulin 4:f1708f6ec905 16 if (mdmOk) {
philemonf 6:58d48b90c9f7 17 mdmOk &= mdm->registerNet(&netStatus);
philemonf 6:58d48b90c9f7 18 mdm->dumpNetStatus(&netStatus);
aroulin 4:f1708f6ec905 19 }
aroulin 4:f1708f6ec905 20
philemonf 5:6d0cdd715100 21 return mdmOk;
philemonf 5:6d0cdd715100 22 }
philemonf 5:6d0cdd715100 23
philemonf 6:58d48b90c9f7 24 int send_sms(struct sms_data_t *sms)
philemonf 5:6d0cdd715100 25 {
philemonf 5:6d0cdd715100 26
philemonf 6:58d48b90c9f7 27 if (!sms || !(sms->phone_num) || !(sms->msg_buf) || !mdm) {
philemonf 5:6d0cdd715100 28 return 0;
aroulin 4:f1708f6ec905 29 }
philemonf 5:6d0cdd715100 30
philemonf 5:6d0cdd715100 31 return mdm->smsSend(sms->phone_num, sms->msg_buf);
philemonf 5:6d0cdd715100 32 }
philemonf 5:6d0cdd715100 33
philemonf 5:6d0cdd715100 34
philemonf 6:58d48b90c9f7 35 int read_sms(struct sms_data_t *sms)
philemonf 5:6d0cdd715100 36 {
philemonf 6:58d48b90c9f7 37 if (!sms || !(sms->phone_num) || !(sms->msg_buf) || !mdm) {
philemonf 5:6d0cdd715100 38 return 0;
philemonf 5:6d0cdd715100 39 }
philemonf 5:6d0cdd715100 40
philemonf 5:6d0cdd715100 41 int ix[1];
philemonf 6:58d48b90c9f7 42 int numReceivedSMS = mdm->smsList("REC UNREAD", ix, 1);
philemonf 5:6d0cdd715100 43
aroulin 14:d1f114749b3c 44 if (numReceivedSMS >= 1 && mdm->smsRead(ix[0], sms->phone_num, sms->msg_buf, sizeof(sms->msg_buf))) {
philemonf 6:58d48b90c9f7 45 mdm->smsDelete(ix[0]);
philemonf 5:6d0cdd715100 46 return 1;
philemonf 5:6d0cdd715100 47 }
philemonf 5:6d0cdd715100 48
philemonf 5:6d0cdd715100 49 return 0;
aroulin 4:f1708f6ec905 50 }