mavlink_diag.cpp
Go to the documentation of this file.
00001 
00006 /*
00007  * Copyright 2014 Vladimir Ermakov.
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 3 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00016  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00017  * for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License along
00020  * with this program; if not, write to the Free Software Foundation, Inc.,
00021  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00022  */
00023 
00024 #include <mavros/mavlink_diag.h>
00025 
00026 using namespace mavros;
00027 
00028 MavlinkDiag::MavlinkDiag(std::string name) :
00029         diagnostic_updater::DiagnosticTask(name),
00030         last_drop_count(0),
00031         is_connected(false)
00032 { };
00033 
00034 void MavlinkDiag::run(diagnostic_updater::DiagnosticStatusWrapper &stat)
00035 {
00036         if (auto link = weak_link.lock()) {
00037                 mavlink_status_t mav_status = link->get_status();
00038 
00039                 stat.addf("Received packets:", "%u", mav_status.packet_rx_success_count);
00040                 stat.addf("Dropped packets:", "%u", mav_status.packet_rx_drop_count);
00041                 stat.addf("Buffer overruns:", "%u", mav_status.buffer_overrun);
00042                 stat.addf("Parse errors:", "%u", mav_status.parse_error);
00043                 stat.addf("Rx sequence number:", "%u", mav_status.current_rx_seq);
00044                 stat.addf("Tx sequence number:", "%u", mav_status.current_tx_seq);
00045 
00046                 if (mav_status.packet_rx_drop_count > last_drop_count)
00047                         stat.summaryf(1, "%d packeges dropped since last report",
00048                                         mav_status.packet_rx_drop_count - last_drop_count);
00049                 else if (is_connected)
00050                         stat.summary(0, "connected");
00051                 else
00052                         // link operational, but not connected
00053                         stat.summary(1, "not connected");
00054 
00055                 last_drop_count = mav_status.packet_rx_drop_count;
00056         } else {
00057                 stat.summary(2, "not connected");
00058         }
00059 }
00060 


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