IGOR / Mbed 2 deprecated PONY_Ph0-uAXIS

Dependencies:   C027 C027_Support M2XStreamClient PowerControl jsonlite mbed-rtos mbed

Fork of PONY_Ph0-uAXIS by Sean McBeath

Files at this revision

API Documentation at this revision

Comitter:
sgmcb
Date:
Tue Dec 29 08:09:21 2015 +0000
Parent:
45:0d8cb417a9e2
Child:
47:d9180474fa1e
Commit message:
Slightly over-complicated our checking?

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Dec 29 07:42:39 2015 +0000
+++ b/main.cpp	Tue Dec 29 08:09:21 2015 +0000
@@ -17,7 +17,7 @@
 //----
 // DEBUG DEFINITIONS
 #define THROWAWAY
-//#define MDMDEBUG
+#define MDMDEBUG
 #define LOCDEBUG
 
 //------------------------------------------------------------------------------------
@@ -103,8 +103,9 @@
     MDMParser::DevStatus devStatus = {};
     MDMParser::NetStatus netStatus = {};
     bool mdmOk = mdm.init(SIMPIN, &devStatus);
+    
     #ifdef MDMDEBUG
-    //mdm.setDebug(4);
+        mdm.setDebug(4);
     #endif
     
     // ----------------
@@ -156,6 +157,11 @@
     // Location data filter variables
     int locAccLower = 50;   // Immediately accept locations with uncertainty lower than this
     int locAccUpper = 5000; // Don't accept locations with uncertainty greater than this
+    
+    // Filter counters
+    int fail1count = -1;
+    int fail2count = -1;
+    int fail3count = -1;
 
 
     // Cell location call variables
@@ -180,10 +186,13 @@
         mdm.cellLocRequest(sensorMask, cellLocReqTimeout, targetAccuracy);
 
     // Hold next functions until we give cellLocRequest time to execute.
-        while( (!mdm.cellLocGet(&thisLoc)) &&  (cellLocDelay.read() < cellLocReqTimeout)) {
+        while((cellLocDelay.read() < cellLocReqTimeout)  &&  (!mdm.cellLocGet(&thisLoc)) ) {
             // Nothin much
         };
         
+        // wait 5 to make sure that our URCs are ready?
+        delay(5000);
+        
         //printf("cellLocDelay=%f\r\n",cellLocDelay.read());
         
         // Stop and reset cellLocDelay timer
@@ -200,7 +209,8 @@
         */
         
         // 1. Does the location data exist?
-        if( mdm.cellLocGet(&thisLoc) ) {
+        if( (mdm.cellLocGet(&thisLoc)) ) {
+            fail1count = 0;
             #ifdef LOCDEBUG
                 printf("LOC uncertainty= %d, sensor= %d\r\n", thisLoc.uncertainty, thisLoc.sensorUsed );
                 printf("LOC = latitude: %0.5f, longitude: %0.5f, altitute: %d\r\n", thisLoc.latitude, thisLoc.longitude, thisLoc.altitude);
@@ -208,12 +218,14 @@
             
             // 2. Is this new position data, or extrapolated from an old reading?
             if(thisLoc.sensorUsed == 2) {
+                fail2count = 0;
                 #ifdef LOCDEBUG
                     printf("LOC has new information (non-extrapolation)\r\n");
                 #endif
                 
                 // 3. Is this data acceptably accurate (e.g. low enough reported uncertainty)?
                 if( (thisLoc.uncertainty < locAccUpper) && (thisLoc.uncertainty > 0) ) {
+                    fail3count = 0;
                     #ifdef LOCDEBUG
                         printf("LOC has suitable uncertainty (<%i).\r\n", locAccUpper);
                     #endif                    
@@ -234,6 +246,7 @@
                 }
                 // Fails 3:
                 else {
+                    ++fail3count;
                     #ifdef LOCDEBUG
                         printf("LOC has high uncertainty (<%i); will not report.\r\n", thisLoc.uncertainty);
                     #endif        
@@ -241,17 +254,26 @@
             }
             // Fails 2:
             else {
+                ++fail2count;
                 #ifdef LOCDEBUG
                     printf("LOC has is extrapolated information; disregard.\r\n");
-                #endif                
+                #endif
+                
             }            
         }
-        // Fails 1:
+        // Fails 1 but inside cellLocReq timeout length; repeat without delay:
+        else if ( cellLocDelay < cellLocReqTimeout ){
+            printf("Waiting on cellLoc timeout...\r\n");
+        }
+        // Fails 1 and timer is up:
         else {
+            ++fail1count;
             printf("CellLocRequest timeout; no location data available.\r\n");    
+            delay(30*1000);
+        
         }
         
-        delay(30*1000);
+        
         continue;
         // Skip this old crap