Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Sat Oct 05 04:45:22 2013 +0000
Revision:
40:1324da35afd4
Parent:
39:2f17131d22a5
Child:
56:0bba0ef15697
first commit of major overhaul to 2013-2014 mbed code. NOT YET FULLY TESTED. too many changes to list (fix local file receive, fix rates, external comm packes, big SD cards, get to comm win w/o SD, v8 config frame, v4 files, SBD buffering changes...)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
uci1 3:24c5f0f50bf1 1 #ifndef SN_SnConfigFrame
uci1 3:24c5f0f50bf1 2 #define SN_SnConfigFrame
uci1 3:24c5f0f50bf1 3
uci1 3:24c5f0f50bf1 4 #include <stdint.h>
uci1 3:24c5f0f50bf1 5 #include "SnConstants.h"
uci1 3:24c5f0f50bf1 6 #include "SnBitUtils.h"
uci1 3:24c5f0f50bf1 7
uci1 16:744ce85aede2 8 //#define DEBUG
uci1 16:744ce85aede2 9
uci1 3:24c5f0f50bf1 10 class SnConfigFrame {
uci1 3:24c5f0f50bf1 11 public:
uci1 31:b5bd3b189150 12 static bool fgApplySafetyNets; // whether to apply safety bounds on certain parameters in ReadFrom (default: true)
uci1 31:b5bd3b189150 13
uci1 3:24c5f0f50bf1 14 static const uint32_t kMinCommWinPrdLowPwr; // exclusive min low power comm win period (s)
uci1 3:24c5f0f50bf1 15 static const uint32_t kMaxCommWinPrdLowPwr; // exclusive max low power comm win period (s)
uci1 3:24c5f0f50bf1 16 static const uint32_t kMinCommWinDurLowPwr; // exclusive min low power comm win duration (s)
uci1 3:24c5f0f50bf1 17 static const uint32_t kMaxCommWinDurLowPwr; // exclusive max low power comm win duration (s)
uci1 3:24c5f0f50bf1 18 static const uint8_t kConfLblLen=64; // length of configuration label char array (63+'\0')
uci1 8:95a325df1f6b 19 static const uint8_t kIPLen=16; // length of IP string. matches MBED's Socket class (so no ipv6)
uci1 3:24c5f0f50bf1 20
uci1 3:24c5f0f50bf1 21 static const char* const kDefConfFile; // default configuration file
uci1 28:484943132bb0 22 static const char* const kDefIPflag; // flag to use IP default
uci1 3:24c5f0f50bf1 23
uci1 8:95a325df1f6b 24 static const uint32_t kMaxSizeOfV1 =
uci1 8:95a325df1f6b 25 + (9u*sizeof(uint32_t)) + (6u*sizeof(uint16_t))
uci1 40:1324da35afd4 26 + (10u*sizeof(uint8_t)) + (3u*kNplasV1*sizeof(uint16_t))
uci1 3:24c5f0f50bf1 27 + (kTotDacs*sizeof(uint16_t))
uci1 3:24c5f0f50bf1 28 + (kConfLblLen*sizeof(uint8_t));
uci1 8:95a325df1f6b 29 static const uint32_t kMaxSizeOfV2 =
uci1 8:95a325df1f6b 30 kMaxSizeOfV1 + sizeof(uint32_t) + sizeof(uint8_t);
uci1 8:95a325df1f6b 31 static const uint32_t kMaxSizeOfV3 =
uci1 8:95a325df1f6b 32 kMaxSizeOfV2 + (2u*sizeof(uint16_t)) + (4u*kIPLen*sizeof(char));
uci1 40:1324da35afd4 33 static const uint32_t kMaxSizeOfV4 = kMaxSizeOfV3 + (sizeof(float)-sizeof(uint16_t)); // forced trig per to float
uci1 39:2f17131d22a5 34 static const uint32_t kMaxSizeOfV5 = kMaxSizeOfV4;
uci1 40:1324da35afd4 35 static const uint32_t kMaxSizeOfV6 = kMaxSizeOfV5 + sizeof(uint16_t); // To/From Low Power
uci1 40:1324da35afd4 36 static const uint32_t kMaxSizeOfV7 = kMaxSizeOfV6 + (2u*sizeof(uint8_t)); // add ConnTOmins, ListenTOmins
uci1 40:1324da35afd4 37 static const uint32_t kMaxSizeOfV8 = kMaxSizeOfV7 - sizeof(uint32_t) + sizeof(uint16_t); // FirstEvt -> FirstSeq
uci1 40:1324da35afd4 38 static const uint32_t kMaxSizeOf = kMaxSizeOfV8;
uci1 3:24c5f0f50bf1 39
uci1 3:24c5f0f50bf1 40 enum EDatPackBit {
uci1 3:24c5f0f50bf1 41 kSDcard = BIT(0),
uci1 3:24c5f0f50bf1 42 kIrid = BIT(1),
uci1 3:24c5f0f50bf1 43 kAfar = BIT(2),
uci1 3:24c5f0f50bf1 44 kUSB = BIT(3)
uci1 3:24c5f0f50bf1 45 };
uci1 3:24c5f0f50bf1 46
uci1 3:24c5f0f50bf1 47 enum ESendDataBit {
uci1 3:24c5f0f50bf1 48 // can't use BIT(0)! (-0 = 0 => send nothing)
uci1 13:7a1fb885a8e4 49 kAllFiles = BIT(1), // if bit=0 => send most recent file
uci1 13:7a1fb885a8e4 50 kTimeout = BIT(2), // if bit=0 => ignore timeout
uci1 13:7a1fb885a8e4 51 kDelete = BIT(3), // if bit=0 => do not delete sent files
uci1 13:7a1fb885a8e4 52 kForceSBDdata = BIT(4), // if bit=0 => do not send data over SBD
uci1 40:1324da35afd4 53 kHnShBefSendDat = BIT(5), // if bit=0 => do not wait for a handshake after GetConfig before calling SendData
uci1 39:2f17131d22a5 54 kUseBits = static_cast<int16_t>(-BIT(14)) // useful to initialize fCommSendData as a bit word
uci1 3:24c5f0f50bf1 55 };
uci1 3:24c5f0f50bf1 56
uci1 4:a91682e19d6b 57 enum EPowerModeBit {
uci1 4:a91682e19d6b 58 kAmpsDatTak = BIT(0),
uci1 4:a91682e19d6b 59 kCardDatTak = BIT(1),
uci1 4:a91682e19d6b 60 kIridDatTak = BIT(2),
uci1 4:a91682e19d6b 61 kAfarDatTak = BIT(3),
uci1 4:a91682e19d6b 62 kAmpsComWin = BIT(4),
uci1 4:a91682e19d6b 63 kCardComWin = BIT(5),
uci1 4:a91682e19d6b 64 kIridComWin = BIT(6),
uci1 4:a91682e19d6b 65 kAfarComWin = BIT(7)
uci1 4:a91682e19d6b 66 };
uci1 4:a91682e19d6b 67
uci1 3:24c5f0f50bf1 68 enum ERunMode {
uci1 8:95a325df1f6b 69 kSingleSeqBit = BIT(0), // if 0, infinite sequences
uci1 8:95a325df1f6b 70 kCountPowerBit = BIT(1), // if 0, count events
uci1 3:24c5f0f50bf1 71 };
uci1 3:24c5f0f50bf1 72
uci1 3:24c5f0f50bf1 73 // i/o version
uci1 3:24c5f0f50bf1 74 static const uint8_t kIOVers; // MUST BE INCREASED if any member var changes (==> also if kNchans, etc. change!)
uci1 3:24c5f0f50bf1 75
uci1 3:24c5f0f50bf1 76 private:
uci1 3:24c5f0f50bf1 77 // !!
uci1 3:24c5f0f50bf1 78 // !! If any member variables change, update: SizeOf function and kIOVers value! (also if kNchans, etc. change!)
uci1 3:24c5f0f50bf1 79 // !!
uci1 3:24c5f0f50bf1 80
uci1 3:24c5f0f50bf1 81 // mbed mac address
uci1 3:24c5f0f50bf1 82 static uint64_t fgMacAdr; // mbed mac address
uci1 3:24c5f0f50bf1 83 // conf header
uci1 3:24c5f0f50bf1 84 char fLabel[kConfLblLen]; // configuration label
uci1 3:24c5f0f50bf1 85 uint32_t fConfTime; // cpu config time
uci1 3:24c5f0f50bf1 86 uint32_t fRun; // run number
uci1 40:1324da35afd4 87 uint16_t fFirstSeq; // starting sequence number
uci1 3:24c5f0f50bf1 88 uint32_t fEvtsPerSeq; // number of events per file
uci1 3:24c5f0f50bf1 89 uint8_t fRunMode; // mode of running (see ERunMode)
uci1 3:24c5f0f50bf1 90 uint8_t fStreamHiLoPlas; // (1byte bool) if true, add the separated hi/lo thresh PLA patterns to the i/o
uci1 3:24c5f0f50bf1 91 // data packing
uci1 3:24c5f0f50bf1 92 uint8_t fWvLoseLSB; // number of least significant bits to lose when packing waveform data
uci1 3:24c5f0f50bf1 93 uint8_t fWvLoseMSB; // number of most significant bits to lose when packing waveform data
uci1 3:24c5f0f50bf1 94 uint16_t fWvBaseline; // global baseline to use when packing data (useful to reduce clipping on the high end)
uci1 3:24c5f0f50bf1 95 uint8_t fDatPackType; // type of data packing. OR'd bitword: if bit 1, will pack for writing. see EDatPackBit. default: always pack (all 1's)
uci1 3:24c5f0f50bf1 96 // trigger setup
uci1 3:24c5f0f50bf1 97 uint16_t fDAC[kNchans][kNfpgaDacs]; //[card id][dac id] values should be 0-4095 here (not checked tho)
uci1 3:24c5f0f50bf1 98 uint8_t fNumPlas; // number of patterns to use. must be <= kNplas.
uci1 3:24c5f0f50bf1 99 uint16_t fPLA[kNplas]; //[pattern id] (same for each card)
uci1 3:24c5f0f50bf1 100 uint8_t fNumCardsMajLog; // number of cards participating in the MajLogic trigger (1 to 4)
uci1 3:24c5f0f50bf1 101 uint8_t fEnableThermTrig; // (1byte bool) whether or not to allow thermal triggers
uci1 18:55f1581f2ee4 102 float fForceTrigPeriod; // number of seconds between force triggers (0=none)
uci1 3:24c5f0f50bf1 103 uint16_t fHeartBeatPeriod; // number of seconds between heartbeats (0=none)
uci1 3:24c5f0f50bf1 104 uint8_t fAmpsOn; // which amps are on (bit word. uint8_t => 8 amps max)
uci1 3:24c5f0f50bf1 105 uint16_t fEvtThrtlPeriodMs; // throttle period to write events (ms)
uci1 3:24c5f0f50bf1 106 // power
uci1 4:a91682e19d6b 107 uint8_t fPowerMode; // power mode bit word: see EPowerModeBit
uci1 40:1324da35afd4 108 uint16_t fBatVoltToLowPwr; // battery level at which to switch to low power (not used?)
uci1 40:1324da35afd4 109 uint16_t fBatVoltFromLowPwr; // battery level at which to switch back from low power (not used?)
uci1 8:95a325df1f6b 110 uint16_t fVoltCheckPeriod; // how often to check the voltages (s)
uci1 3:24c5f0f50bf1 111 // communication
uci1 3:24c5f0f50bf1 112 uint32_t fCommWinPeriod; // seconds between communication window startup (0=always on)
uci1 3:24c5f0f50bf1 113 uint32_t fCommWinDuration; // seconds that communication window stays open (0=always open)
uci1 3:24c5f0f50bf1 114 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)
uci1 3:24c5f0f50bf1 115 uint32_t fCommWinPrdLowPwr; // low power communication window period (seconds) (range enforced)
uci1 3:24c5f0f50bf1 116 uint32_t fCommWinDurLowPwr; // low power communication window duration (seconds) (range enforced)
uci1 40:1324da35afd4 117 uint8_t fCommWinConnectTOMin; // comm win connection timeout (minutes) (range enforced)
uci1 40:1324da35afd4 118 uint8_t fCommWinListenTOMin; // comm win listening timeout (minutes) (range enforced)
uci1 8:95a325df1f6b 119 char fRemoteServer[kIPLen]; // IP address of remote server (for afar)
uci1 8:95a325df1f6b 120 uint16_t fRemotePort; // port number of remote server (for afar)
uci1 8:95a325df1f6b 121 char fMbedIP[kIPLen]; // IP address of this mbed
uci1 8:95a325df1f6b 122 char fMbedMask[kIPLen]; // IP address of this mbed mask
uci1 8:95a325df1f6b 123 char fMbedGate[kIPLen]; // IP address of this mbed gateway
uci1 3:24c5f0f50bf1 124 // watchdog
uci1 3:24c5f0f50bf1 125 uint32_t fWatchDogPeriod; // number of seconds of inactivity for watchdog to issue a reset
uci1 3:24c5f0f50bf1 126
uci1 8:95a325df1f6b 127 // in case of low power, store regular settings
uci1 8:95a325df1f6b 128 // these are not sent over i/o or stored in the file
uci1 8:95a325df1f6b 129 // so they are not included in SizeOf
uci1 8:95a325df1f6b 130 bool fIsLowPower;
uci1 8:95a325df1f6b 131 char fNormLabel[kConfLblLen];
uci1 8:95a325df1f6b 132 uint8_t fNormPowerMode;
uci1 8:95a325df1f6b 133
uci1 3:24c5f0f50bf1 134 void SetHardDefaults();
uci1 3:24c5f0f50bf1 135
uci1 3:24c5f0f50bf1 136 static
uci1 8:95a325df1f6b 137 uint32_t SizeOf(const uint8_t rv,
uci1 8:95a325df1f6b 138 const bool streamHiLoPlas,
uci1 3:24c5f0f50bf1 139 const uint8_t nplas,
uci1 3:24c5f0f50bf1 140 const uint8_t lblLen) {
uci1 3:24c5f0f50bf1 141 // private because it cannot be used to read from a buffer
uci1 3:24c5f0f50bf1 142 // (the label length and fStreamHiLoPlas are not known a priori)
uci1 3:24c5f0f50bf1 143 // returns the num of bytes needed to stream this object
uci1 3:24c5f0f50bf1 144 // = size of member vars + 1 for i/o version + extra PLA strings (maybe)
uci1 8:95a325df1f6b 145 uint32_t maxsize = kMaxSizeOf;
uci1 8:95a325df1f6b 146 if (rv==1) {
uci1 8:95a325df1f6b 147 maxsize = kMaxSizeOfV1;
uci1 8:95a325df1f6b 148 } else if (rv==2) {
uci1 8:95a325df1f6b 149 maxsize = kMaxSizeOfV2;
uci1 19:74155d652c37 150 } else if (rv==3) {
uci1 19:74155d652c37 151 maxsize = kMaxSizeOfV3;
uci1 39:2f17131d22a5 152 } else if (rv==4) {
uci1 39:2f17131d22a5 153 maxsize = kMaxSizeOfV4;
uci1 39:2f17131d22a5 154 } else if (rv==5) {
uci1 39:2f17131d22a5 155 maxsize = kMaxSizeOfV5;
uci1 39:2f17131d22a5 156 } else if (rv==6) {
uci1 40:1324da35afd4 157 maxsize = kMaxSizeOfV6;
uci1 40:1324da35afd4 158 } else if (rv==7) {
uci1 40:1324da35afd4 159 maxsize = kMaxSizeOfV7;
uci1 40:1324da35afd4 160 } else if (rv==8) {
uci1 40:1324da35afd4 161 maxsize = kMaxSizeOfV8;
uci1 8:95a325df1f6b 162 }
uci1 39:2f17131d22a5 163 const int32_t lbldiff = kConfLblLen - lblLen;
uci1 39:2f17131d22a5 164 uint32_t sz = maxsize - lbldiff;
uci1 39:2f17131d22a5 165 if ((lbldiff!=0) && (rv>=4)) {
uci1 39:2f17131d22a5 166 sz += 1; // the \0 at the end of the string
uci1 39:2f17131d22a5 167 }
uci1 3:24c5f0f50bf1 168 static const uint32_t mhlp = 2u*kNplas*sizeof(uint16_t);
uci1 3:24c5f0f50bf1 169 const int32_t dp = (nplas-kNplas)*sizeof(uint16_t);
uci1 3:24c5f0f50bf1 170 const uint8_t fac = (streamHiLoPlas) ? 3u : 1u;
uci1 3:24c5f0f50bf1 171 sz += (fac*dp);
uci1 3:24c5f0f50bf1 172 if (streamHiLoPlas==false) {
uci1 3:24c5f0f50bf1 173 sz -= mhlp;
uci1 3:24c5f0f50bf1 174 }
uci1 3:24c5f0f50bf1 175 return sz;
uci1 3:24c5f0f50bf1 176 }
uci1 28:484943132bb0 177
uci1 28:484943132bb0 178 void SetDefaultIPs();
uci1 28:484943132bb0 179 void SetDefaultRemoteServ();
uci1 28:484943132bb0 180 void SetDefaultRemotePort();
uci1 28:484943132bb0 181 void SetDefaultMbedIP();
uci1 28:484943132bb0 182 void SetDefaultMaskIP();
uci1 28:484943132bb0 183 void SetDefaultGateIP();
uci1 28:484943132bb0 184 void ApplySafetyNets();
uci1 28:484943132bb0 185
uci1 3:24c5f0f50bf1 186 public:
uci1 31:b5bd3b189150 187 SnConfigFrame(const bool applySafety=true) : fIsLowPower(false) {
uci1 31:b5bd3b189150 188 fgApplySafetyNets = applySafety;
uci1 31:b5bd3b189150 189 Reset();
uci1 31:b5bd3b189150 190 }
uci1 3:24c5f0f50bf1 191 virtual ~SnConfigFrame() {}
uci1 40:1324da35afd4 192
uci1 40:1324da35afd4 193 void ApplyConnectListenSafetyNets();
uci1 3:24c5f0f50bf1 194
uci1 8:95a325df1f6b 195 bool IsCountingPowerReadings() const { return ((fRunMode & kCountPowerBit)!=0); }
uci1 8:95a325df1f6b 196 bool IsSingleSeqRunMode() const { return ((fRunMode & kSingleSeqBit)!=0); }
uci1 8:95a325df1f6b 197 bool IsLowPowerMode() const { return fIsLowPower; }
uci1 3:24c5f0f50bf1 198 const char* GetLabel() const { return fLabel; }
uci1 3:24c5f0f50bf1 199 uint32_t GetLabelStrLen() const { return strlen(fLabel); }
uci1 3:24c5f0f50bf1 200 uint32_t GetRun() const { return fRun; }
uci1 40:1324da35afd4 201 uint16_t GetFirstSeq() const { return fFirstSeq; }
uci1 3:24c5f0f50bf1 202 uint32_t GetEvtsPerFile() const { return fEvtsPerSeq; }
uci1 3:24c5f0f50bf1 203 uint16_t GetEvtThrtlPeriodMs() const { return fEvtThrtlPeriodMs; }
uci1 18:55f1581f2ee4 204 float GetForceTrigPeriod() const { return fForceTrigPeriod; }
uci1 3:24c5f0f50bf1 205 uint16_t GetHeartbeatPeriod() const { return fHeartBeatPeriod; }
uci1 39:2f17131d22a5 206 uint16_t GetBatVoltToLowPwr() const { return fBatVoltToLowPwr; }
uci1 39:2f17131d22a5 207 uint16_t GetBatVoltFromLowPwr() const { return fBatVoltFromLowPwr; }
uci1 8:95a325df1f6b 208 uint16_t GetVoltCheckPeriod() const { return fVoltCheckPeriod; }
uci1 3:24c5f0f50bf1 209 uint32_t GetWatchdogPeriod() const { return fWatchDogPeriod; }
uci1 3:24c5f0f50bf1 210 uint16_t GetDac(const uint8_t ch, const uint8_t dn) const { return fDAC[ch][dn]; }
uci1 3:24c5f0f50bf1 211 uint8_t GetNumPlas() const { return fNumPlas; }
uci1 3:24c5f0f50bf1 212 uint16_t GetPla(const uint8_t pn) const { return fPLA[pn]; }
uci1 3:24c5f0f50bf1 213 uint8_t GetNumCardsMajLog() const { return fNumCardsMajLog; }
uci1 3:24c5f0f50bf1 214 bool IsThermTrigEnabled() const { return fEnableThermTrig!=0; }
uci1 3:24c5f0f50bf1 215 bool IsEachAmpOn() const {
uci1 3:24c5f0f50bf1 216 bool allon=true;
uci1 3:24c5f0f50bf1 217 for (uint8_t i=0; (i<kNchans) && allon; i++) {
uci1 3:24c5f0f50bf1 218 allon = (fAmpsOn & BIT(i))!=0;
uci1 3:24c5f0f50bf1 219 }
uci1 3:24c5f0f50bf1 220 return allon;
uci1 3:24c5f0f50bf1 221 }
uci1 3:24c5f0f50bf1 222 // TODO: allow check for individual amps, when they can be turned on individually
uci1 3:24c5f0f50bf1 223
uci1 8:95a325df1f6b 224 const char* GetRemoteServer() const { return fRemoteServer; }
uci1 8:95a325df1f6b 225 uint16_t GetRemotePort() const { return fRemotePort; }
uci1 8:95a325df1f6b 226 const char* GetMbedIP() const { return fMbedIP; }
uci1 8:95a325df1f6b 227 const char* GetMbedMask() const { return fMbedMask; }
uci1 8:95a325df1f6b 228 const char* GetMbedGate() const { return fMbedGate; }
uci1 8:95a325df1f6b 229 uint32_t GetCommWinPeriod() const { return fIsLowPower ? fCommWinPrdLowPwr : fCommWinPeriod; }
uci1 8:95a325df1f6b 230 uint32_t GetCommWinDuration() const { return fIsLowPower ? fCommWinDurLowPwr : fCommWinDuration; }
uci1 40:1324da35afd4 231 uint32_t GetCommWinConnectTO() const { return (static_cast<uint32_t>(fCommWinConnectTOMin) * 60u); }
uci1 40:1324da35afd4 232 uint32_t GetCommWinListenTO() const { return (static_cast<uint32_t>(fCommWinListenTOMin) * 60u); }
uci1 3:24c5f0f50bf1 233 int16_t GetCommSendData() const { return fCommSendData; }
uci1 3:24c5f0f50bf1 234
uci1 3:24c5f0f50bf1 235 bool IsSendingAllFiles() const
uci1 3:24c5f0f50bf1 236 { return (fCommSendData<0) && ((fCommSendData & kAllFiles)!=0); }
uci1 3:24c5f0f50bf1 237 bool IsObeyingTimeout() const
uci1 3:24c5f0f50bf1 238 { return (fCommSendData<0) && ((fCommSendData & kTimeout)!=0); }
uci1 3:24c5f0f50bf1 239 bool IsDeletingFiles() const
uci1 3:24c5f0f50bf1 240 { return (fCommSendData<0) && ((fCommSendData & kDelete)!=0); }
uci1 15:f2569d8e4176 241 bool IsForcingSBDdata() const
uci1 15:f2569d8e4176 242 { return (fCommSendData<0) && ((fCommSendData & kForceSBDdata)!=0); }
uci1 40:1324da35afd4 243 bool IsWaitingHndShkBeforeSendData() const
uci1 40:1324da35afd4 244 { return (fCommSendData<0) && ((fCommSendData & kHnShBefSendDat)!=0); }
uci1 3:24c5f0f50bf1 245
uci1 4:a91682e19d6b 246 uint8_t GetPowerMode() const { return fPowerMode; }
uci1 30:f869ed4bcc08 247 int GetPowPinSetting(const EPowerModeBit p, const bool isOn) const {
uci1 5:9cea89700c66 248 if (p==kCardDatTak || p==kCardComWin ||
uci1 5:9cea89700c66 249 p==kAmpsDatTak || p==kAmpsComWin) {
uci1 30:f869ed4bcc08 250 return isOn ? 0 : 1;
uci1 5:9cea89700c66 251 } else {
uci1 30:f869ed4bcc08 252 return isOn ? 1 : 0;
uci1 5:9cea89700c66 253 }
uci1 5:9cea89700c66 254 }
uci1 30:f869ed4bcc08 255 int GetPowPinSetting(const EPowerModeBit p) const {
uci1 30:f869ed4bcc08 256 // return int to correspond to what DigitalOut::operator= expects
uci1 30:f869ed4bcc08 257 return GetPowPinSetting(p, IsPoweredFor(p));
uci1 30:f869ed4bcc08 258 }
uci1 8:95a325df1f6b 259 bool IsPoweredFor(const EPowerModeBit p) const {
uci1 8:95a325df1f6b 260 return ((fPowerMode & p)!=0);
uci1 8:95a325df1f6b 261 }
uci1 8:95a325df1f6b 262
uci1 8:95a325df1f6b 263 void EnablePowerFor(const EPowerModeBit p) { fPowerMode |= p; }
uci1 8:95a325df1f6b 264 void DisablePowerFor(const EPowerModeBit p) { fPowerMode &= ~p; }
uci1 8:95a325df1f6b 265
uci1 8:95a325df1f6b 266 void ChangeToLowPower();
uci1 8:95a325df1f6b 267 void ChangeToNormPower();
uci1 3:24c5f0f50bf1 268
uci1 3:24c5f0f50bf1 269 const char* GetOutFileName(const char* dir) const;
uci1 3:24c5f0f50bf1 270
uci1 21:ce51bb0ba4a5 271 uint32_t GetTimeoutTime(const uint32_t startTime,
uci1 21:ce51bb0ba4a5 272 const uint32_t delta) const;
uci1 21:ce51bb0ba4a5 273
uci1 21:ce51bb0ba4a5 274
uci1 3:24c5f0f50bf1 275 // waveform packing info
uci1 3:24c5f0f50bf1 276 uint16_t GetWvBaseline() const { return fWvBaseline; }
uci1 3:24c5f0f50bf1 277 uint8_t GetWvLoseLSB() const { return fWvLoseLSB; }
uci1 3:24c5f0f50bf1 278 uint8_t GetWvLoseMSB() const { return fWvLoseMSB; }
uci1 3:24c5f0f50bf1 279 bool IsDatPackedFor(const EDatPackBit d) const { return (fDatPackType & d)!=0; }
uci1 3:24c5f0f50bf1 280 void GetPackParsFor(const EDatPackBit d,
uci1 3:24c5f0f50bf1 281 uint8_t& loseLSB, uint8_t& loseMSB,
uci1 3:24c5f0f50bf1 282 uint16_t& wvBase) const;
uci1 3:24c5f0f50bf1 283
uci1 3:24c5f0f50bf1 284 // i/o
uci1 40:1324da35afd4 285 static
uci1 40:1324da35afd4 286 bool IsIOversionOk(const uint8_t rv) {
uci1 40:1324da35afd4 287 return (kIOVers == rv);
uci1 40:1324da35afd4 288 }
uci1 40:1324da35afd4 289
uci1 40:1324da35afd4 290 template<class T>
uci1 40:1324da35afd4 291 static
uci1 40:1324da35afd4 292 uint8_t PeekIOversion(T& b) {
uci1 40:1324da35afd4 293 // the buffer/file/whatever 'b' must be at the start of the config frame
uci1 40:1324da35afd4 294 uint8_t Rv=0;
uci1 40:1324da35afd4 295 SnBitUtils::ReadFrom(b, Rv);
uci1 40:1324da35afd4 296 return Rv;
uci1 40:1324da35afd4 297 }
uci1 40:1324da35afd4 298
uci1 3:24c5f0f50bf1 299 template<class T>
uci1 3:24c5f0f50bf1 300 void ReadFrom(T& b) {
uci1 3:24c5f0f50bf1 301 // no check on the length of buf is done here
uci1 3:24c5f0f50bf1 302 // that should be been done already
uci1 3:24c5f0f50bf1 303 //
uci1 3:24c5f0f50bf1 304 // must match WriteTo
uci1 3:24c5f0f50bf1 305
uci1 3:24c5f0f50bf1 306 uint8_t Rv=0;
uci1 3:24c5f0f50bf1 307 b = SnBitUtils::ReadFrom(b, Rv); // i/o version
uci1 12:d472f9811262 308 #ifdef DEBUG
uci1 3:24c5f0f50bf1 309 printf("Rv=%hhu\r\n",Rv);
uci1 12:d472f9811262 310 #endif
uci1 3:24c5f0f50bf1 311 if (Rv>0) {
uci1 3:24c5f0f50bf1 312 uint32_t llen=kConfLblLen;
uci1 3:24c5f0f50bf1 313 b = SnBitUtils::ReadFrom(b, llen);
uci1 12:d472f9811262 314 #ifdef DEBUG
uci1 3:24c5f0f50bf1 315 printf("llen=%u\r\n",llen);
uci1 12:d472f9811262 316 #endif
uci1 3:24c5f0f50bf1 317 b = SnBitUtils::ReadFrom(b, fLabel, llen);
uci1 12:d472f9811262 318 #ifdef DEBUG
uci1 3:24c5f0f50bf1 319 printf("lbl=%s\r\n",fLabel);
uci1 12:d472f9811262 320 #endif
uci1 3:24c5f0f50bf1 321 b = SnBitUtils::ReadFrom(b, fConfTime);
uci1 12:d472f9811262 322 #ifdef DEBUG
uci1 3:24c5f0f50bf1 323 printf("ct=%u\r\n",fConfTime);
uci1 12:d472f9811262 324 #endif
uci1 3:24c5f0f50bf1 325 b = SnBitUtils::ReadFrom(b, fRun);
uci1 12:d472f9811262 326 #ifdef DEBUG
uci1 3:24c5f0f50bf1 327 printf("run=%u\r\n",fRun);
uci1 12:d472f9811262 328 #endif
uci1 40:1324da35afd4 329 if (Rv>7) {
uci1 40:1324da35afd4 330 b = SnBitUtils::ReadFrom(b, fFirstSeq);
uci1 40:1324da35afd4 331 } else {
uci1 40:1324da35afd4 332 uint32_t fe(0);
uci1 40:1324da35afd4 333 fFirstSeq = 0;
uci1 40:1324da35afd4 334 b = SnBitUtils::ReadFrom(b, fe);
uci1 40:1324da35afd4 335 }
uci1 12:d472f9811262 336 #ifdef DEBUG
uci1 40:1324da35afd4 337 printf("firstseq=%hu\r\n",fFirstSeq);
uci1 12:d472f9811262 338 #endif
uci1 3:24c5f0f50bf1 339 if (Rv>1) {
uci1 3:24c5f0f50bf1 340 b = SnBitUtils::ReadFrom(b, fEvtsPerSeq);
uci1 40:1324da35afd4 341 b = SnBitUtils::ReadFrom(b, fRunMode);
uci1 40:1324da35afd4 342 } else {
uci1 40:1324da35afd4 343 fEvtsPerSeq = 1000;
uci1 40:1324da35afd4 344 fRunMode = 0;
uci1 40:1324da35afd4 345 }
uci1 12:d472f9811262 346 #ifdef DEBUG
uci1 3:24c5f0f50bf1 347 printf("eps=%u\r\n",fEvtsPerSeq);
uci1 3:24c5f0f50bf1 348 printf("rm=%hhu\r\n",fRunMode);
uci1 12:d472f9811262 349 #endif
uci1 3:24c5f0f50bf1 350 b = SnBitUtils::ReadFrom(b, fStreamHiLoPlas);
uci1 12:d472f9811262 351 #ifdef DEBUG
uci1 3:24c5f0f50bf1 352 printf("shilo=%d\r\n",(int)fStreamHiLoPlas);
uci1 12:d472f9811262 353 #endif
uci1 3:24c5f0f50bf1 354 b = SnBitUtils::ReadFrom(b, fWvLoseLSB);
uci1 12:d472f9811262 355 #ifdef DEBUG
uci1 3:24c5f0f50bf1 356 printf("lsb=%hhu\r\n",fWvLoseLSB);
uci1 12:d472f9811262 357 #endif
uci1 3:24c5f0f50bf1 358 b = SnBitUtils::ReadFrom(b, fWvLoseMSB);
uci1 12:d472f9811262 359 #ifdef DEBUG
uci1 3:24c5f0f50bf1 360 printf("msb=%hhu\r\n",fWvLoseMSB);
uci1 12:d472f9811262 361 #endif
uci1 3:24c5f0f50bf1 362 b = SnBitUtils::ReadFrom(b, fWvBaseline);
uci1 12:d472f9811262 363 #ifdef DEBUG
uci1 3:24c5f0f50bf1 364 printf("bl=%hu\r\n",fWvBaseline);
uci1 12:d472f9811262 365 #endif
uci1 3:24c5f0f50bf1 366 b = SnBitUtils::ReadFrom(b, fDatPackType);
uci1 12:d472f9811262 367 #ifdef DEBUG
uci1 3:24c5f0f50bf1 368 printf("dp=%hhu\r\n",fDatPackType);
uci1 12:d472f9811262 369 #endif
uci1 3:24c5f0f50bf1 370 uint16_t* dc = &(fDAC[0][0]);
uci1 3:24c5f0f50bf1 371 for (uint16_t i=0; i<kTotDacs; i++, dc++) {
uci1 3:24c5f0f50bf1 372 b = SnBitUtils::ReadFrom(b, *dc);
uci1 12:d472f9811262 373 #ifdef DEBUG
uci1 3:24c5f0f50bf1 374 printf("dac[%hu]=%hu\r\n",i,*dc);
uci1 12:d472f9811262 375 #endif
uci1 3:24c5f0f50bf1 376 }
uci1 3:24c5f0f50bf1 377 b = SnBitUtils::ReadFrom(b, fNumPlas);
uci1 12:d472f9811262 378 #ifdef DEBUG
uci1 3:24c5f0f50bf1 379 printf("npla=%hhu\r\n",fNumPlas);
uci1 12:d472f9811262 380 #endif
uci1 3:24c5f0f50bf1 381 uint16_t* pl = &(fPLA[0]);
uci1 3:24c5f0f50bf1 382 for (uint8_t j=0; j<fNumPlas; j++, pl++) {
uci1 3:24c5f0f50bf1 383 b = SnBitUtils::ReadFrom(b, *pl);
uci1 12:d472f9811262 384 #ifdef DEBUG
uci1 3:24c5f0f50bf1 385 printf("pla[%hhu]=%hu\r\n",j,*pl);
uci1 12:d472f9811262 386 #endif
uci1 3:24c5f0f50bf1 387 }
uci1 3:24c5f0f50bf1 388 b = SnBitUtils::ReadFrom(b, fNumCardsMajLog);
uci1 12:d472f9811262 389 #ifdef DEBUG
uci1 3:24c5f0f50bf1 390 printf("mj=%hhu\r\n",fNumCardsMajLog);
uci1 12:d472f9811262 391 #endif
uci1 3:24c5f0f50bf1 392 b = SnBitUtils::ReadFrom(b, fEnableThermTrig);
uci1 12:d472f9811262 393 #ifdef DEBUG
uci1 3:24c5f0f50bf1 394 printf("thm=%d\r\n",(int)fEnableThermTrig);
uci1 12:d472f9811262 395 #endif
uci1 18:55f1581f2ee4 396 if (Rv>3) {
uci1 18:55f1581f2ee4 397 b = SnBitUtils::ReadFrom(b, fForceTrigPeriod);
uci1 18:55f1581f2ee4 398 } else {
uci1 18:55f1581f2ee4 399 uint16_t ftrg(0);
uci1 18:55f1581f2ee4 400 b = SnBitUtils::ReadFrom(b, ftrg);
uci1 18:55f1581f2ee4 401 fForceTrigPeriod = ftrg;
uci1 18:55f1581f2ee4 402 }
uci1 12:d472f9811262 403 #ifdef DEBUG
uci1 18:55f1581f2ee4 404 printf("force=%g\r\n",fForceTrigPeriod);
uci1 12:d472f9811262 405 #endif
uci1 3:24c5f0f50bf1 406 b = SnBitUtils::ReadFrom(b, fHeartBeatPeriod);
uci1 12:d472f9811262 407 #ifdef DEBUG
uci1 3:24c5f0f50bf1 408 printf("heart=%hu\r\n",fHeartBeatPeriod);
uci1 12:d472f9811262 409 #endif
uci1 3:24c5f0f50bf1 410 b = SnBitUtils::ReadFrom(b, fAmpsOn);
uci1 12:d472f9811262 411 #ifdef DEBUG
uci1 3:24c5f0f50bf1 412 printf("amps=%hhu\r\n",fAmpsOn);
uci1 12:d472f9811262 413 #endif
uci1 3:24c5f0f50bf1 414 b = SnBitUtils::ReadFrom(b, fEvtThrtlPeriodMs);
uci1 12:d472f9811262 415 #ifdef DEBUG
uci1 3:24c5f0f50bf1 416 printf("throt=%hu\r\n",fEvtThrtlPeriodMs);
uci1 12:d472f9811262 417 #endif
uci1 3:24c5f0f50bf1 418 b = SnBitUtils::ReadFrom(b, fPowerMode);
uci1 12:d472f9811262 419 #ifdef DEBUG
uci1 3:24c5f0f50bf1 420 printf("pow=%hhu\r\n",fPowerMode);
uci1 12:d472f9811262 421 #endif
uci1 39:2f17131d22a5 422 if (Rv<6) {
uci1 39:2f17131d22a5 423 b = SnBitUtils::ReadFrom(b, fBatVoltToLowPwr);
uci1 40:1324da35afd4 424 fBatVoltFromLowPwr = 1.1*fBatVoltToLowPwr;
uci1 39:2f17131d22a5 425 } else {
uci1 39:2f17131d22a5 426 b = SnBitUtils::ReadFrom(b, fBatVoltToLowPwr);
uci1 39:2f17131d22a5 427 b = SnBitUtils::ReadFrom(b, fBatVoltFromLowPwr);
uci1 39:2f17131d22a5 428 }
uci1 39:2f17131d22a5 429 #ifdef DEBUG
uci1 40:1324da35afd4 430 printf("batlow(to,from)=(%hu,%hu)\r\n",fBatVoltToLowPwr,fBatVoltFromLowPwr);
uci1 12:d472f9811262 431 #endif
uci1 8:95a325df1f6b 432 if (Rv>2) {
uci1 8:95a325df1f6b 433 b = SnBitUtils::ReadFrom(b, fVoltCheckPeriod);
uci1 40:1324da35afd4 434 } else {
uci1 40:1324da35afd4 435 fVoltCheckPeriod = 600u;
uci1 40:1324da35afd4 436 }
uci1 12:d472f9811262 437 #ifdef DEBUG
uci1 8:95a325df1f6b 438 printf("vltchk=%hu\r\n",fVoltCheckPeriod);
uci1 12:d472f9811262 439 #endif
uci1 3:24c5f0f50bf1 440 b = SnBitUtils::ReadFrom(b, fCommWinPeriod);
uci1 12:d472f9811262 441 #ifdef DEBUG
uci1 3:24c5f0f50bf1 442 printf("cmper=%u\r\n",fCommWinPeriod);
uci1 12:d472f9811262 443 #endif
uci1 3:24c5f0f50bf1 444 b = SnBitUtils::ReadFrom(b, fCommWinDuration);
uci1 12:d472f9811262 445 #ifdef DEBUG
uci1 3:24c5f0f50bf1 446 printf("cmdur=%u\r\n",fCommWinDuration);
uci1 12:d472f9811262 447 #endif
uci1 3:24c5f0f50bf1 448 b = SnBitUtils::ReadFrom(b, fCommSendData);
uci1 12:d472f9811262 449 #ifdef DEBUG
uci1 3:24c5f0f50bf1 450 printf("send=%d\r\n",fCommSendData);
uci1 12:d472f9811262 451 #endif
uci1 3:24c5f0f50bf1 452 b = SnBitUtils::ReadFrom(b, fCommWinPrdLowPwr);
uci1 12:d472f9811262 453 #ifdef DEBUG
uci1 3:24c5f0f50bf1 454 printf("cmperlp=%u\r\n",fCommWinPrdLowPwr);
uci1 12:d472f9811262 455 #endif
uci1 3:24c5f0f50bf1 456 b = SnBitUtils::ReadFrom(b, fCommWinDurLowPwr);
uci1 12:d472f9811262 457 #ifdef DEBUG
uci1 3:24c5f0f50bf1 458 printf("cmdurlp=%u\r\n",fCommWinDurLowPwr);
uci1 12:d472f9811262 459 #endif
uci1 40:1324da35afd4 460 if (Rv>6) {
uci1 40:1324da35afd4 461 b = SnBitUtils::ReadFrom(b, fCommWinConnectTOMin);
uci1 40:1324da35afd4 462 b = SnBitUtils::ReadFrom(b, fCommWinListenTOMin);
uci1 40:1324da35afd4 463 } else {
uci1 40:1324da35afd4 464 fCommWinConnectTOMin = fCommWinListenTOMin = 3u;
uci1 40:1324da35afd4 465 }
uci1 40:1324da35afd4 466 #ifdef DEBUG
uci1 40:1324da35afd4 467 printf("connectTO=%hhu, listenTO=%hhu\r\n",
uci1 40:1324da35afd4 468 fCommWinConnectTOMin, fCommWinListenTOMin);
uci1 40:1324da35afd4 469 #endif
uci1 8:95a325df1f6b 470 if (Rv>2) {
uci1 8:95a325df1f6b 471 b = SnBitUtils::ReadFrom(b, fRemoteServer, kIPLen);
uci1 28:484943132bb0 472 if (strncmp(fRemoteServer, kDefIPflag,kIPLen)==0) {
uci1 28:484943132bb0 473 SetDefaultRemoteServ();
uci1 28:484943132bb0 474 }
uci1 12:d472f9811262 475 #ifdef DEBUG
uci1 8:95a325df1f6b 476 printf("rserv=%s\r\n",fRemoteServer);
uci1 12:d472f9811262 477 #endif
uci1 8:95a325df1f6b 478 b = SnBitUtils::ReadFrom(b, fRemotePort);
uci1 28:484943132bb0 479 if (fRemotePort==0) {
uci1 28:484943132bb0 480 SetDefaultRemotePort();
uci1 28:484943132bb0 481 }
uci1 12:d472f9811262 482 #ifdef DEBUG
uci1 8:95a325df1f6b 483 printf("rport=%hu\r\n",fRemotePort);
uci1 12:d472f9811262 484 #endif
uci1 8:95a325df1f6b 485 b = SnBitUtils::ReadFrom(b, fMbedIP, kIPLen);
uci1 28:484943132bb0 486 if (strncmp(fMbedIP, kDefIPflag,kIPLen)==0) {
uci1 28:484943132bb0 487 SetDefaultMbedIP();
uci1 28:484943132bb0 488 }
uci1 12:d472f9811262 489 #ifdef DEBUG
uci1 8:95a325df1f6b 490 printf("mbedip=%s\r\n",fMbedIP);
uci1 12:d472f9811262 491 #endif
uci1 8:95a325df1f6b 492 b = SnBitUtils::ReadFrom(b, fMbedMask, kIPLen);
uci1 28:484943132bb0 493 if (strncmp(fMbedMask, kDefIPflag,kIPLen)==0) {
uci1 28:484943132bb0 494 SetDefaultMaskIP();
uci1 28:484943132bb0 495 }
uci1 12:d472f9811262 496 #ifdef DEBUG
uci1 8:95a325df1f6b 497 printf("mbedmask=%s\r\n",fMbedMask);
uci1 12:d472f9811262 498 #endif
uci1 8:95a325df1f6b 499 b = SnBitUtils::ReadFrom(b, fMbedGate, kIPLen);
uci1 28:484943132bb0 500 if (strncmp(fMbedGate, kDefIPflag,kIPLen)==0) {
uci1 28:484943132bb0 501 SetDefaultGateIP();
uci1 28:484943132bb0 502 }
uci1 12:d472f9811262 503 #ifdef DEBUG
uci1 8:95a325df1f6b 504 printf("mbedgate=%s\r\n",fMbedGate);
uci1 12:d472f9811262 505 #endif
uci1 40:1324da35afd4 506 } else {
uci1 40:1324da35afd4 507 SetDefaultIPs();
uci1 8:95a325df1f6b 508 }
uci1 3:24c5f0f50bf1 509 b = SnBitUtils::ReadFrom(b, fWatchDogPeriod);
uci1 12:d472f9811262 510 #ifdef DEBUG
uci1 3:24c5f0f50bf1 511 printf("watch=%u\r\n",fWatchDogPeriod);
uci1 12:d472f9811262 512 #endif
uci1 3:24c5f0f50bf1 513 if (fStreamHiLoPlas!=0) {
uci1 3:24c5f0f50bf1 514 uint16_t hi, lo;
uci1 3:24c5f0f50bf1 515 for (uint8_t j=0; j<fNumPlas; j++) {
uci1 3:24c5f0f50bf1 516 b = SnBitUtils::ReadFrom(b, hi);
uci1 12:d472f9811262 517 #ifdef DEBUG
uci1 3:24c5f0f50bf1 518 printf("hi=%hu\r\n",hi);
uci1 12:d472f9811262 519 #endif
uci1 3:24c5f0f50bf1 520 b = SnBitUtils::ReadFrom(b, lo);
uci1 12:d472f9811262 521 #ifdef DEBUG
uci1 3:24c5f0f50bf1 522 printf("lo=%hu\r\n",lo);
uci1 12:d472f9811262 523 #endif
uci1 3:24c5f0f50bf1 524 // don't save these
uci1 3:24c5f0f50bf1 525 }
uci1 3:24c5f0f50bf1 526 }
uci1 3:24c5f0f50bf1 527 }
uci1 28:484943132bb0 528
uci1 31:b5bd3b189150 529 if (fgApplySafetyNets) {
uci1 31:b5bd3b189150 530 ApplySafetyNets();
uci1 31:b5bd3b189150 531 }
uci1 28:484943132bb0 532
uci1 12:d472f9811262 533 #ifdef DEBUG
uci1 3:24c5f0f50bf1 534 printf("read from done\r\n");
uci1 12:d472f9811262 535 #endif
uci1 3:24c5f0f50bf1 536 }
uci1 3:24c5f0f50bf1 537
uci1 3:24c5f0f50bf1 538 template <class T>
uci1 3:24c5f0f50bf1 539 void WriteTo(T& b) const {
uci1 3:24c5f0f50bf1 540 // no check on the length of the buf is done here
uci1 3:24c5f0f50bf1 541 // that should be done already
uci1 3:24c5f0f50bf1 542 //
uci1 3:24c5f0f50bf1 543 // must match ReadFromBuf
uci1 3:24c5f0f50bf1 544 //
uci1 3:24c5f0f50bf1 545 // intentionally not writing mac address here, so we don't have to read it in
uci1 3:24c5f0f50bf1 546
uci1 3:24c5f0f50bf1 547 b = SnBitUtils::WriteTo(b, kIOVers); // i/o version
uci1 40:1324da35afd4 548 // account for the ending \0
uci1 40:1324da35afd4 549 uint32_t llen = strlen(fLabel);
uci1 40:1324da35afd4 550 static const uint32_t maxllen = kConfLblLen-1;
uci1 40:1324da35afd4 551 if (llen > maxllen) {
uci1 40:1324da35afd4 552 llen = maxllen;
uci1 40:1324da35afd4 553 }
uci1 40:1324da35afd4 554 b = SnBitUtils::WriteTo(b, llen+1); // strlen + \0
uci1 3:24c5f0f50bf1 555 b = SnBitUtils::WriteTo(b, fLabel, llen);
uci1 39:2f17131d22a5 556 b = SnBitUtils::WriteTo(b, char('\0'));
uci1 3:24c5f0f50bf1 557 b = SnBitUtils::WriteTo(b, fConfTime);
uci1 3:24c5f0f50bf1 558 b = SnBitUtils::WriteTo(b, fRun);
uci1 40:1324da35afd4 559 b = SnBitUtils::WriteTo(b, fFirstSeq);
uci1 3:24c5f0f50bf1 560 b = SnBitUtils::WriteTo(b, fEvtsPerSeq);
uci1 3:24c5f0f50bf1 561 b = SnBitUtils::WriteTo(b, fRunMode);
uci1 3:24c5f0f50bf1 562 b = SnBitUtils::WriteTo(b, fStreamHiLoPlas);
uci1 3:24c5f0f50bf1 563 b = SnBitUtils::WriteTo(b, fWvLoseLSB);
uci1 3:24c5f0f50bf1 564 b = SnBitUtils::WriteTo(b, fWvLoseMSB);
uci1 3:24c5f0f50bf1 565 b = SnBitUtils::WriteTo(b, fWvBaseline);
uci1 3:24c5f0f50bf1 566 b = SnBitUtils::WriteTo(b, fDatPackType);
uci1 3:24c5f0f50bf1 567 const uint16_t* dc = &(fDAC[0][0]);
uci1 3:24c5f0f50bf1 568 for (uint16_t i=0; i<kTotDacs; i++, dc++) {
uci1 3:24c5f0f50bf1 569 b = SnBitUtils::WriteTo(b, *dc);
uci1 3:24c5f0f50bf1 570 }
uci1 3:24c5f0f50bf1 571 b = SnBitUtils::WriteTo(b, fNumPlas);
uci1 3:24c5f0f50bf1 572 const uint16_t* pl = &(fPLA[0]);
uci1 3:24c5f0f50bf1 573 for (uint8_t j=0; j<fNumPlas; j++, pl++) {
uci1 3:24c5f0f50bf1 574 b = SnBitUtils::WriteTo(b, *pl);
uci1 3:24c5f0f50bf1 575 }
uci1 3:24c5f0f50bf1 576 b = SnBitUtils::WriteTo(b, fNumCardsMajLog);
uci1 3:24c5f0f50bf1 577 b = SnBitUtils::WriteTo(b, fEnableThermTrig);
uci1 3:24c5f0f50bf1 578 b = SnBitUtils::WriteTo(b, fForceTrigPeriod);
uci1 3:24c5f0f50bf1 579 b = SnBitUtils::WriteTo(b, fHeartBeatPeriod);
uci1 3:24c5f0f50bf1 580 b = SnBitUtils::WriteTo(b, fAmpsOn);
uci1 3:24c5f0f50bf1 581 b = SnBitUtils::WriteTo(b, fEvtThrtlPeriodMs);
uci1 3:24c5f0f50bf1 582 b = SnBitUtils::WriteTo(b, fPowerMode);
uci1 39:2f17131d22a5 583 b = SnBitUtils::WriteTo(b, fBatVoltToLowPwr);
uci1 39:2f17131d22a5 584 b = SnBitUtils::WriteTo(b, fBatVoltFromLowPwr);
uci1 8:95a325df1f6b 585 b = SnBitUtils::WriteTo(b, fVoltCheckPeriod);
uci1 3:24c5f0f50bf1 586 b = SnBitUtils::WriteTo(b, fCommWinPeriod);
uci1 3:24c5f0f50bf1 587 b = SnBitUtils::WriteTo(b, fCommWinDuration);
uci1 3:24c5f0f50bf1 588 b = SnBitUtils::WriteTo(b, fCommSendData);
uci1 3:24c5f0f50bf1 589 b = SnBitUtils::WriteTo(b, fCommWinPrdLowPwr);
uci1 3:24c5f0f50bf1 590 b = SnBitUtils::WriteTo(b, fCommWinDurLowPwr);
uci1 40:1324da35afd4 591 b = SnBitUtils::WriteTo(b, fCommWinConnectTOMin);
uci1 40:1324da35afd4 592 b = SnBitUtils::WriteTo(b, fCommWinListenTOMin);
uci1 8:95a325df1f6b 593 b = SnBitUtils::WriteTo(b, fRemoteServer, kIPLen);
uci1 8:95a325df1f6b 594 b = SnBitUtils::WriteTo(b, fRemotePort);
uci1 8:95a325df1f6b 595 b = SnBitUtils::WriteTo(b, fMbedIP, kIPLen);
uci1 8:95a325df1f6b 596 b = SnBitUtils::WriteTo(b, fMbedMask, kIPLen);
uci1 8:95a325df1f6b 597 b = SnBitUtils::WriteTo(b, fMbedGate, kIPLen);
uci1 3:24c5f0f50bf1 598 b = SnBitUtils::WriteTo(b, fWatchDogPeriod);
uci1 3:24c5f0f50bf1 599 if (fStreamHiLoPlas!=0) {
uci1 3:24c5f0f50bf1 600 pl = fPLA;
uci1 3:24c5f0f50bf1 601 uint16_t hi, lo;
uci1 3:24c5f0f50bf1 602 for (uint8_t j=0; j<fNumPlas; j++, pl++) {
uci1 3:24c5f0f50bf1 603 GetHiLoPlas(*pl, hi, lo);
uci1 3:24c5f0f50bf1 604 b = SnBitUtils::WriteTo(b, hi);
uci1 3:24c5f0f50bf1 605 b = SnBitUtils::WriteTo(b, lo);
uci1 3:24c5f0f50bf1 606 }
uci1 3:24c5f0f50bf1 607 }
uci1 3:24c5f0f50bf1 608 }
uci1 3:24c5f0f50bf1 609
uci1 3:24c5f0f50bf1 610 bool ReadFromFile(const char* cfile);
uci1 3:24c5f0f50bf1 611 bool WriteToFile(const char* cfile) const;
uci1 3:24c5f0f50bf1 612
uci1 3:24c5f0f50bf1 613 void Reset() {
uci1 3:24c5f0f50bf1 614 memset(fLabel, 0, sizeof(char)*kConfLblLen);
uci1 40:1324da35afd4 615 SetHardDefaults();
uci1 3:24c5f0f50bf1 616 if (ReadFromFile(kDefConfFile)==false) {
uci1 3:24c5f0f50bf1 617 // couldn't get default. use hardcoded version.
uci1 3:24c5f0f50bf1 618 SetHardDefaults();
uci1 3:24c5f0f50bf1 619 }
uci1 16:744ce85aede2 620 #ifdef DEBUG
uci1 16:744ce85aede2 621 printf("config reset to %s\r\n",fLabel);
uci1 16:744ce85aede2 622 #endif
uci1 3:24c5f0f50bf1 623 }
uci1 40:1324da35afd4 624
uci1 8:95a325df1f6b 625 uint32_t SizeOf(const uint8_t rv) const {
uci1 3:24c5f0f50bf1 626 // returns the num of bytes needed to stream this object
uci1 3:24c5f0f50bf1 627 // = size of member vars + 1 for i/o version + extra PLA strings (maybe)
uci1 3:24c5f0f50bf1 628 // + length of label string
uci1 8:95a325df1f6b 629 return SizeOf(rv, fStreamHiLoPlas!=0, fNumPlas, strlen(fLabel));
uci1 3:24c5f0f50bf1 630 }
uci1 40:1324da35afd4 631
uci1 3:24c5f0f50bf1 632 static void SetMacAddress();
uci1 3:24c5f0f50bf1 633 static uint64_t GetMacAddress() {
uci1 3:24c5f0f50bf1 634 if (fgMacAdr==0) {
uci1 3:24c5f0f50bf1 635 SetMacAddress();
uci1 3:24c5f0f50bf1 636 }
uci1 3:24c5f0f50bf1 637 return fgMacAdr;
uci1 3:24c5f0f50bf1 638 }
uci1 3:24c5f0f50bf1 639
uci1 3:24c5f0f50bf1 640 static uint32_t GetLabelMaxLen() { return kConfLblLen; }
uci1 3:24c5f0f50bf1 641
uci1 3:24c5f0f50bf1 642 static void GetHiLoPlas(const uint16_t pla,
uci1 3:24c5f0f50bf1 643 uint16_t& hiPla,
uci1 3:24c5f0f50bf1 644 uint16_t& loPla,
uci1 3:24c5f0f50bf1 645 const bool r2l=false);
uci1 3:24c5f0f50bf1 646 };
uci1 3:24c5f0f50bf1 647
uci1 3:24c5f0f50bf1 648 #endif // SN_SnConfigFrame