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

#include <HwInterface.h>

Public Member Functions

NodegetNode (const std::string nodeId)
 Retrieves a node by its identifier.
 
 HwInterface (std::string connectionFilePath, std::string connectionId, PSocketMode::PSocketMode _mock_mode, std::string mock_directory="")
 Constructor for the HwInterface class.
 
virtual ~HwInterface ()
 Destructor for the HwInterface class.
 

Public Attributes

friend Node
 

Protected Member Functions

uint32_t read (const std::string nodeId) const
 Reads data from a specific node.
 
std::vector< uint32_t > readBlock (const std::string &nodeId, const uint32_t &aSize) const
 Reads a block of data from a specific node.
 
bool write (const std::string &nodeId, const uint32_t &aValue)
 Writes data to a specific node.
 
bool writeBlock (const std::string &nodeId, const std::vector< uint32_t > &aValues) const
 Writes a block of data to a specific node.
 

Protected Attributes

std::string connectionFilePath
 
std::string connectionId
 
std::string mock_directory
 
PSocketMode::PSocketMode mock_mode
 
std::map< std::string, std::unique_ptr< Node > > nodes
 

Static Protected Attributes

static SocketManager manager = SocketManager()
 

Detailed Description

Definition at line 38 of file HwInterface.h.

Constructor & Destructor Documentation

◆ HwInterface()

HwInterface::HwInterface ( std::string connectionFilePath,
std::string connectionId,
PSocketMode::PSocketMode mock_mode,
std::string mock_directory = "" )

Constructor for the HwInterface class.

Initializes the hardware interface, sets the mock mode, and adds a server socket for communication.

Parameters
connectionFilePathPath to the connection file.
connectionIdIdentifier for the connection.
mock_modeMode for mock operation (e.g., MOCK_RECORD or MOCK_PLAYBACK).
mock_directoryDirectory for mock data storage (default: "/tmp").

Definition at line 22 of file HwInterface.cpp.

28 if (mock_directory.empty()) {
29 mock_directory = connectionId + "_mock_dir"; // Default directory
30 }
31 std::filesystem::create_directory(mock_directory);
32 manager.setMode(mock_mode);
33
34 log(uhal::Debug(),
35 "Creating HwInterface. Adding server socket for device: ", connectionId,
36 " from ", connectionFilePath);
37 data_stream_assert(manager.addServerSocket(connectionId, PSocketParam{"localhost", 3390}, Backend::server(connectionFilePath, connectionId), "./", Mock::server()));
38}
PSocketMode::PSocketMode mock_mode
Definition HwInterface.h:52
static SocketManager manager
Definition HwInterface.h:54

References connectionFilePath, connectionId, manager, mock_directory, and mock_mode.

◆ ~HwInterface()

HwInterface::~HwInterface ( )
virtual

Destructor for the HwInterface class.

Cleans up resources, including deleting all dynamically allocated Node objects and clearing the nodes map.

Definition at line 46 of file HwInterface.cpp.

46 {
47 nodes.clear();
48 log(uhal::Debug(), "Deleting HwInterface:", connectionFilePath, ", ",
50}
std::map< std::string, std::unique_ptr< Node > > nodes
Definition HwInterface.h:55

References connectionFilePath, connectionId, and nodes.

Member Function Documentation

◆ getNode()

Node & HwInterface::getNode ( const std::string nodeId)

Retrieves a node by its identifier.

If the node does not exist, it creates a new Node object, stores it in the nodes map, and returns it.

Parameters
nodeIdIdentifier of the node to retrieve.
Returns
Reference to the Node object corresponding to the specified identifier.

Definition at line 62 of file HwInterface.cpp.

62 {
63 if (nodes.count(nodeId)) {
64 return *nodes[nodeId];
65 }
66 nodes[nodeId] = std::unique_ptr<Node>(new Node(this, nodeId));
67 return *nodes[nodeId];
68}

References Node, and nodes.

◆ read()

uint32_t HwInterface::read ( const std::string nodeId) const
protected

Reads data from a specific node.

Sends a request to the node and retrieves the value stored in the node.

Parameters
nodeIdIdentifier of the node to read from.
Returns
The value read from the node.

Definition at line 93 of file HwInterface.cpp.

93 {
94 UaMessage UaMessage(connectionId, nodeId);
95 manager.recvMsg(connectionId, UaMessage);
96 std::vector<uint32_t> *valuePtr = UaMessage.value.get();
97 return valuePtr->at(0);
98}

References connectionId, manager, and UaMessage::value.

◆ readBlock()

std::vector< uint32_t > HwInterface::readBlock ( const std::string & nodeId,
const uint32_t & aSize ) const
protected

Reads a block of data from a specific node.

Parameters
nodeIdIdentifier of the node to read from.
aSizeNumber of values to read.
Returns
Vector of values read from the node.

Definition at line 120 of file HwInterface.cpp.

121 {
122 UaMessage msg{connectionId, nodeId, aSize};
123 manager.recvMsg(connectionId, msg);
124 return *msg.value.get();
125}

References connectionId, and manager.

◆ write()

bool HwInterface::write ( const std::string & nodeId,
const uint32_t & aValue )
protected

Writes data to a specific node.

Sends a message containing the node identifier and the value to be written.

Parameters
nodeIdIdentifier of the node to write to.
aValueValue to write to the node.
Returns
true if the data was sent successfully, false otherwise.

Definition at line 79 of file HwInterface.cpp.

79 {
80 std::vector<uint32_t> data = {aValue};
81 UaMessage msgOut{connectionId, nodeId, &data};
82 return manager.sendMsg(connectionId, msgOut);
83}

References connectionId, and manager.

◆ writeBlock()

bool HwInterface::writeBlock ( const std::string & nodeId,
const std::vector< uint32_t > & aValues ) const
protected

Writes a block of data to a specific node.

Parameters
nodeIdIdentifier of the node to write to.
aValuesVector of values to write to the node.
Returns
true if the data was sent successfully, false otherwise.

Definition at line 107 of file HwInterface.cpp.

108 {
109 UaMessage msgOut{connectionId, nodeId, &aValues};
110 return manager.sendMsg(connectionId, msgOut);
111}

References connectionId, and manager.

Member Data Documentation

◆ connectionFilePath

std::string PIpBusInterface::HwInterface::connectionFilePath
protected

Definition at line 50 of file HwInterface.h.

Referenced by HwInterface(), and ~HwInterface().

◆ connectionId

std::string PIpBusInterface::HwInterface::connectionId
protected

Definition at line 51 of file HwInterface.h.

Referenced by HwInterface(), read(), readBlock(), write(), writeBlock(), and ~HwInterface().

◆ manager

SocketManager HwInterface::manager = SocketManager()
staticprotected

Definition at line 54 of file HwInterface.h.

Referenced by HwInterface(), read(), readBlock(), write(), and writeBlock().

◆ mock_directory

std::string PIpBusInterface::HwInterface::mock_directory
protected

Definition at line 53 of file HwInterface.h.

Referenced by HwInterface().

◆ mock_mode

PSocketMode::PSocketMode PIpBusInterface::HwInterface::mock_mode
protected

Definition at line 52 of file HwInterface.h.

Referenced by HwInterface().

◆ Node

friend PIpBusInterface::HwInterface::Node

Definition at line 40 of file HwInterface.h.

Referenced by getNode().

◆ nodes

std::map<std::string, std::unique_ptr<Node> > PIpBusInterface::HwInterface::nodes
protected

Definition at line 55 of file HwInterface.h.

Referenced by getNode(), and ~HwInterface().


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