Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
withrottle/Defs.hxx
Go to the documentation of this file.
1
28#ifndef _WITHROTTLE_DEFS_HXX_
29#define _WITHROTTLE_DEFS_HXX_
30
31#include <string>
32
34
35namespace withrottle
36{
37
40{
41 uint16_t address : 14;
42 uint16_t addressType : 1;
43 uint16_t inUse : 1;
44};
45
49{
50 string name;
52};
53
57{
58 PRIMARY = 'T',
59 SECONDARY = 'S',
60 MULTI = 'M',
61 HEX_PACKET = 'D',
62 HEARTBEAT = '*',
63 SET_NAME = 'N',
64 SET_ID = 'H',
65 PANEL = 'P',
66 ROSTER = 'R',
67 QUIT = 'Q',
68 TYPE_MASK = 0xFF,
69};
70
74{
75 ACTION = 'A',
76 ADD = '+',
77 REMOVE = '-',
78};
79
83{
84 VELOCITY = 'V',
85 ESTOP = 'X',
86 FUNCTION = 'F',
87 FORCE = 'f',
88 DIRECTION = 'R',
89 RELEASE = 'r',
90 DISPATCH = 'd',
91 ADDR_LONG = 'L',
92 ADDR_SHORT = 'S',
94 CONSIST = 'C',
96 IDLE = 'I',
97 SS_MODE = 's',
98 MOMENTARY = 'm',
99 QUERY = 'q',
101};
102
123
135
138struct Defs
139{
140 static constexpr const int DEFAULT_PORT = 12090;
142 static constexpr const char *PROTOCOL_VERSION = "VN2.0";
143
145 static constexpr const char *TRACK_POWER_OFF = "PPA0";
146
148 static constexpr const char *TRACK_POWER_ON = "PPA1";
149
151 static constexpr const char *TRACK_POWER_UNKNOWN = "PPA2";
152
154 static constexpr const char *HEARTBEAT_TIMEOUT = "*10";
155
159 static string get_init_string()
160 {
161 string init(PROTOCOL_VERSION);
162
163 init.append("\n\nRL0");
164 init.append(2, '\n');
165 init.append(Defs::TRACK_POWER_ON);
166 init.append(2, '\n');
167 init.append("PTT\n\n");
168 init.append("PRT\n\n");
169 init.append("RCC0\n\n");
170 init.append(Defs::HEARTBEAT_TIMEOUT);
171 init.append(2, '\n');
172
173 return init;
174 }
175
182 static string get_function_status_string(const char *loco, int number,
183 bool state)
184 {
185 string status("MTA");
186 status.append(loco);
187 status.append("<;>F");
188 status.append(1, state ? '1' : '0');
189 if (number < 10)
190 {
191 status.append(1, '0' + number);
192 }
193 else
194 {
195 status.append(1, '0' + (number / 10));
196 status.append(1, '0' + (number % 10));
197 }
198 status.append("\n\n");
199
200 return status;
201 }
202
208 const char *loco)
209 {
210 string status("MT+");
211 status.append(loco);
212 status.append("<;>\n\n");
213 for (int i = 0; i <=28; ++i)
214 {
215 status.append(get_function_status_string(loco, i,
216 throttle->get_fn(i)));
217 }
218 status.append("MTA");
219 status.append(loco);
220 status.append("<;>V0\n\nMTA");
221 status.append(loco);
222 status.append("<;>R1\n\nMTA");
223 status.append(loco);
224 status.append("<;>S1\n\n");
225#if 0
226 string status("TL6915\n\nTF00\n\nTF01\n\nTF02\n\nTF03\n\nTF04\n\nTF05\n\n");
227 status.append("TF06\n\nTF07\n\nTF08\n\nTF09\n\nTF010\n\nTF011\n\nTF012\n\n");
228 status.append("TF013\n\nTF014\n\nTF015\n\nTF016\n\nTF017\n\nTF018\n\n");
229 status.append("TF019\n\nTF020\n\nTF021\n\nTF022\n\nTF023\n\nTF024\n\n");
230 status.append("TF025\n\nTF026\n\nTF027\n\nTF028\n\nTV0\n\nTR1\n\nTs1\n\n");
231#endif
232 return status;
233 }
234};
235
236} /* namespace withrottle */
237
238#endif /* _WITHROTTLE_DEFS_HXX_ */
Interface for a single throttle for running a train node.
uint16_t get_fn(uint32_t address) override
Command from the throttle.
CommandMultiType commandMultiType
type of multi throttle command
CommandType commandType
type of command
CommandType id_type
type of the dispatcher criteria
string train
The train description.
CommandSubType commandSubType
type of throttle command
string payload
the command payload
The interface definitions for WiThrottle.
static constexpr const char * TRACK_POWER_ON
Track power off string.
static string get_init_string()
Get the init command string.
static string get_function_status_string(const char *loco, int number, bool state)
Get the function status string.
static constexpr const char * HEARTBEAT_TIMEOUT
Heartbeat timeout string.
static constexpr const char * TRACK_POWER_OFF
Track power on string.
static string get_loco_status_string(openlcb::TractionThrottle *throttle, const char *loco)
Get the locomotive status command string.
static constexpr const char * TRACK_POWER_UNKNOWN
Track power unknown string.
static constexpr const char * PROTOCOL_VERSION
Protocol version string.
Locomotive address.
uint16_t address
14-bit DCC address
uint16_t addressType
true if long address, else short address
uint16_t inUse
reserved bit space
string name
display name of entry
LocoAddress address
locomotive adress
CommandType
type of command.
@ SET_ID
set the device id
@ SET_NAME
set the device name
@ SECONDARY
secondary throttle
@ TYPE_MASK
exact mask for dispatcher
@ HEARTBEAT
send hardbeat or set heartbeat on/off
@ QUIT
device has quit
@ HEX_PACKET
hex packet for command station
@ MULTI
multi throttle
@ PANEL
send panel command
@ ROSTER
send roster command
@ PRIMARY
primary throttle
CommandSubType
type of throttle command.
@ DIRECTION
set direction
@ SUBTYPE_MASK
exact mask for dispatcher
@ ADDR_ROSTER
set address from roster entry
@ QUERY
query about current speed, direction, etc...
@ IDLE
idle, set speed to 0
@ SS_MODE
set speed step mode
@ VELOCITY
velocity command
@ CONSIST_LEAD
consist lead from roster entry
@ ADDR_LONG
set long address
@ ADDR_SHORT
set short address
@ DISPATCH
dispatch a loco
@ MOMENTARY
momentary
@ FORCE
force function
@ FUNCTION
function key
@ RELEASE
release a loco
CommandMultiType
type of multi throttle command.
@ REMOVE
remove a locomotive from the throttle
@ ADD
Add a locomotive to the throttle.
@ ACTION
pefrom an action
ServerState
Server state machine commands.
@ STATE_SUBCOMMAND
look for sub-command
@ STATE_MULTI_TYPE
look for the multi-throttle type
@ STATE_COMMAND
look for command
@ STATE_TRAIN
look for the train
@ STATE_PAYLOAD
look for data
@ STATE_NEXT
look for next command