init

Dependencies:   aconno_I2C Lis2dh12 WatchdogTimer

Revision:
29:059fc7324328
Parent:
28:24b02608fa5f
Child:
31:c84fc6d8eaa3
--- a/main.cpp	Sun Dec 23 23:09:53 2018 +0000
+++ b/main.cpp	Sun Dec 23 23:50:39 2018 +0000
@@ -157,7 +157,7 @@
 void setState(uint8_t state) {
     RET_state_prev = RET_state;
     RET_state = state;
-    DEBUG("STATEREADBACK %d\n",RET_state)
+    //DEBUG("STATEREADBACK %d\n",RET_state)
 }
 bool memoryIntegrityCheck() {
     bool pass = true;
@@ -247,13 +247,13 @@
                         mainthread.release();
                     }
                     break;
-                case 2 :
+                case 3 :
                     if (RET_state == STATE_NORMAL) {
                         RET_state = STATE_BUTTONPRESS2;
                         mainthread.release();
                     }
                     break;
-                case 3 :
+                case 5 :
                     if (RET_state == STATE_NORMAL) {
                         RET_state = STATE_BUTTONPRESS3;
                         mainthread.release();
@@ -363,8 +363,10 @@
     
     //Result
     if (test_count == test_pass) {
+        addToExceptionString("OK."); 
         return true;
     } else {
+        addToExceptionString("FAIL."); 
         return false;   
     }
 }
