summaryrefslogtreecommitdiff
path: root/nmeasource.cpp
blob: e9e93eff66a7ee4351ad4cba80148914237b1698 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
#include <cmath>
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtPositioning/QNmeaPositionInfoSource>

#include "nmeasource.h"

NmeaSource::NmeaSource(QObject *parent) :
	QObject(parent)
{
	m_possrc = QGeoPositionInfoSource::createDefaultSource(this);
	m_satsrc = QGeoSatelliteInfoSource::createDefaultSource(this);
	if (m_possrc) {
		connect(m_possrc, SIGNAL(positionUpdated(QGeoPositionInfo)),
				this, SLOT(handlePosition(QGeoPositionInfo)));
	} else {
#ifdef QT_DEBUG
		qDebug() << "Using test GPS source";
		QNmeaPositionInfoSource* nmea = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::SimulationMode, this);
		QFile* file = new QFile(QDir::home().absoluteFilePath("nmea.txt"), this);
		if (file->open(QIODevice::ReadOnly | QIODevice::Text)) {
			nmea->setDevice(file);
			m_possrc = nmea;
			connect(m_possrc, SIGNAL(positionUpdated(QGeoPositionInfo)),
					this, SLOT(handlePosition(QGeoPositionInfo)));
		} else {
			qWarning() << "Could not open test GPS source";
			delete file;
			delete nmea;
		}
#else
		qWarning() << "No valid GPS position source!";
#endif
	}
	if (m_satsrc) {
		connect(m_satsrc, SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>)),
				this, SLOT(handleSatsInUse(QList<QGeoSatelliteInfo>)));
		connect(m_satsrc, SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>)),
				this, SLOT(handleSatsInView(QList<QGeoSatelliteInfo>)));
	}
}

NmeaSource::~NmeaSource()
{
}

void NmeaSource::start()
{
	m_last_satsinview = 0;
	if (m_possrc) {
		m_possrc->startUpdates();
	}
	if (m_satsrc) {
		m_satsrc->startUpdates();
	}
}

void NmeaSource::stop()
{
	if (m_possrc) {
		m_possrc->stopUpdates();
	}
	if (m_satsrc) {
		m_satsrc->stopUpdates();
	}
}

QString NmeaSource::formatFixMode(const QGeoCoordinate &coord)
{
	switch (coord.type()) {
	case QGeoCoordinate::Coordinate3D:
		return QString::fromLatin1("3");
	case QGeoCoordinate::Coordinate2D:
		return QString::fromLatin1("2");
	default:
		return QString::fromLatin1("1");
	}
}

QString NmeaSource::formatTimestamp(const QTime& time)
{
	return time.toString("HHmmss.zzz");
}

QString NmeaSource::formatDatestamp(const QDate& date)
{
	return date.toString("ddMMyy");
}

QString NmeaSource::formatLatitude(const QGeoCoordinate& coord)
{
	if (coord.isValid()) {
		QLatin1Char fill('0');
		double degrees;
		double minutes = modf(fabs(coord.latitude()), &degrees) * 60;
		return QString::fromLatin1("%1%2")
				.arg(static_cast<int>(degrees), 2, 10, fill)
				.arg(minutes, 7, 'f', 4, fill);
	} else {
		return QString();
	}
}

QString NmeaSource::formatLatitudeNS(const QGeoCoordinate& coord)
{
	if (coord.isValid()) {
		if (coord.latitude() >= 0.0) {
			return QLatin1String("N");
		} else {
			return QLatin1String("S");
		}
	} else {
		return QString();
	}
}

QString NmeaSource::formatLongitude(const QGeoCoordinate& coord)
{
	if (coord.isValid()) {
		QLatin1Char fill('0');
		double degrees;
		double minutes = modf(fabs(coord.longitude()), &degrees) * 60;
		return QString::fromLatin1("%1%2")
				.arg(static_cast<int>(degrees), 3, 10, fill)
				.arg(minutes, 7, 'f', 4, fill);
	} else {
		return QString();
	}
}

QString NmeaSource::formatLongitudeEW(const QGeoCoordinate& coord)
{
	if (coord.isValid()) {
		if (coord.longitude() >= 0.0) {
			return QString::fromLatin1("E");
		} else {
			return QString::fromLatin1("W");
		}
	} else {
		return QString();
	}
}

QString NmeaSource::formatAltitude(const QGeoCoordinate& coord)
{
	if (coord.type() == QGeoCoordinate::Coordinate3D) {
		return QString::number(coord.altitude(), 'f', 1);
	} else {
		return QString();
	}
}

