init

Dependencies:   aconno_I2C Lis2dh12 WatchdogTimer

Files at this revision

API Documentation at this revision

Comitter:
pathfindr
Date:
Thu Jan 03 10:09:38 2019 +0000
Parent:
32:dff4858bdf37
Child:
34:4493c9f6d707
Commit message:
12

Changed in this revision

README.md Show annotated file Show diff for this revision Revisions of this file
common.cpp Show annotated file Show diff for this revision Revisions of this file
common.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
modem.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/README.md	Tue Jan 01 20:46:39 2019 +0000
+++ b/README.md	Thu Jan 03 10:09:38 2019 +0000
@@ -16,17 +16,17 @@
 14) does enabling handshaking and auto sleep on the modem save power
 15) swap motion_g so that it is actually a mg value
 16) test motion start stop times exactly
-17) add extra 1cm to gsm antenna
+17) add extra 0.5cm to gsm antenna?
 18) errors while sending causes need to double send ussd command, adds on 5-10 seconds
 19) check voltage calibation
 21) when setup fails it does not go into dormant mode, could be ram retention
 22) force CL locations to 6 decimal - needs to be done on web api
-23) 3g cell tower data is not being recognised and converted to location by server
+
 
 
 RESOLVED - TO BE TESTED AGAIN...
 20) location accuracy 0 does not seem to work
-
+23) 3g cell tower data is not being recognised and converted to location by server (fix was to convert hex to decimal on server)
 
 TEST RESULTS:
 CE3165 - ID 109
--- a/common.cpp	Tue Jan 01 20:46:39 2019 +0000
+++ b/common.cpp	Thu Jan 03 10:09:38 2019 +0000
@@ -6,14 +6,17 @@
 DigitalOut led1(PN_LED);
 
 void LED1on(long milliseconds = 0) {
+    GLOBAL_LEDSequenceinProgress = true;
     led1 = 0;
     if (milliseconds > 0) {
         //ThisThread::sleep_for(milliseconds);
         Thread::wait(milliseconds);
         led1 = 1;
     }
+    GLOBAL_LEDSequenceinProgress = false;
 }
 void LED1blink(int count = 2, long milliseconds = 100) {
+    GLOBAL_LEDSequenceinProgress = true;
     for (int i = 0; i < (count*2); i++) {
         led1 = !led1;
         if (milliseconds > 0) {
@@ -25,7 +28,23 @@
         }
     }
     led1 = 1;
+    GLOBAL_LEDSequenceinProgress = false;
+}
+void LED1errorCode(int pattern, int count) {
+    GLOBAL_LEDSequenceinProgress = true;
+    for (int i = 0; i < count; i++) {
+        for (int p = 0; p < pattern; p++) {
+            led1 = 0;
+            Thread::wait(200);
+            led1 = 1;
+            Thread::wait(300);
+        }
+        Thread::wait(1000);
+    }
+    led1 = 1;
+    GLOBAL_errorCodeInProgress = false;
 }
 void LED1off() {
     led1 = 1;
+    GLOBAL_LEDSequenceinProgress = false;
 }
\ No newline at end of file
--- a/common.h	Tue Jan 01 20:46:39 2019 +0000
+++ b/common.h	Thu Jan 03 10:09:38 2019 +0000
@@ -6,6 +6,7 @@
 extern DigitalOut led1;
 extern void LED1on(long milliseconds);
 extern void LED1blink(int count, long milliseconds);
+extern void LED1errorCode(int pattern, int count);
 extern void LED1off(void);
 
 #endif
\ No newline at end of file
--- a/main.cpp	Tue Jan 01 20:46:39 2019 +0000
+++ b/main.cpp	Thu Jan 03 10:09:38 2019 +0000
@@ -19,7 +19,6 @@
 #define DEFAULT_CONNECTION_TIMEOUT          180
 #define DEFAULT_BEACON_INTERVAL_SECONDS     10
 
-
 //------------------------------------------------------------------------------
 //FUNCTION PROTOTYPES
 //------------------------------------------------------------------------------ 
@@ -42,6 +41,7 @@
 bool GLOBAL_needToConfigureLis3dh = false;
 bool GLOBAL_registeredOnNetwork = false;
 bool GLOBAL_modemOn = false;
