Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::MemoryConfigDefs Struct Reference

Static constants and helper functions related to the Memory Configuration Protocol. More...

#include <MemoryConfigDefs.hxx>

Public Types

enum  commands {
  COMMAND_MASK = 0xFC , COMMAND_FLAG_MASK = 0x03 , COMMAND_PRESENT_MASK = 0x01 , COMMAND_REPLY_BIT_FOR_RW = 0x10 ,
  COMMAND_WRITE = 0x00 , COMMAND_WRITE_UNDER_MASK = 0x08 , COMMAND_WRITE_REPLY = 0x10 , COMMAND_WRITE_FAILED = 0x18 ,
  COMMAND_WRITE_STREAM = 0x20 , COMMAND_WRITE_STREAM_REPLY = 0x30 , COMMAND_WRITE_STREAM_FAILED = 0x38 , COMMAND_READ = 0x40 ,
  COMMAND_READ_REPLY = 0x50 , COMMAND_READ_FAILED = 0x58 , COMMAND_READ_STREAM = 0x60 , COMMAND_READ_STREAM_REPLY = 0x70 ,
  COMMAND_READ_STREAM_FAILED = 0x78 , COMMAND_MAX_FOR_RW = 0x80 , COMMAND_OPTIONS = 0x80 , COMMAND_OPTIONS_REPLY = 0x82 ,
  COMMAND_INFORMATION = 0x84 , COMMAND_INFORMATION_REPLY = 0x86 , COMMAND_LOCK = 0x88 , COMMAND_LOCK_REPLY = 0x8A ,
  COMMAND_UNIQUE_ID = 0x8C , COMMAND_UNIQUE_ID_REPLY = 0x8D , COMMAND_UPDATE_COMPLETE = 0xA8 , COMMAND_RESET = 0xA9 ,
  COMMAND_FACTORY_RESET = 0xAA , COMMAND_ENTER_BOOTLOADER = 0xAB , COMMAND_FREEZE = 0xA1 , COMMAND_UNFREEZE = 0xA0 ,
  COMMAND_PRESENT = 0x01 , COMMAND_CDI = 0x03 , COMMAND_ALL_MEMORY = 0x02 , COMMAND_CONFIG = 0x01
}
 Possible Commands for a configuration datagram. More...
 
enum  spaces {
  SPACE_SPECIAL = 0xFC , SPACE_CDI = 0xFF , SPACE_ALL_MEMORY = 0xFE , SPACE_CONFIG = 0xFD ,
  SPACE_ACDI_SYS = 0xFC , SPACE_ACDI_USR = 0xFB , SPACE_FDI = 0xFA , SPACE_FUNCTION = 0xF9 ,
  SPACE_DCC_CV = 0xF8 , SPACE_FIRMWARE = 0xEF
}
 Possible memory spaces. More...
 
enum  available {
  AVAIL_WUM = 0x8000 , AVAIL_UR = 0x4000 , AVAIL_UW = 0x2000 , AVAIL_SR = 0x1000 ,
  AVAIL_R0xFC = 0x0800 , AVAIL_R0xFB = 0x0400 , AVAIL_W0xFB = 0x0200
}
 Possible available options. More...
 
enum  lengths {
  LENGTH_1 = 0x80 , LENGTH_2 = 0x40 , LENGTH_4 = 0x20 , LENGTH_63 = 0x10 ,
  LENGTH_ARBITRARY = 0x02 , LENGTH_STREAM = 0x01
}
 Possible supported write lengths. More...
 
enum  flags { FLAG_RO = 0x01 , FLAG_NZLA = 0x02 }
 Possible address space information flags. More...
 
enum  errors { ERROR_SPACE_NOT_KNOWN = Defs::ERROR_INVALID_ARGS | 0x0001 , ERROR_OUT_OF_BOUNDS = Defs::ERROR_INVALID_ARGS | 0x0002 , ERROR_WRITE_TO_RO = Defs::ERROR_INVALID_ARGS | 0x0003 }
 
using DatagramPayload = string
 

Static Public Member Functions

static bool is_special_space (uint8_t space)
 
static DatagramPayload write_datagram (uint8_t space, uint32_t offset, const string &data="")
 
