48 , command(dispatcher.alloc())
49 , serverCommandLoco(this)
81 printf(
"WiThrottle connection closed\n");
89 if (
data.find(
'\n' != string::npos))
112 const char *c_str =
data.c_str();
113 printf(
"WiThrottle stream: %s\n", c_str +
dataIndex);
120 if (
data.length() < 2)
150 }
while (
data.length());
181 write(
fd,
"*10\n\n", 5);
216 size_t end =
data.find(
"<;>");
233 data.erase(0, end + 3);
270 size_t end =
data.find(
'\n');
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
MessageType * alloc()
Synchronously allocates a message buffer from the pool of this flow.
void init()
Initiailize a QMember, in place of a public placement construction.
Return type for a state flow callback.
Base class for state machines.
Action read_single(StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
Attempts to read at most size_t bytes, and blocks the caller until at least one byte is read.
Action delete_this()
Terminates the flow and deletes *this.
Action write_repeated(StateFlowSelectHelper *helper, int fd, const void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
Writes some data into a file descriptor, repeating the operation as necessary until all bytes are wri...
void send(MessageType *msg, unsigned priority=UINT_MAX) OVERRIDE
Sends a message to the state flow for processing.
Base class for NMRAnet nodes conforming to the asynchronous interface.
WiThrottle server object.
StateFlowBase::Action data_sent()
Data sent successfully.
string data
agrigate pre-processed stream data
CommandDispatchFlow dispatcher
flow responsible for routing incoming messages to handlers.
void parse_multi_type()
Parse the incoming data.
void parse_command()
Parse the incoming data.
StateFlowBase::Action data_received()
Process read data.
StateFlowSelectHelper selectHelper
Helper for waiting on data from a file descriptor.
ThrottleFlow(Server *server, int fd, openlcb::Node *node)
Constructor.
bool parse()
Parse the incoming data.
void parse_train()
Parse the incoming data.
ServerState state
Current state of parsing the data.
size_t dataIndex
data index for parsing
int fd
socket descriptor of throttle connection
bool parse_subcommand()
Parse the incoming data.
Buffer< ThrottleCommand > * command
throttle command
char readRaw[128]
read data buffer
StateFlowBase::Action entry()
Beginning of state flow.
unsigned remaining_
Number of bytes still outstanding to read.
unsigned hasError_
1 if there was an error reading of writing.
static string get_init_string()
Get the init command string.
CommandType
type of command.
@ SET_ID
set the device id
@ SET_NAME
set the device name
@ SECONDARY
secondary throttle
@ HEARTBEAT
send hardbeat or set heartbeat on/off
@ HEX_PACKET
hex packet for command station
@ PANEL
send panel command
@ ROSTER
send roster command
@ PRIMARY
primary throttle
CommandSubType
type of throttle command.
@ 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
CommandMultiType
type of multi throttle command.
@ REMOVE
remove a locomotive from the throttle
@ ADD
Add a locomotive to the throttle.
@ 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