IpbusMock  1.0.0
Library which integrates IPbus use in Phoenix
Loading...
Searching...
No Matches
IpBusImpl Class Reference

#include <ipbrw.h>

Public Member Functions

void close ()
 Close the IpBusImpl connection.
 
uint32_t getSize (const std::string &nodeId) const
 Computes the node size.
 
 IpBusImpl (const std::string &connectionFilePath, const std::string &connectionId)
 Constructor of IpBusImpl.
 
bool read (const std::string &nodeId, uint32_t &res)
 Reads a register using the uHAL library.
 
bool readBlock (const std::string &nodeId, std::vector< uint32_t > &results, const uint32_t &aSize)
 Reads a block of data from a block of registers or a block-read port.
 
bool write (const std::string &nodeId, const uint32_t values)
 Writes a register using the uHAL library.
 
bool writeBlock (const std::string &nodeId, const std::vector< uint32_t > values)
 Writes a block of data to a block of registers or a block-write port.
 
 ~IpBusImpl ()
 Destructor of IpBusImpl.
 

Static Public Member Functions

static IpBusImplpipbus_createSocket (const std::string &connectionFilePath, const std::string &connectionId)
 Creates an IpBusImpl instance.
 
static void setLogLevelTo (const std::string level)
 Sets the uHAL log level to the given level.
 

Private Attributes

uhal::HwInterface * hardwareInterface
 

Detailed Description

Definition at line 8 of file ipbrw.h.

Constructor & Destructor Documentation

◆ IpBusImpl()

IpBusImpl::IpBusImpl ( const std::string & connectionFilePath,
const std::string & connectionId )

Constructor of IpBusImpl.

Parameters
connectionFilePathPath to the connection file.
connectionIdIdentifier for the connection.

Definition at line 12 of file ipbrw.cpp.

13 {
14 uhal::ConnectionManager connectionMgr(connectionFilePath);
16 new uhal::HwInterface(connectionMgr.getDevice(connectionId));
17}
uhal::HwInterface * hardwareInterface
Definition ipbrw.h:29

References hardwareInterface.

Referenced by pipbus_createSocket().

+ Here is the caller graph for this function:

◆ ~IpBusImpl()

IpBusImpl::~IpBusImpl ( )

Destructor of IpBusImpl.

Definition at line 22 of file ipbrw.cpp.

22 {
23 delete hardwareInterface;
24 hardwareInterface = nullptr;
25}

References hardwareInterface.

Member Function Documentation

◆ close()

void IpBusImpl::close ( )

Close the IpBusImpl connection.

Definition at line 151 of file ipbrw.cpp.

151 {
152 if (hardwareInterface != nullptr) {
153 try {
154 // uHAL does not provide a close method,
155 // But we can delete the HwInterface to close the connection.
156 delete hardwareInterface;
157 hardwareInterface = nullptr;
158 } catch (const std::exception& e) {
159 std::cerr << "Error closing connection: " << e.what() << std::endl;
160 }
161 }
162}

References hardwareInterface.

◆ getSize()

uint32_t IpBusImpl::getSize ( const std::string & nodeId) const

Computes the node size.

Parameters
nodeIdIdentifier of the node.
Returns
Size of the node.

Definition at line 33 of file ipbrw.cpp.

33 {
34 return this->hardwareInterface->getNode(nodeId).getSize();
35}

References hardwareInterface.

◆ pipbus_createSocket()

IpBusImpl * IpBusImpl::pipbus_createSocket ( const std::string & connectionFilePath,
const std::string & connectionId )
static

Creates an IpBusImpl instance.

Parameters
connectionFilePathPath to the connection file.
connectionIdIdentifier for the connection.
Returns
Pointer to the IpBusImpl instance.

Definition at line 117 of file ipbrw.cpp.

118 {
119 static IpBusImpl _self(connectionFilePath, connectionId);
120 return &_self;
121}
IpBusImpl(const std::string &connectionFilePath, const std::string &connectionId)
Constructor of IpBusImpl.
Definition ipbrw.cpp:12

References IpBusImpl().

Referenced by PIpBusSocket::createClientSocket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

bool IpBusImpl::read ( const std::string & nodeId,
uint32_t & result )