static DatagramPayload read_datagram (uint8_t space, uint32_t offset, uint8_t length)
 
static DatagramPayload read_stream_datagram (uint8_t space, uint32_t offset, uint8_t dst_stream_id, uint32_t length=0xFFFFFFFF)
 
static bool payload_min_length_check (const DatagramPayload &payload, unsigned extra)
 
static uint8_t get_space (const DatagramPayload &payload)
 
static unsigned get_payload_offset (const DatagramPayload &payload)
 
static uint32_t get_address (const DatagramPayload &payload)
 
static const uint8_t * payload_bytes (const DatagramPayload &payload)
 Type casts a DatagramPayload to an array of bytes.
 

Static Public Attributes

static constexpr unsigned MAX_DATAGRAM_RW_BYTES = 64
 

Private Member Functions

 MemoryConfigDefs ()
 Do not instantiate this class.
 

Detailed Description

Static constants and helper functions related to the Memory Configuration Protocol.

Definition at line 47 of file MemoryConfigDefs.hxx.

Member Typedef Documentation

◆ DatagramPayload

using openlcb::MemoryConfigDefs::DatagramPayload = string

Definition at line 49 of file MemoryConfigDefs.hxx.

Member Enumeration Documentation

◆ available

Possible available options.

Enumerator
AVAIL_WUM 

write under mask supported

AVAIL_UR 

unaligned reads supported

AVAIL_UW 

unaligned writes supported

AVAIL_SR 

stream reads supported

Todo:
This is a proposed value, see https://github.com/openlcb/documents/issues/57
AVAIL_R0xFC 

read from adddress space 0xFC available

AVAIL_R0xFB 

read from adddress space 0xFB available

AVAIL_W0xFB 

write from adddress space 0xFB available

Definition at line 114 of file MemoryConfigDefs.hxx.

◆ commands

Possible Commands for a configuration datagram.

Enumerator
COMMAND_FLAG_MASK 

mask for special memory space flags

COMMAND_PRESENT_MASK 

mask for address space present bit

COMMAND_REPLY_BIT_FOR_RW 

This bit is present in REPLY commands for read-write commands.

COMMAND_WRITE 

command to write data to address space

COMMAND_WRITE_UNDER_MASK 

command to write data under mask

COMMAND_WRITE_REPLY 

reply to write data to address space

COMMAND_WRITE_FAILED 

failed to write data to address space

COMMAND_WRITE_STREAM 

command to write data using a stream

COMMAND_WRITE_STREAM_REPLY 

reply to write data using a stream

COMMAND_WRITE_STREAM_FAILED 

failed to write data using a stream

COMMAND_READ 

command to read data from address space

COMMAND_READ_REPLY 

reply to read data from address space

COMMAND_READ_FAILED 

failed to read data from address space

COMMAND_READ_STREAM 

command to read data using a stream

COMMAND_READ_STREAM_REPLY 

reply to read data using a stream

COMMAND_READ_STREAM_FAILED 

failed to read data using a stream

COMMAND_MAX_FOR_RW 

command <= this value have fixed bit arrangement.

COMMAND_LOCK 

lock the configuration space

COMMAND_LOCK_REPLY 

unlock the configuration space

COMMAND_UNIQUE_ID 

ask for a node unique id

COMMAND_UNIQUE_ID_REPLY 

node unique id

COMMAND_UPDATE_COMPLETE 

indicate that a sequence of commands is complete

COMMAND_RESET 

reset node to its power on state

COMMAND_FACTORY_RESET 

reset node to factory defaults

COMMAND_ENTER_BOOTLOADER 

reset node in bootloader mode

COMMAND_FREEZE 

freeze operation of node

COMMAND_UNFREEZE 

unfreeze operation of node

COMMAND_PRESENT 

address space is present

COMMAND_CDI 

flags for a CDI space

COMMAND_ALL_MEMORY 

flags for an all memory space

COMMAND_CONFIG 

flags for a config memory space

Definition at line 53 of file MemoryConfigDefs.hxx.

◆ errors

enum openlcb::MemoryConfigDefs::errors

Definition at line 147 of file MemoryConfigDefs.hxx.

◆ flags

Possible address space information flags.

Enumerator
FLAG_RO 

space is read only

FLAG_NZLA 