@@ -374,7 +376,7 @@
 //------------------------------------------------------------------------------ 
 void checkMotion() {
     if (lis3dh_int2) {
-        if (GLOBAL_debugLED) LED1blink(1,50);
+        //if (GLOBAL_debugLED) LED1blink(1,50);
         RET_motionTriggered = true;
         GLOBAL_needToConfigureLis3dh = true; //interrupt has fire so need to clear it
         if (!RET_motionPendingOnState) {
@@ -399,7 +401,7 @@
         if (inMotionForSeconds >= RET_setting_motion_start_seconds && RET_motionState == false) {
             RET_motionState = true;
             RET_motionTriggeredInTXInterval = true;
-            if (GLOBAL_debugLED) LED1blink(5,50);
+            if (GLOBAL_debugLED) LED1blink(1,50);
             if (RET_setting_location_tx_failsafe_hrs > 0) {
                 time_t epochOffsetMins = ((RET_RTCunixtime - RET_motionFrameStart) / 60);
                 sprintf(RET_activityData+strlen(RET_activityData),"1.%u!",epochOffsetMins);
@@ -413,7 +415,7 @@
             RET_motionState = false;
             GLOBAL_motionStopFlagTriggered = true;
             RET_motionTotalActivityHours += (float(RET_motionStopTime - RET_motionStartTime) / 3600.0); 
-            if (GLOBAL_debugLED) LED1blink(3,400);
+            if (GLOBAL_debugLED) LED1blink(2,50);
             if (RET_setting_location_tx_failsafe_hrs > 0) {
                 time_t epochOffsetMins = ((RET_RTCunixtime - RET_motionFrameStart) / 60);
                 sprintf(RET_activityData+strlen(RET_activityData),"0.%u!",epochOffsetMins);
@@ -432,7 +434,7 @@
     int TEMP_k = -1; int TEMP_l = -1; int TEMP_m = -1; int TEMP_n = -1; int TEMP_o = -1; int TEMP_p = -1; int TEMP_q = -1; int TEMP_r = -1; int TEMP_s = -1;
     if ( (matchCount = sscanf(settingsBuffer,"b:%u,c:%d,d:%d,e:%d,f:%d,g:%d,h:%d,i:%d,j:%d,k:%d,l:%d,m:%d,n:%d,o:%d,p:%d,q:%d,r:%d,s:%d",
     &TEMP_b,&TEMP_c,&TEMP_d,&TEMP_e,&TEMP_f,&TEMP_g,&TEMP_h,&TEMP_i,&TEMP_j,&TEMP_k,&TEMP_l,&TEMP_m,&TEMP_n,&TEMP_o,&TEMP_p,&TEMP_q,&TEMP_r,&TEMP_s) ) > 0 ) {
-        DEBUG("VALUES: b:%u,c:%d,d:%d,e:%d,f:%d,g:%d,h:%d,i:%d,j:%d,k:%d,l:%d,m:%d,n:%d,o:%d,p:%d,q:%d,r:%d,s:%d\n",
+        DEBUG("FROMSERVER: b:%u,c:%d,d:%d,e:%d,f:%d,g:%d,h:%d,i:%d,j:%d,k:%d,l:%d,m:%d,n:%d,o:%d,p:%d,q:%d,r:%d,s:%d\n",
         TEMP_b,TEMP_c,TEMP_d,TEMP_e,TEMP_f,TEMP_g,TEMP_h,TEMP_i,TEMP_j,TEMP_k,TEMP_l,TEMP_m,TEMP_n,TEMP_o,TEMP_p,TEMP_q,TEMP_r,TEMP_s);
         
         //FAILUREMODE need to be checking these against checksums
@@ -521,7 +523,7 @@
             char result[180];
             snprintf(result,sizeof(result),"%s",modem.USSDmessage(bytestosend, true, 2, GLOBAL_defaultApi));
             if (result != "err") {
-                DEBUG("\nfromserver: %s \n",result);
+                //DEBUG("\nfromserver: %s \n",result);
                 if (!saveSettings(result)) { 
                     //something went critically wrong getting settings 
                     pass = false;
@@ -558,7 +560,7 @@
         if (modem.registerOnNetwork(DEFAULT_CONNECTION_ATTEMPTS,(RET_setting_connection_timeout*1000))) {
             int timetaken = (RET_RTCunixtime - GLOBAL_wakeTime);
             char bytestosend[160];
-            snprintf(bytestosend,sizeof(bytestosend),"(%s,a:loc,f:%d,t:%.1f,v:%.2f,z:CONNTEST-%s,e:%d,c:1%s)\0",GLOBAL_defaultApi,FW_VERSION,temperature,voltage,GLOBAL_exceptionString,timetaken,locString);
+            snprintf(bytestosend,sizeof(bytestosend),"(%s,a:loc,f:%d,t:%.1f,v:%.2f,z:TEST-%s,e:%d,c:1%s)\0",GLOBAL_defaultApi,FW_VERSION,temperature,voltage,GLOBAL_exceptionString,timetaken,locString);
             char result[180];
             bool getSettings = true;
             snprintf(result,sizeof(result),"%s",modem.USSDmessage(bytestosend, getSettings, 2, GLOBAL_defaultApi));
@@ -592,7 +594,7 @@
         if (modem.registerOnNetwork(DEFAULT_CONNECTION_ATTEMPTS,(RET_setting_connection_timeout*1000))) {
             int timetaken = (RET_RTCunixtime - GLOBAL_wakeTime);
             char bytesToSend[160];
-            snprintf(bytesToSend,sizeof(bytesToSend),"(%s,a:loc,f:%d,t:%.1f,v:%.2f,z:%s,e:%d,c:1%s)\0",GLOBAL_defaultApi,FW_VERSION,temperature,voltage,GLOBAL_exceptionString,timetaken,locString);
+            snprintf(bytesToSend,sizeof(bytesToSend),"(%s,a:loc,f:%d,t:%.1f,v:%.2f,z:LOC-%s,e:%d,c:1%s)\0",GLOBAL_defaultApi,FW_VERSION,temperature,voltage,GLOBAL_exceptionString,timetaken,locString);
             char result[180];
             bool getSettings = true;
             snprintf(result,sizeof(result),"%s",modem.USSDmessage(bytesToSend, getSettings, 2, GLOBAL_defaultApi));
@@ -624,7 +626,7 @@
             if (result != "err") {
                 //RESET ACTIVITY FRAME
                 memset(RET_activityData,0,sizeof(RET_activityData));
-                if (RET_haveSettings) {RET_motionFrameStart = RET_RTCunixtime;}
+                if (RET_haveSettings) { RET_motionFrameStart = RET_RTCunixtime; }
             }
         }
     }
@@ -678,8 +680,7 @@
             //ACTIVITY EVENT
             bool run_activity_tx = false;
             if(RET_RTCunixtime >= RET_eventTime_activity_tx && RET_eventTime_activity_tx > 0 && strlen(RET_activityData) > 1) { 
-                run_activity_tx = true; 
-                //event_shakertest_tx();
+                run_activity_tx = true;
             }
             if (strlen(RET_activityData) > 130) { run_activity_tx = true; }
             if (run_activity_tx) { DEBUG("ACTIVITY TX...\n"); event_activity_tx();}
@@ -759,20 +760,20 @@
     if (NRF_POWER->RESETREAS != 0xffffffff) {
         switch(NRF_POWER->RESETREAS) {
             case 0x00000001  :
-                DEBUG("reset_reason: 0x%08x. Hard Reset STATE:%d\n",NRF_POWER->RESETREAS, RET_state);
+                DEBUG("0x%08x. Hard Reset ST:%d\n",NRF_POWER->RESETREAS, RET_state);
                 RET_coldBoot = 1;
             break;
             case 0x00000002  :
-                DEBUG("Watchdog reset STATE:%d\n",RET_state);
+                DEBUG("Watchdog ST:%d\n",RET_state);
             break;
             case 0x00000004  :
-                DEBUG("Soft reset STATE:%d SLEEP:%d\n",RET_state, RET_sleepToggle);
+                DEBUG("Soft ST:%d SLP:%d\n",RET_state, RET_sleepToggle);
             break;
         }
         NRF_POWER->RESETREAS = 0xffffffff;
     }
     
-    dumpSettings();
+    //dumpSettings();
     
     //CHECK FOR FIRST BOOT
     if (RET_coldBoot == 1) { factoryReset(); dumpSettings(); }