utils.h
Go to the documentation of this file.
00001 
00010 /*
00011  * Copyright 2014 Vladimir Ermakov.
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 3 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful, but
00019  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00020  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00021  * for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License along
00024  * with this program; if not, write to the Free Software Foundation, Inc.,
00025  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00026  */
00027 
00028 #pragma once
00029 
00030 #include <algorithm>
00031 #include <mavconn/thread_utils.h>
00032 
00033 #include <mavros/Mavlink.h>
00034 #include <mavconn/mavlink_dialect.h>
00035 
00036 
00037 namespace mavutils {
00038 
00042 inline bool copy_ros_to_mavlink(const mavros::Mavlink::ConstPtr &rmsg, mavlink_message_t &mmsg)
00043 {
00044         if (rmsg->payload64.size() > sizeof(mmsg.payload64) / sizeof(mmsg.payload64[0])) {
00045                 return false;
00046         }
00047 
00048         mmsg.msgid = rmsg->msgid;
00049         mmsg.len = rmsg->len;
00050         std::copy(rmsg->payload64.begin(), rmsg->payload64.end(), mmsg.payload64);
00051         return true;
00052 };
00053 
00057 inline void copy_mavlink_to_ros(const mavlink_message_t *mmsg, mavros::MavlinkPtr &rmsg)
00058 {
00059         rmsg->len = mmsg->len;
00060         rmsg->seq = mmsg->seq;
00061         rmsg->sysid = mmsg->sysid;
00062         rmsg->compid = mmsg->compid;
00063         rmsg->msgid = mmsg->msgid;
00064 
00065         rmsg->payload64.reserve((mmsg->len + 7) / 8);
00066         for (size_t i = 0; i < (mmsg->len + 7) / 8; i++)
00067                 rmsg->payload64.push_back(mmsg->payload64[i]);
00068 };
00069 
00070 }; // namespace mavutils


mavros
Author(s): Vladimir Ermakov
autogenerated on Wed Aug 26 2015 12:29:13