Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::TractionThrottle Class Reference

Interface for a single throttle for running a train node. More...

#include <TractionThrottle.hxx>

Inheritance diagram for openlcb::TractionThrottle:
openlcb::TractionThrottleBase LinkedObject< TractionThrottle > CallableFlow< TractionThrottleInput > openlcb::TractionThrottleInterface StateFlow< MessageType, QueueType > openlcb::TrainImpl TypedStateFlow< MessageType, UntypedStateFlow< QueueType > > UntypedStateFlow< QueueType > FlowInterface< MessageType > StateFlowWithQueue StateFlowBase Atomic LinkedObject< StateFlowWithQueue > Executable Notifiable QMember Destructable

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::Nodethrottle_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.
 
Serviceservice ()
 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 >
StateFlowWithQueuelink_next ()
 
- Public Member Functions inherited from FlowInterface< MessageType >
virtual Poolpool ()
 
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< GenMessagesend_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 ()
 
TractionThrottleInputinput ()
 
Ififace ()
 

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_
 
Nodenode_
 
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 StateFlowWithQueuelink_head ()
 
static Atomichead_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 Atomichead_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.
 
QMemberqueue_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.
 
BufferBasemessage ()
 
BufferBasetransfer_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 >
StateFlowWithQueuelink_this ()
 
 LinkedObject ()
 Constructor. Puts *this on the linked list.
 
 ~LinkedObject ()
 Constructor. Removes *this from the linked list.
 
StateFlowWithQueuelink_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 StateFlowWithQueuelink_head ()
 
static Atomichead_mu ()
 Locks the list for modification (at any entry!).
 
- Protected Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 
- Protected Attributes inherited from LinkedObject< StateFlowWithQueue >
StateFlowWithQueuelink_
 Linked list pointer.
 
- Protected Attributes inherited from LinkedObject< TractionThrottle >
TractionThrottle * link_
 Linked list pointer.
 
- Static Protected Attributes inherited from LinkedObject< StateFlowWithQueue >
static StateFlowWithQueuehead_
 Beginning of the list.
 
- Static Protected Attributes inherited from LinkedObject< TractionThrottle >
static TractionThrottle * head_
 Beginning of the list.
 

Detailed Description

Interface for a single throttle for running a train node.

Definition at line 51 of file TractionThrottle.hxx.

Member Typedef Documentation

◆ Command

using openlcb::TractionThrottle::Command = TractionThrottleInput::Command

Definition at line 70 of file TractionThrottle.hxx.

Member Enumeration Documentation

◆ anonymous enum

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.

Constructor & Destructor Documentation

◆ TractionThrottle()

openlcb::TractionThrottle::TractionThrottle ( Node node)
inline
Parameters
nodeis the openlcb node from which this throttle will be sending its messages.

Definition at line 57 of file TractionThrottle.hxx.

◆ ~TractionThrottle()

openlcb::TractionThrottle::~TractionThrottle ( )
inline

Definition at line 64 of file TractionThrottle.hxx.

Member Function Documentation

◆ assign_consist_response()

Action openlcb::TractionThrottle::assign_consist_response ( )
inlineprivate

Definition at line 419 of file TractionThrottle.hxx.

◆ assign_response()

Action openlcb::TractionThrottle::assign_response ( )
inlineprivate

Definition at line 379 of file TractionThrottle.hxx.

◆ assign_train()

Action openlcb::TractionThrottle::assign_train ( )
inlineprivate

Definition at line 370 of file TractionThrottle.hxx.

◆ clear_assigned()

void openlcb::TractionThrottle::clear_assigned ( )
inlineprivate

Definition at line 838 of file TractionThrottle.hxx.

◆ clear_cache()

void openlcb::TractionThrottle::clear_cache ( )
inlineprivate

Definition at line 848 of file TractionThrottle.hxx.

◆ clear_listening()

void openlcb::TractionThrottle::clear_listening ( )
inlineprivate

Definition at line 825 of file TractionThrottle.hxx.

◆ consist_add()

Action openlcb::TractionThrottle::consist_add ( )
inlineprivate

Definition at line 536 of file TractionThrottle.hxx.

◆ consist_add_response()

Action openlcb::TractionThrottle::consist_add_response ( )
inlineprivate

Definition at line 553 of file TractionThrottle.hxx.

◆ consist_del()

Action openlcb::TractionThrottle::consist_del ( )
inlineprivate

Definition at line 545 of file TractionThrottle.hxx.

◆ consist_qry()

Action openlcb::TractionThrottle::consist_qry ( )
inlineprivate

Definition at line 593 of file TractionThrottle.hxx.

◆ consist_qry_response()

Action openlcb::TractionThrottle::consist_qry_response ( )
inlineprivate

Definition at line 610 of file TractionThrottle.hxx.

◆ entry()

Action openlcb::TractionThrottle::entry ( )
inlineoverrideprivatevirtual

Entry into the StateFlow activity.

Pure virtual which must be defined by derived class.

Returns
function pointer to next state

