mavlink_diag.cpp
Go to the documentation of this file.
00001 
00006 /*
00007  * Copyright 2014,2015 Vladimir Ermakov.
00008  *
00009  * This file is part of the mavros package and subject to the license terms
00010  * in the top-level LICENSE file of the mavros repository.
00011  * https://github.com/mavlink/mavros/tree/master/LICENSE.md
00012  */
00013 
00014 #include <mavros/mavlink_diag.h>
00015 
00016 using namespace mavros;
00017 
00018 MavlinkDiag::MavlinkDiag(std::string name) :
00019         diagnostic_updater::DiagnosticTask(name),
00020         last_drop_count(0),
00021         is_connected(false)
00022 { };
00023 
00024 void MavlinkDiag::run(diagnostic_updater::DiagnosticStatusWrapper &stat)
00025 {
00026         if (auto link = weak_link.lock()) {
00027                 auto mav_status = link->get_status();
00028                 auto iostat = link->get_iostat();
00029 
00030                 stat.addf("Received packets:", "%u", mav_status.packet_rx_success_count);
00031                 stat.addf("Dropped packets:", "%u", mav_status.packet_rx_drop_count);
00032                 stat.addf("Buffer overruns:", "%u", mav_status.buffer_overrun);
00033                 stat.addf("Parse errors:", "%u", mav_status.parse_error);
00034                 stat.addf("Rx sequence number:", "%u", mav_status.current_rx_seq);
00035                 stat.addf("Tx sequence number:", "%u", mav_status.current_tx_seq);
00036 
00037                 stat.addf("Rx total bytes:", "%u", iostat.rx_total_bytes);
00038                 stat.addf("Tx total bytes:", "%u", iostat.tx_total_bytes);
00039                 stat.addf("Rx speed:", "%f", iostat.rx_speed);
00040                 stat.addf("Tx speed:", "%f", iostat.tx_speed);
00041 
00042                 if (mav_status.packet_rx_drop_count > last_drop_count)
00043                         stat.summaryf(1, "%d packeges dropped since last report",
00044                                 mav_status.packet_rx_drop_count - last_drop_count);
00045                 else if (is_connected)
00046                         stat.summary(0, "connected");
00047                 else
00048                         // link operational, but not connected
00049                         stat.summary(1, "not connected");
00050 
00051                 last_drop_count = mav_status.packet_rx_drop_count;
00052         } else {
00053                 stat.summary(2, "not connected");
00054         }
00055 }
00056 


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