![](/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-02-16
- Revision:
- 72:c5709ae7b193
- Parent:
- 71:063c45e99578
- Child:
- 73:313975bfec96
File content as of revision 72:c5709ae7b193:
#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 "" int main() { setLevel(A_DEBUG); MDMParser::DevStatus devStatus; int res; uint8_t status = 0; MDMRtos<MDMSerial> mdm; GPSI2C gps; DeviceIO io(gps); //mdm.setDebug(4); io.lcdPrint("Device Init"); if (!mdm.init(SIM_PIN, &devStatus)) status = 1; else if (!gps.init()) status = 2; switch (status) { case 1: io.lcdPrint("Modem Init Failure", "Check SIM"); break; case 2: io.lcdPrint("GPS Init Failure"); break; } if (status != 0) goto error; io.lcdPrint("Register Network", "IMEI", devStatus.imei); if (!mdm.registerNet()) { io.lcdPrint("Network Reg Error"); goto error; } io.lcdPrint("Join Network"); #ifdef SIM_APN if (mdm.join(SIM_APN, SIM_USER, SIM_PASS) == NOIP) { #else if (mdm.join() == NOIP) { #endif io.lcdPrint("Network join failure"); goto error; } { uint8_t tries; DeviceInfo deviceInfo(mdm, devStatus); DeviceMemory deviceMemory(mdm); if (io.resetButtonPressed()) { io.lcdPrint("Factory Reset"); if (deviceMemory.resetPlatformCredentials()) { // io.deviceFeedback().beepSuccess(); io.lcdPrint("Reset Success"); } else { // io.deviceFeedback().beepFailure(); io.lcdPrint("Reset Failure"); } // Thread::wait(1000); return; } MbedAgent agent(io, mdm, deviceInfo, deviceMemory); io.lcdPrint("Agent Init"); if (!agent.init()) { io.lcdPrint("Agent Init Failure"); goto error; } tries = 3; do { // io.lcdPrint("AGENT RUN"); puts("R"); if (agent.run()) break; } while (--tries > 0); if (tries == 0) { io.lcdPrint("Agent Run Failure"); goto error; } } mdm.disconnect(); return 0; error: mdm.disconnect(); return 1; }