RPDO.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 "RPDO.h"
23 
24 #include "ds301.h"
25 #include "Logging.h"
26 #include "exceptions.h"
27 
28 
29 namespace icl_hardware {
30 namespace canopen_schunk {
31 
32 
33 RPDO::RPDO(const uint8_t node_id, const uint8_t pdo_nr, const CanDevPtr& can_device)
34  : PDO(node_id, pdo_nr, can_device)
35 {
36 
37 }
38 
40 {
41  if (m_mapping_list.size() == 0)
42  {
43  // Nothing to do here...
44  return true;
45  }
46  CanMsg msg;
47  msg.id = ds301::ID_RPDO1_MIN + m_node_id - 1 + (m_pdo_nr << 8);
48  msg.dlc = 8;
49  msg.rtr = 0;
50 
51  uint8_t byte_offset = 0;
52  for (MappingList::iterator it = m_mapping_list.begin();
53  it != m_mapping_list.end();
54  ++it)
55  {
56  if (byte_offset + it->data.size() > 8)
57  {
58  throw PDOException ("Too much data for one PDO transmission. The PDO mapping contains too much data! Aborting download.");
59  }
60 
61  // Copy subset of vector
62  std::copy(it->data.begin(),
63  it->data.begin() + it->data.size(),
64  msg.data + byte_offset);
65  byte_offset += it->data.size();
66  }
67 
68  LOGGING_TRACE (CanOpen, "Now sending RPDO download can message with id " << msg.id <<
69  ",length " << byte_offset << ", data " << hexArrayToString(msg.data, byte_offset) <<
70  " to node " << m_node_id << endl);
71  msg.dlc = byte_offset;
72  m_can_device->Send(msg);
73 
74  return true;
75 }
76 
78  const MappingConfigurationList& mappings,
79  const eTransmissionType& transmission_type,
80  const bool dummy_mapping,
81  const uint8_t cyclic_timeout_cycles
82  )
83 {
84  uint16_t pdo_cob_id = ds301::ID_RPDO1_MIN + (m_pdo_nr << 8) + m_node_id - 1;
85  uint16_t pdo_communication_parameter = OD_RPDO_COMMUNICATION_MIN + m_pdo_nr;
86  uint16_t pdo_mapping_parameter = OD_RPDO_MAPPING_PARAMETER_MIN + m_pdo_nr;
87 
88  return PDO::remap(sdo,
89  mappings,
90  transmission_type,
91  pdo_cob_id,
92  pdo_communication_parameter,
93  pdo_mapping_parameter,
94  dummy_mapping,
95  cyclic_timeout_cycles);
96 }
97 
98 
100  const MappingConfigurationList& mappings,
101  const eTransmissionType& transmission_type,
102  const bool dummy_mapping,
103  const uint8_t cyclic_timeout_cycles
104  )
105 {
106  uint16_t pdo_cob_id = ds301::ID_RPDO1_MIN + (m_pdo_nr << 8) + m_node_id - 1;
107  uint16_t pdo_communication_parameter = OD_RPDO_COMMUNICATION_MIN + m_pdo_nr;
108  uint16_t pdo_mapping_parameter = OD_RPDO_MAPPING_PARAMETER_MIN + m_pdo_nr;
109 
110  return PDO::appendMapping(sdo,
111  mappings,
112  transmission_type,
113  pdo_cob_id,
114  pdo_communication_parameter,
115  pdo_mapping_parameter,
116  dummy_mapping,
117  cyclic_timeout_cycles);
118 }
119 
120 
121 }} // end of NS
bool download()
Downloads RPDO data from the master to the slave (From PC to node)
Definition: RPDO.cpp:39
static const uint16_t ID_RPDO1_MIN
Definition: ds301.h:54
MappingList m_mapping_list
List of all mappings inside this PDO.
Definition: PDO.h:216
std::vector< MappingConfiguration > MappingConfigurationList
The MappingConfigurationList holds multiple Mapping configurations. The Mapping of a single PDO is de...
Definition: PDO.h:70
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...
Definition: helper.cpp:42
CanDevPtr m_can_device
Can Device handle.
Definition: PDO.h:226
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
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
static const uint16_t OD_RPDO_COMMUNICATION_MIN
Definition: RPDO.h:41
unsigned char uint8_t
ThreadStream & endl(ThreadStream &stream)
static const uint16_t OD_RPDO_MAPPING_PARAMETER_MIN
Definition: RPDO.h:42
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: RPDO.cpp:77
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
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
RPDO(const uint8_t node_id, const uint8_t pdo_nr, const CanDevPtr &can_device)
Construct a new RPDO.
Definition: RPDO.cpp:33
unsigned short uint16_t
#define LOGGING_TRACE(streamname, arg)
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: RPDO.cpp:99


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