From d3b45c527199837cfd75d7f555766e33e6f5f65d Mon Sep 17 00:00:00 2001 From: pixhawk Date: Mon, 7 Jun 2010 21:34:08 +0200 Subject: [PATCH] Added packet logging --- src/comm/MAVLinkProtocol.cc | 22 +++++++++++++++++++++- src/comm/MAVLinkProtocol.h | 2 ++ src/ui/MAVLinkSettingsWidget.ui | 7 +++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/comm/MAVLinkProtocol.cc b/src/comm/MAVLinkProtocol.cc index 8d3abf0fd..c9924110b 100644 --- a/src/comm/MAVLinkProtocol.cc +++ b/src/comm/MAVLinkProtocol.cc @@ -80,6 +80,11 @@ MAVLinkProtocol::MAVLinkProtocol() : MAVLinkProtocol::~MAVLinkProtocol() { + if (m_logfile) + { + m_logfile->close(); + delete m_logfile; + } } @@ -89,6 +94,11 @@ void MAVLinkProtocol::run() } +QString MAVLinkProtocol::getLogfileName() +{ + return QCoreApplication::applicationDirPath()+"/mavlink.log"; +} + /** * The bytes are copied by calling the LinkInterface::readBytes() method. * This method parses all incoming bytes and constructs a MAVLink packet. @@ -115,6 +125,15 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link) if (decodeState == 1) { + // Log data + if (m_loggingEnabled) + { + uint8_t buf[MAVLINK_MAX_PACKET_LEN]; + mavlink_msg_to_send_buffer(buf, &message); + m_logfile->write((const char*) buf); + qDebug() << "WROTE LOGFILE"; + } + // ORDER MATTERS HERE! // If the matching UAS object does not yet exist, it has to be created // before emitting the packetReceived signal @@ -324,7 +343,8 @@ void MAVLinkProtocol::enableLogging(bool enabled) { if (enabled && !m_loggingEnabled) { - m_logfile = new QFile(QCoreApplication::applicationDirPath()+"mavlink.log"); + m_logfile = new QFile(getLogfileName()); + m_logfile->open(QIODevice::WriteOnly | QIODevice::Append); } else { diff --git a/src/comm/MAVLinkProtocol.h b/src/comm/MAVLinkProtocol.h index 4a02a163a..e2fbafbf2 100644 --- a/src/comm/MAVLinkProtocol.h +++ b/src/comm/MAVLinkProtocol.h @@ -68,6 +68,8 @@ public: bool heartbeatsEnabled(void); /** @brief Get logging state */ bool loggingEnabled(void); + /** @brief Get the name of the packet log file */ + QString getLogfileName(); public slots: /** @brief Receive bytes from a communication interface */ diff --git a/src/ui/MAVLinkSettingsWidget.ui b/src/ui/MAVLinkSettingsWidget.ui index de9b67073..c65627d3b 100644 --- a/src/ui/MAVLinkSettingsWidget.ui +++ b/src/ui/MAVLinkSettingsWidget.ui @@ -24,6 +24,13 @@ + + + + Log all MAVLink packets + + + -- 2.22.0