30 #include <boost/thread/mutex.hpp> 33 namespace canopen_schunk {
40 m_can_device(can_device),
41 m_response_wait_time_ms(100),
42 m_data_update_received(false)
53 ss <<
"SDO Update called with wrong canopen ID. Received ID: " <<
static_cast<int>(node_id) <<
" Node ID: " << static_cast<int>(
m_node_id) <<
". Update ignored.";
63 ss <<
"Unexpected length " <<
static_cast<int>(msg.
dlc) <<
" of SDO response. Expected 8.";
70 ss <<
"Data buffer contains unprocessed data which will be overwritten.";
75 for (
size_t i = 0; i < msg.
dlc; ++i)
87 const std::vector< uint8_t >& usrdata)
90 size_t num_bytes = usrdata.size();
91 if (num_bytes > 4 || normal_transfer)
93 std::string mode =
"expedited";
99 ss <<
"So far only expedited transfers with maximum 4 data bytes are supported. " 100 <<
"However, " << mode <<
" transfer of " << num_bytes
101 <<
" bytes was requested. Aborting download";
107 throw ProtocolException (index, subindex,
"Empty data message passed to download function.");
134 msg.
data[1] = index & 0xff;
135 msg.
data[2] = index >> 8;
136 msg.
data[3] = subindex;
137 for (
size_t i = 0; i < 4; ++i)
141 msg.
data[4 + i] = usrdata[i];
161 throw (
TimeoutException(index, subindex,
"No response to SDO download request received!"));
175 std::stringstream ss;
176 ss <<
"Unexpected length " <<
m_data_buffer.size() <<
" of SDO response. Expected 8.";
182 std::stringstream ss;
188 std::stringstream ss;
196 if (rdindex != index || rdsubindex != subindex)
198 std::stringstream ss;
212 std::vector<uint8_t>& uploaded_data)
217 LOGGING_ERROR_C(CanOpen,
SDO,
"So far only expedited transfers with maximum 4 data bytes " 219 <<
"However, blocked transfer of was requested. Aborting upload" <<
endl);
229 msg.
data[1] = index & 0xff;
230 msg.
data[2] = index >> 8;
231 msg.
data[3] = subindex;
245 throw (
TimeoutException(index, subindex,
"No response to SDO upload request received!"));
258 std::stringstream ss;
259 ss <<
"Unexpected length " <<
m_data_buffer.size() <<
" of SDO response. Expected 8.";
265 std::stringstream ss;
272 if (rdindex != index || rdsubindex != subindex)
274 std::stringstream ss;
280 uploaded_data.clear();
307 std::stringstream ss;
308 ss <<
"Illegal SDO upload response received. Please note that so far only expedited " 309 <<
" uploads with a data length of up to 4 bytes are supported.\n" 315 for (
size_t i = 0; i < num_bytes; ++i)
325 std::map<uint32_t, std::string>::iterator map_it =
m_error_map.find(error_code);
328 return map_it->second;
332 std::stringstream ss;
333 ss <<
"Unknown error code: " <<
hexToString(error_code);
342 m_error_map.insert(new_entries.begin(), new_entries.end());
static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_3BYTE
static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_1BYTE
static unsigned char const SDO_SEG_RES_INIT_UPLOAD_2BYTE
static const uint16_t ID_RSDO_MIN
SDO(const uint8_t &node_id, const CanDevPtr &can_device)
static unsigned char const SDO_SEG_REQ_INIT_UPLOAD
std::string hexArrayToString(const unsigned char *msg, const uint8_t length)
Transforms an array of unsigned chars into a string of Hex representations of those chars...
Basic CanOpen exception that contains the Object dictionary index and subindex.
#define LOGGING_DEBUG(streamname, arg)
bool download(const bool normal_transfer, const uint16_t index, const uint8_t subindex, const std::vector< uint8_t > &usrdata)
Downloads SDO data from the master to the slave (From PC to node).
If a device response times out, this exception will be thrown.
static unsigned char const SDO_SEG_RES_INIT_UPLOAD_4BYTE
#define LOGGING_WARNING_C(streamname, classname, arg)
uint32_t m_response_wait_time_ms
static std::string lookupErrorString(const uint32_t error_code)
Exceptions relating to device responses.
bool m_data_update_received
ThreadStream & endl(ThreadStream &stream)
boost::mutex m_data_buffer_mutex
void update(const CanMsg &msg)
update updates the SDO data with newly received messages
std::vector< uint8_t > m_data_buffer
static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_2BYTE
boost::condition_variable m_data_buffer_updated_cond
bool upload(const bool normal_transfer, const uint16_t index, const uint8_t subindex, std::vector< uint8_t > &uploaded_data)
Uploads data from a slave (node) to a master (PC).
The SDO class represents Service Data Objects (SDO) that are used for slow access of the canOpen obje...
static void addErrorMapFromFile(const std::string &filename)
Adds an error map from an INI file to all SDOs. This should be called once to get human readable erro...
std::map< uint32_t, std::string > getErrorMapFromConfigFile(const std::string &filename, const std::string &category)
Creates an error map from a given INI file.
static std::map< uint32_t, std::string > m_error_map
static unsigned char const SDO_SEG_ABORT_TRANSFER
static const uint16_t ID_TSDO_MIN
static unsigned char const SDO_SEG_RES_INIT_UPLOAD_3BYTE
std::string hexToString(const uint64_t num)
Converts a hexadecimal number into its string representation 0xXX.
static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_4BYTE
void notify_one() BOOST_NOEXCEPT
static unsigned char const SDO_SEG_RES_INIT_DOWNLOAD
#define LOGGING_ERROR_C(streamname, classname, arg)
static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_xBYTE
static unsigned char const SDO_SEG_RES_INIT_UPLOAD_1BYTE