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

Static values and helper functions for CAN-bus interfaces. More...

#include <CanDefs.hxx>

Public Types

enum  AliasStatus { UNDER_TEST , RESERVED , CONFLICT , FREE }
 Status value for an alias pool item. More...
 
enum  ID {
  SRC_MASK = 0x00000fff , MTI_MASK = 0x00fff000 , DST_MASK = 0x00fff000 , CAN_FRAME_TYPE_MASK = 0x07000000 ,
  FRAME_TYPE_MASK = 0x08000000 , PRIORITY_MASK = 0x10000000 , PADDING_MASK = 0xe0000000 , STREAM_DG_RECV_MASK = 0x0fffffff ,
  SRC_SHIFT = 0 , MTI_SHIFT = 12 , DST_SHIFT = 12 , CAN_FRAME_TYPE_SHIFT = 24 ,
  FRAME_TYPE_SHIFT = 27 , PRIORITY_SHIFT = 28 , PADDING_SHIFT = 29 , CONTROL_SRC_MASK = 0x00000fff ,
  CONTROL_FIELD_MASK = 0x07fff000 , CONTROL_SEQUENCE_MASK = 0x07000000 , CONTROL_TYPE_MASK = 0x08000000 , CONTROL_PRIORITY_MASK = 0x10000000 ,
  CONTROL_PADDING_MASK = 0xe0000000 , CONTROL_SRC_SHIFT = 0 , CONTROL_FIELD_SHIFT = 12 , CONTROL_SEQUENCE_SHIFT = 24 ,
  CONTROL_TYPE_SHIFT = 27 , CONTROL_PRIORITY_SHIFT = 28 , CONTROL_PADDING_SHIFT = 29
}
 CAN ID bit fields for most CAN frames. More...
 
enum  CanFrameType {
  GLOBAL_ADDRESSED = 1 , DATAGRAM_ONE_FRAME = 2 , DATAGRAM_FIRST_FRAME = 3 , DATAGRAM_MIDDLE_FRAME = 4 ,
  DATAGRAM_FINAL_FRAME = 5 , STREAM_DATA = 7
}
 CAN Frame Types. More...
 
enum  FrameType { CONTROL_MSG = 0 , NMRANET_MSG = 1 }
 Frame Types, Control or normal NMRAnet message. More...
 
enum  Priority { HIGH_PRIORITY = 0 , NORMAL_PRIORITY = 1 }
 Highest order priority of a CAN message. More...
 
enum  ControlField { RID_FRAME = 0x0700 , AMD_FRAME = 0x0701 , AME_FRAME = 0x0702 , AMR_FRAME = 0x0703 }
 
enum  AddressedPayloadFlags { NOT_FIRST_FRAME = 0x20 , NOT_LAST_FRAME = 0x10 }
 
enum  ReservedAliasNodeId { RESERVED_ALIAS_NODE_BITS = 0xF000 , RESERVED_ALIAS_NODE_MASK = 0xFFFFFFFFF000 }
 Constants used in the LocalAliasCache for reserved but not used aliases. More...
 
typedef uint16_t CanMTI
 

Static Public Member Functions

static NodeAlias get_src (uint32_t can_id)
 Get the source field value of the CAN ID.
 
static CanMTI get_mti (uint32_t can_id)
 Get the MTI field value of the CAN ID.
 
static NodeAlias get_dst (uint32_t can_id)
 Get the destination field value of the CAN ID.
 
static CanFrameType get_can_frame_type (uint32_t can_id)
 Get the CAN frame type field value of the CAN ID.
 
static FrameType get_frame_type (uint32_t can_id)
 Get the frame type field value of the CAN ID.
 
static Priority get_priority (uint32_t can_id)
 Get the priority field value of the CAN ID.
 
static bool is_cid_frame (uint32_t can_id)
 Tests if the incoming frame is a CID frame.
 
static bool is_stream_frame (uint32_t can_id)
 Tests if the incoming frame is a stream data send frame.
 
static void set_mti (uint32_t *can_id, CanMTI mti)
 Set the MTI field value of the CAN ID.
 
static void set_src (uint32_t *can_id, NodeAlias src)
 Set the source field value of the CAN ID.
 
static void set_dst (uint32_t *can_id, NodeAlias dst)
 Set the destination field value of the CAN ID.
 
static void set_can_frame_type (uint32_t *can_id, CanFrameType type)
 Set the CAN frame type field value of the CAN ID.
 
static void set_frame_type (uint32_t *can_id, FrameType type)
 Set the frame type field value of the CAN ID.
 
static void set_priority (uint32_t *can_id, Priority priority)
 Set the priority field value of the CAN ID.
 
