|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QList> |
|
43 #include <QHash> |
|
44 |
|
45 #include <qgeosatelliteinfo.h> |
|
46 |
|
47 #include "qgeosatelliteinfosource_wince_p.h" |
|
48 #include "qgeoinfothread_wince_p.h" |
|
49 |
|
50 QTM_BEGIN_NAMESPACE |
|
51 |
|
52 // ========== QGeoSatelliteInfoValidator ========== |
|
53 |
|
54 QGeoSatelliteInfoValidator::QGeoSatelliteInfoValidator() : QGeoInfoValidator() {} |
|
55 |
|
56 QGeoSatelliteInfoValidator::~QGeoSatelliteInfoValidator() {} |
|
57 |
|
58 // Returns true if data contains at least the minimal amount of data we need to produce one of the |
|
59 // QGeoSatelliteInfoSource signals, otherwise returns false. |
|
60 bool QGeoSatelliteInfoValidator::valid(const GPS_POSITION &data) const |
|
61 { |
|
62 if (((data.dwValidFields & GPS_VALID_SATELLITE_COUNT) == 0) |
|
63 || ((data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW) == 0) |
|
64 || ((data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW_PRNS) == 0) |
|
65 || ((data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW_SIGNAL_TO_NOISE_RATIO) == 0)) { |
|
66 return false; |
|
67 } |
|
68 return true; |
|
69 } |
|
70 |
|
71 // ========== QGeoSatelliteInfoSourceWinCE ========== |
|
72 |
|
73 QGeoSatelliteInfoSourceWinCE::QGeoSatelliteInfoSourceWinCE(QObject *parent) : QGeoSatelliteInfoSource(parent) |
|
74 { |
|
75 QGeoSatelliteInfoValidator *validator = new QGeoSatelliteInfoValidator(); |
|
76 |
|
77 // The QGeoInfoThreadWinCE instance takes ownership of the validator. |
|
78 infoThread = new QGeoInfoThreadWinCE(validator, false, this); |
|
79 infoThread->setUpdateInterval(DefaultUpdateInterval); |
|
80 infoThread->start(); |
|
81 |
|
82 // QGeoInfoThreadWinCE takes care of registering GPS_POSITION as a metatype. |
|
83 connect(infoThread, SIGNAL(dataUpdated(GPS_POSITION)), this, SLOT(dataUpdated(GPS_POSITION))); |
|
84 connect(infoThread, SIGNAL(updateTimeout()), this, SIGNAL(requestTimeout())); |
|
85 } |
|
86 |
|
87 QGeoSatelliteInfoSourceWinCE::~QGeoSatelliteInfoSourceWinCE() |
|
88 { |
|
89 delete infoThread; |
|
90 } |
|
91 |
|
92 void QGeoSatelliteInfoSourceWinCE::startUpdates() |
|
93 { |
|
94 infoThread->startUpdates(); |
|
95 } |
|
96 |
|
97 void QGeoSatelliteInfoSourceWinCE::stopUpdates() |
|
98 { |
|
99 infoThread->stopUpdates(); |
|
100 } |
|
101 |
|
102 void QGeoSatelliteInfoSourceWinCE::requestUpdate(int timeout) |
|
103 { |
|
104 if (timeout < 0) |
|
105 emit requestTimeout(); |
|
106 else |
|
107 infoThread->requestUpdate(timeout); |
|
108 } |
|
109 |
|
110 /* |
|
111 This is _only_ called when QGeoSatelliteInfoValidator::valid() returns true for the position. |
|
112 This means that it is implied that: |
|
113 - (data.dwValidFields & GPS_VALID_SATELLITE_COUNT) != 0 |
|
114 - (data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW) != 0 |
|
115 - (data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW_PRNS) != 0 |
|
116 - (data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW_SIGNAL_TO_NOISE_RATIO) != 0 |
|
117 |
|
118 This guarantees that the newly created position will be valid. |
|
119 If the code is changed such that this is no longer guaranteed then this method will need to be |
|
120 updated to test for those conditions. |
|
121 */ |
|
122 void QGeoSatelliteInfoSourceWinCE::dataUpdated(GPS_POSITION data) |
|
123 { |
|
124 // Satellites in view are hashed on the PRN values since the PRN value is how we |
|
125 // determine which of the satellites are in use. |
|
126 QHash<int, QGeoSatelliteInfo> satellitesInView; |
|
127 |
|
128 for (unsigned int i = 0; i < data.dwSatellitesInView; ++i) { |
|
129 QGeoSatelliteInfo satellite; |
|
130 |
|
131 satellite.setPrnNumber(data.rgdwSatellitesInViewPRNs[i]); |
|
132 satellite.setSignalStrength(data.rgdwSatellitesInViewSignalToNoiseRatio[i]); |
|
133 |
|
134 // The following properties are optional, and so are set if the data is present and valid |
|
135 // in the GPS_POSITION structure. |
|
136 if ((data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW_AZIMUTH) != 0) { |
|
137 satellite.setAttribute(QGeoSatelliteInfo::Azimuth, |
|
138 data.rgdwSatellitesInViewAzimuth[i]); |
|
139 } |
|
140 |
|
141 if ((data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW_ELEVATION) != 0) { |
|
142 satellite.setAttribute(QGeoSatelliteInfo::Elevation, |
|
143 data.rgdwSatellitesInViewElevation[i]); |
|
144 } |
|
145 |
|
146 satellitesInView.insert(satellite.prnNumber(), satellite); |
|
147 } |
|
148 |
|
149 emit satellitesInViewUpdated(satellitesInView.values()); |
|
150 |
|
151 // If the PRN data for the satellites which were used is unavailable we are done... |
|
152 if ((data.dwValidFields & GPS_VALID_SATELLITES_USED_PRNS) == 0) |
|
153 return; |
|
154 |
|
155 // ...otherwise we construct the list of satellites which are in use and emit the appropriate |
|
156 // signal |
|
157 QList<QGeoSatelliteInfo> satellitesInUse; |
|
158 |
|
159 for (unsigned int i = 0; i < data.dwSatelliteCount; ++i) { |
|
160 int inUsePRN = data.rgdwSatellitesUsedPRNs[i]; |
|
161 if (satellitesInView.contains(inUsePRN)) |
|
162 satellitesInUse << satellitesInView.value(inUsePRN); |
|
163 } |
|
164 |
|
165 emit satellitesInUseUpdated(satellitesInUse); |
|
166 } |
|
167 |
|
168 #include "moc_qgeosatelliteinfosource_wince_p.cpp" |
|
169 QTM_END_NAMESPACE |