TPDO.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00003 // This file is part of the SCHUNK Canopen Driver suite.
00004 //
00005 // This program is free software licensed under the LGPL
00006 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00007 // You can find a copy of this license in LICENSE folder in the top
00008 // directory of the source code.
00009 //
00010 // © Copyright 2016 SCHUNK GmbH, Lauffen/Neckar Germany
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 // -- END LICENSE BLOCK ------------------------------------------------
00013 //----------------------------------------------------------------------
00020 //----------------------------------------------------------------------
00021 
00022 #include "TPDO.h"
00023 
00024 #include "ds301.h"
00025 #include "Logging.h"
00026 #include "exceptions.h"
00027 
00028 namespace icl_hardware {
00029 namespace canopen_schunk {
00030 
00031 TPDO::TPDO(const uint8_t node_id, const uint8_t pdo_nr, const CanDevPtr& can_device)
00032   : PDO (node_id, pdo_nr, can_device),
00033     m_data_update_received(false)
00034 {
00035 }
00036 
00037 void TPDO::update (const CanMsg& msg)
00038 {
00039   uint8_t node_id = msg.id - ds301::ID_TPDO1_MIN + 1 + (m_pdo_nr << 8);
00040 
00041   if (node_id != m_node_id)
00042   {
00043     std::stringstream ss;
00044     ss << "PDO Update called with wrong canopen ID. Received ID: " << node_id << " Node ID: " << m_node_id << ". Update ignored.";
00045     throw PDOException (ss.str());
00046   }
00047 
00048   boost::mutex::scoped_lock(m_data_buffer_mutex);
00049 
00050 
00051 //   if (m_data_update_received)
00052 //   {
00053 //     LOGGING_WARNING_C (CanOpen, TPDO, "Data buffer contains unprocessed data which will be overwritten." << endl);
00054 //   }
00055 
00056   m_data_buffer.resize(msg.dlc);
00057   // To increase processing times of PDOs we use a memcopy instead of a loop
00058   std::memcpy (&m_data_buffer[0], msg.data, msg.dlc);
00059 
00060   uint8_t byte_offset = 0;
00061   for (MappingList::iterator it = m_mapping_list.begin();
00062        it != m_mapping_list.end();
00063        ++it)
00064   {
00065     // Copy subset of vector
00066     std::copy(m_data_buffer.begin() + byte_offset,
00067               m_data_buffer.begin() + byte_offset + it->data.size(),
00068               it->data.begin());
00069     byte_offset += it->data.size();
00070   }
00071 
00072 //   m_data_update_received = true;
00073   m_data_buffer_updated_cond.notify_one();
00074 }
00075 
00076 void TPDO::upload()
00077 {
00078   for (size_t i = 0; i < m_notify_callbacks.size(); ++i)
00079   {
00080     m_notify_callbacks[i]();
00081   }
00082 }
00083 
00084 PDO::PDOStringMatchVec TPDO::remap (SDO& sdo,
00085                                     const PDO::MappingConfigurationList& mappings,
00086                                     const PDO::eTransmissionType& transmission_type,
00087                                     const bool dummy_mapping,
00088                                     const uint8_t cyclic_timeout_cycles)
00089 {
00090   uint16_t pdo_cob_id = ds301::ID_TPDO1_MIN + (m_pdo_nr << 8) + m_node_id -1;
00091   uint16_t pdo_communication_parameter = OD_TPDO_COMMUNICATION_MIN + m_pdo_nr;
00092   uint16_t pdo_mapping_parameter = OD_TPDO_MAPPING_PARAMETER_MIN + m_pdo_nr;
00093 
00094   return PDO::remap(sdo,
00095                     mappings,
00096                     transmission_type,
00097                     pdo_cob_id,
00098                     pdo_communication_parameter,
00099                     pdo_mapping_parameter,
00100                     dummy_mapping,
00101                     cyclic_timeout_cycles);
00102 }
00103 
00104 PDO::PDOStringMatchVec TPDO::appendMapping (SDO& sdo,
00105                                             const PDO::MappingConfigurationList& mappings,
00106                                             const PDO::eTransmissionType& transmission_type,
00107                                             const bool dummy_mapping,
00108                                             const uint8_t cyclic_timeout_cycles)
00109 {
00110   uint16_t pdo_cob_id = ds301::ID_TPDO1_MIN + (m_pdo_nr << 8) + m_node_id -1;
00111   uint16_t pdo_communication_parameter = OD_TPDO_COMMUNICATION_MIN + m_pdo_nr;
00112   uint16_t pdo_mapping_parameter = OD_TPDO_MAPPING_PARAMETER_MIN + m_pdo_nr;
00113 
00114   return PDO::appendMapping(sdo,
00115                             mappings,
00116                             transmission_type,
00117                             pdo_cob_id,
00118                             pdo_communication_parameter,
00119                             pdo_mapping_parameter,
00120                             dummy_mapping,
00121                             cyclic_timeout_cycles);
00122 }
00123 
00124 
00125 void TPDO::registerNotifyCallback (const boost::function< void() >& f)
00126 {
00127   m_notify_callbacks.push_back(f);
00128 }
00129 
00130 
00131 
00132 }} // end of NS


schunk_canopen_driver
Author(s): Felix Mauch , Georg Heppner
autogenerated on Thu Jun 6 2019 20:17:24