Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Tue Feb 03 00:04:30 2015 +0000
Revision:
67:ec999336fcd1
Parent:
59:21128cc24b04
Child:
76:f8383f0292c2
STN20 Hardcoded (mac adr and config label). Power off periphs before powering anything on. do NOT use interface chip for mac adr or files (except reprogramming)

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