DS301Node.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 DS301NODE_H
26 #define DS301NODE_H
27 
28 // CANOPEN inlcudes
29 #include "NMT.h"
30 #include "RPDO.h"
31 #include "TPDO.h"
32 #include "SDO.h"
33 #include "EMCY.h"
34 #include "HeartBeatMonitor.h"
35 
36 #include "helper.h"
37 #include "Logging.h"
38 #include "exceptions.h"
39 
40 #include <boost/unordered_map.hpp>
41 
42 #ifdef _IC_BUILDER_ICL_COMM_WEBSOCKET_
43 // Schunk Diagnostics addon
44 #include <icl_comm_websocket/WsBroadcaster.h>
45 #else
46 // Forward Deklaration of the WsBroadcaster
47 // This is not needed for normal driver operation
48 // but might be added later. To keep the interface the same
49 // a forward declaration becomes necessary
50 namespace icl_comm{
51 namespace websocket{
52  class WsBroadcaster;
53 }}// NS end
54 #endif // _IC_BUILDER_ICL_COMM_WEBSOCKET_
55 
56 
57 namespace icl_hardware {
58 namespace canopen_schunk {
59 
67 class DS301Node
68 {
69 public:
78  struct PDOMapEntry
79  {
82  };
83 
88  enum ePDO_TYPE
89  {
91  TRANSMIT_PDO
92  };
93 
98 
99  DS301Node(const uint8_t node_id, const CanDevPtr& can_device, HeartBeatMonitor::Ptr heartbeat_monitor);
100 
101  uint8_t getNodeId() const {return m_node_id;}
102 
103 
107  virtual void initNode();
108 
112  virtual void registerWSBroadcaster(boost::shared_ptr<icl_comm::websocket::WsBroadcaster> broadcaster);
113 
118  virtual void startHeartbeat();
119 
135  virtual void initPDOMappingSingle (const PDO::MappingConfigurationList& config,
136  const uint16_t pdo_nr,
137  const PDO::eTransmissionType& transmission_type,
138  const ePDO_TYPE& pdo_type,
139  const bool dummy_mapping = false,
140  const uint8_t cyclic_timeout_cycles = 0);
141 
157  virtual void appendPDOMappingSingle (const PDO::MappingConfigurationList& config,
158  const uint16_t pdo_nr,
159  const PDO::eTransmissionType& transmission_type,
160  const ePDO_TYPE& pdo_type,
161  const bool dummy_mapping = false,
162  const uint8_t cyclic_timeout_cycles = 0);
163 
164  template <typename T>
165  T getRPDOValue (const std::string& identifier)
166  {
167  // find pdo with this identifier
168  if (m_rpdo_mapping.find(identifier) == m_rpdo_mapping.end())
169  {
170  std::stringstream ss;
171  ss << "Could not find RPDO entry identifier string " << identifier << ". Aborting action now. ";
172  throw PDOException(ss.str());
173  }
174  const PDOMapEntry& entry = m_rpdo_mapping[identifier];
175 
176  const PDO::Mapping& mapping = m_rpdos[entry.pdo_nr]->m_mapping_list[entry.pdo_mapping_index];
177  // check if it is castable to the requested value
178 
179  return convertFromCharVector<T>(mapping.data);
180  }
181 
189  template <typename T>
190  T getTPDOValue (const std::string& identifier)
191  {
192  // find pdo with this identifier
193  if (m_tpdo_mapping.find(identifier) == m_tpdo_mapping.end())
194  {
195  std::stringstream ss;
196  ss << "Could not find TPDO entry identifier string " << identifier << ". Aborting action now. ";
197  throw PDOException(ss.str());
198  }
199  const PDOMapEntry& entry = m_tpdo_mapping[identifier];
200 
201  const PDO::Mapping& mapping = m_tpdos[entry.pdo_nr]->m_mapping_list[entry.pdo_mapping_index];
202  // check if it is castable to the requested value
203 
204  return convertFromCharVector<T>(mapping.data);
205  }
206 
214  template <typename T>
215  bool setRPDOValue (const std::string& identifier, const T value)
216  {
217  // find pdo with this identifier
218  if (m_rpdo_mapping.find(identifier) == m_rpdo_mapping.end())
219  {
220  std::stringstream ss;
221  ss << "Could not find RPDO entry identifier string " << identifier << ". Aborting action now. ";
222  throw PDOException(ss.str());
223  }
224  const PDOMapEntry& entry = m_rpdo_mapping[identifier];
225  PDO::Mapping& mapping = m_rpdos[entry.pdo_nr]->m_mapping_list[entry.pdo_mapping_index];
226 
227  if (sizeof(T) == mapping.data.size())
228  {
229  std::memcpy(&(mapping.data[0]), &value, sizeof(T));
230  }
231 
232  LOGGING_TRACE (CanOpen, "Setting " << identifier << " for node " << m_node_id << " to " << value << endl);
233 
234  return true;
235  }
236 
245  template <typename T>
246  bool setTPDOValue (const std::string& identifier, const T value)
247  {
248  // find pdo with this identifier
249  if (m_tpdo_mapping.find(identifier) == m_tpdo_mapping.end())
250  {
251  std::stringstream ss;
252  ss << "Could not find TPDO entry identifier string " << identifier << ". Aborting action now. ";
253  throw PDOException(ss.str());
254  }
255  const PDOMapEntry& entry = m_tpdo_mapping[identifier];
256  PDO::Mapping& mapping = m_tpdos[entry.pdo_nr]->m_mapping_list[entry.pdo_mapping_index];
257 
258  if (sizeof(T) == mapping.data.size())
259  {
260  std::memcpy(&(mapping.data[0]), &value, sizeof(T));
261  }
262 
263  LOGGING_TRACE (CanOpen, "Setting " << identifier << " for node " << m_node_id << " to " << value << endl);
264 
265  return true;
266  }
267 
271  void uploadPDOs ();
272 
276  void downloadPDOs ();
277 
281  void printPDOMapping();
282 
295  void registerPDONotifyCallback (const std::string& identifier, const boost::function<void ()>& f );
296 
300  virtual void stopNode();
301 
312 
313 protected:
316 
319 
321  boost::unordered_map<std::string, PDOMapEntry> m_rpdo_mapping;
322 
324  boost::unordered_map<std::string, PDOMapEntry> m_tpdo_mapping;
325 
327 
329 
332 
333 };
334 
335 }}// end of NS
336 
337 #endif // DS301NODE_H
boost::shared_ptr< const DS301Node > ConstPtr
Shared pointer to a const DS301Node.
Definition: DS301Node.h:97
RPDO::PtrList m_rpdos
RPDOS of this node (up to 4 in standard config)
Definition: DS301Node.h:307
CanDevPtr m_can_dev
Device handle for transmission of messages.
Definition: DS301Node.h:318
std::vector< MappingConfiguration > MappingConfigurationList
The MappingConfigurationList holds multiple Mapping configurations. The Mapping of a single PDO is de...
Definition: PDO.h:70
boost::shared_ptr< DS301Node > Ptr
Shared pointer to a DS301Node.
Definition: DS301Node.h:95
f
Unique index to find a mapped Object dictionary item in a PDO.
Definition: DS301Node.h:78
SDO m_sdo
SDO object for specific calls.
Definition: DS301Node.h:305
The NMT class provides access to NMT functions of the canOpen protocol and keeps the NMT state of can...
Definition: NMT.h:42
boost::shared_ptr< icl_comm::websocket::WsBroadcaster > m_ws_broadcaster
Interface to send out diagnostics data. Only available if compiled with IC_BUILDER_ICL_COMM_WEBSOCKET...
Definition: DS301Node.h:331
config
std::vector< uint8_t > data
Actual data of the PDO is stored in this data vector.
Definition: PDO.h:97
boost::unordered_map< std::string, PDOMapEntry > m_rpdo_mapping
This map holds a mapping between an identifier string and a mapped position in a RPDO.
Definition: DS301Node.h:321
T getRPDOValue(const std::string &identifier)
Definition: DS301Node.h:165
PDO related exceptions go here.
Definition: exceptions.h:114
std::vector< boost::shared_ptr< TPDO > > PtrList
Convenience typedef to use PDO lists with shared pointers.
Definition: TPDO.h:39
uint8_t m_node_id
CANOPEN ID of the node.
Definition: DS301Node.h:315
eTransmissionType
Transmission types of a PDO, needed when mapping PDOs.
Definition: PDO.h:122
unsigned char uint8_t
boost::unordered_map< std::string, PDOMapEntry > m_tpdo_mapping
This map holds a mapping between an identifier string and a mapped position in a TPDO.
Definition: DS301Node.h:324
ThreadStream & endl(ThreadStream &stream)
bool setRPDOValue(const std::string &identifier, const T value)
Set the value of a PDO which is mapped to a given identifier.
Definition: DS301Node.h:215
std::vector< boost::shared_ptr< RPDO > > PtrList
Convenience typedef to use PDO lists with shared pointers.
Definition: RPDO.h:39
std::vector< unsigned int > mapping(const T &t1, const T &t2)
bool setTPDOValue(const std::string &identifier, const T value)
Set the value of a PDO which is mapped to a given identifier.
Definition: DS301Node.h:246
The SDO class represents Service Data Objects (SDO) that are used for slow access of the canOpen obje...
Definition: SDO.h:40
Holds the mapping parameter plus the actual data.
Definition: PDO.h:84
EMCY::Ptr m_emcy
EMCY object to handle spontaneous callbacks with emergency messages.
Definition: DS301Node.h:311
TPDO::PtrList m_tpdos
TPDOS of this node (up to 4 in standard config)
Definition: DS301Node.h:309
ePDO_TYPE
Type of a PDO. RECEIVE_PDOs carry data from the host to the device, TRANSMIT_PDOs from the device to ...
Definition: DS301Node.h:88
unsigned short uint16_t
HeartBeatMonitor::Ptr m_heartbeat_monitor
Definition: DS301Node.h:326
#define LOGGING_TRACE(streamname, arg)
The DS301Node class Is the base class representation of canOpen devices. It is the access point to th...
Definition: DS301Node.h:67
T getTPDOValue(const std::string &identifier)
Get the value of a PDO which is mapped to a given identifier.
Definition: DS301Node.h:190
NMT m_nmt
Object to handle NMT calls and status.
Definition: DS301Node.h:303


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