Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Revision:
27:efc4d654b139
Parent:
25:57b2627fe756
Child:
28:484943132bb0
--- a/main.cpp	Tue Oct 30 06:02:32 2012 +0000
+++ b/main.cpp	Thu Nov 01 07:00:17 2012 +0000
@@ -227,19 +227,17 @@
 
 void procCommWin() {
     ++gCommWinChecks;
-    if (gReadingOut==false && gCommWinOpen==false) {
-        //if ( (time(0) - gLastCommWin) > gConf.GetCommWinPeriod() ) {
+    //if ( (time(0) - gLastCommWin) > gConf.GetCommWinPeriod() ) {
 #ifdef DEBUG
-        printf("<><><><><><> gCommWinChecks=%u, gNcommWinChecks=%u\r\n",
-            gCommWinChecks, gNcommWinChecks);
+    printf("<><><><><><> gCommWinChecks=%u, gNcommWinChecks=%u\r\n",
+        gCommWinChecks, gNcommWinChecks);
 #endif
-        if ( gCommWinChecks >= gNcommWinChecks ) {
+    if ( gCommWinChecks >= gNcommWinChecks ) {
 #ifdef DEBUG
-            printf("proc comm win\r\n"); 
+        printf("proc comm win.\r\n"); 
 #endif
-            led3=!led3;
-            gOpenCommWin = true;
-        }
+        led3=!led3;
+        gOpenCommWin = true;
     }
 }
 
@@ -505,7 +503,7 @@
 int main() {
     // a failsafe
     Watchdog::kick(WDFAILSAFE);
-    
+
     {
         gCpu.baud(CPUBAUD_SN);
 #if defined(SSNOTIFY) || defined(DEBUG)
@@ -733,7 +731,8 @@
             etms=0;
         } else {
 #ifdef DEBUG
-            printf("gOpenCommWin=false\r\n");
+            printf("gOpenCommWin=false, gCommWinChecks=%u, gNcommWinChecks=%u\r\n",
+                gCommWinChecks, gNcommWinChecks);
 #endif
         }
         
@@ -1282,10 +1281,38 @@
                 cw = gComms;
                 ss = sendStat;
             }
+            // skip if no comm object
             if ((*cw)==0) {
                 continue;
             }
-            
+            // skip if no power for this comm
+            // THIS IS VITAL! For example, if the ethernet
+            // port is powered down, making an Ethernet obejct
+            // (done in netif) will stall forever waiting for the clock.
+            // Do it here to keep all PIN usage in main.cpp
+            bool havePower=false;
+            switch ((*cw)->GetCommType()) {
+                case SnConfigFrame::kIrid:
+                    havePower = gConf.IsPoweredFor(SnConfigFrame::kIridComWin)
+                        && (PIN_iridSbd_power.read() ==
+                            gConf.GetPowPinSetting(SnConfigFrame::kIridComWin));
+                    break;
+                case SnConfigFrame::kAfar:
+                    havePower = gConf.IsPoweredFor(SnConfigFrame::kAfarComWin)
+                        && (PIN_afar_power.read() ==
+                            gConf.GetPowPinSetting(SnConfigFrame::kAfarComWin));
+                    break;
+                case SnConfigFrame::kUSB:
+                    havePower = true; // USB always on (for now)
+                    break;
+                case SnConfigFrame::kSDcard: // shouldn't happen. skip it
+                default: // unknown.. skip it
+                    break;
+            };
+            if (havePower==false) {
+                continue;
+            }
+
             const uint32_t conto = 
                 (gConf.GetCommWinDuration() < (*cw)->GetConnectTimeout()) ?
                  gConf.GetCommWinDuration() : (*cw)->GetConnectTimeout();