From e5c8c2129f9882fd0aa202efb22680266de77b6f Mon Sep 17 00:00:00 2001 From: cranphin Date: Thu, 23 Sep 2010 21:35:08 +0000 Subject: [PATCH] GCS GPSDisplay: Add SNR bars, fix sattelite indexes from nmea parser. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1728 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../gpsdisplay/gpsconstellationwidget.h | 2 +- ground/src/plugins/gpsdisplay/gpsdisplay.pro | 68 ++++++----- .../plugins/gpsdisplay/gpsdisplaygadget.cpp | 1 + .../plugins/gpsdisplay/gpsdisplaywidget.ui | 21 +++- .../src/plugins/gpsdisplay/gpssnrwidget.cpp | 114 ++++++++++++++++++ ground/src/plugins/gpsdisplay/gpssnrwidget.h | 34 ++++++ ground/src/plugins/gpsdisplay/nmeaparser.cpp | 4 +- 7 files changed, 207 insertions(+), 37 deletions(-) create mode 100644 ground/src/plugins/gpsdisplay/gpssnrwidget.cpp create mode 100644 ground/src/plugins/gpsdisplay/gpssnrwidget.h diff --git a/ground/src/plugins/gpsdisplay/gpsconstellationwidget.h b/ground/src/plugins/gpsdisplay/gpsconstellationwidget.h index 166e3f690..6baeeb138 100644 --- a/ground/src/plugins/gpsdisplay/gpsconstellationwidget.h +++ b/ground/src/plugins/gpsdisplay/gpsconstellationwidget.h @@ -38,7 +38,7 @@ class GpsConstellationWidget : public QGraphicsView Q_OBJECT public: - GpsConstellationWidget(QWidget *parent = 0); + explicit GpsConstellationWidget(QWidget *parent = 0); ~GpsConstellationWidget(); public slots: diff --git a/ground/src/plugins/gpsdisplay/gpsdisplay.pro b/ground/src/plugins/gpsdisplay/gpsdisplay.pro index 699a43351..8ed2c93df 100644 --- a/ground/src/plugins/gpsdisplay/gpsdisplay.pro +++ b/ground/src/plugins/gpsdisplay/gpsdisplay.pro @@ -1,33 +1,35 @@ -TEMPLATE = lib -TARGET = GpsDisplayGadget -QT += svg -include(../../openpilotgcsplugin.pri) -include(../../plugins/coreplugin/coreplugin.pri) -include(gpsdisplay_dependencies.pri) -include(../../libs/qwt/qwt.pri) -HEADERS += gpsdisplayplugin.h \ - gpsconstellationwidget.h \ - gpsparser.h \ - telemetryparser.h -HEADERS += buffer.h -HEADERS += nmeaparser.h -HEADERS += gpsdisplaygadget.h -HEADERS += gpsdisplaywidget.h -HEADERS += gpsdisplaygadgetfactory.h -HEADERS += gpsdisplaygadgetconfiguration.h -HEADERS += gpsdisplaygadgetoptionspage.h -SOURCES += gpsdisplayplugin.cpp \ - gpsconstellationwidget.cpp \ - gpsparser.cpp \ - telemetryparser.cpp -SOURCES += buffer.cpp -SOURCES += nmeaparser.cpp -SOURCES += gpsdisplaygadget.cpp -SOURCES += gpsdisplaygadgetfactory.cpp -SOURCES += gpsdisplaywidget.cpp -SOURCES += gpsdisplaygadgetconfiguration.cpp -SOURCES += gpsdisplaygadgetoptionspage.cpp -OTHER_FILES += GpsDisplayGadget.pluginspec -FORMS += gpsdisplaygadgetoptionspage.ui -FORMS += gpsdisplaywidget.ui -RESOURCES += widgetresources.qrc +TEMPLATE = lib +TARGET = GpsDisplayGadget +QT += svg +include(../../openpilotgcsplugin.pri) +include(../../plugins/coreplugin/coreplugin.pri) +include(gpsdisplay_dependencies.pri) +include(../../libs/qwt/qwt.pri) +HEADERS += gpsdisplayplugin.h +HEADERS += gpsconstellationwidget.h +HEADERS += gpsparser.h +HEADERS += telemetryparser.h +HEADERS += gpssnrwidget.h +HEADERS += buffer.h +HEADERS += nmeaparser.h +HEADERS += gpsdisplaygadget.h +HEADERS += gpsdisplaywidget.h +HEADERS += gpsdisplaygadgetfactory.h +HEADERS += gpsdisplaygadgetconfiguration.h +HEADERS += gpsdisplaygadgetoptionspage.h +SOURCES += gpsdisplayplugin.cpp +SOURCES += gpsconstellationwidget.cpp +SOURCES += gpsparser.cpp +SOURCES += telemetryparser.cpp +SOURCES += gpssnrwidget.cpp +SOURCES += buffer.cpp +SOURCES += nmeaparser.cpp +SOURCES += gpsdisplaygadget.cpp +SOURCES += gpsdisplaygadgetfactory.cpp +SOURCES += gpsdisplaywidget.cpp +SOURCES += gpsdisplaygadgetconfiguration.cpp +SOURCES += gpsdisplaygadgetoptionspage.cpp +OTHER_FILES += GpsDisplayGadget.pluginspec +FORMS += gpsdisplaygadgetoptionspage.ui +FORMS += gpsdisplaywidget.ui +RESOURCES += widgetresources.qrc diff --git a/ground/src/plugins/gpsdisplay/gpsdisplaygadget.cpp b/ground/src/plugins/gpsdisplay/gpsdisplaygadget.cpp index ee38293c8..0b658fcc2 100644 --- a/ground/src/plugins/gpsdisplay/gpsdisplaygadget.cpp +++ b/ground/src/plugins/gpsdisplay/gpsdisplaygadget.cpp @@ -113,6 +113,7 @@ void GpsDisplayGadget::loadConfiguration(IUAVGadgetConfiguration* config) connect(parser, SIGNAL(datetime(double,double)), m_widget,SLOT(setDateTime(double,double))); connect(parser, SIGNAL(packet(QString)), m_widget, SLOT(dumpPacket(QString))); connect(parser, SIGNAL(satellite(int,int,int,int,int)), m_widget->gpsSky, SLOT(updateSat(int,int,int,int,int))); + connect(parser, SIGNAL(satellite(int,int,int,int,int)), m_widget->gpsSnrWidget, SLOT(updateSat(int,int,int,int,int))); connect(parser, SIGNAL(fixtype(QString)), m_widget, SLOT(setFixType(QString))); connect(parser, SIGNAL(dop(double,double,double)), m_widget, SLOT(setDOP(double,double,double))); } diff --git a/ground/src/plugins/gpsdisplay/gpsdisplaywidget.ui b/ground/src/plugins/gpsdisplay/gpsdisplaywidget.ui index 9cad0a388..24ba409a8 100644 --- a/ground/src/plugins/gpsdisplay/gpsdisplaywidget.ui +++ b/ground/src/plugins/gpsdisplay/gpsdisplaywidget.ui @@ -2,6 +2,14 @@ GpsDisplayWidget + + + 0 + 0 + 560 + 376 + + 0 @@ -572,13 +580,19 @@ - + 250 95 + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + @@ -667,6 +681,11 @@ QGraphicsView
gpsconstellationwidget.h
+ + GpsSnrWidget + QGraphicsView +
gpssnrwidget.h
+
diff --git a/ground/src/plugins/gpsdisplay/gpssnrwidget.cpp b/ground/src/plugins/gpsdisplay/gpssnrwidget.cpp new file mode 100644 index 000000000..c00ee7bbb --- /dev/null +++ b/ground/src/plugins/gpsdisplay/gpssnrwidget.cpp @@ -0,0 +1,114 @@ +#include "gpssnrwidget.h" + +GpsSnrWidget::GpsSnrWidget(QWidget *parent) : + QGraphicsView(parent) { + + scene = new QGraphicsScene(this); + setScene(scene); + + // Now create 'maxSatellites' satellite icons which we will move around on the map: + for (int i=0; i < MAX_SATTELITES;i++) { + satellites[i][0] = 0; + satellites[i][1] = 0; + satellites[i][2] = 0; + satellites[i][3] = 0; + + boxes[i] = new QGraphicsRectItem(); + boxes[i]->setBrush(QColor("Green")); + scene->addItem(boxes[i]); + boxes[i]->hide(); + + satTexts[i] = new QGraphicsSimpleTextItem("##",boxes[i]); + satTexts[i]->setBrush(QColor("Black")); + satTexts[i]->setFont(QFont("Courier")); + } + +} + +GpsSnrWidget::~GpsSnrWidget() { + delete scene; + scene = 0; +} + +void GpsSnrWidget::showEvent(QShowEvent *event) { + Q_UNUSED(event) + scene->setSceneRect(0,0, this->viewport()->width(), this->viewport()->height()); + for(int index = 0 ;index < MAX_SATTELITES ; index++) { + drawSat(index); + } +} + +void GpsSnrWidget::resizeEvent(QResizeEvent* event) { + Q_UNUSED(event); + scene->setSceneRect(0,0, this->viewport()->width(), this->viewport()->height()); + for(int index = 0 ;index < MAX_SATTELITES ; index++) { + drawSat(index); + } +} + +void GpsSnrWidget::updateSat(int index, int prn, int elevation, int azimuth, int snr) { + if (index >= MAX_SATTELITES) { + // A bit of error checking never hurts. + return; + } + + // TODO: add range checking + satellites[index][0] = prn; + satellites[index][1] = elevation; + satellites[index][2] = azimuth; + satellites[index][3] = snr; + + drawSat(index); +} + +void GpsSnrWidget::drawSat(int index) { + if (index >= MAX_SATTELITES) { + // A bit of error checking never hurts. + return; + } + + const int prn = satellites[index][0]; + const int snr = satellites[index][3]; + if (prn && snr) { + boxes[index]->show(); + + // When using integer values, width and height are the + // box width and height, but the left and bottom borders are drawn on the box, + // and the top and right borders are drawn just next to the box. + // So the box seems one pixel wider and higher with a border. + // I'm sure there's a good explanation for that :) + + // Casting to int rounds down, which is what I want. + // Minus 2 to allow a pixel of white left and right. + int availableWidth = (int)((scene->width()-2) / MAX_SATTELITES); + + // 2 pixels, one on each side. + qreal width = availableWidth - 2; + // SNR = 1-99 (0 is special).. + qreal height = int((scene->height() / 99) * snr + 0.5); + // 1 for showing a pixel of white to the left. + qreal x = availableWidth * index + 1; + // Rember, 0 is at the top. + qreal y = scene->height() - height; + // Compensate for the extra pixel for the border. + boxes[index]->setRect(0,0,width-1,height-1); + boxes[index]->setPos(x,y); + + QRectF boxRect = boxes[index]->boundingRect(); + QString prnString = QString().number(prn); + if(prnString.length() == 1) { + prnString = "0" + prnString; + } + satTexts[index]->setText(prnString); + QRectF textRect = satTexts[index]->boundingRect(); + + QTransform matrix; + qreal scale = 0.85 * (boxRect.width() / textRect.width()); + matrix.translate( boxRect.width()/2, boxRect.height()); + matrix.scale(scale,scale); + matrix.translate(-textRect.width()/2,-textRect.height()); + satTexts[index]->setTransform(matrix,false); + } else { + boxes[index]->hide(); + } +} diff --git a/ground/src/plugins/gpsdisplay/gpssnrwidget.h b/ground/src/plugins/gpsdisplay/gpssnrwidget.h new file mode 100644 index 000000000..590045fdc --- /dev/null +++ b/ground/src/plugins/gpsdisplay/gpssnrwidget.h @@ -0,0 +1,34 @@ +#ifndef GPSSNRWIDGET_H +#define GPSSNRWIDGET_H + +#include +#include + +class GpsSnrWidget : public QGraphicsView +{ + Q_OBJECT +public: + explicit GpsSnrWidget(QWidget *parent = 0); + ~GpsSnrWidget(); + +signals: + +public slots: + void updateSat(int index, int prn, int elevation, int azimuth, int snr); + +private: + static const int MAX_SATTELITES = 16; + int satellites[MAX_SATTELITES][4]; + QGraphicsScene *scene; + QGraphicsRectItem *boxes[MAX_SATTELITES]; + QGraphicsSimpleTextItem* satTexts[MAX_SATTELITES]; + + void drawSat(int index); + +protected: + void showEvent(QShowEvent *event); + void resizeEvent(QResizeEvent *event); + +}; + +#endif // GPSSNRWIDGET_H diff --git a/ground/src/plugins/gpsdisplay/nmeaparser.cpp b/ground/src/plugins/gpsdisplay/nmeaparser.cpp index e04e8ac55..887c17aa3 100644 --- a/ground/src/plugins/gpsdisplay/nmeaparser.cpp +++ b/ground/src/plugins/gpsdisplay/nmeaparser.cpp @@ -301,13 +301,13 @@ void NMEAParser::nmeaProcessGPGSV(char *packet) const int elv = tokenslist.at(base+1).toInt(); // Elevation, degrees const int azimuth = tokenslist.at(base+2).toInt(); // Azimuth, degrees const int sig = tokenslist.at(base+3).toInt(); // SNR - higher is better - const int index = sentence_index * 4 + sat; + const int index = (sentence_index-1) * 4 + sat; emit satellite(index, id, elv, azimuth, sig); } if(sentence_index == sentence_total) { // Last sentence - int total_sats = sentence_index * 4 + sats; + int total_sats = (sentence_index-1) * 4 + sats; for(int emptySatIndex = total_sats; emptySatIndex < 16; emptySatIndex++) { // Wipe the rest. emit satellite(emptySatIndex, 0, 0, 0, 0);