1 /* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation, nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30 #include <LocationUtil.h>
31
32 namespace android {
33 namespace hardware {
34 namespace gnss {
35 namespace V1_1 {
36 namespace implementation {
37
38 using ::android::hardware::gnss::V1_0::GnssLocation;
39 using ::android::hardware::gnss::V1_0::GnssConstellationType;
40 using ::android::hardware::gnss::V1_0::GnssLocationFlags;
41
convertGnssLocation(Location & in,GnssLocation & out)42 void convertGnssLocation(Location& in, GnssLocation& out)
43 {
44 memset(&out, 0, sizeof(GnssLocation));
45 if (in.flags & LOCATION_HAS_LAT_LONG_BIT) {
46 out.gnssLocationFlags |= GnssLocationFlags::HAS_LAT_LONG;
47 out.latitudeDegrees = in.latitude;
48 out.longitudeDegrees = in.longitude;
49 }
50 if (in.flags & LOCATION_HAS_ALTITUDE_BIT) {
51 out.gnssLocationFlags |= GnssLocationFlags::HAS_ALTITUDE;
52 out.altitudeMeters = in.altitude;
53 }
54 if (in.flags & LOCATION_HAS_SPEED_BIT) {
55 out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED;
56 out.speedMetersPerSec = in.speed;
57 }
58 if (in.flags & LOCATION_HAS_BEARING_BIT) {
59 out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING;
60 out.bearingDegrees = in.bearing;
61 }
62 if (in.flags & LOCATION_HAS_ACCURACY_BIT) {
63 out.gnssLocationFlags |= GnssLocationFlags::HAS_HORIZONTAL_ACCURACY;
64 out.horizontalAccuracyMeters = in.accuracy;
65 }
66 if (in.flags & LOCATION_HAS_VERTICAL_ACCURACY_BIT) {
67 out.gnssLocationFlags |= GnssLocationFlags::HAS_VERTICAL_ACCURACY;
68 out.verticalAccuracyMeters = in.verticalAccuracy;
69 }
70 if (in.flags & LOCATION_HAS_SPEED_ACCURACY_BIT) {
71 out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED_ACCURACY;
72 out.speedAccuracyMetersPerSecond = in.speedAccuracy;
73 }
74 if (in.flags & LOCATION_HAS_BEARING_ACCURACY_BIT) {
75 out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING_ACCURACY;
76 out.bearingAccuracyDegrees = in.bearingAccuracy;
77 }
78
79 out.timestamp = static_cast<V1_0::GnssUtcTime>(in.timestamp);
80 }
81
convertGnssLocation(const GnssLocation & in,Location & out)82 void convertGnssLocation(const GnssLocation& in, Location& out)
83 {
84 memset(&out, 0, sizeof(out));
85 if (in.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG) {
86 out.flags |= LOCATION_HAS_LAT_LONG_BIT;
87 out.latitude = in.latitudeDegrees;
88 out.longitude = in.longitudeDegrees;
89 }
90 if (in.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE) {
91 out.flags |= LOCATION_HAS_ALTITUDE_BIT;
92 out.altitude = in.altitudeMeters;
93 }
94 if (in.gnssLocationFlags & GnssLocationFlags::HAS_SPEED) {
95 out.flags |= LOCATION_HAS_SPEED_BIT;
96 out.speed = in.speedMetersPerSec;
97 }
98 if (in.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
99 out.flags |= LOCATION_HAS_BEARING_BIT;
100 out.bearing = in.bearingDegrees;
101 }
102 if (in.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY) {
103 out.flags |= LOCATION_HAS_ACCURACY_BIT;
104 out.accuracy = in.horizontalAccuracyMeters;
105 }
106 if (in.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) {
107 out.flags |= LOCATION_HAS_VERTICAL_ACCURACY_BIT;
108 out.verticalAccuracy = in.verticalAccuracyMeters;
109 }
110 if (in.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) {
111 out.flags |= LOCATION_HAS_SPEED_ACCURACY_BIT;
112 out.speedAccuracy = in.speedAccuracyMetersPerSecond;
113 }
114 if (in.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) {
115 out.flags |= LOCATION_HAS_BEARING_ACCURACY_BIT;
116 out.bearingAccuracy = in.bearingAccuracyDegrees;
117 }
118
119 out.timestamp = static_cast<uint64_t>(in.timestamp);
120 }
121
convertGnssConstellationType(GnssSvType & in,GnssConstellationType & out)122 void convertGnssConstellationType(GnssSvType& in, GnssConstellationType& out)
123 {
124 switch(in) {
125 case GNSS_SV_TYPE_GPS:
126 out = GnssConstellationType::GPS;
127 break;
128 case GNSS_SV_TYPE_SBAS:
129 out = GnssConstellationType::SBAS;
130 break;
131 case GNSS_SV_TYPE_GLONASS:
132 out = GnssConstellationType::GLONASS;
133 break;
134 case GNSS_SV_TYPE_QZSS:
135 out = GnssConstellationType::QZSS;
136 break;
137 case GNSS_SV_TYPE_BEIDOU:
138 out = GnssConstellationType::BEIDOU;
139 break;
140 case GNSS_SV_TYPE_GALILEO:
141 out = GnssConstellationType::GALILEO;
142 break;
143 case GNSS_SV_TYPE_UNKNOWN:
144 default:
145 out = GnssConstellationType::UNKNOWN;
146 break;
147 }
148 }
149
convertGnssSvid(GnssSv & in,int16_t & out)150 void convertGnssSvid(GnssSv& in, int16_t& out)
151 {
152 switch(in.type){
153 case GNSS_SV_TYPE_GPS:
154 out = in.svId;
155 break;
156 case GNSS_SV_TYPE_SBAS:
157 out = in.svId;
158 break;
159 case GNSS_SV_TYPE_GLONASS:
160 if (!isGloSlotUnknown(in.svId)) { // OSN is known
161 out = in.svId - GLO_SV_PRN_MIN + 1;
162 } else { //OSN is not known, report FCN
163 out = in.gloFrequency + 92;
164 }
165 break;
166 case GNSS_SV_TYPE_QZSS:
167 out = in.svId;
168 break;
169 case GNSS_SV_TYPE_BEIDOU:
170 out = in.svId - BDS_SV_PRN_MIN + 1;
171 break;
172 case GNSS_SV_TYPE_GALILEO:
173 out = in.svId - GAL_SV_PRN_MIN + 1;
174 break;
175 case GNSS_SV_TYPE_NAVIC:
176 out = in.svId - NAVIC_SV_PRN_MIN + 1;
177 break;
178 default:
179 out = in.svId;
180 break;
181 }
182 }
183
convertGnssSvid(GnssMeasurementsData & in,int16_t & out)184 void convertGnssSvid(GnssMeasurementsData& in, int16_t& out)
185 {
186 switch (in.svType) {
187 case GNSS_SV_TYPE_GPS:
188 out = in.svId;
189 break;
190 case GNSS_SV_TYPE_SBAS:
191 out = in.svId;
192 break;
193 case GNSS_SV_TYPE_GLONASS:
194 if (!isGloSlotUnknown(in.svId)) { // OSN is known
195 out = in.svId - GLO_SV_PRN_MIN + 1;
196 } else { // OSN is not known, report FCN
197 out = in.gloFrequency + 92;
198 }
199 break;
200 case GNSS_SV_TYPE_QZSS:
201 out = in.svId;
202 break;
203 case GNSS_SV_TYPE_BEIDOU:
204 out = in.svId - BDS_SV_PRN_MIN + 1;
205 break;
206 case GNSS_SV_TYPE_GALILEO:
207 out = in.svId - GAL_SV_PRN_MIN + 1;
208 break;
209 case GNSS_SV_TYPE_NAVIC:
210 out = in.svId - NAVIC_SV_PRN_MIN + 1;
211 break;
212 default:
213 out = in.svId;
214 break;
215 }
216 }
217
convertGnssEphemerisType(GnssEphemerisType & in,GnssDebug::SatelliteEphemerisType & out)218 void convertGnssEphemerisType(GnssEphemerisType& in, GnssDebug::SatelliteEphemerisType& out)
219 {
220 switch(in) {
221 case GNSS_EPH_TYPE_EPHEMERIS:
222 out = GnssDebug::SatelliteEphemerisType::EPHEMERIS;
223 break;
224 case GNSS_EPH_TYPE_ALMANAC:
225 out = GnssDebug::SatelliteEphemerisType::ALMANAC_ONLY;
226 break;
227 case GNSS_EPH_TYPE_UNKNOWN:
228 default:
229 out = GnssDebug::SatelliteEphemerisType::NOT_AVAILABLE;
230 break;
231 }
232 }
233
convertGnssEphemerisSource(GnssEphemerisSource & in,GnssDebug::SatelliteEphemerisSource & out)234 void convertGnssEphemerisSource(GnssEphemerisSource& in, GnssDebug::SatelliteEphemerisSource& out)
235 {
236 switch(in) {
237 case GNSS_EPH_SOURCE_DEMODULATED:
238 out = GnssDebug::SatelliteEphemerisSource::DEMODULATED;
239 break;
240 case GNSS_EPH_SOURCE_SUPL_PROVIDED:
241 out = GnssDebug::SatelliteEphemerisSource::SUPL_PROVIDED;
242 break;
243 case GNSS_EPH_SOURCE_OTHER_SERVER_PROVIDED:
244 out = GnssDebug::SatelliteEphemerisSource::OTHER_SERVER_PROVIDED;
245 break;
246 case GNSS_EPH_SOURCE_LOCAL:
247 case GNSS_EPH_SOURCE_UNKNOWN:
248 default:
249 out = GnssDebug::SatelliteEphemerisSource::OTHER;
250 break;
251 }
252 }
253
convertGnssEphemerisHealth(GnssEphemerisHealth & in,GnssDebug::SatelliteEphemerisHealth & out)254 void convertGnssEphemerisHealth(GnssEphemerisHealth& in, GnssDebug::SatelliteEphemerisHealth& out)
255 {
256 switch(in) {
257 case GNSS_EPH_HEALTH_GOOD:
258 out = GnssDebug::SatelliteEphemerisHealth::GOOD;
259 break;
260 case GNSS_EPH_HEALTH_BAD:
261 out = GnssDebug::SatelliteEphemerisHealth::BAD;
262 break;
263 case GNSS_EPH_HEALTH_UNKNOWN:
264 default:
265 out = GnssDebug::SatelliteEphemerisHealth::UNKNOWN;
266 break;
267 }
268 }
269
270 } // namespace implementation
271 } // namespace V1_1
272 } // namespace gnss
273 } // namespace hardware
274 } // namespace android
275