space has a nonzero low address

Definition at line 141 of file MemoryConfigDefs.hxx.

◆ lengths

Possible supported write lengths.

Enumerator
LENGTH_1 

write length of 1 supported

LENGTH_2 

write length of 2 supported

LENGTH_4 

write length of 4 supported

LENGTH_63 

write length of 64 supported

LENGTH_ARBITRARY 

arbitrary write of any length supported

LENGTH_STREAM 

stream writes supported

Definition at line 129 of file MemoryConfigDefs.hxx.

◆ spaces

Possible memory spaces.

Enumerator
SPACE_SPECIAL 

offset for the special memory spaces

SPACE_CDI 

CDI space.

SPACE_ALL_MEMORY 

all memory space

SPACE_CONFIG 

config memory space

SPACE_ACDI_SYS 

read-only ACDI space

SPACE_ACDI_USR 

read-write ACDI space

SPACE_FDI 

read-only for function definition XML

SPACE_FUNCTION 

read-write for function data

SPACE_DCC_CV 

proxy space for DCC functions

SPACE_FIRMWARE 

firmware upgrade space

Definition at line 98 of file MemoryConfigDefs.hxx.

Member Function Documentation

◆ get_address()

static uint32_t openlcb::MemoryConfigDefs::get_address ( const DatagramPayload &  payload)
inlinestatic
Parameters
payloadis a datagram read or write request or response
Returns
the address field from the datagram

Definition at line 284 of file MemoryConfigDefs.hxx.

◆ get_payload_offset()

static unsigned openlcb::MemoryConfigDefs::get_payload_offset ( const DatagramPayload &  payload)
inlinestatic

Definition at line 269 of file MemoryConfigDefs.hxx.

◆ get_space()

static uint8_t openlcb::MemoryConfigDefs::get_space ( const DatagramPayload &  payload)
inlinestatic
Returns
addressed memory space number.
Parameters
payloadis a read or write datagram request or response message

Definition at line 259 of file MemoryConfigDefs.hxx.

◆ is_special_space()

static bool openlcb::MemoryConfigDefs::is_special_space ( uint8_t  space)
inlinestatic

Definition at line 156 of file MemoryConfigDefs.hxx.

◆ payload_bytes()

static const uint8_t * openlcb::MemoryConfigDefs::payload_bytes ( const DatagramPayload &  payload)
inlinestatic

Type casts a DatagramPayload to an array of bytes.

Parameters
payloaddatagram
Returns
byte array pointing to the same memory

Definition at line 300 of file MemoryConfigDefs.hxx.

◆ payload_min_length_check()

static bool openlcb::MemoryConfigDefs::payload_min_length_check ( const DatagramPayload &  payload,
unsigned  extra 
)
inlinestatic
Returns
true if the payload has minimum number of bytes you need in a read or write datagram message to cover for the necessary fields (command, offset, space).
Parameters
payloadis a datagram (read or write, request or response)
extrais the needed bytes after address and space, usually 0 for write and 1 for read.

Definition at line 241 of file MemoryConfigDefs.hxx.

◆ read_datagram()

static DatagramPayload openlcb::MemoryConfigDefs::read_datagram ( uint8_t  space,
uint32_t  offset,
uint8_t  length 
)
inlinestatic

Definition at line 184 of file MemoryConfigDefs.hxx.

◆ read_stream_datagram()

static DatagramPayload openlcb::MemoryConfigDefs::read_stream_datagram ( uint8_t  space,
uint32_t  offset,
uint8_t  dst_stream_id,
uint32_t  length = 0xFFFFFFFF 
)
inlinestatic

Definition at line 207 of file MemoryConfigDefs.hxx.

◆ write_datagram()

static DatagramPayload openlcb::MemoryConfigDefs::write_datagram ( uint8_t  space,
uint32_t  offset,
const string &  data = "" 
)
inlinestatic

Definition at line 161 of file MemoryConfigDefs.hxx.

Member Data Documentation

◆ MAX_DATAGRAM_RW_BYTES

constexpr unsigned openlcb::MemoryConfigDefs::MAX_DATAGRAM_RW_BYTES = 64
staticconstexpr

Definition at line 154 of file MemoryConfigDefs.hxx.


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