SDO.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of the SCHUNK Canopen Driver suite.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 SCHUNK GmbH, Lauffen/Neckar Germany
12 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
23 //----------------------------------------------------------------------
24 
25 #ifndef SDO_H
26 #define SDO_H
27 #include <stdint.h>
28 #include "helper.h"
29 #include "exceptions.h"
30 
31 namespace icl_hardware {
32 namespace canopen_schunk {
33 
40 class SDO
41 {
42 public:
45 
46 
54  static uint16_t const SDOTX_ID = 0x580; // # 1408 -> 1409 ... 1535
55  static uint16_t const SDORX_ID = 0x600; // # 1536 -> 1537 ... 1663
56 
57  // download
58  static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_xBYTE = 0x22;
59  static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_1BYTE = 0x2F;
60  static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_2BYTE = 0x2B;
61  static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_3BYTE = 0x27;
62  static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_4BYTE = 0x23;
63  static unsigned char const SDO_SEG_RES_INIT_DOWNLOAD = 0x60;
64  // upload
65  static unsigned char const SDO_SEG_REQ_INIT_UPLOAD = 0x40;
66  static unsigned char const SDO_SEG_RES_INIT_UPLOAD_nBYTE = 0x41;
67  static unsigned char const SDO_SEG_RES_INIT_UPLOAD_xBYTE = 0x42;
68  static unsigned char const SDO_SEG_RES_INIT_UPLOAD_1BYTE = 0x4F;
69  static unsigned char const SDO_SEG_RES_INIT_UPLOAD_2BYTE = 0x4B;
70  static unsigned char const SDO_SEG_RES_INIT_UPLOAD_3BYTE = 0x47;
71  static unsigned char const SDO_SEG_RES_INIT_UPLOAD_4BYTE = 0x43;
72  static unsigned char const SDO_SEG_REQ_UPLOAD0 = 0x60; // used for segmented upload only
73  static unsigned char const SDO_SEG_REQ_UPLOAD1 = 0x70; // used for segmented upload only
74 
75  static unsigned char const SDO_SEG_ABORT_TRANSFER =0x80;
76 
77 
78  SDO(const uint8_t& node_id, const CanDevPtr& can_device);
79 
85  void update(const CanMsg& msg);
86 
103  bool download(const bool normal_transfer,
104  const uint16_t index,
105  const uint8_t subindex,
106  const std::vector<uint8_t>& usrdata);
107 
123  template <typename T>
124  bool download(const bool normal_transfer,
125  const uint16_t index,
126  const uint8_t subindex,
127  const T& usrdata)
128  {
129  std::vector<uint8_t> data_vector = convertToCharVector(usrdata);
130  return download(normal_transfer, index, subindex, data_vector);
131  }
132 
133 
148  bool upload(const bool normal_transfer,
149  const uint16_t index,
150  const uint8_t subindex,
151  std::vector<uint8_t>& uploaded_data);
152 
153  template <typename T>
168  bool upload(const bool normal_transfer,
169  const uint16_t index,
170  const uint8_t subindex,
171  T& uploaded_data)
172  {
173  std::vector<uint8_t> buffer;
174  bool ret = upload (false, index, subindex, buffer);
175 
176  if (!ret || buffer.size() == 0)
177  {
178  throw ProtocolException (index, subindex, "Uploaded data was empty");
179  }
180 
181  uploaded_data = convertFromCharVector<T>(buffer);
182 
183  // To be honest, this only can be true right now, otherwise we throw
184  return ret;
185  }
186 
193  static void addErrorMapFromFile(const std::string& filename);
194 
199  void setResponseWaitTime(const uint32_t wait_time_ms) {m_response_wait_time_ms = wait_time_ms;}
200 
205 
206 private:
207  static std::string lookupErrorString(const uint32_t error_code);
208 
209 
213 
215  boost::mutex m_data_buffer_mutex;
217  std::vector<uint8_t> m_data_buffer;
218 
219  static std::map<uint32_t, std::string> m_error_map;
220 };
221 
222 }}//end of NS
223 
224 #endif // SDO_H
unsigned int uint32_t
static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_3BYTE
Definition: SDO.h:61
static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_1BYTE
Definition: SDO.h:59
filename
static unsigned char const SDO_SEG_RES_INIT_UPLOAD_2BYTE
Definition: SDO.h:69
static unsigned char const SDO_SEG_REQ_UPLOAD1
Definition: SDO.h:73
SDO(const uint8_t &node_id, const CanDevPtr &can_device)
Definition: SDO.cpp:38
static unsigned char const SDO_SEG_REQ_INIT_UPLOAD
Definition: SDO.h:65
Basic CanOpen exception that contains the Object dictionary index and subindex.
Definition: exceptions.h:37
boost::shared_ptr< SDO > Ptr
Definition: SDO.h:43
std::vector< uint8_t > convertToCharVector(const T value)
This little helper transforms any datatype that has a size of at most 4 Bytes into a vector of uint8_...
Definition: helper.h:104
boost::shared_ptr< const SDO > ConstPtr
Definition: SDO.h:44
static unsigned char const SDO_SEG_RES_INIT_UPLOAD_xBYTE
Definition: SDO.h:67
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).
Definition: SDO.cpp:84
static unsigned char const SDO_SEG_RES_INIT_UPLOAD_4BYTE
Definition: SDO.h:71
bool upload(const bool normal_transfer, const uint16_t index, const uint8_t subindex, T &uploaded_data)
Uploads data from a slave (node) to a master (PC).
Definition: SDO.h:168
static std::string lookupErrorString(const uint32_t error_code)
Definition: SDO.cpp:323
unsigned char uint8_t
bool download(const bool normal_transfer, const uint16_t index, const uint8_t subindex, const T &usrdata)
Downloads SDO data from the master to the slave (From PC to node)
Definition: SDO.h:124
boost::mutex m_data_buffer_mutex
Definition: SDO.h:215
void update(const CanMsg &msg)
update updates the SDO data with newly received messages
Definition: SDO.cpp:46
std::vector< uint8_t > m_data_buffer
Definition: SDO.h:217
static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_2BYTE
Definition: SDO.h:60
boost::condition_variable m_data_buffer_updated_cond
Definition: SDO.h:216
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).
Definition: SDO.cpp:209
The SDO class represents Service Data Objects (SDO) that are used for slow access of the canOpen obje...
Definition: SDO.h:40
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...
Definition: SDO.cpp:339
static std::map< uint32_t, std::string > m_error_map
Definition: SDO.h:219
static unsigned char const SDO_SEG_ABORT_TRANSFER
Definition: SDO.h:75
static unsigned char const SDO_SEG_RES_INIT_UPLOAD_3BYTE
Definition: SDO.h:70
static unsigned char const SDO_SEG_RES_INIT_UPLOAD_nBYTE
Definition: SDO.h:66
uint32_t getResponseWaitTime() const
Get the current SDO transfer response wait time.
Definition: SDO.h:204
static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_4BYTE
Definition: SDO.h:62
unsigned short uint16_t
static uint16_t const SDOTX_ID
Definition: SDO.h:54
void setResponseWaitTime(const uint32_t wait_time_ms)
Set the time in milliseconds that should be waited for an SDO response when performing a transfer...
Definition: SDO.h:199
static unsigned char const SDO_SEG_RES_INIT_DOWNLOAD
Definition: SDO.h:63
static unsigned char const SDO_SEG_REQ_INIT_DOWNLOAD_xBYTE
Definition: SDO.h:58
static unsigned char const SDO_SEG_RES_INIT_UPLOAD_1BYTE
Definition: SDO.h:68
static unsigned char const SDO_SEG_REQ_UPLOAD0
Definition: SDO.h:72
static uint16_t const SDORX_ID
Definition: SDO.h:55


schunk_canopen_driver
Author(s): Felix Mauch , Georg Heppner
autogenerated on Mon Jun 10 2019 15:07:49