8 #include <boost/asio.hpp>
9 #include <boost/bind/bind.hpp>
19 unsigned int protocolVersion, ip::tcp::socket socket, std::shared_ptr<DummyBackend> registerSpace)
20 : _state(ACCEPT_NEW_COMMAND), _heartbeatCount(0), _helloCount(0), _dont_answer(false), _registerSpace(registerSpace),
21 _protocolVersion(protocolVersion), _currentClientConnection(std::move(socket)) {
22 if(protocolVersion == 0) {
25 else if(protocolVersion == 1) {
29 throw std::invalid_argument(
"RebotDummyServer: unknown protocol version");
40 auto self(shared_from_this());
41 std::shared_ptr<std::vector<uint32_t>> buffer;
45 boost::asio::buffer(*buffer), [
this,
self, buffer](boost::system::error_code ec, std::size_t) {
61 auto self(shared_from_this());
63 boost::asio::buffer(
_dataBuffer), [
this,
self](boost::system::error_code ec, std::size_t) {
68 std::cerr << ec << std::endl;
90 uint32_t requestedAction = buffer.at(0);
91 switch(requestedAction) {
110 std::cout <<
"Instruction unknown in all protocol versions " << requestedAction << std::endl;
121 uint64_t registerAddress = buffer.at(1);
124 registerAddress = registerAddress * 4;
125 int32_t wordToWrite = buffer.at(2);
127 _registerSpace->write(bar, registerAddress, &wordToWrite,
sizeof(wordToWrite));
134 uint64_t registerAddress = buffer.at(1);
135 registerAddress = registerAddress * 4;
136 uint32_t numberOfWordsToRead = buffer.at(2);
142 std::vector<uint32_t> dataToSend(numberOfWordsToRead);
145 int32_t* startAddressForReadInData =
reinterpret_cast<int32_t*
>(dataToSend.data());
146 _registerSpace->read(bar, registerAddress, startAddressForReadInData, numberOfWordsToRead *
sizeof(int32_t));
173 : _protocolVersion(protocolVersion), _io(), _connectionAcceptor(_io, ip::tcp::endpoint(ip::tcp::v4(), portNumber)),
174 _socket(_io), _registerSpace(std::make_shared<
DummyBackend>(mapFile)) {
177 uint64_t registerAddress = 0x04;
178 int32_t wordToWrite = 0xDEADBEEF;
181 _registerSpace->open();
182 _registerSpace->write(bar, registerAddress, &wordToWrite,
sizeof(wordToWrite));
185 void RebotDummyServer::do_accept() {
186 _connectionAcceptor.async_accept(_socket, [
this](boost::system::error_code ec) {
188 if(_currentSession.expired()) {
189 auto newSession = std::make_shared<RebotDummySession>(_protocolVersion, std::move(_socket), _registerSpace);
190 _currentSession = newSession;
194 auto code = boost::system::errc::make_error_code(boost::system::errc::connection_refused);
212 return not _io.stopped();