QString NmeaSource::formatAltitudeUnits(const QGeoCoordinate& coord)
{
	if (coord.type() == QGeoCoordinate::Coordinate3D) {
		return QString::fromLatin1("M");
	} else {
		return QString();
	}
}

QString NmeaSource::formatSpeedKnots(const QGeoPositionInfo& pos)
{
	if (pos.hasAttribute(QGeoPositionInfo::GroundSpeed)) {
		double speed = pos.attribute(QGeoPositionInfo::GroundSpeed); // [m/s]
		speed *= 1.943844; // [knots]
		return QString::number(speed, 'f', 1);
	} else {
		return QString();
	}
}

QString NmeaSource::formatSpeedKmH(const QGeoPositionInfo& pos)
{
	if (pos.hasAttribute(QGeoPositionInfo::GroundSpeed)) {
		double speed = pos.attribute(QGeoPositionInfo::GroundSpeed); // [m/s]
		speed *= 3.6; // [km/h]
		return QString::number(speed, 'f', 1);
	} else {
		return QString();
	}
}

QString NmeaSource::formatTrueCourse(const QGeoPositionInfo& pos)
{
	if (pos.hasAttribute(QGeoPositionInfo::Direction)) {
		double course = pos.attribute(QGeoPositionInfo::Direction); // [deg]
		return QString::number(course, 'f', 1);
	} else {
		return QString();
	}
}

QString NmeaSource::formatMagCourse(const QGeoPositionInfo& pos)
{
	if (pos.hasAttribute(QGeoPositionInfo::Direction)
		&& pos.hasAttribute(QGeoPositionInfo::MagneticVariation)) {
		double course = pos.attribute(QGeoPositionInfo::Direction); // [deg]
		double magvar = pos.attribute(QGeoPositionInfo::MagneticVariation); // [+/-deg]
		return QString::number(course + magvar, 'f', 1);
	} else {
		return QString();
	}
}

QString NmeaSource::formatMagVariation(const QGeoPositionInfo& pos)
{
	if (pos.hasAttribute(QGeoPositionInfo::MagneticVariation)) {
		double var = pos.attribute(QGeoPositionInfo::MagneticVariation); // [+/-deg]
		return QString::number(fabs(var), 'f', 1);
	} else {
		return QString();
	}
}

QString NmeaSource::formatMagVariationEW(const QGeoPositionInfo& pos)
{
	if (pos.hasAttribute(QGeoPositionInfo::MagneticVariation)) {
		if (pos.attribute(QGeoPositionInfo::MagneticVariation) >= 0.0) {
			return QString::fromLatin1("E");
		} else {
			return QString::fromLatin1("W");
		}
	} else {
		return QString();
	}
}

QString NmeaSource::formatHDOP(const QGeoPositionInfo& pos)
{
	if (pos.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) {
		double eph = pos.attribute(QGeoPositionInfo::HorizontalAccuracy); // [m]
		return QString::number(eph / H_UERE, 'f', 1);
	} else {
		return QString();
	}
}

QString NmeaSource::formatVDOP(const QGeoPositionInfo& pos)
{
	if (pos.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) {
		double epv = pos.attribute(QGeoPositionInfo::VerticalAccuracy); // [m]
		return QString::number(epv / V_UERE, 'f', 1);
	} else {
		return QString();
	}
}

QString NmeaSource::formatPDOP(const QGeoPositionInfo& pos)
{

	if (pos.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)
		&& pos.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) {
		double eph = pos.attribute(QGeoPositionInfo::HorizontalAccuracy); // [m]
		double epv = pos.attribute(QGeoPositionInfo::VerticalAccuracy); // [m]
		double epe = sqrt(eph * eph + epv * epv);
		return QString::number(epe / P_UERE, 'f', 1);
	} else {
		return QString();
	}
}

QString NmeaSource::formatError(const QGeoPositionInfo& pos,
						   PositionAccuracyDirection which)
{
	switch (which) {
	case Spherical:
		if (pos.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)
			&& pos.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) {
			double eph = pos.attribute(QGeoPositionInfo::HorizontalAccuracy); // [m]
			double epv = pos.attribute(QGeoPositionInfo::VerticalAccuracy); // [m]
			double epe = sqrt(eph * eph + epv * epv);
			return QString::number(epe, 'f', 1);
		} else {
			return QString();
		}
		break;
	case Horizontal:
		if (pos.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) {
			double eph = pos.attribute(QGeoPositionInfo::HorizontalAccuracy); // [m]
			return QString::number(eph, 'f', 1);
		} else {
			return QString();
		}
		break;
	case Vertical:
		if (pos.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) {
			double epv = pos.attribute(QGeoPositionInfo::VerticalAccuracy); // [m]
			return QString::number(epv, 'f', 1);
		} else {
			return QString();
		}
		break;
	}
	return QString();
}

QString NmeaSource::formatErrorUnits(const QGeoPositionInfo& pos,
								PositionAccuracyDirection which)
{
	switch (which) {
	case Spherical:
		if (pos.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)
			&& pos.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) {
			return QString::fromLatin1("M");
		} else {
			return QString();
		}
		break;
	case Horizontal:
		if (pos.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) {
			return QString::fromLatin1("M");
		} else {
			return QString();
		}
		break;
	case Vertical:
		if (pos.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) {
			return QString::fromLatin1("M");
		} else {
			return QString();
		}
		break;
	}
	return QString();
}

QString NmeaSource::formatSatPrn(const QGeoSatelliteInfo &sat)
{
	return QString::fromLatin1("%1").arg(sat.satelliteIdentifier(), 2, 10, QLatin1Char('0'));
}

QString NmeaSource::formatSatElev(const QGeoSatelliteInfo &sat)
{
	if (sat.hasAttribute(QGeoSatelliteInfo::Elevation)) {
		int elv = lrint(sat.attribute(QGeoSatelliteInfo::Elevation));
		return QString::fromLatin1("%1").arg(elv, 2, 10, QLatin1Char('0'));
	} else {
		return QString();
	}
}

QString NmeaSource::formatSatAz(const QGeoSatelliteInfo &sat)
{
	if (sat.hasAttribute(QGeoSatelliteInfo::Azimuth)) {
		int az = lrint(sat.attribute(QGeoSatelliteInfo::Azimuth));
		return QString::fromLatin1("%1").arg(az, 3, 10, QLatin1Char('0'));
	} else {
		return QString();
	}
}
QString NmeaSource::formatSatSnr(const QGeoSatelliteInfo &sat)
{
	int snr = sat.signalStrength();
	if (snr >= 0) {
		return QString::fromLatin1("%1").arg(snr, 2, 10, QLatin1Char('0'));
	} else {
		return QString();
	}
	return QString::fromLatin1("%1").arg(sat.signalStrength(), 2, 10, QLatin1Char('0'));
}

void NmeaSource::emitSentence(const QString &sentence)
{
	QByteArray data = sentence.toLatin1();
	uint checksum = 0;
	foreach (const char& c, data) {
		checksum ^= c;
	}

#if 0
	qDebug("%s", qPrintable(QString::fromLatin1("$%1*%2").arg(sentence).
					   arg(checksum, 2, 16, QLatin1Char('0'))));
#endif

	emit dataReady(QString::fromLatin1("$%1*%2\r\n")
				   .arg(sentence)
				   .arg(checksum, 2, 16, QLatin1Char('0')));
}

void NmeaSource::generateGPRMC(const QGeoPositionInfo &pos)
{
	QString sentence =
		QString::fromLatin1("GPRMC,%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12")
			// 1 = UTC of position fix
			.arg(formatTimestamp(pos.timestamp().time()))
			// 2 = Data status (A = Autonomous V = Warning)
			.arg(pos.isValid() ? QLatin1Char('A') : QLatin1Char('V'))
			// 3 = Latitude of fix
			.arg(formatLatitude(pos.coordinate()))
			// 4 = N or S
			.arg(formatLatitudeNS(pos.coordinate()))
			// 5 = Longitude of fix
			.arg(formatLongitude(pos.coordinate()))
			// 6 = E or W
			.arg(formatLongitudeEW(pos.coordinate()))
			// 7 = Speed over ground in knots
			.arg(formatSpeedKnots(pos))
			// 8 = True track made good in degrees
			.arg(formatTrueCourse(pos))
			// 9 = Date Stamp
			.arg(formatDatestamp(pos.timestamp().date()))
			// 10 = Magnetic variation in degrees
			.arg(formatMagVariation(pos))
			// 11 = E or W
			.arg(formatMagVariationEW(pos))
			// 12 = FAA mode indicator (A = Autonomous, N = Not valid)
			.arg(pos.isValid() ? QLatin1Char('A') : QLatin1Char('N'))
			;
	emitSentence(sentence);
}

void NmeaSource::generateGPGGA(const QGeoPositionInfo &pos)
{
	QString sentence =
		QString::fromLatin1("GPGGA,%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12,%13,%14")
			// 1 = UTC of position fix
			.arg(formatTimestamp(pos.timestamp().time()))
			// 2 = Latitude of fix
			.arg(formatLatitude(pos.coordinate()))
			// 3 = N or S
			.arg(formatLatitudeNS(pos.coordinate()))
			// 4 = Longitude of fix
			.arg(formatLongitude(pos.coordinate()))
			// 5 = E or W
			.arg(formatLongitudeEW(pos.coordinate()))
			// 6 = Fix quality (0 = invalid, 1 = GPS)
			.arg(pos.isValid() ? QLatin1Char('1') : QLatin1Char('0'))
			// 7 = Number of satellites being tracked
			.arg(m_last_satsinview, 2, 10, QLatin1Char('0'))
			// 8 = Horizontal dillusion of position
			.arg(formatHDOP(pos))
			// 9 = Altitude
			.arg(formatAltitude(pos.coordinate()))
			// 10 = Altitude units
			.arg(formatAltitudeUnits(pos.coordinate()))
			// 11 = Height of geoid (mean sea level) about WGS 84
			.arg(QString()) // TODO We could calculate it. Usefulness debatable.
			// 12 = Units
			.arg(QString())
			// 13 = Time in seconds since last DGPS update
			.arg(QString())
			// 14 = DGPS station ID number
			.arg(QString())
			;
	emitSentence(sentence);
}

void NmeaSource::generateGPGLL(const QGeoPositionInfo &pos)
{
	QString sentence =
		QString::fromLatin1("GPGLL,%1,%2,%3,%4,%5,%6,%7")
			// 1 = Latitude of fix
			.arg(formatLatitude(pos.coordinate()))
			// 2 = N or S
			.arg(formatLatitudeNS(pos.coordinate()))
			// 3 = Longitude of fix
			.arg(formatLongitude(pos.coordinate()))
			// 4 = E or W
			.arg(formatLongitudeEW(pos.coordinate()))
			// 5 = UTC of fix
			.arg(formatTimestamp(pos.timestamp().time()))
			// 6 = Data valid (A = Active, V = Void)
			.arg(pos.isValid() ? QLatin1Char('A') : QLatin1Char('V'))
			// 7 = Mode indicator (A = Autonomous, N = Not valid)
			.arg(pos.isValid() ? QLatin1Char('A') : QLatin1Char('N'))
			;
	emitSentence(sentence);
}

void NmeaSource::generateGPVTG(const QGeoPositionInfo &pos)
{
	QString sentence =
		QString::fromLatin1("GPVTG,%1,%2,%3,%4,%5,%6,%7,%8")
			// 1 = True track made good in degrees
			.arg(formatTrueCourse(pos))
			// 2 = T
			.arg(pos.hasAttribute(QGeoPositionInfo::Direction)
				 ? QString::fromLatin1("T") : QString())
			// 3 = Magnetic track made good
			.arg(formatMagCourse(pos))
			// 4 = M
			.arg((pos.hasAttribute(QGeoPositionInfo::Direction)
				 && pos.hasAttribute(QGeoPositionInfo::MagneticVariation))
					  ? QString::fromLatin1("M") : QString())
			// 5 = Speed over ground in knots
			.arg(formatSpeedKnots(pos))
			// 6 = N
			.arg(pos.hasAttribute(QGeoPositionInfo::GroundSpeed)
				 ? QString::fromLatin1("N") : QString())
			// 7 = Mode indicator (A = Autonomous, N = Not valid)
			.arg(formatSpeedKmH(pos))
			// 8 = K
			.arg(pos.hasAttribute(QGeoPositionInfo::GroundSpeed)
				 ? QString::fromLatin1("K") : QString())
			;
	emitSentence(sentence);
}

void NmeaSource::generatePGRME(const QGeoPositionInfo &pos)
{
	QString sentence =
		QString::fromLatin1("PGRME,%1,%2,%3,%4,%5,%6")
			// 1 = Horizontal error estimate
			.arg(formatError(pos, Horizontal))
			// 2 = Units
			.arg(formatErrorUnits(pos, Horizontal))
			// 3 = Vertical error estimate
			.arg(formatError(pos, Vertical))
			// 4 = Units
			.arg(formatErrorUnits(pos, Vertical))
			// 5 = Spherical error estimate
			.arg(formatError(pos, Spherical))
			// 6 = Units
			.arg(formatErrorUnits(pos, Spherical))
			;
	emitSentence(sentence);
}

void NmeaSource::generateGPGSA(const QGeoPositionInfo& pos, const QList<QGeoSatelliteInfo>& info)
{
	const int n = info.size();
	QString sentence =
		QString::fromLatin1("GPGSA,%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12,%13,%14,%15,%16,%17")
			// 1 = Mode (A = Automatic)
			.arg(QLatin1Char('A'))
			// 2 = Fix mode
			.arg(formatFixMode(pos.coordinate()))
			// 3 - 14 = IDs of SVs used in position fix
			.arg(n > 0 ? formatSatPrn(info[0]) : QString())
			.arg(n > 1 ? formatSatPrn(info[1]) : QString())
			.arg(n > 2 ? formatSatPrn(info[2]) : QString())
			.arg(n > 3 ? formatSatPrn(info[3]) : QString())
			.arg(n > 4 ? formatSatPrn(info[4]) : QString())
			.arg(n > 5 ? formatSatPrn(info[5]) : QString())
			.arg(n > 6 ? formatSatPrn(info[6]) : QString())
			.arg(n > 7 ? formatSatPrn(info[7]) : QString())
			.arg(n > 8 ? formatSatPrn(info[8]) : QString())
			.arg(n > 9 ? formatSatPrn(info[9]) : QString())
			.arg(n > 10 ? formatSatPrn(info[10]) : QString())
			.arg(n > 11 ? formatSatPrn(info[11]) : QString())
			// 15 = PDOP
			.arg(formatPDOP(pos))
			// 16 = HDOP
			.arg(formatHDOP(pos))
			// 17 = VDOP
			.arg(formatVDOP(pos))
			;
	emitSentence(sentence);
}

void NmeaSource::generateGPGSV(const QGeoPositionInfo& pos, const QList<QGeoSatelliteInfo>& info)
{
	const int nsats = info.size();
	const int nmsgs = nsats / 4;
	int i;

	Q_UNUSED(pos);

	for (i = 0; i < nmsgs; i++) {
		int s = i * 4; // Start from this satellite index)
		QString sentence =
			QString::fromLatin1("GPGSV,%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12,%13,%14,%15,%16,%17,%18,%19")
				// 1 = Number of sentences for full data
				.arg(nmsgs)
				// 2 = Sentence number
				.arg(i + 1)
				// 3 = Total number of satellites in view
				.arg(nsats)
				// 4 - 14 = IDs of SVs used in position fix
				.arg(nsats > s + 0 ? formatSatPrn(info[s + 0]) : QString())
				.arg(nsats > s + 0 ? formatSatElev(info[s + 0]) : QString())
				.arg(nsats > s + 0 ? formatSatAz(info[s + 0]) : QString())
				.arg(nsats > s + 0 ? formatSatSnr(info[s + 0]) : QString())
				.arg(nsats > s + 1 ? formatSatPrn(info[s + 1]) : QString())
				.arg(nsats > s + 1 ? formatSatElev(info[s + 1]) : QString())
				.arg(nsats > s + 1 ? formatSatAz(info[s + 1]) : QString())
				.arg(nsats > s + 1 ? formatSatSnr(info[s + 1]) : QString())
				.arg(nsats > s + 2 ? formatSatPrn(info[s + 2]) : QString())
				.arg(nsats > s + 2 ? formatSatElev(info[s + 2]) : QString())
				.arg(nsats > s + 2 ? formatSatAz(info[s + 2]) : QString())
				.arg(nsats > s + 2 ? formatSatSnr(info[s + 2]) : QString())
				.arg(nsats > s + 3 ? formatSatPrn(info[s + 3]) : QString())
				.arg(nsats > s + 3 ? formatSatElev(info[s + 3]) : QString())
				.arg(nsats > s + 3 ? formatSatAz(info[s + 3]) : QString())
				.arg(nsats > s + 3 ? formatSatSnr(info[s + 3]) : QString())
				;
		emitSentence(sentence);
	}
}

void NmeaSource::handlePosition(const QGeoPositionInfo &pos)
{
	generateGPRMC(pos);

	generateGPGGA(pos);
	generateGPGLL(pos);
	generateGPVTG(pos);
	generatePGRME(pos); //Estimated Position Error

	//PGRMZ = Altitude info, PGRMM = Map datum?
	//generateGPRMB?
	//generateGPBOD?
	//generateGPRTE?

	m_last_pos = pos;
}

void NmeaSource::handleSatsInUse(const QList<QGeoSatelliteInfo> &info)
{
	generateGPGSA(m_last_pos, info);
}

void NmeaSource::handleSatsInView(const QList<QGeoSatelliteInfo> &info)
{
	generateGPGSV(m_last_pos, info);
	m_last_satsinview = info.count();
}