• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2017, 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_0 {
36 namespace implementation {
37 
convertGnssLocation(Location & in,GnssLocation & out)38 void convertGnssLocation(Location& in, GnssLocation& out)
39 {
40     memset(&out, 0, sizeof(GnssLocation));
41     if (in.flags & LOCATION_HAS_LAT_LONG_BIT)
42         out.gnssLocationFlags |= GnssLocationFlags::HAS_LAT_LONG;
43     if (in.flags & LOCATION_HAS_ALTITUDE_BIT)
44         out.gnssLocationFlags |= GnssLocationFlags::HAS_ALTITUDE;
45     if (in.flags & LOCATION_HAS_SPEED_BIT)
46         out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED;
47     if (in.flags & LOCATION_HAS_BEARING_BIT)
48         out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING;
49     if (in.flags & LOCATION_HAS_ACCURACY_BIT)
50         out.gnssLocationFlags |= GnssLocationFlags::HAS_HORIZONTAL_ACCURACY;
51     if (in.flags & LOCATION_HAS_VERTICAL_ACCURACY_BIT)
52         out.gnssLocationFlags |= GnssLocationFlags::HAS_VERTICAL_ACCURACY;
53     if (in.flags & LOCATION_HAS_SPEED_ACCURACY_BIT)
54         out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED_ACCURACY;
55     if (in.flags & LOCATION_HAS_BEARING_ACCURACY_BIT)
56         out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING_ACCURACY;
57     out.latitudeDegrees = in.latitude;
58     out.longitudeDegrees = in.longitude;
59     out.altitudeMeters = in.altitude;
60     out.speedMetersPerSec = in.speed;
61     out.bearingDegrees = in.bearing;
62     out.horizontalAccuracyMeters = in.accuracy;
63     out.verticalAccuracyMeters = in.verticalAccuracy;
64     out.speedAccuracyMetersPerSecond = in.speedAccuracy;
65     out.bearingAccuracyDegrees = in.bearingAccuracy;
66     out.timestamp = static_cast<GnssUtcTime>(in.timestamp);
67 }
68 
convertGnssConstellationType(GnssSvType & in,GnssConstellationType & out)69 void convertGnssConstellationType(GnssSvType& in, GnssConstellationType& out)
70 {
71     switch(in) {
72         case GNSS_SV_TYPE_GPS:
73             out = GnssConstellationType::GPS;
74             break;
75         case GNSS_SV_TYPE_SBAS:
76             out = GnssConstellationType::SBAS;
77             break;
78         case GNSS_SV_TYPE_GLONASS:
79             out = GnssConstellationType::GLONASS;
80             break;
81         case GNSS_SV_TYPE_QZSS:
82             out = GnssConstellationType::QZSS;
83             break;
84         case GNSS_SV_TYPE_BEIDOU:
85             out = GnssConstellationType::BEIDOU;
86             break;
87         case GNSS_SV_TYPE_GALILEO:
88             out = GnssConstellationType::GALILEO;
89             break;
90         case GNSS_SV_TYPE_UNKNOWN:
91         default:
92             out = GnssConstellationType::UNKNOWN;
93             break;
94     }
95 }
96 
convertGnssEphemerisType(GnssEphemerisType & in,GnssDebug::SatelliteEphemerisType & out)97 void convertGnssEphemerisType(GnssEphemerisType& in, GnssDebug::SatelliteEphemerisType& out)
98 {
99     switch(in) {
100         case GNSS_EPH_TYPE_EPHEMERIS:
101             out = GnssDebug::SatelliteEphemerisType::EPHEMERIS;
102             break;
103         case GNSS_EPH_TYPE_ALMANAC:
104             out = GnssDebug::SatelliteEphemerisType::ALMANAC_ONLY;
105             break;
106         case GNSS_EPH_TYPE_UNKNOWN:
107         default:
108             out = GnssDebug::SatelliteEphemerisType::NOT_AVAILABLE;
109             break;
110     }
111 }
112 
convertGnssEphemerisSource(GnssEphemerisSource & in,GnssDebug::SatelliteEphemerisSource & out)113 void convertGnssEphemerisSource(GnssEphemerisSource& in, GnssDebug::SatelliteEphemerisSource& out)
114 {
115     switch(in) {
116         case GNSS_EPH_SOURCE_DEMODULATED:
117             out = GnssDebug::SatelliteEphemerisSource::DEMODULATED;
118             break;
119         case GNSS_EPH_SOURCE_SUPL_PROVIDED:
120             out = GnssDebug::SatelliteEphemerisSource::SUPL_PROVIDED;
121             break;
122         case GNSS_EPH_SOURCE_OTHER_SERVER_PROVIDED:
123             out = GnssDebug::SatelliteEphemerisSource::OTHER_SERVER_PROVIDED;
124             break;
125         case GNSS_EPH_SOURCE_LOCAL:
126         case GNSS_EPH_SOURCE_UNKNOWN:
127         default:
128             out = GnssDebug::SatelliteEphemerisSource::OTHER;
129             break;
130     }
131 }
132 
convertGnssEphemerisHealth(GnssEphemerisHealth & in,GnssDebug::SatelliteEphemerisHealth & out)133 void convertGnssEphemerisHealth(GnssEphemerisHealth& in, GnssDebug::SatelliteEphemerisHealth& out)
134 {
135     switch(in) {
136         case GNSS_EPH_HEALTH_GOOD:
137             out = GnssDebug::SatelliteEphemerisHealth::GOOD;
138             break;
139         case GNSS_EPH_HEALTH_BAD:
140             out = GnssDebug::SatelliteEphemerisHealth::BAD;
141             break;
142         case GNSS_EPH_HEALTH_UNKNOWN:
143         default:
144             out = GnssDebug::SatelliteEphemerisHealth::UNKNOWN;
145             break;
146     }
147 }
148 
149 }  // namespace implementation
150 }  // namespace V1_0
151 }  // namespace gnss
152 }  // namespace hardware
153 }  // namespace android
154