msgbuffer.h
Go to the documentation of this file.
00001 
00009 /*
00010  * libmavconn
00011  * Copyright 2014,2015 Vladimir Ermakov, All rights reserved.
00012  *
00013  * This file is part of the mavros package and subject to the license terms
00014  * in the top-level LICENSE file of the mavros repository.
00015  * https://github.com/mavlink/mavros/tree/master/LICENSE.md
00016  */
00017 
00018 #pragma once
00019 
00020 #include <cassert>
00021 #include <mavconn/mavlink_dialect.h>
00022 
00023 namespace mavconn {
00024 
00028 struct MsgBuffer {
00030         static constexpr ssize_t MAX_SIZE = MAVLINK_MAX_PACKET_LEN + 2 + 7;
00031         uint8_t data[MAX_SIZE];
00032         ssize_t len;
00033         ssize_t pos;
00034 
00035         MsgBuffer() :
00036                 pos(0),
00037                 len(0)
00038         { }
00039 
00043         explicit MsgBuffer(const mavlink_message_t *msg) :
00044                 pos(0)
00045         {
00046                 len = mavlink_msg_to_send_buffer(data, msg);
00047                 // paranoic check, it must be less than MAVLINK_MAX_PACKET_LEN
00048                 assert(len < MAX_SIZE);
00049         }
00050 
00055         MsgBuffer(const uint8_t *bytes, ssize_t nbytes) :
00056                 pos(0),
00057                 len(nbytes)
00058         {
00059                 assert(0 < nbytes && nbytes < MAX_SIZE);
00060                 memcpy(data, bytes, nbytes);
00061         }
00062 
00063         virtual ~MsgBuffer() {
00064                 pos = 0;
00065                 len = 0;
00066         }
00067 
00068         uint8_t *dpos() {
00069                 return data + pos;
00070         }
00071 
00072         ssize_t nbytes() {
00073                 return len - pos;
00074         }
00075 };
00076 
00077 }; // namespace mavconn
00078 


libmavconn
Author(s): Vladimir Ermakov
autogenerated on Sat Jun 8 2019 19:55:13