Reads a register using the uHAL library.

Parameters
nodeIdIdentifier of the node.
resultReference to store the read value.
Returns
true if the read was successful, false otherwise.

Definition at line 44 of file ipbrw.cpp.

44 {
45 const uhal::Node &lNode = this->hardwareInterface->getNode(nodeId);
46 uhal::ValWord<uint32_t> lReg = lNode.read();
47 this->hardwareInterface->dispatch();
48 if (!lReg.valid()) {
49 std::cerr << "Error: Register read failed." << std::endl;
50 return false;
51 } else {
52 result = lReg.value();
53 return true;
54 }
55}

References hardwareInterface.

◆ readBlock()

bool IpBusImpl::readBlock ( const std::string & nodeId,
std::vector< uint32_t > & results,
const uint32_t & aSize )

Reads a block of data from a block of registers or a block-read port.

Parameters
nodeIdIdentifier of the node.
resultsVector to store the read values.
aSizeNumber of words to read.
Returns
true if the read was successful, false otherwise.

Definition at line 79 of file ipbrw.cpp.

81 {
82 const uhal::Node &lNode = this->hardwareInterface->getNode(nodeId);
83 uhal::ValVector<uint32_t> lReg = lNode.readBlock(aSize);
84 this->hardwareInterface->dispatch();
85 if (!lReg.valid()) {
86 std::cerr << "Error: Register read failed." << std::endl;
87 return false;
88 } else {
89 results.clear();
90 copy(lReg.begin(), lReg.end(), back_inserter(results));
91 return true;
92 }
93}

References hardwareInterface.

◆ setLogLevelTo()

void IpBusImpl::setLogLevelTo ( const std::string level)
static

Sets the uHAL log level to the given level.

Parameters
levelLog level (e.g., Debug, Info, Warning, etc.).

Definition at line 128 of file ipbrw.cpp.

128 {
129 if (level == "Debug") {
130 uhal::setLogLevelTo(uhal::Debug());
131 } else if (level == "Info") {
132 uhal::setLogLevelTo(uhal::Info());
133 } else if (level == "Notice") {
134 uhal::setLogLevelTo(uhal::Notice());
135 } else if (level == "Warning") {
136 uhal::setLogLevelTo(uhal::Warning());
137 } else if (level == "Error") {
138 uhal::setLogLevelTo(uhal::Error());
139 } else if (level == "Fatal") {
140 uhal::setLogLevelTo(uhal::Fatal());
141 } else {
142 std::cerr << "Invalid log level. Use Debug, Info, Notice, Warning, "
143 << "Error, or Fatal." << std::endl;
144 uhal::setLogLevelTo(uhal::Info());
145 }
146}

◆ write()

bool IpBusImpl::write ( const std::string & nodeId,
const uint32_t value )

Writes a register using the uHAL library.

Parameters
nodeIdIdentifier of the node.
valueValue to write.
Returns
true if the write was successful, false otherwise.

Definition at line 64 of file ipbrw.cpp.

64 {
65 const uhal::Node &lNode = this->hardwareInterface->getNode(nodeId);
66 lNode.write(value);
67 this->hardwareInterface->dispatch();
68 return true;
69}

References hardwareInterface.

◆ writeBlock()

bool IpBusImpl::writeBlock ( const std::string & nodeId,
const std::vector< uint32_t > values )

Writes a block of data to a block of registers or a block-write port.

Parameters
nodeIdIdentifier of the node.
valuesVector of values to write.
Returns
true if the write was successful, false otherwise.

Definition at line 102 of file ipbrw.cpp.

103 {
104 const uhal::Node &lNode = this->hardwareInterface->getNode(nodeId);
105 lNode.writeBlock(values);
106 this->hardwareInterface->dispatch();
107 return true;
108}

References hardwareInterface.

Member Data Documentation

◆ hardwareInterface

uhal::HwInterface* IpBusImpl::hardwareInterface
private

Definition at line 29 of file ipbrw.h.

Referenced by close(), getSize(), IpBusImpl(), read(), readBlock(), write(), writeBlock(), and ~IpBusImpl().


The documentation for this class was generated from the following files: