mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-18 08:54:15 +01:00
gpswidget outputs now something to the gui
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1229 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
516815807c
commit
d9d42ff068
@ -5,23 +5,23 @@ include(../../openpilotgcsplugin.pri)
|
||||
include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(gpsdisplay_dependencies.pri)
|
||||
include(../../libs/qwt/qwt.pri)
|
||||
HEADERS += gpsdisplayplugin.h \
|
||||
buffer.h \
|
||||
nmeaparser.h
|
||||
HEADERS += gpsdisplayplugin.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 \
|
||||
buffer.cpp \
|
||||
nmeaparser.cpp
|
||||
SOURCES += gpsdisplayplugin.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 \
|
||||
gpsdisplaywidget.ui
|
||||
FORMS += gpsdisplaygadgetoptionspage.ui
|
||||
FORMS += gpsdisplaywidget.ui
|
||||
RESOURCES += widgetresources.qrc
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QtGui>
|
||||
#include <QDebug>
|
||||
#include <QThread>
|
||||
#include "nmeaparser.h"
|
||||
@ -44,12 +44,11 @@ public:
|
||||
QextSerialPort *port;
|
||||
NMEAParser *parser;
|
||||
void setPort(QextSerialPort* port);
|
||||
void setParser(NMEAParser* parser);
|
||||
void processInputStream();
|
||||
void run();
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Initialize the widget
|
||||
*/
|
||||
@ -77,9 +76,12 @@ GpsDisplayWidget::GpsDisplayWidget(QWidget *parent) : QWidget(parent)
|
||||
widget->gpsWorld->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
|
||||
world->setScale(factor);
|
||||
|
||||
|
||||
connect(widget->connectButton, SIGNAL(clicked(bool)),
|
||||
this,SLOT(connectButtonClicked()));
|
||||
parser=new NMEAParser();
|
||||
connect(parser,SIGNAL(sv(int)),this,SLOT(setSVs(int)));
|
||||
connect(parser,SIGNAL(position(double,double,double)),this,SLOT(setPosition(double,double,double)));
|
||||
|
||||
}
|
||||
|
||||
GpsDisplayWidget::~GpsDisplayWidget()
|
||||
@ -87,6 +89,24 @@ GpsDisplayWidget::~GpsDisplayWidget()
|
||||
delete widget;
|
||||
}
|
||||
|
||||
void GpsDisplayWidget::setSVs(int sv)
|
||||
{
|
||||
QString temp = "FIX: ";
|
||||
temp.append(QString::number(sv));
|
||||
widget->label_2->setText(temp);
|
||||
}
|
||||
|
||||
void GpsDisplayWidget::setPosition(double lat, double lon, double alt)
|
||||
{
|
||||
QString temp = "Position: ";
|
||||
temp.append(QString::number(lat));
|
||||
temp.append(" ");
|
||||
temp.append(QString::number(lon));
|
||||
temp.append(" ");
|
||||
temp.append(QString::number(alt));
|
||||
widget->label->setText(temp);
|
||||
widget->textBrowser->append(temp);
|
||||
}
|
||||
|
||||
void GpsDisplayWidget::setPort(QextSerialPort* port)
|
||||
{
|
||||
@ -96,26 +116,35 @@ void GpsDisplayWidget::setPort(QextSerialPort* port)
|
||||
|
||||
void GpsDisplayWidget::connectButtonClicked() {
|
||||
GpsDisplayThread* gpsThread = new GpsDisplayThread();
|
||||
widget->textBrowser->append(QString("Connecting to GPS ...\n"));
|
||||
gpsThread->setPort(port);
|
||||
gpsThread->setParser(parser);
|
||||
gpsThread->start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GpsDisplayThread::setPort(QextSerialPort* port)
|
||||
{
|
||||
|
||||
this->port=port;
|
||||
}
|
||||
|
||||
void GpsDisplayThread::setParser(NMEAParser* parser)
|
||||
{
|
||||
|
||||
this->parser=parser;
|
||||
}
|
||||
|
||||
void GpsDisplayThread::run()
|
||||
{
|
||||
|
||||
qDebug() << "Opening.";
|
||||
|
||||
qDebug() << port->portName();
|
||||
|
||||
bool isOpen = port->open(QIODevice::ReadWrite);
|
||||
qDebug() << "Open: " << isOpen;
|
||||
parser=new NMEAParser();
|
||||
|
||||
char buf[1024];
|
||||
char c;
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include <QFile>
|
||||
#include <QTimer>
|
||||
#include "nmeaparser.h"
|
||||
|
||||
class Ui_GpsDisplayWidget;
|
||||
|
||||
@ -49,13 +50,17 @@ public:
|
||||
|
||||
// void setMode(QString mode); // Either UAVTalk or serial port
|
||||
void setPort(QextSerialPort* port);
|
||||
void setParser(NMEAParser *parser);
|
||||
|
||||
private slots:
|
||||
void connectButtonClicked();
|
||||
void setSVs(int);
|
||||
void setPosition(double, double, double);
|
||||
|
||||
private:
|
||||
Ui_GpsDisplayWidget* widget;
|
||||
QextSerialPort *port;
|
||||
NMEAParser *parser;
|
||||
bool connected;
|
||||
|
||||
};
|
||||
|
@ -33,12 +33,21 @@
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>46</width>
|
||||
<height>13</height>
|
||||
<width>251</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Position:</string>
|
||||
<string>Position: </string>
|
||||
</property>
|
||||
<property name="indent">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
@ -46,12 +55,18 @@
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>30</y>
|
||||
<width>46</width>
|
||||
<height>13</height>
|
||||
<width>61</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fix:</string>
|
||||
<string>Fix: </string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_3">
|
||||
@ -59,8 +74,8 @@
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>50</y>
|
||||
<width>46</width>
|
||||
<height>13</height>
|
||||
<width>111</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
@ -72,8 +87,8 @@
|
||||
<rect>
|
||||
<x>150</x>
|
||||
<y>50</y>
|
||||
<width>46</width>
|
||||
<height>13</height>
|
||||
<width>111</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
@ -85,8 +100,8 @@
|
||||
<rect>
|
||||
<x>90</x>
|
||||
<y>30</y>
|
||||
<width>46</width>
|
||||
<height>13</height>
|
||||
<width>161</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
@ -98,8 +113,8 @@
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>70</y>
|
||||
<width>46</width>
|
||||
<height>13</height>
|
||||
<width>121</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
@ -27,6 +27,13 @@
|
||||
|
||||
|
||||
#include "nmeaparser.h"
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QPushButton>
|
||||
|
||||
// Message Codes
|
||||
#define NMEA_NODATA 0 // No data. Packet not available, bad, or not decoded
|
||||
@ -56,12 +63,17 @@
|
||||
/**
|
||||
* Initialize the parser
|
||||
*/
|
||||
NMEAParser::NMEAParser()
|
||||
NMEAParser::NMEAParser(QObject *parent):QObject(parent)
|
||||
{
|
||||
bufferInit(&gpsRxBuffer, (unsigned char *)gpsRxData, 512);
|
||||
gpsRxOverflow=0;
|
||||
}
|
||||
|
||||
NMEAParser::~NMEAParser()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called each time there are data in the input buffer
|
||||
*/
|
||||
@ -251,10 +263,12 @@ void NMEAParser::nmeaProcessGPGGA(char* packet)
|
||||
|
||||
QString* nmeaString = new QString( packet );
|
||||
QStringList tokenslist = nmeaString->split(",");
|
||||
GpsData.Latitude = tokenslist.at(2).toFloat();
|
||||
GpsData.Longitude = tokenslist.at(4).toFloat();
|
||||
GpsData.Altitude = tokenslist.at(9).toFloat();
|
||||
GpsData.Latitude = tokenslist.at(2).toDouble();
|
||||
GpsData.Longitude = tokenslist.at(4).toDouble();
|
||||
GpsData.Altitude = tokenslist.at(9).toDouble();
|
||||
GpsData.SV = tokenslist.at(7).toInt();
|
||||
emit position(GpsData.Latitude,GpsData.Longitude,GpsData.Altitude);
|
||||
emit sv(GpsData.SV);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,7 +290,7 @@ void NMEAParser::nmeaProcessGPRMC(char* packet)
|
||||
|
||||
QString* nmeaString = new QString( packet );
|
||||
QStringList tokenslist = nmeaString->split(",");
|
||||
GpsData.Groundspeed = tokenslist.at(7).toFloat();
|
||||
GpsData.Groundspeed = tokenslist.at(7).toDouble();
|
||||
GpsData.Groundspeed = GpsData.Groundspeed*0.51444;
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#ifndef NMEAPARSER_H
|
||||
#define NMEAPARSER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtCore>
|
||||
#include <stdint.h>
|
||||
#include "buffer.h"
|
||||
@ -37,10 +38,10 @@
|
||||
|
||||
typedef struct struct_GpsData
|
||||
{
|
||||
float Latitude;
|
||||
float Longitude;
|
||||
float Altitude;
|
||||
float Groundspeed;
|
||||
double Latitude;
|
||||
double Longitude;
|
||||
double Altitude;
|
||||
double Groundspeed;
|
||||
int SV;
|
||||
uint8_t channel;
|
||||
uint8_t value_h;
|
||||
@ -48,10 +49,12 @@ typedef struct struct_GpsData
|
||||
uint8_t sum;
|
||||
}GpsData_t;
|
||||
|
||||
class NMEAParser
|
||||
class NMEAParser: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
NMEAParser();
|
||||
NMEAParser(QObject *parent = 0);
|
||||
~NMEAParser();
|
||||
void processInputStream(char c);
|
||||
char* nmeaGetPacketBuffer(void);
|
||||
char nmeaChecksum(char* gps_buffer);
|
||||
@ -67,6 +70,10 @@ public:
|
||||
uint32_t numUpdates;
|
||||
uint32_t numErrors;
|
||||
int32_t gpsRxOverflow;
|
||||
signals:
|
||||
void sv(int);
|
||||
void position(double,double,double);
|
||||
private slots:
|
||||
};
|
||||
|
||||
#endif // NMEAPARSER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user