TPDO.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 // -- BEGIN LICENSE BLOCK ----------------------------------------------
3 // This file is part of the SCHUNK Canopen Driver suite.
4 //
5 // This program is free software licensed under the LGPL
6 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
7 // You can find a copy of this license in LICENSE folder in the top
8 // directory of the source code.
9 //
10 // © Copyright 2016 SCHUNK GmbH, Lauffen/Neckar Germany
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 // -- END LICENSE BLOCK ------------------------------------------------
13 //----------------------------------------------------------------------
20 //----------------------------------------------------------------------
21 
22 #include "TPDO.h"
23 
24 #include "ds301.h"
25 #include "Logging.h"
26 #include "exceptions.h"
27 
28 namespace icl_hardware {
29 namespace canopen_schunk {
30 
31 TPDO::TPDO(const uint8_t node_id, const uint8_t pdo_nr, const CanDevPtr& can_device)
32  : PDO (node_id, pdo_nr, can_device),
33  m_data_update_received(false)
34 {
35 }
36 
37 void TPDO::update (const CanMsg& msg)
38 {
39  uint8_t node_id = msg.id - ds301::ID_TPDO1_MIN + 1 + (m_pdo_nr << 8);
40 
41  if (node_id != m_node_id)
42  {
43  std::stringstream ss;
44  ss << "PDO Update called with wrong canopen ID. Received ID: " << node_id << " Node ID: " << m_node_id << ". Update ignored.";
45  throw PDOException (ss.str());
46  }
47 
48  boost::mutex::scoped_lock(m_data_buffer_mutex);
49 
50 
51 // if (m_data_update_received)
52 // {
53 // LOGGING_WARNING_C (CanOpen, TPDO, "Data buffer contains unprocessed data which will be overwritten." << endl);
54 // }
55 
56  m_data_buffer.resize(msg.dlc);
57  // To increase processing times of PDOs we use a memcopy instead of a loop
58  std::memcpy (&m_data_buffer[0], msg.data, msg.dlc);
59 
60  uint8_t byte_offset = 0;
61  for (MappingList::iterator it = m_mapping_list.begin();
62  it != m_mapping_list.end();
63  ++it)
64  {
65  // Copy subset of vector
66  std::copy(m_data_buffer.begin() + byte_offset,
67  m_data_buffer.begin() + byte_offset + it->data.size(),
68  it->data.begin());
69  byte_offset += it->data.size();
70  }
71 
72 // m_data_update_received = true;
74 }
75 
77 {
78  for (size_t i = 0; i < m_notify_callbacks.size(); ++i)
79  {
80  m_notify_callbacks[i]();
81  }
82 }
83 
85  const PDO::MappingConfigurationList& mappings,
86  const PDO::eTransmissionType& transmission_type,
87  const bool dummy_mapping,
88  const uint8_t cyclic_timeout_cycles)
89 {
90  uint16_t pdo_cob_id = ds301::ID_TPDO1_MIN + (m_pdo_nr << 8) + m_node_id -1;
91  uint16_t pdo_communication_parameter = OD_TPDO_COMMUNICATION_MIN + m_pdo_nr;
92  uint16_t pdo_mapping_parameter = OD_TPDO_MAPPING_PARAMETER_MIN + m_pdo_nr;
93 
94  return PDO::remap(sdo,
95  mappings,
96  transmission_type,
97  pdo_cob_id,
98  pdo_communication_parameter,
99  pdo_mapping_parameter,
100  dummy_mapping,
101  cyclic_timeout_cycles);
102 }
103 
105  const PDO::MappingConfigurationList& mappings,
106  const PDO::eTransmissionType& transmission_type,
107  const bool dummy_mapping,
108  const uint8_t cyclic_timeout_cycles)
109 {
110  uint16_t pdo_cob_id = ds301::ID_TPDO1_MIN + (m_pdo_nr << 8) + m_node_id -1;
111  uint16_t pdo_communication_parameter = OD_TPDO_COMMUNICATION_MIN + m_pdo_nr;
112  uint16_t pdo_mapping_parameter = OD_TPDO_MAPPING_PARAMETER_MIN + m_pdo_nr;
113 
114  return PDO::appendMapping(sdo,
115  mappings,
116  transmission_type,
117  pdo_cob_id,
118  pdo_communication_parameter,
119  pdo_mapping_parameter,
120  dummy_mapping,
121  cyclic_timeout_cycles);
122 }
123 
124 
125 void TPDO::registerNotifyCallback (const boost::function< void() >& f)
126 {
127  m_notify_callbacks.push_back(f);
128 }
129 
130 
131 
132 }} // end of NS
void update(const CanMsg &msg)
update updates the TPDO data with newly received messages
Definition: TPDO.cpp:37
MappingList m_mapping_list
List of all mappings inside this PDO.
Definition: PDO.h:216
static const uint16_t OD_TPDO_COMMUNICATION_MIN
Definition: TPDO.h:41
std::vector< MappingConfiguration > MappingConfigurationList
The MappingConfigurationList holds multiple Mapping configurations. The Mapping of a single PDO is de...
Definition: PDO.h:70
f
PDOStringMatchVec remap(SDO &sdo, const MappingConfigurationList &mappings, const eTransmissionType &transmission_type, const bool dummy_mapping=false, const uint8_t cyclic_timeout_cycles=0)
Configure a PDO by sending some SDO packages. This can be either done during NMT state pre-operationa...
Definition: TPDO.cpp:84
void upload()
Upload data from the slave to the master (Node to PC)
Definition: TPDO.cpp:76
std::vector< boost::function< void()> > m_notify_callbacks
Definition: TPDO.h:127
static const uint16_t OD_TPDO_MAPPING_PARAMETER_MIN
Definition: TPDO.h:42
PDO related exceptions go here.
Definition: exceptions.h:114
uint8_t m_node_id
CANOPEN ID of the node this PDO belongs to.
Definition: PDO.h:220
PDOStringMatchVec remap(SDO &sdo, const MappingConfigurationList &mappings, const eTransmissionType &transmission_type, const uint16_t pdo_cob_id, const uint16_t pdo_communication_parameter, const uint16_t pdo_mapping_parameter, const bool dummy_mapping=false, const uint8_t cyclic_timeout_cycles=0)
Configure a PDO by sending some SDO packages. This can be either done during NMT state pre-operationa...
Definition: PDO.cpp:45
void registerNotifyCallback(const boost::function< void()> &f)
Register a notification callback function for incoming PDO messages.
Definition: TPDO.cpp:125
eTransmissionType
Transmission types of a PDO, needed when mapping PDOs.
Definition: PDO.h:122
uint8_t m_pdo_nr
The PDO number inside the logical device. Theoretically this can be in 0 to 511.
Definition: PDO.h:223
unsigned char uint8_t
TPDO(const uint8_t node_id, const uint8_t pdo_nr, const CanDevPtr &can_device)
Construct a new TPDO.
Definition: TPDO.cpp:31
boost::mutex m_data_buffer_mutex
Definition: TPDO.h:129
std::vector< PDOStringMatch > PDOStringMatchVec
Definition: PDO.h:119
PDOStringMatchVec appendMapping(SDO &sdo, const MappingConfigurationList &mappings, const eTransmissionType &transmission_type, const uint16_t pdo_cob_id, const uint16_t pdo_communication_parameter, const uint16_t pdo_mapping_parameter, const bool dummy_mapping=false, const uint8_t cyclic_timeout_cycles=0)
Appends one or more mapping parameters to the existing mapping. Note that the PDO will be disabled wh...
Definition: PDO.cpp:229
std::vector< uint8_t > m_data_buffer
Definition: TPDO.h:132
PDOStringMatchVec appendMapping(SDO &sdo, const MappingConfigurationList &mappings, const eTransmissionType &transmission_type, const bool dummy_mapping=false, const uint8_t cyclic_timeout_cycles=0)
Appends one or more mapping parameters to the existing mapping. Note that the PDO will be disabled wh...
Definition: TPDO.cpp:104
The PDO class provides access to one (of the possible multiple) Process Data Object of a canOpen node...
Definition: PDO.h:44
The SDO class represents Service Data Objects (SDO) that are used for slow access of the canOpen obje...
Definition: SDO.h:40
boost::condition_variable m_data_buffer_updated_cond
Definition: TPDO.h:130
void notify_one() BOOST_NOEXCEPT
unsigned short uint16_t
static const uint16_t ID_TPDO1_MIN
Definition: ds301.h:52


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