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