Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Sun Feb 22 20:42:44 2015 +0000
Revision:
76:f8383f0292c2
Parent:
67:ec999336fcd1
Child:
84:80b15993944e
Stn14 mac adr. Allow SD to be ignored. Only access run/seq list if going to send the list.

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