35#ifndef _DCC_PACKET_HXX_
36#define _DCC_PACKET_HXX_
79 memset((
DCCPacket*)
this, 0,
sizeof(*
this));
86 return packet_header.
is_pkt;
95 header_raw_data = cmd;
224 uint8_t cmd_hi,
unsigned cv_number, uint8_t value);
257 unsigned cv_number,
unsigned bit,
bool expected);
377 void add_mm_new_fn(
unsigned fn_num,
bool value,
unsigned speed);
LogonEnableParam
Parameters for the Logon Enable command.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define DCC_PACKET_EMERGENCY_STOP
Send this speed step to emergency-stop the locomotive.
#define DCC_PACKET_MAX_PAYLOAD
Maximum number of payload bytes.
uint8_t send_long_preamble
1: send long preamble instead of packet.
Stores a DCC packet in memory.
uint8_t dlc
Specifies the number of used payload bytes.
Strongly typed wrapper representing a long DCC address.
Strongly typed wrapper representing a short DCC address.
Strongly typed wrapper representing a marklin-motorola protocol address.
Represents a command to be sent to the track driver.
void start_mm_packet()
Sets the packet type to marklin-motorola.
void set_dcc_reset_all_decoders()
Creates a DCC reset-all-decoders packet.
void add_mm_new_speed(bool is_fwd, unsigned speed)
Sets the packet to a direction-aware 14-step MM speed-and-light packet.
void set_dcc_speed14(A a, bool is_fwd, bool light, unsigned speed)
Adds a speed-and-direction command (dcc baseline command) ot the packet.
void add_dcc_speed28(bool is_fwd, unsigned speed)
Adds a speed-and-direction command (dcc baseline command) to the packet.
void start_dcc_svc_packet()
Initializes the packet structure for a regular DCC packet.
void add_dcc_pom_write1(unsigned cv_number, uint8_t value)
Adds a DCC POM write single CV command and the xor byte.
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_dcc_basic_accessory(unsigned address, bool is_activate)
Adds a DCC basic accessory decoder command packet and the checksum byte.
void set_dcc_speed28(A a, bool is_fwd, unsigned speed)
void add_mm_speed(unsigned speed)
Sets the packet to a 14-step MM speed-and-light packet.
void set_dcc_svc_write_byte(unsigned cv_number, uint8_t value)
Sets the packet to a DCC service mode packet writing the contents of an entire CV.
void set_dcc_basic_accy_params(bool is_normal, bool is_activate)
Call this function after setting a basic accy address to set the accessory packet options.
void set_dcc_svc_paged_verify_reg(uint8_t reg, uint8_t value)
Sets the packet to a DCC service mode packet in Paged Mode, setting the page register.
void set_dcc_logon_assign(uint64_t decoder_id, uint16_t address)
Sets the packet to a logon assign packet.
void add_dcc_function_hi(uint8_t base, uint8_t values)
Adds a DCC function group command to the packet.
void set_dcc_svc_write_bit(unsigned cv_number, unsigned bit, bool desired)
Sets the packet to a DCC service mode packet verifying the contents of a single bit in a CV.
unsigned set_mm_speed_bits(unsigned speed)
Sets the speed bits of an MM packet.
void add_dcc_pom_read1(unsigned cv_number)
Adds a DCC POM read single CV command and the xor byte.
void add_dcc_analog_function(uint8_t fn, uint8_t value)
Adds a DCC analog function control command to the packet.
void set_dcc_select_shortinfo(uint64_t decoder_id)
Sets the packet to a Select+GetShortInfo packet.
Packet(DCC_IDLE i)
Constructor generating a DCC IDLE packet.
void add_dcc_speed128(bool is_fwd, unsigned speed)
Adds a speed-and-direction command (dcc extended command) for 128 speed steps to the packet.
void add_dcc_prog_command(uint8_t cmd_hi, unsigned cv_number, uint8_t value)
Helper function for adding programming mode packets.
void set_dcc_svc_verify_byte(unsigned cv_number, uint8_t value)
Sets the packet to a DCC service mode packet verifying the contents of an entire CV.
void set_dcc_svc_paged_set_page(unsigned page=1)
Sets the packet to a DCC service mode packet in Paged Mode, setting the page register.
void set_dcc_svc_verify_bit(unsigned cv_number, unsigned bit, bool expected)
Sets the packet to a DCC service mode packet verifying the contents of a single bit in a CV.
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 clear()
Resets the packet ot empty.
void add_dcc_speed14(bool is_fwd, bool light, unsigned speed)
Adds a speed-and-direction command (dcc baseline command) ot the packet.
static const unsigned PAGE_REGISTER_ID
Used for page-preset packets.
void set_cmd(uint8_t cmd)
Sets the packet to a standalone command.
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.
void set_dcc_logon_enable(Defs::LogonEnableParam param, uint16_t cid, uint8_t session_id)
Sets the packet to a logon enable packet.
static const unsigned MAX_PAYLOAD
Maximum number of payload bytes.
void set_dcc_speed128(A a, bool is_fwd, unsigned speed)
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_dcc_ext_accessory(unsigned address, uint8_t aspect)
Adds a DCC extended accessory decoder command packet and the checksum byte.
void add_dcc_checksum()
Appends one byte to the packet payload that represents the XOR checksum for DCC.
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_accy_address(bool is_basic, unsigned address)
Adds the header to the packet needed for addressing a DCC accessory (e.g.
void add_dcc_function13_20(unsigned values)
Adds a DCC function group command to the packet.
void add_dcc_binary_state(uint16_t fn, bool value)
Adds a DCC binary state control command to the packet.
void mm_shift()
Shifts a MM packet to the second half of the packet buffer.
void set_dcc_svc_paged_write_reg(uint8_t reg, uint8_t value)
Sets the packet to a DCC service mode packet in Paged Mode, setting any register.
void add_dcc_function9_12(unsigned values)
Adds a DCC function group command to the packet.
void set_dcc_idle()
Creates a DCC idle packet.