Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
dcc::AbstractTrain< P > Class Template Reference

AbstractTrain is a templated class for train implementations in a command station. More...

#include <Loco.hxx>

Inheritance diagram for dcc::AbstractTrain< P >:
dcc::PacketSource openlcb::TrainImpl

Public Member Functions

void set_speed (SpeedType speed) OVERRIDE
 Sets the train speed (asking for a high-priority outgoing update packet to be generated).
 
SpeedType get_speed () OVERRIDE
 
SpeedType get_commanded_speed () OVERRIDE
 
void set_emergencystop () OVERRIDE
 Sets the train to ESTOP state, generating an emergency stop packet.
 
bool get_emergencystop () OVERRIDE
 Gets the train's ESTOP state.
 
void set_fn (uint32_t address, uint16_t value) OVERRIDE
 Sets a function to a given value.
 
uint16_t get_fn (uint32_t address) OVERRIDE
 
uint32_t legacy_address () OVERRIDE
 
TrainAddressType legacy_address_type () OVERRIDE
 
- Public Member Functions inherited from dcc::PacketSource
virtual void get_next_packet (unsigned code, Packet *packet)=0
 Generates the next packet to send out to the track.
 
- Public Member Functions inherited from openlcb::TrainImpl
virtual SpeedType get_actual_speed ()
 Returns the actual speed of the locomotive, as provided by feedback from the decoder.
 

Protected Member Functions

unsigned get_effective_f0 ()
 
void update_f0_direction_changed ()
 Updates the f0 states after a direction change occurred.
 

Protected Attributes

p
 Payload – actual data we know about the train.
 

Static Protected Attributes

static constexpr unsigned VIRTF0_DIRECTIONAL_ENABLE = 0
 Function number of "enable directional F0".
 
static constexpr unsigned VIRTF0_BLANK_FWD = 1
 Function number of "Blank F0 Forward".
 
static constexpr unsigned VIRTF0_BLANK_REV = 2
 Function number of "Blank F0 Reverse".
 

Detailed Description

template<class P>
class dcc::AbstractTrain< P >

AbstractTrain is a templated class for train implementations in a command station.

It gives implementations for most functions that the OpenLCB command station neeeds, while using a compact structure for representing the state the command station needs to know about the train itself.

The only shared assumption about the train is that it has to participate in the standard command station packet loop. The exact protocol, number of speed steps, number of functions etc. are all defined by the template argument. The goal is to minimize the number of bytes needed to store information about one train in the RAM so that command stations with limited memory can still serve a large number of trains in their update loop.

Example implementations of the template payload are Dcc28Payload, Dcc128Payload, MMOldPayload, MMNewPayload.

Definition at line 105 of file Loco.hxx.

Constructor & Destructor Documentation

◆ AbstractTrain()

template<class P >
dcc::AbstractTrain< P >::AbstractTrain ( )
inline

Definition at line 108 of file Loco.hxx.

Member Function Documentation

◆ get_commanded_speed()

template<class P >
SpeedType dcc::AbstractTrain< P >::get_commanded_speed ( )
inlinevirtual
Returns
the commanded speed (which as of now is interpreted as the last set speed).

Reimplemented from openlcb::TrainImpl.

Definition at line 176 of file Loco.hxx.

◆ get_effective_f0()

template<class P >
unsigned dcc::AbstractTrain< P >::get_effective_f0 ( )
inlineprotected
Returns
the currently applicable value of F0 to be sent out to the packets (1 if on, 0 if off).

Definition at line 317 of file Loco.hxx.

◆ get_emergencystop()

template<class P >
bool dcc::AbstractTrain< P >::get_emergencystop ( )
inlinevirtual

Gets the train's ESTOP state.

Implements openlcb::TrainImpl.

Definition at line 195 of file Loco.hxx.

◆ get_fn()

