Skip to content

Commit

Permalink
Added satellite system info and simulator timer.
Browse files Browse the repository at this point in the history
  • Loading branch information
direc85 committed Dec 1, 2019
1 parent 773bad0 commit b9df0b6
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
76 changes: 75 additions & 1 deletion src/gpsdatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ GPSSatellite::GPSSatellite(QObject *parent) :
}

GPSDataSource::GPSDataSource(QObject *parent) :
QObject(parent),
QObject(parent), SimulatorTimer(this),
numberOfUsedSatellites(0),
numberOfVisibleSatellites(0)
{
connect(&SimulatorTimer, SIGNAL(timeout()), this, SLOT(SimulatorTimeout()));

this->sSource = QGeoSatelliteInfoSource::createDefaultSource(this);
if (this->sSource) {
qDebug() << "created QGeoSatelliteInfoSource" << this->sSource->sourceName();
Expand All @@ -35,6 +37,7 @@ void GPSDataSource::satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &infos
sat->setAzimuth(info.attribute(QGeoSatelliteInfo::Azimuth));
sat->setElevation(info.attribute(QGeoSatelliteInfo::Elevation));
sat->setIdentifier(info.satelliteIdentifier());
sat->setSystem(info.satelliteSystem());
sat->setInUse(true);
sat->setSignalStrength(info.signalStrength());
this->satellites[info.satelliteIdentifier()] = sat;
Expand Down Expand Up @@ -76,6 +79,20 @@ QVariantList GPSDataSource::getSatellites() {
}

void GPSDataSource::setActive(bool active) {
if ( !sSource )
{
if ( !this->active && active )
{
SimulatorTimer.start(1000);
this->active = true;
}
else if ( this->active && !active )
{
SimulatorTimer.stop();
this->active = false;
}
return;
}
if (!this->active && active) {
if (this->sSource) {
qDebug() << "activating source...";
Expand Down Expand Up @@ -105,3 +122,60 @@ void GPSDataSource::setUpdateInterval(int updateInterval) {
emit this->updateIntervalChanged(updateInterval);
}
}

void GPSDataSource::SimulatorTimeout()
{
QList<QGeoSatelliteInfo> satellites;
QGeoSatelliteInfo satellite;

satellite.setAttribute(QGeoSatelliteInfo::Azimuth, 60.0);
satellite.setAttribute(QGeoSatelliteInfo::Elevation, 45.0);
satellite.setSatelliteIdentifier(8);
satellite.setSatelliteSystem(QGeoSatelliteInfo::GPS);
satellite.setSignalStrength(40);
satellites.append(satellite);

satellite.setAttribute(QGeoSatelliteInfo::Azimuth, 100.0);
satellite.setAttribute(QGeoSatelliteInfo::Elevation, 40.0);
satellite.setSatelliteIdentifier(22);
satellite.setSatelliteSystem(QGeoSatelliteInfo::GLONASS);
satellite.setSignalStrength(35);
satellites.append(satellite);

satellite.setAttribute(QGeoSatelliteInfo::Azimuth, 200.0);
satellite.setAttribute(QGeoSatelliteInfo::Elevation, 60.0);
satellite.setSatelliteIdentifier(131);
satellite.setSatelliteSystem(QGeoSatelliteInfo::GPS);
satellite.setSignalStrength(30);
satellites.append(satellite);

satellite.setAttribute(QGeoSatelliteInfo::Azimuth, 80.0);
satellite.setAttribute(QGeoSatelliteInfo::Elevation, 45.0);
satellite.setSatelliteIdentifier(9);
satellite.setSatelliteSystem(QGeoSatelliteInfo::GPS);
satellite.setSignalStrength(22);
satellites.append(satellite);

satellite.setAttribute(QGeoSatelliteInfo::Azimuth, 120.0);
satellite.setAttribute(QGeoSatelliteInfo::Elevation, 40.0);
satellite.setSatelliteIdentifier(21);
satellite.setSatelliteSystem(QGeoSatelliteInfo::GLONASS);
satellite.setSignalStrength(16);
satellites.append(satellite);

satellite.setAttribute(QGeoSatelliteInfo::Azimuth, 250.0);
satellite.setAttribute(QGeoSatelliteInfo::Elevation, 60.0);
satellite.setSatelliteIdentifier(228);
satellite.setSatelliteSystem(QGeoSatelliteInfo::GPS);
satellite.setSignalStrength(2);
satellites.append(satellite);

// Return all satellites in view
satellitesInViewUpdated(satellites);
// Return only half of the satellites in use
satellitesInUseUpdated(satellites.mid(0, satellites.size()/2));

QGeoPositionInfo position;
position.setAttribute(QGeoPositionInfo::Direction, 24.0);
positionUpdated(position);
}
9 changes: 9 additions & 0 deletions src/gpsdatasource.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QObject>
#include <QVariant>
#include <QMap>
#include <QTimer>
#include <QGeoSatelliteInfoSource>
#include <QGeoPositionInfoSource>

Expand All @@ -12,6 +13,7 @@ class GPSSatellite : public QObject {
Q_PROPERTY(qreal azimuth READ getAzimuth WRITE setAzimuth NOTIFY azimuthChanged)
Q_PROPERTY(qreal elevation READ getElevation WRITE setElevation NOTIFY elevationChanged)
Q_PROPERTY(int identifier READ getIdentifier WRITE setIdentifier NOTIFY identifierChanged)
Q_PROPERTY(int system READ getSystem WRITE setSystem NOTIFY systemChanged)
Q_PROPERTY(bool inUse READ isInUse WRITE setInUse NOTIFY inUseChanged)
Q_PROPERTY(int signalStrength READ getSignalStrength WRITE setSignalStrength NOTIFY signalStrengthChanged)
public:
Expand All @@ -20,23 +22,28 @@ class GPSSatellite : public QObject {
qreal azimuth;
qreal elevation;
int identifier;
int system;
bool inUse;
int signalStrength;
public slots:
qreal getAzimuth() {return this->azimuth;}
qreal getElevation() {return this->elevation;}
int getIdentifier() {return this->identifier;}
int getSignalStrength() {return this->signalStrength;}
int getSystem() {return system;}
bool isInUse() {return this->inUse;}
void setAzimuth(qreal azimuth) {this->azimuth = azimuth; emit this->azimuthChanged(this->azimuth);}
void setElevation(qreal elevation) {this->elevation = elevation; emit this->elevationChanged(this->elevation);}
void setIdentifier(int identifier) {this->identifier = identifier; emit this->identifierChanged(this->identifier);}
void setSystem(int system) {this->system = system; emit this->systemChanged(this->system);}
void setInUse(bool inUse) {this->inUse = inUse; emit this->inUseChanged(this->inUse);}

void setSignalStrength(int signalStrength) {this->signalStrength = signalStrength; emit this->signalStrengthChanged(this->signalStrength);}
signals:
void azimuthChanged(qreal azimuth);
void elevationChanged(qreal elevation);
void identifierChanged(int identifier);
void systemChanged(int system);
void inUseChanged(bool inUse);
void signalStrengthChanged(int signalStrength);
};
Expand All @@ -53,6 +60,7 @@ class GPSDataSource : public QObject
public:
explicit GPSDataSource(QObject *parent = 0);
private:
QTimer SimulatorTimer;
QGeoSatelliteInfoSource* sSource;
QGeoPositionInfoSource* pSource;
QMap<int, GPSSatellite*> satellites;
Expand All @@ -75,6 +83,7 @@ public slots:
void setNumberOfUsedSatellites(int numberOfUsedSatellites) {this->numberOfUsedSatellites = numberOfUsedSatellites; emit this->numberOfUsedSatellitesChanged(numberOfUsedSatellites);}
void setNumberOfVisibleSatellites(int numberOfVisibleSatellites) {this->numberOfVisibleSatellites = numberOfVisibleSatellites; emit this->numberOfVisibleSatellitesChanged(numberOfVisibleSatellites);}
void setUpdateInterval(int updateInterval);
void SimulatorTimeout();
signals:
void activeChanged(bool);
void movementDirectionChanged(qreal);
Expand Down

0 comments on commit b9df0b6

Please sign in to comment.