Porting mros2 as an Mbed library.
Dependents: mbed-os-example-mros2 example-mbed-mros2-sub-pose example-mbed-mros2-pub-twist example-mbed-mros2-mturtle-teleop
mros2_msgs/std_msgs/msg/string.hpp@0:580aba13d1a1, 2021-12-30 (annotated)
- Committer:
- smoritaemb
- Date:
- Thu Dec 30 21:06:29 2021 +0900
- Revision:
- 0:580aba13d1a1
- Child:
- 2:159877d749c2
Updated to catch up to mros2 v2.3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
smoritaemb | 0:580aba13d1a1 | 1 | #include <string> |
smoritaemb | 0:580aba13d1a1 | 2 | |
smoritaemb | 0:580aba13d1a1 | 3 | namespace std_msgs |
smoritaemb | 0:580aba13d1a1 | 4 | { |
smoritaemb | 0:580aba13d1a1 | 5 | namespace msg |
smoritaemb | 0:580aba13d1a1 | 6 | { |
smoritaemb | 0:580aba13d1a1 | 7 | class String |
smoritaemb | 0:580aba13d1a1 | 8 | { |
smoritaemb | 0:580aba13d1a1 | 9 | public: |
smoritaemb | 0:580aba13d1a1 | 10 | std::string getTypeName(); |
smoritaemb | 0:580aba13d1a1 | 11 | std::string data; |
smoritaemb | 0:580aba13d1a1 | 12 | void copyToBuf(uint8_t *addrPtr) |
smoritaemb | 0:580aba13d1a1 | 13 | { |
smoritaemb | 0:580aba13d1a1 | 14 | uint32_t size = data.size(); |
smoritaemb | 0:580aba13d1a1 | 15 | memcpy(addrPtr, &size, 4); |
smoritaemb | 0:580aba13d1a1 | 16 | addrPtr += 4; |
smoritaemb | 0:580aba13d1a1 | 17 | memcpy(addrPtr, data.c_str(),size); |
smoritaemb | 0:580aba13d1a1 | 18 | addrPtr += size; |
smoritaemb | 0:580aba13d1a1 | 19 | *addrPtr = 0; |
smoritaemb | 0:580aba13d1a1 | 20 | } |
smoritaemb | 0:580aba13d1a1 | 21 | |
smoritaemb | 0:580aba13d1a1 | 22 | void copyFromBuf(const uint8_t *addrPtr) |
smoritaemb | 0:580aba13d1a1 | 23 | { |
smoritaemb | 0:580aba13d1a1 | 24 | uint32_t msg_size; |
smoritaemb | 0:580aba13d1a1 | 25 | memcpy(&msg_size, addrPtr, 4); |
smoritaemb | 0:580aba13d1a1 | 26 | addrPtr += 4; |
smoritaemb | 0:580aba13d1a1 | 27 | data.resize(msg_size); |
smoritaemb | 0:580aba13d1a1 | 28 | memcpy(&data[0], addrPtr, msg_size); |
smoritaemb | 0:580aba13d1a1 | 29 | |
smoritaemb | 0:580aba13d1a1 | 30 | } |
smoritaemb | 0:580aba13d1a1 | 31 | |
smoritaemb | 0:580aba13d1a1 | 32 | uint8_t getTotalSize() |
smoritaemb | 0:580aba13d1a1 | 33 | { |
smoritaemb | 0:580aba13d1a1 | 34 | return (5 + data.size()); |
smoritaemb | 0:580aba13d1a1 | 35 | } |
smoritaemb | 0:580aba13d1a1 | 36 | private: |
smoritaemb | 0:580aba13d1a1 | 37 | std::string type_name = "std_msgs::msg::dds_::String"; |
smoritaemb | 0:580aba13d1a1 | 38 | }; |
smoritaemb | 0:580aba13d1a1 | 39 | }//namspace msg |
smoritaemb | 0:580aba13d1a1 | 40 | }//namespace std_msgs |
smoritaemb | 0:580aba13d1a1 | 41 | |
smoritaemb | 0:580aba13d1a1 | 42 | namespace message_traits |
smoritaemb | 0:580aba13d1a1 | 43 | { |
smoritaemb | 0:580aba13d1a1 | 44 | |
smoritaemb | 0:580aba13d1a1 | 45 | template<> |
smoritaemb | 0:580aba13d1a1 | 46 | struct TypeName<std_msgs::msg::String*> { |
smoritaemb | 0:580aba13d1a1 | 47 | static const char* value() |
smoritaemb | 0:580aba13d1a1 | 48 | { |
smoritaemb | 0:580aba13d1a1 | 49 | return "std_msgs::msg::dds_::String_"; |
smoritaemb | 0:580aba13d1a1 | 50 | } |
smoritaemb | 0:580aba13d1a1 | 51 | }; |
smoritaemb | 0:580aba13d1a1 | 52 | |
smoritaemb | 0:580aba13d1a1 | 53 | } |