static void set_fields (uint32_t *can_id, NodeAlias src, Defs::MTI mti, CanFrameType can_type, FrameType type, Priority priority)
 Set all the CAN ID fields.
 
static void set_datagram_fields (uint32_t *can_id, NodeAlias src, NodeAlias dst, CanFrameType can_type)
 Set all the CAN ID fields for datagram or stream message.
 
static Defs::MTI nmranet_mti (uint32_t can_id)
 Get the NMRAnet MTI from a can identifier.
 
static uint32_t can_identifier (Defs::MTI mti, NodeAlias src)
 Get the CAN identifier from an NMRAnet mti and source alias.
 
static ControlField get_control_field (uint32_t can_id)
 Get the control field of a can control frame.
 
static uint32_t set_control_fields (NodeAlias src, uint16_t field, int sequence)
 Initialize a control frame CAN ID and set DLC to 0.
 
static void control_init (struct can_frame &frame, NodeAlias src, uint16_t field, int sequence)
 Initialize a control frame CAN ID and set DLC to 0.
 
static NodeID get_reserved_alias_node_id (NodeAlias alias)
 Computes a reserved alias node ID for the local alias cache map.
 
static bool is_reserved_alias_node_id (NodeID id)
 Tests if a node ID is a reserved alias Node ID.
 

Private Member Functions

 CanDefs ()
 This class should not be instantiated.
 

Detailed Description

Static values and helper functions for CAN-bus interfaces.

Definition at line 47 of file CanDefs.hxx.

Member Typedef Documentation

◆ CanMTI

typedef uint16_t openlcb::CanDefs::CanMTI

Definition at line 95 of file CanDefs.hxx.

Member Enumeration Documentation

◆ AddressedPayloadFlags

enum openlcb::CanDefs::AddressedPayloadFlags

Definition at line 132 of file CanDefs.hxx.

◆ AliasStatus

Status value for an alias pool item.

Enumerator
UNDER_TEST 

this is an alias we are trying to claim

RESERVED 

the alias has been reserved for use

CONFLICT 

we discovered someone else already is using this alias

FREE 

the alias is free for another request

Definition at line 50 of file CanDefs.hxx.

◆ CanFrameType

CAN Frame Types.

Enumerator
GLOBAL_ADDRESSED 

most CAN frame types fall in this category

DATAGRAM_ONE_FRAME 

a single frame datagram

DATAGRAM_FIRST_FRAME 

first frame of multi-frame datagram

DATAGRAM_MIDDLE_FRAME 

middle frame of multi-frame datagram

DATAGRAM_FINAL_FRAME 

last frame of multi-frame datagram

STREAM_DATA 

stream data frame

Definition at line 98 of file CanDefs.hxx.

◆ ControlField

Enumerator
RID_FRAME 

Reserve ID Frame.

AMD_FRAME 

Alias Map Definition frame.

AME_FRAME 

Alias Mapping Enquiry.

AMR_FRAME 

Alias Map Reset.

Definition at line 124 of file CanDefs.hxx.

◆ FrameType

Frame Types, Control or normal NMRAnet message.

Enumerator
CONTROL_MSG 

CAN control frame message.

NMRANET_MSG 

normal NMRAnet message

Definition at line 109 of file CanDefs.hxx.

◆ ID

CAN ID bit fields for most CAN frames.

Enumerator
SRC_MASK 

mask for source field of CAN ID

MTI_MASK 

mask for MTI field of CAN ID

DST_MASK 

mask for MTI field of CAN ID

CAN_FRAME_TYPE_MASK 

mask for can frame type field of CAN ID

FRAME_TYPE_MASK 

mask for frame type field of CAN ID

PRIORITY_MASK 

mask for priority field of CAN ID

PADDING_MASK 

mask for padding field of CAN ID

STREAM_DG_RECV_MASK 

mask for receiving datagram and stream frames.

SRC_SHIFT 

shift for source field of CAN ID

MTI_SHIFT 

shift for MTI field of CAN ID

DST_SHIFT 

shift for MTI field of CAN ID

CAN_FRAME_TYPE_SHIFT 

shift for can frame type field of CAN ID

FRAME_TYPE_SHIFT 

shift for frame type field of CAN ID

PRIORITY_SHIFT 

shift for priority field of CAN ID

PADDING_SHIFT 

shift for padding field of CAN ID

CONTROL_SRC_MASK 

source alias mask

CONTROL_FIELD_MASK 

control field data mask

CONTROL_SEQUENCE_MASK 

frame sequence number mask

CONTROL_TYPE_MASK 

value of '0' means control frame mask

