Lely core libraries 2.3.4
sdo_error.hpp
Go to the documentation of this file.
1
22#ifndef LELY_COAPP_SDO_ERROR_HPP_
23#define LELY_COAPP_SDO_ERROR_HPP_
24
25#include <lely/features.h>
26
27#include <stdexcept>
28#include <string>
29#include <system_error>
30
31#include <cstdint>
32
33#ifdef ERROR
34#undef ERROR
35#endif
36
37namespace lely {
38
39namespace canopen {
40
42enum class SdoErrc : uint32_t {
44 TOGGLE = UINT32_C(0x05030000),
46 TIMEOUT = UINT32_C(0x05040000),
48 NO_CS = UINT32_C(0x05040001),
50 BLK_SIZE = UINT32_C(0x05040002),
52 BLK_SEQ = UINT32_C(0x05040003),
54 BLK_CRC = UINT32_C(0x05040004),
56 NO_MEM = UINT32_C(0x05040005),
58 NO_ACCESS = UINT32_C(0x06010000),
60 NO_READ = UINT32_C(0x06010001),
62 NO_WRITE = UINT32_C(0x06010002),
64 NO_OBJ = UINT32_C(0x06020000),
66 NO_PDO = UINT32_C(0x06040041),
71 PDO_LEN = UINT32_C(0x06040042),
73 PARAM = UINT32_C(0x06040043),
75 COMPAT = UINT32_C(0x06040047),
77 HARDWARE = UINT32_C(0x06060000),
79 TYPE_LEN = UINT32_C(0x06070010),
81 TYPE_LEN_HI = UINT32_C(0x06070012),
83 TYPE_LEN_LO = UINT32_C(0x06070013),
85 NO_SUB = UINT32_C(0x06090011),
87 PARAM_VAL = UINT32_C(0x06090030),
89 PARAM_HI = UINT32_C(0x06090031),
91 PARAM_LO = UINT32_C(0x06090032),
93 PARAM_RANGE = UINT32_C(0x06090036),
95 NO_SDO = UINT32_C(0x060a0023),
97 ERROR = UINT32_C(0x08000000),
99 DATA = UINT32_C(0x08000020),
104 DATA_CTL = UINT32_C(0x08000021),
109 DATA_DEV = UINT32_C(0x08000022),
115 NO_OD = UINT32_C(0x08000023),
117 NO_VAL = UINT32_C(0x08000024)
118};
119
121class SdoError : public ::std::system_error {
122 public:
123 SdoError(uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code ec);
124 SdoError(uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code ec,
125 const ::std::string& what_arg);
126 SdoError(uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code ec,
127 const char* what_arg);
128 SdoError(uint8_t id, uint16_t idx, uint8_t subidx, int ev);
129 SdoError(uint8_t id, uint16_t idx, uint8_t subidx, int ev,
130 const ::std::string& what_arg);
131 SdoError(uint8_t id, uint16_t idx, uint8_t subidx, int ev,
132 const char* what_arg);
133
135 uint8_t
136 id() const noexcept {
137 return id_;
138 }
139
141 uint16_t
142 idx() const noexcept {
143 return idx_;
144 }
145
147 uint8_t
148 subidx() const noexcept {
149 return subidx_;
150 }
151
152 private:
153 uint8_t id_{0};
154 uint16_t idx_{0};
155 uint8_t subidx_{0};
156};
157
159const ::std::error_category& SdoCategory() noexcept;
160
162::std::error_code make_error_code(SdoErrc e) noexcept;
163
165::std::error_condition make_error_condition(SdoErrc e) noexcept;
166
168SdoErrc sdo_errc(::std::error_code ec);
169
180::std::exception_ptr make_sdo_exception_ptr(uint8_t id, uint16_t idx,
181 uint8_t subidx,
182 ::std::error_code ec) noexcept;
183
194::std::exception_ptr make_sdo_exception_ptr(
195 uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code ec,
196 const ::std::string& what_arg) noexcept;
197
208::std::exception_ptr make_sdo_exception_ptr(uint8_t id, uint16_t idx,
209 uint8_t subidx,
210 ::std::error_code ec,
211 const char* what_arg) noexcept;
212
218[[noreturn]] inline void
219throw_sdo_error(uint8_t id, uint16_t idx, uint8_t subidx,
220 ::std::error_code ec) {
221 if (ec.category() == SdoCategory())
222 throw SdoError(id, idx, subidx, ec);
223 else
224 throw ::std::system_error(ec);
225}
226
233[[noreturn]] inline void
234throw_sdo_error(uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code ec,
235 const ::std::string& what_arg) {
236 if (ec.category() == SdoCategory())
237 throw SdoError(id, idx, subidx, ec, what_arg);
238 else
239 throw ::std::system_error(ec, what_arg);
240}
241
248[[noreturn]] inline void
249throw_sdo_error(uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code ec,
250 const char* what_arg) {
251 if (ec.category() == SdoCategory())
252 throw SdoError(id, idx, subidx, ec, what_arg);
253 else
254 throw ::std::system_error(ec, what_arg);
255}
256
257} // namespace canopen
258
259} // namespace lely
260
261namespace std {
262
263template <>
264struct is_error_code_enum<::lely::canopen::SdoErrc> : true_type {};
265
266} // namespace std
267
268#endif // LELY_COAPP_SDO_ERROR_HPP_
The type of exception thrown when an SDO abort code is received.
Definition: sdo_error.hpp:121
uint8_t id() const noexcept
Returns the node-ID.
Definition: sdo_error.hpp:136
uint16_t idx() const noexcept
Returns the object index.
Definition: sdo_error.hpp:142
uint8_t subidx() const noexcept
Returns the object sub-index.
Definition: sdo_error.hpp:148
This header file is part of the Lely libraries; it contains the compiler feature definitions.
@ TOGGLE
The mask to get/set the toggle bit from an NMT state.
const ::std::error_category & SdoCategory() noexcept
Returns a reference to the error category object for SDO abort codes.
Definition: sdo_error.cpp:164
SdoErrc
The SDO abort codes.
Definition: sdo_error.hpp:42
@ TIMEOUT
SDO protocol timed out.
@ BLK_SIZE
Invalid block size (block mode only).
@ NO_CS
Client/server command specifier not valid or unknown.
@ TYPE_LEN_LO
Data type does not match, length of service parameter too low.
@ PARAM_VAL
Invalid value for parameter (download only).
@ PARAM
General parameter incompatibility reason.
@ NO_VAL
No data available. (NO_DATA is a macro defined in <netdb.h>)
@ NO_SUB
Sub-index does not exist.
@ PARAM_LO
Value of parameter written too low (download only).
@ BLK_SEQ
Invalid sequence number (block mode only).
@ NO_OD
Object dictionary dynamic generation fails or no object dictionary is present (e.g.
@ DATA_DEV
Data cannot be transferred or stored to the application because of the present device state.
@ HARDWARE
Access failed due to a hardware error.
@ PDO_LEN
The number and length of the objects to be mapped would exceed the PDO length.
@ BLK_CRC
CRC error (block mode only).
@ PARAM_HI
Value of parameter written too high (download only).
@ TYPE_LEN
Data type does not match, length of service parameter does not match.
@ PARAM_RANGE
Maximum value is less than minimum value (download only).
@ COMPAT
General internal incompatibility in the device.
@ NO_MEM
Out of memory.
@ NO_OBJ
Object does not exist in the object dictionary.
@ NO_WRITE
Attempt to write a read only object.
@ ERROR
General error.
@ NO_SDO
Resource not available: SDO connection.
@ DATA_CTL
Data cannot be transferred or stored to the application because of local control.
@ TYPE_LEN_HI
Data type does not match, length of service parameter too high.
@ NO_ACCESS
Unsupported access to an object.
@ NO_PDO
Object cannot be mapped to the PDO.
@ DATA
Data cannot be transferred or stored to the application.
@ NO_READ
Attempt to read a write only object.
SdoErrc sdo_errc(::std::error_code ec)
Returns the SDO abort code corresponding to an error code.
Definition: sdo_error.cpp:180
::std::error_condition make_error_condition(SdoErrc e) noexcept
Creates an error condition corresponding to an SDO abort code.
Definition: sdo_error.cpp:175
void throw_sdo_error(uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code ec)
Throws a lely::canopen::SdoError with the specified attributes if ec is an SDO error (ec....
Definition: sdo_error.hpp:219
::std::error_code make_error_code(SdoErrc e) noexcept
Creates an error code corresponding to an SDO abort code.
Definition: sdo_error.cpp:170
::std::exception_ptr make_sdo_exception_ptr(uint8_t id, uint16_t idx, uint8_t subidx, ::std::error_code ec) noexcept
Creates an std::exception_ptr that holds a reference to a lely::canopen::SdoError with the specified ...
Definition: sdo_error.cpp:209
STL namespace.