#ifndef _BLDMCASTRECEIVER_H_ #define _BLDMCASTRECEIVER_H_ #include "BLDData.h" #include "TimeUtil.h" #include "epicsMessageQueue.h" #include "epicsThread.h" #include #include #include #include #include #include #include #include #include #include static const std::string BLD_EBEAM_GROUP = "239.255.24.0"; static const std::string BLD_PHASE_CAVITY_GROUP = "239.255.24.1"; static const std::string BLD_GAS_DETECTOR_GROUP = "239.255.24.2"; class BLDMCastReceiver; class PayloadReader { public: PayloadReader(std::string multicastAddress) : _size(-1), _multicastAddress(multicastAddress) { _mutex = epicsMutexCreate(); }; PayloadReader(const PayloadReader &other) : _size(other._size), _multicastAddress(other._multicastAddress) { _mutex = epicsMutexCreate(); } PayloadReader(std::string multicastAddress, int size) : _size(size), _multicastAddress(multicastAddress) { _mutex = epicsMutexCreate(); }; virtual ~PayloadReader() { epicsMutexDestroy(_mutex); }; virtual void readBld(BLDHeader *header); int getSize() { return _size; } std::string getMulticastAddress() { return _multicastAddress; } friend class BLDMCastReceiver; protected: int _size; epicsMutexId _mutex; unsigned int _pulseId; std::string _multicastAddress; }; class EBeamPayloadReader : public PayloadReader { public: EBeamPayloadReader() : PayloadReader(BLD_EBEAM_GROUP, sizeof(BLDEBeam)) { }; EBeamPayloadReader(const PayloadReader &other) : PayloadReader(other) { }; virtual ~EBeamPayloadReader() { }; virtual void readBld(BLDHeader *header); void getLatest(unsigned int &pulseId, double &dmpTmit); protected: double _dmpTmit; }; class PCAVPayloadReader : public PayloadReader { public: PCAVPayloadReader() : PayloadReader(BLD_PHASE_CAVITY_GROUP, sizeof(BLDPhaseCavity)) { }; PCAVPayloadReader(const PayloadReader &other) : PayloadReader(other) { }; virtual ~PCAVPayloadReader() { }; virtual void readBld(BLDHeader *header); void getLatest(unsigned int &pulseId, double &fitTime1, double &fitTime2, double &charge1, double &charge2); protected: double _fitTime1; double _fitTime2; double _charge1; double _charge2; }; class GDETPayloadReader : public PayloadReader { public: GDETPayloadReader() : PayloadReader(BLD_GAS_DETECTOR_GROUP, sizeof(BLDGasDetector)) { }; GDETPayloadReader(const PayloadReader &other) : PayloadReader(other) { }; virtual ~GDETPayloadReader() { }; virtual void readBld(BLDHeader *header); void getLatest(unsigned int &pulseId, BLDGasDetector &gasDetector); protected: double _f_11_ENRC; double _f_12_ENRC; double _f_21_ENRC; double _f_22_ENRC; }; /** * BLDMCastReceiver.h * * Definition of functions and data fields to handle incoming BLD data packets. * */ class BLDMCastReceiver : public epicsThreadRunable { public: BLDMCastReceiver(PayloadReader *reader); virtual ~BLDMCastReceiver(); void start(); /** Run the BLD receiver */ virtual void run(); friend class BLDMCastReceiverTest; protected: /** Socket for receiving multicast BLD packets */ int _sock; /** Multicast group address */ std::string _multicastGroup; /** Port number */ int _port; /** Latest BLD header - passed to recvmsg */ BLDHeader *_bldHeader; /** Latest BLD payload - contiguous memory after bld_header */ void *_bldPayload; /** Size of BLD data following the header */ int _payloadSize; /** Number of BLD packets received */ long _bldCount; /** Current BLD PULSEID */ unsigned int _pulseid; /** Stats about BLD receiving time */ TimeAverage _bldStats; struct msghdr _msghdr; struct iovec _iov; // Buffer description socket receive struct sockaddr_in _src; // Socket name source machine epicsThread _thread; bool _done; PayloadReader *_reader; int connect(); int getMessage(); }; #endif