• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "FixLocationParser.h"
18 
19 namespace android {
20 namespace hardware {
21 namespace gnss {
22 namespace common {
23 
24 using aidl::android::hardware::gnss::ElapsedRealtime;
25 using aidl::android::hardware::gnss::GnssLocation;
26 
getLocationFromInputStr(const std::string & locationStr)27 std::unique_ptr<GnssLocation> FixLocationParser::getLocationFromInputStr(
28         const std::string& locationStr) {
29     /*
30      * Fix,Provider,LatitudeDegrees,LongitudeDegrees,AltitudeMeters,SpeedMps,
31      * AccuracyMeters,BearingDegrees,UnixTimeMillis,SpeedAccuracyMps,BearingAccuracyDegrees,
32      * elapsedRealtimeNanos
33      */
34     if (locationStr.empty()) {
35         return nullptr;
36     }
37     std::vector<std::string> locationStrRecords;
38     ParseUtils::splitStr(locationStr, LINE_SEPARATOR, locationStrRecords);
39     if (locationStrRecords.empty()) {
40         return nullptr;
41     }
42 
43     std::vector<std::string> locationValues;
44     ParseUtils::splitStr(locationStrRecords[0], COMMA_SEPARATOR, locationValues);
45     if (locationValues.size() < 12) {
46         return nullptr;
47     }
48     ElapsedRealtime elapsedRealtime = {
49             .flags = ElapsedRealtime::HAS_TIMESTAMP_NS | ElapsedRealtime::HAS_TIME_UNCERTAINTY_NS,
50             .timestampNs = ::android::elapsedRealtimeNano(),
51             // This is an hardcoded value indicating a 1ms of uncertainty between the two clocks.
52             // In an actual implementation provide an estimate of the synchronization uncertainty
53             // or don't set the field.
54             .timeUncertaintyNs = 1020400};
55 
56     GnssLocation location = {
57             .gnssLocationFlags = 0xFF,
58             .latitudeDegrees = ParseUtils::tryParseDouble(locationValues[2], 0),
59             .longitudeDegrees = ParseUtils::tryParseDouble(locationValues[3], 0),
60             .altitudeMeters = ParseUtils::tryParseDouble(locationValues[4], 0),
61             .speedMetersPerSec = ParseUtils::tryParseDouble(locationValues[5], 0),
62             .bearingDegrees = ParseUtils::tryParseDouble(locationValues[7], 0),
63             .horizontalAccuracyMeters = ParseUtils::tryParseDouble(locationValues[6], 0),
64             .verticalAccuracyMeters = ParseUtils::tryParseDouble(locationValues[6], 0),
65             .speedAccuracyMetersPerSecond = ParseUtils::tryParseDouble(locationValues[9], 0),
66             .bearingAccuracyDegrees = ParseUtils::tryParseDouble(locationValues[10], 0),
67             .timestampMillis = ParseUtils::tryParseLongLong(locationValues[8], 0),
68             .elapsedRealtime = elapsedRealtime};
69     return std::make_unique<GnssLocation>(location);
70 }
71 
72 }  // namespace common
73 }  // namespace gnss
74 }  // namespace hardware
75 }  // namespace android