#ifndef SPADIC_MESSAGE_H #define SPADIC_MESSAGE_H #include #include #include #include /* * Susibo/Spadic Message wrapper for DABC and Go4 * First version 21-October-2010 by JAM */ // switches debug output between dabc logger and iostream: // set this define to use Message class without dabc (Go4 Unpacker!) //#define __SPADIC_WITHOUT_DABC__ 1 #define SUSIBO_PACKAGE_LENGTH 368 #define SUSIBO_MAX_CHANNEL 8 #define SUSIBO_MAX_SAMPLE 45 namespace spadic { extern const char* typeSusiboInput; extern const char* nameReadoutAppClass; extern const char* xmlNumSusibo; extern const char* xmlSusiboDevID; extern const char* xmlHitDelay; extern const char* xmlEventsPerBuffer; extern const char* xmlFormatMbs; extern const char* xmlTimeout; extern const char* xmlUseInternalTrigger; extern const char* xmlInternalTriggerFreq; extern const char* xmlModuleName; extern const char* xmlModuleThread; enum { bt_Spadic = 104 }; /* this class wraps the susibo message contained in the external byte vector*/ class Message { public: enum PackageKind { packageNone = 0, packageVector = 1, // message stored in std vector packageStruct = 2 // message expanded to structure in memory }; /* external data package from susibo will be wrapped into this object*/ Message(std::vector * package); /* external data field will be wrapped into this object*/ Message(uint8_t* field); virtual ~Message(); /* evaluate the event id (trigger message) number from the current package*/ uint32_t GetEventIDNumber(); /* evaluate the status from the package*/ uint16_t GetStatusNumber(); /* evaluate susibo timestamp*/ uint32_t GetTimeStamp(); /* Check if current message has correct length and format*/ bool CheckMessage(); /* Direct access to message data with general index*/ uint8_t Data(size_t ix) { switch (fKind) { case packageVector: return (fPackage->at(ix)); case packageStruct: return fField[ix]; default: return 0; }; return 0; } /* access sample data of channel*/ uint8_t Sample(size_t channel, size_t bin) { if (channel>=SUSIBO_MAX_CHANNEL) return 0; size_t ix=channel*SUSIBO_MAX_SAMPLE + bin; if(ix>=SUSIBO_PACKAGE_LENGTH) return 0; return Data(ix); } protected: /* reference to the package containing the current message*/ std::vector * fPackage; /* reference to the package containing the current message*/ uint8_t* fField; PackageKind fKind; }; } #endif