2013-04-05 23:46:56 +03:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file telemetryparser.cpp
|
|
|
|
* @author Edouard Lafargue & the OpenPilot team Copyright (C) 2010.
|
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
|
|
|
* @addtogroup GPSGadgetPlugin GPS Gadget Plugin
|
|
|
|
* @{
|
|
|
|
* @brief A gadget that displays GPS status and enables basic configuration
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "telemetryparser.h"
|
|
|
|
#include <math.h>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the parser
|
|
|
|
*/
|
|
|
|
TelemetryParser::TelemetryParser(QObject *parent) : GPSParser(parent)
|
|
|
|
{
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
2013-05-19 17:37:30 +03:00
|
|
|
UAVDataObject *gpsObj = dynamic_cast<UAVDataObject *>(objManager->getObject("GPSPosition"));
|
|
|
|
|
2013-04-05 23:46:56 +03:00
|
|
|
if (gpsObj != NULL) {
|
2013-05-19 17:37:30 +03:00
|
|
|
connect(gpsObj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(updateGPS(UAVObject *)));
|
2013-04-05 23:46:56 +03:00
|
|
|
} else {
|
|
|
|
qDebug() << "Error: Object is unknown (GPSPosition).";
|
|
|
|
}
|
|
|
|
|
2013-05-19 17:37:30 +03:00
|
|
|
gpsObj = dynamic_cast<UAVDataObject *>(objManager->getObject("GPSTime"));
|
2013-04-05 23:46:56 +03:00
|
|
|
if (gpsObj != NULL) {
|
2013-05-19 17:37:30 +03:00
|
|
|
connect(gpsObj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(updateTime(UAVObject *)));
|
2013-04-05 23:46:56 +03:00
|
|
|
} else {
|
|
|
|
qDebug() << "Error: Object is unknown (GPSTime).";
|
|
|
|
}
|
|
|
|
|
2013-05-19 17:37:30 +03:00
|
|
|
gpsObj = dynamic_cast<UAVDataObject *>(objManager->getObject("GPSSatellites"));
|
2013-04-05 23:46:56 +03:00
|
|
|
if (gpsObj != NULL) {
|
2013-05-19 17:37:30 +03:00
|
|
|
connect(gpsObj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(updateSats(UAVObject *)));
|
2013-04-05 23:46:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TelemetryParser::~TelemetryParser()
|
2013-05-19 17:37:30 +03:00
|
|
|
{}
|
2013-04-05 23:46:56 +03:00
|
|
|
|
|
|
|
|
2013-05-19 17:37:30 +03:00
|
|
|
void TelemetryParser::updateGPS(UAVObject *object1)
|
|
|
|
{
|
|
|
|
UAVObjectField *field = object1->getField(QString("Satellites"));
|
2013-04-05 23:46:56 +03:00
|
|
|
emit sv(field->getValue().toInt());
|
|
|
|
|
|
|
|
double lat = object1->getField(QString("Latitude"))->getDouble();
|
|
|
|
double lon = object1->getField(QString("Longitude"))->getDouble();
|
|
|
|
double alt = object1->getField(QString("Altitude"))->getDouble();
|
2013-05-19 17:37:30 +03:00
|
|
|
|
2013-04-05 23:46:56 +03:00
|
|
|
lat *= 1E-7;
|
|
|
|
lon *= 1E-7;
|
2013-05-19 17:37:30 +03:00
|
|
|
emit position(lat, lon, alt);
|
2013-04-05 23:46:56 +03:00
|
|
|
|
2013-05-19 17:37:30 +03:00
|
|
|
double hdg = object1->getField(QString("Heading"))->getDouble();
|
|
|
|
double spd = object1->getField(QString("Groundspeed"))->getDouble();
|
|
|
|
emit speedheading(spd, hdg);
|
2013-04-05 23:46:56 +03:00
|
|
|
|
|
|
|
QString fix = object1->getField(QString("Status"))->getValue().toString();
|
|
|
|
emit fixtype(fix);
|
|
|
|
|
|
|
|
double hdop = object1->getField(QString("HDOP"))->getDouble();
|
|
|
|
double vdop = object1->getField(QString("VDOP"))->getDouble();
|
|
|
|
double pdop = object1->getField(QString("PDOP"))->getDouble();
|
2013-05-19 17:37:30 +03:00
|
|
|
emit dop(hdop, vdop, pdop);
|
2013-04-05 23:46:56 +03:00
|
|
|
}
|
|
|
|
|
2013-05-19 17:37:30 +03:00
|
|
|
void TelemetryParser::updateTime(UAVObject *object1)
|
|
|
|
{
|
|
|
|
double hour = object1->getField(QString("Hour"))->getDouble();
|
2013-04-05 23:46:56 +03:00
|
|
|
double minute = object1->getField(QString("Minute"))->getDouble();
|
|
|
|
double second = object1->getField(QString("Second"))->getDouble();
|
2013-05-19 17:37:30 +03:00
|
|
|
double time = second + minute * 100 + hour * 10000;
|
|
|
|
double year = object1->getField(QString("Year"))->getDouble();
|
|
|
|
double month = object1->getField(QString("Month"))->getDouble();
|
|
|
|
double day = object1->getField(QString("Day"))->getDouble();
|
|
|
|
double date = day + month * 100 + year * 10000;
|
|
|
|
emit datetime(date, time);
|
2013-04-05 23:46:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-19 17:37:30 +03:00
|
|
|
Updates the satellite constellation.
|
|
|
|
|
|
|
|
Not really optimized for now, we should only send updates for the stas
|
|
|
|
which have changed instead of updating everything... That said, Qt is supposed
|
|
|
|
to be able to optimize redraws anyway.
|
|
|
|
*/
|
|
|
|
void TelemetryParser::updateSats(UAVObject *object1)
|
|
|
|
{
|
|
|
|
UAVObjectField *prn = object1->getField(QString("PRN"));
|
|
|
|
UAVObjectField *elevation = object1->getField(QString("Elevation"));
|
|
|
|
UAVObjectField *azimuth = object1->getField(QString("Azimuth"));
|
|
|
|
UAVObjectField *snr = object1->getField(QString("SNR"));
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < prn->getNumElements(); i++) {
|
|
|
|
emit satellite(i, prn->getValue(i).toInt(), elevation->getValue(i).toInt(),
|
2013-04-05 23:46:56 +03:00
|
|
|
azimuth->getValue(i).toInt(), snr->getValue(i).toInt());
|
|
|
|
}
|
|
|
|
}
|