Lely core libraries 1.9.2
device.hpp
Go to the documentation of this file.
1
22#ifndef LELY_COAPP_DEVICE_HPP_
23#define LELY_COAPP_DEVICE_HPP_
24
27
28#include <memory>
29#include <typeinfo>
30
31namespace lely {
32
33// The CANopen device from <lely/co/dev.hpp>.
34class CODev;
35
36namespace canopen {
37
42class Device {
43 public:
58 Device(const ::std::string& dcf_txt, const ::std::string& dcf_bin = "",
59 uint8_t id = 0xff, BasicLockable* mutex = nullptr);
60
61 Device(const Device&) = delete;
62 Device(Device&&) = default;
63
64 Device& operator=(const Device&) = delete;
65 Device& operator=(Device&&);
66
68 uint8_t netid() const noexcept;
69
71 uint8_t id() const noexcept;
72
85 template <class T>
86 typename ::std::enable_if<detail::IsCanopenType<T>::value, T>::type Read(
87 uint16_t idx, uint8_t subidx) const;
88
100 template <class T>
101 typename ::std::enable_if<detail::IsCanopenType<T>::value, T>::type Read(
102 uint16_t idx, uint8_t subidx, ::std::error_code& ec) const;
103
115 template <class T>
116 typename ::std::enable_if<detail::IsCanopenBasic<T>::value>::type Write(
117 uint16_t idx, uint8_t subidx, T value);
118
129 template <class T>
130 typename ::std::enable_if<detail::IsCanopenBasic<T>::value>::type Write(
131 uint16_t idx, uint8_t subidx, T value, ::std::error_code& ec);
132
144 template <class T>
145 typename ::std::enable_if<detail::IsCanopenArray<T>::value>::type Write(
146 uint16_t idx, uint8_t subidx, const T& value);
147
158 template <class T>
159 typename ::std::enable_if<detail::IsCanopenArray<T>::value>::type Write(
160 uint16_t idx, uint8_t subidx, const T& value, ::std::error_code& ec);
161
173 void Write(uint16_t idx, uint8_t subidx, const char* value);
174
185 void Write(uint16_t idx, uint8_t subidx, const char* value,
186 ::std::error_code& ec);
187
200 void Write(uint16_t idx, uint8_t subidx, const char16_t* value);
201
213 void Write(uint16_t idx, uint8_t subidx, const char16_t* value,
214 ::std::error_code& ec);
215
228 void Write(uint16_t idx, uint8_t subidx, const void* p, ::std::size_t n);
229
241 void Write(uint16_t idx, uint8_t subidx, const void* p, ::std::size_t n,
242 ::std::error_code& ec);
243
244 protected:
245 ~Device();
246
248 CODev* dev() const noexcept;
249
261 const ::std::type_info& Type(uint16_t idx, uint8_t subidx) const;
262
274 const ::std::type_info& Type(uint16_t idx, uint8_t subidx,
275 ::std::error_code& ec) const;
276
290 template <class T>
291 typename ::std::enable_if<detail::IsCanopenType<T>::value, T>::type Get(
292 uint16_t idx, uint8_t subidx) const;
293
306 template <class T>
307 typename ::std::enable_if<detail::IsCanopenType<T>::value, T>::type Get(
308 uint16_t idx, uint8_t subidx, ::std::error_code& ec) const;
309
322 template <class T>
323 typename ::std::enable_if<detail::IsCanopenBasic<T>::value>::type Set(
324 uint16_t idx, uint8_t subidx, T value);
325
337 template <class T>
338 typename ::std::enable_if<detail::IsCanopenBasic<T>::value>::type Set(
339 uint16_t idx, uint8_t subidx, T value, ::std::error_code& ec);
340
353 template <class T>
354 typename ::std::enable_if<detail::IsCanopenArray<T>::value>::type Set(
355 uint16_t idx, uint8_t subidx, const T& value);
356
368 template <class T>
369 typename ::std::enable_if<detail::IsCanopenArray<T>::value>::type Set(
370 uint16_t idx, uint8_t subidx, const T& value, ::std::error_code& ec);
371
384 void Set(uint16_t idx, uint8_t subidx, const char* value);
385
397 void Set(uint16_t idx, uint8_t subidx, const char* value,
398 ::std::error_code& ec);
399
413 void Set(uint16_t idx, uint8_t subidx, const char16_t* value);
414
427 void Set(uint16_t idx, uint8_t subidx, const char16_t* value,
428 ::std::error_code& ec);
429
443 void Set(uint16_t idx, uint8_t subidx, const void* p, ::std::size_t n);
444
457 void Set(uint16_t idx, uint8_t subidx, const void* p, ::std::size_t n,
458 ::std::error_code& ec);
459
460 private:
461 struct Impl_;
462 ::std::unique_ptr<Impl_> impl_;
463};
464
465} // namespace canopen
466
467} // namespace lely
468
469#endif // LELY_COAPP_DEVICE_HPP_
An opaque CANopen device type.
Definition: dev.hpp:76
An abstract interface conforming to the BasicLockable concept.
Definition: coapp.hpp:40
The CANopen device description.
Definition: device.hpp:42
uint8_t netid() const noexcept
Returns the network-ID.
Definition: device.cpp:87
typename::std::enable_if< detail::IsCanopenType< T >::value, T >::type Get(uint16_t idx, uint8_t subidx) const
Reads the value of a sub-object.
Definition: device.cpp:462
typename::std::enable_if< detail::IsCanopenType< T >::value, T >::type Read(uint16_t idx, uint8_t subidx) const
Submits an SDO upload request to the local object dictionary.
Definition: device.cpp:118
const ::std::type_info & Type(uint16_t idx, uint8_t subidx) const
Returns the type of a sub-object.
Definition: device.cpp:392
CODev * dev() const noexcept
Returns a pointer to the internal CANopen device from <lely/co/dev.hpp>.
Definition: device.cpp:387
typename::std::enable_if< detail::IsCanopenBasic< T >::value >::type Set(uint16_t idx, uint8_t subidx, T value)
Writes a CANopen basic value to a sub-object.
Definition: device.cpp:499
typename::std::enable_if< detail::IsCanopenBasic< T >::value >::type Write(uint16_t idx, uint8_t subidx, T value)
Submits an SDO download request to the local object dictionary.
Definition: device.cpp:145
uint8_t id() const noexcept
Returns the node-ID.
Definition: device.cpp:94
Global namespace for the Lely Industries N.V. libraries.
Definition: buf.hpp:32
This header file is part of the C++ CANopen application library; it contains the SDO error declaratio...
The internal implementation of the CANopen device description.
Definition: device.cpp:38
This header file is part of the C++ CANopen application library; it contains the CANopen type traits.