Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Thu Aug 02 05:42:47 2012 +0000
Revision:
4:a91682e19d6b
Parent:
3:24c5f0f50bf1
Child:
5:9cea89700c66
Add power reading, once per file. Prevent seq number from wrapping around. Still many debugging messages. Communications not finished.

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 3:24c5f0f50bf1 8 class SnConfigFrame {
uci1 3:24c5f0f50bf1 9 public:
uci1 3:24c5f0f50bf1 10 static const uint32_t kMinCommWinPrdLowPwr; // exclusive min low power comm win period (s)
uci1 3:24c5f0f50bf1 11 static const uint32_t kMaxCommWinPrdLowPwr; // exclusive max low power comm win period (s)
uci1 3:24c5f0f50bf1 12 static const uint32_t kMinCommWinDurLowPwr; // exclusive min low power comm win duration (s)
uci1 3:24c5f0f50bf1 13 static const uint32_t kMaxCommWinDurLowPwr; // exclusive max low power comm win duration (s)
uci1 3:24c5f0f50bf1 14 static const uint8_t kConfLblLen=64; // length of configuration label char array (63+'\0')
uci1 3:24c5f0f50bf1 15
uci1 3:24c5f0f50bf1 16 static const char* const kDefConfFile; // default configuration file
uci1 3:24c5f0f50bf1 17
uci1 3:24c5f0f50bf1 18 static const uint32_t kMaxSizeOf =
uci1 3:24c5f0f50bf1 19 + (10u*sizeof(uint32_t)) + (6u*sizeof(uint16_t))
uci1 3:24c5f0f50bf1 20 + (11u*sizeof(uint8_t)) + (3u*kNplas*sizeof(uint16_t))
uci1 3:24c5f0f50bf1 21 + (kTotDacs*sizeof(uint16_t))
uci1 3:24c5f0f50bf1 22 + (kConfLblLen*sizeof(uint8_t));
uci1 3:24c5f0f50bf1 23
uci1 3:24c5f0f50bf1 24
uci1 3:24c5f0f50bf1 25 enum EDatPackBit {
uci1 3:24c5f0f50bf1 26 kSDcard = BIT(0),
uci1 3:24c5f0f50bf1 27 kIrid = BIT(1),
uci1 3:24c5f0f50bf1 28 kAfar = BIT(2),
uci1 3:24c5f0f50bf1 29 kUSB = BIT(3)
uci1 3:24c5f0f50bf1 30 };
uci1 3:24c5f0f50bf1 31
uci1 3:24c5f0f50bf1 32 enum ESendDataBit {
uci1 3:24c5f0f50bf1 33 // can't use BIT(0)! (-0 = 0 => send nothing)
uci1 3:24c5f0f50bf1 34 kAllFiles = BIT(1), // if bit=0 => send most recent file
uci1 3:24c5f0f50bf1 35 kTimeout = BIT(2), // if bit=0 => ignore timeout
uci1 3:24c5f0f50bf1 36 kDelete = BIT(3), // if bit=0 => do not delete sent files
uci1 3:24c5f0f50bf1 37 kUseBits = -BIT(10) // useful to initialize fCommSendData as a bit word
uci1 3:24c5f0f50bf1 38 };
uci1 3:24c5f0f50bf1 39
uci1 4:a91682e19d6b 40 enum EPowerModeBit {
uci1 4:a91682e19d6b 41 kAmpsDatTak = BIT(0),
uci1 4:a91682e19d6b 42 kCardDatTak = BIT(1),
uci1 4:a91682e19d6b 43 kIridDatTak = BIT(2),
uci1 4:a91682e19d6b 44 kAfarDatTak = BIT(3),
uci1 4:a91682e19d6b 45 kAmpsComWin = BIT(4),
uci1 4:a91682e19d6b 46 kCardComWin = BIT(5),
uci1 4:a91682e19d6b 47 kIridComWin = BIT(6),
uci1 4:a91682e19d6b 48 kAfarComWin = BIT(7)
uci1 4:a91682e19d6b 49 };
uci1 4:a91682e19d6b 50
uci1 3:24c5f0f50bf1 51 enum ERunMode {
uci1 3:24c5f0f50bf1 52 kInfSeqs = 0,
uci1 3:24c5f0f50bf1 53 kSingleSeq = 1
uci1 3:24c5f0f50bf1 54 };
uci1 3:24c5f0f50bf1 55
uci1 3:24c5f0f50bf1 56 // i/o version
uci1 3:24c5f0f50bf1 57 static const uint8_t kIOVers; // MUST BE INCREASED if any member var changes (==> also if kNchans, etc. change!)
uci1 3:24c5f0f50bf1 58
uci1 3:24c5f0f50bf1 59 private:
uci1 3:24c5f0f50bf1 60 // !!
uci1 3:24c5f0f50bf1 61 // !! If any member variables change, update: SizeOf function and kIOVers value! (also if kNchans, etc. change!)
uci1 3:24c5f0f50bf1 62 // !!
uci1 3:24c5f0f50bf1 63
uci1 3:24c5f0f50bf1 64 // mbed mac address
uci1 3:24c5f0f50bf1 65 static uint64_t fgMacAdr; // mbed mac address
uci1 3:24c5f0f50bf1 66 // conf header
uci1 3:24c5f0f50bf1 67 char fLabel[kConfLblLen]; // configuration label
uci1 3:24c5f0f50bf1 68 uint32_t fConfTime; // cpu config time
uci1 3:24c5f0f50bf1 69 uint32_t fRun; // run number
uci1 3:24c5f0f50bf1 70 uint32_t fFirstEvt; // starting event number
uci1 3:24c5f0f50bf1 71 uint32_t fEvtsPerSeq; // number of events per file
uci1 3:24c5f0f50bf1 72 uint8_t fRunMode; // mode of running (see ERunMode)
uci1 3:24c5f0f50bf1 73 uint8_t fStreamHiLoPlas; // (1byte bool) if true, add the separated hi/lo thresh PLA patterns to the i/o
uci1 3:24c5f0f50bf1 74 // data packing
uci1 3:24c5f0f50bf1 75 uint8_t fWvLoseLSB; // number of least significant bits to lose when packing waveform data
uci1 3:24c5f0f50bf1 76 uint8_t fWvLoseMSB; // number of most significant bits to lose when packing waveform data
uci1 3:24c5f0f50bf1 77 uint16_t fWvBaseline; // global baseline to use when packing data (useful to reduce clipping on the high end)
uci1 3:24c5f0f50bf1 78 uint8_t fDatPackType; // type of data packing. OR'd bitword: if bit 1, will pack for writing. see EDatPackBit. default: always pack (all 1's)
uci1 3:24c5f0f50bf1 79 // trigger setup
uci1 3:24c5f0f50bf1 80 uint16_t fDAC[kNchans][kNfpgaDacs]; //[card id][dac id] values should be 0-4095 here (not checked tho)
uci1 3:24c5f0f50bf1 81 uint8_t fNumPlas; // number of patterns to use. must be <= kNplas.
uci1 3:24c5f0f50bf1 82 uint16_t fPLA[kNplas]; //[pattern id] (same for each card)
uci1 3:24c5f0f50bf1 83 uint8_t fNumCardsMajLog; // number of cards participating in the MajLogic trigger (1 to 4)
uci1 3:24c5f0f50bf1 84 uint8_t fEnableThermTrig; // (1byte bool) whether or not to allow thermal triggers
uci1 3:24c5f0f50bf1 85 uint16_t fForceTrigPeriod; // number of seconds between force triggers (0=none)
uci1 3:24c5f0f50bf1 86 uint16_t fHeartBeatPeriod; // number of seconds between heartbeats (0=none)
uci1 3:24c5f0f50bf1 87 uint8_t fAmpsOn; // which amps are on (bit word. uint8_t => 8 amps max)
uci1 3:24c5f0f50bf1 88 uint16_t fEvtThrtlPeriodMs; // throttle period to write events (ms)
uci1 3:24c5f0f50bf1 89 // power
uci1 4:a91682e19d6b 90 uint8_t fPowerMode; // power mode bit word: see EPowerModeBit
uci1 3:24c5f0f50bf1 91 int16_t fBatVoltLowPwr; // battery level at which to switch to low power (not used?)
uci1 3:24c5f0f50bf1 92 // communication
uci1 3:24c5f0f50bf1 93 uint32_t fCommWinPeriod; // seconds between communication window startup (0=always on)
uci1 3:24c5f0f50bf1 94 uint32_t fCommWinDuration; // seconds that communication window stays open (0=always open)
uci1 3:24c5f0f50bf1 95 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 96 uint32_t fCommWinPrdLowPwr; // low power communication window period (seconds) (range enforced)
uci1 3:24c5f0f50bf1 97 uint32_t fCommWinDurLowPwr; // low power communication window duration (seconds) (range enforced)
uci1 3:24c5f0f50bf1 98 // watchdog
uci1 3:24c5f0f50bf1 99 uint32_t fWatchDogPeriod; // number of seconds of inactivity for watchdog to issue a reset
uci1 3:24c5f0f50bf1 100
uci1 3:24c5f0f50bf1 101 void SetHardDefaults();
uci1 3:24c5f0f50bf1 102
uci1 3:24c5f0f50bf1 103 static
uci1 3:24c5f0f50bf1 104 uint32_t SizeOf(const bool streamHiLoPlas,
uci1 3:24c5f0f50bf1 105 const uint8_t nplas,
uci1 3:24c5f0f50bf1 106 const uint8_t lblLen) {
uci1 3:24c5f0f50bf1 107 // private because it cannot be used to read from a buffer
uci1 3:24c5f0f50bf1 108 // (the label length and fStreamHiLoPlas are not known a priori)
uci1 3:24c5f0f50bf1 109 // returns the num of bytes needed to stream this object
uci1 3:24c5f0f50bf1 110 // = size of member vars + 1 for i/o version + extra PLA strings (maybe)
uci1 3:24c5f0f50bf1 111 uint32_t sz = kMaxSizeOf - kConfLblLen + lblLen;
uci1 3:24c5f0f50bf1 112 static const uint32_t mhlp = 2u*kNplas*sizeof(uint16_t);
uci1 3:24c5f0f50bf1 113 const int32_t dp = (nplas-kNplas)*sizeof(uint16_t);
uci1 3:24c5f0f50bf1 114 const uint8_t fac = (streamHiLoPlas) ? 3u : 1u;
uci1 3:24c5f0f50bf1 115 sz += (fac*dp);
uci1 3:24c5f0f50bf1 116 if (streamHiLoPlas==false) {
uci1 3:24c5f0f50bf1 117 sz -= mhlp;
uci1 3:24c5f0f50bf1 118 }
uci1 3:24c5f0f50bf1 119 return sz;
uci1 3:24c5f0f50bf1 120 }
uci1 3:24c5f0f50bf1 121
uci1 3:24c5f0f50bf1 122 public:
uci1 3:24c5f0f50bf1 123 SnConfigFrame() { Reset(); }
uci1 3:24c5f0f50bf1 124 virtual ~SnConfigFrame() {}
uci1 3:24c5f0f50bf1 125
uci1 3:24c5f0f50bf1 126 const char* GetLabel() const { return fLabel; }
uci1 3:24c5f0f50bf1 127 uint32_t GetLabelStrLen() const { return strlen(fLabel); }
uci1 3:24c5f0f50bf1 128 uint32_t GetRun() const { return fRun; }
uci1 3:24c5f0f50bf1 129 uint32_t GetFirstEvt() const { return fFirstEvt; }
uci1 3:24c5f0f50bf1 130 uint32_t GetEvtsPerFile() const { return fEvtsPerSeq; }
uci1 3:24c5f0f50bf1 131 bool IsSingleSeqRunMode() const { return fRunMode==kSingleSeq; }
uci1 3:24c5f0f50bf1 132 uint16_t GetEvtThrtlPeriodMs() const { return fEvtThrtlPeriodMs; }
uci1 3:24c5f0f50bf1 133 uint16_t GetForceTrigPeriod() const { return fForceTrigPeriod; }
uci1 3:24c5f0f50bf1 134 uint16_t GetHeartbeatPeriod() const { return fHeartBeatPeriod; }
uci1 3:24c5f0f50bf1 135 uint32_t GetWatchdogPeriod() const { return fWatchDogPeriod; }
uci1 3:24c5f0f50bf1 136 uint16_t GetDac(const uint8_t ch, const uint8_t dn) const { return fDAC[ch][dn]; }
uci1 3:24c5f0f50bf1 137 uint8_t GetNumPlas() const { return fNumPlas; }
uci1 3:24c5f0f50bf1 138 uint16_t GetPla(const uint8_t pn) const { return fPLA[pn]; }
uci1 3:24c5f0f50bf1 139 uint8_t GetNumCardsMajLog() const { return fNumCardsMajLog; }
uci1 3:24c5f0f50bf1 140 bool IsThermTrigEnabled() const { return fEnableThermTrig!=0; }
uci1 3:24c5f0f50bf1 141 bool IsEachAmpOn() const {
uci1 3:24c5f0f50bf1 142 bool allon=true;
uci1 3:24c5f0f50bf1 143 for (uint8_t i=0; (i<kNchans) && allon; i++) {
uci1 3:24c5f0f50bf1 144 allon = (fAmpsOn & BIT(i))!=0;
uci1 3:24c5f0f50bf1 145 }
uci1 3:24c5f0f50bf1 146 return allon;
uci1 3:24c5f0f50bf1 147 }
uci1 3:24c5f0f50bf1 148 // TODO: allow check for individual amps, when they can be turned on individually
uci1 3:24c5f0f50bf1 149
uci1 3:24c5f0f50bf1 150 uint32_t GetCommWinPeriod() const { return fCommWinPeriod; }
uci1 3:24c5f0f50bf1 151 uint32_t GetCommWinDuration() const { return fCommWinDuration; }
uci1 3:24c5f0f50bf1 152 int16_t GetCommSendData() const { return fCommSendData; }
uci1 3:24c5f0f50bf1 153
uci1 3:24c5f0f50bf1 154 bool IsSendingAllFiles() const
uci1 3:24c5f0f50bf1 155 { return (fCommSendData<0) && ((fCommSendData & kAllFiles)!=0); }
uci1 3:24c5f0f50bf1 156 bool IsObeyingTimeout() const
uci1 3:24c5f0f50bf1 157 { return (fCommSendData<0) && ((fCommSendData & kTimeout)!=0); }
uci1 3:24c5f0f50bf1 158 bool IsDeletingFiles() const
uci1 3:24c5f0f50bf1 159 { return (fCommSendData<0) && ((fCommSendData & kDelete)!=0); }
uci1 3:24c5f0f50bf1 160
uci1 4:a91682e19d6b 161 uint8_t GetPowerMode() const { return fPowerMode; }
uci1 4:a91682e19d6b 162 int IsPoweredFor(const EPowerModeBit p) { return ((fPowerMode & p)!=0) ? 1 : 0; }
uci1 3:24c5f0f50bf1 163
uci1 3:24c5f0f50bf1 164 const char* GetOutFileName(const char* dir) const;
uci1 3:24c5f0f50bf1 165
uci1 3:24c5f0f50bf1 166 // waveform packing info
uci1 3:24c5f0f50bf1 167 uint16_t GetWvBaseline() const { return fWvBaseline; }
uci1 3:24c5f0f50bf1 168 uint8_t GetWvLoseLSB() const { return fWvLoseLSB; }
uci1 3:24c5f0f50bf1 169 uint8_t GetWvLoseMSB() const { return fWvLoseMSB; }
uci1 3:24c5f0f50bf1 170 bool IsDatPackedFor(const EDatPackBit d) const { return (fDatPackType & d)!=0; }
uci1 3:24c5f0f50bf1 171 void GetPackParsFor(const EDatPackBit d,
uci1 3:24c5f0f50bf1 172 uint8_t& loseLSB, uint8_t& loseMSB,
uci1 3:24c5f0f50bf1 173 uint16_t& wvBase) const;
uci1 3:24c5f0f50bf1 174
uci1 3:24c5f0f50bf1 175 // i/o
uci1 3:24c5f0f50bf1 176 template<class T>
uci1 3:24c5f0f50bf1 177 void ReadFrom(T& b) {
uci1 3:24c5f0f50bf1 178 // no check on the length of buf is done here
uci1 3:24c5f0f50bf1 179 // that should be been done already
uci1 3:24c5f0f50bf1 180 //
uci1 3:24c5f0f50bf1 181 // must match WriteTo
uci1 3:24c5f0f50bf1 182
uci1 3:24c5f0f50bf1 183 uint8_t Rv=0;
uci1 3:24c5f0f50bf1 184 b = SnBitUtils::ReadFrom(b, Rv); // i/o version
uci1 3:24c5f0f50bf1 185 printf("Rv=%hhu\r\n",Rv);
uci1 3:24c5f0f50bf1 186 if (Rv>0) {
uci1 3:24c5f0f50bf1 187 uint32_t llen=kConfLblLen;
uci1 3:24c5f0f50bf1 188 b = SnBitUtils::ReadFrom(b, llen);
uci1 3:24c5f0f50bf1 189 printf("llen=%u\r\n",llen);
uci1 3:24c5f0f50bf1 190 b = SnBitUtils::ReadFrom(b, fLabel, llen);
uci1 3:24c5f0f50bf1 191 printf("lbl=%s\r\n",fLabel);
uci1 3:24c5f0f50bf1 192 b = SnBitUtils::ReadFrom(b, fConfTime);
uci1 3:24c5f0f50bf1 193 printf("ct=%u\r\n",fConfTime);
uci1 3:24c5f0f50bf1 194 b = SnBitUtils::ReadFrom(b, fRun);
uci1 3:24c5f0f50bf1 195 printf("run=%u\r\n",fRun);
uci1 3:24c5f0f50bf1 196 b = SnBitUtils::ReadFrom(b, fFirstEvt);
uci1 3:24c5f0f50bf1 197 printf("fe=%u\r\n",fFirstEvt);
uci1 3:24c5f0f50bf1 198 if (Rv>1) {
uci1 3:24c5f0f50bf1 199 b = SnBitUtils::ReadFrom(b, fEvtsPerSeq);
uci1 3:24c5f0f50bf1 200 printf("eps=%u\r\n",fEvtsPerSeq);
uci1 3:24c5f0f50bf1 201 b = SnBitUtils::ReadFrom(b, fRunMode);
uci1 3:24c5f0f50bf1 202 printf("rm=%hhu\r\n",fRunMode);
uci1 3:24c5f0f50bf1 203 }
uci1 3:24c5f0f50bf1 204 b = SnBitUtils::ReadFrom(b, fStreamHiLoPlas);
uci1 3:24c5f0f50bf1 205 printf("shilo=%d\r\n",(int)fStreamHiLoPlas);
uci1 3:24c5f0f50bf1 206 b = SnBitUtils::ReadFrom(b, fWvLoseLSB);
uci1 3:24c5f0f50bf1 207 printf("lsb=%hhu\r\n",fWvLoseLSB);
uci1 3:24c5f0f50bf1 208 b = SnBitUtils::ReadFrom(b, fWvLoseMSB);
uci1 3:24c5f0f50bf1 209 printf("msb=%hhu\r\n",fWvLoseMSB);
uci1 3:24c5f0f50bf1 210 b = SnBitUtils::ReadFrom(b, fWvBaseline);
uci1 3:24c5f0f50bf1 211 printf("bl=%hu\r\n",fWvBaseline);
uci1 3:24c5f0f50bf1 212 b = SnBitUtils::ReadFrom(b, fDatPackType);
uci1 3:24c5f0f50bf1 213 printf("dp=%hhu\r\n",fDatPackType);
uci1 3:24c5f0f50bf1 214 uint16_t* dc = &(fDAC[0][0]);
uci1 3:24c5f0f50bf1 215 for (uint16_t i=0; i<kTotDacs; i++, dc++) {
uci1 3:24c5f0f50bf1 216 b = SnBitUtils::ReadFrom(b, *dc);
uci1 3:24c5f0f50bf1 217 printf("dac[%hu]=%hu\r\n",i,*dc);
uci1 3:24c5f0f50bf1 218 }
uci1 3:24c5f0f50bf1 219 b = SnBitUtils::ReadFrom(b, fNumPlas);
uci1 3:24c5f0f50bf1 220 printf("npla=%hhu\r\n",fNumPlas);
uci1 3:24c5f0f50bf1 221 uint16_t* pl = &(fPLA[0]);
uci1 3:24c5f0f50bf1 222 for (uint8_t j=0; j<fNumPlas; j++, pl++) {
uci1 3:24c5f0f50bf1 223 b = SnBitUtils::ReadFrom(b, *pl);
uci1 3:24c5f0f50bf1 224 printf("pla[%hhu]=%hu\r\n",j,*pl);
uci1 3:24c5f0f50bf1 225 }
uci1 3:24c5f0f50bf1 226 b = SnBitUtils::ReadFrom(b, fNumCardsMajLog);
uci1 3:24c5f0f50bf1 227 printf("mj=%hhu\r\n",fNumCardsMajLog);
uci1 3:24c5f0f50bf1 228 b = SnBitUtils::ReadFrom(b, fEnableThermTrig);
uci1 3:24c5f0f50bf1 229 printf("thm=%d\r\n",(int)fEnableThermTrig);
uci1 3:24c5f0f50bf1 230 b = SnBitUtils::ReadFrom(b, fForceTrigPeriod);
uci1 3:24c5f0f50bf1 231 printf("force=%hu\r\n",fForceTrigPeriod);
uci1 3:24c5f0f50bf1 232 b = SnBitUtils::ReadFrom(b, fHeartBeatPeriod);
uci1 3:24c5f0f50bf1 233 printf("heart=%hu\r\n",fHeartBeatPeriod);
uci1 3:24c5f0f50bf1 234 b = SnBitUtils::ReadFrom(b, fAmpsOn);
uci1 3:24c5f0f50bf1 235 printf("amps=%hhu\r\n",fAmpsOn);
uci1 3:24c5f0f50bf1 236 b = SnBitUtils::ReadFrom(b, fEvtThrtlPeriodMs);
uci1 3:24c5f0f50bf1 237 printf("throt=%hu\r\n",fEvtThrtlPeriodMs);
uci1 3:24c5f0f50bf1 238 b = SnBitUtils::ReadFrom(b, fPowerMode);
uci1 3:24c5f0f50bf1 239 printf("pow=%hhu\r\n",fPowerMode);
uci1 3:24c5f0f50bf1 240 b = SnBitUtils::ReadFrom(b, fBatVoltLowPwr);
uci1 3:24c5f0f50bf1 241 printf("batlow=%d\r\n",fBatVoltLowPwr);
uci1 3:24c5f0f50bf1 242 b = SnBitUtils::ReadFrom(b, fCommWinPeriod);
uci1 3:24c5f0f50bf1 243 printf("cmper=%u\r\n",fCommWinPeriod);
uci1 3:24c5f0f50bf1 244 b = SnBitUtils::ReadFrom(b, fCommWinDuration);
uci1 3:24c5f0f50bf1 245 printf("cmdur=%u\r\n",fCommWinDuration);
uci1 3:24c5f0f50bf1 246 b = SnBitUtils::ReadFrom(b, fCommSendData);
uci1 3:24c5f0f50bf1 247 printf("send=%d\r\n",fCommSendData);
uci1 3:24c5f0f50bf1 248 b = SnBitUtils::ReadFrom(b, fCommWinPrdLowPwr);
uci1 3:24c5f0f50bf1 249 printf("cmperlp=%u\r\n",fCommWinPrdLowPwr);
uci1 3:24c5f0f50bf1 250 b = SnBitUtils::ReadFrom(b, fCommWinDurLowPwr);
uci1 3:24c5f0f50bf1 251 printf("cmdurlp=%u\r\n",fCommWinDurLowPwr);
uci1 3:24c5f0f50bf1 252 b = SnBitUtils::ReadFrom(b, fWatchDogPeriod);
uci1 3:24c5f0f50bf1 253 printf("watch=%u\r\n",fWatchDogPeriod);
uci1 3:24c5f0f50bf1 254 if (fStreamHiLoPlas!=0) {
uci1 3:24c5f0f50bf1 255 uint16_t hi, lo;
uci1 3:24c5f0f50bf1 256 for (uint8_t j=0; j<fNumPlas; j++) {
uci1 3:24c5f0f50bf1 257 b = SnBitUtils::ReadFrom(b, hi);
uci1 3:24c5f0f50bf1 258 printf("hi=%hu\r\n",hi);
uci1 3:24c5f0f50bf1 259 b = SnBitUtils::ReadFrom(b, lo);
uci1 3:24c5f0f50bf1 260 printf("lo=%hu\r\n",lo);
uci1 3:24c5f0f50bf1 261 // don't save these
uci1 3:24c5f0f50bf1 262 }
uci1 3:24c5f0f50bf1 263 }
uci1 3:24c5f0f50bf1 264 }
uci1 3:24c5f0f50bf1 265 printf("read from done\r\n");
uci1 3:24c5f0f50bf1 266 }
uci1 3:24c5f0f50bf1 267
uci1 3:24c5f0f50bf1 268 template <class T>
uci1 3:24c5f0f50bf1 269 void WriteTo(T& b) const {
uci1 3:24c5f0f50bf1 270 // no check on the length of the buf is done here
uci1 3:24c5f0f50bf1 271 // that should be done already
uci1 3:24c5f0f50bf1 272 //
uci1 3:24c5f0f50bf1 273 // must match ReadFromBuf
uci1 3:24c5f0f50bf1 274 //
uci1 3:24c5f0f50bf1 275 // intentionally not writing mac address here, so we don't have to read it in
uci1 3:24c5f0f50bf1 276
uci1 3:24c5f0f50bf1 277 const uint32_t llen = strlen(fLabel);
uci1 3:24c5f0f50bf1 278
uci1 3:24c5f0f50bf1 279 b = SnBitUtils::WriteTo(b, kIOVers); // i/o version
uci1 3:24c5f0f50bf1 280 b = SnBitUtils::WriteTo(b, llen);
uci1 3:24c5f0f50bf1 281 b = SnBitUtils::WriteTo(b, fLabel, llen);
uci1 3:24c5f0f50bf1 282 b = SnBitUtils::WriteTo(b, fConfTime);
uci1 3:24c5f0f50bf1 283 b = SnBitUtils::WriteTo(b, fRun);
uci1 3:24c5f0f50bf1 284 b = SnBitUtils::WriteTo(b, fFirstEvt);
uci1 3:24c5f0f50bf1 285 b = SnBitUtils::WriteTo(b, fEvtsPerSeq);
uci1 3:24c5f0f50bf1 286 b = SnBitUtils::WriteTo(b, fRunMode);
uci1 3:24c5f0f50bf1 287 b = SnBitUtils::WriteTo(b, fStreamHiLoPlas);
uci1 3:24c5f0f50bf1 288 b = SnBitUtils::WriteTo(b, fWvLoseLSB);
uci1 3:24c5f0f50bf1 289 b = SnBitUtils::WriteTo(b, fWvLoseMSB);
uci1 3:24c5f0f50bf1 290 b = SnBitUtils::WriteTo(b, fWvBaseline);
uci1 3:24c5f0f50bf1 291 b = SnBitUtils::WriteTo(b, fDatPackType);
uci1 3:24c5f0f50bf1 292 const uint16_t* dc = &(fDAC[0][0]);
uci1 3:24c5f0f50bf1 293 for (uint16_t i=0; i<kTotDacs; i++, dc++) {
uci1 3:24c5f0f50bf1 294 b = SnBitUtils::WriteTo(b, *dc);
uci1 3:24c5f0f50bf1 295 }
uci1 3:24c5f0f50bf1 296 b = SnBitUtils::WriteTo(b, fNumPlas);
uci1 3:24c5f0f50bf1 297 const uint16_t* pl = &(fPLA[0]);
uci1 3:24c5f0f50bf1 298 for (uint8_t j=0; j<fNumPlas; j++, pl++) {
uci1 3:24c5f0f50bf1 299 b = SnBitUtils::WriteTo(b, *pl);
uci1 3:24c5f0f50bf1 300 }
uci1 3:24c5f0f50bf1 301 b = SnBitUtils::WriteTo(b, fNumCardsMajLog);
uci1 3:24c5f0f50bf1 302 b = SnBitUtils::WriteTo(b, fEnableThermTrig);
uci1 3:24c5f0f50bf1 303 b = SnBitUtils::WriteTo(b, fForceTrigPeriod);
uci1 3:24c5f0f50bf1 304 b = SnBitUtils::WriteTo(b, fHeartBeatPeriod);
uci1 3:24c5f0f50bf1 305 b = SnBitUtils::WriteTo(b, fAmpsOn);
uci1 3:24c5f0f50bf1 306 b = SnBitUtils::WriteTo(b, fEvtThrtlPeriodMs);
uci1 3:24c5f0f50bf1 307 b = SnBitUtils::WriteTo(b, fPowerMode);
uci1 3:24c5f0f50bf1 308 b = SnBitUtils::WriteTo(b, fBatVoltLowPwr);
uci1 3:24c5f0f50bf1 309 b = SnBitUtils::WriteTo(b, fCommWinPeriod);
uci1 3:24c5f0f50bf1 310 b = SnBitUtils::WriteTo(b, fCommWinDuration);
uci1 3:24c5f0f50bf1 311 b = SnBitUtils::WriteTo(b, fCommSendData);
uci1 3:24c5f0f50bf1 312 b = SnBitUtils::WriteTo(b, fCommWinPrdLowPwr);
uci1 3:24c5f0f50bf1 313 b = SnBitUtils::WriteTo(b, fCommWinDurLowPwr);
uci1 3:24c5f0f50bf1 314 b = SnBitUtils::WriteTo(b, fWatchDogPeriod);
uci1 3:24c5f0f50bf1 315 if (fStreamHiLoPlas!=0) {
uci1 3:24c5f0f50bf1 316 pl = fPLA;
uci1 3:24c5f0f50bf1 317 uint16_t hi, lo;
uci1 3:24c5f0f50bf1 318 for (uint8_t j=0; j<fNumPlas; j++, pl++) {
uci1 3:24c5f0f50bf1 319 GetHiLoPlas(*pl, hi, lo);
uci1 3:24c5f0f50bf1 320 b = SnBitUtils::WriteTo(b, hi);
uci1 3:24c5f0f50bf1 321 b = SnBitUtils::WriteTo(b, lo);
uci1 3:24c5f0f50bf1 322 }
uci1 3:24c5f0f50bf1 323 }
uci1 3:24c5f0f50bf1 324 }
uci1 3:24c5f0f50bf1 325
uci1 3:24c5f0f50bf1 326 bool ReadFromFile(const char* cfile);
uci1 3:24c5f0f50bf1 327 bool WriteToFile(const char* cfile) const;
uci1 3:24c5f0f50bf1 328
uci1 3:24c5f0f50bf1 329 void Reset() {
uci1 3:24c5f0f50bf1 330 memset(fLabel, 0, sizeof(char)*kConfLblLen);
uci1 3:24c5f0f50bf1 331 if (ReadFromFile(kDefConfFile)==false) {
uci1 3:24c5f0f50bf1 332 // couldn't get default. use hardcoded version.
uci1 3:24c5f0f50bf1 333 SetHardDefaults();
uci1 3:24c5f0f50bf1 334 }
uci1 3:24c5f0f50bf1 335 }
uci1 3:24c5f0f50bf1 336
uci1 3:24c5f0f50bf1 337 uint32_t SizeOf() const {
uci1 3:24c5f0f50bf1 338 // returns the num of bytes needed to stream this object
uci1 3:24c5f0f50bf1 339 // = size of member vars + 1 for i/o version + extra PLA strings (maybe)
uci1 3:24c5f0f50bf1 340 // + length of label string
uci1 3:24c5f0f50bf1 341 return SizeOf(fStreamHiLoPlas!=0, fNumPlas, strlen(fLabel));
uci1 3:24c5f0f50bf1 342 }
uci1 3:24c5f0f50bf1 343
uci1 3:24c5f0f50bf1 344 static void SetMacAddress();
uci1 3:24c5f0f50bf1 345 static uint64_t GetMacAddress() {
uci1 3:24c5f0f50bf1 346 if (fgMacAdr==0) {
uci1 3:24c5f0f50bf1 347 SetMacAddress();
uci1 3:24c5f0f50bf1 348 }
uci1 3:24c5f0f50bf1 349 return fgMacAdr;
uci1 3:24c5f0f50bf1 350 }
uci1 3:24c5f0f50bf1 351
uci1 3:24c5f0f50bf1 352 static uint32_t GetLabelMaxLen() { return kConfLblLen; }
uci1 3:24c5f0f50bf1 353
uci1 3:24c5f0f50bf1 354 static void GetHiLoPlas(const uint16_t pla,
uci1 3:24c5f0f50bf1 355 uint16_t& hiPla,
uci1 3:24c5f0f50bf1 356 uint16_t& loPla,
uci1 3:24c5f0f50bf1 357 const bool r2l=false);
uci1 3:24c5f0f50bf1 358 };
uci1 3:24c5f0f50bf1 359
uci1 3:24c5f0f50bf1 360 #endif // SN_SnConfigFrame