Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00023
00024
00025 #ifndef SDO_H
00026 #define SDO_H
00027 #include <stdint.h>
00028 #include "helper.h"
00029 #include "exceptions.h"
00030
00031 namespace icl_hardware {
00032 namespace canopen_schunk {
00033
00040 class SDO
00041 {
00042 public:
00043 typedef boost::shared_ptr<SDO> Ptr;
00044 typedef boost::shared_ptr<const SDO> ConstPtr;
00045
00046
00054 static uint16_t const SDOTX_ID = 0x580;
00055 static uint16_t const SDORX_ID = 0x600;
00056
00057
00058 static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_xBYTE = 0x22;
00059 static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_1BYTE = 0x2F;
00060 static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_2BYTE = 0x2B;
00061 static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_3BYTE = 0x27;
00062 static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_4BYTE = 0x23;
00063 static unsigned char const SDO_SEG_RES_INIT_DOWNLOAD = 0x60;
00064
00065 static unsigned char const SDO_SEG_REQ_INIT_UPLOAD = 0x40;
00066 static unsigned char const SDO_SEG_RES_INIT_UPLOAD_nBYTE = 0x41;
00067 static unsigned char const SDO_SEG_RES_INIT_UPLOAD_xBYTE = 0x42;
00068 static unsigned char const SDO_SEG_RES_INIT_UPLOAD_1BYTE = 0x4F;
00069 static unsigned char const SDO_SEG_RES_INIT_UPLOAD_2BYTE = 0x4B;
00070 static unsigned char const SDO_SEG_RES_INIT_UPLOAD_3BYTE = 0x47;
00071 static unsigned char const SDO_SEG_RES_INIT_UPLOAD_4BYTE = 0x43;
00072 static unsigned char const SDO_SEG_REQ_UPLOAD0 = 0x60;
00073 static unsigned char const SDO_SEG_REQ_UPLOAD1 = 0x70;
00074
00075 static unsigned char const SDO_SEG_ABORT_TRANSFER =0x80;
00076
00077
00078 SDO(const uint8_t& node_id, const CanDevPtr& can_device);
00079
00085 void update(const CanMsg& msg);
00086
00103 bool download(const bool normal_transfer,
00104 const uint16_t index,
00105 const uint8_t subindex,
00106 const std::vector<uint8_t>& usrdata);
00107
00123 template <typename T>
00124 bool download(const bool normal_transfer,
00125 const uint16_t index,
00126 const uint8_t subindex,
00127 const T& usrdata)
00128 {
00129 std::vector<uint8_t> data_vector = convertToCharVector(usrdata);
00130 return download(normal_transfer, index, subindex, data_vector);
00131 }
00132
00133
00148 bool upload(const bool normal_transfer,
00149 const uint16_t index,
00150 const uint8_t subindex,
00151 std::vector<uint8_t>& uploaded_data);
00152
00153 template <typename T>
00168 bool upload(const bool normal_transfer,
00169 const uint16_t index,
00170 const uint8_t subindex,
00171 T& uploaded_data)
00172 {
00173 std::vector<uint8_t> buffer;
00174 bool ret = upload (false, index, subindex, buffer);
00175
00176 if (!ret || buffer.size() == 0)
00177 {
00178 throw ProtocolException (index, subindex, "Uploaded data was empty");
00179 }
00180
00181 uploaded_data = convertFromCharVector<T>(buffer);
00182
00183
00184 return ret;
00185 }
00186
00193 static void addErrorMapFromFile(const std::string& filename);
00194
00199 void setResponseWaitTime(const uint32_t wait_time_ms) {m_response_wait_time_ms = wait_time_ms;}
00200
00204 uint32_t getResponseWaitTime () const {return m_response_wait_time_ms;}
00205
00206 private:
00207 static std::string lookupErrorString(const uint32_t error_code);
00208
00209
00210 uint8_t m_node_id;
00211 CanDevPtr m_can_device;
00212 uint32_t m_response_wait_time_ms;
00213
00214 bool m_data_update_received;
00215 boost::mutex m_data_buffer_mutex;
00216 boost::condition_variable m_data_buffer_updated_cond;
00217 std::vector<uint8_t> m_data_buffer;
00218
00219 static std::map<uint32_t, std::string> m_error_map;
00220 };
00221
00222 }}
00223
00224 #endif // SDO_H