Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Revision:
8:95a325df1f6b
Parent:
5:9cea89700c66
Child:
12:d472f9811262
--- a/SnConfigFrame.h	Sat Aug 04 01:48:55 2012 +0000
+++ b/SnConfigFrame.h	Wed Aug 08 23:27:37 2012 +0000
@@ -12,15 +12,20 @@
     static const uint32_t    kMinCommWinDurLowPwr; // exclusive min low power comm win duration (s)
     static const uint32_t    kMaxCommWinDurLowPwr; // exclusive max low power comm win duration (s)
     static const uint8_t     kConfLblLen=64;       // length of configuration label char array (63+'\0')
+    static const uint8_t     kIPLen=16;            // length of IP string. matches MBED's Socket class (so no ipv6)
     
     static const char* const kDefConfFile;  // default configuration file
 
-    static const uint32_t   kMaxSizeOf = 
-            + (10u*sizeof(uint32_t)) + (6u*sizeof(uint16_t))
-            + (11u*sizeof(uint8_t)) + (3u*kNplas*sizeof(uint16_t))
+    static const uint32_t   kMaxSizeOfV1 = 
+            + (9u*sizeof(uint32_t)) + (6u*sizeof(uint16_t))
+            + (10u*sizeof(uint8_t)) + (3u*kNplas*sizeof(uint16_t))
             + (kTotDacs*sizeof(uint16_t))
             + (kConfLblLen*sizeof(uint8_t));
-
+    static const uint32_t   kMaxSizeOfV2 =
+            kMaxSizeOfV1 + sizeof(uint32_t) + sizeof(uint8_t);
+    static const uint32_t   kMaxSizeOfV3 =
+            kMaxSizeOfV2 + (2u*sizeof(uint16_t)) + (4u*kIPLen*sizeof(char));
+    static const uint32_t   kMaxSizeOf = kMaxSizeOfV3;
     
     enum EDatPackBit {
         kSDcard = BIT(0),
@@ -49,8 +54,8 @@
     };
     
     enum ERunMode {
-        kInfSeqs   = 0,
-        kSingleSeq = 1
+        kSingleSeqBit   = BIT(0), // if 0, infinite sequences
+        kCountPowerBit  = BIT(1), // if 0, count events
     };
     
     // i/o version
@@ -89,26 +94,46 @@
     // power
     uint8_t     fPowerMode;                // power mode bit word: see EPowerModeBit
     int16_t     fBatVoltLowPwr;            // battery level at which to switch to low power (not used?)
+    uint16_t    fVoltCheckPeriod;          // how often to check the voltages (s)
     // communication
     uint32_t    fCommWinPeriod;            // seconds between communication window startup (0=always on)
     uint32_t    fCommWinDuration;          // seconds that communication window stays open (0=always open)
     int16_t     fCommSendData;             // data to send during comm win (=0: none, >0=send up to x events from last file until comm win closes, <0=see ESendDataBit)
     uint32_t    fCommWinPrdLowPwr;         // low power communication window period (seconds) (range enforced)
     uint32_t    fCommWinDurLowPwr;         // low power communication window duration (seconds) (range enforced)
+    char        fRemoteServer[kIPLen];     // IP address of remote server (for afar)
+    uint16_t    fRemotePort;               // port number of remote server (for afar)
+    char        fMbedIP[kIPLen];           // IP address of this mbed
+    char        fMbedMask[kIPLen];         // IP address of this mbed mask
+    char        fMbedGate[kIPLen];         // IP address of this mbed gateway
     // watchdog
     uint32_t    fWatchDogPeriod;           // number of seconds of inactivity for watchdog to issue a reset
     
+    // in case of low power, store regular settings
+    // these are not sent over i/o or stored in the file
+    // so they are not included in SizeOf
+    bool        fIsLowPower;
+    char        fNormLabel[kConfLblLen];
+    uint8_t     fNormPowerMode;
+    
     void SetHardDefaults();
     
     static
