#ifndef GMD_DEBUG_STREAM_ASYN_DRIVER_H #define GMD_DEBUG_STREAM_ASYN_DRIVER_H #include #include "debugStream.h" // The firmware defines what it understands as 1 unit. Typical values are // 1 unit = 2^17 or 2^23 and they are called normalization factors. In other // words, if for a given parameter the normalization factor is 2^17 and we read // an integer corresponding to 1.5*2^17 (196608), we know that the value that // we want is, indeed 1.5. 196608/2^17 = 1.5. #define ENERGY_NORM_FACTOR 0x20000 #define POSITION_NORM_FACTOR 0x20000 // Status mask from the firmware #define ENERGY_INVALID_MASK 0xE100 #define CALIBRATION_CYCLE_MASK 0x1800 #define SOFT_TRIGGER_MASK 0X400 #define ENERGY_BELOW_THRESHOLD_MASK 0X200 #define ENERGY_OVERFLOW_MASK 0X80 #define ENERGY_UNDERFLOW_MASK 0X40 // The firmware brings us a maximum of 2 mJ after we denormalize (see above) // the data. During tests, we've discovered that a combination of a small pulse // with a high beam intensity would make the scaling factor be higher than 2. // To fix this, we need to multiply the returned calculated energy by a // multiplication factor. // Beware that changing this factor here is not sufficient. You will // need to adapt the Offset_U, Offset_V, and TMIT scaling factors on the // EPICS database to have consistent values. #define ENERGY_MULT_FACTOR 16.0 // Asyn Port Driver parameters #define p_EnergyString "ENERGY" /* asynInt32, r/o */ #define p_PosXString "POSX" /* asynInt32, r/o */ #define p_PosYString "POSY" /* asynInt32, r/o */ #define p_RmsAString "RMSA" /* asynInt32, r/o */ #define p_RmsBString "RMSB" /* asynInt32, r/o */ #define p_RmsCString "RMSC" /* asynInt32, r/o */ #define p_RmsDString "RMSD" /* asynInt32, r/o */ #define p_EnableNCBldString "ENABLENCBLD" class GmdDebugStream: public DebugStreamAsynDriver { public: GmdDebugStream(const char *portName, const char *named_root, unsigned size, bool header, const char *stream0, const char *stream1, const char *stream2, const char *stream3); ~GmdDebugStream(); void streamPoll(const int ch); static bool isStatusEnergyInvalid(epicsUInt16 statusBits); static bool isStatusCalibCycle(epicsUInt16 statusBits); static bool isStatusSoftTrigger(epicsUInt16 statusBits); static bool isStatusEnergyLow(epicsUInt16 statusBits); static bool isStatusOverFlow(epicsUInt16 statusBits); static bool isStatusUnderFlow(epicsUInt16 statusBits); asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value); private: protected: // Asyn Port Driver parameters int p_Energy; int p_PosX; int p_PosY; int p_RmsA; int p_RmsB; int p_RmsC; int p_RmsD; int p_EnableNCBld; }; #pragma pack(push) #pragma pack(1) typedef struct { // Firmware sends data in big endian and our CPU uses little endian #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ epicsUInt8 header_length_version; epicsUInt8 reserved1; epicsUInt16 status; epicsInt32 tmit; epicsInt32 rmsA; epicsInt32 rmsB; epicsInt32 rmsC; epicsInt32 rmsD; epicsInt32 x_pos; epicsInt32 y_pos; epicsUInt32 nsec; epicsUInt32 secPastEpoch; epicsUInt64 pulseID; epicsUInt32 reserved2; epicsFloat32 tmit_fp; epicsFloat32 x_pos_fp; epicsFloat32 y_pos_fp; epicsInt32 sumU; epicsInt32 difU; epicsInt32 sumV; epicsInt32 difV; epicsInt16 reserved4; epicsInt16 quotU_r; epicsInt16 reserved3; epicsInt16 quotV_r; epicsInt16 bkGrndCH0; epicsInt16 bkGrndCH1; epicsInt16 bkGrndCH2; epicsInt16 bkGrndCH3; #else epicsInt32 tmit; epicsUInt16 status; epicsUInt8 reserved1; epicsUInt8 header_length_version; epicsInt32 rmsB; epicsInt32 rmsA; epicsInt32 rmsD; epicsInt32 rmsC; epicsUInt32 y_pos; epicsUInt32 x_pos; epicsUInt32 secPastEpoch; epicsUInt32 nsec; epicsUInt64 pulseID; epicsFloat32 tmit_fp; epicsUInt32 reserved2; epicsFloat32 y_pos_fp; epicsFloat32 x_pos_fp; epicsInt32 difU; epicsInt32 sumU; epicsInt32 difV; epicsInt32 sumV; epicsInt16 quotV_r; epicsInt16 reserved3; epicsInt16 quotU_r; epicsInt16 reserved4; epicsInt16 bkGrndCH3; epicsInt16 bkGrndCH2; epicsInt16 bkGrndCH1; epicsInt16 bkGrndCH0; #endif // BYTE_ORDER } gmd_packet_header_t; typedef struct { gmd_packet_header_t packet; union { epicsInt16 int16; epicsInt32 int32; epicsInt64 int64; epicsFloat32 float32; epicsFloat64 float64; } payload; } gmd_stream_with_header_t; typedef struct { union { epicsInt16 int16; epicsInt32 int32; epicsInt64 int64; epicsFloat32 float32; epicsFloat64 float64; } payload; } gmd_stream_without_header_t; #pragma pack(pop) #endif /* GMD_DEBUG_STREAM_ASYN_DRIVER_H */