ecos: simulation improvements
Dieser Commit ist enthalten in:
Ursprung
ab925013b6
Commit
7a07f7da88
@ -23,6 +23,7 @@
|
||||
#include "simulationiohandler.hpp"
|
||||
#include "../kernel.hpp"
|
||||
#include "../messages.hpp"
|
||||
#include "../../../../utils/rtrim.hpp"
|
||||
|
||||
namespace ECoS {
|
||||
|
||||
@ -39,7 +40,7 @@ bool SimulationIOHandler::send(std::string_view message)
|
||||
|
||||
if(request.command == Command::request && request.options.size() == 1 && request.options[0] == Option::view)
|
||||
{
|
||||
return reply(std::string("<REPLY ").append(message).append(">\r\n<END 0 (OK)>\r\n"));
|
||||
return replyOk(message); // notify view active
|
||||
}
|
||||
|
||||
if(request.objectId == ObjectId::ecos)
|
||||
@ -54,6 +55,40 @@ bool SimulationIOHandler::send(std::string_view message)
|
||||
"1 HardwareVersion[2.0]\r\n"
|
||||
"<END 0 (OK)>\r\n");
|
||||
}
|
||||
if(request.command == Command::set && request.options.size() == 1 && (request.options[0] == Option::stop || request.options[0] == Option::go))
|
||||
{
|
||||
return replyOk(message);
|
||||
}
|
||||
}
|
||||
else if(request.objectId == ObjectId::locomotiveManager)
|
||||
{
|
||||
if(request.command == Command::queryObjects)
|
||||
{
|
||||
return replyOk(message); // empty list for now
|
||||
}
|
||||
}
|
||||
else if(request.objectId == ObjectId::switchManager)
|
||||
{
|
||||
if(request.command == Command::set && request.options.size() == 1)
|
||||
{
|
||||
std::string_view option;
|
||||
std::string_view value;
|
||||
if(parseOptionValue(request.options[0], option, value) && option == Option::switch_)
|
||||
{
|
||||
return replyOk(message); // notify executed
|
||||
}
|
||||
}
|
||||
else if(request.command == Command::queryObjects)
|
||||
{
|
||||
return replyOk(message); // empty list for now
|
||||
}
|
||||
}
|
||||
else if(request.objectId == ObjectId::feedbackManager)
|
||||
{
|
||||
if(request.command == Command::queryObjects)
|
||||
{
|
||||
return replyOk(message); // empty list for now
|
||||
}
|
||||
}
|
||||
|
||||
return reply(std::string("<REPLY ").append(message).append(">\r\n<END 999 (Traintastic: no simulation support)>\r\n"));
|
||||
@ -71,4 +106,9 @@ bool SimulationIOHandler::reply(std::string_view message)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SimulationIOHandler::replyOk(std::string_view request)
|
||||
{
|
||||
return reply(std::string("<REPLY ").append(rtrim(request, {'\r', '\n'})).append(">\r\n<END 0 (OK)>\r\n"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -33,6 +33,7 @@ class SimulationIOHandler final : public IOHandler
|
||||
{
|
||||
private:
|
||||
bool reply(std::string_view message);
|
||||
bool replyOk(std::string_view request);
|
||||
|
||||
public:
|
||||
SimulationIOHandler(Kernel& kernel);
|
||||
|
||||
@ -266,4 +266,14 @@ bool parseLine(std::string_view text, Line& line)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseOptionValue(std::string_view text, std::string_view& option, std::string_view& value)
|
||||
{
|
||||
auto n = text.find('[');
|
||||
if(n == std::string_view::npos || *text.rbegin() != ']')
|
||||
return false;
|
||||
option = text.substr(0, n);
|
||||
value = text.substr(n + 1, text.size() - (n + 2));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -209,6 +209,8 @@ bool parseEvent(std::string_view message, Event& event);
|
||||
bool parseId(std::string_view line, uint16_t& id);
|
||||
bool parseLine(std::string_view text, Line& line);
|
||||
|
||||
bool parseOptionValue(std::string_view text, std::string_view& option, std::string_view& value);
|
||||
|
||||
constexpr bool isS88FeedbackId(uint16_t id)
|
||||
{
|
||||
return id >= ObjectId::s88 && id < ObjectId::ecosDetector;
|
||||
|
||||
@ -43,13 +43,11 @@ bool Object::receiveReply(const Reply& reply)
|
||||
}
|
||||
else if(reply.command == Command::set && reply.status == Status::Ok)
|
||||
{
|
||||
std::string_view key;
|
||||
std::string_view value;
|
||||
for(auto option : reply.options)
|
||||
{
|
||||
auto n = option.find('[');
|
||||
if(n == std::string_view::npos || *option.rbegin() != ']')
|
||||
continue;
|
||||
update(option.substr(0, n), option.substr(n + 1, option.size() - (n + 2)));
|
||||
}
|
||||
if(parseOptionValue(option, key, value))
|
||||
update(key, value);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren