Yipeng Cao | 48618f6 | 2020-03-19 18:11:16 -0700 | [diff] [blame] | 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 | namespace android { |
| 26 | namespace hardware { |
| 27 | namespace gnss { |
| 28 | namespace common { |
Yipeng Cao | 48618f6 | 2020-03-19 18:11:16 -0700 | [diff] [blame] | 29 | |
Yipeng Cao | 48618f6 | 2020-03-19 18:11:16 -0700 | [diff] [blame] | 30 | /** Helper class to parse and store the GNSS fix details information. */ |
| 31 | class NmeaFixInfo { |
| 32 | private: |
| 33 | float altitudeMeters; |
| 34 | float bearingDegrees; |
| 35 | uint32_t fixId; |
| 36 | bool hasGMCRecord; |
| 37 | bool hasGGARecord; |
| 38 | float hDop; |
| 39 | float vDop; |
| 40 | float latDeg; |
| 41 | float lngDeg; |
| 42 | uint32_t satelliteCount; |
| 43 | float speedMetersPerSec; |
| 44 | int64_t timestamp; |
| 45 | |
| 46 | public: |
| 47 | static std::unique_ptr<V2_0::GnssLocation> getLocationFromInputStr(const std::string& inputStr); |
| 48 | |
| 49 | private: |
| 50 | static void splitStr(const std::string& line, const char& delimiter, |
| 51 | std::vector<std::string>& out); |
| 52 | static float checkAndConvertToFloat(const std::string& sentence); |
| 53 | static int64_t nmeaPartsToTimestamp(const std::string& timeStr, const std::string& dateStr); |
| 54 | |
| 55 | NmeaFixInfo(); |
| 56 | void parseGGALine(const std::vector<std::string>& sentenceValues); |
| 57 | void parseRMCLine(const std::vector<std::string>& sentenceValues); |
| 58 | std::unique_ptr<V2_0::GnssLocation> toGnssLocation() const; |
| 59 | |
| 60 | // Getters |
| 61 | float getAltitudeMeters() const; |
| 62 | float getBearingAccuracyDegrees() const; |
| 63 | float getBearingDegrees() const; |
| 64 | uint32_t getFixId() const; |
| 65 | float getHorizontalAccuracyMeters() const; |
| 66 | float getLatDeg() const; |
| 67 | float getLngDeg() const; |
| 68 | float getSpeedAccuracyMetersPerSecond() const; |
| 69 | float getSpeedMetersPerSec() const; |
| 70 | int64_t getTimestamp() const; |
| 71 | float getVerticalAccuracyMeters() const; |
| 72 | |
| 73 | bool isValidFix() const; |
| 74 | void reset(); |
| 75 | NmeaFixInfo& operator=(const NmeaFixInfo& rhs); |
| 76 | }; |
| 77 | |
| 78 | } // namespace common |
| 79 | } // namespace gnss |
| 80 | } // namespace hardware |
| 81 | } // namespace android |