CONTROL_PRIORITY_MASK 

priority mask

CONTROL_PADDING_MASK 

pad out to a full 32-bit word

CONTROL_SRC_SHIFT 

source alias shift

CONTROL_FIELD_SHIFT 

control field data shift

CONTROL_SEQUENCE_SHIFT 

frame sequence number shift

CONTROL_TYPE_SHIFT 

value of '0' means control frame shift

CONTROL_PRIORITY_SHIFT 

priority shift

CONTROL_PADDING_SHIFT 

pad out to a full 32-bit word

Definition at line 60 of file CanDefs.hxx.

◆ Priority

Highest order priority of a CAN message.

Most messages fall into the NORMAL_PRIORITY category.

Enumerator
HIGH_PRIORITY 

high priority CAN message

NORMAL_PRIORITY 

normal priority CAN message

Definition at line 118 of file CanDefs.hxx.

◆ ReservedAliasNodeId

Constants used in the LocalAliasCache for reserved but not used aliases.

Enumerator
RESERVED_ALIAS_NODE_BITS 

To mark a reserved alias in the local alias cache, we use this as a node ID and add the alias to the lowest 12 bits.

Since this value starts with a zero MSB byte, it is not a valid node ID.

RESERVED_ALIAS_NODE_MASK 

Mask for the reserved aliases.

Definition at line 140 of file CanDefs.hxx.

Member Function Documentation

◆ can_identifier()

uint32_t openlcb::CanDefs::can_identifier ( Defs::MTI  mti,
NodeAlias  src 
)
static

Get the CAN identifier from an NMRAnet mti and source alias.

Parameters
mtiNMRAnet MTI
srcSource node alias
Returns
CAN identifier

Definition at line 69 of file CanDefs.cxx.

◆ control_init()

static void openlcb::CanDefs::control_init ( struct can_frame &  frame,
NodeAlias  src,
uint16_t  field,
int  sequence 
)
inlinestatic

Initialize a control frame CAN ID and set DLC to 0.

Parameters
_framecontrol frame to initialize
_sourcesource data
_fieldfield data
_sequencesequence data

Definition at line 379 of file CanDefs.hxx.

◆ get_can_frame_type()

static CanFrameType openlcb::CanDefs::get_can_frame_type ( uint32_t  can_id)
inlinestatic

Get the CAN frame type field value of the CAN ID.

Parameters
can_ididentifier to act upon
Returns
CAN frame type field value

Definition at line 181 of file CanDefs.hxx.

◆ get_control_field()

static ControlField openlcb::CanDefs::get_control_field ( uint32_t  can_id)
inlinestatic

Get the control field of a can control frame.

This includes the sequence number and the variable field.

Parameters
can_idCAN ID of the control frame
Returns
value of the control field

Definition at line 334 of file CanDefs.hxx.

◆ get_dst()

static NodeAlias openlcb::CanDefs::get_dst ( uint32_t  can_id)
inlinestatic

Get the destination field value of the CAN ID.

Parameters
can_ididentifier to act upon
Returns
destination field value

Definition at line 172 of file CanDefs.hxx.

◆ get_frame_type()

static FrameType openlcb::CanDefs::get_frame_type ( uint32_t  can_id)
inlinestatic

Get the frame type field value of the CAN ID.

Parameters
can_ididentifier to act upon
Returns
frame type field value

Definition at line 190 of file CanDefs.hxx.

◆ get_mti()

static CanMTI openlcb::CanDefs::get_mti ( uint32_t  can_id)
inlinestatic

Get the MTI field value of the CAN ID.

Parameters
can_ididentifier to act upon
Returns
MTI field value

Definition at line 163 of file CanDefs.hxx.

◆ get_priority()

static Priority openlcb::CanDefs::get_priority ( uint32_t  can_id)
inlinestatic

Get the priority field value of the CAN ID.

Parameters
can_ididentifier to act upon
Returns
priority field value

Definition at line 199 of file CanDefs.hxx.

◆ get_reserved_alias_node_id()

static NodeID openlcb::CanDefs::get_reserved_alias_node_id ( NodeAlias  alias)
inlinestatic

Computes a reserved alias node ID for the local alias cache map.

Parameters
aliasthe alias to reserve
Returns
Node ID to use in the alias map as a key.

Definition at line 389 of file CanDefs.hxx.

◆ get_src()

static NodeAlias openlcb::CanDefs::get_src ( uint32_t  can_id)
inlinestatic

Get the source field value of the CAN ID.

Parameters
can_ididentifier to act upon
Returns
source field

Definition at line 154 of file CanDefs.hxx.

◆ is_cid_frame()

