mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
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
This commit is contained in:
parent
aec96a3867
commit
e5c8c2129f
@ -38,7 +38,7 @@ class GpsConstellationWidget : public QGraphicsView
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GpsConstellationWidget(QWidget *parent = 0);
|
||||
explicit GpsConstellationWidget(QWidget *parent = 0);
|
||||
~GpsConstellationWidget();
|
||||
|
||||
public slots:
|
||||
|
@ -5,10 +5,11 @@ 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 += gpsdisplayplugin.h
|
||||
HEADERS += gpsconstellationwidget.h
|
||||
HEADERS += gpsparser.h
|
||||
HEADERS += telemetryparser.h
|
||||
HEADERS += gpssnrwidget.h
|
||||
HEADERS += buffer.h
|
||||
HEADERS += nmeaparser.h
|
||||
HEADERS += gpsdisplaygadget.h
|
||||
@ -16,10 +17,11 @@ HEADERS += gpsdisplaywidget.h
|
||||
HEADERS += gpsdisplaygadgetfactory.h
|
||||
HEADERS += gpsdisplaygadgetconfiguration.h
|
||||
HEADERS += gpsdisplaygadgetoptionspage.h
|
||||
SOURCES += gpsdisplayplugin.cpp \
|
||||
gpsconstellationwidget.cpp \
|
||||
gpsparser.cpp \
|
||||
telemetryparser.cpp
|
||||
SOURCES += gpsdisplayplugin.cpp
|
||||
SOURCES += gpsconstellationwidget.cpp
|
||||
SOURCES += gpsparser.cpp
|
||||
SOURCES += telemetryparser.cpp
|
||||
SOURCES += gpssnrwidget.cpp
|
||||
SOURCES += buffer.cpp
|
||||
SOURCES += nmeaparser.cpp
|
||||
SOURCES += 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)));
|
||||
}
|
||||
|
@ -2,6 +2,14 @@
|
||||
<ui version="4.0">
|
||||
<class>GpsDisplayWidget</class>
|
||||
<widget class="QWidget" name="GpsDisplayWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>560</width>
|
||||
<height>376</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
@ -572,13 +580,19 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QGraphicsView" name="graphicsView">
|
||||
<widget class="GpsSnrWidget" name="gpsSnrWidget">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>95</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
@ -667,6 +681,11 @@
|
||||
<extends>QGraphicsView</extends>
|
||||
<header>gpsconstellationwidget.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>GpsSnrWidget</class>
|
||||
<extends>QGraphicsView</extends>
|
||||
<header>gpssnrwidget.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
114
ground/src/plugins/gpsdisplay/gpssnrwidget.cpp
Normal file
114
ground/src/plugins/gpsdisplay/gpssnrwidget.cpp
Normal file
@ -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();
|
||||
}
|
||||
}
|
34
ground/src/plugins/gpsdisplay/gpssnrwidget.h
Normal file
34
ground/src/plugins/gpsdisplay/gpssnrwidget.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef GPSSNRWIDGET_H
|
||||
#define GPSSNRWIDGET_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QtGui/QGraphicsRectItem>
|
||||
|
||||
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
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user