Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Mon Oct 24 18:54:21 2016 +0000
Revision:
117:fd6798ba2e26
Parent:
116:8099b754fbb4
Child:
119:b3d7699d0eb0
Rev 17.  Updated SnConfigFrame.cpp to add default IP addresses for new stations to be deployed for 2016-2017 season.

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 84:80b15993944e 18 static const uint8_t kConfLblLenNoStrTerm=63; // length of configuration label char array without the terminating '\0' (must not change!! used in i/o sizes)
uci1 84:80b15993944e 19 static const uint8_t kConfLblLen=kConfLblLenNoStrTerm+1; // length of configuration label char array (63+'\0') (must not change!! used in i/o sizes)
uci1 84:80b15993944e 20 static const uint8_t kIPLen=16; // length of IP string (includes \0). matches MBED's Socket class (so no ipv6) (must not change!! used in i/o sizes)
uci1 3:24c5f0f50bf1 21
uci1 67:ec999336fcd1 22 #ifdef USE_INTERFACE_CHIP
uci1 3:24c5f0f50bf1 23 static const char* const kDefConfFile; // default configuration file
uci1 59:21128cc24b04 24 static const char* const kDefRemIpFilen;
uci1 59:21128cc24b04 25 static const char* const kDefRemPortFilen;
uci1 59:21128cc24b04 26 static const char* const kDefMbedIPFilen;
uci1 59:21128cc24b04 27 static const char* const kDefMbedMaskFilen;
uci1 59:21128cc24b04 28 static const char* const kDefMbedGateFilen;
uci1 67:ec999336fcd1 29 #endif
uci1 67:ec999336fcd1 30
uci1 28:484943132bb0 31 static const char* const kDefIPflag; // flag to use IP default
uci1 84:80b15993944e 32 static const uint32_t kDefIPvalue; // value to indicate use of default IP
uci1 3:24c5f0f50bf1 33
uci1 56:0bba0ef15697 34 // ATWD 4channel configs
uci1 8:95a325df1f6b 35 static const uint32_t kMaxSizeOfV1 =
uci1 8:95a325df1f6b 36 + (9u*sizeof(uint32_t)) + (6u*sizeof(uint16_t))
uci1 56:0bba0ef15697 37 + (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 38 + (kTotDacsAtwd4ch*sizeof(uint16_t))
uci1 3:24c5f0f50bf1 39 + (kConfLblLen*sizeof(uint8_t));
uci1 8:95a325df1f6b 40 static const uint32_t kMaxSizeOfV2 =
uci1 8:95a325df1f6b 41 kMaxSizeOfV1 + sizeof(uint32_t) + sizeof(uint8_t);
uci1 8:95a325df1f6b 42 static const uint32_t kMaxSizeOfV3 =
uci1 8:95a325df1f6b 43 kMaxSizeOfV2 + (2u*sizeof(uint16_t)) + (4u*kIPLen*sizeof(char));
uci1 40:1324da35afd4 44 static const uint32_t kMaxSizeOfV4 = kMaxSizeOfV3 + (sizeof(float)-sizeof(uint16_t)); // forced trig per to float
uci1 39:2f17131d22a5 45 static const uint32_t kMaxSizeOfV5 = kMaxSizeOfV4;
uci1 40:1324da35afd4 46 static const uint32_t kMaxSizeOfV6 = kMaxSizeOfV5 + sizeof(uint16_t); // To/From Low Power
uci1 40:1324da35afd4 47 static const uint32_t kMaxSizeOfV7 = kMaxSizeOfV6 + (2u*sizeof(uint8_t)); // add ConnTOmins, ListenTOmins
uci1 40:1324da35afd4 48 static const uint32_t kMaxSizeOfV8 = kMaxSizeOfV7 - sizeof(uint32_t) + sizeof(uint16_t); // FirstEvt -> FirstSeq
uci1 56:0bba0ef15697 49
uci1 56:0bba0ef15697 50 // SST 4channel configs
uci1 56:0bba0ef15697 51 static const uint32_t kMaxSizeOfV9 = kMaxSizeOfV8
uci1 56:0bba0ef15697 52 - (3u*kNplasV1*sizeof(uint16_t)) // no patterns in SST
uci1 56:0bba0ef15697 53 - (kTotDacsAtwd4ch*sizeof(uint16_t))
uci1 56:0bba0ef15697 54 + (kTotDacsSst4ch*sizeof(uint16_t)) // switch to number of SST dacs
uci1 56:0bba0ef15697 55 - sizeof(uint8_t) // no stream hi/lo pla flag
uci1 56:0bba0ef15697 56 - sizeof(uint8_t); // no num plas variable
uci1 56:0bba0ef15697 57 static const uint32_t kMaxSizeOfV10 = kMaxSizeOfV9 + sizeof(int8_t); // add fTempCheckPeriod
uci1 84:80b15993944e 58
uci1 84:80b15993944e 59 // ATWD - expanding upon V8 (previous ATWD config)
uci1 84:80b15993944e 60 static const uint32_t kMaxSizeOfV11 = kMaxSizeOfV8
uci1 84:80b15993944e 61 - sizeof(uint32_t) // label length (now always 64 bytes written)
uci1 84:80b15993944e 62 - (sizeof(uint32_t) - sizeof(uint16_t)) // fEvtsPerSeq from uint32_t to uint16_t
uci1 84:80b15993944e 63 - sizeof(uint8_t) // remove stream hi/lo pla's (always false now)
uci1 84:80b15993944e 64 - sizeof(uint8_t) // remove pack data (always done for all peripherals)
uci1 84:80b15993944e 65 - sizeof(uint8_t) // remove amps on completely
uci1 84:80b15993944e 66 - (4u*kIPLen) + (4u*sizeof(uint32_t)) // change IP from strings to numbers
uci1 84:80b15993944e 67 - (2u*kNplasV1*sizeof(uint16_t)) // no streaming of hi/lo patterns
uci1 84:80b15993944e 68 + sizeof(uint8_t) // add single freq ratio L1 trig parameter
uci1 84:80b15993944e 69 + sizeof(uint8_t) // L1 scaledown
uci1 84:80b15993944e 70 + sizeof(uint16_t) - sizeof(uint8_t) // change fEnableTherm from 8 bit to 16 bit to match trigger bit word in event
uci1 84:80b15993944e 71 + (2u*sizeof(uint8_t)) // connect and listen TOs for Irid & Afar
uci1 84:80b15993944e 72 + sizeof(uint16_t) - sizeof(uint8_t); // run mode from 8 to 16 bit integer
uci1 84:80b15993944e 73
uci1 84:80b15993944e 74 // SST - expanding upon V10 (previous SST config)
uci1 84:80b15993944e 75 static const uint32_t kMaxSizeOfV12 = kMaxSizeOfV10
uci1 84:80b15993944e 76 - sizeof(uint32_t) // label length (now always 64 bytes written)
uci1 84:80b15993944e 77 - (sizeof(uint32_t) - sizeof(uint16_t)) // fEvtsPerSeq from uint32_t to uint16_t
uci1 84:80b15993944e 78 - sizeof(uint8_t) // remove pack data (always done for all peripherals)
uci1 84:80b15993944e 79 - sizeof(uint8_t) // remove amps on completely
uci1 84:80b15993944e 80 - (4u*kIPLen) + (4u*sizeof(uint32_t)) // change IP from strings to numbers
uci1 84:80b15993944e 81 + sizeof(uint8_t) // add single freq ratio L1 trig parameter
uci1 84:80b15993944e 82 + sizeof(uint8_t) // L1 scaledown
uci1 84:80b15993944e 83 + sizeof(uint16_t) - sizeof(uint8_t) // change fEnableTherm from 8 bit to 16 bit to match trigger bit word in event
uci1 84:80b15993944e 84 + (2u*sizeof(uint8_t)) // connect and listen TOs for Irid & Afar
uci1 84:80b15993944e 85 + sizeof(uint16_t) - sizeof(uint8_t); // run mode from 8 to 16 bit integer
uci1 114:554fa3a956b4 86 static const uint32_t kMaxSizeOfV13 = kMaxSizeOfV12; // same as V12 (just signifies SST4CH_1GHz)
uci1 116:8099b754fbb4 87 static const uint32_t kMaxSizeOfV14 = kMaxSizeOfV12; // same as V12 (just signifies SST4CH512)
uci1 116:8099b754fbb4 88 static const uint32_t kMaxSizeOfV15 = kMaxSizeOfV12; // same as V12 (just signifies SST4CH512_1GHz)
uci1 116:8099b754fbb4 89
uci1 56:0bba0ef15697 90 static const uint32_t kMaxSizeOf = kMaxSizeOfV7; // should be the biggest one
uci1 3:24c5f0f50bf1 91
uci1 3:24c5f0f50bf1 92 enum EDatPackBit {
uci1 3:24c5f0f50bf1 93 kSDcard = BIT(0),
uci1 3:24c5f0f50bf1 94 kIrid = BIT(1),
uci1 3:24c5f0f50bf1 95 kAfar = BIT(2),
uci1 3:24c5f0f50bf1 96 kUSB = BIT(3)
uci1 3:24c5f0f50bf1 97 };
uci1 84:80b15993944e 98 static const uint8_t kNumDatStreams = 4; // ** note: need to change manually
uci1 3:24c5f0f50bf1 99
uci1 3:24c5f0f50bf1 100 enum ESendDataBit {
uci1 3:24c5f0f50bf1 101 // can't use BIT(0)! (-0 = 0 => send nothing)
uci1 84:80b15993944e 102 kAllFiles = BIT(1), // if bit=0 => send most recent file
uci1 84:80b15993944e 103 kTimeout = BIT(2), // if bit=0 => ignore timeout
uci1 84:80b15993944e 104 kDelete = BIT(3), // if bit=0 => do not delete sent files
uci1 84:80b15993944e 105 kForceSBDdata = BIT(4), // if bit=0 => do not send data over SBD
uci1 84:80b15993944e 106 kHnShBefSendDat = BIT(5), // if bit=0 => do not wait for a handshake after GetConfig before calling SendData
uci1 84:80b15993944e 107 kSendRunSeqList = BIT(6), // if bit=1 and kAllFiles bit=0, send all files in the run/seq list (instead of most recent file)
uci1 84:80b15993944e 108 kStatSendConf = BIT(7), // if bit=1, send a config with the status update data
uci1 84:80b15993944e 109 kStatSendTrgTim = BIT(8), // if bit=1, send trigger start/stop times with the status update data
uci1 84:80b15993944e 110 kStatSendPwrDat = BIT(9), // if bit=1, send the last power frame recorded in data taking mode with the status update
uci1 84:80b15993944e 111 kStatSendEvent = BIT(10), // if bit=1, send the last event frame recorded in data taking mode with the status update
uci1 84:80b15993944e 112 kStatSendHtbt = BIT(11), // if bit=1, send the last heartbeat frame recorded in data taking mode with the status update
uci1 84:80b15993944e 113 kStatSendTmpDat = BIT(12), // if bit=1, send the last temperature frame recorded in data taking mode with the status update
uci1 39:2f17131d22a5 114 kUseBits = static_cast<int16_t>(-BIT(14)) // useful to initialize fCommSendData as a bit word
uci1 3:24c5f0f50bf1 115 };
uci1 3:24c5f0f50bf1 116
uci1 4:a91682e19d6b 117 enum EPowerModeBit {
uci1 4:a91682e19d6b 118 kAmpsDatTak = BIT(0),
uci1 4:a91682e19d6b 119 kCardDatTak = BIT(1),
uci1 4:a91682e19d6b 120 kIridDatTak = BIT(2),
uci1 4:a91682e19d6b 121 kAfarDatTak = BIT(3),
uci1 4:a91682e19d6b 122 kAmpsComWin = BIT(4),
uci1 4:a91682e19d6b 123 kCardComWin = BIT(5),
uci1 4:a91682e19d6b 124 kIridComWin = BIT(6),
uci1 4:a91682e19d6b 125 kAfarComWin = BIT(7)
uci1 4:a91682e19d6b 126 };
uci1 4:a91682e19d6b 127
uci1 3:24c5f0f50bf1 128 enum ERunMode {
uci1 8:95a325df1f6b 129 kSingleSeqBit = BIT(0), // if 0, infinite sequences
uci1 8:95a325df1f6b 130 kCountPowerBit = BIT(1), // if 0, count events
uci1 56:0bba0ef15697 131 kDualThreshBit = BIT(2), // if 0, single sided thresholds on SST
uci1 56:0bba0ef15697 132 kDiffTrigBit = BIT(3), // if 0, send result of each comparator on SST
uci1 56:0bba0ef15697 133 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 134 kRSListOneCW = BIT(5), // if 0, only clear run/seq list after files sent from it
uci1 84:80b15993944e 135 kIgnoreSDcard = BIT(6), // if 0, read/write data to SD card as normal. if 1, function as though no SD card is present
uci1 84:80b15993944e 136 kComPwrSimple = BIT(7), // if 0, comm periphs powered as needed during comm win. if 1, power adjusted once at start/finish of comm win
uci1 116:8099b754fbb4 137 kCommEachEvent = BIT(8), // if 0, comm windows only after comm period of seconds. if 1, comm winodows also after each event that qualifies for saving to SD card
uci1 116:8099b754fbb4 138 kSkipTrgStartReset = BIT(9) // if 0, the digitizer (SST) is reset when the mbed starts waiting for triggers. if 0, no reset occurs, which can cause an immediate readout if the chip had triggered before the mbed was ready
uci1 56:0bba0ef15697 139 };
uci1 3:24c5f0f50bf1 140
uci1 3:24c5f0f50bf1 141 // i/o version
uci1 3:24c5f0f50bf1 142 static const uint8_t kIOVers; // MUST BE INCREASED if any member var changes (==> also if kNchans, etc. change!)
uci1 3:24c5f0f50bf1 143
uci1 3:24c5f0f50bf1 144 private:
uci1 3:24c5f0f50bf1 145 // !!
uci1 3:24c5f0f50bf1 146 // !! If any member variables change, update: SizeOf function and kIOVers value! (also if kNchans, etc. change!)
uci1 3:24c5f0f50bf1 147 // !!
uci1 3:24c5f0f50bf1 148
uci1 3:24c5f0f50bf1 149 // mbed mac address
uci1 3:24c5f0f50bf1 150 static uint64_t fgMacAdr; // mbed mac address
uci1 3:24c5f0f50bf1 151 // conf header
uci1 3:24c5f0f50bf1 152 char fLabel[kConfLblLen]; // configuration label
uci1 3:24c5f0f50bf1 153 uint32_t fConfTime; // cpu config time
uci1 3:24c5f0f50bf1 154 uint32_t fRun; // run number
uci1 40:1324da35afd4 155 uint16_t fFirstSeq; // starting sequence number
uci1 84:80b15993944e 156 uint16_t fEvtsPerSeq; // number of events per file
uci1 84:80b15993944e 157 uint16_t fRunMode; // mode of running (see ERunMode) -- changed from uint8 to uint16 with V11+
uci1 56:0bba0ef15697 158 #if CHIPBOARD==ATWD4CH
uci1 84:80b15993944e 159 // in newer versions (11+), this is always false
uci1 3:24c5f0f50bf1 160 uint8_t fStreamHiLoPlas; // (1byte bool) if true, add the separated hi/lo thresh PLA patterns to the i/o
uci1 56:0bba0ef15697 161 #endif
uci1 3:24c5f0f50bf1 162 // data packing
uci1 3:24c5f0f50bf1 163 uint8_t fWvLoseLSB; // number of least significant bits to lose when packing waveform data
uci1 3:24c5f0f50bf1 164 uint8_t fWvLoseMSB; // number of most significant bits to lose when packing waveform data
uci1 3:24c5f0f50bf1 165 uint16_t fWvBaseline; // global baseline to use when packing data (useful to reduce clipping on the high end)
uci1 84:80b15993944e 166 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). starting with IOVers 11+, this is always all 1's and is not settable
uci1 3:24c5f0f50bf1 167 // trigger setup
uci1 56:0bba0ef15697 168 uint16_t fDAC[kNchans][kNchanDacs]; //[card id][dac id] values should be 0-4095 here (not checked tho)
uci1 56:0bba0ef15697 169 #if CHIPBOARD==ATWD4CH
uci1 3:24c5f0f50bf1 170 uint8_t fNumPlas; // number of patterns to use. must be <= kNplas.
uci1 3:24c5f0f50bf1 171 uint16_t fPLA[kNplas]; //[pattern id] (same for each card)
uci1 56:0bba0ef15697 172 #endif
uci1 3:24c5f0f50bf1 173 uint8_t fNumCardsMajLog; // number of cards participating in the MajLogic trigger (1 to 4)
uci1 84:80b15993944e 174 uint16_t fEnableThermTrig; // whether or not to allow thermal triggers. as of vers 11+, now a bit word that can enable L1 triggers in addition to in-chip triggers. that means it now must be the same size as the trigger bit word in the event!
uci1 18:55f1581f2ee4 175 float fForceTrigPeriod; // number of seconds between force triggers (0=none)
uci1 3:24c5f0f50bf1 176 uint16_t fHeartBeatPeriod; // number of seconds between heartbeats (0=none)
uci1 84:80b15993944e 177 //uint8_t fAmpsOn; // which amps are on (bit word. uint8_t => 8 amps max). removed vers 11+, as it cannot be implemented.
uci1 3:24c5f0f50bf1 178 uint16_t fEvtThrtlPeriodMs; // throttle period to write events (ms)
uci1 3:24c5f0f50bf1 179 // power
uci1 4:a91682e19d6b 180 uint8_t fPowerMode; // power mode bit word: see EPowerModeBit
uci1 40:1324da35afd4 181 uint16_t fBatVoltToLowPwr; // battery level at which to switch to low power (not used?)
uci1 40:1324da35afd4 182 uint16_t fBatVoltFromLowPwr; // battery level at which to switch back from low power (not used?)
uci1 8:95a325df1f6b 183 uint16_t fVoltCheckPeriod; // how often to check the voltages (s)
uci1 3:24c5f0f50bf1 184 // communication
uci1 3:24c5f0f50bf1 185 uint32_t fCommWinPeriod; // seconds between communication window startup (0=always on)
uci1 3:24c5f0f50bf1 186 uint32_t fCommWinDuration; // seconds that communication window stays open (0=always open)
uci1 3:24c5f0f50bf1 187 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 188 uint32_t fCommWinPrdLowPwr; // low power communication window period (seconds) (range enforced)
uci1 3:24c5f0f50bf1 189 uint32_t fCommWinDurLowPwr; // low power communication window duration (seconds) (range enforced)
uci1 84:80b15993944e 190 uint8_t fCommWinConnTOMins[kNumDatStreams]; // comm win connection timeout (minutes) for each data stream (range enforced)
uci1 84:80b15993944e 191 uint8_t fCommWinListTOMins[kNumDatStreams]; // comm win listening timeout (minutes) for each data stream (range enforced)
uci1 8:95a325df1f6b 192 char fRemoteServer[kIPLen]; // IP address of remote server (for afar)
uci1 8:95a325df1f6b 193 uint16_t fRemotePort; // port number of remote server (for afar)
uci1 8:95a325df1f6b 194 char fMbedIP[kIPLen]; // IP address of this mbed
uci1 8:95a325df1f6b 195 char fMbedMask[kIPLen]; // IP address of this mbed mask
uci1 8:95a325df1f6b 196 char fMbedGate[kIPLen]; // IP address of this mbed gateway
uci1 3:24c5f0f50bf1 197 // watchdog
uci1 3:24c5f0f50bf1 198 uint32_t fWatchDogPeriod; // number of seconds of inactivity for watchdog to issue a reset
uci1 114:554fa3a956b4 199 #if CHIPBOARD!=ATWD4CH
uci1 56:0bba0ef15697 200 // temp
uci1 56:0bba0ef15697 201 int8_t fTempCheckPeriod; // number of minutes between temperature checks. if negative, uses parasite power. if 0, never check.
uci1 84:80b15993944e 202 #endif
uci1 84:80b15993944e 203 // vers 11+ below
uci1 84:80b15993944e 204 uint8_t fSnglFreqRatio; // single frequency L1 trigger parameter = max / (tot - max). [0,255] => [0.0, 1.0]
uci1 84:80b15993944e 205 uint8_t fL1Scaledown; // save an L1 fail event every fL1Scaledown
uci1 3:24c5f0f50bf1 206
uci1 8:95a325df1f6b 207 // in case of low power, store regular settings
uci1 8:95a325df1f6b 208 // these are not sent over i/o or stored in the file
uci1 8:95a325df1f6b 209 // so they are not included in SizeOf
uci1 8:95a325df1f6b 210 bool fIsLowPower;
uci1 8:95a325df1f6b 211 char fNormLabel[kConfLblLen];
uci1 8:95a325df1f6b 212 uint8_t fNormPowerMode;
uci1 8:95a325df1f6b 213
uci1 3:24c5f0f50bf1 214 void SetHardDefaults();
uci1 76:f8383f0292c2 215
uci1 76:f8383f0292c2 216 static
uci1 76:f8383f0292c2 217 void SetSDNeedToInitFlag();
uci1 76:f8383f0292c2 218
uci1 3:24c5f0f50bf1 219 static
uci1 84:80b15993944e 220 bool IsIOversForATWD(const uint8_t rv) {
uci1 84:80b15993944e 221 return ( (rv<9) || (rv==11) );
uci1 84:80b15993944e 222 }
uci1 84:80b15993944e 223
uci1 84:80b15993944e 224 static
uci1 56:0bba0ef15697 225 uint16_t GetTotDacsForIOVers(const uint8_t rv) {
uci1 84:80b15993944e 226 if ( IsIOversForATWD(rv) ) {
uci1 56:0bba0ef15697 227 return kTotDacsAtwd4ch;
uci1 56:0bba0ef15697 228 } else {
uci1 56:0bba0ef15697 229 return kTotDacsSst4ch;
uci1 56:0bba0ef15697 230 }
uci1 56:0bba0ef15697 231 }
uci1 56:0bba0ef15697 232
uci1 56:0bba0ef15697 233 static
uci1 56:0bba0ef15697 234 uint16_t GetMaxPlasForIOVers(const uint8_t rv) {
uci1 84:80b15993944e 235 if ( IsIOversForATWD(rv) ) {
uci1 56:0bba0ef15697 236 return kNplasV1;
uci1 56:0bba0ef15697 237 } else {
uci1 56:0bba0ef15697 238 return 0;
uci1 56:0bba0ef15697 239 }
uci1 56:0bba0ef15697 240 }
uci1 84:80b15993944e 241
uci1 84:80b15993944e 242
uci1 56:0bba0ef15697 243 static
uci1 8:95a325df1f6b 244 uint32_t SizeOf(const uint8_t rv,
uci1 8:95a325df1f6b 245 const bool streamHiLoPlas,
uci1 3:24c5f0f50bf1 246 const uint8_t nplas,
uci1 3:24c5f0f50bf1 247 const uint8_t lblLen) {
uci1 3:24c5f0f50bf1 248 // private because it cannot be used to read from a buffer
uci1 3:24c5f0f50bf1 249 // (the label length and fStreamHiLoPlas are not known a priori)
uci1 3:24c5f0f50bf1 250 // returns the num of bytes needed to stream this object
uci1 3:24c5f0f50bf1 251 // = size of member vars + 1 for i/o version + extra PLA strings (maybe)
uci1 8:95a325df1f6b 252 uint32_t maxsize = kMaxSizeOf;
uci1 8:95a325df1f6b 253 if (rv==1) {
uci1 8:95a325df1f6b 254 maxsize = kMaxSizeOfV1;
uci1 8:95a325df1f6b 255 } else if (rv==2) {
uci1 8:95a325df1f6b 256 maxsize = kMaxSizeOfV2;
uci1 19:74155d652c37 257 } else if (rv==3) {
uci1 19:74155d652c37 258 maxsize = kMaxSizeOfV3;
uci1 39:2f17131d22a5 259 } else if (rv==4) {
uci1 39:2f17131d22a5 260 maxsize = kMaxSizeOfV4;
uci1 39:2f17131d22a5 261 } else if (rv==5) {
uci1 39:2f17131d22a5 262 maxsize = kMaxSizeOfV5;
uci1 39:2f17131d22a5 263 } else if (rv==6) {
uci1 40:1324da35afd4 264 maxsize = kMaxSizeOfV6;
uci1 40:1324da35afd4 265 } else if (rv==7) {
uci1 40:1324da35afd4 266 maxsize = kMaxSizeOfV7;
uci1 40:1324da35afd4 267 } else if (rv==8) {
uci1 40:1324da35afd4 268 maxsize = kMaxSizeOfV8;
uci1 56:0bba0ef15697 269 } else if (rv==9) {
uci1 56:0bba0ef15697 270 maxsize = kMaxSizeOfV9;
uci1 56:0bba0ef15697 271 } else if (rv==10) {
uci1 56:0bba0ef15697 272 maxsize = kMaxSizeOfV10;
uci1 84:80b15993944e 273 } else if (rv==11) {
uci1 84:80b15993944e 274 maxsize = kMaxSizeOfV11;
uci1 84:80b15993944e 275 } else if (rv==12) {
uci1 84:80b15993944e 276 maxsize = kMaxSizeOfV12;
uci1 114:554fa3a956b4 277 } else if (rv==13) {
uci1 114:554fa3a956b4 278 maxsize = kMaxSizeOfV13;
uci1 116:8099b754fbb4 279 } else if (rv==14) {
uci1 116:8099b754fbb4 280 maxsize = kMaxSizeOfV14;
uci1 116:8099b754fbb4 281 } else if (rv==15) {
uci1 116:8099b754fbb4 282 maxsize = kMaxSizeOfV15;
uci1 8:95a325df1f6b 283 }
uci1 84:80b15993944e 284 uint32_t sz = maxsize;
uci1 84:80b15993944e 285 if (rv<11) {
uci1 116:8099b754fbb4 286 // less than V11? then we need to account for the dynamic
uci1 116:8099b754fbb4 287 // length of the label :( with V12+, the length is always the same
uci1 84:80b15993944e 288 const int32_t lbldiff = kConfLblLen - lblLen;
uci1 84:80b15993944e 289 sz = maxsize - lbldiff;
uci1 84:80b15993944e 290 if ((lbldiff!=0) && (rv>=4)) {
uci1 84:80b15993944e 291 sz += 1; // the \0 at the end of the string
uci1 84:80b15993944e 292 }
uci1 39:2f17131d22a5 293 }
uci1 84:80b15993944e 294 #if CHIPBOARD==ATWD4CH
uci1 84:80b15993944e 295 if ( IsIOversForATWD(rv) ) {
uci1 84:80b15993944e 296 // streaming hi/lo plas separately?
uci1 84:80b15993944e 297 const uint8_t fac = (streamHiLoPlas && (rv<11)) ? 3u : 1u;
uci1 84:80b15993944e 298 const int32_t nplasNotSent = GetMaxPlasForIOVers(rv) - nplas;
uci1 84:80b15993944e 299 sz -= (fac*nplasNotSent);
uci1 56:0bba0ef15697 300
uci1 84:80b15993944e 301 /*
uci1 56:0bba0ef15697 302 const uint32_t mhlp = 2u*GetMaxPlasForIOVers(rv)*sizeof(uint16_t);
uci1 56:0bba0ef15697 303 const int32_t dp = (nplas-GetMaxPlasForIOVers(rv))*sizeof(uint16_t);
uci1 84:80b15993944e 304 const uint8_t fac = (streamHiLoPlas && (rv<11)) ? 3u : 1u;
uci1 56:0bba0ef15697 305 sz += (fac*dp);
uci1 84:80b15993944e 306 if ((streamHiLoPlas==false) || (rv>=11)) {
uci1 84:80b15993944e 307 sz -= mhlp; // should be * (maxPlas - nplas), right?
uci1 56:0bba0ef15697 308 }
uci1 84:80b15993944e 309 */
uci1 3:24c5f0f50bf1 310 }
uci1 56:0bba0ef15697 311 #endif
uci1 3:24c5f0f50bf1 312 return sz;
uci1 3:24c5f0f50bf1 313 }
uci1 28:484943132bb0 314
uci1 67:ec999336fcd1 315 #ifdef USE_INTERFACE_CHIP
uci1 59:21128cc24b04 316 bool ReadOneIPFrom(const char* ipfname, char* ipstr);
uci1 67:ec999336fcd1 317 #endif
uci1 59:21128cc24b04 318 bool ReadDefaultRemoteServer();
uci1 59:21128cc24b04 319 bool ReadDefaultRemotePort();
uci1 59:21128cc24b04 320 bool ReadDefaultMbedIP();
uci1 59:21128cc24b04 321 bool ReadDefaultMbedMask();
uci1 59:21128cc24b04 322 bool ReadDefaultMbedGate();
uci1 28:484943132bb0 323 void SetDefaultIPs();
uci1 28:484943132bb0 324 void SetDefaultRemoteServ();
uci1 28:484943132bb0 325 void SetDefaultRemotePort();
uci1 28:484943132bb0 326 void SetDefaultMbedIP();
uci1 28:484943132bb0 327 void SetDefaultMaskIP();
uci1 28:484943132bb0 328 void SetDefaultGateIP();
uci1 28:484943132bb0 329 void ApplySafetyNets();
uci1 84:80b15993944e 330 void ApplyConnectListenSafetyNets(const uint8_t dataStreamIdx);
uci1 28:484943132bb0 331
uci1 3:24c5f0f50bf1 332 public:
uci1 31:b5bd3b189150 333 SnConfigFrame(const bool applySafety=true) : fIsLowPower(false) {
uci1 84:80b15993944e 334 memset(fLabel, 0, kConfLblLen);
uci1 31:b5bd3b189150 335 fgApplySafetyNets = applySafety;
uci1 31:b5bd3b189150 336 Reset();
uci1 31:b5bd3b189150 337 }
uci1 3:24c5f0f50bf1 338 virtual ~SnConfigFrame() {}
uci1 40:1324da35afd4 339
uci1 40:1324da35afd4 340 void ApplyConnectListenSafetyNets();
uci1 3:24c5f0f50bf1 341
uci1 8:95a325df1f6b 342 bool IsCountingPowerReadings() const { return ((fRunMode & kCountPowerBit)!=0); }
uci1 8:95a325df1f6b 343 bool IsSingleSeqRunMode() const { return ((fRunMode & kSingleSeqBit)!=0); }
uci1 56:0bba0ef15697 344 bool IsDualThresholdMode() const { return ((fRunMode & kDualThreshBit)!=0); }
uci1 56:0bba0ef15697 345 bool IsDifferentialTrigMode() const { return ((fRunMode & kDiffTrigBit)!=0); }
uci1 56:0bba0ef15697 346 bool IsSBDonlyLowPwrMode() const { return ((fRunMode & kLowPwrSBDonly)!=0); }
uci1 56:0bba0ef15697 347 bool IsRunSeqListOneCommWinOnly() const { return ((fRunMode & kRSListOneCW)!=0); }
uci1 76:f8383f0292c2 348 bool IsIgnoringSDcard() const { return ((fRunMode & kIgnoreSDcard)!=0); }
uci1 84:80b15993944e 349 bool IsCommPowerSimple() const { return ((fRunMode & kComPwrSimple)!=0); }
uci1 84:80b15993944e 350 bool IsCommWindowEachEvent() const { return ((fRunMode & kCommEachEvent)!=0); }
uci1 116:8099b754fbb4 351 bool IsSkippingTrgStartReset() const { return ((fRunMode & kSkipTrgStartReset)!=0); }
uci1 8:95a325df1f6b 352 bool IsLowPowerMode() const { return fIsLowPower; }
uci1 3:24c5f0f50bf1 353 const char* GetLabel() const { return fLabel; }
uci1 3:24c5f0f50bf1 354 uint32_t GetLabelStrLen() const { return strlen(fLabel); }
uci1 3:24c5f0f50bf1 355 uint32_t GetRun() const { return fRun; }
uci1 40:1324da35afd4 356 uint16_t GetFirstSeq() const { return fFirstSeq; }
uci1 84:80b15993944e 357 uint16_t GetEvtsPerFile() const { return fEvtsPerSeq; }
uci1 56:0bba0ef15697 358 inline
uci1 3:24c5f0f50bf1 359 uint16_t GetEvtThrtlPeriodMs() const { return fEvtThrtlPeriodMs; }
uci1 18:55f1581f2ee4 360 float GetForceTrigPeriod() const { return fForceTrigPeriod; }
uci1 3:24c5f0f50bf1 361 uint16_t GetHeartbeatPeriod() const { return fHeartBeatPeriod; }
uci1 39:2f17131d22a5 362 uint16_t GetBatVoltToLowPwr() const { return fBatVoltToLowPwr; }
uci1 39:2f17131d22a5 363 uint16_t GetBatVoltFromLowPwr() const { return fBatVoltFromLowPwr; }
uci1 8:95a325df1f6b 364 uint16_t GetVoltCheckPeriod() const { return fVoltCheckPeriod; }
uci1 3:24c5f0f50bf1 365 uint32_t GetWatchdogPeriod() const { return fWatchDogPeriod; }
uci1 114:554fa3a956b4 366 #if CHIPBOARD!=ATWD4CH
uci1 56:0bba0ef15697 367 uint16_t GetTempCheckPeriod() const {
uci1 56:0bba0ef15697 368 const uint16_t t = (fTempCheckPeriod<0) ? (-fTempCheckPeriod) : fTempCheckPeriod;
uci1 56:0bba0ef15697 369 return t*60;
uci1 56:0bba0ef15697 370 }
uci1 56:0bba0ef15697 371 bool IsTempUsingParasitePower() const { return (fTempCheckPeriod<0); }
uci1 84:80b15993944e 372 #else
uci1 84:80b15993944e 373 uint16_t GetTempCheckPeriod() const { return 0; }
uci1 84:80b15993944e 374 #endif
uci1 84:80b15993944e 375 uint8_t GetSingleFreqSuppRatioRaw() const { return fSnglFreqRatio; }
uci1 84:80b15993944e 376 inline
uci1 84:80b15993944e 377 float GetSingleFreqSuppRatio() const { return static_cast<float>(fSnglFreqRatio) / 255.0f; }
uci1 3:24c5f0f50bf1 378 uint16_t GetDac(const uint8_t ch, const uint8_t dn) const { return fDAC[ch][dn]; }
uci1 56:0bba0ef15697 379 #if CHIPBOARD==ATWD4CH
uci1 3:24c5f0f50bf1 380 uint8_t GetNumPlas() const { return fNumPlas; }
uci1 3:24c5f0f50bf1 381 uint16_t GetPla(const uint8_t pn) const { return fPLA[pn]; }
uci1 56:0bba0ef15697 382 #endif
uci1 3:24c5f0f50bf1 383 uint8_t GetNumCardsMajLog() const { return fNumCardsMajLog; }
uci1 84:80b15993944e 384 // bool IsThermTrigEnabled() const { return fEnableThermTrig!=0; }
uci1 84:80b15993944e 385 uint8_t GetL1Scaledown() const { return fL1Scaledown; }
uci1 84:80b15993944e 386 bool IsThermTrigEnabled() const
uci1 84:80b15993944e 387 { return (fEnableThermTrig & kThermal)!=0; }
uci1 84:80b15993944e 388 bool IsSingleFreqSuppEnabled() const
uci1 84:80b15993944e 389 { return (fEnableThermTrig & kSingleFreqSupp)!=0; }
uci1 84:80b15993944e 390 bool IsL1TrigApplied() const
uci1 84:80b15993944e 391 { return (fEnableThermTrig & kL1TrgApplied)!=0; }
uci1 84:80b15993944e 392 /*
uci1 3:24c5f0f50bf1 393 bool IsEachAmpOn() const {
uci1 3:24c5f0f50bf1 394 bool allon=true;
uci1 3:24c5f0f50bf1 395 for (uint8_t i=0; (i<kNchans) && allon; i++) {
uci1 3:24c5f0f50bf1 396 allon = (fAmpsOn & BIT(i))!=0;
uci1 3:24c5f0f50bf1 397 }
uci1 3:24c5f0f50bf1 398 return allon;
uci1 3:24c5f0f50bf1 399 }
uci1 3:24c5f0f50bf1 400 // TODO: allow check for individual amps, when they can be turned on individually
uci1 84:80b15993944e 401 */
uci1 8:95a325df1f6b 402 const char* GetRemoteServer() const { return fRemoteServer; }
uci1 8:95a325df1f6b 403 uint16_t GetRemotePort() const { return fRemotePort; }
uci1 8:95a325df1f6b 404 const char* GetMbedIP() const { return fMbedIP; }
uci1 8:95a325df1f6b 405 const char* GetMbedMask() const { return fMbedMask; }
uci1 8:95a325df1f6b 406 const char* GetMbedGate() const { return fMbedGate; }
uci1 8:95a325df1f6b 407 uint32_t GetCommWinPeriod() const { return fIsLowPower ? fCommWinPrdLowPwr : fCommWinPeriod; }
uci1 8:95a325df1f6b 408 uint32_t GetCommWinDuration() const { return fIsLowPower ? fCommWinDurLowPwr : fCommWinDuration; }
uci1 84:80b15993944e 409 uint32_t GetCommWinConnectTOofIdx(const uint8_t idx) const {
uci1 84:80b15993944e 410 return (static_cast<uint32_t>( fCommWinConnTOMins[idx] ) * 60u);
uci1 84:80b15993944e 411 }
uci1 84:80b15993944e 412 uint32_t GetCommWinConnectTO(const SnConfigFrame::EDatPackBit b) const {
uci1 84:80b15993944e 413 return GetCommWinConnectTOofIdx(IndexOfDataStream(b));
uci1 84:80b15993944e 414 }
uci1 84:80b15993944e 415 uint32_t GetCommWinListenTOofIdx(const uint8_t idx) const {
uci1 84:80b15993944e 416 return (static_cast<uint32_t>( fCommWinListTOMins[idx] ) * 60u);
uci1 84:80b15993944e 417 }
uci1 84:80b15993944e 418 uint32_t GetCommWinListenTO(const SnConfigFrame::EDatPackBit b) const {
uci1 84:80b15993944e 419 return GetCommWinListenTOofIdx(IndexOfDataStream(b));
uci1 84:80b15993944e 420 }
uci1 3:24c5f0f50bf1 421 int16_t GetCommSendData() const { return fCommSendData; }
uci1 3:24c5f0f50bf1 422
uci1 3:24c5f0f50bf1 423 bool IsSendingAllFiles() const
uci1 3:24c5f0f50bf1 424 { return (fCommSendData<0) && ((fCommSendData & kAllFiles)!=0); }
uci1 3:24c5f0f50bf1 425 bool IsObeyingTimeout() const
uci1 3:24c5f0f50bf1 426 { return (fCommSendData<0) && ((fCommSendData & kTimeout)!=0); }
uci1 3:24c5f0f50bf1 427 bool IsDeletingFiles() const
uci1 3:24c5f0f50bf1 428 { return (fCommSendData<0) && ((fCommSendData & kDelete)!=0); }
uci1 15:f2569d8e4176 429 bool IsForcingSBDdata() const
uci1 15:f2569d8e4176 430 { return (fCommSendData<0) && ((fCommSendData & kForceSBDdata)!=0); }
uci1 40:1324da35afd4 431 bool IsWaitingHndShkBeforeSendData() const
uci1 40:1324da35afd4 432 { return (fCommSendData<0) && ((fCommSendData & kHnShBefSendDat)!=0); }
uci1 56:0bba0ef15697 433 bool IsSendingFilesRunSeqList() const
uci1 56:0bba0ef15697 434 { return (fCommSendData<0) && ((fCommSendData & kSendRunSeqList)!=0); }
uci1 84:80b15993944e 435 bool IsStatusSendingConfig() const
uci1 84:80b15993944e 436 { return (fCommSendData<0) && ((fCommSendData & kStatSendConf)!=0); }
uci1 84:80b15993944e 437 bool IsStatusSendingTrigTimes() const
uci1 84:80b15993944e 438 { return (fCommSendData<0) && ((fCommSendData & kStatSendTrgTim)!=0); }
uci1 84:80b15993944e 439 bool IsStatusSendingPowerReading() const
uci1 84:80b15993944e 440 { return (fCommSendData<0) && ((fCommSendData & kStatSendPwrDat)!=0); }
uci1 84:80b15993944e 441 bool IsStatusSendingEvent() const
uci1 84:80b15993944e 442 { return (fCommSendData<0) && ((fCommSendData & kStatSendEvent)!=0); }
uci1 84:80b15993944e 443 bool IsStatusSendingHeartbeat() const
uci1 84:80b15993944e 444 { return (fCommSendData<0) && ((fCommSendData & kStatSendHtbt)!=0); }
uci1 84:80b15993944e 445 bool IsStatusSendingTemperature() const
uci1 84:80b15993944e 446 { return (fCommSendData<0) && ((fCommSendData & kStatSendTmpDat)!=0); }
uci1 3:24c5f0f50bf1 447
uci1 4:a91682e19d6b 448 uint8_t GetPowerMode() const { return fPowerMode; }
uci1 30:f869ed4bcc08 449 int GetPowPinSetting(const EPowerModeBit p, const bool isOn) const {
uci1 56:0bba0ef15697 450 #if CHIPBOARD==ATWD4CH
uci1 5:9cea89700c66 451 if (p==kCardDatTak || p==kCardComWin ||
uci1 5:9cea89700c66 452 p==kAmpsDatTak || p==kAmpsComWin) {
uci1 30:f869ed4bcc08 453 return isOn ? 0 : 1;
uci1 5:9cea89700c66 454 } else {
uci1 30:f869ed4bcc08 455 return isOn ? 1 : 0;
uci1 5:9cea89700c66 456 }
uci1 56:0bba0ef15697 457 #else
uci1 56:0bba0ef15697 458 return isOn ? 1 : 0;
uci1 56:0bba0ef15697 459 #endif
uci1 5:9cea89700c66 460 }
uci1 30:f869ed4bcc08 461 int GetPowPinSetting(const EPowerModeBit p) const {
uci1 30:f869ed4bcc08 462 // return int to correspond to what DigitalOut::operator= expects
uci1 30:f869ed4bcc08 463 return GetPowPinSetting(p, IsPoweredFor(p));
uci1 30:f869ed4bcc08 464 }
uci1 8:95a325df1f6b 465 bool IsPoweredFor(const EPowerModeBit p) const {
uci1 8:95a325df1f6b 466 return ((fPowerMode & p)!=0);
uci1 8:95a325df1f6b 467 }
uci1 8:95a325df1f6b 468
uci1 8:95a325df1f6b 469 void EnablePowerFor(const EPowerModeBit p) { fPowerMode |= p; }
uci1 8:95a325df1f6b 470 void DisablePowerFor(const EPowerModeBit p) { fPowerMode &= ~p; }
uci1 8:95a325df1f6b 471
uci1 8:95a325df1f6b 472 void ChangeToLowPower();
uci1 8:95a325df1f6b 473 void ChangeToNormPower();
uci1 3:24c5f0f50bf1 474
uci1 3:24c5f0f50bf1 475 const char* GetOutFileName(const char* dir) const;
uci1 3:24c5f0f50bf1 476
uci1 21:ce51bb0ba4a5 477 uint32_t GetTimeoutTime(const uint32_t startTime,
uci1 21:ce51bb0ba4a5 478 const uint32_t delta) const;
uci1 21:ce51bb0ba4a5 479
uci1 21:ce51bb0ba4a5 480
uci1 3:24c5f0f50bf1 481 // waveform packing info
uci1 3:24c5f0f50bf1 482 uint16_t GetWvBaseline() const { return fWvBaseline; }
uci1 3:24c5f0f50bf1 483 uint8_t GetWvLoseLSB() const { return fWvLoseLSB; }
uci1 3:24c5f0f50bf1 484 uint8_t GetWvLoseMSB() const { return fWvLoseMSB; }
uci1 3:24c5f0f50bf1 485 bool IsDatPackedFor(const EDatPackBit d) const { return (fDatPackType & d)!=0; }
uci1 3:24c5f0f50bf1 486 void GetPackParsFor(const EDatPackBit d,
uci1 3:24c5f0f50bf1 487 uint8_t& loseLSB, uint8_t& loseMSB,
uci1 3:24c5f0f50bf1 488 uint16_t& wvBase) const;
uci1 3:24c5f0f50bf1 489
uci1 3:24c5f0f50bf1 490 // i/o
uci1 40:1324da35afd4 491 static
uci1 40:1324da35afd4 492 bool IsIOversionOk(const uint8_t rv) {
uci1 40:1324da35afd4 493 return (kIOVers == rv);
uci1 40:1324da35afd4 494 }
uci1 40:1324da35afd4 495
uci1 40:1324da35afd4 496 template<class T>
uci1 40:1324da35afd4 497 static
uci1 40:1324da35afd4 498 uint8_t PeekIOversion(T& b) {
uci1 40:1324da35afd4 499 // the buffer/file/whatever 'b' must be at the start of the config frame
uci1 40:1324da35afd4 500 uint8_t Rv=0;
uci1 40:1324da35afd4 501 SnBitUtils::ReadFrom(b, Rv);
uci1 40:1324da35afd4 502 return Rv;
uci1 40:1324da35afd4 503 }
uci1 40:1324da35afd4 504
uci1 3:24c5f0f50bf1 505 template<class T>
uci1 3:24c5f0f50bf1 506 void ReadFrom(T& b) {
uci1 3:24c5f0f50bf1 507 // no check on the length of buf is done here
uci1 3:24c5f0f50bf1 508 // that should be been done already
uci1 3:24c5f0f50bf1 509 //
uci1 3:24c5f0f50bf1 510 // must match WriteTo
uci1 3:24c5f0f50bf1 511
uci1 3:24c5f0f50bf1 512 uint8_t Rv=0;
uci1 3:24c5f0f50bf1 513 b = SnBitUtils::ReadFrom(b, Rv); // i/o version
uci1 12:d472f9811262 514 #ifdef DEBUG
uci1 3:24c5f0f50bf1 515 printf("Rv=%hhu\r\n",Rv);
uci1 12:d472f9811262 516 #endif
uci1 84:80b15993944e 517 if ( IsIOversionOk(Rv) ) {
uci1 56:0bba0ef15697 518
uci1 56:0bba0ef15697 519 if (IsLowPowerMode()) {
uci1 56:0bba0ef15697 520 // the low power bit is not streamed, so we need to
uci1 56:0bba0ef15697 521 // reset it explicitly
uci1 56:0bba0ef15697 522 ChangeToNormPower();
uci1 56:0bba0ef15697 523 }
uci1 56:0bba0ef15697 524
uci1 84:80b15993944e 525 if (Rv<11) {
uci1 84:80b15993944e 526 uint32_t llen=kConfLblLen;
uci1 84:80b15993944e 527 b = SnBitUtils::ReadFrom(b, llen);
uci1 12:d472f9811262 528 #ifdef DEBUG
uci1 84:80b15993944e 529 printf("llen=%u\r\n",llen);
uci1 12:d472f9811262 530 #endif
uci1 84:80b15993944e 531 b = SnBitUtils::ReadFrom(b, fLabel, llen);
uci1 84:80b15993944e 532 } else {
uci1 84:80b15993944e 533 b = SnBitUtils::ReadFrom(b, fLabel, kConfLblLen);
uci1 84:80b15993944e 534 }
uci1 12:d472f9811262 535 #ifdef DEBUG
uci1 3:24c5f0f50bf1 536 printf("lbl=%s\r\n",fLabel);
uci1 12:d472f9811262 537 #endif
uci1 3:24c5f0f50bf1 538 b = SnBitUtils::ReadFrom(b, fConfTime);
uci1 12:d472f9811262 539 #ifdef DEBUG
uci1 3:24c5f0f50bf1 540 printf("ct=%u\r\n",fConfTime);
uci1 12:d472f9811262 541 #endif
uci1 3:24c5f0f50bf1 542 b = SnBitUtils::ReadFrom(b, fRun);
uci1 12:d472f9811262 543 #ifdef DEBUG
uci1 3:24c5f0f50bf1 544 printf("run=%u\r\n",fRun);
uci1 12:d472f9811262 545 #endif
uci1 40:1324da35afd4 546 if (Rv>7) {
uci1 40:1324da35afd4 547 b = SnBitUtils::ReadFrom(b, fFirstSeq);
uci1 40:1324da35afd4 548 } else {
uci1 40:1324da35afd4 549 uint32_t fe(0);
uci1 40:1324da35afd4 550 fFirstSeq = 0;
uci1 40:1324da35afd4 551 b = SnBitUtils::ReadFrom(b, fe);
uci1 40:1324da35afd4 552 }
uci1 12:d472f9811262 553 #ifdef DEBUG
uci1 40:1324da35afd4 554 printf("firstseq=%hu\r\n",fFirstSeq);
uci1 12:d472f9811262 555 #endif
uci1 3:24c5f0f50bf1 556 if (Rv>1) {
uci1 84:80b15993944e 557 if (Rv<11) {
uci1 84:80b15993944e 558 uint32_t eps(0);
uci1 84:80b15993944e 559 b = SnBitUtils::ReadFrom(b, eps);
uci1 84:80b15993944e 560 fEvtsPerSeq = (1<<sizeof(fEvtsPerSeq))-1; // biggest value
uci1 84:80b15993944e 561 if ( eps < fEvtsPerSeq ) {
uci1 84:80b15993944e 562 fEvtsPerSeq = eps;
uci1 84:80b15993944e 563 }
uci1 84:80b15993944e 564 } else {
uci1 84:80b15993944e 565 b = SnBitUtils::ReadFrom(b, fEvtsPerSeq);
uci1 84:80b15993944e 566 }
uci1 84:80b15993944e 567 if (Rv<11) {
uci1 84:80b15993944e 568 uint8_t rm(0);
uci1 84:80b15993944e 569 b = SnBitUtils::ReadFrom(b, rm);
uci1 84:80b15993944e 570 fRunMode = rm;
uci1 84:80b15993944e 571 } else {
uci1 84:80b15993944e 572 b = SnBitUtils::ReadFrom(b, fRunMode);
uci1 84:80b15993944e 573 }
uci1 40:1324da35afd4 574 } else {
uci1 40:1324da35afd4 575 fEvtsPerSeq = 1000;
uci1 40:1324da35afd4 576 fRunMode = 0;
uci1 40:1324da35afd4 577 }
uci1 12:d472f9811262 578 #ifdef DEBUG
uci1 84:80b15993944e 579 printf("eps=%hu\r\n",fEvtsPerSeq);
uci1 84:80b15993944e 580 printf("rm=%hu\r\n",fRunMode);
uci1 12:d472f9811262 581 #endif
uci1 56:0bba0ef15697 582 #if CHIPBOARD==ATWD4CH
uci1 84:80b15993944e 583 if ( IsIOversForATWD(Rv) && Rv<11 ) {
uci1 56:0bba0ef15697 584 b = SnBitUtils::ReadFrom(b, fStreamHiLoPlas);
uci1 12:d472f9811262 585 #ifdef DEBUG
uci1 56:0bba0ef15697 586 printf("shilo=%d\r\n",(int)fStreamHiLoPlas);
uci1 12:d472f9811262 587 #endif
uci1 56:0bba0ef15697 588 }
uci1 56:0bba0ef15697 589 #endif // ATWD4CH
uci1 3:24c5f0f50bf1 590 b = SnBitUtils::ReadFrom(b, fWvLoseLSB);
uci1 12:d472f9811262 591 #ifdef DEBUG
uci1 3:24c5f0f50bf1 592 printf("lsb=%hhu\r\n",fWvLoseLSB);
uci1 12:d472f9811262 593 #endif
uci1 3:24c5f0f50bf1 594 b = SnBitUtils::ReadFrom(b, fWvLoseMSB);
uci1 12:d472f9811262 595 #ifdef DEBUG
uci1 3:24c5f0f50bf1 596 printf("msb=%hhu\r\n",fWvLoseMSB);
uci1 12:d472f9811262 597 #endif
uci1 3:24c5f0f50bf1 598 b = SnBitUtils::ReadFrom(b, fWvBaseline);
uci1 12:d472f9811262 599 #ifdef DEBUG
uci1 3:24c5f0f50bf1 600 printf("bl=%hu\r\n",fWvBaseline);
uci1 12:d472f9811262 601 #endif
uci1 84:80b15993944e 602 if (Rv<11) {
uci1 84:80b15993944e 603 b = SnBitUtils::ReadFrom(b, fDatPackType);
uci1 12:d472f9811262 604 #ifdef DEBUG
uci1 84:80b15993944e 605 printf("dp=%hhu\r\n",fDatPackType);
uci1 12:d472f9811262 606 #endif
uci1 84:80b15993944e 607 }
uci1 3:24c5f0f50bf1 608 uint16_t* dc = &(fDAC[0][0]);
uci1 56:0bba0ef15697 609 const uint8_t ntotdacs = GetTotDacsForIOVers(Rv);
uci1 56:0bba0ef15697 610 #ifdef DEBUG
uci1 56:0bba0ef15697 611 printf("ntotdacs=%hhu\r\n",ntotdacs);
uci1 56:0bba0ef15697 612 #endif
uci1 56:0bba0ef15697 613 for (uint16_t i=0; i<ntotdacs; i++, dc++) {
uci1 3:24c5f0f50bf1 614 b = SnBitUtils::ReadFrom(b, *dc);
uci1 12:d472f9811262 615 #ifdef DEBUG
uci1 3:24c5f0f50bf1 616 printf("dac[%hu]=%hu\r\n",i,*dc);
uci1 12:d472f9811262 617 #endif
uci1 3:24c5f0f50bf1 618 }
uci1 56:0bba0ef15697 619 #if CHIPBOARD==ATWD4CH
uci1 84:80b15993944e 620 if ( IsIOversForATWD(Rv) ) {
uci1 56:0bba0ef15697 621 b = SnBitUtils::ReadFrom(b, fNumPlas);
uci1 12:d472f9811262 622 #ifdef DEBUG
uci1 56:0bba0ef15697 623 printf("npla=%hhu\r\n",fNumPlas);
uci1 12:d472f9811262 624 #endif
uci1 56:0bba0ef15697 625 uint16_t* pl = &(fPLA[0]);
uci1 56:0bba0ef15697 626 for (uint8_t j=0; j<fNumPlas; j++, pl++) {
uci1 56:0bba0ef15697 627 b = SnBitUtils::ReadFrom(b, *pl);
uci1 12:d472f9811262 628 #ifdef DEBUG
uci1 56:0bba0ef15697 629 printf("pla[%hhu]=%hu\r\n",j,*pl);
uci1 12:d472f9811262 630 #endif
uci1 56:0bba0ef15697 631 }
uci1 3:24c5f0f50bf1 632 }
uci1 56:0bba0ef15697 633 #endif // ATWD4CH
uci1 3:24c5f0f50bf1 634 b = SnBitUtils::ReadFrom(b, fNumCardsMajLog);
uci1 12:d472f9811262 635 #ifdef DEBUG
uci1 3:24c5f0f50bf1 636 printf("mj=%hhu\r\n",fNumCardsMajLog);
uci1 12:d472f9811262 637 #endif
uci1 84:80b15993944e 638 if (Rv<11) {
uci1 84:80b15993944e 639 uint8_t e(0);
uci1 84:80b15993944e 640 b = SnBitUtils::ReadFrom(b, e);
uci1 84:80b15993944e 641 fEnableThermTrig = e;
uci1 84:80b15993944e 642 } else {
uci1 84:80b15993944e 643 b = SnBitUtils::ReadFrom(b, fEnableThermTrig);
uci1 84:80b15993944e 644 }
uci1 12:d472f9811262 645 #ifdef DEBUG
uci1 3:24c5f0f50bf1 646 printf("thm=%d\r\n",(int)fEnableThermTrig);
uci1 12:d472f9811262 647 #endif
uci1 18:55f1581f2ee4 648 if (Rv>3) {
uci1 18:55f1581f2ee4 649 b = SnBitUtils::ReadFrom(b, fForceTrigPeriod);
uci1 18:55f1581f2ee4 650 } else {
uci1 18:55f1581f2ee4 651 uint16_t ftrg(0);
uci1 18:55f1581f2ee4 652 b = SnBitUtils::ReadFrom(b, ftrg);
uci1 18:55f1581f2ee4 653 fForceTrigPeriod = ftrg;
uci1 18:55f1581f2ee4 654 }
uci1 12:d472f9811262 655 #ifdef DEBUG
uci1 18:55f1581f2ee4 656 printf("force=%g\r\n",fForceTrigPeriod);
uci1 12:d472f9811262 657 #endif
uci1 3:24c5f0f50bf1 658 b = SnBitUtils::ReadFrom(b, fHeartBeatPeriod);
uci1 12:d472f9811262 659 #ifdef DEBUG
uci1 3:24c5f0f50bf1 660 printf("heart=%hu\r\n",fHeartBeatPeriod);
uci1 12:d472f9811262 661 #endif
uci1 84:80b15993944e 662 if (Rv<11) {
uci1 84:80b15993944e 663 uint8_t ampson(0);
uci1 84:80b15993944e 664 b = SnBitUtils::ReadFrom(b, ampson);
uci1 12:d472f9811262 665 #ifdef DEBUG
uci1 84:80b15993944e 666 printf("amps=%hhu (IGNORED)\r\n",ampson);
uci1 12:d472f9811262 667 #endif
uci1 84:80b15993944e 668 }
uci1 3:24c5f0f50bf1 669 b = SnBitUtils::ReadFrom(b, fEvtThrtlPeriodMs);
uci1 12:d472f9811262 670 #ifdef DEBUG
uci1 3:24c5f0f50bf1 671 printf("throt=%hu\r\n",fEvtThrtlPeriodMs);
uci1 12:d472f9811262 672 #endif
uci1 3:24c5f0f50bf1 673 b = SnBitUtils::ReadFrom(b, fPowerMode);
uci1 12:d472f9811262 674 #ifdef DEBUG
uci1 3:24c5f0f50bf1 675 printf("pow=%hhu\r\n",fPowerMode);
uci1 12:d472f9811262 676 #endif
uci1 39:2f17131d22a5 677 if (Rv<6) {
uci1 39:2f17131d22a5 678 b = SnBitUtils::ReadFrom(b, fBatVoltToLowPwr);
uci1 40:1324da35afd4 679 fBatVoltFromLowPwr = 1.1*fBatVoltToLowPwr;
uci1 39:2f17131d22a5 680 } else {
uci1 39:2f17131d22a5 681 b = SnBitUtils::ReadFrom(b, fBatVoltToLowPwr);
uci1 39:2f17131d22a5 682 b = SnBitUtils::ReadFrom(b, fBatVoltFromLowPwr);
uci1 39:2f17131d22a5 683 }
uci1 39:2f17131d22a5 684 #ifdef DEBUG
uci1 40:1324da35afd4 685 printf("batlow(to,from)=(%hu,%hu)\r\n",fBatVoltToLowPwr,fBatVoltFromLowPwr);
uci1 12:d472f9811262 686 #endif
uci1 8:95a325df1f6b 687 if (Rv>2) {
uci1 8:95a325df1f6b 688 b = SnBitUtils::ReadFrom(b, fVoltCheckPeriod);
uci1 40:1324da35afd4 689 } else {
uci1 40:1324da35afd4 690 fVoltCheckPeriod = 600u;
uci1 40:1324da35afd4 691 }
uci1 12:d472f9811262 692 #ifdef DEBUG
uci1 8:95a325df1f6b 693 printf("vltchk=%hu\r\n",fVoltCheckPeriod);
uci1 12:d472f9811262 694 #endif
uci1 3:24c5f0f50bf1 695 b = SnBitUtils::ReadFrom(b, fCommWinPeriod);
uci1 12:d472f9811262 696 #ifdef DEBUG
uci1 3:24c5f0f50bf1 697 printf("cmper=%u\r\n",fCommWinPeriod);
uci1 12:d472f9811262 698 #endif
uci1 3:24c5f0f50bf1 699 b = SnBitUtils::ReadFrom(b, fCommWinDuration);
uci1 12:d472f9811262 700 #ifdef DEBUG
uci1 3:24c5f0f50bf1 701 printf("cmdur=%u\r\n",fCommWinDuration);
uci1 12:d472f9811262 702 #endif
uci1 3:24c5f0f50bf1 703 b = SnBitUtils::ReadFrom(b, fCommSendData);
uci1 12:d472f9811262 704 #ifdef DEBUG
uci1 84:80b15993944e 705 printf("send=%hd\r\n",fCommSendData);
uci1 12:d472f9811262 706 #endif
uci1 3:24c5f0f50bf1 707 b = SnBitUtils::ReadFrom(b, fCommWinPrdLowPwr);
uci1 12:d472f9811262 708 #ifdef DEBUG
uci1 3:24c5f0f50bf1 709 printf("cmperlp=%u\r\n",fCommWinPrdLowPwr);
uci1 12:d472f9811262 710 #endif
uci1 3:24c5f0f50bf1 711 b = SnBitUtils::ReadFrom(b, fCommWinDurLowPwr);
uci1 12:d472f9811262 712 #ifdef DEBUG
uci1 3:24c5f0f50bf1 713 printf("cmdurlp=%u\r\n",fCommWinDurLowPwr);
uci1 12:d472f9811262 714 #endif
uci1 40:1324da35afd4 715 if (Rv>6) {
uci1 84:80b15993944e 716 if (Rv>10) {
uci1 84:80b15993944e 717 // Irid first
uci1 84:80b15993944e 718 b = SnBitUtils::ReadFrom(b, fCommWinConnTOMins[IndexOfDataStream(kIrid)]);
uci1 84:80b15993944e 719 b = SnBitUtils::ReadFrom(b, fCommWinListTOMins[IndexOfDataStream(kIrid)]);
uci1 84:80b15993944e 720 // Afar next
uci1 84:80b15993944e 721 b = SnBitUtils::ReadFrom(b, fCommWinConnTOMins[IndexOfDataStream(kAfar)]);
uci1 84:80b15993944e 722 b = SnBitUtils::ReadFrom(b, fCommWinListTOMins[IndexOfDataStream(kAfar)]);
uci1 84:80b15993944e 723 } else {
uci1 84:80b15993944e 724 // older versions: set them all the same
uci1 84:80b15993944e 725 uint8_t cto, lto;
uci1 84:80b15993944e 726 b = SnBitUtils::ReadFrom(b, cto);
uci1 84:80b15993944e 727 b = SnBitUtils::ReadFrom(b, lto);
uci1 84:80b15993944e 728 for (uint8_t i=0; i<kNumDatStreams; ++i) {
uci1 84:80b15993944e 729 fCommWinConnTOMins[i] = cto;
uci1 84:80b15993944e 730 fCommWinListTOMins[i] = lto;
uci1 84:80b15993944e 731 }
uci1 84:80b15993944e 732 }
uci1 40:1324da35afd4 733 } else {
uci1 84:80b15993944e 734 for (uint8_t i=0; i<kNumDatStreams; ++i) {
uci1 85:3ced48ef94c5 735 fCommWinConnTOMins[i] = GetDefaultConnTOMinOf(GetDataStreamForIndex(i));
uci1 85:3ced48ef94c5 736 fCommWinListTOMins[i] = GetDefaultListTOMinOf(GetDataStreamForIndex(i));
uci1 84:80b15993944e 737 }
uci1 40:1324da35afd4 738 }
uci1 40:1324da35afd4 739 #ifdef DEBUG
uci1 84:80b15993944e 740 for (uint8_t i=0; i<kNumDatStreams; ++i) {
uci1 84:80b15993944e 741 printf("data stream %hhu (%s): connectTO=%hhu, listenTO=%hhu\r\n",
uci1 84:80b15993944e 742 i, GetDataStreamNameOfIdx(i),
uci1 84:80b15993944e 743 fCommWinConnTOMins[i], fCommWinListTOMins[i]);
uci1 84:80b15993944e 744 }
uci1 40:1324da35afd4 745 #endif
uci1 8:95a325df1f6b 746 if (Rv>2) {
uci1 84:80b15993944e 747 if (Rv<11) {
uci1 84:80b15993944e 748 b = SnBitUtils::ReadFrom(b, fRemoteServer, kIPLen);
uci1 84:80b15993944e 749 } else {
uci1 84:80b15993944e 750 // read the numerical value and convert to string
uci1 84:80b15993944e 751 uint32_t rip(0);
uci1 84:80b15993944e 752 b = SnBitUtils::ReadFrom(b, rip);
uci1 84:80b15993944e 753 GetIpStrFromVal(rip, fRemoteServer);
uci1 84:80b15993944e 754 }
uci1 28:484943132bb0 755 if (strncmp(fRemoteServer, kDefIPflag,kIPLen)==0) {
uci1 28:484943132bb0 756 SetDefaultRemoteServ();
uci1 28:484943132bb0 757 }
uci1 12:d472f9811262 758 #ifdef DEBUG
uci1 8:95a325df1f6b 759 printf("rserv=%s\r\n",fRemoteServer);
uci1 12:d472f9811262 760 #endif
uci1 8:95a325df1f6b 761 b = SnBitUtils::ReadFrom(b, fRemotePort);
uci1 28:484943132bb0 762 if (fRemotePort==0) {
uci1 28:484943132bb0 763 SetDefaultRemotePort();
uci1 28:484943132bb0 764 }
uci1 12:d472f9811262 765 #ifdef DEBUG
uci1 8:95a325df1f6b 766 printf("rport=%hu\r\n",fRemotePort);
uci1 12:d472f9811262 767 #endif
uci1 84:80b15993944e 768 if (Rv<11) {
uci1 84:80b15993944e 769 b = SnBitUtils::ReadFrom(b, fMbedIP, kIPLen);
uci1 84:80b15993944e 770 } else {
uci1 84:80b15993944e 771 // read the numerical value and convert to string
uci1 84:80b15993944e 772 uint32_t rip(0);
uci1 84:80b15993944e 773 b = SnBitUtils::ReadFrom(b, rip);
uci1 84:80b15993944e 774 GetIpStrFromVal(rip, fMbedIP);
uci1 84:80b15993944e 775 }
uci1 28:484943132bb0 776 if (strncmp(fMbedIP, kDefIPflag,kIPLen)==0) {
uci1 28:484943132bb0 777 SetDefaultMbedIP();
uci1 28:484943132bb0 778 }
uci1 12:d472f9811262 779 #ifdef DEBUG
uci1 8:95a325df1f6b 780 printf("mbedip=%s\r\n",fMbedIP);
uci1 12:d472f9811262 781 #endif
uci1 84:80b15993944e 782 if (Rv<11) {
uci1 84:80b15993944e 783 b = SnBitUtils::ReadFrom(b, fMbedMask, kIPLen);
uci1 84:80b15993944e 784 } else {
uci1 84:80b15993944e 785 // read the numerical value and convert to string
uci1 84:80b15993944e 786 uint32_t rip(0);
uci1 84:80b15993944e 787 b = SnBitUtils::ReadFrom(b, rip);
uci1 84:80b15993944e 788 GetIpStrFromVal(rip, fMbedMask);
uci1 84:80b15993944e 789 }
uci1 28:484943132bb0 790 if (strncmp(fMbedMask, kDefIPflag,kIPLen)==0) {
uci1 28:484943132bb0 791 SetDefaultMaskIP();
uci1 28:484943132bb0 792 }
uci1 12:d472f9811262 793 #ifdef DEBUG
uci1 8:95a325df1f6b 794 printf("mbedmask=%s\r\n",fMbedMask);
uci1 12:d472f9811262 795 #endif
uci1 84:80b15993944e 796 if (Rv<11) {
uci1 84:80b15993944e 797 b = SnBitUtils::ReadFrom(b, fMbedGate, kIPLen);
uci1 84:80b15993944e 798 } else {
uci1 84:80b15993944e 799 // read the numerical value and convert to string
uci1 84:80b15993944e 800 uint32_t rip(0);
uci1 84:80b15993944e 801 b = SnBitUtils::ReadFrom(b, rip);
uci1 84:80b15993944e 802 GetIpStrFromVal(rip, fMbedGate);
uci1 84:80b15993944e 803 }
uci1 28:484943132bb0 804 if (strncmp(fMbedGate, kDefIPflag,kIPLen)==0) {
uci1 28:484943132bb0 805 SetDefaultGateIP();
uci1 28:484943132bb0 806 }
uci1 12:d472f9811262 807 #ifdef DEBUG
uci1 8:95a325df1f6b 808 printf("mbedgate=%s\r\n",fMbedGate);
uci1 12:d472f9811262 809 #endif
uci1 40:1324da35afd4 810 } else {
uci1 40:1324da35afd4 811 SetDefaultIPs();
uci1 8:95a325df1f6b 812 }
uci1 3:24c5f0f50bf1 813 b = SnBitUtils::ReadFrom(b, fWatchDogPeriod);
uci1 12:d472f9811262 814 #ifdef DEBUG
uci1 3:24c5f0f50bf1 815 printf("watch=%u\r\n",fWatchDogPeriod);
uci1 12:d472f9811262 816 #endif
uci1 114:554fa3a956b4 817 #if CHIPBOARD!=ATWD4CH
uci1 84:80b15993944e 818 if ( (IsIOversForATWD(Rv)==false) && (Rv>9) ) {
uci1 56:0bba0ef15697 819 b = SnBitUtils::ReadFrom(b, fTempCheckPeriod);
uci1 56:0bba0ef15697 820 }
uci1 12:d472f9811262 821 #ifdef DEBUG
uci1 56:0bba0ef15697 822 printf("temp check period=%hhd\r\n", fTempCheckPeriod);
uci1 12:d472f9811262 823 #endif
uci1 84:80b15993944e 824 #endif
uci1 84:80b15993944e 825 if (Rv>10) {
uci1 84:80b15993944e 826 b = SnBitUtils::ReadFrom(b, fSnglFreqRatio);
uci1 84:80b15993944e 827 #ifdef DEBUG
uci1 84:80b15993944e 828 printf("single freq ratio=%hhd\r\n", fSnglFreqRatio);
uci1 84:80b15993944e 829 #endif
uci1 84:80b15993944e 830
uci1 84:80b15993944e 831 b = SnBitUtils::ReadFrom(b, fL1Scaledown);
uci1 84:80b15993944e 832 #ifdef DEBUG
uci1 84:80b15993944e 833 printf("L1 scaledown=%hhd\r\n", fL1Scaledown);
uci1 84:80b15993944e 834 #endif
uci1 84:80b15993944e 835 }
uci1 56:0bba0ef15697 836 #if CHIPBOARD==ATWD4CH
uci1 84:80b15993944e 837 if ( IsIOversForATWD(Rv) ) {
uci1 56:0bba0ef15697 838 if (fStreamHiLoPlas!=0) {
uci1 56:0bba0ef15697 839 uint16_t hi, lo;
uci1 56:0bba0ef15697 840 for (uint8_t j=0; j<fNumPlas; j++) {
uci1 56:0bba0ef15697 841 b = SnBitUtils::ReadFrom(b, hi);
uci1 12:d472f9811262 842 #ifdef DEBUG
uci1 56:0bba0ef15697 843 printf("hi=%hu\r\n",hi);
uci1 56:0bba0ef15697 844 #endif
uci1 56:0bba0ef15697 845 b = SnBitUtils::ReadFrom(b, lo);
uci1 56:0bba0ef15697 846 #ifdef DEBUG
uci1 56:0bba0ef15697 847 printf("lo=%hu\r\n",lo);
uci1 12:d472f9811262 848 #endif
uci1 3:24c5f0f50bf1 849 // don't save these
uci1 56:0bba0ef15697 850 }
uci1 3:24c5f0f50bf1 851 }
uci1 3:24c5f0f50bf1 852 }
uci1 56:0bba0ef15697 853 #endif // ATWD4CH
uci1 84:80b15993944e 854 } else {
uci1 84:80b15993944e 855 // trying to read an invalid config version
uci1 84:80b15993944e 856 #ifdef DEBUG
uci1 84:80b15993944e 857 printf("Cannot accept config version [%hhu]. "
uci1 84:80b15993944e 858 "Expect [%hhu].",Rv,SnConfigFrame::kIOVers);
uci1 84:80b15993944e 859 #endif
uci1 3:24c5f0f50bf1 860 }
uci1 28:484943132bb0 861
uci1 31:b5bd3b189150 862 if (fgApplySafetyNets) {
uci1 31:b5bd3b189150 863 ApplySafetyNets();
uci1 31:b5bd3b189150 864 }
uci1 28:484943132bb0 865
uci1 76:f8383f0292c2 866 // reset the SD card init cache, in case the SD ignore run mode changed
uci1 76:f8383f0292c2 867 SetSDNeedToInitFlag();
uci1 76:f8383f0292c2 868
uci1 12:d472f9811262 869 #ifdef DEBUG
uci1 3:24c5f0f50bf1 870 printf("read from done\r\n");
uci1 12:d472f9811262 871 #endif
uci1 3:24c5f0f50bf1 872 }
uci1 3:24c5f0f50bf1 873
uci1 3:24c5f0f50bf1 874 template <class T>
uci1 3:24c5f0f50bf1 875 void WriteTo(T& b) const {
uci1 3:24c5f0f50bf1 876 // no check on the length of the buf is done here
uci1 3:24c5f0f50bf1 877 // that should be done already
uci1 3:24c5f0f50bf1 878 //
uci1 3:24c5f0f50bf1 879 // must match ReadFromBuf
uci1 3:24c5f0f50bf1 880 //
uci1 3:24c5f0f50bf1 881 // intentionally not writing mac address here, so we don't have to read it in
uci1 3:24c5f0f50bf1 882
uci1 3:24c5f0f50bf1 883 b = SnBitUtils::WriteTo(b, kIOVers); // i/o version
uci1 84:80b15993944e 884
uci1 84:80b15993944e 885 // first write the label, then explicitly write the trailing \0
uci1 84:80b15993944e 886 // so it's for sure always there
uci1 84:80b15993944e 887 /* legacy code when io vers < 11
uci1 40:1324da35afd4 888 // account for the ending \0
uci1 40:1324da35afd4 889 uint32_t llen = strlen(fLabel);
uci1 40:1324da35afd4 890 static const uint32_t maxllen = kConfLblLen-1;
uci1 40:1324da35afd4 891 if (llen > maxllen) {
uci1 40:1324da35afd4 892 llen = maxllen;
uci1 40:1324da35afd4 893 }
uci1 40:1324da35afd4 894 b = SnBitUtils::WriteTo(b, llen+1); // strlen + \0
uci1 3:24c5f0f50bf1 895 b = SnBitUtils::WriteTo(b, fLabel, llen);
uci1 84:80b15993944e 896 */
uci1 84:80b15993944e 897 b = SnBitUtils::WriteTo(b, fLabel, kConfLblLenNoStrTerm);
uci1 39:2f17131d22a5 898 b = SnBitUtils::WriteTo(b, char('\0'));
uci1 3:24c5f0f50bf1 899 b = SnBitUtils::WriteTo(b, fConfTime);
uci1 3:24c5f0f50bf1 900 b = SnBitUtils::WriteTo(b, fRun);
uci1 40:1324da35afd4 901 b = SnBitUtils::WriteTo(b, fFirstSeq);
uci1 84:80b15993944e 902 b = SnBitUtils::WriteTo(b, fEvtsPerSeq); // changed to uint16 with V11+
uci1 84:80b15993944e 903 b = SnBitUtils::WriteTo(b, fRunMode); // changed to uint16 with V11+
uci1 84:80b15993944e 904 /* - the option is no longer written to the config
uci1 56:0bba0ef15697 905 #if CHIPBOARD==ATWD4CH
uci1 84:80b15993944e 906 if ( IsIOversForATWD(kIOVers) ) {
uci1 56:0bba0ef15697 907 b = SnBitUtils::WriteTo(b, fStreamHiLoPlas);
uci1 56:0bba0ef15697 908 }
uci1 56:0bba0ef15697 909 #endif
uci1 84:80b15993944e 910 */
uci1 3:24c5f0f50bf1 911 b = SnBitUtils::WriteTo(b, fWvLoseLSB);
uci1 3:24c5f0f50bf1 912 b = SnBitUtils::WriteTo(b, fWvLoseMSB);
uci1 3:24c5f0f50bf1 913 b = SnBitUtils::WriteTo(b, fWvBaseline);
uci1 84:80b15993944e 914 //b = SnBitUtils::WriteTo(b, fDatPackType); // removed vers 11+
uci1 3:24c5f0f50bf1 915 const uint16_t* dc = &(fDAC[0][0]);
uci1 56:0bba0ef15697 916 const uint8_t ntotdacs = GetTotDacsForIOVers(kIOVers);
uci1 56:0bba0ef15697 917 for (uint16_t i=0; i<ntotdacs; i++, dc++) {
uci1 3:24c5f0f50bf1 918 b = SnBitUtils::WriteTo(b, *dc);
uci1 3:24c5f0f50bf1 919 }
uci1 56:0bba0ef15697 920 #if CHIPBOARD==ATWD4CH
uci1 84:80b15993944e 921 if ( IsIOversForATWD(kIOVers) ) {
uci1 56:0bba0ef15697 922 b = SnBitUtils::WriteTo(b, fNumPlas);
uci1 56:0bba0ef15697 923 const uint16_t* pl = &(fPLA[0]);
uci1 56:0bba0ef15697 924 for (uint8_t j=0; j<fNumPlas; j++, pl++) {
uci1 56:0bba0ef15697 925 b = SnBitUtils::WriteTo(b, *pl);
uci1 56:0bba0ef15697 926 }
uci1 3:24c5f0f50bf1 927 }
uci1 56:0bba0ef15697 928 #endif
uci1 3:24c5f0f50bf1 929 b = SnBitUtils::WriteTo(b, fNumCardsMajLog);
uci1 84:80b15993944e 930 b = SnBitUtils::WriteTo(b, fEnableThermTrig); // 16 bits in vers 11+
uci1 3:24c5f0f50bf1 931 b = SnBitUtils::WriteTo(b, fForceTrigPeriod);
uci1 3:24c5f0f50bf1 932 b = SnBitUtils::WriteTo(b, fHeartBeatPeriod);
uci1 84:80b15993944e 933 //b = SnBitUtils::WriteTo(b, fAmpsOn); removed vers 11+
uci1 3:24c5f0f50bf1 934 b = SnBitUtils::WriteTo(b, fEvtThrtlPeriodMs);
uci1 3:24c5f0f50bf1 935 b = SnBitUtils::WriteTo(b, fPowerMode);
uci1 39:2f17131d22a5 936 b = SnBitUtils::WriteTo(b, fBatVoltToLowPwr);
uci1 39:2f17131d22a5 937 b = SnBitUtils::WriteTo(b, fBatVoltFromLowPwr);
uci1 8:95a325df1f6b 938 b = SnBitUtils::WriteTo(b, fVoltCheckPeriod);
uci1 3:24c5f0f50bf1 939 b = SnBitUtils::WriteTo(b, fCommWinPeriod);
uci1 3:24c5f0f50bf1 940 b = SnBitUtils::WriteTo(b, fCommWinDuration);
uci1 3:24c5f0f50bf1 941 b = SnBitUtils::WriteTo(b, fCommSendData);
uci1 3:24c5f0f50bf1 942 b = SnBitUtils::WriteTo(b, fCommWinPrdLowPwr);
uci1 3:24c5f0f50bf1 943 b = SnBitUtils::WriteTo(b, fCommWinDurLowPwr);
uci1 84:80b15993944e 944 // vers 11+, separate conn/listen timeouts for Irid and Afar
uci1 84:80b15993944e 945 b = SnBitUtils::WriteTo(b, fCommWinConnTOMins[IndexOfDataStream(kIrid)]);
uci1 84:80b15993944e 946 b = SnBitUtils::WriteTo(b, fCommWinListTOMins[IndexOfDataStream(kIrid)]);
uci1 84:80b15993944e 947 b = SnBitUtils::WriteTo(b, fCommWinConnTOMins[IndexOfDataStream(kAfar)]);
uci1 84:80b15993944e 948 b = SnBitUtils::WriteTo(b, fCommWinListTOMins[IndexOfDataStream(kAfar)]);
uci1 84:80b15993944e 949 // with vers 11+, the numerical values are stored instead of strings (saves many bytes)
uci1 84:80b15993944e 950 b = SnBitUtils::WriteTo(b, GetIpValFromStr(fRemoteServer) );
uci1 8:95a325df1f6b 951 b = SnBitUtils::WriteTo(b, fRemotePort);
uci1 84:80b15993944e 952 b = SnBitUtils::WriteTo(b, GetIpValFromStr(fMbedIP) );
uci1 84:80b15993944e 953 b = SnBitUtils::WriteTo(b, GetIpValFromStr(fMbedMask) );
uci1 84:80b15993944e 954 b = SnBitUtils::WriteTo(b, GetIpValFromStr(fMbedGate) );
uci1 3:24c5f0f50bf1 955 b = SnBitUtils::WriteTo(b, fWatchDogPeriod);
uci1 114:554fa3a956b4 956 #if CHIPBOARD!=ATWD4CH
uci1 84:80b15993944e 957 if ( (IsIOversForATWD(kIOVers)==false) && (kIOVers>9) ) {
uci1 67:ec999336fcd1 958 b = SnBitUtils::WriteTo(b, fTempCheckPeriod);
uci1 67:ec999336fcd1 959 }
uci1 84:80b15993944e 960 #endif
uci1 84:80b15993944e 961 b = SnBitUtils::WriteTo(b, fSnglFreqRatio); // with vers 11+
uci1 84:80b15993944e 962 b = SnBitUtils::WriteTo(b, fL1Scaledown); // with vers 11+
uci1 84:80b15993944e 963
uci1 56:0bba0ef15697 964 #if CHIPBOARD==ATWD4CH
uci1 84:80b15993944e 965 if ( IsIOversForATWD(kIOVers) ) {
uci1 56:0bba0ef15697 966 if (fStreamHiLoPlas!=0) {
uci1 56:0bba0ef15697 967 const uint16_t* pl = &(fPLA[0]);
uci1 56:0bba0ef15697 968 uint16_t hi, lo;
uci1 56:0bba0ef15697 969 for (uint8_t j=0; j<fNumPlas; j++, pl++) {
uci1 56:0bba0ef15697 970 GetHiLoPlas(*pl, hi, lo);
uci1 56:0bba0ef15697 971 b = SnBitUtils::WriteTo(b, hi);
uci1 56:0bba0ef15697 972 b = SnBitUtils::WriteTo(b, lo);
uci1 56:0bba0ef15697 973 }
uci1 3:24c5f0f50bf1 974 }
uci1 3:24c5f0f50bf1 975 }
uci1 56:0bba0ef15697 976 #endif
uci1 3:24c5f0f50bf1 977 }
uci1 3:24c5f0f50bf1 978
uci1 3:24c5f0f50bf1 979 bool ReadFromFile(const char* cfile);
uci1 3:24c5f0f50bf1 980 bool WriteToFile(const char* cfile) const;
uci1 3:24c5f0f50bf1 981
uci1 3:24c5f0f50bf1 982 void Reset() {
uci1 3:24c5f0f50bf1 983 memset(fLabel, 0, sizeof(char)*kConfLblLen);
uci1 40:1324da35afd4 984 SetHardDefaults();
uci1 67:ec999336fcd1 985 #ifdef USE_INTERFACE_CHIP
uci1 3:24c5f0f50bf1 986 if (ReadFromFile(kDefConfFile)==false) {
uci1 117:fd6798ba2e26 987 // couldn't get setharddefaults. use hardcoded version.
uci1 67:ec999336fcd1 988 // (reset in case a few parameters from the file
uci1 67:ec999336fcd1 989 // got assigned)
uci1 3:24c5f0f50bf1 990 SetHardDefaults();
uci1 3:24c5f0f50bf1 991 }
uci1 67:ec999336fcd1 992 #endif
uci1 16:744ce85aede2 993 #ifdef DEBUG
uci1 16:744ce85aede2 994 printf("config reset to %s\r\n",fLabel);
uci1 16:744ce85aede2 995 #endif
uci1 3:24c5f0f50bf1 996 }
uci1 40:1324da35afd4 997
uci1 84:80b15993944e 998 uint32_t SizeOf(const uint8_t rv=SnConfigFrame::kIOVers) const {
uci1 3:24c5f0f50bf1 999 // returns the num of bytes needed to stream this object
uci1 3:24c5f0f50bf1 1000 // = size of member vars + 1 for i/o version + extra PLA strings (maybe)
uci1 84:80b15993944e 1001 // + length of label string if rv<11
uci1 84:80b15993944e 1002 const uint8_t lbllen = (rv<11) ? strlen(fLabel) : kConfLblLen;
uci1 56:0bba0ef15697 1003 #if CHIPBOARD==ATWD4CH
uci1 84:80b15993944e 1004 return SizeOf(rv, fStreamHiLoPlas!=0, fNumPlas, lbllen);
uci1 56:0bba0ef15697 1005 #else // SST
uci1 84:80b15993944e 1006 return SizeOf(rv, false, 0, lbllen);
uci1 56:0bba0ef15697 1007 #endif
uci1 3:24c5f0f50bf1 1008 }
uci1 40:1324da35afd4 1009
uci1 3:24c5f0f50bf1 1010 static void SetMacAddress();
uci1 3:24c5f0f50bf1 1011 static uint64_t GetMacAddress() {
uci1 116:8099b754fbb4 1012 #ifdef DEBUG
uci1 116:8099b754fbb4 1013 printf("GetMacAddress call: fgMacAdr=%012llX\r\n", fgMacAdr>>16); // 64 -> 48 bits
uci1 116:8099b754fbb4 1014 #endif
uci1 3:24c5f0f50bf1 1015 if (fgMacAdr==0) {
uci1 116:8099b754fbb4 1016 #ifdef DEBUG
uci1 116:8099b754fbb4 1017 printf("Calling SetMacAddress()\r\n");
uci1 116:8099b754fbb4 1018 #endif
uci1 3:24c5f0f50bf1 1019 SetMacAddress();
uci1 3:24c5f0f50bf1 1020 }
uci1 116:8099b754fbb4 1021 #ifdef DEBUG
uci1 116:8099b754fbb4 1022 printf("GetMacAddress return: fgMacAdr=%012llX\r\n", fgMacAdr>>16); // 64 -> 48 bits
uci1 116:8099b754fbb4 1023 #endif
uci1 3:24c5f0f50bf1 1024 return fgMacAdr;
uci1 3:24c5f0f50bf1 1025 }
uci1 3:24c5f0f50bf1 1026
uci1 3:24c5f0f50bf1 1027 static uint32_t GetLabelMaxLen() { return kConfLblLen; }
uci1 3:24c5f0f50bf1 1028
uci1 3:24c5f0f50bf1 1029 static void GetHiLoPlas(const uint16_t pla,
uci1 3:24c5f0f50bf1 1030 uint16_t& hiPla,
uci1 3:24c5f0f50bf1 1031 uint16_t& loPla,
uci1 3:24c5f0f50bf1 1032 const bool r2l=false);
uci1 84:80b15993944e 1033
uci1 84:80b15993944e 1034 static
uci1 84:80b15993944e 1035 void GetIpStrFromVal(const uint32_t ip,
uci1 84:80b15993944e 1036 char(& str)[kIPLen]);
uci1 84:80b15993944e 1037
uci1 84:80b15993944e 1038 static
uci1 84:80b15993944e 1039 uint32_t GetIpValFromStr(const char(& str)[kIPLen]);
uci1 84:80b15993944e 1040
uci1 84:80b15993944e 1041 static
uci1 85:3ced48ef94c5 1042 EDatPackBit GetDataStreamForIndex(const uint8_t idx) {
uci1 85:3ced48ef94c5 1043 switch (idx) {
uci1 85:3ced48ef94c5 1044 case 0: return kSDcard;
uci1 85:3ced48ef94c5 1045 case 1: return kIrid;
uci1 85:3ced48ef94c5 1046 case 2: return kAfar;
uci1 85:3ced48ef94c5 1047 case 3: return kUSB;
uci1 85:3ced48ef94c5 1048 default:
uci1 85:3ced48ef94c5 1049 #ifdef DEBUG
uci1 85:3ced48ef94c5 1050 printf("**** unknown stream idx [%hhu]", idx);
uci1 85:3ced48ef94c5 1051 #endif
uci1 85:3ced48ef94c5 1052 return kSDcard;
uci1 85:3ced48ef94c5 1053 };
uci1 85:3ced48ef94c5 1054 }
uci1 85:3ced48ef94c5 1055
uci1 85:3ced48ef94c5 1056 static
uci1 84:80b15993944e 1057 uint8_t IndexOfDataStream(const SnConfigFrame::EDatPackBit b) {
uci1 84:80b15993944e 1058 switch (b) {
uci1 84:80b15993944e 1059 case kSDcard: return 0u;
uci1 84:80b15993944e 1060 case kIrid: return 1u;
uci1 84:80b15993944e 1061 case kAfar: return 2u;
uci1 84:80b15993944e 1062 case kUSB: return 3u;
uci1 84:80b15993944e 1063 default:
uci1 84:80b15993944e 1064 #ifdef DEBUG
uci1 84:80b15993944e 1065 printf("**** unknown stream bit [%u]", static_cast<uint32_t>(b));
uci1 84:80b15993944e 1066 #endif
uci1 84:80b15993944e 1067 return 0;
uci1 84:80b15993944e 1068 };
uci1 84:80b15993944e 1069 }
uci1 84:80b15993944e 1070
uci1 84:80b15993944e 1071 static
uci1 85:3ced48ef94c5 1072 uint8_t GetDefaultConnTOMinOf(const SnConfigFrame::EDatPackBit b) {
uci1 85:3ced48ef94c5 1073 switch (b) {
uci1 84:80b15993944e 1074 case kSDcard: return 1u;
uci1 84:80b15993944e 1075 case kIrid: return 3u;
uci1 84:80b15993944e 1076 case kAfar: return 1u;
uci1 84:80b15993944e 1077 case kUSB: return 1u;
uci1 84:80b15993944e 1078 default:
uci1 84:80b15993944e 1079 #ifdef DEBUG
uci1 85:3ced48ef94c5 1080 printf("**** unknown stream big [%u]",
uci1 85:3ced48ef94c5 1081 static_cast<uint32_t>(b));
uci1 84:80b15993944e 1082 #endif
uci1 85:3ced48ef94c5 1083 return 3u;
uci1 84:80b15993944e 1084 };
uci1 84:80b15993944e 1085 }
uci1 84:80b15993944e 1086
uci1 84:80b15993944e 1087 static
uci1 85:3ced48ef94c5 1088 uint8_t GetDefaultListTOMinOf(const SnConfigFrame::EDatPackBit b) {
uci1 85:3ced48ef94c5 1089 return GetDefaultConnTOMinOf(b);
uci1 84:80b15993944e 1090 }
uci1 84:80b15993944e 1091
uci1 84:80b15993944e 1092 static
uci1 84:80b15993944e 1093 const char* GetDataStreamName(const SnConfigFrame::EDatPackBit b) {
uci1 84:80b15993944e 1094 switch (b) {
uci1 84:80b15993944e 1095 case kSDcard: return "SDcard";
uci1 84:80b15993944e 1096 case kIrid: return "Iridium";
uci1 84:80b15993944e 1097 case kAfar: return "Afar";
uci1 84:80b15993944e 1098 case kUSB: return "USB";
uci1 84:80b15993944e 1099 default:
uci1 84:80b15993944e 1100 #ifdef DEBUG
uci1 84:80b15993944e 1101 printf("**** unknown stream bit [%u]", static_cast<uint32_t>(b));
uci1 84:80b15993944e 1102 #endif
uci1 84:80b15993944e 1103 return NULL;
uci1 84:80b15993944e 1104 };
uci1 84:80b15993944e 1105 }
uci1 84:80b15993944e 1106
uci1 84:80b15993944e 1107 static
uci1 84:80b15993944e 1108 const char* GetDataStreamNameOfIdx(const uint8_t idx) {
uci1 84:80b15993944e 1109 switch (idx) {
uci1 84:80b15993944e 1110 case 0u: return GetDataStreamName(kSDcard);
uci1 84:80b15993944e 1111 case 1u: return GetDataStreamName(kIrid);
uci1 84:80b15993944e 1112 case 2u: return GetDataStreamName(kAfar);
uci1 84:80b15993944e 1113 case 3u: return GetDataStreamName(kUSB);
uci1 84:80b15993944e 1114 default:
uci1 84:80b15993944e 1115 #ifdef DEBUG
uci1 84:80b15993944e 1116 printf("**** unknown stream index [%hhu]", idx);
uci1 84:80b15993944e 1117 #endif
uci1 84:80b15993944e 1118 return NULL;
uci1 84:80b15993944e 1119 };
uci1 84:80b15993944e 1120 }
uci1 84:80b15993944e 1121
uci1 3:24c5f0f50bf1 1122 };
uci1 3:24c5f0f50bf1 1123
uci1 3:24c5f0f50bf1 1124 #endif // SN_SnConfigFrame