blob: fb2c1a4491319435821bb5dc57520942956d3f98 [file] [log] [blame]
Yipeng Cao48618f62020-03-19 18:11:16 -07001/*
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>
25namespace android {
26namespace hardware {
27namespace gnss {
28namespace common {
29using ::android::sp;
30using ::android::hardware::hidl_string;
31using ::android::hardware::hidl_vec;
32using ::android::hardware::Return;
33using ::android::hardware::Void;
34
35constexpr char GPGA_RECORD_TAG[] = "$GPGGA";
36constexpr char GPRMC_RECORD_TAG[] = "$GPRMC";
37constexpr char LINE_SEPARATOR = '\n';
38constexpr char COMMA_SEPARATOR = ',';
39constexpr double TIMESTAMP_EPSILON = 0.001;
40
41/** Helper class to parse and store the GNSS fix details information. */
42class NmeaFixInfo {
43 private:
44 float altitudeMeters;
45 float bearingDegrees;
46 uint32_t fixId;
47 bool hasGMCRecord;
48 bool hasGGARecord;
49 float hDop;
50 float vDop;
51 float latDeg;
52 float lngDeg;
53 uint32_t satelliteCount;
54 float speedMetersPerSec;
55 int64_t timestamp;
56
57 public:
58 static std::unique_ptr<V2_0::GnssLocation> getLocationFromInputStr(const std::string& inputStr);
59
60 private:
61 static void splitStr(const std::string& line, const char& delimiter,
62 std::vector<std::string>& out);
63 static float checkAndConvertToFloat(const std::string& sentence);
64 static int64_t nmeaPartsToTimestamp(const std::string& timeStr, const std::string& dateStr);
65
66 NmeaFixInfo();
67 void parseGGALine(const std::vector<std::string>& sentenceValues);
68 void parseRMCLine(const std::vector<std::string>& sentenceValues);
69 std::unique_ptr<V2_0::GnssLocation> toGnssLocation() const;
70
71 // Getters
72 float getAltitudeMeters() const;
73 float getBearingAccuracyDegrees() const;
74 float getBearingDegrees() const;
75 uint32_t getFixId() const;
76 float getHorizontalAccuracyMeters() const;
77 float getLatDeg() const;
78 float getLngDeg() const;
79 float getSpeedAccuracyMetersPerSecond() const;
80 float getSpeedMetersPerSec() const;
81 int64_t getTimestamp() const;
82 float getVerticalAccuracyMeters() const;
83
84 bool isValidFix() const;
85 void reset();
86 NmeaFixInfo& operator=(const NmeaFixInfo& rhs);
87};
88
89} // namespace common
90} // namespace gnss
91} // namespace hardware
92} // namespace android