Line data Source code
1 : /**
2 : * @file EthernetDevice.h
3 : *
4 : * This is part of the DUNE DAQ , copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 : #ifndef SSPMODULES_SRC_ANLBOARD_ETHERNETDEVICE_HPP_
9 : #define SSPMODULES_SRC_ANLBOARD_ETHERNETDEVICE_HPP_
10 :
11 : #include "SSPTypes.hpp"
12 :
13 : #include "Device.hpp"
14 : #include "boost/asio.hpp"
15 :
16 : #include <iostream>
17 : #include <iomanip>
18 : #include <string>
19 : #include <cstdint>
20 : #include <cstdio>
21 : #include <cstring>
22 : #include <unistd.h>
23 : #include <vector>
24 :
25 : namespace dunedaq {
26 : namespace sspmodules {
27 :
28 : class EthernetDevice : public Device{
29 :
30 : public:
31 :
32 : //Create a device object using FTDI handles given for data and communication channels
33 : explicit EthernetDevice(unsigned long ipAddress); // NOLINT
34 :
35 : //Implementation of base class interface
36 :
37 0 : inline virtual bool IsOpen(){
38 0 : return isOpen;
39 : }
40 :
41 : virtual void Close();
42 :
43 : virtual void DevicePurgeComm();
44 :
45 : virtual void DevicePurgeData();
46 :
47 : virtual void DeviceQueueStatus(unsigned int* numWords);
48 :
49 : virtual void DeviceReceive(std::vector<unsigned int>& data, unsigned int size);
50 :
51 : virtual void DeviceRead(unsigned int address, unsigned int* value);
52 :
53 : virtual void DeviceReadMask(unsigned int address, unsigned int mask, unsigned int* value);
54 :
55 : virtual void DeviceWrite(unsigned int address, unsigned int value);
56 :
57 : virtual void DeviceWriteMask(unsigned int address, unsigned int mask, unsigned int value);
58 :
59 : virtual void DeviceSet(unsigned int address, unsigned int mask);
60 :
61 : virtual void DeviceClear(unsigned int address, unsigned int mask);
62 :
63 : virtual void DeviceArrayRead(unsigned int address, unsigned int size, unsigned int* data);
64 :
65 : virtual void DeviceArrayWrite(unsigned int address, unsigned int size, unsigned int* data);
66 :
67 : //Internal functions - make public so debugging code can access them
68 :
69 : void SendReceive(dunedaq::sspmodules::CtrlPacket& tx, dunedaq::sspmodules::CtrlPacket& rx, unsigned int txSize, unsigned int rxSizeExpected, unsigned int retryCount=0);
70 :
71 : void SendEthernet(dunedaq::sspmodules::CtrlPacket& tx, unsigned int txSize);
72 :
73 : void ReceiveEthernet(dunedaq::sspmodules::CtrlPacket& rx, unsigned int rxSizeExpected);
74 :
75 : void DevicePurge(boost::asio::ip::tcp::socket& socket);
76 :
77 : private:
78 :
79 : friend class DeviceManager;
80 :
81 : bool isOpen;
82 :
83 : static boost::asio::io_service fIo_service;
84 :
85 : boost::asio::ip::tcp::socket fCommSocket;
86 : boost::asio::ip::tcp::socket fDataSocket;
87 :
88 : boost::asio::ip::address fIP;
89 :
90 : //Can only be opened by DeviceManager, not by user
91 : virtual void Open(bool slowControlOnly);
92 :
93 : };
94 :
95 : } // namespace sspmodules
96 : } // namespace dunedaq
97 :
98 : #endif // SSPMODULES_SRC_ANLBOARD_ETHERNETDEVICE_HPP_
|