11 #include <boost/bind/bind.hpp>
24 if(serverVersion == 0) {
25 return std::make_unique<RebotProtocol0>(c);
27 if(serverVersion == 1) {
28 return std::make_unique<RebotProtocol1>(c);
31 std::stringstream errorMessage;
32 errorMessage <<
"Server protocol version " << serverVersion <<
" not supported!";
39 std::vector<uint32_t> clientHelloMessage;
40 clientHelloMessage.push_back(Rebot::HELLO_TOKEN);
41 clientHelloMessage.push_back(Rebot::MAGIC_WORD);
42 clientHelloMessage.push_back(Rebot::CLIENT_PROTOCOL_VERSION);
44 c->write(clientHelloMessage);
50 auto serverHello = c->read(1);
52 if(serverHello.at(0) ==
static_cast<uint32_t
>(Rebot::UNKNOWN_INSTRUCTION)) {
56 auto remainingBytesOfAValidServerHello = c->read(Rebot::LENGTH_OF_HELLO_TOKEN_MESSAGE - 1);
59 serverHello.end(), remainingBytesOfAValidServerHello.begin(), remainingBytesOfAValidServerHello.end());
65 return serverHello.at(2);
69 std::string boardAddr, std::string port,
const std::string& mapFileName, uint32_t connectionTimeout_sec)
72 _connection(boost::make_shared<Rebot::
Connection>(_boardAddr, _port, connectionTimeout_sec)),
73 _lastSendTime(testable_rebot_sleep::
now()), _connectionTimeout(Rebot::DEFAULT_CONNECTION_TIMEOUT),
89 catch(boost::system::system_error&) {
140 std::string , std::map<std::string, std::string> parameters) {
142 if(parameters[
"ip"].empty()) {
145 if(parameters[
"port"].empty()) {
149 std::string tmcbIP = parameters[
"ip"];
150 std::string portNumber = parameters[
"port"];
151 std::string mapFileName = parameters[
"map"];
154 auto it = parameters.find(
"timeout");
155 if(it != parameters.end()) {
156 timeout =
static_cast<uint32_t
>(std::stoul(it->second));
158 return boost::shared_ptr<RebotBackend>(
new RebotBackend(tmcbIP, portNumber, mapFileName, timeout));
170 boost::chrono::steady_clock::time_point wakeupTime;
178 if(threadInformerMutex->quitThread) {
196 setException(std::string(
"RebotBackend: Sending heartbeat failed. Caught exception: ") + e.
what());