Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Thu Oct 30 06:42:17 2014 +0000
Revision:
56:0bba0ef15697
Parent:
40:1324da35afd4
Child:
59:21128cc24b04
update ext libs, add tempr, allow SST/ATWD, improve handshaking, run/seq list, req seq range, allow SBD only in low pwr, all pins start off, can collect data to ram w/o SD card, add parameters to status update

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