• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 #pragma once
18 
19 #include <Constants.h>
20 #include <android/hardware/gnss/1.0/IGnss.h>
21 #include <android/hardware/gnss/2.0/IGnss.h>
22 #include <hidl/Status.h>
23 #include <ctime>
24 #include <string>
25 #include "aidl/android/hardware/gnss/IGnss.h"
26 namespace android {
27 namespace hardware {
28 namespace gnss {
29 namespace common {
30 
31 /** Helper class to parse and store the GNSS fix details information. */
32 class NmeaFixInfo {
33   private:
34     float altitudeMeters;
35     float bearingDegrees;
36     uint32_t fixId;
37     bool hasGMCRecord;
38     bool hasGGARecord;
39     float hDop;
40     float vDop;
41     float latDeg;
42     float lngDeg;
43     uint32_t satelliteCount;
44     float speedMetersPerSec;
45     int64_t timestamp;
46 
47   public:
48     static std::unique_ptr<V2_0::GnssLocation> getLocationFromInputStr(const std::string& inputStr);
49     static std::unique_ptr<aidl::android::hardware::gnss::GnssLocation> getAidlLocationFromInputStr(
50             const std::string& inputStr);
51 
52   private:
53     static void splitStr(const std::string& line, const char& delimiter,
54                          std::vector<std::string>& out);
55     static float checkAndConvertToFloat(const std::string& sentence);
56     static int64_t nmeaPartsToTimestamp(const std::string& timeStr, const std::string& dateStr);
57 
58     NmeaFixInfo();
59     void parseGGALine(const std::vector<std::string>& sentenceValues);
60     void parseRMCLine(const std::vector<std::string>& sentenceValues);
61     std::unique_ptr<V2_0::GnssLocation> toGnssLocation() const;
62 
63     // Getters
64     float getAltitudeMeters() const;
65     float getBearingAccuracyDegrees() const;
66     float getBearingDegrees() const;
67     uint32_t getFixId() const;
68     float getHorizontalAccuracyMeters() const;
69     float getLatDeg() const;
70     float getLngDeg() const;
71     float getSpeedAccuracyMetersPerSecond() const;
72     float getSpeedMetersPerSec() const;
73     int64_t getTimestamp() const;
74     float getVerticalAccuracyMeters() const;
75 
76     bool isValidFix() const;
77     void reset();
78     NmeaFixInfo& operator=(const NmeaFixInfo& rhs);
79 };
80 
81 }  // namespace common
82 }  // namespace gnss
83 }  // namespace hardware
84 }  // namespace android