template<class P >
uint16_t dcc::AbstractTrain< P >::get_fn ( uint32_t  address)
inlinevirtual
Returns
the last set value of a given function, or 0 if the function is not known.
Parameters
addressis the function address.

Implements openlcb::TrainImpl.

Definition at line 266 of file Loco.hxx.

◆ get_speed()

template<class P >
SpeedType dcc::AbstractTrain< P >::get_speed ( )
inlinevirtual
Returns
the last set speed.

Implements openlcb::TrainImpl.

Definition at line 168 of file Loco.hxx.

◆ legacy_address()

template<class P >
uint32_t dcc::AbstractTrain< P >::legacy_address ( )
inlinevirtual
Returns
the legacy address of this loco.

Implements openlcb::TrainImpl.

Definition at line 289 of file Loco.hxx.

◆ legacy_address_type()

template<class P >
TrainAddressType dcc::AbstractTrain< P >::legacy_address_type ( )
inlinevirtual
Returns
the legacy address type.

Implements openlcb::TrainImpl.

Definition at line 294 of file Loco.hxx.

◆ set_emergencystop()

template<class P >
void dcc::AbstractTrain< P >::set_emergencystop ( )
inlinevirtual

Sets the train to ESTOP state, generating an emergency stop packet.

Todo:
(Stuart.Baker) We should not just send a single E-Stop burst. It is possible that the loco was on dirt and missed this. Should send continuous E-Stop packets until the estop condition is cleared.

Implements openlcb::TrainImpl.

Definition at line 181 of file Loco.hxx.

◆ set_fn()

template<class P >
void dcc::AbstractTrain< P >::set_fn ( uint32_t  address,
uint16_t  value 
)
inlinevirtual

Sets a function to a given value.

Parameters
addressis the function number (0..28),
valueis 0 for funciton OFF, 1 for function ON.

Implements openlcb::TrainImpl.

Definition at line 201 of file Loco.hxx.

◆ set_speed()

template<class P >
void dcc::AbstractTrain< P >::set_speed ( SpeedType  speed)
inlinevirtual

Sets the train speed (asking for a high-priority outgoing update packet to be generated).

Parameters
speedis the desired speed that came from the throttle.

Implements openlcb::TrainImpl.

Definition at line 115 of file Loco.hxx.

◆ update_f0_direction_changed()

template<class P >
void dcc::AbstractTrain< P >::update_f0_direction_changed ( )
inlineprotected

Updates the f0 states after a direction change occurred.

Definition at line 334 of file Loco.hxx.

Member Data Documentation

◆ p

template<class P >
P dcc::AbstractTrain< P >::p
protected

Payload – actual data we know about the train.

Definition at line 351 of file Loco.hxx.

◆ VIRTF0_BLANK_FWD

template<class P >
constexpr unsigned dcc::AbstractTrain< P >::VIRTF0_BLANK_FWD = 1
staticconstexprprotected

Function number of "Blank F0 Forward".

Offset from config option dcc_virtual_f0_offset. When this function is enabled, F0 on the track packet will turn off when direction==forward, even if function 0 is set.

Definition at line 308 of file Loco.hxx.

◆ VIRTF0_BLANK_REV

template<class P >
constexpr unsigned dcc::AbstractTrain< P >::VIRTF0_BLANK_REV = 2
staticconstexprprotected

Function number of "Blank F0 Reverse".

Offset from config option dcc_virtual_f0_offset. When this function is enabled, F0 on the track packet will turn off when direction==reverse, even if function 0 is set.

Definition at line 313 of file Loco.hxx.

◆ VIRTF0_DIRECTIONAL_ENABLE

template<class P >
constexpr unsigned dcc::AbstractTrain< P >::VIRTF0_DIRECTIONAL_ENABLE = 0
staticconstexprprotected

Function number of "enable directional F0".

Offset from config option dcc_virtual_f0_offset. When this function is enabled, F0 is set and cleared separately for forward and reverse drive.

Definition at line 303 of file Loco.hxx.


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