Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef ROC_UDPDEVICE_H
00016 #define ROC_UDPDEVICE_H
00017
00018 #ifndef DABC_Device
00019 #include "dabc/Device.h"
00020 #endif
00021
00022 #ifndef DABC_SocketThread
00023 #include "dabc/SocketThread.h"
00024 #endif
00025
00026 #include "roc/UdpBoard.h"
00027 #include "roc/UdpTransport.h"
00028
00029 namespace roc {
00030
00031 class UdpDevice;
00032
00033
00034
00035
00036 class UdpControlSocket : public dabc::SocketWorker {
00037 friend class UdpDevice;
00038 friend class UdpDataSocket;
00039 protected:
00040
00041 enum EUdpEvents { evntSendCtrl = evntSocketLast + 1,
00042 evntCheckCmd };
00043
00044 UdpDevice* fDev;
00045
00046 dabc::CommandsQueue fUdpCmds;
00047
00048 bool fCtrlRuns;
00049 UdpMessageFull fControlSend;
00050 unsigned fControlSendSize;
00051 UdpMessageFull fControlRecv;
00052
00053 uint32_t fPacketCounter;
00054
00055 double fTotalTmoutSec;
00056 bool fFastMode;
00057 int fLoopCnt;
00058
00059 dabc::TimeStamp fSendLastOper;
00060
00061 void checkCommandsQueue();
00062
00063 void completeLoop(bool res, int len = 0);
00064
00065 void SendDisconnect();
00066
00067 void SetLastSendTime();
00068
00069 public:
00070 UdpControlSocket(UdpDevice* dev, int fd);
00071 virtual ~UdpControlSocket();
00072
00073 virtual double ProcessTimeout(double last_diff);
00074
00075 virtual void ProcessEvent(const dabc::EventId&);
00076
00077 virtual int ExecuteCommand(dabc::Command cmd);
00078 };
00079
00080
00081 class UdpDevice : public dabc::Device,
00082 public roc::UdpBoard {
00083
00084 enum EUdpDeviceEvents { eventCheckUdpCmds = eventDeviceLast,
00085 eventUdpDeviceLast };
00086
00087 friend class UdpControlSocket;
00088 friend class UdpDataSocket;
00089
00090 protected:
00091 bool fConnected;
00092
00093 int fFormat;
00094
00095 std::string fRocIp;
00096 int fRocCtrlPort;
00097 int fRocDataPort;
00098
00099 int fCtrlPort;
00100 UdpControlSocket *fCtrlCh;
00101
00102 int fDataPort;
00103 int fDataFD;
00104 UdpDataSocket *fDataCh;
00105
00106 BoardStatistic brdStat;
00107 bool isBrdStat;
00108
00109 bool displayConsoleOutput_;
00110
00111 dabc::Mutex fSwMutex;
00112 int fSwCmdState;
00113
00114 void processCtrlMessage(UdpMessageFull* pkt, unsigned len);
00115 void setBoardStat(void* rawdata, bool print);
00116
00117 virtual int rawPut(uint32_t address, uint32_t value, const void* rawdata = 0, double tmout = 0.);
00118
00119 bool initUdp();
00120
00121 virtual int ExecuteCommand(dabc::Command cmd);
00122
00123 virtual bool submitSwPut(uint32_t address, uint32_t value, double tmout);
00124 virtual int checkSwPut();
00125 void completeSwPut(bool res);
00126
00127 public:
00128
00129 UdpDevice(const char* name, const char* thrdname, dabc::Command cmd);
00130 virtual ~UdpDevice();
00131
00132 bool IsConnected() const { return fConnected; }
00133
00134 virtual const char* ClassName() const { return typeUdpDevice; }
00135
00136 virtual const char* RequiredThrdClass() const { return dabc::typeSocketThread; }
00137
00138 virtual dabc::Transport* CreateTransport(dabc::Command cmd, dabc::Reference port);
00139
00140 bool InitAsBoard();
00141 bool CloseAsBoard();
00142
00143 virtual void setFlushTimeout(double tmout);
00144
00145
00146 virtual int operGen(base::OperList& lst, double tmout = 0.);
00147
00148
00149 virtual bool startDaq();
00150 virtual bool suspendDaq();
00151 virtual bool stopDaq();
00152 virtual bool getNextBuffer(void* &buf, unsigned& len, double tmout = 1.);
00153
00154 virtual int getMsgFormat() const { return fFormat; }
00155
00156 virtual bool enableCalibration(double period = 10., double calibr = 1., int cnt = -1);
00157
00158
00159 BoardStatistic* takeStat(double tmout = 0.01, bool print = false);
00160
00161 static const char* CmdPutSuspendDaq() { return "PutSuspendDaq"; }
00162 static const char* CmdPutDisconnect() { return "PutDisconnect"; }
00163 };
00164
00165 class UdpDeviceRef : public dabc::DeviceRef {
00166 DABC_REFERENCE(UdpDeviceRef, dabc::DeviceRef, UdpDevice)
00167
00168 };
00169
00170
00171 }
00172
00173 #endif