![](/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
- Committer:
- vwochnik
- Date:
- 2014-05-26
- Revision:
- 29:853741b9ea3b
- Parent:
- 28:2004400abeec
- Child:
- 30:daa499571db7
File content as of revision 29:853741b9ea3b:
#include "common.h" #include "apndb.h" #include "io.h" C027 c027; MDMSerial mdm; sigq_t sigQ = {}; char cCellId[8+1]; MDMParser::DevStatus devStatus = {}; MDMParser::NetStatus netStatus = {}; int main() { int ret; size_t c; puts("Started..."); io_init(); puts("IO initialized."); c027.mdmWakeup(); c027.mdmReset(); c027.mdmPower(true); Thread::wait(2000); puts("Initializing modem."); if (!mdm.init(NULL, &devStatus)) { puts("Modem initialization failed. Check your PIN number."); return 1; } puts("Searching for login..."); apndb_t *apn = apndb_get(devStatus.imsi); if (apn == NULL) { puts("No APN found. Stop."); return 1; } // print out basic device data printf("IMEI: %s\n", devStatus.imei); printf("IMSI: %s\n", devStatus.imsi); // wait until we are connected int i = 60; while (!mdm.checkNetStatus(&netStatus)) { if ((netStatus.reg == MDMParser::REG_DENIED) || (i-- == 0)) break; Thread::wait(2000); } if ((netStatus.reg == MDMParser::REG_DENIED) || (i == 0)) { puts("Network connection failed."); return 1; } printf("Carrier: %s\n", apn->carrier); puts("Joining Network."); if (mdm.join(apn->apn) == NOIP) { puts("Could not join network. Make sure chosen carrier is correct and no credentials are required."); return 1; } // get before starting program as they're permanent if ((!strlen(imei())) || (!strlen(iccid()))) { puts("Couldn't read IMEI or ICCID."); return 2; } // Shown on display signalQuality(); puts("Starting program..."); // restart program upon failure do { ret = program(); if (ret) puts("Restarting program..."); } while (ret); c027.mdmPower(false); return 0; } const char * imei() { return devStatus.imei; } const char * imsi() { return devStatus.imsi; } const char * cellId() { if (!mdm.checkNetStatus(&netStatus)) return NULL; if (snprintf(cCellId, sizeof(cCellId), "%X", netStatus.ci) < 1) return NULL; return cCellId; } const char * iccid() { return devStatus.ccid; } sigq_t * signalQuality() { sigQ.rssi = 0; sigQ.ber = 0; if (!mdm.checkNetStatus(&netStatus)) return NULL; sigQ.rssi = netStatus.rssi; sigQ.ber = netStatus.ber; lcd_signal(sigQ.rssi, sigQ.ber); return &sigQ; }