Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort TPDOs based on frame id #451

Open
wants to merge 1 commit into
base: melodic-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion canopen_master/include/canopen_master/canopen.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,25 @@ class PDOMapper{
tpdo.reset();
return tpdo;
}
bool operator <(const TPDO& other) const{
return frame.id < other.frame.id;
}
private:
TPDO(const can::CommInterfaceSharedPtr interface) : interface_(interface){}
bool init(const ObjectStorageSharedPtr &storage, const uint16_t &com_index, const uint16_t &map_index);
const can::CommInterfaceSharedPtr interface_;
boost::mutex mutex;
};

template <typename T, typename Compare>
struct cmp_ptr
{
bool operator()(const T lhs, const T rhs) const {
Compare c;
return c(*lhs, *rhs);
}
};

struct RPDO : public PDO{
void sync(LayerStatus &status);
typedef std::shared_ptr<RPDO> RPDOSharedPtr;
Expand All @@ -134,7 +146,7 @@ class PDOMapper{
};

std::unordered_set<RPDO::RPDOSharedPtr> rpdos_;
std::unordered_set<TPDO::TPDOSharedPtr> tpdos_;
std::set<TPDO::TPDOSharedPtr,cmp_ptr<TPDO::TPDOSharedPtr, std::less<TPDO>>> tpdos_;

const can::CommInterfaceSharedPtr interface_;

Expand Down
2 changes: 1 addition & 1 deletion canopen_master/src/pdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void PDOMapper::read(LayerStatus &status){
}
bool PDOMapper::write(){
boost::mutex::scoped_lock lock(mutex_);
for(std::unordered_set<TPDO::TPDOSharedPtr >::iterator it = tpdos_.begin(); it != tpdos_.end(); ++it){
for(auto it = tpdos_.begin(); it != tpdos_.end(); ++it){
(*it)->sync();
}
return true; // TODO: check for errors
Expand Down