• 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/protocol/cbus/cbusopcode.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_PROTOCOL_CBUS_CBUSOPCODE_HPP
23
#define TRAINTASTIC_SERVER_HARDWARE_PROTOCOL_CBUS_CBUSOPCODE_HPP
24

25
#include <cstdint>
26

27
namespace CBUS {
28

29
//! \brief CBUS OpCode
30
//! \see https://github.com/cbus-traincontrol/cbus-traincontrol.github.io/blob/main/CBUS%20Developers%20Guide%206c.pdf
31
//!
32
enum class OpCode : uint8_t
33
{
34
  // 00-1F – 0 data bytes packets:
35
  ACK    = 0x00, //!< General Acknowledgement
36
  NAK    = 0x01, //!< General No Ack
37
  HLT    = 0x02, //!< Bus Halt
38
  BON    = 0x03, //!< Bus ON
39
  TOF    = 0x04, //!< Track OFF
40
  TON    = 0x05, //!< Track ON
41
  ESTOP  = 0x06, //!< Emergency Stop
42
  ARST   = 0x07, //!< System Reset
43
  RTOF   = 0x08, //!< Request Track OFF
44
  RTON   = 0x09, //!< Request Track ON
45
  RESTP  = 0x0A, //!< Request Emergency Stop ALL
46
  RSTAT  = 0x0C, //!< Request Command Station Status
47
  QNN    = 0x0D, //!< Query node number
48
  RQNP   = 0x10, //!< Request node parameters
49
  RQMN   = 0x11, //!< Request module name
50

51
  // 20–3F - 1 data byte packets:
52
  KLOC   = 0x21, //!< Release Engine
53
  QLOC   = 0x22, //!< Query engine
54
  DKEEP  = 0x23, //!< Session keep alive
55
  DBG1   = 0x30, //!< Debug with one data byte
56
  EXTC   = 0x3F, //!< Extended op-code with no additional bytes
57

58
  // 40–5F - 2 data byte packets:
59
  RLOC   = 0x40, //!< Request engine session
60
  QCON   = 0x41, //!< Query Consist
61
  SNN    = 0x42, //!< Set Node Number
62
  ALOC   = 0x43, //!< Allocate loco to activity
63
  STMOD  = 0x44, //!< Set CAB session mode
64
  PCON   = 0x45, //!< Consist Engine
65
  KCON   = 0x46, //!< Remove Engine from consist
66
  DSPD   = 0x47, //!< Set Engine Speed/Dir
67
  DFLG   = 0x48, //!< Set Engine Flags
68
  DFNON  = 0x49, //!< Set Engine function on
69
  DFNOF  = 0x4A, //!< Set Engine function off
70
  SSTAT  = 0x4C, //!< Service mode status
71
  NNRSM  = 0x4F, //!< Reset to manufacturers defaults
72
  RQNN   = 0x50, //!< Request node number
73
  NNREL  = 0x51, //!< Node number release
74
  NNACK  = 0x52, //!< Node number acknowledge
75
  NNLRN  = 0x53, //!< Set node into learn mode
76
  NNULN  = 0x54, //!< Release node from learn mode
77
  NNCLR  = 0x55, //!< Clear all events from a node
78
  NNEVN  = 0x56, //!< Read number of events available in a node
79
  NERD   = 0x57, //!< Read back all stored events in a node
80
  RQEVN  = 0x58, //!< Request to read number of stored events
81
  WRACK  = 0x59, //!< Write acknowledge
82
  RQDAT  = 0x5A, //!< Request node data event
83
  RQDDS  = 0x5B, //!< Request device data – short mode
84
  BOOTM  = 0x5C, //!< Put node into bootload mode
85
  ENUM   = 0x5D, //!< Force a self enumeration cycle for use with CAN
86
  NNRST  = 0x5E, //!< Restart node
87
  EXTC1  = 0x5F, //!< Extended op-code with 1 additional byte
88

89
  // 60-7F - 3 data byte packets:
90
  DFUN   = 0x60, //!< Set Engine functions
91
  GLOC   = 0x61, //!< Get engine session
92
  ERR    = 0x63, //!< Command Station Error report
93
  CMDERR = 0x6F, //!< Error messages from nodes during configuration
94
  EVNLF  = 0x70, //!< Event space left reply from node
95
  NVRD   = 0x71, //!< Request read of a node variable
96
  NENRD  = 0x72, //!< Request read of stored events by event index
97
  RQNPN  = 0x73, //!< Request read of a node parameter by index
98
  NUMEV  = 0x74, //!< Number of events stored in node
99
  CANID  = 0x75, //!< Set a CAN_ID in existing FLiM node
100
  EXTC2  = 0x7F, //!< Extended op-code with 2 additional bytes
101

102
  // 80-9F - 4 data byte packets:
103
  RDCC3  = 0x80, //!< Request 3-byte DCC Packet
104
  WCVO   = 0x82, //!< Write CV (byte) in OPS mode
105
  WCVB   = 0x83, //!< Write CV (bit) in OPS mode
106
  QCVS   = 0x84, //!< Read CV
107
  PCVS   = 0x85, //!< Report CV
108
  ACON   = 0x90, //!< Accessory ON
109
  ACOF   = 0x91, //!< Accessory OFF
110
  AREQ   = 0x92, //!< Accessory Request Event
111
  ARON   = 0x93, //!< Accessory Response Event
112
  AROF   = 0x94, //!< Accessory Response Event
113
  EVULN  = 0x95, //!< Unlearn an event in learn mode
114
  NVSET  = 0x96, //!< Set a node variable
115
  NVANS  = 0x97, //!< Response to a request for a node variable value
116
  ASON   = 0x98, //!< Accessory Short ON
117
  ASOF   = 0x99, //!< Accessory Short OFF
118
  ASRQ   = 0x9A, //!< Accessory Short Request Event
119
  PARAN  = 0x9B, //!< Response to request for individual node parameter
120
  REVAL  = 0x9C, //!< Request for read of an event variable
121
  ARSON  = 0x9D, //!< Accessory Short Response Event
122
  ARSOF  = 0x9E, //!< Accessory Short Response Event
123
  EXTC3  = 0x9F, //!< Extended op-code with 3 additional bytes
124

125
  // A0-BF - 5 data byte packets:
126
  RDCC4  = 0xA0, //!< Request 4-byte DCC Packet
127
  WCVS   = 0xA2, //!< Write CV in Service mode
128
  ACON1  = 0xB0, //!< Accessory ON
129
  ACOF1  = 0xB1, //!< Accessory OFF
130
  REQEV  = 0xB2, //!< Read event variable in learn mode
131
  ARON1  = 0xB3, //!< Accessory Response Event
132
  AROF1  = 0xB4, //!< Accessory Response Event
133
  NEVAL  = 0xB5, //!< Response to request for read of EV value
134
  PNN    = 0xB6, //!< Response to Query Node
135
  ASON1  = 0xB8, //!< Accessory Short ON
136
  ASOF1  = 0xB9, //!< Accessory Short OFF
137
  ARSON1 = 0xBD, //!< Accessory Short Response Event with one data byte
138
  ARSOF1 = 0xBE, //!< Accessory Short Response Event with one data byte
139
  EXTC4  = 0xBF, //!< Extended op-code with 4 data bytes
140

141
  // C0-DF - 6 data byte packets:
142
  RDCC5  = 0xC0, //!< Request 5-byte DCC Packet
143
  WCVOA  = 0xC1, //!< Write CV (byte) in OPS mode by address
144
  CABDAT = 0xC2, //!< Cab Data
145
  FCLK   = 0xCF, //!< Fast Clock
146
  ACON2  = 0xD0, //!< Accessory ON
147
  ACOF2  = 0xD1, //!< Accessory OFF
148
  EVLRN  = 0xD2, //!< Teach an event in learn mode
149
  EVANS  = 0xD3, //!< Response to a request for an EV value in a node in learn mode
150
  ARON2  = 0xD4, //!< Accessory Response Event
151
  AROF2  = 0xD5, //!< Accessory Response Event
152
  ASON2  = 0xD8, //!< Accessory Short ON
153
  ASOF2  = 0xD9, //!< Accessory Short OFF
154
  ARSON2 = 0xDD, //!< Accessory Short Response Event with two data bytes
155
  ARSOF2 = 0xDE, //!< Accessory Short Response Event with two data bytes
156
  EXTC5  = 0xDF, //!< Extended op-code with 5 data bytes
157

158
  // E0-FF - 7 data byte packets:
159
  RDCC6  = 0xE0, //!< Request 6-byte DCC Packet
160
  PLOC   = 0xE1, //!< Engine report
161
  NAME   = 0xE2, //!< Response to request for node name string
162
  STAT   = 0xE3, //!< Command Station status report
163
  PARAMS = 0xEF, //!< Response to request for node parameters
164
  ACON3  = 0xF0, //!< Accessory ON
165
  ACOF3  = 0xF1, //!< Accessory OFF
166
  ENRSP  = 0xF2, //!< Response to request to read node events
167
  ARON3  = 0xF3, //!< Accessory Response Event
168
  AROF3  = 0xF4, //!< Accessory Response Event
169
  EVLRNI = 0xF5, //!< Teach an event in learn mode using event indexing
170
  ACDAT  = 0xF6, //!< Accessory node data event
171
  ARDAT  = 0xF7, //!< Accessory node data Response
172
  ASON3  = 0xF8, //!< Accessory Short ON
173
  ASOF3  = 0xF9, //!< Accessory Short OFF
174
  DDES   = 0xFA, //!< Device data event (short mode)
175
  DDRS   = 0xFB, //!< Device data response (short mode)
176
  ARSON3 = 0xFD, //!< Accessory Short Response Event
177
  ARSOF3 = 0xFE, //!< Accessory Short Response Event
178
  EXTC6  = 0xFF, //!< Extended op-code with 6 data bytes
179
};
180

NEW
181
constexpr uint8_t dataSize(OpCode opc)
×
182
{
NEW
183
  return static_cast<uint8_t>(opc) >> 5; // highest 3 bits determine data length
×
184
}
185

186
}
187

188
#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