whatever
Dependencies: C027 C027_Support M2XStreamClient PowerControl jsonlite mbed-rtos mbed
Fork of PONY_Ph0-uAXIS by
Diff: main.cpp
- Revision:
- 48:3512b3c7a5ae
- Parent:
- 47:d9180474fa1e
- Child:
- 49:a8c40c816199
--- a/main.cpp Tue Dec 29 08:48:44 2015 +0000 +++ b/main.cpp Tue Dec 29 09:00:09 2015 +0000 @@ -16,7 +16,7 @@ //---- // DEBUG DEFINITIONS -#define THROWAWAY +//#define THROWAWAY //#define MDMDEBUG #define LOCDEBUG @@ -38,9 +38,9 @@ #endif #ifndef THROWAWAY -// v1.2 codes -#define M2XAPIKEY "bbc483492238dc76f7d12f0cd6e13a4b" -#define DEVID "3764db38b6c9ec4045a38e0125b14b4c" +// v1.4 codes +#define M2XAPIKEY "537d09e921aa6589523e10aecde17a44" +#define DEVID "59a85c486aaf8dd427945320f4f779eb" #endif @@ -70,8 +70,8 @@ char statusBuf[145] = ""; // Location reading -unsigned int kLocLoopDelayMin = 30 * 1000; // The minimum loop waiting time for location reads -unsigned int kLocLoopDelay = kLocLoopDelayMin; // The default loop waiting time for location reads +unsigned int kLocLoopDelayDef = 30 * 1000; // The default loop waiting time for location reads +unsigned int kLocLoopDelay = kLocLoopDelayDef; unsigned int kReadingDelay = 3 * 60 * 1000; // How many seconds to wait between reads @@ -127,24 +127,12 @@ int locConf = mdm.cellLocConfigSensor(1); - - - - - - - - - - // Cell location data MDMSerial::CellLocData ponyLoc, thisLoc; - - - - // Loop driving variables + // Location loop driving variables int loopIter = 0; + bool sendStatus = false; bool locLock; // Loop timing variables @@ -182,6 +170,7 @@ // Set some important variables M2X_response = 0; + sendStatus = 0; locLock = false; loopIter++; @@ -254,7 +243,7 @@ // PASSSES ALL 3 TESTS => REPORT TO M2X // Report position - printf("\r\n\033[34mTRANSMIT LOCATION DATA:\r\nla=%0.5f, lo=%0.5f, alt=%d\033[39m\r\n", thisLoc.latitude, thisLoc.longitude, thisLoc.altitude); + printf("\r\n\033[34mTRANSMIT LOCATION DATA:\033[39m\r\nla=%0.5f, lo=%0.5f, alt=%d\r\n", thisLoc.latitude, thisLoc.longitude, thisLoc.altitude); M2X_response = m2xClient.updateLocation(DEVID, "pony-spot", (double) thisLoc.latitude, (double) thisLoc.longitude, (double) thisLoc.altitude); if(M2X_response == 202) printf("Location POST successful\r\n"); @@ -268,7 +257,7 @@ thisTime = time(NULL); M2X_response = m2xClient.updateStreamValue(DEVID, "systime", ctime(&thisTime) ); if(M2X_response == 202) - printf("Systime (%s) POST successful\r\n", ctime(&thisTime) ); + printf("Systime POST successful - %s \r", ctime(&thisTime) ); } @@ -307,29 +296,55 @@ // TODO: Add conditionals to handle successful location and unsuccessful communication with M2X + // ACTIONS BASED ON LOCATION READ SUCCESS/FAILURE + // Successful read if( (!fail3count) ) { - kLocLoopDelay = (60 * 1000); // Set ### minute wait before next read + kLocLoopDelay = 5 * (60 * 1000); // Set # minute wait before next read printf("Successful LOC read; "); } - // Some other behavior - else if (false) { - + // Too many invalid location reads + else if (fail1count > 10) { + sprintf(statusBuf, "Fail1count exceeds 10.\r\n"); + printf(statusBuf); + fail1count = 0; + sendStatus = true; } + + else if (fail2count > 10) { + sprintf(statusBuf, "Fail2count exceeds 10.\r\n"); + printf(statusBuf); + fail2count = 0; + sendStatus = true; + } + + else if (fail3count > 10) { + sprintf(statusBuf, "Fail3Count exceeds 10.\r\n"); + printf(statusBuf); + fail3count = 0; + sendStatus = true; + } + else { - kLocLoopDelay = kLocLoopDelayMin; + kLocLoopDelay = kLocLoopDelayDef; printf("Failed LOC loop; "); } + // Transmit a status response? + if(sendStatus) { + M2X_response = m2xClient.updateStreamValue(DEVID, "status", statusBuf); + if(M2X_response == 202) + printf("Status POST successful\r\n"); + } // Set loop delay (i.e. period) printf("loop waiting for %i seconds...\r\n---\n\r\n", (kLocLoopDelay / 1000) ); - delay(kLocLoopDelay); - - + flipper.attach(&flip, 0.5); // LED toggle! // the address of the function to be attached (flip) and the interval (2 seconds) + delay(kLocLoopDelay); + led1 = 0; // Turn that LED off! - + continue; // Skip this old crap @@ -408,11 +423,7 @@ continue; } else if (loopIter > readLoopMax) { - sprintf(statusBuf, "CellLoc location not found after %i loops.\r\n", loopIter); - printf(statusBuf); - M2X_response = m2xClient.updateStreamValue(DEVID, "status", statusBuf); - if(M2X_response == 202) - printf("Status POST successful\r\n"); + ponyLoc.uncertainty = locAccUpper + 1; printf("Begin %i second delay\r\n",kReadingDelay/1000); loopIter = 0; delay(kReadingDelay); @@ -422,7 +433,7 @@ else { printf("Bad data delay = submitPeriod...\r\n"); delay(submitPeriod * 1000); // Delay between CellLoc requests when not getting good data - flipper.attach(&flip, 0.5); // the address of the function to be attached (flip) and the interval (2 seconds) + } led1 = 0; }