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

traintastic / traintastic / 24288605255

11 Apr 2026 06:17PM UTC coverage: 25.599% (-2.4%) from 27.99%
24288605255

push

github

web-flow
Merge pull request #222 from traintastic/cbus

Added CBUS/VLCB hardware support

169 of 3369 new or added lines in 99 files covered. (5.02%)

5 existing lines in 4 files now uncovered.

8300 of 32423 relevant lines covered (25.6%)

178.31 hits per line

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

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

22
#ifndef TRAINTASTIC_SERVER_HARDWARE_INTERFACE_CBUSINTERFACE_HPP
23
#define TRAINTASTIC_SERVER_HARDWARE_INTERFACE_CBUSINTERFACE_HPP
24

25
#include "interface.hpp"
26
#include "../decoder/decodercontroller.hpp"
27
#include "../input/inputcontroller.hpp"
28
#include "../output/outputcontroller.hpp"
29
#include "../../core/serialdeviceproperty.hpp"
30
#include <traintastic/enum/cbusinterfacetype.hpp>
31

32
class CBUSSettings;
33
class CBUSNodeList;
34
class CBUSSessionList;
35

36
namespace CBUS {
37
enum class OpCode : uint8_t;
38
struct Message;
39
class Kernel;
40
class Simulator;
41
}
42

43
/**
44
 * @brief CBUS hardware interface
45
 */
46
class CBUSInterface final
47
  : public Interface
48
  , public DecoderController
49
  , public InputController
50
  , public OutputController
51
{
NEW
52
  CLASS_ID("interface.cbus")
×
53
  DEFAULT_ID("cbus")
54
  CREATE_DEF(CBUSInterface)
55

56
public:
57
  Property<CBUSInterfaceType> type;
58
  SerialDeviceProperty device;
59
  Property<std::string> hostname;
60
  Property<uint16_t> port;
61
  Property<std::string> interface;
62
  Property<uint8_t> canId;
63
  ObjectProperty<CBUSSettings> cbus;
64
  ObjectProperty<CBUSNodeList> cbusNodeList;
65
  ObjectProperty<CBUSSessionList> cbusSessionList;
66

67
  CBUSInterface(World& world, std::string_view _id);
68
  ~CBUSInterface() final;
69

70
  //! \brief Send CBUS/VLCB message
71
  //! \param[in] message CBUS/VLCB message bytes, 1..8 bytes.
72
  //! \return \c true if send, \c false otherwise.
73
  bool send(std::vector<uint8_t> message);
74

75
  //! \brief Send DCC packet
76
  //! \param[in] dccPacket DCC packet byte, exluding checksum. Length is limited to 6.
77
  //! \param[in] repeat DCC packet repeat count 0..7
78
  //! \return \c true if send, \c false otherwise.
79
  bool sendDCC(std::vector<uint8_t> dccPacket, uint8_t repeat);
80

81
  size_t registerOnReceive(CBUS::OpCode opCode, std::function<void(uint8_t, const CBUS::Message&)> callback);
82
  void unregisterOnReceive(size_t handle);
83

84
  // DecoderController:
85
  std::span<const DecoderProtocol> decoderProtocols() const final;
86
  void decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber) final;
87

88
  // InputController:
89
  std::span<const InputChannel> inputChannels() const final;
90
  bool isInputLocation(InputChannel channel, const InputLocation& location) const final;
91
  std::pair<uint32_t, uint32_t> inputAddressMinMax(InputChannel channel) const final;
92
  void inputSimulateChange(InputChannel channel, const InputLocation& location, SimulateInputAction action) final;
93

94
  // OutputController:
95
  std::span<const OutputChannel> outputChannels() const final;
96
  std::pair<uint32_t, uint32_t> outputNodeMinMax(OutputChannel channel) const final;
97
  std::pair<uint32_t, uint32_t> outputAddressMinMax(OutputChannel channel) const final;
98
  [[nodiscard]] bool setOutputValue(OutputChannel channel, const OutputLocation& location, OutputValue value) final;
99

100
protected:
101
  void addToWorld() final;
102
  void loaded() final;
103
  void destroying() final;
104
  void worldEvent(WorldState state, WorldEvent event) final;
105

106
  bool setOnline(bool& value, bool simulation) final;
107

108
private:
109
  std::unique_ptr<CBUS::Kernel> m_kernel;
110
  std::unique_ptr<CBUS::Simulator> m_simulator;
111
  boost::signals2::connection m_cbusPropertyChanged;
112

113
  void updateVisible();
114
};
115

116
#endif
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