![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
main.cpp@28:2004400abeec, 2014-05-25 (annotated)
- Committer:
- vwochnik
- Date:
- Sun May 25 17:46:19 2014 +0000
- Revision:
- 28:2004400abeec
- Parent:
- 27:bfd402593acc
- Child:
- 29:853741b9ea3b
update info functions to new driver. use apn db.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vwochnik | 6:642e7c233e83 | 1 | #include "common.h" |
vwochnik | 23:0a48eebaaba8 | 2 | #include "apndb.h" |
vwochnik | 15:0ccf0f530a05 | 3 | #include "io.h" |
vwochnik | 0:ed4d6fd405ea | 4 | |
vwochnik | 27:bfd402593acc | 5 | #define SIMPIN NULL |
vwochnik | 27:bfd402593acc | 6 | |
vwochnik | 0:ed4d6fd405ea | 7 | C027 c027; |
vwochnik | 27:bfd402593acc | 8 | MDMSerial mdm; |
vwochnik | 28:2004400abeec | 9 | sigq_t sigQ = {}; |
vwochnik | 28:2004400abeec | 10 | char cCellId[8+1]; |
vwochnik | 28:2004400abeec | 11 | MDMParser::DevStatus devStatus = {}; |
vwochnik | 28:2004400abeec | 12 | MDMParser::NetStatus netStatus = {}; |
vwochnik | 0:ed4d6fd405ea | 13 | |
vwochnik | 0:ed4d6fd405ea | 14 | int main() |
vwochnik | 0:ed4d6fd405ea | 15 | { |
vwochnik | 24:8f9b678a7932 | 16 | int ret; size_t c; |
vwochnik | 7:f77afd49c35d | 17 | |
vwochnik | 7:f77afd49c35d | 18 | puts("Started..."); |
vwochnik | 15:0ccf0f530a05 | 19 | io_init(); |
vwochnik | 15:0ccf0f530a05 | 20 | puts("IO initialized."); |
vwochnik | 15:0ccf0f530a05 | 21 | |
vwochnik | 7:f77afd49c35d | 22 | c027.mdmWakeup(); |
vwochnik | 7:f77afd49c35d | 23 | c027.mdmReset(); |
vwochnik | 7:f77afd49c35d | 24 | c027.mdmPower(true); |
vwochnik | 28:2004400abeec | 25 | Thread::wait(2000); |
vwochnik | 27:bfd402593acc | 26 | |
vwochnik | 28:2004400abeec | 27 | puts("Initializing modem."); |
vwochnik | 28:2004400abeec | 28 | if (!mdm.init(SIMPIN, &devStatus)) { |
vwochnik | 28:2004400abeec | 29 | puts("Modem initialization failed. Check your PIN number."); |
vwochnik | 28:2004400abeec | 30 | return 1; |
vwochnik | 28:2004400abeec | 31 | } |
vwochnik | 28:2004400abeec | 32 | |
vwochnik | 28:2004400abeec | 33 | puts("Searching for login..."); |
vwochnik | 28:2004400abeec | 34 | apndb_t *apn = apndb_get(devStatus.imsi); |
vwochnik | 28:2004400abeec | 35 | if (apn == NULL) { |
vwochnik | 28:2004400abeec | 36 | puts("No APN found. Stop."); |
vwochnik | 28:2004400abeec | 37 | return 1; |
vwochnik | 4:363b4cc49445 | 38 | } |
vwochnik | 24:8f9b678a7932 | 39 | |
vwochnik | 28:2004400abeec | 40 | // wait until we are connected |
vwochnik | 28:2004400abeec | 41 | int i = 60; |
vwochnik | 28:2004400abeec | 42 | while (!mdm.checkNetStatus(&netStatus)) { |
vwochnik | 28:2004400abeec | 43 | if ((netStatus.reg == MDMParser::REG_DENIED) || (i-- == 0)) |
vwochnik | 28:2004400abeec | 44 | break; |
vwochnik | 28:2004400abeec | 45 | Thread::wait(2000); |
vwochnik | 28:2004400abeec | 46 | } |
vwochnik | 28:2004400abeec | 47 | |
vwochnik | 28:2004400abeec | 48 | if ((netStatus.reg == MDMParser::REG_DENIED) || (i == 0)) { |
vwochnik | 28:2004400abeec | 49 | puts("Network connection failed."); |
vwochnik | 28:2004400abeec | 50 | return 1; |
vwochnik | 28:2004400abeec | 51 | } |
vwochnik | 28:2004400abeec | 52 | |
vwochnik | 28:2004400abeec | 53 | puts("Joining Network."); |
vwochnik | 28:2004400abeec | 54 | if (mdm.join(apn->apn, apn->user, apn->pass) == NOIP) { |
vwochnik | 28:2004400abeec | 55 | puts("Could not join network. Check APN and credentials."); |
vwochnik | 28:2004400abeec | 56 | return 1; |
vwochnik | 28:2004400abeec | 57 | } |
vwochnik | 24:8f9b678a7932 | 58 | |
vwochnik | 8:940c782eec5e | 59 | // get before starting program as they're permanent |
vwochnik | 13:4045b6ac448d | 60 | if ((!strlen(imei())) || (!strlen(iccid()))) { |
vwochnik | 12:beb64aa0da86 | 61 | puts("Couldn't read IMEI or ICCID."); |
vwochnik | 12:beb64aa0da86 | 62 | return 2; |
vwochnik | 12:beb64aa0da86 | 63 | } |
vwochnik | 23:0a48eebaaba8 | 64 | |
vwochnik | 23:0a48eebaaba8 | 65 | // Shown on display |
vwochnik | 23:0a48eebaaba8 | 66 | signalQuality(); |
vwochnik | 4:363b4cc49445 | 67 | |
vwochnik | 7:f77afd49c35d | 68 | puts("Starting program..."); |
vwochnik | 8:940c782eec5e | 69 | |
vwochnik | 8:940c782eec5e | 70 | // restart program upon failure |
vwochnik | 8:940c782eec5e | 71 | do { |
vwochnik | 8:940c782eec5e | 72 | ret = program(); |
vwochnik | 12:beb64aa0da86 | 73 | if (ret) |
vwochnik | 12:beb64aa0da86 | 74 | puts("Restarting program..."); |
vwochnik | 8:940c782eec5e | 75 | } while (ret); |
vwochnik | 4:363b4cc49445 | 76 | |
vwochnik | 6:642e7c233e83 | 77 | c027.mdmPower(false); |
vwochnik | 6:642e7c233e83 | 78 | |
vwochnik | 8:940c782eec5e | 79 | return 0; |
vwochnik | 4:363b4cc49445 | 80 | } |
vwochnik | 4:363b4cc49445 | 81 | |
vwochnik | 6:642e7c233e83 | 82 | const char * imei() |
vwochnik | 4:363b4cc49445 | 83 | { |
vwochnik | 28:2004400abeec | 84 | return devStatus.imei; |
vwochnik | 0:ed4d6fd405ea | 85 | } |
vwochnik | 4:363b4cc49445 | 86 | |
vwochnik | 23:0a48eebaaba8 | 87 | const char * imsi() |
vwochnik | 23:0a48eebaaba8 | 88 | { |
vwochnik | 28:2004400abeec | 89 | return devStatus.imsi; |
vwochnik | 23:0a48eebaaba8 | 90 | } |
vwochnik | 23:0a48eebaaba8 | 91 | |
vwochnik | 6:642e7c233e83 | 92 | const char * cellId() |
vwochnik | 4:363b4cc49445 | 93 | { |
vwochnik | 28:2004400abeec | 94 | if (!mdm.checkNetStatus(&netStatus)) |
vwochnik | 28:2004400abeec | 95 | return NULL; |
vwochnik | 28:2004400abeec | 96 | |
vwochnik | 28:2004400abeec | 97 | if (snprintf(cCellId, sizeof(cCellId), "%X", netStatus.ci) < 1) |
vwochnik | 28:2004400abeec | 98 | return NULL; |
vwochnik | 28:2004400abeec | 99 | |
vwochnik | 6:642e7c233e83 | 100 | return cCellId; |
vwochnik | 4:363b4cc49445 | 101 | } |
vwochnik | 4:363b4cc49445 | 102 | |
vwochnik | 7:f77afd49c35d | 103 | const char * iccid() |
vwochnik | 7:f77afd49c35d | 104 | { |
vwochnik | 28:2004400abeec | 105 | return devStatus.ccid; |
vwochnik | 7:f77afd49c35d | 106 | } |
vwochnik | 7:f77afd49c35d | 107 | |
vwochnik | 6:642e7c233e83 | 108 | sigq_t * signalQuality() |
vwochnik | 4:363b4cc49445 | 109 | { |
vwochnik | 6:642e7c233e83 | 110 | sigQ.rssi = 0; sigQ.ber = 0; |
vwochnik | 28:2004400abeec | 111 | if (!mdm.checkNetStatus(&netStatus)) |
vwochnik | 28:2004400abeec | 112 | return NULL; |
vwochnik | 28:2004400abeec | 113 | |
vwochnik | 28:2004400abeec | 114 | sigQ.rssi = netStatus.rssi; |
vwochnik | 28:2004400abeec | 115 | sigQ.ber = netStatus.ber; |
vwochnik | 20:ef9cc1b42e9d | 116 | |
vwochnik | 28:2004400abeec | 117 | lcd_signal(sigQ.rssi, sigQ.ber); |
vwochnik | 6:642e7c233e83 | 118 | return &sigQ; |
vwochnik | 4:363b4cc49445 | 119 | } |