DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DaphneV2Interface.hpp
Go to the documentation of this file.
1
12#ifndef DAPHNEMODULES_SRC_DAPHNEV2INTERFACE_HPP_
13#define DAPHNEMODULES_SRC_DAPHNEV2INTERFACE_HPP_
14
15#include <sys/socket.h>
16#include <netinet/in.h>
17#include <arpa/inet.h>
18#include <vector>
19#include <cstring>
20#include <unistd.h>
21#include <memory>
22#include <mutex>
23#include <functional>
24
25
26#include <ers/ers.hpp>
27#include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
28
30
31namespace dunedaq {
32
33 ERS_DECLARE_ISSUE( daphnemodules,
34 SocketCreationError,
35 "Failed to create a socket",
37 )
38
39 ERS_DECLARE_ISSUE( daphnemodules,
41 "Failed to ping daphne board at " << ip << ':' << port,
42 ((std::string)ip)((int)port)
43 )
44
45 ERS_DECLARE_ISSUE( daphnemodules,
46 FailedSocketInteraction,
47 "Failed to call " << command,
48 ((std::string)command)
49 )
50
51 ERS_DECLARE_ISSUE( daphnemodules,
52 CommandTimeout,
53 "Command " << command << " timed out after " << timeout_us << " microseconds",
54 ((std::string)command)((unsigned int)timeout_us)
55 )
56
57 ERS_DECLARE_ISSUE( daphnemodules,
58 SocketTimeout,
59 "Socket timed out after " << timeout_us << " microseconds",
60 ((unsigned int)timeout_us)
61 )
62
63 } // dunedaq namespace
64
65
67
69 std::string command;
70 std::string result;
71 };
72
73
75
76 public:
77 DaphneV2Interface( const char* ipaddr, int port,
78 std::chrono::milliseconds timeout = std::chrono::milliseconds(500));
79
81
86
87 std::vector<uint64_t> read_register(uint64_t addr, uint8_t size) const { return read(0x00, addr, size) ; }
88 void write_register(uint64_t addr, std::vector<uint64_t> && data) const { write(0x01, addr, std::move(data)) ; }
89
90 std::vector<uint64_t> read_buffer(uint64_t addr, uint8_t size) const { return read(0x08, addr, size) ; }
91 void write_buffer(uint64_t addr, std::vector<uint64_t> && data) const { write(0x09, addr, std::move(data)) ; }
92
93 bool validate_connection() const ;
94
95 command_result send_command(std::string cmd) const;
96
97 // this will throw if it fails
98 command_result send_command_retry( std::string cmd, size_t retry = std::numeric_limits<size_t>::max() ) const ;
99
100 // this will try until success but it won't thrwo if can retry become false
101 command_result send_command_interruptible( std::string cmd, std::function<bool()> can_retry) const ;
102
103
104 protected:
105
106 void close();
107
108 void write( uint8_t command_id, uint64_t addr, std::vector<uint64_t> && data) const;
109 std::vector<uint64_t> read(uint8_t command_id, uint64_t addr, uint8_t size) const;
110
111
112 private:
113 std::string m_ip;
115 sockaddr_in m_target;
116 std::chrono::milliseconds m_timeout{5};
117 mutable std::mutex m_access_mutex;
118 mutable std::mutex m_command_mutex;
119 };
120
121
122} // namespce dunedaq::daphnemodules
123
124
125#endif // DAPHNEMODULES_SRC_DAPHNEV2INTERFACE_HPP_
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message, attributes)
#define ERS_EMPTY
void write_register(uint64_t addr, std::vector< uint64_t > &&data) const
DaphneV2Interface(DaphneV2Interface &&)=delete
void write(uint8_t command_id, uint64_t addr, std::vector< uint64_t > &&data) const
std::vector< uint64_t > read_buffer(uint64_t addr, uint8_t size) const
std::vector< uint64_t > read(uint8_t command_id, uint64_t addr, uint8_t size) const
void write_buffer(uint64_t addr, std::vector< uint64_t > &&data) const
command_result send_command_retry(std::string cmd, size_t retry=std::numeric_limits< size_t >::max()) const
DaphneV2Interface(const DaphneV2Interface &)=delete
DaphneV2Interface(const char *ipaddr, int port, std::chrono::milliseconds timeout=std::chrono::milliseconds(500))
std::vector< uint64_t > read_register(uint64_t addr, uint8_t size) const
command_result send_command(std::string cmd) const
DaphneV2Interface & operator=(const DaphneV2Interface &)=delete
command_result send_command_interruptible(std::string cmd, std::function< bool()> can_retry) const
The DUNE-DAQ namespace.
FELIX Initialization std::string initerror FELIX queue timed std::string queuename Unexpected chunk size