• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

plugin/roc/UdpDevice.h (r4864/r3193)

Go to the documentation of this file.
00001 /********************************************************************
00002  * The Data Acquisition Backbone Core (DABC)
00003  ********************************************************************
00004  * Copyright (C) 2009-
00005  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
00006  * Planckstr. 1
00007  * 64291 Darmstadt
00008  * Germany
00009  * Contact:  http://dabc.gsi.de
00010  ********************************************************************
00011  * This software can be used under the GPL license agreements as stated
00012  * in LICENSE.txt file which is part of the distribution.
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    // TODO: in DABC2 control socket should be inherited from dabc::SocketWorker
00034    //       or one should reorganize event loop to inherit from dabc::SocketIOWorker
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;   // ROC port number, used for control communication
00097          int               fRocDataPort;   // ROC port number, used for data transport
00098 
00099          int               fCtrlPort;  // local port, used for control communication
00100          UdpControlSocket *fCtrlCh;
00101 
00102          int               fDataPort; // local port number, used for data transport
00103          int               fDataFD;   // socket descriptor, kept temporary in this variable
00104          UdpDataSocket    *fDataCh;   // created data channel
00105 
00106          BoardStatistic    brdStat;    // last available statistic block
00107          bool              isBrdStat;  // is block statistic contains valid data
00108 
00109          bool              displayConsoleOutput_; // display output, coming from ROC
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          // put/get interface part of roc::Board
00146          virtual int operGen(base::OperList& lst, double tmout = 0.);
00147 
00148          // daq interface part of roc::Board
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          // interface part of roc::UdpBoard
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

Generated on Tue Dec 10 2013 04:52:23 for ROCsoft by  doxygen 1.7.1