IDS peak genericC++ v1.17.0
Loading...
Searching...
No Matches
peak_register_node.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
10
12#include <peak/dll_interface/peak_dll_interface_util.hpp>
13#include <peak/error_handling/peak_error_handling.hpp>
16
17#include <type_traits>
18#include <cstddef>
19#include <cstdint>
20#include <vector>
21
22
23namespace peak
24{
25namespace core
26{
27namespace nodes
28{
29
35class RegisterNode : public Node
36{
37public:
38 static constexpr auto NodeType = nodes::NodeType::Register;
39 using NodeDataType = std::vector<uint8_t>;
40 using NodeHasRange = std::false_type;
41
42 RegisterNode() = delete;
43 ~RegisterNode() override = default;
44 RegisterNode(const RegisterNode& other) = delete;
45 RegisterNode& operator=(const RegisterNode& other) = delete;
46 RegisterNode(RegisterNode&& other) = delete;
48
58 PEAK_COMMON_NO_DISCARD uint64_t Address() const;
59
69 PEAK_COMMON_NO_DISCARD size_t Length() const;
70
85 PEAK_COMMON_NO_DISCARD std::vector<uint8_t> Read(
86 size_t numBytes, NodeCacheUsePolicy cacheUsePolicy = NodeCacheUsePolicy::UseCache) const;
87
101 PEAK_COMMON_NO_DISCARD std::vector<uint8_t> ReadAll(
102 NodeCacheUsePolicy cacheUsePolicy = NodeCacheUsePolicy::UseCache) const;
103
114 void Write(const std::vector<uint8_t>& bytes);
115
127 void Write(const uint8_t* bytes, size_t size);
128
129private:
130 friend ClassCreator<RegisterNode>;
131 RegisterNode(PEAK_REGISTER_NODE_HANDLE registerNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap);
132 PEAK_REGISTER_NODE_HANDLE m_backendHandle;
133};
134
135} /* namespace nodes */
136} /* namespace core */
137} /* namespace peak */
138
139/* Implementation */
140namespace peak
141{
142namespace core
143{
144namespace nodes
145{
146
148 PEAK_REGISTER_NODE_HANDLE registerNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap)
149 : Node(QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* nodeHandle) {
150 return PEAK_C_ABI_PREFIX PEAK_RegisterNode_ToNode(registerNodeHandle, nodeHandle);
151 }),
152 parentNodeMap)
153 , m_backendHandle(registerNodeHandle)
154{}
155
156inline uint64_t RegisterNode::Address() const
157{
158 return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* address) {
159 return PEAK_C_ABI_PREFIX PEAK_RegisterNode_GetAddress(m_backendHandle, address);
160 });
161}
162
163inline size_t RegisterNode::Length() const
164{
165 return QueryNumericFromCInterfaceFunction<size_t>(
166 [&](size_t* length) { return PEAK_C_ABI_PREFIX PEAK_RegisterNode_GetLength(m_backendHandle, length); });
167}
168
169inline std::vector<uint8_t> RegisterNode::Read(
170 size_t numBytes, NodeCacheUsePolicy cacheUsePolicy /* = NodeCacheUsePolicy::UseCache */) const
171{
172 std::vector<uint8_t> bytes(numBytes);
173 ExecuteAndMapReturnCodes([&] {
175 m_backendHandle, static_cast<PEAK_NODE_CACHE_USE_POLICY>(cacheUsePolicy), bytes.data(), bytes.size());
176 });
177
178 return bytes;
179}
180
181inline std::vector<uint8_t> RegisterNode::ReadAll(NodeCacheUsePolicy cacheUsePolicy) const
182{
183 return Read(Length(), cacheUsePolicy);
184}
185
186inline void RegisterNode::Write(const std::vector<uint8_t>& bytes)
187{
188 Write(bytes.data(), bytes.size());
189}
190
191inline void RegisterNode::Write(const uint8_t* bytes, size_t size)
192{
193 ExecuteAndMapReturnCodes(
194 [&] { return PEAK_C_ABI_PREFIX PEAK_RegisterNode_Write(m_backendHandle, bytes, size); });
195}
196
197} /* namespace nodes */
198} /* namespace core */
199} /* namespace peak */
~RegisterNode() override=default
PEAK_COMMON_NO_DISCARD size_t Length() const
Returns the length.
Definition peak_register_node.hpp:163
std::false_type NodeHasRange
Definition peak_register_node.hpp:40
static constexpr auto NodeType
Definition peak_register_node.hpp:38
RegisterNode & operator=(RegisterNode &&other)=delete
RegisterNode & operator=(const RegisterNode &other)=delete
PEAK_COMMON_NO_DISCARD std::vector< uint8_t > Read(size_t numBytes, NodeCacheUsePolicy cacheUsePolicy=NodeCacheUsePolicy::UseCache) const
Reads a given amount of bytes.
Definition peak_register_node.hpp:169
RegisterNode(RegisterNode &&other)=delete
void Write(const std::vector< uint8_t > &bytes)
Writes a given amount of bytes.
Definition peak_register_node.hpp:186
std::vector< uint8_t > NodeDataType
Definition peak_register_node.hpp:39
RegisterNode(const RegisterNode &other)=delete
PEAK_COMMON_NO_DISCARD uint64_t Address() const
Returns the address.
Definition peak_register_node.hpp:156
PEAK_COMMON_NO_DISCARD std::vector< uint8_t > ReadAll(NodeCacheUsePolicy cacheUsePolicy=NodeCacheUsePolicy::UseCache) const
Reads all bytes.
Definition peak_register_node.hpp:181
NodeCacheUsePolicy
Defines how node value access should interact with the internal cache.
Definition peak_common_node_enums.hpp:36
@ Register
Definition peak_node.hpp:94
@ UseCache
Definition peak_common_node_enums.hpp:38
The "nodes" namespace contains all GenAPI node types.
Definition peak_utils.hpp:31
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:32
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_buffer.hpp:29
struct PEAK_NODE * PEAK_NODE_HANDLE
Definition peak_backend.h:427
int32_t PEAK_NODE_CACHE_USE_POLICY
Definition peak_backend.h:240
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:451
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_COMMON_NO_DISCARD
Definition peak_common_defines.h:89
#define PEAK_C_ABI_PREFIX
Definition peak_dll_defines.h:13