|
Open Model Railroad Network (OpenMRN)
|
Interface for a single throttle for running a train node. More...
#include <TractionThrottle.hxx>
Public Types | |
| enum | { TIMEOUT_NSEC = SEC_TO_NSEC(2) , MAX_FN_QUERY = 28 , ERROR_UNASSIGNED = 0x4000000 , ERROR_ASSIGNED = 0x4010000 } |
| using | Command = TractionThrottleInput::Command |
Public Types inherited from openlcb::TractionThrottleBase | |
| enum | { FN_NOT_KNOWN = 0xffff } |
Public Types inherited from TypedStateFlow< MessageType, UntypedStateFlow< QueueType > > | |
| typedef Base::Action | Action |
| Allows using Action without having StateFlowBase:: prefix in front of it. | |
Public Types inherited from FlowInterface< MessageType > | |
| typedef MessageType | message_type |
| Stores the message template type for external reference. | |
Public Member Functions | |
| TractionThrottle (Node *node) | |
| void | set_speed (SpeedType speed) override |
| Sets the speed of the locomotive. | |
| SpeedType | get_speed () override |
| void | set_emergencystop () override |
| Sets the train to emergency stop. | |
| bool | get_emergencystop () override |
| Get the current E-Stop state. | |
| void | set_fn (uint32_t address, uint16_t value) override |
| Sets the value of a function. | |
| uint16_t | get_fn (uint32_t address) override |
| void | toggle_fn (uint32_t fn) override |
| Flips a function on<>off. | |
| void | query_fn (uint32_t address) override |
| Sends out a function query command. | |
| uint32_t | legacy_address () override |
| dcc::TrainAddressType | legacy_address_type () override |
| bool | is_train_assigned () override |
| Determine if a train is currently assigned to this trottle. | |
| openlcb::Node * | throttle_node () override |
| openlcb::NodeID | target_node () override |
| void | set_throttle_listener (std::function< void(int fn)> update_callback) override |
| Sets up a callback for listening for remote throttle updates. | |
Public Member Functions inherited from openlcb::TractionThrottleBase | |
| TractionThrottleBase (Service *s) | |
Public Member Functions inherited from CallableFlow< TractionThrottleInput > | |
| CallableFlow (Service *s) | |
| Creates a callable flow. | |
Public Member Functions inherited from StateFlow< MessageType, QueueType > | |
| StateFlow (Service *service) | |
| Constructor. | |
Public Member Functions inherited from TypedStateFlow< MessageType, UntypedStateFlow< QueueType > > | |
| TypedStateFlow (Service *service) | |
| Constructor. | |
| virtual | ~TypedStateFlow () |
| Destructor. | |
| void | send (MessageType *msg, unsigned priority=UINT_MAX) OVERRIDE |
| Sends a message to the state flow for processing. | |
Public Member Functions inherited from UntypedStateFlow< QueueType > | |
| UntypedStateFlow (Service *service) | |
| Constructor. | |
Public Member Functions inherited from StateFlowWithQueue | |
| void | notify () override |
| Wakeup call arrived. Schedules *this on the executor. | |
| bool | is_waiting () |
Public Member Functions inherited from StateFlowBase | |
| void | run () override |
| Callback from the executor. | |
| Service * | service () |
| Return a pointer to the service I am bound to. | |
Public Member Functions inherited from Executable | |
| void | test_deletion () |
Public Member Functions inherited from QMember | |
| void | init () |
| Initiailize a QMember, in place of a public placement construction. | |
Public Member Functions inherited from LinkedObject< StateFlowWithQueue > | |
| StateFlowWithQueue * | link_next () |
Public Member Functions inherited from FlowInterface< MessageType > | |
| virtual Pool * | pool () |
| virtual MessageType * | type_helper () |
| This function is never user in the code, but GDB can use it to infer the correct message types. | |
| MessageType * | alloc () |
| Synchronously allocates a message buffer from the pool of this flow. | |
| void | alloc_async (Executable *target) |
| Asynchronously allocates a message buffer from the pool of this flow. | |
Public Member Functions inherited from openlcb::TrainImpl | |
| virtual SpeedType | get_commanded_speed () |
| virtual SpeedType | get_actual_speed () |
| Returns the actual speed of the locomotive, as provided by feedback from the decoder. | |
Public Member Functions inherited from LinkedObject< TractionThrottle > | |
| TractionThrottle * | link_next () |
Private Member Functions | |
| Action | entry () override |
| Entry into the StateFlow activity. | |
| Action | release_train () |
| Action | release_listener_response () |
| Action | release_step_2 () |
| Action | assign_train () |
| Action | assign_response () |
| Action | assign_consist_response () |
| Action | load_state () |
| Action | load_done () |
| bool | pending_reply_arrived () |
| Notifies that a pending query during load has gotten a reply. | |
| void | speed_reply (Buffer< GenMessage > *msg) |
| Invoked for TRACTION_CONTROL_REPLY messages coming in via the dispatcher. | |
| Action | consist_add () |
| Action | consist_del () |
| Action | consist_add_response () |
| Action | consist_qry () |
| Action | consist_qry_response () |
| void | listen_reply (Buffer< GenMessage > *msg) |
| Invoked for TRACTION_CONTROL_COMMAND messages coming in via the dispatcher. | |
| void | listen_reply_process (const Payload &p) |
| Business logic for interpreting a proxied traction command payload. | |
| void | send_traction_message_with_loopback (Payload payload) |
| Allocates (synchronously) an outgoing openlcb buffer with traction request MTI and the given payload and sends off the message to the bus for dst_. | |
| void | loopback_traction_message (Buffer< GenMessage > *b) |
| Performs loopback processing of an outgoing traction message. | |
| void | send_traction_message (Payload payload) |
| Allocates (synchronously) an outgoing openlcb buffer with traction request MTI and the given payload and sends off the message to the bus for dst_. | |
| BufferPtr< GenMessage > | send_traction_message_helper (Payload payload) |
| Allocates (synchronously) an outgoing openlcb buffer with traction request MTI and the given payload and sends off the message to the bus for dst_. | |
| void | set_listening () |
| void | clear_listening () |
| void | set_assigned () |
| void | clear_assigned () |
| void | clear_cache () |
| TractionThrottleInput * | input () |
| If * | iface () |
Private Attributes | |
| MessageHandler::GenericHandler | speedReplyHandler_ |
| MessageHandler::GenericHandler | listenReplyHandler_ |
| unsigned | pendingQueries_ {0} |
| How many speed/fn query requests I have sent off to the train node that have not yet seen a reply. | |
| StateFlowTimer | timer_ {this} |
| bool | assigned_ {false} |
| True if the assign controller has returned positive. | |
| bool | listenConsist_ {false} |
| True if we also have a consist link with the assigned loco. | |
| bool | estopActive_ {false} |
| keep track if E-Stop is active | |
| NodeID | dst_ |
| Node * | node_ |
| TractionResponseHandler | handler_ {iface(), node_} |
| Helper class for stateful query/return flows. | |
| std::function< void(int fn)> | updateCallback_ |
| Function to call when a different controller updates the train. | |
| SpeedType | lastSetSpeed_ |
| Cache: Velocity value that we last commanded to the train. | |
| std::map< uint32_t, uint16_t > | lastKnownFn_ |
| Cache: all known function values. | |
Additional Inherited Members | |
Static Public Member Functions inherited from StateFlowBase | |
| template<class T , typename... Args> | |
| static void | invoke_subflow_and_ignore_result (FlowInterface< Buffer< T > > *target_flow, Args &&... args) |
| Calls a helper flow to perform some actions. | |
Static Public Member Functions inherited from LinkedObject< StateFlowWithQueue > | |
| static StateFlowWithQueue * | link_head () |
| static Atomic * | head_mu () |
| Locks the list for modification (at any entry!). | |
Static Public Member Functions inherited from FlowInterface< MessageType > | |
| static MessageType * | cast_alloc (QMember *entry) |
| Down casts and initializes an asynchronous allocation result to the appropriate flow's buffer type. | |
Static Public Member Functions inherited from LinkedObject< TractionThrottle > | |
| static TractionThrottle * | link_head () |
| static Atomic * | head_mu () |
| Locks the list for modification (at any entry!). | |
Protected Types inherited from CallableFlow< TractionThrottleInput > | |
| using | Action = StateFlowBase::Action |
Protected Types inherited from UntypedStateFlow< QueueType > | |
| typedef Action(StateFlowBase::* | Callback) () |
| State Flow callback prototype. | |
Protected Types inherited from StateFlowBase | |
| typedef Action(StateFlowBase::* | Callback) () |
| State Flow callback prototype. | |
Protected Member Functions inherited from CallableFlow< TractionThrottleInput > | |
| TractionThrottleInput * | request () |
| bool | has_request () |
| Action | return_ok () |
| Terminates the flow and returns the request buffer to the caller with an error code of OK (zero). | |
| Action | wait_and_return_ok () |
| Waits to be notified before moving onto the next state for termination. | |
| Action | wait_done () |
| Terminates the flow and returns the request buffer to the caller with an error code of OK (zero). | |
| Action | return_with_error (int error) |
| Terminates the flow and returns the request buffer to the caller with an specific error code. | |
Protected Member Functions inherited from TypedStateFlow< MessageType, UntypedStateFlow< QueueType > > | |
| void | release () OVERRIDE |
| Unrefs the current buffer. | |
| void | return_buffer () |
| For state flows that are operated using invoke_subflow_and_wait this is a way to hand back the buffer to the caller. | |
| MessageType * | message () |
| MessageType * | transfer_message () |
| Releases ownership of the current message. | |
Protected Member Functions inherited from UntypedStateFlow< QueueType > | |
| void | send (BufferBase *msg, unsigned priority=UINT_MAX) |
| Sends a message to the state flow for processing. | |
| QMember * | queue_next (unsigned *priority) OVERRIDE |
| Takes the front entry in the queue. | |
| bool | queue_empty () OVERRIDE |
| Action | call_immediately (Callback c) |
| Imediately call the next state upon return. | |
Protected Member Functions inherited from StateFlowWithQueue | |
| StateFlowWithQueue (Service *service) | |
| Constructor. | |
| Action | exit () |
| Terminates the processing of this flow. | |
| Action | release_and_exit () |
| Terminates the processing of the current message. | |
| BufferBase * | message () |
| BufferBase * | transfer_message () |
| Releases ownership of the current message. | |
| void | reset_message (BufferBase *message, unsigned priority) |
| Sets the current message being processed. | |
| unsigned | priority () |
| void | set_priority (unsigned priority) |
| Overrides the current priority. | |
| void | start_flow_at_init (Callback c) |
| Call this from the constructor of the child class to do some work before the main queue processing loop begins. | |
Protected Member Functions inherited from StateFlowBase | |
| StateFlowBase (Service *service) | |
| Constructor. | |
| ~StateFlowBase () | |
| Destructor. | |
| void | reset_flow (Callback c) |
| Resets the flow to the specified state. | |
| bool | is_state (Callback c) |
| bool | is_terminated () |
| void | start_flow (Callback c) |
| Resets the flow to the specified state and starts it. | |
| Action | again () |
| Call the current state again via call_immediately. | |
| Action | exit () |
| Terminate current StateFlow activity. | |
| Action | delete_this () |
| Terminates the flow and deletes *this. | |
| Action | set_terminated () |
| Sets the flow to terminated state. | |
| Action | call_immediately (Callback c) |
| Imediately call the next state upon return. | |
| Action | wait () |
| Wait for an asynchronous call. | |
| Action | wait_and_call (Callback c) |
| Wait for resource to become available before proceeding to next state. | |
| template<class T > | |
| Action | allocate_and_call (FlowInterface< Buffer< T > > *target_flow, Callback c, Pool *pool=nullptr) |
| Allocates a buffer from a pool and proceed to the next state when allocation is successful. | |
| Action | allocate_and_call (Callback c, QAsync *queue) |
| Allocates an entry from an asynchronous queue, and transitions to a state once the allocation is complete. | |
| template<class T > | |
| Buffer< T > * | full_allocation_result (FlowInterface< Buffer< T > > *target_flow) |
| Takes the result of the asynchronous allocation without resetting the object. | |
| template<class T > | |
| T * | full_allocation_result (TypedQAsync< T > *queue) |
| Takes the result of the asynchronous allocation without resetting the object. | |
| template<class T > | |
| void | cast_allocation_result (T **member) |
| Takes the result of the asynchronous allocation without resetting the object. | |
| template<class T > | |
| Buffer< T > * | get_allocation_result (FlowInterface< Buffer< T > > *target_flow) |
| Takes the result of the asynchronous allocation. | |
| Action | yield_and_call (Callback c) |
| Place the current flow to the back of the executor, and transition to a new state after we get the CPU again. | |
| Action | yield () |
| Place the current flow to the back of the executor, and re-try the current state after we get the CPU again. | |
| Action | sleep_and_call (::Timer *timer, long long timeout_nsec, Callback c) |
| Suspends execution of this control flow for a specified time. | |
| template<class T , typename... Args> | |
| Action | invoke_subflow_and_wait (FlowInterface< Buffer< T > > *target_flow, Callback c, Args &&... args) |
| Calls a helper flow to perform some actions. | |
| Action | read_repeated (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO) |
| Blocks until size bytes are read and then invokes the next state. | |
| 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 | read_nonblocking (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO) |
| Attempts to read at most size bytes, and then invokes the next state, even if only zero bytes are available right now. | |
| Action | read_repeated_with_timeout (StateFlowTimedSelectHelper *helper, long long timeout_nsec, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO) |
| Blocks until size bytes are read, or a timeout expires. | |
| Action | internal_try_read () |
| Implementation state that gets repeatedly called upon every wakeup and tries to make progress on reading. | |
| 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 written. | |
| Action | internal_try_write () |
| Implementation state that gets repeatedly called upon every wakeup and tries to make progress on writing. | |
Protected Member Functions inherited from QMember | |
| QMember () | |
| Constructor. | |
| ~QMember () | |
| Destructor. | |
Protected Member Functions inherited from Atomic | |
| void | lock () |
| void | unlock () |
Protected Member Functions inherited from LinkedObject< StateFlowWithQueue > | |
| StateFlowWithQueue * | link_this () |
| LinkedObject () | |
| Constructor. Puts *this on the linked list. | |
| ~LinkedObject () | |
| Constructor. Removes *this from the linked list. | |
| StateFlowWithQueue * | link_next () |
Protected Member Functions inherited from LinkedObject< TractionThrottle > | |
| TractionThrottle * | link_this () |
| LinkedObject () | |
| Constructor. Puts *this on the linked list. | |
| ~LinkedObject () | |
| Constructor. Removes *this from the linked list. | |
Static Protected Member Functions inherited from LinkedObject< StateFlowWithQueue > | |
| static StateFlowWithQueue * | link_head () |
| static Atomic * | head_mu () |
| Locks the list for modification (at any entry!). | |
Protected Attributes inherited from QMember | |
| QMember * | next |
| pointer to the next member in the queue | |
Protected Attributes inherited from LinkedObject< StateFlowWithQueue > | |
| StateFlowWithQueue * | link_ |
| Linked list pointer. | |
Protected Attributes inherited from LinkedObject< TractionThrottle > | |
| TractionThrottle * | link_ |
| Linked list pointer. | |
Static Protected Attributes inherited from LinkedObject< StateFlowWithQueue > | |
| static StateFlowWithQueue * | head_ |
| Beginning of the list. | |
Static Protected Attributes inherited from LinkedObject< TractionThrottle > | |
| static TractionThrottle * | head_ |
| Beginning of the list. | |
Interface for a single throttle for running a train node.
Definition at line 51 of file TractionThrottle.hxx.
| using openlcb::TractionThrottle::Command = TractionThrottleInput::Command |
Definition at line 70 of file TractionThrottle.hxx.
| anonymous enum |
| Enumerator | |
|---|---|
| TIMEOUT_NSEC | Timeout for assign controller request. |
| MAX_FN_QUERY | Upon a load state request, how far do we go into the function list? |
Definition at line 72 of file TractionThrottle.hxx.
|
inline |
| node | is the openlcb node from which this throttle will be sending its messages. |
Definition at line 57 of file TractionThrottle.hxx.
|
inline |
Definition at line 64 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 419 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 379 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 370 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 838 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 848 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 825 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 536 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 553 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 545 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 593 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 610 of file TractionThrottle.hxx.
|
inlineoverrideprivatevirtual |
Entry into the StateFlow activity.
Pure virtual which must be defined by derived class.
Implements TypedStateFlow< MessageType, UntypedStateFlow< QueueType > >.
Definition at line 203 of file TractionThrottle.hxx.
|
inlineoverridevirtual |
Get the current E-Stop state.
Implements openlcb::TrainImpl.
Definition at line 106 of file TractionThrottle.hxx.
|
inlineoverridevirtual |
Implements openlcb::TrainImpl.
Definition at line 118 of file TractionThrottle.hxx.
|
inlineoverridevirtual |
Implements openlcb::TrainImpl.
Definition at line 90 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 860 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 855 of file TractionThrottle.hxx.
|
inlineoverridevirtual |
Determine if a train is currently assigned to this trottle.
Implements openlcb::TractionThrottleInterface.
Definition at line 162 of file TractionThrottle.hxx.
|
inlineoverridevirtual |
Implements openlcb::TrainImpl.
Definition at line 150 of file TractionThrottle.hxx.
|
inlineoverridevirtual |
Implements openlcb::TrainImpl.
Definition at line 155 of file TractionThrottle.hxx.
|
inlineprivate |
Invoked for TRACTION_CONTROL_COMMAND messages coming in via the dispatcher.
These are generally update commands coming on when another throttle is controlling the same loco or consist via another member.
Definition at line 646 of file TractionThrottle.hxx.
|
inlineprivate |
Business logic for interpreting a proxied traction command payload.
The command may be coming back as a consist forward message due to throttle listener, or may be one that went out from another TractionThrottle instance to the same train.
Definition at line 665 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 447 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 435 of file TractionThrottle.hxx.
|
inlineprivate |
Performs loopback processing of an outgoing traction message.
Run on the iface()'s executor.
| b | the message that was sent out. Will be unreffed. |
Definition at line 734 of file TractionThrottle.hxx.
|
inlineprivate |
Notifies that a pending query during load has gotten a reply.
Definition at line 463 of file TractionThrottle.hxx.
|
inlineoverridevirtual |
Sends out a function query command.
The throttle listener will be called when the response is available.
| address | function to query. |
Reimplemented from openlcb::TractionThrottleInterface.
Definition at line 145 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 343 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 354 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 286 of file TractionThrottle.hxx.
|
inlineprivate |
Allocates (synchronously) an outgoing openlcb buffer with traction request MTI and the given payload and sends off the message to the bus for dst_.
| payload | is the data contents of the message (e.g. TractionDefs::speed_set_payload(...). |
Definition at line 798 of file TractionThrottle.hxx.
|
inlineprivate |
Allocates (synchronously) an outgoing openlcb buffer with traction request MTI and the given payload and sends off the message to the bus for dst_.
Returns a reference to the buffer.
Definition at line 808 of file TractionThrottle.hxx.
|
inlineprivate |
Allocates (synchronously) an outgoing openlcb buffer with traction request MTI and the given payload and sends off the message to the bus for dst_.
Performs loopback to other traction throttles that might be assigned to the same train.
| payload | is the data contents of the message (e.g. TractionDefs::speed_set_payload(...). |
Definition at line 722 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 832 of file TractionThrottle.hxx.
|
inlineoverridevirtual |
Sets the train to emergency stop.
Implements openlcb::TrainImpl.
Definition at line 97 of file TractionThrottle.hxx.
|
inlineoverridevirtual |
Sets the value of a function.
| address | is a 24-bit address of the function to set. For legacy DCC locomotives, see TractionDefs for the address definitions (0=light, 1-28= traditional function buttons). |
| value | is the function value. For binary functions, any non-zero value sets the function to on, zero sets it to off. |
Implements openlcb::TrainImpl.
Definition at line 111 of file TractionThrottle.hxx.
|
inlineprivate |
Definition at line 818 of file TractionThrottle.hxx.
|
inlineoverridevirtual |
Sets the speed of the locomotive.
| speed | is the requested scale speed in m/s. The sign of the number means the direction. |
Implements openlcb::TrainImpl.
Definition at line 82 of file TractionThrottle.hxx.
|
inlineoverridevirtual |
Sets up a callback for listening for remote throttle updates.
When a different throttle modifies the train node's state, and the ASSIGN_TRAIN command was executed with "listen==true" parameter, we will get notifications about those remote changes. The notifications update the cached state in TractionThrottle, and call this update callback. Repeat with nullptr if the callbacks are not desired anymore.
| update_callback | will be executed when a different throttle changes the train state. fn is the function number changed, or -1 for speed update. |
Implements openlcb::TractionThrottleInterface.
Definition at line 188 of file TractionThrottle.hxx.
|
inlineprivate |
Invoked for TRACTION_CONTROL_REPLY messages coming in via the dispatcher.
Definition at line 478 of file TractionThrottle.hxx.
|
inlineoverridevirtual |
Implements openlcb::TractionThrottleInterface.
Definition at line 174 of file TractionThrottle.hxx.
|
inlineoverridevirtual |
Implements openlcb::TractionThrottleInterface.
Definition at line 168 of file TractionThrottle.hxx.
|
inlineoverridevirtual |
Flips a function on<>off.
Implements openlcb::TractionThrottleInterface.
Definition at line 128 of file TractionThrottle.hxx.
|
private |
True if the assign controller has returned positive.
Definition at line 876 of file TractionThrottle.hxx.
|
private |
Definition at line 881 of file TractionThrottle.hxx.
|
private |
keep track if E-Stop is active
Definition at line 880 of file TractionThrottle.hxx.
|
private |
Helper class for stateful query/return flows.
Definition at line 884 of file TractionThrottle.hxx.
|
private |
Cache: all known function values.
Definition at line 890 of file TractionThrottle.hxx.
|
private |
Cache: Velocity value that we last commanded to the train.
Definition at line 888 of file TractionThrottle.hxx.
|
private |
True if we also have a consist link with the assigned loco.
Definition at line 878 of file TractionThrottle.hxx.
|
private |
Definition at line 869 of file TractionThrottle.hxx.
|
private |
Definition at line 882 of file TractionThrottle.hxx.
|
private |
How many speed/fn query requests I have sent off to the train node that have not yet seen a reply.
Definition at line 873 of file TractionThrottle.hxx.
|
private |
Definition at line 867 of file TractionThrottle.hxx.
|
private |
Definition at line 874 of file TractionThrottle.hxx.
|
private |
Function to call when a different controller updates the train.
Definition at line 886 of file TractionThrottle.hxx.