msgbuffer.h
Go to the documentation of this file.
00001 
00009 /*
00010  * Copyright 2014 Vladimir Ermakov.
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 3 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful, but
00018  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00019  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00020  * for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License along
00023  * with this program; if not, write to the Free Software Foundation, Inc.,
00024  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00025  */
00026 
00027 #pragma once
00028 
00029 #include <cassert>
00030 #include <mavconn/mavlink_dialect.h>
00031 
00032 namespace mavconn {
00033 
00037 struct MsgBuffer {
00039         static constexpr ssize_t MAX_SIZE = MAVLINK_MAX_PACKET_LEN + 2 + 7;
00040         uint8_t data[MAX_SIZE];
00041         ssize_t len;
00042         ssize_t pos;
00043 
00044         MsgBuffer() :
00045                 pos(0),
00046                 len(0)
00047         { }
00048 
00052         explicit MsgBuffer(const mavlink_message_t *msg) :
00053                 pos(0)
00054         {
00055                 len = mavlink_msg_to_send_buffer(data, msg);
00056                 // paranoic check, it must be less than MAVLINK_MAX_PACKET_LEN
00057                 assert(len < MAX_SIZE);
00058         }
00059 
00064         MsgBuffer(const uint8_t *bytes, ssize_t nbytes) :
00065                 pos(0),
00066                 len(nbytes)
00067         {
00068                 assert(0 < nbytes && nbytes < MAX_SIZE);
00069                 memcpy(data, bytes, nbytes);
00070         }
00071 
00072         virtual ~MsgBuffer() {
00073                 pos = 0;
00074                 len = 0;
00075         }
00076 
00077         uint8_t *dpos() {
00078                 return data + pos;
00079         }
00080 
00081         ssize_t nbytes() {
00082                 return len - pos;
00083         }
00084 };
00085 
00086 }; // namespace mavconn
00087 


libmavconn
Author(s): Vladimir Ermakov
autogenerated on Wed Aug 26 2015 12:29:08