#ifndef SP605_ITERATOR_H #define SP605_ITERATOR_H #include "sp605/Message.h" #include "roc/Message.h" namespace sp605 { class Board; class Iterator { protected: enum IteratorMessageKind { kindNone, kindRoc, kindSpadic }; enum { MaxGroupId = 2, MaxSpadicId = 4 }; sp605::Board* fBoard; //!< pointer on board object - source of buffers int fFormat; //!< format of data in binary buffer void* fBuffer; //!< assigned buffer unsigned fBufferLen; //!< length of assigned buffer unsigned fBufferPos; //!< current position void* fInterm; //!< intermediate memory for messages unsigned fIntermSize; //!< allocated size of intermediate memory unsigned fIntermFill; //!< filled number of bytes in intermediate buffer unsigned fSP605Id; //!< current identifier of the SP605 board IteratorMessageKind fKind; //!< kind of the current message sp605::Message fMsg; //!< content of current message unsigned fLastEpoch[MaxSpadicId][MaxGroupId]; //!< value of last epoch for each spadic/group id combination unsigned fLastSenderId; //!< last id, that was taken from buffer in intermediate buffer unsigned fSpadicId; //!< current id of spadic chip roc::Message fRocMsg; //!< roc message, used to decode SYNC/AUX/SYS messages unsigned fLastRocEpoch; //!< last seen ROC epoch void allocateInterm(); public: Iterator(int fmt = formatSpadic10Optic); ~Iterator(); void setFormat(int fmt) { fFormat = fmt; } int getFormat() const { return fFormat; } void setBoardId(unsigned id) { fSP605Id = id; } void resetBoardId() { fSP605Id = 0xffffffff; } bool isBoardId() const { return fSP605Id != 0xffffffff; } unsigned getBoardId() const { return isBoardId() ? fSP605Id : 0; } /** Assigns directly raw buffer */ bool assign(void* buf, unsigned sz); /** Extract next buffer from the board */ bool nextBuffer(sp605::Board* brd, double tmout = 1.); /** Extract next message from the buffer */ bool next(double tmout=1.); /** Check if current buffer is at the end */ bool at_the_end() const { return fBufferPos>=fBufferLen; } /** Specific for Spadic message methods */ bool isSpadicMsg() const { return fKind == kindSpadic; } sp605::Message& msg() { return fMsg; } void setSpadicId(unsigned id) { fSpadicId = id; } unsigned getSpadicId() const { return fSpadicId; } /** Specific for ROC message methods */ bool isRocMsg() const { return fKind == kindRoc; } roc::Message& rocmsg() { return fRocMsg; } /** Time, returned in nanoseconds */ uint64_t getMsgFullTime() const; double getMsgFullTimeD() const; void printMessage(); }; } #endif