• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

traintastic / traintastic / 23669027368

27 Mar 2026 09:50PM UTC coverage: 26.198% (+0.02%) from 26.176%
23669027368

push

github

reinder
Merge remote-tracking branch 'origin/master' into cbus

11 of 144 new or added lines in 34 files covered. (7.64%)

1 existing line in 1 file now uncovered.

8256 of 31514 relevant lines covered (26.2%)

182.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/server/src/hardware/protocol/xpressnet/iohandler/simulationiohandler.cpp
1
/**
2
 * server/src/hardware/protocol/xpressnet/iohandler/simulationiohandler.cpp
3
 *
4
 * This file is part of the traintastic source code.
5
 *
6
 * Copyright (C) 2022,2024 Reinder Feenstra
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
 */
22

23
#include "simulationiohandler.hpp"
24
#include "../kernel.hpp"
25
#include "../messages.hpp"
26

27
namespace XpressNet {
28

29
static std::shared_ptr<std::byte[]> copy(const Message& message)
×
30
{
31
  auto* bytes = new std::byte[message.size()];
×
32
  std::memcpy(bytes, &message, message.size());
×
33
  return std::shared_ptr<std::byte[]>{bytes};
×
34
}
35

36
SimulationIOHandler::SimulationIOHandler(Kernel& kernel)
×
37
  : IOHandler(kernel)
×
38
{
39
}
×
40

41
void SimulationIOHandler::start()
×
42
{
43
  m_kernel.started();
×
44
}
×
45

46
bool SimulationIOHandler::send(const Message& message)
×
47
{
48
  switch(message.header)
×
49
  {
50
    case 0x21:
×
51
      if(message == ResumeOperationsRequest())
×
52
        reply(NormalOperationResumed(), 3);
×
53
      else if(message == StopOperationsRequest())
×
54
        reply(TrackPowerOff(), 3);
×
55
      break;
×
56

57
    case 0x80:
×
58
      if(message == StopAllLocomotivesRequest())
×
59
        reply(EmergencyStop(), 3);
×
60
      break;
×
61
  }
62

63
  return true;
×
64
}
65

66
void SimulationIOHandler::reply(const Message& message)
×
67
{
68
  // post the reply, so it has some delay
69
  //! \todo better delay simulation? at least xpressnet message transfer time?
NEW
70
  boost::asio::post(m_kernel.ioContext(), 
×
71
    [this, data=copy(message)]()
×
72
    {
73
      m_kernel.receive(*reinterpret_cast<const Message*>(data.get()));
×
74
    });
×
75
}
×
76

77
void SimulationIOHandler::reply(const Message& message, const size_t count)
×
78
{
79
  for(size_t i = 0; i < count; i++)
×
80
    reply(message);
×
81
}
×
82

83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc