Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
main.cpp
- Committer:
- xinlei
- Date:
- 2015-03-03
- Revision:
- 77:f6717e4eccc4
- Parent:
- 76:b07effe83fb8
- Child:
- 80:757c3ff7b92b
File content as of revision 77:f6717e4eccc4:
#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() { MDMParser::DevStatus devStatus; int res; uint8_t status = 0; MDMRtos<MDMSerial> mdm; GPSI2C gps; DeviceIO io(gps); DigitalIn joystickUp(A2); DigitalIn joystickDown(A3); if (joystickUp) { setLevel(A_DEBUG); mdm.setDebug(3); printf("Enable debug mode.\r\n"); } else { setLevel(A_INFO); mdm.setDebug(1); } io.lcdPrint("Device Init"); if (!mdm.init(SIM_PIN, &devStatus)) { status = 1; io.lcdPrint("Modem Init Failure", "No SIM card found", "Or SIM has PIN code"); } else if (!gps.init()) { status = 2; io.lcdPrint("GPS Init Failure"); } if (status != 0) goto error; io.lcdPrint("Register Network", "IMEI", devStatus.imei); if (!mdm.registerNet()) { io.lcdPrint("No Network Coverage"); 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", "Wrong APN settting,", "username and password"); goto error; } { 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 0; } MbedAgent agent(io, mdm, deviceInfo, deviceMemory); io.lcdPrint("Agent Init"); if (!agent.init()) { io.lcdPrint("Agent Init Failure", "Debug via serial port"); goto error; } uint8_t tries = 3; do { io.lcdPrint("Agent Run"); if (agent.run()) break; } while (--tries > 0); if (tries == 0) { io.lcdPrint("Integration/Config Failure"); goto error; } } mdm.disconnect(); mdm.powerOff(); return 0; error: mdm.disconnect(); mdm.powerOff(); return 1; }