34 namespace canopen_schunk {
41 m_can_device(can_device)
49 const uint16_t pdo_communication_parameter,
50 const uint16_t pdo_mapping_parameter,
51 const bool dummy_mapping,
52 const uint8_t cyclic_timeout_cycles
59 if (mappings.size() == 0)
67 if (mappings.size() > 64)
70 ss <<
"Illegal number of mappings given. A maximum of 64 mappings is allowed. " <<
71 "However, " << mappings.size() <<
" mappings were given.";
76 uint8_t transmission_type_int =
static_cast<uint8_t>(transmission_type);
79 transmission_type_int += cyclic_timeout_cycles;
83 uint16_t index = pdo_communication_parameter;
85 std::vector<uint8_t> data(4, 0);
88 data[0] = pdo_cob_id & 0xff;
89 data[1] = pdo_cob_id >> 8;
97 sdo.
download(
false, index, subindex, data);
99 catch (
const std::exception& e)
101 std::stringstream ss;
102 ss <<
"Downloading PDO communication object failed! ";
109 index = pdo_mapping_parameter;
117 sdo.
download(
false, index, subindex, clear_data);
119 catch (
const std::exception& e)
121 std::stringstream ss;
122 ss <<
"Clearing PDO mapping failed! ";
130 index = pdo_mapping_parameter;
133 for (
size_t i = 0; i < mappings.size(); ++i)
136 data[0] = mappings[i].length;
137 data[1] = mappings[i].subindex;
138 data[2] = mappings[i].index & 0xff;
139 data[3] = mappings[i].index >> 8;
140 cumul_length += mappings[i].length;
143 match.
name = mappings[i].name;
145 ret_vec.push_back(match);
147 if (cumul_length > 64)
149 throw PDOException (
"The configured length of the PDO mapping is too big. To send a PDO in one CAN frame its size cannot be larger than 64 bit");
157 sdo.
download(
false, index, subindex, data);
163 index = pdo_mapping_parameter;
165 uint8_t num_mappings = mappings.size();
171 sdo.
download(
false, index, subindex, num_mappings);
173 catch (
const std::exception& e)
175 std::stringstream ss;
176 ss <<
"Setting number of mappings failed! ";
183 index = pdo_communication_parameter;
189 sdo.
download(
false, index, subindex, transmission_type_int);
191 catch (
const std::exception& e)
193 std::stringstream ss;
194 ss <<
"Downloading PDO communication object failed! ";
201 index = pdo_communication_parameter;
203 data[0] = pdo_cob_id & 0xff;
204 data[1] = pdo_cob_id >> 8;
212 sdo.
download(
false, index, subindex, data);
214 catch (
const std::exception& e)
216 std::stringstream ss;
217 ss <<
"Enabling PDO object failed! ";
233 const uint16_t pdo_communication_parameter,
234 const uint16_t pdo_mapping_parameter,
235 const bool dummy_mapping,
236 const uint8_t cyclic_timeout_cycles)
243 new_configuration.push_back(it->getConfiguration());
244 cum_length += it->getConfiguration().length;
249 for (MappingConfigurationList::const_iterator it = mappings.begin(); it != mappings.end(); ++it)
251 new_cum_length += it->length;
252 new_configuration.push_back(*it);
256 if (cum_length + new_cum_length > 64)
258 std::stringstream ss;
259 ss <<
"The requested length of the PDO mapping is too big. "<<
260 "To send a PDO in one CAN frame its size cannot be larger than 64 bit." <<
261 "Please append this configuration to another PDO.";
270 pdo_communication_parameter,
271 pdo_mapping_parameter,
272 cyclic_timeout_cycles);
#define LOGGING_INFO_C(streamname, classname, arg)
MappingList m_mapping_list
List of all mappings inside this PDO.
std::vector< MappingConfiguration > MappingConfigurationList
The MappingConfigurationList holds multiple Mapping configurations. The Mapping of a single PDO is de...
#define LOGGING_DEBUG(streamname, arg)
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).
PDO related exceptions go here.
uint8_t m_node_id
CANOPEN ID of the node this PDO belongs to.
uint8_t pdo_mapping_index
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...
PDO(const uint8_t node_id, const uint8_t pdo_nr, const CanDevPtr &can_device)
Construct a new PDO.
eTransmissionType
Transmission types of a PDO, needed when mapping PDOs.
ThreadStream & endl(ThreadStream &stream)
Unique index to find a mapped Object dictionary item in a PDO.
std::vector< PDOStringMatch > PDOStringMatchVec
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...
The PDO class provides access to one (of the possible multiple) Process Data Object of a canOpen node...
The SDO class represents Service Data Objects (SDO) that are used for slow access of the canOpen obje...
Holds the mapping parameter plus the actual data.
std::string hexToString(const uint64_t num)
Converts a hexadecimal number into its string representation 0xXX.