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 #include <chrono>
19 #include <optional>
20 #include <vector>
21 
22 #include <aidl/android/hardware/gnss/ElapsedRealtime.h>
23 
24 #include "IDataSink.h"
25 
26 namespace aidl {
27 namespace android {
28 namespace hardware {
29 namespace gnss {
30 namespace implementation {
31 
32 class GnssHwListener {
33 public:
34     explicit GnssHwListener(IDataSink& sink);
35     ~GnssHwListener();
36 
37     void consume(const char* buf, size_t sz);
38 
39 private:
40     void consume1(char);
41 
42     bool parse(const char* begin, const char* end,
43                const int64_t timestampMs,
44                const ElapsedRealtime& ert);
45     bool parseGPRMC(const char* begin, const char* end,
46                     const int64_t timestampMs,
47                     const ElapsedRealtime& ert);
48     bool parseGPGGA(const char* begin, const char* end,
49                     const int64_t timestampMs,
50                     const ElapsedRealtime& ert);
51 
52     IDataSink&              mSink;
53     std::vector<char>       mBuffer;
54     std::optional<double>   mAltitude;
55 };
56 
57 }  // namespace implementation
58 }  // namespace gnss
59 }  // namespace hardware
60 }  // namespace android
61 }  // namespace aidl
62