Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Wed Aug 08 23:27:37 2012 +0000
Revision:
8:95a325df1f6b
Parent:
3:24c5f0f50bf1
Child:
12:d472f9811262
Check power for low pow running. Average power over 500 readings. Use RTOS timers instead of tickers. Allow data taking of events, power readings or both, even if cards are off. Bug in EthernetInterface prevents IPs being reset. Lots of debug output.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
uci1 0:664899e0b988 1 #ifndef SN_SnEventFrame
uci1 0:664899e0b988 2 #define SN_SnEventFrame
uci1 0:664899e0b988 3
uci1 0:664899e0b988 4 #include <stdint.h>
uci1 0:664899e0b988 5 #include "SnConstants.h"
uci1 0:664899e0b988 6
uci1 0:664899e0b988 7 class SnEventFrame {
uci1 0:664899e0b988 8
uci1 0:664899e0b988 9 public:
uci1 0:664899e0b988 10 // i/o version
uci1 8:95a325df1f6b 11 static const uint8_t kIOVers; // MUST BE INCREASED if any member var changes (==> also if kNchans, etc. change!)
uci1 0:664899e0b988 12 static const uint32_t kMaxSizeOf =
uci1 0:664899e0b988 13 ((sizeof(uint32_t)*4u)+sizeof(int32_t)+sizeof(uint16_t)
uci1 0:664899e0b988 14 +(kTotSamps*sizeof(uint16_t))+1u);
uci1 0:664899e0b988 15
uci1 0:664899e0b988 16 private:
uci1 0:664899e0b988 17 // !!
uci1 0:664899e0b988 18 // !! If any member variables change, update: SizeOf function and kIOVers value! (also if kNchans, etc. change!)
uci1 0:664899e0b988 19 // !!
uci1 0:664899e0b988 20
uci1 0:664899e0b988 21 uint16_t fData[kTotSamps]; // the (uncompressed) waveform data
uci1 0:664899e0b988 22 uint32_t fMbedTime; // mbed time in seconds since epoch
uci1 0:664899e0b988 23 // TODO: time since last event?
uci1 0:664899e0b988 24 uint32_t fEvtNum; // written event number ...
uci1 0:664899e0b988 25 int32_t fDTms; // time since last written event (ms)
uci1 0:664899e0b988 26 uint32_t fTrgNum; // this event is trigger number ...
uci1 0:664899e0b988 27 uint16_t fTrgBits; // trigger bit word
uci1 0:664899e0b988 28 mutable uint32_t fCRC; // CRC on the uncompressed waveform data
uci1 0:664899e0b988 29 // TODO: check if other parameters should be added:
uci1 0:664899e0b988 30 // - stop position?
uci1 0:664899e0b988 31 // - card(s) producing trigger?
uci1 0:664899e0b988 32 // - power & voltage during acquisition?
uci1 0:664899e0b988 33
uci1 0:664899e0b988 34 void CalcCRC();
uci1 0:664899e0b988 35
uci1 0:664899e0b988 36 static
uci1 0:664899e0b988 37 bool ReadFromFileToBuf(FILE* f,
uci1 0:664899e0b988 38 char* const evtBuf,
uci1 0:664899e0b988 39 const uint8_t loseLSB, const uint8_t loseMSB);
uci1 0:664899e0b988 40
uci1 0:664899e0b988 41 static
uci1 0:664899e0b988 42 bool WriteToFileFromBuf(FILE* f, char* const evtBuf,
uci1 0:664899e0b988 43 const uint8_t loseLSB, const uint8_t loseMSB);
uci1 0:664899e0b988 44
uci1 0:664899e0b988 45 public:
uci1 0:664899e0b988 46 SnEventFrame() { ClearEvent(); }
uci1 0:664899e0b988 47 virtual ~SnEventFrame() {}
uci1 0:664899e0b988 48
uci1 0:664899e0b988 49 const uint16_t* GetData() const { return fData; }
uci1 0:664899e0b988 50 uint16_t* GetData() { return fData; }
uci1 0:664899e0b988 51 const uint16_t* GetData(const uint8_t ch) const { return fData + (ch*kNsamps); }
uci1 0:664899e0b988 52 uint16_t* GetData(const uint8_t ch) { return fData + (ch*kNsamps); }
uci1 0:664899e0b988 53 uint16_t GetData(const uint8_t ch, const uint8_t sm) const
uci1 0:664899e0b988 54 { return fData[(ch*kNsamps)+sm]; }
uci1 0:664899e0b988 55 uint16_t& GetData(const uint8_t ch, const uint8_t sm)
uci1 0:664899e0b988 56 { return fData[(ch*kNsamps)+sm]; }
uci1 0:664899e0b988 57
uci1 8:95a325df1f6b 58 uint32_t GetEvtNum() const { return fEvtNum; }
uci1 8:95a325df1f6b 59
uci1 0:664899e0b988 60 void ClearEvent() {
uci1 0:664899e0b988 61 fMbedTime = fEvtNum = fTrgNum = 0;
uci1 0:664899e0b988 62 fTrgBits = 0;
uci1 0:664899e0b988 63 memset(fData, 0, kTotSamps*sizeof(int16_t));
uci1 0:664899e0b988 64 fCRC = 0;
uci1 0:664899e0b988 65 }
uci1 0:664899e0b988 66
uci1 0:664899e0b988 67 void SetTrgBit(const ESnTrgTypes t) { fTrgBits |= kTrgBW[t]; }
uci1 0:664899e0b988 68 void SetTrgNum(const uint32_t t) { fTrgNum = t; }
uci1 0:664899e0b988 69 void SetEvtNum(const uint32_t n) { fEvtNum = n; }
uci1 0:664899e0b988 70 void SetDTms(const int32_t dtms) { fDTms = dtms; }
uci1 0:664899e0b988 71 void SetCurMbedTime() { fMbedTime = time(0); }
uci1 0:664899e0b988 72
uci1 0:664899e0b988 73 bool IsForcedTrg() const { return (fTrgBits & kTrgBW[kFrcTrg])!=0; }
uci1 0:664899e0b988 74
uci1 0:664899e0b988 75 void ReadWaveforms(SPI& spi,
uci1 0:664899e0b988 76 DigitalOut& cardHiBit, DigitalOut& cardLoBit) {
uci1 0:664899e0b988 77 uint16_t* dev=fData;
uci1 0:664899e0b988 78 for( uint8_t ch = 0; ch < kNchans; ch++ ) {
uci1 0:664899e0b988 79 // Pick which register to read.
uci1 0:664899e0b988 80 SnBitUtils::SetChanNumBits(ch, cardHiBit, cardLoBit);
uci1 0:664899e0b988 81 for( uint8_t i = 0; i < kNsamps; i++, dev++ ) {
uci1 0:664899e0b988 82 *dev = spi.write(0x00) >> 1;
uci1 0:664899e0b988 83 //fprintf(stderr,"ch%hhd, s%03hhd = %hd\r\n",ch,i,*dev);
uci1 0:664899e0b988 84 }
uci1 0:664899e0b988 85 }
uci1 0:664899e0b988 86 CalcCRC();
uci1 0:664899e0b988 87 }
uci1 0:664899e0b988 88
uci1 0:664899e0b988 89 static
uci1 8:95a325df1f6b 90 uint32_t SizeOf(const uint8_t rv, const uint8_t loseLSB, const uint8_t loseMSB) {
uci1 0:664899e0b988 91 // size of member vars + size of packed waveform + 1 for i/o version
uci1 0:664899e0b988 92 if ((loseLSB==0) && (loseMSB==0)) {
uci1 0:664899e0b988 93 return kMaxSizeOf;
uci1 0:664899e0b988 94 } else {
uci1 0:664899e0b988 95 return (kMaxSizeOf-(kTotSamps*sizeof(uint16_t))
uci1 0:664899e0b988 96 +SizeOfPackedWavef(loseLSB, loseMSB));
uci1 0:664899e0b988 97 }
uci1 0:664899e0b988 98 }
uci1 0:664899e0b988 99
uci1 0:664899e0b988 100 static
uci1 0:664899e0b988 101 uint32_t SizeOfPackedWavef(const uint8_t loseLSB,
uci1 0:664899e0b988 102 const uint8_t loseMSB) {
uci1 0:664899e0b988 103 const uint8_t p = BITS_IN_SHORT-loseLSB-loseMSB;
uci1 0:664899e0b988 104 return ((p*kTotSamps)/8u) + (((p*kTotSamps)%8u)!=0 ? 1u : 0u);
uci1 0:664899e0b988 105 }
uci1 0:664899e0b988 106
uci1 3:24c5f0f50bf1 107 const char* ReadFrom(const char* const buf,
uci1 3:24c5f0f50bf1 108 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 3:24c5f0f50bf1 109 const uint16_t wvBaseline);
uci1 0:664899e0b988 110
uci1 3:24c5f0f50bf1 111 char* WriteTo(char* const buf,
uci1 3:24c5f0f50bf1 112 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 3:24c5f0f50bf1 113 const uint16_t wvBaseline) const;
uci1 0:664899e0b988 114
uci1 0:664899e0b988 115 bool ReadFrom(FILE* f, char* const evtBuf,
uci1 0:664899e0b988 116 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 0:664899e0b988 117 const uint16_t wvBaseline);
uci1 0:664899e0b988 118 bool WriteTo(FILE* f, char* const evtBuf,
uci1 0:664899e0b988 119 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 0:664899e0b988 120 const uint16_t wvBaseline) const;
uci1 0:664899e0b988 121
uci1 0:664899e0b988 122 static
uci1 0:664899e0b988 123 const uint8_t* UnpackWavef(const uint8_t* const buf,
uci1 0:664899e0b988 124 uint16_t* const data,
uci1 0:664899e0b988 125 const uint8_t loseLSB,
uci1 0:664899e0b988 126 const uint8_t loseMSB,
uci1 0:664899e0b988 127 const uint16_t wvBaseline);
uci1 0:664899e0b988 128
uci1 0:664899e0b988 129 static
uci1 0:664899e0b988 130 uint8_t* PackWavef(uint8_t* const buf, const uint16_t* const data,
uci1 0:664899e0b988 131 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 0:664899e0b988 132 const uint16_t wvBaseline);
uci1 0:664899e0b988 133 };
uci1 0:664899e0b988 134
uci1 0:664899e0b988 135
uci1 0:664899e0b988 136 #endif // SN_SnEventFrame