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
convertGnssEphemerisType(GnssEphemerisType & in,GnssDebug::SatelliteEphemerisType & out)150 void convertGnssEphemerisType(GnssEphemerisType& in, GnssDebug::SatelliteEphemerisType& out)
151 {
152 switch(in) {
153 case GNSS_EPH_TYPE_EPHEMERIS:
154 out = GnssDebug::SatelliteEphemerisType::EPHEMERIS;
155 break;
156 case GNSS_EPH_TYPE_ALMANAC:
157 out = GnssDebug::SatelliteEphemerisType::ALMANAC_ONLY;
158 break;
159 case GNSS_EPH_TYPE_UNKNOWN:
160 default:
161 out = GnssDebug::SatelliteEphemerisType::NOT_AVAILABLE;
162 break;
163 }
164 }
165
convertGnssEphemerisSource(GnssEphemerisSource & in,GnssDebug::SatelliteEphemerisSource & out)166 void convertGnssEphemerisSource(GnssEphemerisSource& in, GnssDebug::SatelliteEphemerisSource& out)
167 {
168 switch(in) {
169 case GNSS_EPH_SOURCE_DEMODULATED:
170 out = GnssDebug::SatelliteEphemerisSource::DEMODULATED;
171 break;
172 case GNSS_EPH_SOURCE_SUPL_PROVIDED:
173 out = GnssDebug::SatelliteEphemerisSource::SUPL_PROVIDED;
174 break;
175 case GNSS_EPH_SOURCE_OTHER_SERVER_PROVIDED:
176 out = GnssDebug::SatelliteEphemerisSource::OTHER_SERVER_PROVIDED;
177 break;
178 case GNSS_EPH_SOURCE_LOCAL:
179 case GNSS_EPH_SOURCE_UNKNOWN:
180 default:
181 out = GnssDebug::SatelliteEphemerisSource::OTHER;
182 break;
183 }
184 }
185
convertGnssEphemerisHealth(GnssEphemerisHealth & in,GnssDebug::SatelliteEphemerisHealth & out)186 void convertGnssEphemerisHealth(GnssEphemerisHealth& in, GnssDebug::SatelliteEphemerisHealth& out)
187 {
188 switch(in) {
189 case GNSS_EPH_HEALTH_GOOD:
190 out = GnssDebug::SatelliteEphemerisHealth::GOOD;
191 break;
192 case GNSS_EPH_HEALTH_BAD:
193 out = GnssDebug::SatelliteEphemerisHealth::BAD;
194 break;
195 case GNSS_EPH_HEALTH_UNKNOWN:
196 default:
197 out = GnssDebug::SatelliteEphemerisHealth::UNKNOWN;
198 break;
199 }
200 }
201
202 } // namespace implementation
203 } // namespace V1_1
204 } // namespace gnss
205 } // namespace hardware
206 } // namespace android
207