Browse Source

Cleaned up debug output and fixed logging using settings

QGC4.4
pixhawk 15 years ago
parent
commit
c28456d442
  1. 42
      src/comm/MAVLinkProtocol.cc
  2. 38
      src/uas/UAS.cc
  3. 4
      src/uas/UAS.h
  4. 5
      src/uas/UASManager.cc
  5. 40
      src/ui/MainWindow.cc
  6. 2
      src/ui/designer/QGCToolWidget.cc

42
src/comm/MAVLinkProtocol.cc

@ -73,15 +73,16 @@ void MAVLinkProtocol::loadSettings()
QSettings settings; QSettings settings;
settings.sync(); settings.sync();
settings.beginGroup("QGC_MAVLINK_PROTOCOL"); settings.beginGroup("QGC_MAVLINK_PROTOCOL");
m_heartbeatsEnabled = settings.value("HEARTBEATS_ENABLED", m_heartbeatsEnabled).toBool(); enableHeartbeats(settings.value("HEARTBEATS_ENABLED", m_heartbeatsEnabled).toBool());
m_loggingEnabled = settings.value("LOGGING_ENABLED", m_loggingEnabled).toBool(); enableVersionCheck(settings.value("VERION_CHECK_ENABLED", m_enable_version_check).toBool());
m_enable_version_check = settings.value("VERION_CHECK_ENABLED", m_enable_version_check).toBool();
// Only set logfile if there is a name present in settings // Only set logfile if there is a name present in settings
if (settings.contains("LOGFILE_NAME") && m_logfile == NULL) if (settings.contains("LOGFILE_NAME") && m_logfile == NULL)
{ {
m_logfile = new QFile(settings.value("LOGFILE_NAME").toString()); m_logfile = new QFile(settings.value("LOGFILE_NAME").toString());
} }
// Enable logging
enableLogging(settings.value("LOGGING_ENABLED", m_loggingEnabled).toBool());
// Only set system id if it was valid // Only set system id if it was valid
int temp = settings.value("GCS_SYSTEM_ID", systemId).toInt(); int temp = settings.value("GCS_SYSTEM_ID", systemId).toInt();
@ -116,8 +117,11 @@ MAVLinkProtocol::~MAVLinkProtocol()
storeSettings(); storeSettings();
if (m_logfile) if (m_logfile)
{ {
m_logfile->flush(); if (m_logfile->isOpen())
m_logfile->close(); {
m_logfile->flush();
m_logfile->close();
}
delete m_logfile; delete m_logfile;
} }
} }
@ -137,7 +141,7 @@ QString MAVLinkProtocol::getLogfileName()
} }
else else
{ {
return QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "qgrouncontrol_packetlog.mavlink"; return QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/qgrouncontrol_packetlog.mavlink";
} }
} }
@ -161,20 +165,21 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b)
if (decodeState == 1) if (decodeState == 1)
{ {
// Log data // Log data
if (m_loggingEnabled) if (m_loggingEnabled && m_logfile)
{ {
const int len = MAVLINK_MAX_PACKET_LEN+sizeof(quint64); const int len = MAVLINK_MAX_PACKET_LEN+sizeof(quint64);
uint8_t buf[len]; uint8_t buf[len];
quint64 time = QGC::groundTimeUsecs(); quint64 time = QGC::groundTimeUsecs();
memcpy(buf, (void*)&time, sizeof(quint64)); memcpy(buf, (void*)&time, sizeof(quint64));
// int packetlen = // Write message to buffer
// quint64 checktime = *((quint64*)buf);
// qDebug() << "TIME" << time << "CHECKTIME:" << checktime;
mavlink_msg_to_send_buffer(buf+sizeof(quint64), &message); mavlink_msg_to_send_buffer(buf+sizeof(quint64), &message);
QByteArray b((const char*)buf, len); QByteArray b((const char*)buf, len);
//int packetlen = if(m_logfile->write(b) < MAVLINK_MAX_PACKET_LEN+sizeof(quint64))
if(m_logfile->write(b) < MAVLINK_MAX_PACKET_LEN+sizeof(quint64)) qDebug() << "WRITING TO LOG FAILED!"; {
//qDebug() << "WROTE LOGFILE"; emit protocolStatusMessage(tr("MAVLink Logging failed"), tr("Could not write to file %1, disabling logging.").arg(m_logfile->fileName()));
// Stop logging
enableLogging(false);
}
} }
// ORDER MATTERS HERE! // ORDER MATTERS HERE!
@ -399,8 +404,8 @@ void MAVLinkProtocol::enableLogging(bool enabled)
{ {
if (!m_logfile->open(QIODevice::WriteOnly | QIODevice::Append)) if (!m_logfile->open(QIODevice::WriteOnly | QIODevice::Append))
{ {
emit protocolStatusMessage(tr("Opening MAVLink logfile for writing failed"), tr("MAVLink cannot log to the file %1, please choose a different file.").arg(m_logfile->fileName())); emit protocolStatusMessage(tr("Opening MAVLink logfile for writing failed"), tr("MAVLink cannot log to the file %1, please choose a different file. Stopping logging.").arg(m_logfile->fileName()));
qDebug() << "OPENING LOGFILE FAILED!"; m_loggingEnabled = false;
} }
} }
} }
@ -408,8 +413,11 @@ void MAVLinkProtocol::enableLogging(bool enabled)
{ {
if (m_logfile) if (m_logfile)
{ {
m_logfile->flush(); if (m_logfile->isOpen())
m_logfile->close(); {
m_logfile->flush();
m_logfile->close();
}
delete m_logfile; delete m_logfile;
m_logfile = NULL; m_logfile = NULL;
} }

38
src/uas/UAS.cc

@ -16,10 +16,10 @@
#include <iostream> #include <iostream>
#include <QDebug> #include <QDebug>
#include <cmath> #include <cmath>
#include <qmath.h>
#include "UAS.h" #include "UAS.h"
#include "LinkInterface.h" #include "LinkInterface.h"
#include "UASManager.h" #include "UASManager.h"
//#include "MG.h"
#include "QGC.h" #include "QGC.h"
#include "GAudioOutput.h" #include "GAudioOutput.h"
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
@ -27,20 +27,6 @@
#include "LinkManager.h" #include "LinkManager.h"
#include "SerialLink.h" #include "SerialLink.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846 /* pi */
#endif
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923 /* pi/2 */
#endif
#ifndef M_PI_4
#define M_PI_4 0.78539816339744830962 /* pi/4 */
#endif
UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(), UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(),
uasId(id), uasId(id),
startTime(MG::TIME::getGroundTimeNow()), startTime(MG::TIME::getGroundTimeNow()),
@ -322,8 +308,7 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message)
emit voltageChanged(message.sysid, state.vbat/1000.0f); emit voltageChanged(message.sysid, state.vbat/1000.0f);
// LOW BATTERY ALARM // LOW BATTERY ALARM
float chargeLevel = getChargeLevel(); if (lpVoltage < warnVoltage)
if (chargeLevel <= 20.0f)
{ {
startLowBattAlarm(); startLowBattAlarm();
} }
@ -1426,6 +1411,25 @@ void UAS::setParameter(const int component, const QString& id, const float value
} }
} }
void UAS::setSystemType(int systemType)
{
type = systemType;
// If the airframe is still generic, change it to a close default type
if (airframe == 0)
{
switch (systemType)
{
case MAV_FIXED_WING:
airframe = QGC_AIRFRAME_EASYSTAR;
break;
case MAV_QUADROTOR:
airframe = QGC_AIRFRAME_MIKROKOPTER;
break;
}
}
emit systemSpecsChanged(uasId);
}
void UAS::setUASName(const QString& name) void UAS::setUASName(const QString& name)
{ {
this->name = name; this->name = name;

4
src/uas/UAS.h

@ -122,8 +122,8 @@ protected: //COMMENTS FOR TEST UNIT
// Battery stats // Battery stats
float fullVoltage; ///< Voltage of the fully charged battery (100%) float fullVoltage; ///< Voltage of the fully charged battery (100%)
float emptyVoltage; ///< Voltage of the empty battery (0%) float emptyVoltage; ///< Voltage of the empty battery (0%)
float warnVoltage; ///< Voltage where QGC will start to warn about low battery
float startVoltage; ///< Voltage at system start float startVoltage; ///< Voltage at system start
float warnVoltage; ///< Voltage where QGC will start to warn about low battery
double currentVoltage; ///< Voltage currently measured double currentVoltage; ///< Voltage currently measured
float lpVoltage; ///< Low-pass filtered voltage float lpVoltage; ///< Low-pass filtered voltage
int timeRemaining; ///< Remaining time calculated based on previous and current int timeRemaining; ///< Remaining time calculated based on previous and current
@ -181,7 +181,7 @@ public slots:
/** @brief Set the autopilot type */ /** @brief Set the autopilot type */
void setAutopilotType(int apType) { autopilot = apType; emit systemSpecsChanged(uasId); } void setAutopilotType(int apType) { autopilot = apType; emit systemSpecsChanged(uasId); }
/** @brief Set the type of airframe */ /** @brief Set the type of airframe */
void setSystemType(int systemType) { type = systemType; emit systemSpecsChanged(uasId); } void setSystemType(int systemType);
/** @brief Set the specific airframe type */ /** @brief Set the specific airframe type */
void setAirframe(int airframe) { this->airframe = airframe; emit systemSpecsChanged(uasId); } void setAirframe(int airframe) { this->airframe = airframe; emit systemSpecsChanged(uasId); }
/** @brief Set a new name **/ /** @brief Set a new name **/

5
src/uas/UASManager.cc

@ -64,6 +64,11 @@ UASManager::UASManager() :
UASManager::~UASManager() UASManager::~UASManager()
{ {
// Delete all systems
foreach (UASInterface* mav, systems)
{
delete mav;
}
} }

40
src/ui/MainWindow.cc

@ -260,7 +260,6 @@ void MainWindow::buildCustomWidget()
for(int i = 0; i < widgets.size(); ++i) for(int i = 0; i < widgets.size(); ++i)
{ {
qDebug() << "ADDING WIDGET #" << i << widgets.at(i);
// Check if this widget already has a parent, do not create it in this case // Check if this widget already has a parent, do not create it in this case
QDockWidget* dock = dynamic_cast<QDockWidget*>(widgets.at(i)->parentWidget()); QDockWidget* dock = dynamic_cast<QDockWidget*>(widgets.at(i)->parentWidget());
if (!dock) if (!dock)
@ -771,20 +770,16 @@ void MainWindow::showToolWidget(bool visible)
QDockWidget* dockWidget = qobject_cast<QDockWidget *> (dockWidgets[tool]); QDockWidget* dockWidget = qobject_cast<QDockWidget *> (dockWidgets[tool]);
qDebug() << "DATA:" << tool << "FLOATING" << dockWidget->isFloating() << "checked" << action->isChecked() << "visible" << dockWidget->isVisible() << "action vis:" << action->isVisible();
if (dockWidget && dockWidget->isVisible() != visible) if (dockWidget && dockWidget->isVisible() != visible)
{ {
if (visible) if (visible)
{ {
qDebug() << "DOCK WIDGET ADDED";
addDockWidget(dockWidgetLocations[tool], dockWidget); addDockWidget(dockWidgetLocations[tool], dockWidget);
dockWidget->show(); dockWidget->show();
} }
else else
{ {
qDebug() << "DOCK WIDGET REMOVED";
removeDockWidget(dockWidget); removeDockWidget(dockWidget);
//dockWidget->hide();
} }
QHashIterator<int, QWidget*> i(dockWidgets); QHashIterator<int, QWidget*> i(dockWidgets);
@ -795,7 +790,7 @@ void MainWindow::showToolWidget(bool visible)
{ {
QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast<TOOLS_WIDGET_NAMES>(i.key()), currentView); QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast<TOOLS_WIDGET_NAMES>(i.key()), currentView);
settings.setValue(chKey,visible); settings.setValue(chKey,visible);
qDebug() << "showToolWidget(): Set key" << chKey << "to" << visible; //qDebug() << "showToolWidget(): Set key" << chKey << "to" << visible;
break; break;
} }
} }
@ -804,14 +799,14 @@ void MainWindow::showToolWidget(bool visible)
QDockWidget* dockWidget = qobject_cast<QDockWidget*>(QObject::sender()); QDockWidget* dockWidget = qobject_cast<QDockWidget*>(QObject::sender());
qDebug() << "Trying to cast dockwidget" << dockWidget << "isvisible" << visible; //qDebug() << "Trying to cast dockwidget" << dockWidget << "isvisible" << visible;
if (dockWidget) if (dockWidget)
{ {
// Get action // Get action
int tool = dockWidgets.key(dockWidget); int tool = dockWidgets.key(dockWidget);
qDebug() << "Updating widget setting" << tool << "to" << visible; //qDebug() << "Updating widget setting" << tool << "to" << visible;
QAction* action = toolsMenuActions[tool]; QAction* action = toolsMenuActions[tool];
action->blockSignals(true); action->blockSignals(true);
@ -826,7 +821,7 @@ void MainWindow::showToolWidget(bool visible)
{ {
QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast<TOOLS_WIDGET_NAMES>(i.key()), currentView); QString chKey = buildMenuKey (SUB_SECTION_CHECKED,static_cast<TOOLS_WIDGET_NAMES>(i.key()), currentView);
settings.setValue(chKey,visible); settings.setValue(chKey,visible);
qDebug() << "showToolWidget(): Set key" << chKey << "to" << visible; // qDebug() << "showToolWidget(): Set key" << chKey << "to" << visible;
break; break;
} }
} }
@ -843,7 +838,7 @@ void MainWindow::showTheWidget (TOOLS_WIDGET_NAMES widget, VIEW_SECTIONS view)
tempVisible = settings.value(buildMenuKey(SUB_SECTION_CHECKED,widget,view), false).toBool(); tempVisible = settings.value(buildMenuKey(SUB_SECTION_CHECKED,widget,view), false).toBool();
qDebug() << "showTheWidget(): Set key" << buildMenuKey(SUB_SECTION_CHECKED,widget,view) << "to" << tempVisible; //qDebug() << "showTheWidget(): Set key" << buildMenuKey(SUB_SECTION_CHECKED,widget,view) << "to" << tempVisible;
if (tempWidget) if (tempWidget)
{ {
@ -855,14 +850,6 @@ void MainWindow::showTheWidget (TOOLS_WIDGET_NAMES widget, VIEW_SECTIONS view)
tempLocation = static_cast <Qt::DockWidgetArea>(settings.value(buildMenuKey (SUB_SECTION_LOCATION,widget, view), QVariant(Qt::RightDockWidgetArea)).toInt()); tempLocation = static_cast <Qt::DockWidgetArea>(settings.value(buildMenuKey (SUB_SECTION_LOCATION,widget, view), QVariant(Qt::RightDockWidgetArea)).toInt());
// if (widget == MainWindow::MENU_UAS_LIST)
// {
// if (!settings.contains(buildMenuKey (SUB_SECTION_LOCATION,widget, view)))
// {
// tempLocation = Qt::RightDockWidgetArea;
// }
// }
if (tempWidget != NULL) if (tempWidget != NULL)
{ {
if (tempVisible) if (tempVisible)
@ -897,6 +884,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
//settings.setValue("windowState", saveState()); //settings.setValue("windowState", saveState());
aboutToCloseFlag = true; aboutToCloseFlag = true;
mavlink->storeSettings(); mavlink->storeSettings();
joystick->deleteLater();
// Save the last current view in any case // Save the last current view in any case
settings.setValue("CURRENT_VIEW", currentView); settings.setValue("CURRENT_VIEW", currentView);
// Save the current window state, but only if a system is connected (else no real number of widgets would be present) // Save the current window state, but only if a system is connected (else no real number of widgets would be present)
@ -997,7 +985,6 @@ void MainWindow::connectCommonWidgets()
void MainWindow::createCustomWidget() void MainWindow::createCustomWidget()
{ {
//qDebug() << "ADDING CUSTOM WIDGET";
QGCToolWidget* tool = new QGCToolWidget("Unnamed Tool", this); QGCToolWidget* tool = new QGCToolWidget("Unnamed Tool", this);
if (QGCToolWidget::instances()->size() < 2) if (QGCToolWidget::instances()->size() < 2)
@ -1425,9 +1412,6 @@ void MainWindow::addLink(LinkInterface *link)
// Error handling // Error handling
connect(link, SIGNAL(communicationError(QString,QString)), this, SLOT(showCriticalMessage(QString,QString)), Qt::QueuedConnection); connect(link, SIGNAL(communicationError(QString,QString)), this, SLOT(showCriticalMessage(QString,QString)), Qt::QueuedConnection);
//qDebug() << "ADDING LINK:" << link->getName() << "ACTION IS: " << commWidget->getAction();
// Special case for simulationlink // Special case for simulationlink
MAVLinkSimulationLink* sim = dynamic_cast<MAVLinkSimulationLink*>(link); MAVLinkSimulationLink* sim = dynamic_cast<MAVLinkSimulationLink*>(link);
if (sim) if (sim)
@ -1599,8 +1583,6 @@ void MainWindow::UASCreated(UASInterface* uas)
// the currently active UAS // the currently active UAS
if (UASManager::instance()->getUASList().size() == 1) if (UASManager::instance()->getUASList().size() == 1)
{ {
//qDebug() << "UPDATING THE VIEW SINCE THIS IS THE FIRST CONNECTED SYSTEM";
// Load last view if setting is present // Load last view if setting is present
if (settings.contains("CURRENT_VIEW_WITH_UAS_CONNECTED")) if (settings.contains("CURRENT_VIEW_WITH_UAS_CONNECTED"))
{ {
@ -1659,12 +1641,12 @@ void MainWindow::clearView()
if (temp) if (temp)
{ {
qDebug() << "TOOL:" << chKey << "IS:" << temp->isChecked(); //qDebug() << "TOOL:" << chKey << "IS:" << temp->isChecked();
settings.setValue(chKey,temp->isChecked()); settings.setValue(chKey,temp->isChecked());
} }
else else
{ {
qDebug() << "TOOL:" << chKey << "IS DEFAULT AND UNCHECKED"; //qDebug() << "TOOL:" << chKey << "IS DEFAULT AND UNCHECKED";
settings.setValue(chKey,false); settings.setValue(chKey,false);
} }
} }
@ -1876,16 +1858,16 @@ void MainWindow::showTheCentralWidget (TOOLS_WIDGET_NAMES centralWidget, VIEW_SE
QWidget* tempWidget = dockWidgets[centralWidget]; QWidget* tempWidget = dockWidgets[centralWidget];
tempVisible = settings.value(buildMenuKey(SUB_SECTION_CHECKED,centralWidget,view), false).toBool(); tempVisible = settings.value(buildMenuKey(SUB_SECTION_CHECKED,centralWidget,view), false).toBool();
qDebug() << buildMenuKey (SUB_SECTION_CHECKED,centralWidget,view) << tempVisible; //qDebug() << buildMenuKey (SUB_SECTION_CHECKED,centralWidget,view) << tempVisible;
if (toolsMenuActions[centralWidget]) if (toolsMenuActions[centralWidget])
{ {
qDebug() << "SETTING TO:" << tempVisible; //qDebug() << "SETTING TO:" << tempVisible;
toolsMenuActions[centralWidget]->setChecked(tempVisible); toolsMenuActions[centralWidget]->setChecked(tempVisible);
} }
if (centerStack && tempWidget && tempVisible) if (centerStack && tempWidget && tempVisible)
{ {
qDebug() << "ACTIVATING MAIN WIDGET"; //qDebug() << "ACTIVATING MAIN WIDGET";
centerStack->setCurrentWidget(tempWidget); centerStack->setCurrentWidget(tempWidget);
} }
} }

2
src/ui/designer/QGCToolWidget.cc

@ -32,7 +32,7 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent) :
} }
// Try with parent // Try with parent
dock = dynamic_cast<QDockWidget*>(this->parentWidget()); dock = dynamic_cast<QDockWidget*>(parent);
if (dock) if (dock)
{ {
dock->setWindowTitle(title); dock->setWindowTitle(title);

Loading…
Cancel
Save