+bool GLOBAL_LEDSequenceinProgress = false;
 time_t GLOBAL_RTCunixtime = 0;
 time_t GLOBAL_wakeTime = 0;
 char GLOBAL_exceptionString[10];
@@ -269,7 +269,7 @@
         }
     }
     //SETUP STATE VISUALISE
-    if (RET_state == STATE_SETUP) {
+    if (!GLOBAL_LEDSequenceinProgress && RET_state == STATE_SETUP) {
         led1 = !led1;
     }
 }
@@ -516,6 +516,7 @@
     float voltage = getBatteryV();
     float temperature = getTemperature();
     bool selftestresult = selfTest();
+    if (selftestresult == false) { LED1errorCode(4,20); } //ERROR 4
     Modem modem(PN_UART_TX, PN_UART_RX, PN_UART_CTS, PN_UART_RTS, PN_GSM_PWR_KEY, PN_VREG_EN, PN_GSM_WAKE_DISABLE);
     if (modem.on()) {
         //RET_imei = modem.getIMEI();
@@ -524,7 +525,7 @@
         char locString[70];
         memcpy(locString, modem.getLocation(1, RET_setting_location_timeout), 70);
         if (modem.registerOnNetwork(DEFAULT_CONNECTION_ATTEMPTS,(RET_setting_connection_timeout*1000))) {
-            int timetaken = (RET_RTCunixtime - GLOBAL_wakeTime);
+            int timetaken = (RET_RTCunixtime - GLOBAL_wakeTime) + 10; //add 10 for ussd response time.
             char bytestosend[160];
             snprintf(bytestosend,sizeof(bytestosend),"(%s,a:setup,f:%d,v:%.2f,t:%.1f,e:%d,z:SETUP-%s,c:1,s:1%s)\0",GLOBAL_defaultApi,FW_VERSION,voltage,temperature,timetaken,GLOBAL_exceptionString,locString);
             char result[180];
@@ -534,17 +535,19 @@
                 if (!saveSettings(result)) { 
                     //something went critically wrong getting settings 
                     pass = false;
+                    LED1errorCode(5,20); //ERROR 5
                 }              
             }
         } else {
             //FAILUREMODE modem failed to register on network
             DEBUG("NET REGISTER FAIL");
+            LED1errorCode(3,20); //ERROR 3
             pass = false;
         }
     } else {
         //FAILUREMODE Modem failed to turn on  
         DEBUG("MODEM ON FAIL");
-        LED1blink(200,50);
+        LED1errorCode(2,20); //ERROR 2
         pass = false;
     }
     
@@ -568,7 +571,7 @@
         char locString[70];
         memcpy(locString, modem.getLocation(location_accuracy, RET_setting_location_timeout), 70);
         if (modem.registerOnNetwork(DEFAULT_CONNECTION_ATTEMPTS,(RET_setting_connection_timeout*1000))) {
-            int timetaken = (RET_RTCunixtime - GLOBAL_wakeTime);
+            int timetaken = (RET_RTCunixtime - GLOBAL_wakeTime) + 10; //add 10 for ussd response time.;
             char bytestosend[160];
             snprintf(bytestosend,sizeof(bytestosend),"(%s,a:loc,f:%d,t:%.1f,v:%.2f,z:TEST-%s,e:%d,c:1,s:1%s)\0",GLOBAL_defaultApi,FW_VERSION,temperature,voltage,GLOBAL_exceptionString,timetaken,locString);
             char result[180];
@@ -578,12 +581,14 @@
                 //DEBUG("\nfromserver: %s \n",result);
                 if (getSettings) {
                     saveSettings(result);
-                    LED1blink(6,250);
+                    LED1blink(5,250);
                 }
             }
+        } else {
+            LED1errorCode(3,20); //ERROR 3   
         }
     } else {
-        LED1blink(200,50);   
+        LED1errorCode(2,20); //ERROR 2
     }
     //RESETS
     RET_motionTriggeredInTXInterval = 0;
