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