Implements TypedStateFlow< MessageType, UntypedStateFlow< QueueType > >.

Definition at line 203 of file TractionThrottle.hxx.

◆ get_emergencystop()

bool openlcb::TractionThrottle::get_emergencystop ( )
inlineoverridevirtual

Get the current E-Stop state.

Returns
true if the train is E-Stopped, else false

Implements openlcb::TrainImpl.

Definition at line 106 of file TractionThrottle.hxx.

◆ get_fn()

uint16_t openlcb::TractionThrottle::get_fn ( uint32_t  address)
inlineoverridevirtual
Returns
the value of a function.

Implements openlcb::TrainImpl.

Definition at line 118 of file TractionThrottle.hxx.

◆ get_speed()

SpeedType openlcb::TractionThrottle::get_speed ( )
inlineoverridevirtual
Returns
the last set speed of the locomotive.

Implements openlcb::TrainImpl.

Definition at line 90 of file TractionThrottle.hxx.

◆ iface()

If * openlcb::TractionThrottle::iface ( )
inlineprivate

Definition at line 860 of file TractionThrottle.hxx.

◆ input()

TractionThrottleInput * openlcb::TractionThrottle::input ( )
inlineprivate

Definition at line 855 of file TractionThrottle.hxx.

◆ is_train_assigned()

bool openlcb::TractionThrottle::is_train_assigned ( )
inlineoverridevirtual

Determine if a train is currently assigned to this trottle.

Returns
true if a train is assigned, else false

Implements openlcb::TractionThrottleInterface.

Definition at line 162 of file TractionThrottle.hxx.

◆ legacy_address()

uint32_t openlcb::TractionThrottle::legacy_address ( )
inlineoverridevirtual
Returns
the legacy (DCC) address of this train. This value is used in determining the train's NMRAnet NodeID.
Todo:
(balazs.racz) This function should not be here. Specifying the NodeID should be more generic, but it is not clear what would be the best interface for that.

Implements openlcb::TrainImpl.

Definition at line 150 of file TractionThrottle.hxx.

◆ legacy_address_type()

dcc::TrainAddressType openlcb::TractionThrottle::legacy_address_type ( )
inlineoverridevirtual
Returns
the type of legacy protocol in use.

Implements openlcb::TrainImpl.

Definition at line 155 of file TractionThrottle.hxx.

◆ listen_reply()

void openlcb::TractionThrottle::listen_reply ( Buffer< GenMessage > *  msg)
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.

◆ listen_reply_process()

void openlcb::TractionThrottle::listen_reply_process ( const Payload p)
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.

◆ load_done()

Action openlcb::TractionThrottle::load_done ( )
inlineprivate

Definition at line 447 of file TractionThrottle.hxx.

◆ load_state()

Action openlcb::TractionThrottle::load_state ( )
inlineprivate

Definition at line 435 of file TractionThrottle.hxx.

◆ loopback_traction_message()

void openlcb::TractionThrottle::loopback_traction_message ( Buffer< GenMessage > *  b)
inlineprivate

Performs loopback processing of an outgoing traction message.

Run on the iface()'s executor.

Parameters
bthe message that was sent out. Will be unreffed.

Definition at line 734 of file TractionThrottle.hxx.

◆ pending_reply_arrived()

bool openlcb::TractionThrottle::pending_reply_arrived ( )
inlineprivate

Notifies that a pending query during load has gotten a reply.

Returns
true if we were in the load state.

Definition at line 463 of file TractionThrottle.hxx.

◆ query_fn()

void openlcb::TractionThrottle::query_fn ( uint32_t  address)
inlineoverridevirtual

Sends out a function query command.

The throttle listener will be called when the response is available.

Parameters
addressfunction to query.

Reimplemented from openlcb::TractionThrottleInterface.

Definition at line 145 of file TractionThrottle.hxx.

◆ release_listener_response()

Action openlcb::TractionThrottle::release_listener_response ( )
inlineprivate

Definition at line 343 of file TractionThrottle.hxx.

◆ release_step_2()

Action openlcb::TractionThrottle::release_step_2 ( )
inlineprivate

Definition at line 354 of file TractionThrottle.hxx.

◆ release_train()

Action openlcb::TractionThrottle::release_train ( )
inlineprivate

Definition at line 286 of file TractionThrottle.hxx.

◆ send_traction_message()

void openlcb::TractionThrottle::send_traction_message ( Payload  payload)
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_.

