Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::TrainNode Class Referenceabstract

Virtual node class for an OpenLCB train protocol node. More...

#include <TractionTrain.hxx>

Inheritance diagram for openlcb::TrainNode:
openlcb::Node openlcb::TrainNodeWithConsist openlcb::DefaultTrainNode openlcb::TrainNodeForProxy openlcb::TrainNodeWithId

Public Member Functions

virtual TrainImpltrain ()=0
 
virtual bool function_policy (NodeHandle src, uint8_t command_byte, uint32_t fnum, uint16_t value, Notifiable *done)=0
 Applies a policy to function change requests coming in from the OpenLCB bus.
 
virtual void command_hook (NodeHandle src, const Payload &p)=0
 Invoked for every incoming traction command targeted to this node.
 
virtual NodeHandle get_controller ()=0
 
virtual void set_controller (NodeHandle id)=0
 
virtual bool add_consist (NodeID tgt, uint8_t flags)=0
 Adds a node ID to the consist targets.
 
virtual bool remove_consist (NodeID tgt)=0
 Removes a node ID from the consist targets.
 
virtual NodeID query_consist (int id, uint8_t *flags)=0
 Fetch a given consist link.
 
virtual int query_consist_length ()=0
 
- Public Member Functions inherited from openlcb::Node
virtual NodeID node_id ()=0
 
virtual Ififace ()=0
 
virtual bool is_initialized ()=0
 
virtual void set_initialized ()
 Callback from the node initialization flow when the node finished initialization.
 
virtual void clear_initialized ()=0
 Callback from the simple stack when the node has to return to uninitialized state.
 
void initialize ()
 Callback from the simple stack to start the initialization process.
 

Detailed Description

Virtual node class for an OpenLCB train protocol node.

Usage:

  • Create a TrainImpl defining how to send the commands to the hardware.
  • Create a TrainNode and pass it the pointer to the implementation.

for train implementations see LoggingTrain, dcc::Dcc28Train, dcc::MMNewTrain etc.

Definition at line 60 of file TractionTrain.hxx.

Constructor & Destructor Documentation

◆ ~TrainNode()

openlcb::TrainNode::~TrainNode ( )

Definition at line 53 of file TractionTrain.cxx.

Member Function Documentation

◆ add_consist()

virtual bool openlcb::TrainNode::add_consist ( NodeID  tgt,
uint8_t  flags 
)
pure virtual

Adds a node ID to the consist targets.

Returns
false if the node was already in the target list, true if it was newly added.
Parameters
tgtthe destination of the consist link
flagsconsisting flags from the Traction protocol.

Implemented in openlcb::TrainNodeWithConsist.

◆ command_hook()

virtual void openlcb::TrainNode::command_hook ( NodeHandle  src,
const Payload p 
)
pure virtual

Invoked for every incoming traction command targeted to this node.

Parameters
srcwhat node sent this command
pcommand payload

Implemented in openlcb::TrainNodeWithConsist.

◆ function_policy()

virtual bool openlcb::TrainNode::function_policy ( NodeHandle  src,
uint8_t  command_byte,
uint32_t  fnum,
uint16_t  value,
Notifiable done 
)
pure virtual

Applies a policy to function change requests coming in from the OpenLCB bus.

If the policy returns false, the change will not be applied to the TrainImpl. This is used to implement consist function behavior.

Parameters
srcsource node where the request came from.
command_byteis the first byte of the payload (usually 0x01 or 0x81 depending on the REQ_LISTENER bit)
fnumwhich function to set
valuewhat value to set this function to
donemust be notified inline if the policy application is successful. If not notified inline, then the returned value is ignored and the call is repeated after done has been invoked by the callee.
Returns
true if the function should be applied to the TrainImpl, false if it should not be applied.

Implemented in openlcb::TrainNodeWithConsist.

◆ get_controller()

virtual NodeHandle openlcb::TrainNode::get_controller ( )
pure virtual
Returns
the last stored controller node.

Implemented in openlcb::DefaultTrainNode.

◆ query_consist()

virtual NodeID openlcb::TrainNode::query_consist ( int  id,
uint8_t *  flags 
)
pure virtual

Fetch a given consist link.

Returns
The target of a given consist link, or NodeID(0) if there are fewer than id consist targets.
Parameters
idzero-based index of consist links.
flagsretrieved consist link's flags go here.

Implemented in openlcb::TrainNodeWithConsist.

◆ query_consist_length()

virtual int openlcb::TrainNode::query_consist_length ( )
pure virtual
Returns
the number of slaves in this consist.

Implemented in openlcb::TrainNodeWithConsist.

◆ remove_consist()

virtual bool openlcb::TrainNode::remove_consist ( NodeID  tgt)
pure virtual

Removes a node ID from the consist targets.

Returns
true if the target was removed, false if the target was not on the list.
Parameters
tgtdestination of consist link to remove.

Implemented in openlcb::TrainNodeWithConsist.

◆ set_controller()

virtual void openlcb::TrainNode::set_controller ( NodeHandle  id)
pure virtual
Parameters
idthe controller node of this train.

Implemented in openlcb::DefaultTrainNode.

◆ train()

virtual TrainImpl * openlcb::TrainNode::train ( )
pure virtual
Returns
the train implementation object for issuing control commands to this train.

Implemented in openlcb::DefaultTrainNode.


The documentation for this class was generated from the following files: