|
Open Model Railroad Network (OpenMRN)
|
Useful definitions for the traction modem. More...
#include <TractionModemDefs.hxx>
Classes | |
| struct | CRC |
| struct | Header |
| The header of a message. More... | |
| struct | Message |
| The definition of a message. More... | |
Public Types | |
| enum | Command : uint16_t { CMD_PING = 0x0000 , CMD_NOP = 0x0001 , CMD_REBOOT = 0x0002 , CMD_BAUD_RATE_QUERY = 0x0003 , CMD_BAUD_RATE_REQUEST = 0x0004 , CMD_SPEED_SET = 0x0100 , CMD_FN_SET = 0x0101 , CMD_ESTOP_SET = 0x0102 , CMD_SPEED_QUERY = 0x0110 , CMD_FN_QUERY = 0x0111 , CMD_DC_DCC_PRESENT = 0x0200 , CMD_WIRELESS_PRESENT = 0x0201 , CMD_MEM_R = 0x1000 , CMD_MEM_W = 0x1001 , RESP_PING = RESPONSE | CMD_PING , RESP_BAUD_RATE_QUERY = RESPONSE | CMD_BAUD_RATE_QUERY , RESP_SPEED_SET = RESPONSE | CMD_SPEED_SET , RESP_FN_SET = RESPONSE | CMD_FN_SET , RESP_ESTOP_SET = RESPONSE | CMD_ESTOP_SET , RESP_SPEED_QUERY = RESPONSE | CMD_SPEED_QUERY , RESP_FN_QUERY = RESPONSE | CMD_FN_QUERY , RESP_DC_DCC_PRESENT = RESPONSE | CMD_DC_DCC_PRESENT , RESP_WIRELESS_PRESENT = RESPONSE | CMD_WIRELESS_PRESENT , RESP_MEM_R = RESPONSE | CMD_MEM_R , RESP_MEM_W = RESPONSE | CMD_MEM_W } |
| Command values. More... | |
| using | Payload = std::string |
Static Public Member Functions | |
| static Payload | get_wireless_present_payload (bool is_present) |
| Computes payload for the wireless present message. | |
| static Payload | get_fn_set_payload (unsigned fn, uint16_t value) |
| Computes payload to set a function. | |
| static Payload | get_speed_set_payload (openlcb::Velocity v) |
| Computes payload to set speed and direction. | |
| static Payload | get_estop_payload () |
| Computes payload to set estop. | |
| static Payload | get_memr_payload (uint8_t space, uint32_t address, uint8_t count) |
| Computes payload to read some data. | |
| static Payload | get_memw_payload (uint8_t space, uint32_t address, const std::string &data) |
| Computes payload to write some data. | |
| static Payload | get_memw_payload (uint8_t space, uint32_t address, const uint8_t *buf, size_t count) |
| Computes payload to write some data. | |
| static void | append_uint32 (Payload *p, uint32_t v) |
| Appends an uint32_t in network byte order to the payload. | |
| static void | append_uint16 (Payload *p, uint16_t v) |
| Appends an uint16_t in network byte order to the payload. | |
| static void | append_uint8 (Payload *p, uint8_t v) |
| Appends an uint8_t to the payload. | |
| static void | prepare (Payload *p, Command cmd, uint16_t len) |
| Prepares the header of a packet. | |
| static void | append_crc (Payload *p) |
| Computes and appends the CRC to the payload. | |
| static uint32_t | get_uint32 (const Payload &p, unsigned ofs) |
| Extract uint32_t value from a given offset in a wire formatted payload. | |
| static uint16_t | get_uint16 (const Payload &p, unsigned ofs) |
| Extract uint16_t value from a given offset in a wire formatted payload. | |
| static const CRC | get_crc (const Payload &p, uint16_t length) |
| Extract the CRC value(s) from a given payload. | |
| static bool | is_valid (const Payload &p) |
| Verifies that a given payload is a valid packet. | |
Static Public Attributes | |
| static constexpr uint32_t | PREAMBLE = 0x41d2c37a |
| Every command starts with these bytes. | |
| static constexpr char | PREAMBLE_FIRST = 0x41 |
| First byte of the preamble. | |
| static constexpr uint16_t | RESPONSE = 0x8000 |
| The most significant bit of each command means "response" to a previous message. | |
| static constexpr unsigned | LEN_HEADER = 4+2+2 |
| Length of a the header. 4 bytes preamble, 2 bytes cmd, 2 bytes length. | |
| static constexpr unsigned | LEN_BASE = 14 |
| Length of a zero-payload packet. | |
| static constexpr unsigned | LEN_FN_SET = 6 |
| Length of the data payload of a set function packet. | |
| static constexpr unsigned | LEN_SPEED_SET = 1 |
| Length of the data payload of a set speed packet. | |
| static constexpr unsigned | LEN_ESTOP_SET = 0 |
| Length of the data payload of a set estop packet. | |
| static constexpr unsigned | LEN_WIRELESS_PRESENT = 1 |
| Length of the data payload of a wireless present packet. | |
| static constexpr unsigned | LEN_MEM_R = 6 |
| Length of the data payload of a set estop packet. | |
| static constexpr unsigned | LEN_MEM_W = 5 |
| Base length of the data, add the number of payload bytes. | |
| static constexpr unsigned | MAX_LEN = 512 |
| Maximum allowed len value. | |
| static constexpr unsigned | OFS_CMD = 4 |
| Offset of the command in the packet. | |
| static constexpr unsigned | OFS_LEN = 6 |
| Offset of the length in the packet. | |
| static constexpr unsigned | OFS_DATA = 8 |
| Offset of the first data byte in the packet. | |
Useful definitions for the traction modem.
Definition at line 46 of file TractionModemDefs.hxx.
| using traction_modem::Defs::Payload = std::string |
Definition at line 48 of file TractionModemDefs.hxx.
| enum traction_modem::Defs::Command : uint16_t |
Command values.
Definition at line 60 of file TractionModemDefs.hxx.
|
inlinestatic |
Computes and appends the CRC to the payload.
| p | wire formatted payload, including prepended preamble, to append to |
Definition at line 322 of file TractionModemDefs.hxx.
|
inlinestatic |
Appends an uint16_t in network byte order to the payload.
| p | wire formatted payload to append to |
| v | value to append |
Definition at line 293 of file TractionModemDefs.hxx.
|
inlinestatic |
Appends an uint32_t in network byte order to the payload.
| p | wire formatted payload to append to |
| v | value to append |
Definition at line 282 of file TractionModemDefs.hxx.
|
inlinestatic |
Appends an uint8_t to the payload.
| p | wire formatted payload to append to |
| v | value to append |
Definition at line 302 of file TractionModemDefs.hxx.
|
inlinestatic |
Extract the CRC value(s) from a given payload.
The assumption is that p contains a valid (correctly formatted) message. Additional partial or complete messages contained within p are ignored.
| p | wire formatted payload |
| length | length field from the Header in host endianess (length in bytes of the message data) |
Definition at line 368 of file TractionModemDefs.hxx.
|
inlinestatic |
Computes payload to set estop.
Definition at line 222 of file TractionModemDefs.hxx.
|
inlinestatic |
Computes payload to set a function.
| fn | function number |
| value | function value. For binary functions, 0 is off, 1 is on. |
Definition at line 196 of file TractionModemDefs.hxx.
|
inlinestatic |
Computes payload to read some data.
| space | address space |
| address | address offset within address space |
| count | size of read data requested in bytes |
Definition at line 236 of file TractionModemDefs.hxx.
|
inlinestatic |
Computes payload to write some data.
| space | address space |
| address | address offset within address space |
| data | data to write |
Definition at line 254 of file TractionModemDefs.hxx.
|
inlinestatic |
Computes payload to write some data.
| space | address space |
| address | address offset within address space |
| buf | data to write |
| count | size of data to write in bytes |
Definition at line 266 of file TractionModemDefs.hxx.
|
inlinestatic |
Computes payload to set speed and direction.
| v | speed and direction data. |
Definition at line 210 of file TractionModemDefs.hxx.
|
inlinestatic |
Extract uint16_t value from a given offset in a wire formatted payload.
| p | wire formatted payload |
| ofs | byte offset to start from for extraction |
Definition at line 351 of file TractionModemDefs.hxx.
|
inlinestatic |
Extract uint32_t value from a given offset in a wire formatted payload.
| p | wire formatted payload |
| ofs | byte offset to start from for extraction |
Definition at line 336 of file TractionModemDefs.hxx.
|
inlinestatic |
Computes payload for the wireless present message.
| is_present | true if "present", else false |
Definition at line 182 of file TractionModemDefs.hxx.
|
inlinestatic |
Verifies that a given payload is a valid packet.
This checks for the preamble and the length matching what is needed for the packet size. Does not check the CRC.
| p | wire formatted payload |
Definition at line 382 of file TractionModemDefs.hxx.
|
inlinestatic |
Prepares the header of a packet.
| p | packet buffer. |
| cmd | command to add to header. |
| len | length of data payload that will come after the header. |
Definition at line 311 of file TractionModemDefs.hxx.
|
staticconstexpr |
Length of a zero-payload packet.
4 bytes preamble, 2 bytes cmd, 2 bytes length, 6 bytes CRC.
Definition at line 109 of file TractionModemDefs.hxx.
|
staticconstexpr |
Length of the data payload of a set estop packet.
Definition at line 115 of file TractionModemDefs.hxx.
|
staticconstexpr |
Length of the data payload of a set function packet.
Definition at line 111 of file TractionModemDefs.hxx.
|
staticconstexpr |
Length of a the header. 4 bytes preamble, 2 bytes cmd, 2 bytes length.
Definition at line 105 of file TractionModemDefs.hxx.
|
staticconstexpr |
Length of the data payload of a set estop packet.
Definition at line 119 of file TractionModemDefs.hxx.
|
staticconstexpr |
Base length of the data, add the number of payload bytes.
Definition at line 121 of file TractionModemDefs.hxx.
|
staticconstexpr |
Length of the data payload of a set speed packet.
Definition at line 113 of file TractionModemDefs.hxx.
|
staticconstexpr |
Length of the data payload of a wireless present packet.
Definition at line 117 of file TractionModemDefs.hxx.
|
staticconstexpr |
Maximum allowed len value.
Definition at line 124 of file TractionModemDefs.hxx.
|
staticconstexpr |
Offset of the command in the packet.
Definition at line 127 of file TractionModemDefs.hxx.
|
staticconstexpr |
Offset of the first data byte in the packet.
Definition at line 131 of file TractionModemDefs.hxx.
|
staticconstexpr |
Offset of the length in the packet.
Definition at line 129 of file TractionModemDefs.hxx.
|
staticconstexpr |
Every command starts with these bytes.
Definition at line 51 of file TractionModemDefs.hxx.
|
staticconstexpr |
First byte of the preamble.
Definition at line 53 of file TractionModemDefs.hxx.
|
staticconstexpr |
The most significant bit of each command means "response" to a previous message.
Definition at line 57 of file TractionModemDefs.hxx.