Parameters
payloadis the data contents of the message (e.g. TractionDefs::speed_set_payload(...).

Definition at line 798 of file TractionThrottle.hxx.

◆ send_traction_message_helper()

BufferPtr< GenMessage > openlcb::TractionThrottle::send_traction_message_helper ( Payload  payload)
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.

◆ send_traction_message_with_loopback()

void openlcb::TractionThrottle::send_traction_message_with_loopback ( Payload  payload)
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.

Parameters
payloadis the data contents of the message (e.g. TractionDefs::speed_set_payload(...).

Definition at line 722 of file TractionThrottle.hxx.

◆ set_assigned()

void openlcb::TractionThrottle::set_assigned ( )
inlineprivate

Definition at line 832 of file TractionThrottle.hxx.

◆ set_emergencystop()

void openlcb::TractionThrottle::set_emergencystop ( )
inlineoverridevirtual

Sets the train to emergency stop.

Implements openlcb::TrainImpl.

Definition at line 97 of file TractionThrottle.hxx.

◆ set_fn()

void openlcb::TractionThrottle::set_fn ( uint32_t  address,
uint16_t  value 
)
inlineoverridevirtual

Sets the value of a function.

Parameters
addressis 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).
valueis 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.

◆ set_listening()

void openlcb::TractionThrottle::set_listening ( )
inlineprivate

Definition at line 818 of file TractionThrottle.hxx.

◆ set_speed()

void openlcb::TractionThrottle::set_speed ( SpeedType  speed)
inlineoverridevirtual

Sets the speed of the locomotive.

Parameters
speedis 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.

◆ set_throttle_listener()

void openlcb::TractionThrottle::set_throttle_listener ( std::function< void(int fn)>  update_callback)
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.

Parameters
update_callbackwill 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.

◆ speed_reply()

void openlcb::TractionThrottle::speed_reply ( Buffer< GenMessage > *  msg)
inlineprivate

Invoked for TRACTION_CONTROL_REPLY messages coming in via the dispatcher.

Definition at line 478 of file TractionThrottle.hxx.

◆ target_node()

openlcb::NodeID openlcb::TractionThrottle::target_node ( )
inlineoverridevirtual
Returns
the controlled node (the train node) ID.

Implements openlcb::TractionThrottleInterface.

Definition at line 174 of file TractionThrottle.hxx.

◆ throttle_node()

openlcb::Node * openlcb::TractionThrottle::throttle_node ( )
inlineoverridevirtual
Returns
the controlling node (virtual node of the throttle, i.e., us.)

Implements openlcb::TractionThrottleInterface.

Definition at line 168 of file TractionThrottle.hxx.

◆ toggle_fn()

void openlcb::TractionThrottle::toggle_fn ( uint32_t  fn)
inlineoverridevirtual

Flips a function on<>off.

Implements openlcb::TractionThrottleInterface.

Definition at line 128 of file TractionThrottle.hxx.

Member Data Documentation

◆ assigned_

bool openlcb::TractionThrottle::assigned_ {false}
private

True if the assign controller has returned positive.

Definition at line 876 of file TractionThrottle.hxx.

◆ dst_

NodeID openlcb::TractionThrottle::dst_
private

Definition at line 881 of file TractionThrottle.hxx.

◆ estopActive_

bool openlcb::TractionThrottle::estopActive_ {false}
private

keep track if E-Stop is active

Definition at line 880 of file TractionThrottle.hxx.

◆ handler_

TractionResponseHandler openlcb::TractionThrottle::handler_ {iface(), node_}
private

Helper class for stateful query/return flows.

Definition at line 884 of file TractionThrottle.hxx.

◆ lastKnownFn_

std::map<uint32_t, uint16_t> openlcb::TractionThrottle::lastKnownFn_
private

Cache: all known function values.

Definition at line 890 of file TractionThrottle.hxx.

◆ lastSetSpeed_

SpeedType openlcb::TractionThrottle::lastSetSpeed_
private

Cache: Velocity value that we last commanded to the train.

Definition at line 888 of file TractionThrottle.hxx.

◆ listenConsist_

bool openlcb::TractionThrottle::listenConsist_ {false}
private

True if we also have a consist link with the assigned loco.

Definition at line 878 of file TractionThrottle.hxx.

◆ listenReplyHandler_

MessageHandler::GenericHandler openlcb::TractionThrottle::listenReplyHandler_
private
Initial value:
{
void listen_reply(Buffer< GenMessage > *msg)
Invoked for TRACTION_CONTROL_COMMAND messages coming in via the dispatcher.

Definition at line 869 of file TractionThrottle.hxx.

◆ node_

Node* openlcb::TractionThrottle::node_
private

Definition at line 882 of file TractionThrottle.hxx.

◆ pendingQueries_

unsigned openlcb::TractionThrottle::pendingQueries_ {0}
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.

◆ speedReplyHandler_

MessageHandler::GenericHandler openlcb::TractionThrottle::speedReplyHandler_
private
Initial value:
{
void speed_reply(Buffer< GenMessage > *msg)
Invoked for TRACTION_CONTROL_REPLY messages coming in via the dispatcher.

Definition at line 867 of file TractionThrottle.hxx.

◆ timer_

StateFlowTimer openlcb::TractionThrottle::timer_ {this}
private

Definition at line 874 of file TractionThrottle.hxx.

◆ updateCallback_

std::function<void(int fn)> openlcb::TractionThrottle::updateCallback_
private

Function to call when a different controller updates the train.

Definition at line 886 of file TractionThrottle.hxx.


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