Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00020
00021
00022 #include "RPDO.h"
00023
00024 #include "ds301.h"
00025 #include "Logging.h"
00026 #include "exceptions.h"
00027
00028
00029 namespace icl_hardware {
00030 namespace canopen_schunk {
00031
00032
00033 RPDO::RPDO(const uint8_t node_id, const uint8_t pdo_nr, const CanDevPtr& can_device)
00034 : PDO(node_id, pdo_nr, can_device)
00035 {
00036
00037 }
00038
00039 bool RPDO::download()
00040 {
00041 if (m_mapping_list.size() == 0)
00042 {
00043
00044 return true;
00045 }
00046 CanMsg msg;
00047 msg.id = ds301::ID_RPDO1_MIN + m_node_id - 1 + (m_pdo_nr << 8);
00048 msg.dlc = 8;
00049 msg.rtr = 0;
00050
00051 uint8_t byte_offset = 0;
00052 for (MappingList::iterator it = m_mapping_list.begin();
00053 it != m_mapping_list.end();
00054 ++it)
00055 {
00056 if (byte_offset + it->data.size() > 8)
00057 {
00058 throw PDOException ("Too much data for one PDO transmission. The PDO mapping contains too much data! Aborting download.");
00059 }
00060
00061
00062 std::copy(it->data.begin(),
00063 it->data.begin() + it->data.size(),
00064 msg.data + byte_offset);
00065 byte_offset += it->data.size();
00066 }
00067
00068 LOGGING_TRACE (CanOpen, "Now sending RPDO download can message with id " << msg.id <<
00069 ",length " << byte_offset << ", data " << hexArrayToString(msg.data, byte_offset) <<
00070 " to node " << m_node_id << endl);
00071 msg.dlc = byte_offset;
00072 m_can_device->Send(msg);
00073
00074 return true;
00075 }
00076
00077 PDO::PDOStringMatchVec RPDO::remap (SDO& sdo,
00078 const MappingConfigurationList& mappings,
00079 const eTransmissionType& transmission_type,
00080 const bool dummy_mapping,
00081 const uint8_t cyclic_timeout_cycles
00082 )
00083 {
00084 uint16_t pdo_cob_id = ds301::ID_RPDO1_MIN + (m_pdo_nr << 8) + m_node_id - 1;
00085 uint16_t pdo_communication_parameter = OD_RPDO_COMMUNICATION_MIN + m_pdo_nr;
00086 uint16_t pdo_mapping_parameter = OD_RPDO_MAPPING_PARAMETER_MIN + m_pdo_nr;
00087
00088 return PDO::remap(sdo,
00089 mappings,
00090 transmission_type,
00091 pdo_cob_id,
00092 pdo_communication_parameter,
00093 pdo_mapping_parameter,
00094 dummy_mapping,
00095 cyclic_timeout_cycles);
00096 }
00097
00098
00099 PDO::PDOStringMatchVec RPDO::appendMapping (SDO& sdo,
00100 const MappingConfigurationList& mappings,
00101 const eTransmissionType& transmission_type,
00102 const bool dummy_mapping,
00103 const uint8_t cyclic_timeout_cycles
00104 )
00105 {
00106 uint16_t pdo_cob_id = ds301::ID_RPDO1_MIN + (m_pdo_nr << 8) + m_node_id - 1;
00107 uint16_t pdo_communication_parameter = OD_RPDO_COMMUNICATION_MIN + m_pdo_nr;
00108 uint16_t pdo_mapping_parameter = OD_RPDO_MAPPING_PARAMETER_MIN + m_pdo_nr;
00109
00110 return PDO::appendMapping(sdo,
00111 mappings,
00112 transmission_type,
00113 pdo_cob_id,
00114 pdo_communication_parameter,
00115 pdo_mapping_parameter,
00116 dummy_mapping,
00117 cyclic_timeout_cycles);
00118 }
00119
00120
00121 }}