Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
TractionThrottleInterface.hxx
Go to the documentation of this file.
1
35#ifndef _OPENLCB_TRACTIONTHROTTLEINTERFACE_HXX_
36#define _OPENLCB_TRACTIONTHROTTLEINTERFACE_HXX_
37
39#include "openlcb/Defs.hxx"
41
42namespace openlcb
43{
44
45class Node;
46struct TractionThrottleInput;
47
51{
52 enum SetDst
53 {
54 SET_DST,
55 };
56
57 enum AssignTrain
58 {
59 ASSIGN_TRAIN,
60 };
61
62 enum ReleaseTrain
63 {
64 RELEASE_TRAIN,
65 };
66
67 enum LoadState
68 {
69 LOAD_STATE,
70 };
71
72 enum ConsistAdd
73 {
74 CONSIST_ADD,
75 };
76
77 enum ConsistDel
78 {
79 CONSIST_DEL,
80 };
81
82 enum ConsistQry
83 {
84 CONSIST_QRY,
85 };
86};
87
92{
93 enum Command
94 {
95 CMD_SET_DST,
96 CMD_ASSIGN_TRAIN,
97 CMD_RELEASE_TRAIN,
98 CMD_LOAD_STATE,
99 CMD_CONSIST_ADD,
100 CMD_CONSIST_DEL,
101 CMD_CONSIST_QRY,
102 };
103
106 void reset(const TractionThrottleCommands::SetDst &, const NodeID &dst)
107 {
108 cmd = CMD_SET_DST;
109 this->dst = dst;
110 }
111
112 void reset(const TractionThrottleCommands::AssignTrain &, const NodeID &dst,
113 bool listen)
114 {
115 cmd = CMD_ASSIGN_TRAIN;
116 this->dst = dst;
117 this->flags = listen ? 1 : 0;
118 }
119
120 void reset(const TractionThrottleCommands::ReleaseTrain &)
121 {
122 cmd = CMD_RELEASE_TRAIN;
123 }
124
125 void reset(const TractionThrottleCommands::LoadState &)
126 {
127 cmd = CMD_LOAD_STATE;
128 }
129
130 void reset(const TractionThrottleCommands::ConsistAdd &, NodeID slave,
131 uint8_t flags)
132 {
133 cmd = CMD_CONSIST_ADD;
134 dst = slave;
135 this->flags = flags;
136 }
137
138 void reset(const TractionThrottleCommands::ConsistDel &, NodeID slave)
139 {
140 cmd = CMD_CONSIST_DEL;
141 dst = slave;
142 }
143
144 void reset(const TractionThrottleCommands::ConsistQry &)
145 {
146 cmd = CMD_CONSIST_QRY;
147 replyCause = 0xff;
148 }
149
150 void reset(const TractionThrottleCommands::ConsistQry &, uint8_t ofs)
151 {
152 cmd = CMD_CONSIST_QRY;
153 consistIndex = ofs;
154 replyCause = 0;
155 }
156
157 Command cmd;
163 uint8_t flags;
164
167 uint8_t replyCause;
172};
173
175{
176public:
178 virtual void toggle_fn(uint32_t fn) = 0;
179
183 virtual void query_fn(uint32_t fn)
184 {
185 }
186
189 virtual bool is_train_assigned() = 0;
190
194
205 std::function<void(int fn)> update_callback) = 0;
206
210};
211
212class TractionThrottleBase : public CallableFlow<TractionThrottleInput>,
214{
215public:
218 {
219 }
220
221 enum
222 {
225 FN_NOT_KNOWN = 0xffff,
226 };
227};
228
229} // namespace openlcb
230
231#endif // _OPENLCB_TRACTIONTHROTTLEINTERFACE_HXX_
int listen(int socket, int backlog)
Mark a connection-mode socket, specified by the socket argument, as accepting connections.
Definition Socket.cxx:174
Node information.
Definition Devtab.hxx:549
Collection of related state machines that pend on incoming messages.
Base class for NMRAnet nodes conforming to the asynchronous interface.
Definition Node.hxx:52
@ FN_NOT_KNOWN
Returned from get_fn() when we don't have a cahced value for a function.
virtual openlcb::Node * throttle_node()=0
virtual void toggle_fn(uint32_t fn)=0
Flips a function on<>off.
virtual void query_fn(uint32_t fn)
Sends a query for a function to the server.
virtual openlcb::NodeID target_node()=0
virtual bool is_train_assigned()=0
Determine if a train is currently assigned to this trottle.
virtual void set_throttle_listener(std::function< void(int fn)> update_callback)=0
Sets up a callback for listening for remote throttle updates.
Abstract base class for train implementations.
uint64_t NodeID
48-bit NMRAnet Node ID type
All callable flow request objects have to derive from this struct.
C++ Namespace for collecting all commands that can be sent to the TractionThrottle flow.
Request structure used to send requests to the TractionThrottle class.
uint8_t flags
Contains the flags for the consist listener.
void reset(const TractionThrottleCommands::SetDst &, const NodeID &dst)
Sets the destination node to send messages to without sending assign commands to that train node.
NodeID dst
For assign, this carries the destination node ID.
uint8_t replyCause
For assign controller reply REJECTED, this is 1 for controller refused connection,...
uint8_t consistIndex
Index of the entry in the consisting list that needs to be returned.
uint8_t consistCount
Total number of entries in the consisting list.