-    uint32_t    SizeOf(const bool streamHiLoPlas,
+    uint32_t    SizeOf(const uint8_t rv,
+                       const bool streamHiLoPlas,
                        const uint8_t nplas,
                        const uint8_t lblLen) {
         // private because it cannot be used to read from a buffer
         // (the label length and fStreamHiLoPlas are not known a priori)
         // returns the num of bytes needed to stream this object
         // = size of member vars + 1 for i/o version + extra PLA strings (maybe)
-        uint32_t sz = kMaxSizeOf - kConfLblLen + lblLen;
+        uint32_t maxsize = kMaxSizeOf;
+        if (rv==1) {
+            maxsize = kMaxSizeOfV1;
+        } else if (rv==2) {
+            maxsize = kMaxSizeOfV2;
+        }
+        uint32_t sz = maxsize - kConfLblLen + lblLen;
         static const uint32_t mhlp = 2u*kNplas*sizeof(uint16_t);
         const int32_t dp = (nplas-kNplas)*sizeof(uint16_t);
         const uint8_t fac = (streamHiLoPlas) ? 3u : 1u;
@@ -120,18 +145,22 @@
     }
    
  public:
-    SnConfigFrame() { Reset(); }
+    SnConfigFrame() : fIsLowPower(false) { Reset(); }
     virtual ~SnConfigFrame() {}
     
+    bool     IsCountingPowerReadings() const { return ((fRunMode & kCountPowerBit)!=0); }
+    bool     IsSingleSeqRunMode() const { return ((fRunMode & kSingleSeqBit)!=0); }
+    bool     IsLowPowerMode() const { return fIsLowPower; }
     const char* GetLabel() const { return fLabel; }
     uint32_t GetLabelStrLen() const { return strlen(fLabel); }
     uint32_t GetRun() const { return fRun; }
     uint32_t GetFirstEvt() const { return fFirstEvt; }
     uint32_t GetEvtsPerFile() const { return fEvtsPerSeq; }
-    bool     IsSingleSeqRunMode() const { return fRunMode==kSingleSeq; }
     uint16_t GetEvtThrtlPeriodMs() const { return fEvtThrtlPeriodMs; }
     uint16_t GetForceTrigPeriod() const { return fForceTrigPeriod; }
     uint16_t GetHeartbeatPeriod() const { return fHeartBeatPeriod; }
+    uint16_t GetBatVoltLowPwr() const { return fBatVoltLowPwr; }
+    uint16_t GetVoltCheckPeriod() const { return fVoltCheckPeriod; }
     uint32_t GetWatchdogPeriod() const { return fWatchDogPeriod; }
     uint16_t GetDac(const uint8_t ch, const uint8_t dn) const { return fDAC[ch][dn]; }
     uint8_t  GetNumPlas() const { return fNumPlas; }
@@ -147,8 +176,13 @@
     }
     // TODO: allow check for individual amps, when they can be turned on individually
     
-    uint32_t GetCommWinPeriod() const { return fCommWinPeriod; }
-    uint32_t GetCommWinDuration() const { return fCommWinDuration; }
+    const char* GetRemoteServer() const { return fRemoteServer; }
+    uint16_t    GetRemotePort() const { return fRemotePort; }
+    const char* GetMbedIP() const { return fMbedIP; }
+    const char* GetMbedMask() const { return fMbedMask; }
+    const char* GetMbedGate() const { return fMbedGate; }
+    uint32_t GetCommWinPeriod() const { return fIsLowPower ? fCommWinPrdLowPwr : fCommWinPeriod; }
+    uint32_t GetCommWinDuration() const { return fIsLowPower ? fCommWinDurLowPwr : fCommWinDuration; }
     int16_t  GetCommSendData() const { return fCommSendData; }
     
     bool     IsSendingAllFiles() const
@@ -159,9 +193,9 @@
         { return (fCommSendData<0) && ((fCommSendData & kDelete)!=0); }
     
     uint8_t GetPowerMode() const { return fPowerMode; }
