Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
main.cpp@61:15719dbe8820, 2014-10-24 (annotated)
- Committer:
- vwochnik
- Date:
- Fri Oct 24 15:21:21 2014 +0000
- Revision:
- 61:15719dbe8820
- Parent:
- 58:4cc0ae5a7058
- Child:
- 67:c360a2b2c948
operation support
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Cumulocity | 41:804f6a0bda26 | 1 | #include "mbed.h" |
Cumulocity | 41:804f6a0bda26 | 2 | #include "rtos.h" |
Cumulocity | 41:804f6a0bda26 | 3 | #include "MDM.h" |
Cumulocity | 47:89ae46d5c466 | 4 | #include "GPS.h" |
Cumulocity | 41:804f6a0bda26 | 5 | #include "DeviceInfo.h" |
Cumulocity | 41:804f6a0bda26 | 6 | #include "MbedAgent.h" |
Cumulocity | 47:89ae46d5c466 | 7 | #include "GPSTracker.h" |
vwochnik | 0:ed4d6fd405ea | 8 | |
vwochnik | 52:8f1370084268 | 9 | /** |
vwochnik | 52:8f1370084268 | 10 | * SIM PIN. Null for no pin. |
vwochnik | 52:8f1370084268 | 11 | */ |
vwochnik | 52:8f1370084268 | 12 | #define SIM_PIN NULL |
vwochnik | 52:8f1370084268 | 13 | |
vwochnik | 52:8f1370084268 | 14 | /** |
vwochnik | 52:8f1370084268 | 15 | * SIM GPRS login data. Leave commented out for automatic setting. |
vwochnik | 52:8f1370084268 | 16 | */ |
vwochnik | 52:8f1370084268 | 17 | //#define SIM_APN "" |
vwochnik | 52:8f1370084268 | 18 | //#define SIM_USER "" |
vwochnik | 52:8f1370084268 | 19 | //#define SIM_PASS "" |
vwochnik | 52:8f1370084268 | 20 | |
vwochnik | 0:ed4d6fd405ea | 21 | int main() |
vwochnik | 0:ed4d6fd405ea | 22 | { |
Cumulocity | 41:804f6a0bda26 | 23 | MDMParser::DevStatus devStatus; |
Cumulocity | 46:f6976fd64387 | 24 | int res; |
vwochnik | 52:8f1370084268 | 25 | uint8_t status = 0; |
Cumulocity | 42:104746744af8 | 26 | |
vwochnik | 55:a0f7295ed6b6 | 27 | MDMRtos<MDMSerial> mdm; |
Cumulocity | 47:89ae46d5c466 | 28 | GPSI2C gps; |
vwochnik | 58:4cc0ae5a7058 | 29 | |
vwochnik | 61:15719dbe8820 | 30 | //mdm.setDebug(4); |
vwochnik | 27:bfd402593acc | 31 | |
vwochnik | 52:8f1370084268 | 32 | if (!mdm.init(SIM_PIN, &devStatus)) |
vwochnik | 52:8f1370084268 | 33 | status = 1; |
vwochnik | 52:8f1370084268 | 34 | else if (!gps.init()) |
vwochnik | 52:8f1370084268 | 35 | status = 2; |
Cumulocity | 47:89ae46d5c466 | 36 | |
Cumulocity | 47:89ae46d5c466 | 37 | DeviceIO io(gps); |
vwochnik | 52:8f1370084268 | 38 | |
vwochnik | 52:8f1370084268 | 39 | switch (status) { |
vwochnik | 52:8f1370084268 | 40 | case 1: |
vwochnik | 55:a0f7295ed6b6 | 41 | io.lcdPrint("MODEM INIT FAILURE", "CHECK SIM"); |
vwochnik | 52:8f1370084268 | 42 | break; |
vwochnik | 52:8f1370084268 | 43 | case 2: |
vwochnik | 52:8f1370084268 | 44 | io.lcdPrint("GPS INIT FAILURE"); |
vwochnik | 52:8f1370084268 | 45 | break; |
vwochnik | 52:8f1370084268 | 46 | } |
vwochnik | 52:8f1370084268 | 47 | |
vwochnik | 52:8f1370084268 | 48 | if (status != 0) |
vwochnik | 52:8f1370084268 | 49 | goto error; |
vwochnik | 52:8f1370084268 | 50 | |
Cumulocity | 47:89ae46d5c466 | 51 | io.lcdPrint("DEVICE INIT"); |
Cumulocity | 46:f6976fd64387 | 52 | |
Cumulocity | 48:d5e21301543e | 53 | /*if (io.resetButtonPressed()) { |
Cumulocity | 47:89ae46d5c466 | 54 | puts("Resetting program."); |
Cumulocity | 46:f6976fd64387 | 55 | res = mdm.delFile("001_CREDENTIALS"); |
Cumulocity | 46:f6976fd64387 | 56 | if (res < 0) { |
Cumulocity | 46:f6976fd64387 | 57 | puts("Credential reset failed."); |
Cumulocity | 46:f6976fd64387 | 58 | io.lcdPrint("CREDENTIAL RESET", "FAILURE", "PLEASE RESTART DEVICE"); |
Cumulocity | 46:f6976fd64387 | 59 | } else { |
Cumulocity | 46:f6976fd64387 | 60 | puts("Credential reset successful."); |
Cumulocity | 46:f6976fd64387 | 61 | io.lcdPrint("CREDENTIAL RESET", "SUCCESS", "PLEASE RESTART DEVICE"); |
Cumulocity | 46:f6976fd64387 | 62 | } |
Cumulocity | 46:f6976fd64387 | 63 | return 0; |
Cumulocity | 48:d5e21301543e | 64 | }*/ |
vwochnik | 28:2004400abeec | 65 | |
vwochnik | 55:a0f7295ed6b6 | 66 | io.lcdPrint("REGISTER NETWORK", "IMEI", devStatus.imei); |
Cumulocity | 42:104746744af8 | 67 | |
Cumulocity | 41:804f6a0bda26 | 68 | if (!mdm.registerNet()) { |
Cumulocity | 42:104746744af8 | 69 | io.lcdPrint("NETWORK REG ERROR"); |
vwochnik | 52:8f1370084268 | 70 | goto error; |
vwochnik | 28:2004400abeec | 71 | } |
vwochnik | 28:2004400abeec | 72 | |
vwochnik | 55:a0f7295ed6b6 | 73 | io.lcdPrint("JOIN NETWORK"); |
vwochnik | 52:8f1370084268 | 74 | #ifdef SIM_APN |
vwochnik | 52:8f1370084268 | 75 | if (mdm.join(SIM_APN, SIM_USER, SIM_PASS) == NOIP) { |
vwochnik | 55:a0f7295ed6b6 | 76 | #else |
vwochnik | 55:a0f7295ed6b6 | 77 | if (mdm.join() == NOIP) { |
vwochnik | 55:a0f7295ed6b6 | 78 | #endif |
vwochnik | 52:8f1370084268 | 79 | io.lcdPrint("NETWORK JOIN FAILURE"); |
vwochnik | 52:8f1370084268 | 80 | goto error; |
vwochnik | 52:8f1370084268 | 81 | } |
vwochnik | 8:940c782eec5e | 82 | |
vwochnik | 52:8f1370084268 | 83 | { |
vwochnik | 52:8f1370084268 | 84 | uint8_t tries; |
vwochnik | 52:8f1370084268 | 85 | DeviceInfo deviceInfo(mdm, devStatus); |
vwochnik | 52:8f1370084268 | 86 | MbedAgent agent(io, mdm, deviceInfo); |
vwochnik | 52:8f1370084268 | 87 | |
vwochnik | 52:8f1370084268 | 88 | io.lcdPrint("AGENT INIT"); |
vwochnik | 52:8f1370084268 | 89 | if (!agent.init()) { |
vwochnik | 52:8f1370084268 | 90 | io.lcdPrint("AGENT INIT FAILURE"); |
vwochnik | 52:8f1370084268 | 91 | goto error; |
vwochnik | 52:8f1370084268 | 92 | } |
vwochnik | 52:8f1370084268 | 93 | |
vwochnik | 52:8f1370084268 | 94 | tries = 3; |
vwochnik | 52:8f1370084268 | 95 | do { |
vwochnik | 52:8f1370084268 | 96 | io.lcdPrint("AGENT RUN"); |
vwochnik | 52:8f1370084268 | 97 | if (agent.run()) |
vwochnik | 52:8f1370084268 | 98 | break; |
vwochnik | 52:8f1370084268 | 99 | } while (--tries > 0); |
Cumulocity | 41:804f6a0bda26 | 100 | |
vwochnik | 52:8f1370084268 | 101 | if (tries == 0) { |
vwochnik | 52:8f1370084268 | 102 | io.lcdPrint("AGENT RUN FAILURE"); |
vwochnik | 52:8f1370084268 | 103 | goto error; |
Cumulocity | 41:804f6a0bda26 | 104 | } |
vwochnik | 52:8f1370084268 | 105 | } |
vwochnik | 32:56804dd00193 | 106 | |
vwochnik | 30:daa499571db7 | 107 | mdm.disconnect(); |
vwochnik | 8:940c782eec5e | 108 | return 0; |
vwochnik | 52:8f1370084268 | 109 | |
vwochnik | 52:8f1370084268 | 110 | error: |
vwochnik | 52:8f1370084268 | 111 | mdm.disconnect(); |
vwochnik | 52:8f1370084268 | 112 | return 1; |
vwochnik | 4:363b4cc49445 | 113 | } |