static bool openlcb::CanDefs::is_cid_frame ( uint32_t  can_id)
inlinestatic

Tests if the incoming frame is a CID frame.

Parameters
can_ididentifier to act upon
Returns
true for CID frame, false for any other frame.

Definition at line 208 of file CanDefs.hxx.

◆ is_reserved_alias_node_id()

static bool openlcb::CanDefs::is_reserved_alias_node_id ( NodeID  id)
inlinestatic

Tests if a node ID is a reserved alias Node ID.

Parameters
idnode id to test
Returns
true if this is a reserved alias node ID.

Definition at line 397 of file CanDefs.hxx.

◆ is_stream_frame()

static bool openlcb::CanDefs::is_stream_frame ( uint32_t  can_id)
inlinestatic

Tests if the incoming frame is a stream data send frame.

Parameters
can_ididentifier to act upon
Returns
true for Stream Data frame, false for any other frame.

Definition at line 217 of file CanDefs.hxx.

◆ nmranet_mti()

Defs::MTI openlcb::CanDefs::nmranet_mti ( uint32_t  can_id)
static

Get the NMRAnet MTI from a can identifier.

Parameters
can_idCAN identifider
Returns
NMRAnet MTI

Definition at line 43 of file CanDefs.cxx.

◆ set_can_frame_type()

static void openlcb::CanDefs::set_can_frame_type ( uint32_t *  can_id,
CanFrameType  type 
)
inlinestatic

Set the CAN frame type field value of the CAN ID.

Parameters
can_ididentifier to act upon, passed by reference
typeCAN frame type field value

Definition at line 256 of file CanDefs.hxx.

◆ set_control_fields()

static uint32_t openlcb::CanDefs::set_control_fields ( NodeAlias  src,
uint16_t  field,
int  sequence 
)
inlinestatic

Initialize a control frame CAN ID and set DLC to 0.

Parameters
srcsource node alias
fieldcontrol field data (e.g. AME_FRAME)
sequencesequence number or zero if not CID frame

Definition at line 365 of file CanDefs.hxx.

◆ set_datagram_fields()

static void openlcb::CanDefs::set_datagram_fields ( uint32_t *  can_id,
NodeAlias  src,
NodeAlias  dst,
CanFrameType  can_type 
)
inlinestatic

Set all the CAN ID fields for datagram or stream message.

Parameters
can_ididentifier to act upon
sourcesource alias
dstdesitnation alias
can_typeCAN frame type field value

Definition at line 305 of file CanDefs.hxx.

◆ set_dst()

static void openlcb::CanDefs::set_dst ( uint32_t *  can_id,
NodeAlias  dst 
)
inlinestatic

Set the destination field value of the CAN ID.

Parameters
can_ididentifier to act upon, passed by reference
dstdestination field value

Definition at line 246 of file CanDefs.hxx.

◆ set_fields()

static void openlcb::CanDefs::set_fields ( uint32_t *  can_id,
NodeAlias  src,
Defs::MTI  mti,
CanFrameType  can_type,
FrameType  type,
Priority  priority 
)
inlinestatic

Set all the CAN ID fields.

Parameters
can_ididentifier to act upon
sourcesource field value
mtiMTI field value
can_typeCAN frame type field value
typeframe type field value
prioritypriority field value

Definition at line 290 of file CanDefs.hxx.

◆ set_frame_type()

static void openlcb::CanDefs::set_frame_type ( uint32_t *  can_id,
FrameType  type 
)
inlinestatic

Set the frame type field value of the CAN ID.

Parameters
can_ididentifier to act upon, passed by reference
typeframe type field value

Definition at line 266 of file CanDefs.hxx.

◆ set_mti()

static void openlcb::CanDefs::set_mti ( uint32_t *  can_id,
CanMTI  mti 
)
inlinestatic

Set the MTI field value of the CAN ID.

Parameters
can_ididentifier to act upon, passed by reference
mtiMTI field value

Definition at line 226 of file CanDefs.hxx.

◆ set_priority()

static void openlcb::CanDefs::set_priority ( uint32_t *  can_id,
Priority  priority 
)
inlinestatic

Set the priority field value of the CAN ID.

Parameters
can_ididentifier to act upon, passed by reference
prioritypryority field value

Definition at line 276 of file CanDefs.hxx.

◆ set_src()

static void openlcb::CanDefs::set_src ( uint32_t *  can_id,
NodeAlias  src 
)
inlinestatic

Set the source field value of the CAN ID.

Parameters
can_ididentifier to act upon, passed by pointer
srcsource field value

Definition at line 236 of file CanDefs.hxx.


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