48template <> DccTrain<Dcc28Payload>::~DccTrain()
50 packet_processor_remove_refresh_source(
this);
53template <> DccTrain<Dcc128Payload>::~DccTrain()
55 packet_processor_remove_refresh_source(
this);
68 else if (address < 13)
72 else if (address <= 68)
74 return FUNCTION13 + (address - 13) / 8;
80template <
class Payload>
84 if (this->p.isShortAddress_)
94 code = MIN_REFRESH + this->p.nextRefresh_++;
95 if (this->p.nextRefresh_ >
MAX_REFRESH - MIN_REFRESH)
97 this->p.nextRefresh_ = 0;
110 (this->p.fn_ & 0x1E) | this->get_effective_f0());
139 unsigned s = code - FUNCTION29;
145 this->p.add_dcc_estop_to_packet(packet);
150 LOG(
WARNING,
"Unknown packet generation code: %x", code);
154 if (this->p.directionChanged_)
157 this->p.directionChanged_ = 0;
160 this->p.add_dcc_speed_to_packet(packet);
169 packet_processor_add_refresh_source(
this);
172MMOldTrain::~MMOldTrain()
174 packet_processor_remove_refresh_source(
this);
208 packet_processor_add_refresh_source(
this);
211MMNewTrain::~MMNewTrain()
213 packet_processor_remove_refresh_source(
this);
252 else if (code == SPEED)
267 else if (MM_F1 <= code && code <= MM_F4)
269 unsigned fnum = code + 1 - MM_F1;
void createtrains()
Forces compilation of all existing train implementations even though many are actually templates.
@ MAX_REFRESH
@TODO(balazs.racz) choose adaptive max-refresh based on how many functions are actually in use for th...
unsigned get_effective_f0()
MMOldPayload p
Payload – actual data we know about the train.
TrainImpl class for a DCC locomotive.
void get_next_packet(unsigned code, Packet *packet) OVERRIDE
Generates next outgoing packet.
TrainImpl structure for Marklin-Motorola v2 protocol locomotives.
MMNewTrain(MMAddress a)
Constructor.
void get_next_packet(unsigned code, Packet *packet) OVERRIDE
Generates next outgoing packet.
TrainImpl structure for Marklin-Motorola v1 protocol locomotives.
MMOldTrain(MMAddress a)
Constructor.
void get_next_packet(unsigned code, Packet *packet) OVERRIDE
Generates next outgoing packet.
#define LOG(level, message...)
Conditionally write a message to the logging output.
static const int WARNING
Loglevel that is always printed, reporting a warning or a retryable error.
uint8_t rept_count
The packet will be sent 1 + rept_count times to the wire.
Strongly typed wrapper representing a long DCC address.
static unsigned get_fn_update_code(unsigned address)
Strongly typed wrapper representing a short DCC address.
Strongly typed wrapper representing a marklin-motorola protocol address.
uint8_t value
Address value.
unsigned nextRefresh_
internal refresh cycle state machine
unsigned speed_
Speed step we last set.
unsigned direction_
0: forward, 1: reverse
unsigned directionChanged_
Whether the direction change packet still needs to go out.
unsigned address_
largest address allowed is 80, but we keep a few more bits around to allow for an extension to arbitr...
unsigned fn_
function f0-f4.
unsigned address_
largest address allowed is 80, but we keep a few more bits around to allow for an extension to arbitr...
unsigned directionChanged_
Whether the direction change packet still needs to go out.
unsigned speed_
Speed step we last set.
unsigned direction_
0: forward, 1: reverse
Represents a command to be sent to the track driver.
void start_mm_packet()
Sets the packet type to marklin-motorola.
void add_mm_new_speed(bool is_fwd, unsigned speed)
Sets the packet to a direction-aware 14-step MM speed-and-light packet.
static const unsigned EMERGENCY_STOP
Send this speed step to emergency-stop the locomotive.
void add_dcc_function21_28(unsigned values)
Adds a DCC function group command to the packet.
void add_mm_speed(unsigned speed)
Sets the packet to a 14-step MM speed-and-light packet.
void add_dcc_function_hi(uint8_t base, uint8_t values)
Adds a DCC function group command to the packet.
void add_dcc_function0_4(unsigned values)
Adds a DCC function group command to the packet.
void add_dcc_function5_8(unsigned values)
Adds a DCC function group command to the packet.
void add_mm_new_fn(unsigned fn_num, bool value, unsigned speed)
Creates a speed-and-fn packet for the new MM format.
void start_dcc_packet()
Initializes the packet structure for a regular DCC packet.
static const unsigned CHANGE_DIR
Send this speed step to switch direction of the locomotive.
void add_dcc_address(DccShortAddress address)
Adds the header to the packet needed for addressing a DCC locomotive.
void add_mm_address(MMAddress address, bool light)
Sets the address and F0 bits of an MM packet to a specific loco address.
void add_dcc_function13_20(unsigned values)
Adds a DCC function group command to the packet.
void mm_shift()
Shifts a MM packet to the second half of the packet buffer.
void add_dcc_function9_12(unsigned values)
Adds a DCC function group command to the packet.