62 switch (
message()->data()->commandSubType)
65 return release_and_exit();
76 unsigned long value = strtoul(
message()->data()->payload.c_str(), NULL, 0);
78 if ((value == 0 && errno == EINVAL) || value > 9999)
80 return release_and_exit();
83 printf(
"loco: %lu\n", value);
87 dcc::TrainAddressType::DCC_LONG_ADDRESS, value);
90 openlcb::TractionThrottleCommands::ASSIGN_TRAIN, node_id, 0);
98 auto *m = full_allocation_result(&
throttle->olcbThrottle);
99 switch (m->data()->resultCode)
111 openlcb::TractionThrottleCommands::LOAD_STATE);
119 auto *m = full_allocation_result(&
throttle->olcbThrottle);
123 message()->data()->train.c_str());
125 ::write(
throttle->
fd, status.c_str(), status.length());
126 printf(
"%s", status.c_str());
128 return release_and_exit();
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
void register_handler(HandlerType *handler, ID id, ID mask)
Adds a new handler to this dispatcher.
void unregister_handler(HandlerType *handler, ID id, ID mask)
Removes a specific instance of a handler from this dispatcher.
Return type for a state flow callback.
WiThrottle server command handler base object.
ThrottleFlow * throttle
pointer to parent throttle
StateFlowBase::Action entry() override
Entry point to the state machine.
ServerCommandLoco(ThrottleFlow *throttle)
Constructor.
StateFlowBase::Action address_long()
Handle a DCC long address sub-command.
~ServerCommandLoco()
Destructor.
StateFlowBase::Action assign_train()
Handle succes or failure of assigning the train, including getting the latest train state.
StateFlowBase::Action load_state()
Update the LCD display with the trains current state.
State flow for handling a throttle instance.
CommandDispatchFlow dispatcher
flow responsible for routing incoming messages to handlers.
int fd
socket descriptor of throttle connection
uint64_t NodeID
48-bit NMRAnet Node ID type
static NodeID train_node_id_from_legacy(dcc::TrainAddressType type, uint32_t addr)
Converts a legacy address to an NMRAnet node ID.
static string get_loco_status_string(openlcb::TractionThrottle *throttle, const char *loco)
Get the locomotive status command string.
@ SECONDARY
secondary throttle
@ TYPE_MASK
exact mask for dispatcher
@ PRIMARY
primary throttle
@ ADDR_LONG
set long address