IDS peak genericC++ v1.16.0
Loading...
Searching...
No Matches
peak_register_node.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13
15#include <peak/dll_interface/peak_dll_interface_util.hpp>
16#include <peak/error_handling/peak_error_handling.hpp>
19
20#include <cstddef>
21#include <cstdint>
22#include <vector>
23#include <type_traits>
24
25
26namespace peak
27{
28namespace core
29{
30namespace nodes
31{
32
38class RegisterNode : public Node
39{
40public:
41 static constexpr auto NodeType = nodes::NodeType::Register;
42 using NodeDataType = std::vector<uint8_t>;
43 using NodeHasRange = std::false_type;
44
45 RegisterNode() = delete;
46 ~RegisterNode() override = default;
47 RegisterNode(const RegisterNode& other) = delete;
48 RegisterNode& operator=(const RegisterNode& other) = delete;
49 RegisterNode(RegisterNode&& other) = delete;
51
61 uint64_t Address() const;
62
72 size_t Length() const;
73
88 std::vector<uint8_t> Read(size_t numBytes, NodeCacheUsePolicy cacheUsePolicy = NodeCacheUsePolicy::UseCache) const;
89
100 void Write(const std::vector<uint8_t>& bytes);
101
113 void Write(const uint8_t* bytes, size_t size);
114
115private:
116 friend ClassCreator<RegisterNode>;
117 RegisterNode(PEAK_REGISTER_NODE_HANDLE registerNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap);
118 PEAK_REGISTER_NODE_HANDLE m_backendHandle;
119};
120
121} /* namespace nodes */
122} /* namespace core */
123} /* namespace peak */
124
125/* Implementation */
126namespace peak
127{
128namespace core
129{
130namespace nodes
131{
132
134 PEAK_REGISTER_NODE_HANDLE registerNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap)
135 : Node(QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* nodeHandle) {
136 return PEAK_C_ABI_PREFIX PEAK_RegisterNode_ToNode(registerNodeHandle, nodeHandle);
137 }),
138 parentNodeMap)
139 , m_backendHandle(registerNodeHandle)
140{}
141
142inline uint64_t RegisterNode::Address() const
143{
144 return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* address) {
145 return PEAK_C_ABI_PREFIX PEAK_RegisterNode_GetAddress(m_backendHandle, address);
146 });
147}
148
149inline size_t RegisterNode::Length() const
150{
151 return QueryNumericFromCInterfaceFunction<size_t>(
152 [&](size_t* length) { return PEAK_C_ABI_PREFIX PEAK_RegisterNode_GetLength(m_backendHandle, length); });
153}
154
155inline std::vector<uint8_t> RegisterNode::Read(
156 size_t numBytes, NodeCacheUsePolicy cacheUsePolicy /* = NodeCacheUsePolicy::UseCache */) const
157{
158 std::vector<uint8_t> bytes(numBytes);
159 ExecuteAndMapReturnCodes([&] {
161 m_backendHandle, static_cast<PEAK_NODE_CACHE_USE_POLICY>(cacheUsePolicy), bytes.data(), bytes.size());
162 });
163
164 return bytes;
165}
166
167inline void RegisterNode::Write(const std::vector<uint8_t>& bytes)
168{
169 Write(bytes.data(), bytes.size());
170}
171
172inline void RegisterNode::Write(const uint8_t* bytes, size_t size)
173{
174 ExecuteAndMapReturnCodes(
175 [&] { return PEAK_C_ABI_PREFIX PEAK_RegisterNode_Write(m_backendHandle, bytes, size); });
176}
177
178} /* namespace nodes */
179} /* namespace core */
180} /* namespace peak */
~RegisterNode() override=default
size_t Length() const
Returns the length.
Definition peak_register_node.hpp:149
std::false_type NodeHasRange
Definition peak_register_node.hpp:43
static constexpr auto NodeType
Definition peak_register_node.hpp:41
RegisterNode & operator=(RegisterNode &&other)=delete
RegisterNode & operator=(const RegisterNode &other)=delete
std::vector< uint8_t > Read(size_t numBytes, NodeCacheUsePolicy cacheUsePolicy=NodeCacheUsePolicy::UseCache) const
Reads a given amount of bytes.
Definition peak_register_node.hpp:155
RegisterNode(RegisterNode &&other)=delete
void Write(const std::vector< uint8_t > &bytes)
Writes a given amount of bytes.
Definition peak_register_node.hpp:167
std::vector< uint8_t > NodeDataType
Definition peak_register_node.hpp:42
RegisterNode(const RegisterNode &other)=delete
uint64_t Address() const
Returns the address.
Definition peak_register_node.hpp:142
NodeCacheUsePolicy
Defines how node value access should interact with the internal cache.
Definition peak_common_node_enums.hpp:37
@ Register
Definition peak_node.hpp:97
@ UseCache
Definition peak_common_node_enums.hpp:39
The "nodes" namespace contains all GenAPI node types.
Definition peak_boolean_node.hpp:26
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:34
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_dynamic_loader.h:35
struct PEAK_NODE * PEAK_NODE_HANDLE
Definition peak_backend.h:429
int32_t PEAK_NODE_CACHE_USE_POLICY
Definition peak_backend.h:242
PEAK_C_API PEAK_RegisterNode_GetAddress(PEAK_REGISTER_NODE_HANDLE registerNodeHandle, uint64_t *address)
Asks the given register node for its address.
PEAK_C_API PEAK_RegisterNode_ToNode(PEAK_REGISTER_NODE_HANDLE registerNodeHandle, PEAK_NODE_HANDLE *nodeHandle)
Casts the given register node to a node.
struct PEAK_REGISTER_NODE * PEAK_REGISTER_NODE_HANDLE
Definition peak_backend.h:453
PEAK_C_API PEAK_RegisterNode_GetLength(PEAK_REGISTER_NODE_HANDLE registerNodeHandle, size_t *length)
Asks the given register node for its length.
PEAK_C_API PEAK_RegisterNode_Write(PEAK_REGISTER_NODE_HANDLE registerNodeHandle, const uint8_t *bytesToWrite, size_t bytesToWriteSize)
Tells the given register node to write the given bytes.
PEAK_C_API PEAK_RegisterNode_Read(PEAK_REGISTER_NODE_HANDLE registerNodeHandle, PEAK_NODE_CACHE_USE_POLICY cacheUsePolicy, uint8_t *bytesToRead, size_t bytesToReadSize)
Tells the given register node to read the given amount of bytes.
#define PEAK_C_ABI_PREFIX
Definition peak_dll_defines.h:16