39class SdoErrcCategory :
public ::std::error_category {
42 name() const noexcept
override {
46 ::std::error_condition default_error_condition(
47 int ev)
const noexcept override;
50 message(
int ev)
const override {
56SdoErrcCategory::default_error_condition(
int ev)
const noexcept {
57 switch (
static_cast<SdoErrc>(ev)) {
59 return ::std::errc::protocol_error;
61 return ::std::errc::timed_out;
65 return ::std::errc::protocol_error;
67 return ::std::errc::illegal_byte_sequence;
69 return ::std::errc::not_enough_memory;
73 return ::std::errc::permission_denied;
75 return ::std::errc::no_such_file_or_directory;
79 return ::std::errc::invalid_argument;
81 return ::std::errc::no_such_device_or_address;
83 return ::std::errc::io_error;
87 return ::std::errc::invalid_argument;
89 return ::std::errc::no_such_file_or_directory;
91 return ::std::errc::invalid_argument;
95 return ::std::errc::result_out_of_range;
97 return ::std::errc::protocol_not_supported;
100 return ::std::errc::io_error;
103 return ::std::errc::device_or_resource_busy;
105#if !defined(__MINGW32__) || defined(ENODATA)
107 return ::std::errc::no_message_available;
110 return ::std::error_condition(ev, *
this);
115SdoWhat(uint8_t
id, uint16_t idx, uint8_t subidx, ::std::error_code ec,
116 const ::std::string& what_arg =
"") {
117 ::std::stringstream ss;
118 ss << ::std::uppercase << ::std::setfill(
'0') << ::std::hex;
119 if (!what_arg.empty()) ss << what_arg <<
':';
120 ss << ::std::setw(2) << int(
id) <<
':';
121 ss << ::std::setw(4) << idx <<
':' << ::std::setw(2) << int(subidx) <<
": ";
123 ss <<
" (" << ::std::setw(8) << uint32_t(ec.value()) <<
')';
129SdoError::SdoError(uint8_t
id, uint16_t idx, uint8_t subidx,
130 ::std::error_code ec)
131 : ::
std::system_error(ec, SdoWhat(id, idx, subidx, ec)),
136SdoError::SdoError(uint8_t
id, uint16_t idx, uint8_t subidx,
137 ::std::error_code ec, const ::std::string& what_arg)
138 : ::
std::system_error(ec, SdoWhat(id, idx, subidx, ec, what_arg)),
143SdoError::SdoError(uint8_t
id, uint16_t idx, uint8_t subidx,
144 ::std::error_code ec,
const char* what_arg)
145 : ::
std::system_error(ec, SdoWhat(id, idx, subidx, ec, what_arg)),
150SdoError::SdoError(uint8_t
id, uint16_t idx, uint8_t subidx,
int ev)
151 : SdoError(id, idx, subidx, ::
std::error_code(ev,
SdoCategory())) {}
153SdoError::SdoError(uint8_t
id, uint16_t idx, uint8_t subidx,
int ev,
154 const ::std::string& what_arg)
158SdoError::SdoError(uint8_t
id, uint16_t idx, uint8_t subidx,
int ev,
159 const char* what_arg)
163const ::std::error_category&
165 static const SdoErrcCategory category;
174::std::error_condition
183 return static_cast<SdoErrc>(ec.value());
184 }
else if (ec.category() == ::std::generic_category()) {
185 switch (
static_cast<::std::errc
>(ec.value())) {
186 case ::std::errc::timed_out:
187 return SdoErrc::TIMEOUT;
188 case ::std::errc::not_enough_memory:
189 return SdoErrc::NO_MEM;
191 return SdoErrc::ERROR;
193 }
else if (ec.category() == ::std::system_category()) {
196 return SdoErrc::TIMEOUT;
198 return SdoErrc::NO_MEM;
200 return SdoErrc::ERROR;
203 return SdoErrc::ERROR;
205 return static_cast<SdoErrc>(0);
210 ::std::error_code ec)
noexcept {
213 return ::std::make_exception_ptr(
SdoError(
id, idx, subidx, ec));
215 return ::std::make_exception_ptr(::std::system_error(ec));
217 return ::std::current_exception();
223 ::std::error_code ec,
224 const ::std::string& what_arg)
noexcept {
227 return ::std::make_exception_ptr(
SdoError(
id, idx, subidx, ec, what_arg));
229 return ::std::make_exception_ptr(::std::system_error(ec, what_arg));
231 return ::std::current_exception();
237 ::std::error_code ec,
const char* what_arg)
noexcept {
240 return ::std::make_exception_ptr(
SdoError(
id, idx, subidx, ec, what_arg));
242 return ::std::make_exception_ptr(::std::system_error(ec, what_arg));
244 return ::std::current_exception();
The type of exception thrown when an SDO abort code is received.
This is the internal header file of the C++ CANopen application library.
errnum_t errc2num(int errc)
Transforms a native error code to a platform-independent error number.
@ ERRNUM_TIMEDOUT
Connection timed out.
@ ERRNUM_NOMEM
Not enough space.
This header file is part of the utilities library; it contains C++ convenience functions for creating...
This header file is part of the CANopen library; it contains the Service Data Object (SDO) declaratio...
const char * co_sdo_ac2str(co_unsigned32_t ac)
Returns a string describing an SDO abort code.
const ::std::error_category & SdoCategory() noexcept
Returns a reference to the error category object for SDO abort codes.
SdoErrc
The SDO abort codes.
@ 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.
@ TOGGLE
Toggle bit not altered.
@ 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).
@ 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.
@ 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_OBJ
Object does not exist in the object dictionary.
@ NO_WRITE
Attempt to write a read only object.
@ 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.
@ 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.
::std::error_condition make_error_condition(SdoErrc e) noexcept
Creates an error condition corresponding to an SDO abort code.
::std::error_code make_error_code(SdoErrc e) noexcept
Creates an error code corresponding to an SDO abort code.
::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 ...
This header file is part of the C++ CANopen application library; it contains the SDO error declaratio...