-    // return int to correspond to what DigitalOut::operator= expects
-    int     GetPowPinSetting(const EPowerModeBit p) {
-        const bool on = ((fPowerMode & p)!=0);
+    int     GetPowPinSetting(const EPowerModeBit p) const {
+        // return int to correspond to what DigitalOut::operator= expects
+        const bool on = IsPoweredFor(p);
         if (p==kCardDatTak || p==kCardComWin ||
             p==kAmpsDatTak || p==kAmpsComWin) {
             return on ? 0 : 1;
@@ -169,6 +203,15 @@
             return on ? 1 : 0;
         }
     }
+    bool   IsPoweredFor(const EPowerModeBit p) const {
+        return ((fPowerMode & p)!=0);
+    }
+    
+    void EnablePowerFor(const EPowerModeBit p)  { fPowerMode |= p; }
+    void DisablePowerFor(const EPowerModeBit p) { fPowerMode &= ~p; }
+    
+    void ChangeToLowPower();
+    void ChangeToNormPower();
     
     const char* GetOutFileName(const char* dir) const;
     
@@ -247,7 +290,11 @@
             b           = SnBitUtils::ReadFrom(b, fPowerMode);
             printf("pow=%hhu\r\n",fPowerMode);
             b           = SnBitUtils::ReadFrom(b, fBatVoltLowPwr);
-            printf("batlow=%d\r\n",fBatVoltLowPwr);
+            printf("batlow=%hd\r\n",fBatVoltLowPwr);
+            if (Rv>2) {
+                b       = SnBitUtils::ReadFrom(b, fVoltCheckPeriod);
+                printf("vltchk=%hu\r\n",fVoltCheckPeriod);
+            }
             b           = SnBitUtils::ReadFrom(b, fCommWinPeriod);
             printf("cmper=%u\r\n",fCommWinPeriod);
             b           = SnBitUtils::ReadFrom(b, fCommWinDuration);
@@ -258,6 +305,18 @@
             printf("cmperlp=%u\r\n",fCommWinPrdLowPwr);
             b           = SnBitUtils::ReadFrom(b, fCommWinDurLowPwr);
             printf("cmdurlp=%u\r\n",fCommWinDurLowPwr);
+            if (Rv>2) {
+                b       = SnBitUtils::ReadFrom(b, fRemoteServer, kIPLen);
+                printf("rserv=%s\r\n",fRemoteServer);
+                b       = SnBitUtils::ReadFrom(b, fRemotePort);
+                printf("rport=%hu\r\n",fRemotePort);
+                b       = SnBitUtils::ReadFrom(b, fMbedIP, kIPLen);
+                printf("mbedip=%s\r\n",fMbedIP);
+                b       = SnBitUtils::ReadFrom(b, fMbedMask, kIPLen);
+                printf("mbedmask=%s\r\n",fMbedMask);
+                b       = SnBitUtils::ReadFrom(b, fMbedGate, kIPLen);
+                printf("mbedgate=%s\r\n",fMbedGate);
+            }
             b           = SnBitUtils::ReadFrom(b, fWatchDogPeriod);
             printf("watch=%u\r\n",fWatchDogPeriod);
             if (fStreamHiLoPlas!=0) {
@@ -315,11 +374,17 @@
         b           = SnBitUtils::WriteTo(b, fEvtThrtlPeriodMs);
         b           = SnBitUtils::WriteTo(b, fPowerMode);
         b           = SnBitUtils::WriteTo(b, fBatVoltLowPwr);
+        b           = SnBitUtils::WriteTo(b, fVoltCheckPeriod);
         b           = SnBitUtils::WriteTo(b, fCommWinPeriod);
         b           = SnBitUtils::WriteTo(b, fCommWinDuration);
         b           = SnBitUtils::WriteTo(b, fCommSendData);
         b           = SnBitUtils::WriteTo(b, fCommWinPrdLowPwr);
         b           = SnBitUtils::WriteTo(b, fCommWinDurLowPwr);
+        b           = SnBitUtils::WriteTo(b, fRemoteServer, kIPLen);
+        b           = SnBitUtils::WriteTo(b, fRemotePort);
+        b           = SnBitUtils::WriteTo(b, fMbedIP, kIPLen);
+        b           = SnBitUtils::WriteTo(b, fMbedMask, kIPLen);
+        b           = SnBitUtils::WriteTo(b, fMbedGate, kIPLen);
         b           = SnBitUtils::WriteTo(b, fWatchDogPeriod);
         if (fStreamHiLoPlas!=0) {
             pl = fPLA;
@@ -343,11 +408,11 @@
         }
     }
         
-    uint32_t    SizeOf() const {
+    uint32_t    SizeOf(const uint8_t rv) const {
         // returns the num of bytes needed to stream this object
         // = size of member vars + 1 for i/o version + extra PLA strings (maybe)
         //   + length of label string
-        return SizeOf(fStreamHiLoPlas!=0, fNumPlas, strlen(fLabel));
+        return SizeOf(rv, fStreamHiLoPlas!=0, fNumPlas, strlen(fLabel));
     }
 
     static void     SetMacAddress();