@@ -602,11 +607,11 @@
         //DEBUG("locString:%s-\n",locString);
         //SEND DATA
         if (modem.registerOnNetwork(DEFAULT_CONNECTION_ATTEMPTS,(RET_setting_connection_timeout*1000))) {
-            int timetaken = (RET_RTCunixtime - GLOBAL_wakeTime);
+            int timetaken = (RET_RTCunixtime - GLOBAL_wakeTime) + 10; //add 10 for ussd response time 
             
             //Check if we should wait for settings back
             bool getSettings = true;
-            if (  ((RET_RTCunixtime - RET_SettingsGotAt)/3600) < RET_setting_minimumupdate_hrs  ) { getSettings = false;}
+            if (  ((RET_RTCunixtime - RET_SettingsGotAt)/3600) < RET_setting_minimumupdate_hrs  ) { getSettings = false; timetaken -= 10;} //remove the extra 10 seconds from times
             
             char bytesToSend[160];
             snprintf(bytesToSend,sizeof(bytesToSend),"(%s,a:loc,f:%d,t:%.1f,v:%.2f,z:LOC-%s,e:%d,c:1,s:%d%s)\0",GLOBAL_defaultApi,FW_VERSION,temperature,voltage,GLOBAL_exceptionString,timetaken,getSettings,locString);
@@ -618,9 +623,11 @@
                     saveSettings(result);
                 }
             }
+        } else {
+            LED1errorCode(3,20); //ERROR 3   
         }
     } else {
-        LED1blink(200,50);   
+        LED1errorCode(2,20); //ERROR 2
     }
     //RESETS
     RET_motionTriggeredInTXInterval = 0;
@@ -644,9 +651,11 @@
                 memset(RET_activityData,0,sizeof(RET_activityData));
                 if (RET_haveSettings) { RET_motionFrameStart = RET_RTCunixtime; }
             }
+        } else {
+            LED1errorCode(3,20); //ERROR 3
         }
     } else {
-        LED1blink(200,50);   
+        LED1errorCode(2,20); //ERROR 3
     }
     //RESETS
     RET_motionTriggeredInTXInterval = 0;
@@ -664,7 +673,7 @@
             if (setup()) {
                 // All good
             } else {
-                LED1blink(200,50);   
+                //LED1blink(200,50);   
                 RET_eventTime_wakeFromDormant = (RET_RTCunixtime + (24*3600)); //24hrs
                 setState(STATE_DORMANT);
                 DEBUG("SETUP FAILED:DORMANT until %u\n",RET_eventTime_wakeFromDormant);
@@ -793,7 +802,7 @@
     
     
     //CHECK FOR FIRST BOOT
-    if (RET_coldBoot == 1) { factoryReset(); dumpSettings(); }
+    if (RET_coldBoot == 1) { factoryReset(); dumpSettings(); LED1errorCode(6,3); }
     
     //SHALL WE SLEEP
     if (RET_sleepToggle == 1) {
--- a/main.h	Tue Jan 01 20:46:39 2019 +0000
+++ b/main.h	Thu Jan 03 10:09:38 2019 +0000
@@ -66,6 +66,7 @@
 extern bool GLOBAL_needToConfigureLis3dh;
 extern bool GLOBAL_registeredOnNetwork;
 extern bool GLOBAL_modemOn;
+extern bool GLOBAL_LEDSequenceinProgress;
 extern time_t GLOBAL_RTCunixtime;
 extern time_t GLOBAL_wakeTime;
 
--- a/modem.cpp	Tue Jan 01 20:46:39 2019 +0000
+++ b/modem.cpp	Thu Jan 03 10:09:38 2019 +0000
@@ -139,13 +139,12 @@
 {
     //CHECK WE ARE NOT ALREADY ON NETOWRK
     if (!GLOBAL_registeredOnNetwork) {
-            
         int attempt = 0;
         Timer t;
         t.start();
         //DISABLE AIRPLANE MODE
         _w_disable = 1;
-        flushSerial();    
+        flushSerial();
         while (attempt < maxAttempts) {
             watchdogKick();
             t.reset();
@@ -162,8 +161,8 @@
             }
             if (!GLOBAL_registeredOnNetwork) {
                 off(true);
-                Thread::wait(500);
-                on();   
+                Thread::wait(1000);
+                on();
             }
             attempt ++;
         }