![](/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:
- xinlei
- Date:
- 2015-04-13
- Revision:
- 92:0acd11870c6a
- Parent:
- 90:423177e8a401
- Child:
- 93:61d44636f020
File content as of revision 92:0acd11870c6a:
#include <stdio.h> #include "mbed.h" #include "rtos.h" #include "MDM.h" #include "GPS.h" #include "DeviceInfo.h" #include "DeviceMemory.h" #include "MbedAgent.h" #include "GPSTracker.h" #include "DeviceConfiguration.h" #include "logging.h" /** * SIM PIN. Null for no pin. */ #define SIM_PIN NULL /** * SIM GPRS login data. Leave commented out for automatic setting. */ //#define SIM_APN "" //#define SIM_USER "" //#define SIM_PASS "" MDMRtos<MDMSerial> *pMdm = NULL; unsigned short getMNCLen(const char *imsi) { if (strncmp(imsi, "310", 3) != 0) // Non American ISMI return 2; else return 3; } void enableDebug() { setLevel(A_DEBUG); if (pMdm) pMdm->setDebug(3); } void disableDebug() { setLevel(A_NONE); if (pMdm) pMdm->setDebug(-1); } int main() { MDMRtos<MDMSerial> mdm; pMdm = &mdm; InterruptIn joystickUp(A2); InterruptIn joystickDown(A3); LCDDisplay lcdDisplay; MDMParser::DevStatus devStatus; GPSI2C gps; lcdDisplay.setLines("Mbed Agent V2.1rc1", getHost()); if (!mdm.init(SIM_PIN, &devStatus)) { lcdDisplay.setLines("Modem Init Failure", "No SIM card found", "Or SIM has PIN"); mdm.disconnect(); mdm.powerOff(); return 1; } else if (!gps.init()) { lcdDisplay.setLines("GPS Init Failure"); mdm.disconnect(); mdm.powerOff(); return 2; } joystickUp.rise(&enableDebug); joystickDown.rise(&disableDebug); DeviceMemory deviceMemory(mdm); DigitalIn fireButton(D4); if (fireButton) { lcdDisplay.setLines("Factory Reset"); if (deviceMemory.resetPlatformCredentials()) { lcdDisplay.setLines("Reset Success"); } else { lcdDisplay.setLines("Reset Failure"); } mdm.disconnect(); mdm.powerOff(); Thread::wait(1000); return 0; } aInfo("Main Thread: %p\r\n", Thread::gettid()); lcdDisplay.setLines("Register Network...", "IMEI", devStatus.imei); if (!mdm.registerNet()) { lcdDisplay.setLines("No Network Coverage"); mdm.disconnect(); mdm.powerOff(); return 3; } lcdDisplay.setLines("Join Network"); #ifdef SIM_APN if (mdm.join(SIM_APN, SIM_USER, SIM_PASS) == NOIP) { #else if (mdm.join() == NOIP) { #endif char s[8] = "Unknown"; const char *p = devStatus.imsi; if (p) { snprintf(s, sizeof(s), "%.*s-%.*s", 3, p, getMNCLen(p), p+3); } lcdDisplay.setLines("Wrong APN Settting", "MCC-MNC:", s); mdm.disconnect(); mdm.powerOff(); return 4; } { DeviceInfo deviceInfo(mdm, devStatus); MbedAgent agent(gps, mdm, lcdDisplay, deviceInfo, deviceMemory); lcdDisplay.setLines("Agent Init"); if (!agent.init()) { mdm.disconnect(); mdm.powerOff(); return 5; } lcdDisplay.setLines("Agent Run"); int ret = 0; for (uint8_t tries = 3; tries; --tries) { ret = agent.run(); if (ret == 0) break; } switch (ret) { case -1: lcdDisplay.setLines("Bootstrap error"); break; case -2: lcdDisplay.setLines("Integrate failure"); break; case -3: lcdDisplay.setLines("Config sync failure"); break; default: agent.loop(); } mdm.disconnect(); mdm.powerOff(); return ret; } }