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 <cstdint>
17 : #include <cstdio>
18 : #include <cstring>
19 : #include <iomanip>
20 : #include <iostream>
21 : #include <string>
22 : #include <unistd.h>
23 : #include <vector>
24 :
25 : namespace dunedaq {
26 : namespace sspmodules {
27 :
28 : class EthernetDevice : public Device
29 : {
30 :
31 : public:
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() { return isOpen; }
38 :
39 : virtual void Close();
40 :
41 : virtual void DevicePurgeComm();
42 :
43 : virtual void DevicePurgeData();
44 :
45 : virtual void DeviceQueueStatus(unsigned int* numWords);
46 :
47 : virtual void DeviceReceive(std::vector<unsigned int>& data, unsigned int size);
48 :
49 : virtual void DeviceRead(unsigned int address, unsigned int* value);
50 :
51 : virtual void DeviceReadMask(unsigned int address, unsigned int mask, unsigned int* value);
52 :
53 : virtual void DeviceWrite(unsigned int address, unsigned int value);
54 :
55 : virtual void DeviceWriteMask(unsigned int address, unsigned int mask, unsigned int value);
56 :
57 : virtual void DeviceSet(unsigned int address, unsigned int mask);
58 :
59 : virtual void DeviceClear(unsigned int address, unsigned int mask);
60 :
61 : virtual void DeviceArrayRead(unsigned int address, unsigned int size, unsigned int* data);
62 :
63 : virtual void DeviceArrayWrite(unsigned int address, unsigned int size, unsigned int* data);
64 :
65 : // Internal functions - make public so debugging code can access them
66 :
67 : void SendReceive(dunedaq::sspmodules::CtrlPacket& tx,
68 : dunedaq::sspmodules::CtrlPacket& rx,
69 : unsigned int txSize,
70 : unsigned int rxSizeExpected,
71 : unsigned int retryCount = 0);
72 :
73 : void SendEthernet(dunedaq::sspmodules::CtrlPacket& tx, unsigned int txSize);
74 :
75 : void ReceiveEthernet(dunedaq::sspmodules::CtrlPacket& rx, unsigned int rxSizeExpected);
76 :
77 : void DevicePurge(boost::asio::ip::tcp::socket& socket);
78 :
79 : private:
80 : friend class DeviceManager;
81 :
82 : bool isOpen;
83 :
84 : static boost::asio::io_service fIo_service;
85 :
86 : boost::asio::ip::tcp::socket fCommSocket;
87 : boost::asio::ip::tcp::socket fDataSocket;
88 :
89 : boost::asio::ip::address fIP;
90 :
91 : // Can only be opened by DeviceManager, not by user
92 : virtual void Open(bool slowControlOnly);
93 : };
94 :
95 : } // namespace sspmodules
96 : } // namespace dunedaq
97 :
98 : #endif // SSPMODULES_SRC_ANLBOARD_ETHERNETDEVICE_HPP_
|