-
Notifications
You must be signed in to change notification settings - Fork 0
/
GnssAntennaInfo.cpp
149 lines (129 loc) · 6.01 KB
/
GnssAntennaInfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "GnssAntennaInfoAidl"
#include "GnssAntennaInfo.h"
#include <aidl/android/hardware/gnss/BnGnss.h>
#include <log/log.h>
#include "Utils.h"
namespace aidl::android::hardware::gnss {
using namespace ::android::hardware::gnss;
using Row = IGnssAntennaInfoCallback::Row;
using Coord = IGnssAntennaInfoCallback::Coord;
std::shared_ptr<IGnssAntennaInfoCallback> GnssAntennaInfo::sCallback = nullptr;
GnssAntennaInfo::GnssAntennaInfo() : mMinIntervalMs(1000) {}
GnssAntennaInfo::~GnssAntennaInfo() {
stop();
}
// Methods from ::android::hardware::gnss::V2_1::IGnssAntennaInfo follow.
ndk::ScopedAStatus GnssAntennaInfo::setCallback(
const std::shared_ptr<IGnssAntennaInfoCallback>& callback) {
ALOGD("setCallback");
std::unique_lock<std::mutex> lock(mMutex);
sCallback = callback;
if (mIsActive) {
ALOGW("GnssAntennaInfo callback already set. Resetting the callback...");
stop();
}
start();
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus GnssAntennaInfo::close() {
ALOGD("close");
stop();
std::unique_lock<std::mutex> lock(mMutex);
sCallback = nullptr;
return ndk::ScopedAStatus::ok();
}
void GnssAntennaInfo::start() {
ALOGD("start");
mIsActive = true;
mThread = std::thread([this]() {
while (mIsActive == true) {
if (sCallback != nullptr) {
IGnssAntennaInfoCallback::GnssAntennaInfo mockAntennaInfo_1 = {
.carrierFrequencyHz = 1575420000,
.phaseCenterOffsetCoordinateMillimeters = Coord{.x = 1,
.xUncertainty = 0.1,
.y = 2,
.yUncertainty = 0.1,
.z = 3,
.zUncertainty = 0.1},
.phaseCenterVariationCorrectionMillimeters =
{
Row{std::vector<double>{1, -1, 5, -2, 3, -1}},
Row{std::vector<double>{-2, 3, 2, 0, 1, 2}},
Row{std::vector<double>{1, 3, 2, -1, -3, 5}},
},
.phaseCenterVariationCorrectionUncertaintyMillimeters =
{
Row{std::vector<double>{0.1, 0.2, 0.4, 0.1, 0.2, 0.3}},
Row{std::vector<double>{0.3, 0.2, 0.3, 0.6, 0.1, 0.1}},
Row{std::vector<double>{0.1, 0.1, 0.4, 0.2, 0.5, 0.3}},
},
.signalGainCorrectionDbi =
{
Row{std::vector<double>{2, -3, 1, -3, 0, -4}},
Row{std::vector<double>{1, 0, -4, 1, 3, -2}},
Row{std::vector<double>{3, -2, 0, -2, 3, 0}},
},
.signalGainCorrectionUncertaintyDbi =
{
Row{std::vector<double>{0.3, 0.1, 0.2, 0.6, 0.1, 0.3}},
Row{std::vector<double>{0.1, 0.1, 0.5, 0.2, 0.3, 0.1}},
Row{std::vector<double>{0.2, 0.4, 0.2, 0.1, 0.1, 0.2}},
},
};
IGnssAntennaInfoCallback::GnssAntennaInfo mockAntennaInfo_2 = {
.carrierFrequencyHz = 1176450000,
.phaseCenterOffsetCoordinateMillimeters = Coord{.x = 5,
.xUncertainty = 0.1,
.y = 6,
.yUncertainty = 0.1,
.z = 7,
.zUncertainty = 0.1},
};
std::vector<IGnssAntennaInfoCallback::GnssAntennaInfo> mockAntennaInfos = {
mockAntennaInfo_1,
mockAntennaInfo_2,
};
this->reportAntennaInfo(mockAntennaInfos);
}
/** For mock implementation this is good. On real device, we should only report
antennaInfo at start and when there is a configuration change. **/
std::this_thread::sleep_for(std::chrono::milliseconds(mMinIntervalMs));
}
});
}
void GnssAntennaInfo::stop() {
ALOGD("stop");
mIsActive = false;
if (mThread.joinable()) {
mThread.join();
}
}
void GnssAntennaInfo::reportAntennaInfo(
const std::vector<IGnssAntennaInfoCallback::GnssAntennaInfo>& antennaInfo) const {
std::unique_lock<std::mutex> lock(mMutex);
if (sCallback == nullptr) {
ALOGE("%s: No non-null callback", __func__);
return;
}
auto ret = sCallback->gnssAntennaInfoCb(antennaInfo);
if (!ret.isOk()) {
ALOGE("%s: Unable to invoke callback", __func__);
}
}
} // namespace aidl::android::hardware::gnss