Go to the documentation of this file.00001 #ifndef SP605_MESSAGE_H
00002 #define SP605_MESSAGE_H
00003
00004 #include <stdint.h>
00005 #include <iostream>
00006 #include <vector>
00007
00008 #define SP605_SPADIC_MAX_CHANNEL 0xF // 4 bit max channel id
00009 #define SP605_SPADIC_MAX_GROUP 0xFF // 8 bit max group id
00010 #define SP605_SPADIC_MAX_SAMPLE 0x3F // 6 bit maximum number of samples per message
00011
00012
00013
00014 #ifndef DEBUG605
00015 #define DPRINT605( args ...) ;
00016 #else
00017 #define DPRINT605( args ...) printf( args )
00018 #endif
00019
00020
00021 namespace sp605 {
00022
00023
00024
00025
00026
00027
00028 enum MessageFormat {
00029 formatSpadic10Direct = 5,
00030 formatSpadic10Optic = 6
00031 };
00032
00033
00034 enum MessageTypes {
00035 MSG_NOP = 0,
00036 MSG_HIT = 1,
00037 MSG_EPOCH = 2,
00038 MSG_OVERFLOW = 3,
00039 MSG_INFO = 4,
00040 MSG_LASTID = 5
00041 };
00042
00043
00044 enum HitTrgTypes {
00045 TRIG_GLOBAL = 0,
00046 TRIG_SELF = 1,
00047 TRIG_NEIGHBOR = 2,
00048 TRIG_BOTH = 3
00049 };
00050
00051
00052 enum MsgStopTypes {
00053 STOP_NORMAL = 0,
00054 STOP_OUTBUFFULL = 1,
00055 STOP_FIFOFULL = 2,
00056 STOP_MULTIHIT = 3,
00057 STOP_OUTBUFFULLMULTIHIT = 4,
00058 STOP_FIFOFULLMULTIHIT = 5
00059 };
00060
00061
00062 enum InfoTypes {
00063 INFO_DIS = 0,
00064 INFO_NGT = 1,
00065 INFO_NRT = 2,
00066 INFO_NBE = 3,
00067 INFO_MSB = 4,
00068 INFO_NOP = 5,
00069 INFO_SYN = 6
00070 };
00071
00072
00073
00074
00075
00076 class Message {
00077 protected:
00078 uint8_t fMsgType;
00079 uint16_t fSpadicId;
00080 uint8_t fGroup;
00081 uint8_t fChan;
00082 uint8_t fHitType;
00083 uint8_t fInfoType;
00084 uint16_t fTimeStamp;
00085 uint16_t fEpoch;
00086 uint8_t fTraceSize;
00087 std::vector<int16_t> fTraces;
00088
00089
00090
00091 void InitTraceBuffer(uint16_t* fRDA);
00092
00093
00094
00095
00096
00097 bool SetTrace(unsigned bin, int16_t value, unsigned len)
00098 {
00099 if (bin >= fTraces.size()) return false;
00100 fTraces[bin] = (value>256) ? value-512 : value;
00101 return (bin + 1 == len) ? false : true;
00102 }
00103
00104 public:
00105
00106 Message() { clear(); }
00107 ~Message() { }
00108
00109 void clear()
00110 {
00111 fMsgType=MSG_NOP;
00112 fSpadicId=0;
00113 fGroup=0xff;
00114 fChan=0xff;
00115 fHitType=0;
00116 fEpoch=0;
00117 fTimeStamp=0;
00118 fTraceSize=0;
00119 fTraces.clear();
00120 }
00121
00122
00130 size_t assign(void* buf, unsigned fullsz);
00131
00132
00133
00134
00135
00136
00137 uint8_t getMsgType() const { return fMsgType; }
00138
00139
00140 uint16_t getSpadicNumber() const { return fSpadicId; }
00141
00142
00143 void setSpadicNumber(uint16_t id) { fSpadicId=id;}
00144
00145
00146 uint8_t getGroup() const
00147 {
00148 return fGroup;
00149 }
00150
00151
00152 uint8_t getChNum() const
00153 {
00154 return fChan;
00155 }
00156
00157
00158 unsigned getFullChNum() const
00159 {
00160 return getGroup() * 16 + getChNum();
00161 }
00162
00163
00164
00165 uint8_t getHitType() const
00166 {
00167 return fHitType;
00168 }
00169
00170 uint8_t getStopType() const
00171 {
00172 return fInfoType;
00173 }
00174
00175
00176
00177
00178 uint8_t getTraceSize() const
00179 {
00180 return fTraceSize;
00181 }
00182
00183 uint16_t getTimeStamp() const
00184 {
00185 return fTimeStamp;
00186 }
00187
00188
00189
00190 uint8_t getOverflowHits() const
00191 { return fEpoch; }
00192
00193
00194
00195
00196 uint8_t getInfoType() const
00197 {
00198 return fInfoType;
00199 }
00200
00201 uint8_t getInfoChannel() const
00202 {
00203 return fChan;
00204 }
00205
00206 uint8_t getInfoEpoch() const
00207 {
00208 return fEpoch;
00209 }
00210
00211
00212
00214
00215 uint8_t evalGroup(uint16_t* pSOM) const
00216 {
00217 if(pSOM==0) return 0;
00218 return (uint8_t) (( *pSOM >> 4) & 0xFF);
00219 }
00220
00221
00222 uint8_t evalChNum(uint16_t* pSOM) const
00223 {
00224 if (pSOM == 0)
00225 return 0;
00226 return (uint8_t)(*pSOM & 0xF);
00227 }
00228
00229
00230 uint8_t evalHitType(uint16_t* pEOM) const
00231 {
00232 if (getMsgType() != MSG_HIT || pEOM == 0)
00233 return 0;
00234 return (uint8_t)((*pEOM >> 4) & 0x3);
00235 }
00236
00237 uint8_t evalStopType(uint16_t* pEOM) const
00238 {
00239 if (getMsgType() != MSG_HIT || pEOM == 0)
00240 return 0;
00241 return (uint8_t)(*pEOM & 0x7);
00242 }
00243
00244
00245
00246
00247
00248
00249 size_t evalTraceSize(uint16_t* pEOM) const
00250 {
00251 if (getMsgType() != MSG_HIT || pEOM == 0)
00252 return 0;
00253 return (size_t)((*pEOM >> 6) & 0x3F);
00254 }
00255
00256
00257
00258 int16_t getTrace(unsigned bin)
00259 {
00260 if(getMsgType()!=MSG_HIT) return -1024;
00261 if(bin>=getTraceSize()) return -2048;
00262
00263 return fTraces[bin];
00264 }
00265
00266
00267 unsigned getEpoch() const { return fEpoch; }
00268
00269 uint16_t evalTimeStamp(uint16_t* fTSW) const
00270 {
00271 if(fTSW==0) return 0;
00272 return (*fTSW & 0xFFF);
00273 }
00274
00275
00276 uint32_t getMsgFullTime(uint16_t epoch=0) const;
00277
00278 double getMsgFullTimeD(uint16_t epoch=0) const;
00279
00281
00282 inline static uint32_t FullTimeStamp(uint16_t epoch, uint16_t stamp)
00283 { return 40 * (((uint32_t) epoch << 12) | (stamp & 0xfff)); }
00284
00285
00286 void printData();
00287
00288
00289 bool isTrace() const { return isHitMsg(); }
00290
00291 bool isEpoch() const { return isEpochMsg(); }
00292
00293 inline bool isNopMsg() const { return getMsgType() == MSG_NOP; }
00294 inline bool isHitMsg() const { return getMsgType() == MSG_HIT; }
00295 inline bool isEpochMsg() const { return getMsgType() == MSG_EPOCH;}
00296 inline bool isOverflowMsg() const { return getMsgType() == MSG_OVERFLOW; }
00297 inline bool isInfoMsg() const { return getMsgType() == MSG_INFO; }
00298
00299
00300 };
00301 }
00302
00303 #endif