forked from ros-industrial/ros_canopen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented ROS param parsing for error ignoring in CAN, CAN_ERR_LOST…
…ARB is ignored by default, see also ros-industrial#362
- Loading branch information
1 parent
860ebf5
commit fbe7bbf
Showing
5 changed files
with
153 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
socketcan_interface/include/socketcan_interface/serializable_map.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef SOCKETCAN_INTERFACE_SERIALIZABLE_MAP_H | ||
#define SOCKETCAN_INTERFACE_SERIALIZABLE_MAP_H | ||
|
||
#include <map> | ||
#include <sstream> | ||
|
||
template<class Key, class Value> | ||
class serializable_map : public std::map<Key, Value> { | ||
private: | ||
size_t offset; | ||
|
||
template<class T> | ||
void write(std::stringstream &ss, T &t) const { | ||
ss.write((char*)(&t), sizeof(t)); | ||
} | ||
|
||
void write(std::stringstream &ss, std::string &str) const { | ||
size_t size = str.size(); | ||
ss.write((char*)(&size), sizeof(size)); | ||
ss.write((char*)(str.data()), str.length()); | ||
} | ||
|
||
template<class T> | ||
void read(const std::string &s, T &t) { | ||
t = (T)(*(s.data() + offset)); | ||
offset += sizeof(T); | ||
} | ||
|
||
void read(const std::string &s, std::string &str) { | ||
size_t size = (int)(*(s.data() + offset)); | ||
offset += sizeof(size_t); | ||
std::string str2(s.data() + offset, s.data() + offset + size); | ||
str = str2; | ||
offset += size; | ||
} | ||
public: | ||
std::string serialize() const { | ||
std::stringstream ss; | ||
for (auto &i : (*this)) { | ||
Key str = i.first; | ||
Value value = i.second; | ||
write(ss, str); | ||
write(ss, value); | ||
} | ||
return ss.str(); | ||
} | ||
void deserialize(const std::string &s) { | ||
offset = 0; | ||
while (offset < s.size()) { | ||
Key key; | ||
Value value; | ||
read(s, key); | ||
read(s, value); | ||
(*this)[key] = value; | ||
} | ||
} | ||
}; | ||
|
||
#endif /* SOCKETCAN_INTERFACE_SERIALIZABLE_MAP_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters