| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #include "qlocationtestutils_p.h" |
| 30 | |
| 31 | bool QLocationTestUtils::hasDefaultSource() |
| 32 | { |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | bool QLocationTestUtils::hasDefaultMonitor() |
| 37 | { |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | QString QLocationTestUtils::addNmeaChecksumAndBreaks(const QString &sentence) |
| 42 | { |
| 43 | Q_ASSERT(sentence[0] == '$' && sentence[sentence.length()-1] == '*'); |
| 44 | |
| 45 | // XOR byte value of all characters between '$' and '*' |
| 46 | int result = 0; |
| 47 | for (int i=1; i<sentence.length()-1; i++) |
| 48 | result ^= sentence[i].toLatin1(); |
| 49 | const QString sum = QString::asprintf(format: "%02x" , result); |
| 50 | return sentence + sum + "\r\n" ; |
| 51 | } |
| 52 | |
| 53 | QString QLocationTestUtils::createRmcSentence(const QDateTime &dt) |
| 54 | { |
| 55 | QString time = dt.toString(format: "hhmmss.zzz" ); |
| 56 | QString date = dt.toString(format: "ddMMyy" ); |
| 57 | QString nmea = QString("$GPRMC,%1,A,2730.83609,S,15301.87844,E,0.7,9.0,%2,11.2,W,A*" ) |
| 58 | .arg(a: time).arg(a: date); |
| 59 | return addNmeaChecksumAndBreaks(sentence: nmea); |
| 60 | } |
| 61 | |
| 62 | QString QLocationTestUtils::createGgaSentence(const QTime &time) |
| 63 | { |
| 64 | QString nmea = QString("$GPGGA,%1,2734.76859,S,15305.99361,E,1,04,3.5,49.4,M,39.2,M,,*" ) |
| 65 | .arg(a: time.toString(format: "hhmmss.zzz" )); |
| 66 | return addNmeaChecksumAndBreaks(sentence: nmea); |
| 67 | } |
| 68 | |
| 69 | QString QLocationTestUtils::createGgaSentence(int lat, int lng, const QTime &time) { |
| 70 | QString nmea = QString("$GPGGA,%1,%200.00000,S,%300.,E,1,04,3.5,49.4,M,39.2,M,,*" ) |
| 71 | .arg(a: time.toString(format: "hhmmss.zzz" )).arg(a: lat).arg(a: lng); |
| 72 | return addNmeaChecksumAndBreaks(sentence: nmea); |
| 73 | } |
| 74 | |
| 75 | QString QLocationTestUtils::createZdaSentence(const QDateTime &dt) |
| 76 | { |
| 77 | QString time = dt.toString(format: "hhmmss.zzz" ); |
| 78 | QString nmea = QString("$GPZDA,%1,%2,%3,%4,,*" ) |
| 79 | .arg(a: time).arg(a: dt.toString(format: "dd" )).arg(a: dt.toString(format: "MM" )).arg(a: dt.toString(format: "yyyy" )); |
| 80 | return addNmeaChecksumAndBreaks(sentence: nmea); |
| 81 | } |
| 82 | |
| 83 | QString QLocationTestUtils::createGsaSentence() |
| 84 | { |
| 85 | return addNmeaChecksumAndBreaks(QStringLiteral("$GPGSA,A,3,,,,,,,,,,,,,3.0,3.5,4.0*" )); |
| 86 | } |
| 87 | |