Commit 12a43c79 authored by lm's avatar lm

Mainwindow cleanup, fixed short value filter in Linechart, working on Python XML parser support

parent c2c05fbc
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -33,6 +33,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -33,6 +33,7 @@ This file is part of the QGROUNDCONTROL project
#include <QObject> #include <QObject>
#include <QDomDocument> #include <QDomDocument>
#include <QString> #include <QString>
#include <QProcess>
#include <inttypes.h> #include <inttypes.h>
...@@ -55,20 +56,24 @@ public slots: ...@@ -55,20 +56,24 @@ public slots:
/** @brief Parse XML and generate C files */ /** @brief Parse XML and generate C files */
bool generate(); bool generate();
/** @brief Handle process errors */
void processError(QProcess::ProcessError err);
signals: signals:
/** @brief Status message on the parsing */ /** @brief Status message on the parsing */
void parseState(QString message); void parseState(QString message);
protected: protected:
/** @brief Accumulate the X.25 CRC by adding one char at a time. */ // /** @brief Accumulate the X.25 CRC by adding one char at a time. */
void crcAccumulate(uint8_t data, uint16_t *crcAccum); // void crcAccumulate(uint8_t data, uint16_t *crcAccum);
/** @brief Initialize the buffer for the X.25 CRC */ // /** @brief Initialize the buffer for the X.25 CRC */
void crcInit(uint16_t* crcAccum); // void crcInit(uint16_t* crcAccum);
QDomDocument* doc; QDomDocument* doc;
QString outputDirName; QString outputDirName;
QString fileName; QString fileName;
QProcess* process;
}; };
#endif // MAVLINKXMLPARSERV10_H #endif // MAVLINKXMLPARSERV10_H
...@@ -8,6 +8,18 @@ MAVLinkDecoder::MAVLinkDecoder(MAVLinkProtocol* protocol, QObject *parent) : ...@@ -8,6 +8,18 @@ MAVLinkDecoder::MAVLinkDecoder(MAVLinkProtocol* protocol, QObject *parent) :
memcpy(messageInfo, msg, sizeof(mavlink_message_info_t)*256); memcpy(messageInfo, msg, sizeof(mavlink_message_info_t)*256);
memset(receivedMessages, 0, sizeof(mavlink_message_t)*256); memset(receivedMessages, 0, sizeof(mavlink_message_t)*256);
// Fill filter
messageFilter.insert(MAVLINK_MSG_ID_HEARTBEAT, false);
messageFilter.insert(MAVLINK_MSG_ID_SYS_STATUS, false);
messageFilter.insert(MAVLINK_MSG_ID_STATUSTEXT, false);
messageFilter.insert(MAVLINK_MSG_ID_COMMAND, false);
messageFilter.insert(MAVLINK_MSG_ID_COMMAND_ACK, false);
messageFilter.insert(MAVLINK_MSG_ID_PARAM_SET, false);
messageFilter.insert(MAVLINK_MSG_ID_PARAM_VALUE, false);
messageFilter.insert(MAVLINK_MSG_ID_MISSION_ITEM, false);
messageFilter.insert(MAVLINK_MSG_ID_MISSION_COUNT, false);
messageFilter.insert(MAVLINK_MSG_ID_MISSION_ACK, false);
connect(protocol, SIGNAL(messageReceived(LinkInterface*,mavlink_message_t)), this, SLOT(receiveMessage(LinkInterface*,mavlink_message_t))); connect(protocol, SIGNAL(messageReceived(LinkInterface*,mavlink_message_t)), this, SLOT(receiveMessage(LinkInterface*,mavlink_message_t)));
} }
...@@ -24,20 +36,21 @@ void MAVLinkDecoder::receiveMessage(LinkInterface* link,mavlink_message_t messag ...@@ -24,20 +36,21 @@ void MAVLinkDecoder::receiveMessage(LinkInterface* link,mavlink_message_t messag
quint64 time = 0; quint64 time = 0;
uint8_t fieldid = 0; uint8_t fieldid = 0;
uint8_t* m = ((uint8_t*)(receivedMessages+msgid))+8; uint8_t* m = ((uint8_t*)(receivedMessages+msgid))+8;
if (messageInfo[msgid].fields[fieldid].name == "time_boot_ms" && messageInfo[msgid].fields[fieldid].type == MAVLINK_TYPE_UINT32_T) if (QString(messageInfo[msgid].fields[fieldid].name) == QString("time_boot_ms") && messageInfo[msgid].fields[fieldid].type == MAVLINK_TYPE_UINT32_T)
{ {
time = *((quint32*)(m+messageInfo[msgid].fields[fieldid].wire_offset)); time = *((quint32*)(m+messageInfo[msgid].fields[fieldid].wire_offset));
} }
else if (messageInfo[msgid].fields[fieldid].name == "time_usec" && messageInfo[msgid].fields[fieldid].type == MAVLINK_TYPE_UINT64_T) else if (QString(messageInfo[msgid].fields[fieldid].name) == QString("time_usec") && messageInfo[msgid].fields[fieldid].type == MAVLINK_TYPE_UINT64_T)
{ {
time = *((quint64*)(m+messageInfo[msgid].fields[fieldid].wire_offset)); time = *((quint64*)(m+messageInfo[msgid].fields[fieldid].wire_offset));
} }
else else
{ {
// First value is not time, send out value 0
emitFieldValue(&message, fieldid, time); emitFieldValue(&message, fieldid, time);
} }
// Send out field values // Send out field values from 1..n
for (unsigned int i = 1; i < messageInfo[msgid].num_fields; ++i) for (unsigned int i = 1; i < messageInfo[msgid].num_fields; ++i)
{ {
emitFieldValue(&message, i, time); emitFieldValue(&message, i, time);
...@@ -51,6 +64,7 @@ void MAVLinkDecoder::emitFieldValue(mavlink_message_t* msg, int fieldid, quint64 ...@@ -51,6 +64,7 @@ void MAVLinkDecoder::emitFieldValue(mavlink_message_t* msg, int fieldid, quint64
{ {
// Add field tree widget item // Add field tree widget item
uint8_t msgid = msg->msgid; uint8_t msgid = msg->msgid;
if (messageFilter.contains(msgid)) return;
QString fieldName(messageInfo[msgid].fields[fieldid].name); QString fieldName(messageInfo[msgid].fields[fieldid].name);
QString fieldType; QString fieldType;
uint8_t* m = ((uint8_t*)(receivedMessages+msgid))+8; uint8_t* m = ((uint8_t*)(receivedMessages+msgid))+8;
......
...@@ -27,7 +27,8 @@ protected: ...@@ -27,7 +27,8 @@ protected:
void emitFieldValue(mavlink_message_t* msg, int fieldid, quint64 time); void emitFieldValue(mavlink_message_t* msg, int fieldid, quint64 time);
mavlink_message_t receivedMessages[256]; ///< Available / known messages mavlink_message_t receivedMessages[256]; ///< Available / known messages
mavlink_message_info_t messageInfo[256]; mavlink_message_info_t messageInfo[256]; ///< Message information
QMap<uint16_t, bool> messageFilter; ///< Message/field names not to emit
}; };
......
...@@ -91,8 +91,8 @@ MainWindow::MainWindow(QWidget *parent): ...@@ -91,8 +91,8 @@ MainWindow::MainWindow(QWidget *parent):
styleFileName(QCoreApplication::applicationDirPath() + "/style-indoor.css"), styleFileName(QCoreApplication::applicationDirPath() + "/style-indoor.css"),
autoReconnect(false), autoReconnect(false),
currentStyle(QGC_MAINWINDOW_STYLE_INDOOR), currentStyle(QGC_MAINWINDOW_STYLE_INDOOR),
lowPowerMode(false), centerStackActionGroup(this),
centerStackActionGroup(this) lowPowerMode(false)
{ {
loadSettings(); loadSettings();
if (!settings.contains("CURRENT_VIEW")) if (!settings.contains("CURRENT_VIEW"))
...@@ -115,12 +115,20 @@ MainWindow::MainWindow(QWidget *parent): ...@@ -115,12 +115,20 @@ MainWindow::MainWindow(QWidget *parent):
settings.sync(); settings.sync();
// Setup UI state machines loadStyle(currentStyle);
centerStackActionGroup.setExclusive(true);
// Setup user interface // Setup user interface
ui.setupUi(this); ui.setupUi(this);
// Set dock options
setDockOptions(AnimatedDocks | AllowTabbedDocks | AllowNestedDocks);
statusBar()->setSizeGripEnabled(true);
configureWindowName();
// Setup UI state machines
centerStackActionGroup.setExclusive(true);
centerStack = new QStackedWidget(this); centerStack = new QStackedWidget(this);
setCentralWidget(centerStack); setCentralWidget(centerStack);
...@@ -131,22 +139,14 @@ MainWindow::MainWindow(QWidget *parent): ...@@ -131,22 +139,14 @@ MainWindow::MainWindow(QWidget *parent):
toolBar->addPerspectiveChangeAction(ui.actionOperatorsView); toolBar->addPerspectiveChangeAction(ui.actionOperatorsView);
toolBar->addPerspectiveChangeAction(ui.actionEngineersView); toolBar->addPerspectiveChangeAction(ui.actionEngineersView);
toolBar->addPerspectiveChangeAction(ui.actionPilotsView); toolBar->addPerspectiveChangeAction(ui.actionPilotsView);
// toolBar->addPerspectiveChangeAction(ui.actionUnconnectedView);
buildCommonWidgets(); buildCommonWidgets();
connectCommonWidgets(); connectCommonWidgets();
configureWindowName();
loadStyle(currentStyle);
// Create actions // Create actions
connectCommonActions(); connectCommonActions();
// Set dock options
setDockOptions(AnimatedDocks | AllowTabbedDocks | AllowNestedDocks);
statusBar()->setSizeGripEnabled(true);
// Restore the window setup // Restore the window setup
if (settings.contains(getWindowStateKey())) if (settings.contains(getWindowStateKey()))
...@@ -179,14 +179,6 @@ MainWindow::MainWindow(QWidget *parent): ...@@ -179,14 +179,6 @@ MainWindow::MainWindow(QWidget *parent):
joystickWidget = 0; joystickWidget = 0;
joystick = new JoystickInput(); joystick = new JoystickInput();
// Load Toolbar
toolBar = new QGCToolBar(this);
this->addToolBar(toolBar);
// Add actions
toolBar->addPerspectiveChangeAction(ui.actionOperatorsView);
toolBar->addPerspectiveChangeAction(ui.actionEngineersView);
toolBar->addPerspectiveChangeAction(ui.actionPilotsView);
// Connect link // Connect link
if (autoReconnect) if (autoReconnect)
{ {
...@@ -204,6 +196,9 @@ MainWindow::MainWindow(QWidget *parent): ...@@ -204,6 +196,9 @@ MainWindow::MainWindow(QWidget *parent):
windowStateVal = windowState(); windowStateVal = windowState();
show(); show();
connect(&windowNameUpdateTimer, SIGNAL(timeout()), this, SLOT(configureWindowName()));
windowNameUpdateTimer.start(15000);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
......
...@@ -213,6 +213,9 @@ public slots: ...@@ -213,6 +213,9 @@ public slots:
*/ */
void showCentralWidget(); void showCentralWidget();
/** @brief Update the window name */
void configureWindowName();
public: public:
QGCMAVLinkLogPlayer* getLogPlayer() QGCMAVLinkLogPlayer* getLogPlayer()
{ {
...@@ -283,7 +286,6 @@ protected: ...@@ -283,7 +286,6 @@ protected:
void connectCommonWidgets(); void connectCommonWidgets();
void connectCommonActions(); void connectCommonActions();
void configureWindowName();
void loadSettings(); void loadSettings();
void storeSettings(); void storeSettings();
...@@ -369,6 +371,7 @@ protected: ...@@ -369,6 +371,7 @@ protected:
Qt::WindowStates windowStateVal; Qt::WindowStates windowStateVal;
bool lowPowerMode; ///< If enabled, QGC reduces the update rates of all widgets bool lowPowerMode; ///< If enabled, QGC reduces the update rates of all widgets
QGCFlightGearLink* fgLink; QGCFlightGearLink* fgLink;
QTimer windowNameUpdateTimer;
private: private:
Ui::MainWindow ui; Ui::MainWindow ui;
......
...@@ -641,7 +641,7 @@ void LinechartWidget::addCurve(const QString& curve, const QString& unit) ...@@ -641,7 +641,7 @@ void LinechartWidget::addCurve(const QString& curve, const QString& unit)
curvesWidgetLayout->addWidget(label, labelRow, 2); curvesWidgetLayout->addWidget(label, labelRow, 2);
//checkBox->setText(QString()); //checkBox->setText(QString());
label->setText(curve); label->setText(getCurveName(curve+unit, ui.shortNameCheckBox->isChecked()));
QColor color(Qt::gray);// = plot->getColorForCurve(curve+unit); QColor color(Qt::gray);// = plot->getColorForCurve(curve+unit);
QString colorstyle; QString colorstyle;
colorstyle = colorstyle.sprintf("QWidget { background-color: #%X%X%X; }", color.red(), color.green(), color.blue()); colorstyle = colorstyle.sprintf("QWidget { background-color: #%X%X%X; }", color.red(), color.green(), color.blue());
...@@ -770,54 +770,70 @@ void LinechartWidget::recolor() ...@@ -770,54 +770,70 @@ void LinechartWidget::recolor()
} }
} }
void LinechartWidget::setShortNames(bool enable) QString LinechartWidget::getCurveName(const QString& key, bool shortEnabled)
{ {
foreach (QString key, curveNames.keys()) if (shortEnabled)
{ {
QString name; QString name;
if (enable) QStringList parts = curveNames.value(key).split(".");
if (parts.length() > 1)
{ {
QStringList parts = curveNames.value(key).split("."); name = parts.at(1);
if (parts.length() > 1) }
{ else
name = parts.at(1); {
} name = parts.at(0);
else }
{
name = parts.at(0);
}
const unsigned int sizeLimit = 10;
// Replace known words with abbreviations const int sizeLimit = 20;
if (name.length() > sizeLimit)
{
name.replace("gyroscope", "gyro");
name.replace("accelerometer", "acc");
name.replace("magnetometer", "mag");
name.replace("distance", "dist");
name.replace("altitude", "alt");
name.replace("waypoint", "wp");
name.replace("error", "err");
name.replace("message", "msg");
name.replace("source", "src");
}
// Check if sub-part is still exceeding N chars // Replace known words with abbreviations
if (name.length() > sizeLimit) if (name.length() > sizeLimit)
{ {
name.replace("a", ""); name.replace("gyroscope", "gyro");
name.replace("e", ""); name.replace("accelerometer", "acc");
name.replace("i", ""); name.replace("magnetometer", "mag");
name.replace("o", ""); name.replace("distance", "dist");
name.replace("u", ""); name.replace("ailerons", "ail");
} name.replace("altitude", "alt");
name.replace("waypoint", "wp");
name.replace("throttle", "thr");
name.replace("elevator", "elev");
name.replace("rudder", "rud");
name.replace("error", "err");
name.replace("version", "ver");
name.replace("message", "msg");
name.replace("count", "cnt");
name.replace("value", "val");
name.replace("source", "src");
name.replace("index", "idx");
name.replace("type", "typ");
name.replace("mode", "mod");
} }
else
// Check if sub-part is still exceeding N chars
if (name.length() > sizeLimit)
{ {
name = curveNames.value(key); name.replace("a", "");
name.replace("e", "");
name.replace("i", "");
name.replace("o", "");
name.replace("u", "");
} }
curveNameLabels.value(key)->setText(name);
return name;
}
else
{
return curveNames.value(key);
}
}
void LinechartWidget::setShortNames(bool enable)
{
foreach (QString key, curveNames.keys())
{
curveNameLabels.value(key)->setText(getCurveName(key, enable));
} }
} }
......
...@@ -124,6 +124,8 @@ protected: ...@@ -124,6 +124,8 @@ protected:
QToolButton* createButton(QWidget* parent); QToolButton* createButton(QWidget* parent);
void createCurveItem(QString curve); void createCurveItem(QString curve);
void createLayout(); void createLayout();
/** @brief Get the name for a curve key */
QString getCurveName(const QString& key, bool shortEnabled);
int sysid; ///< ID of the unmanned system this plot belongs to int sysid; ///< ID of the unmanned system this plot belongs to
LinechartPlot* activePlot; ///< Plot for this system LinechartPlot* activePlot; ///< Plot for this system
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment