Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Fri Jul 20 19:04:02 2012 +0000
Revision:
1:e392595b4b76
Parent:
0:664899e0b988
Child:
3:24c5f0f50bf1
many features checked and working. afar implemented. sending of data not yet tested. contains many debug prints

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 1:e392595b4b76 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 0:664899e0b988 58 void ClearEvent() {
uci1 0:664899e0b988 59 fMbedTime = fEvtNum = fTrgNum = 0;
uci1 0:664899e0b988 60 fTrgBits = 0;
uci1 0:664899e0b988 61 memset(fData, 0, kTotSamps*sizeof(int16_t));
uci1 0:664899e0b988 62 fCRC = 0;
uci1 0:664899e0b988 63 }
uci1 0:664899e0b988 64
uci1 0:664899e0b988 65 void SetTrgBit(const ESnTrgTypes t) { fTrgBits |= kTrgBW[t]; }
uci1 0:664899e0b988 66 void SetTrgNum(const uint32_t t) { fTrgNum = t; }
uci1 0:664899e0b988 67 void SetEvtNum(const uint32_t n) { fEvtNum = n; }
uci1 0:664899e0b988 68 void SetDTms(const int32_t dtms) { fDTms = dtms; }
uci1 0:664899e0b988 69 void SetCurMbedTime() { fMbedTime = time(0); }
uci1 0:664899e0b988 70
uci1 0:664899e0b988 71 bool IsForcedTrg() const { return (fTrgBits & kTrgBW[kFrcTrg])!=0; }
uci1 0:664899e0b988 72
uci1 0:664899e0b988 73 void ReadWaveforms(SPI& spi,
uci1 0:664899e0b988 74 DigitalOut& cardHiBit, DigitalOut& cardLoBit) {
uci1 0:664899e0b988 75 uint16_t* dev=fData;
uci1 0:664899e0b988 76 for( uint8_t ch = 0; ch < kNchans; ch++ ) {
uci1 0:664899e0b988 77 // Pick which register to read.
uci1 0:664899e0b988 78 SnBitUtils::SetChanNumBits(ch, cardHiBit, cardLoBit);
uci1 0:664899e0b988 79 for( uint8_t i = 0; i < kNsamps; i++, dev++ ) {
uci1 0:664899e0b988 80 *dev = spi.write(0x00) >> 1;
uci1 0:664899e0b988 81 //fprintf(stderr,"ch%hhd, s%03hhd = %hd\r\n",ch,i,*dev);
uci1 0:664899e0b988 82 }
uci1 0:664899e0b988 83 }
uci1 0:664899e0b988 84 CalcCRC();
uci1 0:664899e0b988 85 }
uci1 0:664899e0b988 86
uci1 0:664899e0b988 87 static
uci1 0:664899e0b988 88 uint32_t SizeOf(const uint8_t loseLSB, const uint8_t loseMSB) {
uci1 0:664899e0b988 89 // size of member vars + size of packed waveform + 1 for i/o version
uci1 0:664899e0b988 90 if ((loseLSB==0) && (loseMSB==0)) {
uci1 0:664899e0b988 91 return kMaxSizeOf;
uci1 0:664899e0b988 92 } else {
uci1 0:664899e0b988 93 return (kMaxSizeOf-(kTotSamps*sizeof(uint16_t))
uci1 0:664899e0b988 94 +SizeOfPackedWavef(loseLSB, loseMSB));
uci1 0:664899e0b988 95 }
uci1 0:664899e0b988 96 }
uci1 0:664899e0b988 97
uci1 0:664899e0b988 98 static
uci1 0:664899e0b988 99 uint32_t SizeOfPackedWavef(const uint8_t loseLSB,
uci1 0:664899e0b988 100 const uint8_t loseMSB) {
uci1 0:664899e0b988 101 const uint8_t p = BITS_IN_SHORT-loseLSB-loseMSB;
uci1 0:664899e0b988 102 return ((p*kTotSamps)/8u) + (((p*kTotSamps)%8u)!=0 ? 1u : 0u);
uci1 0:664899e0b988 103 }
uci1 0:664899e0b988 104
uci1 0:664899e0b988 105 void ReadFrom(const char* const buf,
uci1 0:664899e0b988 106 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 0:664899e0b988 107 const uint16_t wvBaseline);
uci1 0:664899e0b988 108
uci1 0:664899e0b988 109 void WriteTo(char* const buf,
uci1 0:664899e0b988 110 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 0:664899e0b988 111 const uint16_t wvBaseline) const;
uci1 0:664899e0b988 112
uci1 0:664899e0b988 113 bool ReadFrom(FILE* f, char* const evtBuf,
uci1 0:664899e0b988 114 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 0:664899e0b988 115 const uint16_t wvBaseline);
uci1 0:664899e0b988 116 bool WriteTo(FILE* f, char* const evtBuf,
uci1 0:664899e0b988 117 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 0:664899e0b988 118 const uint16_t wvBaseline) const;
uci1 0:664899e0b988 119
uci1 0:664899e0b988 120 static
uci1 0:664899e0b988 121 const uint8_t* UnpackWavef(const uint8_t* const buf,
uci1 0:664899e0b988 122 uint16_t* const data,
uci1 0:664899e0b988 123 const uint8_t loseLSB,
uci1 0:664899e0b988 124 const uint8_t loseMSB,
uci1 0:664899e0b988 125 const uint16_t wvBaseline);
uci1 0:664899e0b988 126
uci1 0:664899e0b988 127 static
uci1 0:664899e0b988 128 uint8_t* PackWavef(uint8_t* const buf, const uint16_t* const data,
uci1 0:664899e0b988 129 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 0:664899e0b988 130 const uint16_t wvBaseline);
uci1 0:664899e0b988 131 };
uci1 0:664899e0b988 132
uci1 0:664899e0b988 133
uci1 0:664899e0b988 134 #endif // SN_SnEventFrame