Is there documentation or example on how to use the C++11 generated libraries?
aarondewindt opened this issue · 7 comments
I have an incoming and outgoing stream of bytes which I need to serialize and deserialize to/from mavlink::Message
objects. How do I do this? I can't find the documentation for the C++11 libraries or some example. So does anyone know of some example code doing this?
So to be more specific. I want to deserialize the stream into messages of their own type, but return a std::shared_pointer<mavlink::Message>
.
@aarondewindt The only examples and docs we have are for C and Python. @julianoes Can you advise?
What about MAVROS? Does that help?
e.g. https://github.com/mavlink/mavros/blob/ros2/mavros/src/plugins/manual_control.cpp
@julianoes i think plugins code didn't help here, because mavlink transcoding is hidden by the api.
@aarondewindt C++11 uses C library to finalize serialization and message parsing.
You should implement mavlink::mavlink_get_msg_entry()
, as i gives extra crc byte.
To serialize mavlink::Message you need to:
- Copy your message to mavlink_message_t trough mavlink::MsgMap by calling Message::serialize();
- Set headers and crc by mavlink_finalize_message_buffer();
- Copy mavlink_message_t to bytes buffer (which then you could send)
To parse you should call mavlink::mavlink_frame_char_buffer() and then use MsgMap with resulting mavlink_message_t to be able to Message::deserialize().
@vooon Thaaanks, that help quite a bit. I figured I had to use the C library and mavlink::MsgMap
but implemented it using mavlink_parse_char
instead, I haven't had a chance to test it though. I'll post an short update once I get it to work. Maybe with a gist as a simple example for future reference.
A simple example or advice we can add to the docs would be great.