-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathunix_simulator_backend.cpp
76 lines (61 loc) · 2.89 KB
/
unix_simulator_backend.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
#include "software/backend/unix_simulator_backend.h"
#include "proto/message_translation/ssl_wrapper.h"
#include "proto/message_translation/tbots_protobuf.h"
#include "proto/parameters.pb.h"
#include "proto/robot_log_msg.pb.h"
#include "proto/sensor_msg.pb.h"
#include "shared/constants.h"
#include "software/constants.h"
#include "software/logger/logger.h"
#include "software/util/generic_factory/generic_factory.h"
UnixSimulatorBackend::UnixSimulatorBackend(std::string runtime_dir)
{
// Protobuf Inputs
robot_status_input.reset(new ThreadedProtoUnixListener<TbotsProto::RobotStatus>(
runtime_dir + ROBOT_STATUS_PATH,
boost::bind(&Backend::receiveRobotStatus, this, _1)));
ssl_wrapper_input.reset(new ThreadedProtoUnixListener<SSLProto::SSL_WrapperPacket>(
runtime_dir + SSL_WRAPPER_PATH,
boost::bind(&Backend::receiveSSLWrapperPacket, this, _1)));
ssl_referee_input.reset(new ThreadedProtoUnixListener<SSLProto::Referee>(
runtime_dir + SSL_REFEREE_PATH,
boost::bind(&Backend::receiveSSLReferee, this, _1)));
sensor_proto_input.reset(new ThreadedProtoUnixListener<SensorProto>(
runtime_dir + SENSOR_PROTO_PATH,
boost::bind(&Backend::receiveSensorProto, this, _1)));
dynamic_parameter_update_request_listener.reset(
new ThreadedProtoUnixListener<TbotsProto::ThunderbotsConfig>(
runtime_dir + DYNAMIC_PARAMETER_UPDATE_REQUEST_PATH,
boost::bind(&UnixSimulatorBackend::receiveThunderbotsConfig, this, _1)));
// Protobuf Outputs
world_output.reset(
new ThreadedProtoUnixSender<TbotsProto::World>(runtime_dir + WORLD_PATH));
primitive_output.reset(new ThreadedProtoUnixSender<TbotsProto::PrimitiveSet>(
runtime_dir + PRIMITIVE_PATH));
dynamic_parameter_update_respone_sender.reset(
new ThreadedProtoUnixSender<TbotsProto::ThunderbotsConfig>(
runtime_dir + DYNAMIC_PARAMETER_UPDATE_RESPONSE_PATH));
}
void UnixSimulatorBackend::receiveThunderbotsConfig(TbotsProto::ThunderbotsConfig request)
{
// Send new config to all observers
Subject<TbotsProto::ThunderbotsConfig>::sendValueToObservers(request);
// Echo back the request as an acknowledge
dynamic_parameter_update_respone_sender->sendProto(request);
}
void UnixSimulatorBackend::onValueReceived(TbotsProto::PrimitiveSet primitives)
{
primitive_output->sendProto(primitives);
LOG(VISUALIZE) << *createNamedValue(
"Primitive Hz",
static_cast<float>(FirstInFirstOutThreadedObserver<
TbotsProto::PrimitiveSet>::getDataReceivedPerSecond()));
}
void UnixSimulatorBackend::onValueReceived(World world)
{
world_output->sendProto(*createWorldWithSequenceNumber(world, sequence_number++));
LOG(VISUALIZE) << *createNamedValue(
"World Hz",
static_cast<float>(
FirstInFirstOutThreadedObserver<World>::getDataReceivedPerSecond()));
}