11 static const unsigned int ID_MASK = (1u << 29)-1;
12 static const unsigned int EXTENDED_MASK = (1u << 29);
13 static const unsigned int NO_RTR_MASK = (1u << 30);
14 static const unsigned int INVALID_MASK = (1u << 31);
20 return can::Header(value_ & ID_MASK, value_ & EXTENDED_MASK, fill_rtr && !(value_ & NO_RTR_MASK),
false);
22 bool isInvalid()
const {
return value_ & INVALID_MASK; }
31 sub_index((val>>8) & 0xFF),
52 bool com_changed =
false;
55 for(uint8_t sub = 0; sub <=6 ; ++sub){
57 if(!dict(com_id,sub).init_val.is_empty()){
62 catch (std::out_of_range) {}
68 bool map_changed =
false;
72 for(uint8_t sub = 1; sub <=num ; ++sub){
74 if(!dict(map_index,sub).init_val.is_empty()){
79 catch (std::out_of_range) {}
82 map_changed = dict( map_index ,0 ).init_val.is_empty();
108 if((map_changed || com_changed) && cob_id.
desc().
writable){
111 if(map_num > 0 && map_num <= 0x40){
117 for(uint8_t sub = 1; sub <=map_num; ++sub){
119 storage->entry(mapentry, map_index, sub);
120 const HoldAny init = dict(map_index ,sub).init_val;
125 if(param.index < 0x1000){
132 size_t l = storage->map(param.index, param.sub_index, rd, wd);
133 assert(l == param.length/8);
136 frame.dlc += b->size;
137 assert( frame.dlc <= 8 );
139 buffers.push_back(b);
143 uint8_t subs = dict(com_index,
SUB_COM_NUM).value().
get<uint8_t>();
149 catch (
const std::out_of_range &){
155 num_entry.
set(map_num);
157 if((com_changed || map_changed) && cob_id.
desc().
writable){
166 :interface_(interface)
170 boost::mutex::scoped_lock lock(
mutex_);
199 catch(
const std::out_of_range &e){
200 status.
error(std::string(
"PDO error: ") + e.what());
207 boost::mutex::scoped_lock lock(mutex);
210 parse_and_set_mapping(storage, com_index, map_index,
true,
false);
214 if(buffers.empty() || pdoid.
isInvalid()){
218 frame = pdoid.
header(
true);
228 boost::mutex::scoped_lock lock(mutex);
235 parse_and_set_mapping(storage, com_index, map_index,
false,
true);
236 if(buffers.empty() || pdoid.
isInvalid()){
243 if(transmission_type != 1 && transmission_type <=240){
250 boost::mutex::scoped_lock lock(mutex);
252 bool updated =
false;
253 size_t len = frame.dlc;
255 for(std::vector< BufferSharedPtr >::iterator b_it = buffers.begin(); b_it != buffers.end(); ++b_it){
258 updated = b.
read(dest, len) || updated;
277 boost::mutex::scoped_lock lock(mutex);
278 if((transmission_type >= 1 && transmission_type <= 240) || transmission_type == 0xFC){
281 }
else if(timeout == 0) {
282 status.
warn(
"RPDO timeout");
285 if(transmission_type == 0xFC || transmission_type == 0xFD){
294 const uint8_t * src = msg.
data.data();
295 for(std::vector<BufferSharedPtr >::iterator it = buffers.begin(); it != buffers.end(); ++it){
298 if( offset + b.
size <= msg.
dlc ){
305 if( offset != msg.
dlc ){
309 boost::mutex::scoped_lock lock(mutex);
310 if(transmission_type >= 1 && transmission_type <= 240){
311 timeout = transmission_type + 2;
312 }
else if(transmission_type == 0xFC || transmission_type == 0xFD){
321 boost::mutex::scoped_lock lock(
mutex_);
322 for(boost::unordered_set<RPDO::RPDOSharedPtr >::iterator it =
rpdos_.begin(); it !=
rpdos_.end(); ++it){
327 boost::mutex::scoped_lock lock(
mutex_);
328 for(boost::unordered_set<TPDO::TPDOSharedPtr >::iterator it =
tpdos_.begin(); it !=
tpdos_.end(); ++it){
335 boost::mutex::scoped_lock lock(mutex);
337 BOOST_THROW_EXCEPTION( std::bad_cast() );
339 if(empty)
return false;
341 memcpy(b,&buffer[0], size);
342 bool was_dirty = dirty;
347 boost::mutex::scoped_lock lock(mutex);
349 BOOST_THROW_EXCEPTION( std::bad_cast() );
353 memcpy(&buffer[0], b, size);
356 boost::mutex::scoped_lock lock(mutex);
358 if(size != data.size()){
365 data.assign(buffer.begin(), buffer.end());
370 boost::mutex::scoped_lock lock(mutex);
371 if(size != data.size()){
376 buffer.assign(data.begin(),data.end());
static RPDOSharedPtr create(const can::CommInterfaceSharedPtr interface, const ObjectStorageSharedPtr &storage, const uint16_t &com_index, const uint16_t &map_index)
bool init(const ObjectStorageSharedPtr storage, LayerStatus &status)
bool check_map_changed(const uint8_t &num, const ObjectDict &dict, const uint16_t &map_index)
bool read(uint8_t *b, const size_t len)
bool check_com_changed(const ObjectDict &dict, const uint16_t com_id)
boost::shared_ptr< Buffer > BufferSharedPtr
const uint16_t RPDO_COM_BASE
boost::unordered_map< Key, EntryConstSharedPtr > dict_
const uint8_t SUB_COM_NUM
const ObjectDict::Entry & desc() const
PDOid(const uint32_t &val)
const void warn(const std::string &r)
const uint8_t SUB_MAP_NUM
const uint16_t TPDO_MAP_BASE
boost::array< value_type, 8 > data
boost::shared_ptr< CommInterface > CommInterfaceSharedPtr
boost::shared_ptr< TPDO > TPDOSharedPtr
const uint16_t RPDO_MAP_BASE
fastdelegate::FastDelegate2< const ObjectDict::Entry &, const String & > WriteDelegate
PDOMapper(const can::CommInterfaceSharedPtr interface)
boost::chrono::high_resolution_clock::time_point time_point
bool has(uint16_t i, uint8_t s) const
void read(LayerStatus &status)
void sync(LayerStatus &status)
fastdelegate::FastDelegate1< const Frame & > FrameDelegate
void write(const uint8_t *b, const size_t len)
bool init(const ObjectStorageSharedPtr &storage, const uint16_t &com_index, const uint16_t &map_index)
static const unsigned int INVALID_MASK
const uint8_t SUB_COM_TRANSMISSION_TYPE
const can::CommInterfaceSharedPtr interface_
static TPDOSharedPtr create(const can::CommInterfaceSharedPtr interface, const ObjectStorageSharedPtr &storage, const uint16_t &com_index, const uint16_t &map_index)
const uint16_t TPDO_COM_BASE
const DeviceInfo device_info
fastdelegate::FastDelegate2< const ObjectDict::Entry &, String & > ReadDelegate
boost::unordered_set< TPDO::TPDOSharedPtr > tpdos_
const void error(const std::string &r)
const EntryConstSharedPtr & get(const Key &k) const
bool init(const ObjectStorageSharedPtr &storage, const uint16_t &com_index, const uint16_t &map_index)
#define THROW_WITH_KEY(e, k)
time_point get_abs_time(const time_duration &timeout)
can::Header header(bool fill_rtr=false) const
void parse_and_set_mapping(const ObjectStorageSharedPtr &storage, const uint16_t &com_index, const uint16_t &map_index, const bool &read, const bool &write)
boost::shared_ptr< RPDO > RPDOSharedPtr
ObjectStorage::ObjectStorageSharedPtr ObjectStorageSharedPtr
const HoldAny & value() const
const uint8_t SUB_COM_RESERVED
void handleFrame(const can::Frame &msg)
boost::unordered_set< RPDO::RPDOSharedPtr > rpdos_
const uint8_t SUB_COM_COB_ID