-
Notifications
You must be signed in to change notification settings - Fork 0
/
opendlv-logic-microservice.cpp
58 lines (45 loc) · 1.5 KB
/
opendlv-logic-microservice.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
/*
* Copyright (C) 2024 OpenDLV
*/
#include <cmath>
#include <cstdint>
#include <iostream>
#include "cluon-complete.hpp"
#include "opendlv-message-standard.hpp"
int32_t main(int32_t argc, char **argv)
{
auto cmd = cluon::getCommandlineArguments(argc, argv);
if (!cmd.contains("cid")) {
std::cout << argv[0] << " is an OpenDLV microservice." << std::endl;
std::cout << "Usage: " << argv[0] << " "
<< "--cid=<conference id; e.g. 111> "
<< "[--verbose] " << std::endl;
return 0;
}
uint16_t const cid = std::stoi(cmd.at("cid"));
bool const verbose = (cmd.count("verbose") != 0);
if (verbose) {
std::cout << "Starting microservice." << std::endl;
}
cluon::OD4Session od4(cid);
auto onGroundSpeedRequest{[&verbose, &od4](cluon::data::Envelope &&envelope) {
auto const gsr = cluon::extractMessage<opendlv::proxy::GroundSpeedRequest>(
std::move(envelope));
float speed = gsr.groundSpeed();
if (verbose) {
std::cout << "Got ground speed reading " << speed << std::endl;
}
opendlv::proxy::GroundSpeedReading gsrReading;
gsrReading.groundSpeed(speed * 0.5f);
od4.send(gsrReading);
}};
od4.dataTrigger(
opendlv::proxy::GroundSpeedRequest::ID(), onGroundSpeedRequest);
while (od4.isRunning()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
if (verbose) {
std::cout << "Closing microservice." << std::endl;
}
return 0;
}