1
0
mirror of git://projects.qi-hardware.com/nanomap.git synced 2024-11-22 11:26:14 +02:00

update gpsclient to new json based gpsd protocol

This commit is contained in:
Niels 2010-06-22 22:33:55 +02:00
parent 2dbc275890
commit 012268a764
2 changed files with 31 additions and 17 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de> * Copyright 2008, 2010 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -20,6 +20,7 @@
#include "gpsclient.h" #include "gpsclient.h"
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QStringList>
#include <QtCore/QTimer> #include <QtCore/QTimer>
GpsClient::GpsClient(QObject *parent) : QObject(parent), GpsClient::GpsClient(QObject *parent) : QObject(parent),
@ -37,31 +38,45 @@ void GpsClient::connectGps()
} }
void GpsClient::disconnectGps() void GpsClient::disconnectGps()
{
m_socket->disconnectFromHost();
}
void GpsClient::query()
{ {
QTextStream out(m_socket); QTextStream out(m_socket);
out << "p\n"; out << "?WATCH={\"enable\":false}\n";
m_socket->disconnectFromHost();
} }
void GpsClient::readData() void GpsClient::readData()
{ {
QTextStream in(m_socket); QTextStream in(m_socket);
QString reply = in.readLine(); QString reply = in.readLine();
reply.remove(0, 7); if (reply.contains("TPV")) {
if (reply != "?") { reply.remove("{");
float lat = reply.section(' ', 0, 0).toFloat(); reply.remove("}");
float lon = reply.section(' ', 1, 1).toFloat(); qreal lat = 0;
emit position(QPointF(lon, lat)); qreal lon = 0;
int mode = 0;
QStringList entries = reply.split(",");
foreach (const QString &entry, entries) {
if (entry.contains("lat")) {
lat = entry.section(":", 1, 1).toDouble();
} else if (entry.contains("lon")) {
lon = entry.section(":", 1, 1).toDouble();
} else if (entry.contains("mode")) {
// 0: no mode value yet seen
// 1: no fix
// 2: 2D
// 3: 3D
mode = entry.section(":", 1, 1).toInt();
}
}
if (mode > 1) {
emit position(QPointF(lon, lat));
}
} }
QTimer::singleShot(1000, this, SLOT(query()));
} }
void GpsClient::conn() void GpsClient::conn()
{ {
QTimer::singleShot(1000, this, SLOT(query())); QTextStream out(m_socket);
out << "?WATCH={\"enable\":true,\"json\":true}\n";
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de> * Copyright 2008, 2010 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -40,7 +40,6 @@ signals:
void disconnected(); void disconnected();
private slots: private slots:
void query();
void readData(); void readData();
void conn(); void conn();
@ -49,4 +48,4 @@ private:
}; };
#endif #endif // GPSCLIENT_H