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 { |
| 29 | using ::android::sp; |
| 30 | using ::android::hardware::hidl_string; |
| 31 | using ::android::hardware::hidl_vec; |
| 32 | using ::android::hardware::Return; |
| 33 | using ::android::hardware::Void; |
| 34 | |
| 35 | constexpr char GPGA_RECORD_TAG[] = "$GPGGA"; |
| 36 | constexpr char GPRMC_RECORD_TAG[] = "$GPRMC"; |
| 37 | constexpr char LINE_SEPARATOR = '\n'; |
| 38 | constexpr char COMMA_SEPARATOR = ','; |
| 39 | constexpr double TIMESTAMP_EPSILON = 0.001; |
| 40 | |
| 41 | /** Helper class to parse and store the GNSS fix details information. */ |
| 42 | class 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 |