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
|
/* Copyright (C) 2014 Mentor Graphics
* Author: Marco Residori(marco_residori@mentor.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <CommonAPI/CommonAPI.hpp>
#include <org/genivi/EnhancedPositionService/EnhancedPositionProxy.hpp>
#include "log.h"
#include <unistd.h>
DLT_DECLARE_CONTEXT(gCtx);
using namespace org::genivi::EnhancedPositionService;
void getPositionInfoAsyncCallback(const CommonAPI::CallStatus& callStatus, const EnhancedPositionServiceTypes::Timestamp& timestamp, const EnhancedPositionServiceTypes::PositionInfo& posInfo)
{
if (callStatus != CommonAPI::CallStatus::SUCCESS) {
LOG_ERROR_MSG(gCtx,"Remote call failed!\n");
return;
}
for ( auto it = posInfo.begin(); it != posInfo.end(); ++it ) {
if (it->first == EnhancedPositionServiceTypes::PositionInfoKey::LATITUDE)
{
LOG_INFO(gCtx,"LAT=%lf", it->second.get<double>());
}
if (it->first == EnhancedPositionServiceTypes::PositionInfoKey::LONGITUDE)
{
LOG_INFO(gCtx,"LON=%lf", it->second.get<double>());
}
if (it->first == EnhancedPositionServiceTypes::PositionInfoKey::ALTITUDE)
{
LOG_INFO(gCtx,"ALT=%lf", it->second.get<float>());
}
if (it->first == EnhancedPositionServiceTypes::PositionInfoKey::SPEED)
{
LOG_INFO(gCtx,"SPEED=%lf", it->second.get<float>());
}
if (it->first == EnhancedPositionServiceTypes::PositionInfoKey::CLIMB)
{
LOG_INFO(gCtx,"CLIMB=%lf", it->second.get<float>());
}
if (it->first == EnhancedPositionServiceTypes::PositionInfoKey::HEADING)
{
LOG_INFO(gCtx,"HEADING=%lf", it->second.get<float>());
}
}
}
void positionUpdate(std::shared_ptr<EnhancedPositionProxyDefault> proxy, const EnhancedPositionServiceTypes::Bitmask& changedValues)
{
LOG_INFO_MSG(gCtx,"Position Update");
if(proxy == NULL)
{
LOG_ERROR_MSG(gCtx,"Null pointer!");
return;
}
std::function<void(const CommonAPI::CallStatus&,
const EnhancedPositionServiceTypes::Timestamp&,
const EnhancedPositionServiceTypes::PositionInfo&)> fcb = getPositionInfoAsyncCallback;
proxy->GetPositionInfoAsync(changedValues,getPositionInfoAsyncCallback);
}
int main() {
DLT_REGISTER_APP("ENHC","ENHANCED-POSITION-CLIENT");
DLT_REGISTER_CONTEXT(gCtx,"ENHC","Global Context");
std::shared_ptr < CommonAPI::Runtime > runtime = CommonAPI::Runtime::get();
const std::string &domain = "local";
const std::string &instance = "EnhancedPositionService";
std::shared_ptr<EnhancedPositionProxyDefault> myProxy = runtime->buildProxy<EnhancedPositionProxy>(domain,instance);
LOG_INFO_MSG(gCtx,"EnhancedPositionClient");
while (!myProxy->isAvailable()) {
usleep(10);
}
myProxy->getPositionUpdateEvent().subscribe([&](const EnhancedPositionServiceTypes::Bitmask& changedValues) {
positionUpdate(myProxy, changedValues);
});
while (true) {
std::this_thread::sleep_for(std::chrono::seconds(5));
}
return 0;
}
|