|
Open Model Railroad Network (OpenMRN)
|
Represents a command to be sent to the track driver. More...
#include <Packet.hxx>
Classes | |
| struct | DCC_IDLE |
Public Member Functions | |
| Packet (DCC_IDLE i) | |
| Constructor generating a DCC IDLE packet. | |
| void | clear () |
| Resets the packet ot empty. | |
| bool | IsPacket () |
| void | set_cmd (uint8_t cmd) |
| Sets the packet to a standalone command. | |
| void | start_dcc_packet () |
| Initializes the packet structure for a regular DCC packet. | |
| void | start_dcc_svc_packet () |
| Initializes the packet structure for a regular DCC packet. | |
| void | add_dcc_address (DccShortAddress address) |
| Adds the header to the packet needed for addressing a DCC locomotive. | |
| void | add_dcc_address (DccLongAddress address) |
| Adds the header to the packet needed for addressing a DCC locomotive. | |
| 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_speed14 (bool is_fwd, bool light, unsigned speed) |
| Adds a speed-and-direction command (dcc baseline command) ot the packet. | |
| template<class A > | |
| 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. | |
| template<class A > | |
| void | set_dcc_speed28 (A a, bool is_fwd, unsigned speed) |
| 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. | |
| template<class A > | |
| void | set_dcc_speed128 (A a, bool is_fwd, unsigned speed) |
| 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_dcc_function9_12 (unsigned values) |
| Adds a DCC function group command to the packet. | |
| void | add_dcc_function13_20 (unsigned values) |
| Adds a DCC function group command to the packet. | |
| void | add_dcc_function21_28 (unsigned values) |
| Adds a DCC function group command to the packet. | |
| void | add_dcc_function_hi (uint8_t base, uint8_t 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 | add_dcc_analog_function (uint8_t fn, uint8_t value) |
| Adds a DCC analog function control command 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 | add_dcc_pom_read1 (unsigned cv_number) |
| Adds a DCC POM read single CV command and the xor byte. | |
| void | add_dcc_pom_write1 (unsigned cv_number, uint8_t value) |
| Adds a DCC POM write single CV command and the xor byte. | |
| 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_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_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 | 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. | |
| 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_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 | 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 | add_dcc_basic_accessory (unsigned address, bool is_activate) |
| Adds a DCC basic accessory decoder command packet and the checksum byte. | |
| 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 | add_dcc_ext_accessory (unsigned address, uint8_t aspect) |
| Adds a DCC extended accessory decoder command packet and the checksum byte. | |
| void | set_dcc_logon_enable (Defs::LogonEnableParam param, uint16_t cid, uint8_t session_id) |
| Sets the packet to a logon enable packet. | |
| void | set_dcc_select_shortinfo (uint64_t decoder_id) |
| Sets the packet to a Select+GetShortInfo packet. | |
| void | set_dcc_logon_assign (uint64_t decoder_id, uint16_t address) |
| Sets the packet to a logon assign packet. | |
| void | add_dcc_checksum () |
| Appends one byte to the packet payload that represents the XOR checksum for DCC. | |
| void | set_dcc_idle () |
| Creates a DCC idle packet. | |
| void | set_dcc_reset_all_decoders () |
| Creates a DCC reset-all-decoders packet. | |
| void | start_mm_packet () |
| Sets the packet type to marklin-motorola. | |
| 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_mm_speed (unsigned speed) |
| Sets the packet to a 14-step MM speed-and-light 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 | add_mm_new_fn (unsigned fn_num, bool value, unsigned speed) |
| Creates a speed-and-fn packet for the new MM format. | |
| void | mm_shift () |
| Shifts a MM packet to the second half of the packet buffer. | |
Static Public Attributes | |
| static const unsigned | MAX_PAYLOAD = DCC_PACKET_MAX_PAYLOAD |
| Maximum number of payload bytes. | |
| static const unsigned | EMERGENCY_STOP = DCC_PACKET_EMERGENCY_STOP |
| Send this speed step to emergency-stop the locomotive. | |
| static const unsigned | CHANGE_DIR = DCC_PACKET_EMERGENCY_STOP |
| Send this speed step to switch direction of the locomotive. | |
| static const unsigned | PAGE_REGISTER_ID = 0b101 |
| Used for page-preset packets. | |
Private Member Functions | |
| unsigned | set_mm_speed_bits (unsigned speed) |
| Sets the speed bits of an MM packet. | |
Additional Inherited Members | ||
Public Attributes inherited from DCCPacket | ||
| union { | ||
| uint8_t header_raw_data | ||
| struct pkt_t packet_header | ||
| struct cmd_t command_header | ||
| }; | ||
| uint8_t | dlc | |
| Specifies the number of used payload bytes. | ||
| uint8_t | payload [DCC_PACKET_MAX_PAYLOAD] | |
| Packet payload bytes. | ||
| uintptr_t | feedback_key | |
| An opaque key used by the hardware driver to attribute feedback information to the source of the packet. | ||
Represents a command to be sent to the track driver.
Most of the commands are "send packet X", but there are some that are controlling the track booster itself, such as "power off".
Definition at line 51 of file Packet.hxx.
|
inline |
Definition at line 64 of file Packet.hxx.
|
inline |
Constructor generating a DCC IDLE packet.
| i | indicator type. |
Definition at line 71 of file Packet.hxx.
| void dcc::Packet::add_dcc_accy_address | ( | bool | is_basic, |
| unsigned | address | ||
| ) |
Adds the header to the packet needed for addressing a DCC accessory (e.g.
for POM).
| is_basic | true for basic accessory, false for extended accessory |
| address | the 11-bit accessory address, 0..2047. This is NOT the user-visible address (that one is rotated by 3). For basic accessories this is addressing an output number. |
Definition at line 113 of file Packet.cxx.
| void dcc::Packet::add_dcc_address | ( | DccLongAddress | address | ) |
Adds the header to the packet needed for addressing a DCC locomotive.
| address | is the DCC (long) address. |
Definition at line 105 of file Packet.cxx.
| void dcc::Packet::add_dcc_address | ( | DccShortAddress | address | ) |
Adds the header to the packet needed for addressing a DCC locomotive.
| address | is the DCC (short) address. |
Definition at line 98 of file Packet.cxx.
| void dcc::Packet::add_dcc_analog_function | ( | uint8_t | fn, |
| uint8_t | value | ||
| ) |
Adds a DCC analog function control command to the packet.
| fn | is an analog function variable, 0 to 255. |
| value | to set it to, 0 to 255. |
Definition at line 248 of file Packet.cxx.
| void dcc::Packet::add_dcc_basic_accessory | ( | unsigned | address, |
| bool | is_activate | ||
| ) |
Adds a DCC basic accessory decoder command packet and the checksum byte.
| address | is the unencoded 12-bit address, containing both the A bits and the D bits in the DCC standard, in the range of 0..4095. The values of 4088-4095 are broadcast addresses. |
| is_activate | is true for setting bit C to one, false for setting bit C to zero. Usually commandstations set is_activate to one and use the lowest bit of the address to decide whether the turnouts should be closed or thrown. |
Definition at line 342 of file Packet.cxx.
| void dcc::Packet::add_dcc_binary_state | ( | uint16_t | fn, |
| bool | value | ||
| ) |
Adds a DCC binary state control command to the packet.
Automatically picks the short or long form, depending on the range of the argument.
| fn | is a binary function variable, 0 to 32767. |
| value | true/false, what to set to. |
Definition at line 232 of file Packet.cxx.
| void dcc::Packet::add_dcc_checksum | ( | ) |
Appends one byte to the packet payload that represents the XOR checksum for DCC.
Definition at line 54 of file Packet.cxx.
| void dcc::Packet::add_dcc_ext_accessory | ( | unsigned | address, |
| uint8_t | aspect | ||
| ) |
Adds a DCC extended accessory decoder command packet and the checksum byte.
| address | is the 11-bit binary address, 0..2047. No bits have to be inverted. This will be A10..A0 on the track. (To convert from a user address, see accy_address_user_to_binary in dcc::Defs.) |
| aspect | is the argument byte to the extended accessory. Traditionally this was used as an aspect for a signal decoder, but different accessories might have different interpretation of it. |
Definition at line 349 of file Packet.cxx.
| void dcc::Packet::add_dcc_function0_4 | ( | unsigned | values | ) |
Adds a DCC function group command to the packet.
The lowest numbered function is always at bit zero.
| values | are bitmask of functions to send to the loco. |
Definition at line 194 of file Packet.cxx.
|
inline |
Adds a DCC function group command to the packet.
The lowest numbered function is always at bit zero.
| values | are bitmask of functions to send to the loco. |
Definition at line 193 of file Packet.hxx.
|
inline |
Adds a DCC function group command to the packet.
The lowest numbered function is always at bit zero.
| values | are bitmask of functions to send to the loco. |
Definition at line 200 of file Packet.hxx.
| void dcc::Packet::add_dcc_function5_8 | ( | unsigned | values | ) |
Adds a DCC function group command to the packet.
The lowest numbered function is always at bit zero.
| values | are bitmask of functions to send to the loco. |
Definition at line 204 of file Packet.cxx.
| void dcc::Packet::add_dcc_function9_12 | ( | unsigned | values | ) |
Adds a DCC function group command to the packet.
The lowest numbered function is always at bit zero.
| values | are bitmask of functions to send to the loco. |
Definition at line 212 of file Packet.cxx.
| void dcc::Packet::add_dcc_function_hi | ( | uint8_t | base, |
| uint8_t | values | ||
| ) |
Adds a DCC function group command to the packet.
The lowest numbered function is always at bit zero.
| base | is a valid function number base, 13, 21, 29, 37, 45, 53 or 61. |
| values | are bitmask of functions to send to the loco. |
Definition at line 220 of file Packet.cxx.
| void dcc::Packet::add_dcc_pom_read1 | ( | unsigned | cv_number | ) |
Adds a DCC POM read single CV command and the xor byte.
This should be called after add_dcc_address.
| cv_number | which CV to read. |
Definition at line 265 of file Packet.cxx.
| void dcc::Packet::add_dcc_pom_write1 | ( | unsigned | cv_number, |
| uint8_t | value | ||
| ) |
Adds a DCC POM write single CV command and the xor byte.
This should be called after add_dcc_address.
| cv_number | which CV to write - 1, |
| value | is the value to set it to. |
Definition at line 270 of file Packet.cxx.
| void dcc::Packet::add_dcc_prog_command | ( | uint8_t | cmd_hi, |
| unsigned | cv_number, | ||
| uint8_t | value | ||
| ) |
Helper function for adding programming mode packets.
Definition at line 256 of file Packet.cxx.
| void dcc::Packet::add_dcc_speed128 | ( | bool | is_fwd, |
| unsigned | speed | ||
| ) |
Adds a speed-and-direction command (dcc extended command) for 128 speed steps to the packet.
Speed is maximum 126. This shoudl be called after add_dcc_address.
| is_fwd | true for forward speed |
| speed | the speed step to set (0..14) |
Definition at line 174 of file Packet.cxx.
Adds a speed-and-direction command (dcc baseline command) ot the packet.
Speed is maximum 14. This should be called after add_dcc_address.
| is_fwd | true for forward speed |
| light | true for light on, false for off |
| speed | the speed step to set (0..14) |
TODO(balazs.racz) add unittests.
Definition at line 125 of file Packet.cxx.
| void dcc::Packet::add_dcc_speed28 | ( | bool | is_fwd, |
| unsigned | speed | ||
| ) |
Adds a speed-and-direction command (dcc baseline command) to the packet.
Speed is maximum 28. This should be called after add_dcc_address.
| is_fwd | true for forward speed |
| speed | the speed step to set (0..14) |
Definition at line 150 of file Packet.cxx.
Sets the address and F0 bits of an MM packet to a specific loco address.
Sets the address bits of an MM packet to a specific loco address.
| a | is the train address |
| light | if true, light (f0) will be set to ON. |
Definition at line 417 of file Packet.cxx.
| void dcc::Packet::add_mm_new_fn | ( | unsigned | fn_num, |
| bool | value, | ||
| unsigned | speed | ||
| ) |
Creates a speed-and-fn packet for the new MM format.
| fn_num | is the function, valid values = 1..4 |
| value | is whether the funciton is on or off |
| speed | is the speed step (0..14). If it is set to emergency stop, then no function packet will be generated. |
Definition at line 500 of file Packet.cxx.
| void dcc::Packet::add_mm_new_speed | ( | bool | is_fwd, |
| unsigned | speed | ||
| ) |
Sets the packet to a direction-aware 14-step MM speed-and-light packet.
Max value of speed is 14.
| is_fwd | true for forward speed |
| speed | the speed step to set (0..14) |
Max value of speed is 14.
Definition at line 474 of file Packet.cxx.
| void dcc::Packet::add_mm_speed | ( | unsigned | speed | ) |
Sets the packet to a 14-step MM speed-and-light packet.
Max value of speed is 14. A special value of speed == CHANGE_DIR will signal direction change.
Definition at line 456 of file Packet.cxx.
|
inline |
Resets the packet ot empty.
Definition at line 77 of file Packet.hxx.
|
inline |
Definition at line 84 of file Packet.hxx.
| void dcc::Packet::mm_shift | ( | ) |
Shifts a MM packet to the second half of the packet buffer.
After this call another add_mm_speed call is valid, which will fill in the first half of the double packet.
Definition at line 534 of file Packet.cxx.
|
inline |
Sets the packet to a standalone command.
| cmd | is the standalone command to send. |
Definition at line 91 of file Packet.hxx.
Call this function after setting a basic accy address to set the accessory packet options.
| is_normal | true for normal, false for reverse |
| is_activate | true for activate, false for deactivate |
Definition at line 322 of file Packet.cxx.
| void dcc::Packet::set_dcc_idle | ( | ) |
| void dcc::Packet::set_dcc_logon_assign | ( | uint64_t | decoder_id, |
| uint16_t | address | ||
| ) |
Sets the packet to a logon assign packet.
| decoder_id | unique ID of the decoder (44 bits at LSB). |
| address | address to assign. Normally 14 bits, but the two high bits are reserved for option bits (these will be output inverted). |
Definition at line 384 of file Packet.cxx.
| void dcc::Packet::set_dcc_logon_enable | ( | Defs::LogonEnableParam | param, |
| uint16_t | cid, | ||
| uint8_t | session_id | ||
| ) |
Sets the packet to a logon enable packet.
| param | defines which decoders should be requested to logon. |
| cid | the command station unique ID hashed. |
| session_id | is the session id of the current power cycle. |
Definition at line 357 of file Packet.cxx.
| void dcc::Packet::set_dcc_reset_all_decoders | ( | ) |
Creates a DCC reset-all-decoders packet.
(Includes the checksum.)
Definition at line 90 of file Packet.cxx.
| void dcc::Packet::set_dcc_select_shortinfo | ( | uint64_t | decoder_id | ) |
Sets the packet to a Select+GetShortInfo packet.
| decoder_id | unique ID of the decoder (44 bits at LSB). |
Definition at line 369 of file Packet.cxx.
|
inline |
| a | the DCC address |
| is_fwd | true for forward speed |
| speed | the speed step to set (0..14) |
Definition at line 172 of file Packet.hxx.
|
inline |
Adds a speed-and-direction command (dcc baseline command) ot the packet.
Speed is maximum 14. This should be called after add_dcc_address.
| a | the DCC address |
| is_fwd | true for forward speed |
| light | true for light on, false for off |
| speed | the speed step to set (0..14) |
Definition at line 142 of file Packet.hxx.
|
inline |
| a | the DCC address |
| is_fwd | true for forward speed |
| speed | the speed step to set (0..14) |
Definition at line 157 of file Packet.hxx.
|
inline |
Sets the packet to a DCC service mode packet in Paged Mode, setting the page register.
This function does not need a DCC address. Includes the checksum.
| page | Page to set, 1 is the default page, zero is reserved, 255 max. |
Definition at line 273 of file Packet.hxx.
| void dcc::Packet::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.
This function does not need a DCC address. Includes the checksum.
| reg | register, 0 to 7. On the default page register 0 is CV1 (address). |
| value | Payload to check on that register. |
Definition at line 313 of file Packet.cxx.
| void dcc::Packet::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.
This function does not need a DCC address. Includes the checksum.
| reg | register, 0 to 7. On the default page register 0 is CV1 (address). |
| value | Payload to write to that register. 0 to 255. |
Definition at line 304 of file Packet.cxx.
| void dcc::Packet::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.
This function does not need a DCC address. (Includes the checksum.)
| cv_number | which CV to test - 1, |
| bit | is 0..7 to set which bit to test |
| desired | is true if bit==1 should be tested |
Definition at line 286 of file Packet.cxx.
| void dcc::Packet::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.
This function does not need a DCC address. (Includes the checksum.)
| cv_number | which CV to test - 1, |
| value | is the value to test. |
Definition at line 274 of file Packet.cxx.
| void dcc::Packet::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.
This function does not need a DCC address. (Includes the checksum.)
| cv_number | which CV to edit - 1, |
| bit | is 0..7 to define which bit to edit |
| desired | is true if bit:=1 should be written |
Definition at line 295 of file Packet.cxx.
| void dcc::Packet::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.
This function does not need a DCC address. (Includes the checksum.)
| cv_number | which CV to write - 1, |
| value | is the value to write. |
Definition at line 280 of file Packet.cxx.
|
private |
Sets the speed bits of an MM packet.
Clips speed to 15, avoids speed==1 and returns the final speed step number.
| speed | is the raw speed step value (0..14 but more are accepted). |
Definition at line 433 of file Packet.cxx.
|
inline |
Initializes the packet structure for a regular DCC packet.
Definition at line 99 of file Packet.hxx.
|
inline |
Initializes the packet structure for a regular DCC packet.
Definition at line 106 of file Packet.hxx.
| void dcc::Packet::start_mm_packet | ( | ) |
Sets the packet type to marklin-motorola.
Initilizes the packet with 18 zero bits.
Definition at line 400 of file Packet.cxx.
|
static |
Send this speed step to switch direction of the locomotive.
Only used for marklin-14-step speed commands.
Definition at line 59 of file Packet.hxx.
|
static |
Send this speed step to emergency-stop the locomotive.
Definition at line 56 of file Packet.hxx.
|
static |
Maximum number of payload bytes.
Definition at line 54 of file Packet.hxx.
|
static |
Used for page-preset packets.
Definition at line 62 of file Packet.hxx.