Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::TcpDefs Class Reference

Static class for constants and utilities related to the TCP transport protocol. More...

#include <IfTcpImpl.hxx>

Public Types

enum  {
  FLAGS_OPENLCB_MSG = 0x8000 , FLAGS_CHAINING = 0x4000 , FLAGS_RESVD1_ZERO_CHECK = 0x3000 , FLAGS_FRAGMENT_NOT_FIRST = 0x0800 ,
  FLAGS_FRAGMENT_NOT_LAST = 0x0400 , FLAGS_RESVD2_IGNORED = 0x03FF , HDR_FLAG_OFS = 0 , HDR_SIZE_OFS = 2 ,
  HDR_GATEWAY_OFS = 2 + 3 , HDR_SIZE_END = HDR_GATEWAY_OFS , HDR_TIMESTAMP_OFS = 2 + 3 + 6 , HDR_LEN = 2 + 3 + 6 + 6 ,
  MSG_MTI_OFS = 0 , MSG_SRC_OFS = 2 , MSG_DST_OFS = 2 + 6 , MSG_ADR_PAYLOAD_OFS = 2 + 6 + 6 ,
  MSG_GLOBAL_PAYLOAD_OFS = MSG_DST_OFS , MIN_MESSAGE_SIZE = MSG_GLOBAL_PAYLOAD_OFS + HDR_LEN , MIN_ADR_MESSAGE_SIZE = MSG_ADR_PAYLOAD_OFS + HDR_LEN , ABS_MTI_OFS = HDR_LEN + MSG_MTI_OFS
}
 

Static Public Member Functions

static void render_tcp_message (const GenMessage &msg, NodeID gateway_node_id, long long sequence, string *tgt)
 Renders a TCP message into a single buffer, ready to transmit.
 
static int get_tcp_message_len (const void *data, size_t len)
 Guesses the length of a tcp message from looking at the prefix of the payload.
 
static bool parse_tcp_message (const string &src, GenMessage *tgt)
 Parses a TCP message format (from binary payload) into a general OpenLCB message.
 
static unsigned guess_priority (const string &tcp_payload)
 

Static Public Attributes

static const char MDNS_PROTOCOL_TCP [] = "_tcp"
 Protocol to be used for mDNS broadcast.
 
static const char MDNS_SERVICE_NAME_HUB [] = "_openlcb-hub"
 base name of the mDNS Service Name for mDNS broadcast as a hub
 
static const char MDNS_SERVICE_NAME_HUB_TCP [] = "_openlcb-hub._tcp"
 complete mDNS broadcast name for a TCP hub
 
static const char MDNS_SERVICE_NAME_GRIDCONNECT_CAN [] = "_openlcb-can"
 base name of the mDNS Service Name for mDNS broadcast as a client
 
static const char MDNS_SERVICE_NAME_GRIDCONNECT_CAN_TCP [] = "_openlcb-can._tcp"
 complete mDNS broadcast name for a TCP GridConnect protocol client
 

Private Member Functions

 TcpDefs ()
 No usable constructor; this is a static-only class.
 
 TcpDefs ()
 Nobody can construct this class.
 
 DISALLOW_COPY_AND_ASSIGN (TcpDefs)
 

Detailed Description

Static class for constants and utilities related to the TCP transport protocol.

Definition at line 47 of file IfTcpImpl.hxx.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
FLAGS_OPENLCB_MSG 

Bit in the uint16 flags field in the header that signals frames that carry an OpenLCB message.

FLAGS_CHAINING 

Chaining bit in the uint16 flags field.

Means (according to the old draft) that there will be anopther header embedded inside this.

FLAGS_RESVD1_ZERO_CHECK 

Reserved bits in the flags field. Check as zero.

FLAGS_FRAGMENT_NOT_FIRST 

"not first" fragmenting bit in the flags field.

FLAGS_FRAGMENT_NOT_LAST 

"not last" fragmenting bit in the flags field.

FLAGS_RESVD2_IGNORED 

Reserved bits in the flags field. Ignore (by the standard).

HDR_FLAG_OFS 

Offset in the header of the flags field.

HDR_SIZE_OFS 

Offset in the header of the size field.

HDR_GATEWAY_OFS 

Offset in the header of the source gateway field.

HDR_SIZE_END 

Offset in the header of the end of the size field.

HDR_TIMESTAMP_OFS 

Offset in the header of the timestamp (seq no) field.

HDR_LEN 

Total length of the fixed header.

MSG_MTI_OFS 

Offset in the message (=after the header) of the MTI field.

MSG_SRC_OFS 

Offset in the message (=after the header) of the src node ID field.

MSG_DST_OFS 

Offset in the message (=after the header) of the dst node ID field (for addressed MTI only).

MSG_ADR_PAYLOAD_OFS 

Offset in the message (=after the header) of the message payload (for addressed MTI only).

MSG_GLOBAL_PAYLOAD_OFS 

Offset in the message (=after the header) of the message payload (for global MTI only).

MIN_MESSAGE_SIZE 

Minimum length of a valid message.

MIN_ADR_MESSAGE_SIZE 

Minimum length of a valid message that has an addressed MTI.

ABS_MTI_OFS 

Offset from the header of the MTI field in the message.

Assumes no chaining.

Definition at line 185 of file IfTcpImpl.hxx.

Member Function Documentation

◆ get_tcp_message_len()

static int openlcb::TcpDefs::get_tcp_message_len ( const void *  data,
size_t  len 
)
inlinestatic

Guesses the length of a tcp message from looking at the prefix of the payload.

Parameters
datais the prefix of the incoming stream.
lenis the number of available bytes in this prefix.
Returns
-1 if there is not enough bytes in the prefix yet to know the length. Otherwise the total number of bytes that constitute this packet.

Definition at line 96 of file IfTcpImpl.hxx.

◆ guess_priority()

static unsigned openlcb::TcpDefs::guess_priority ( const string &  tcp_payload)
inlinestatic
Parameters
tcp_payloadis a message holding a TCP protocol frame.
Returns
the OpenLCB priority in range 0..3 or uint_max if the message is broken.

Definition at line 175 of file IfTcpImpl.hxx.

◆ parse_tcp_message()

static bool openlcb::TcpDefs::parse_tcp_message ( const string &  src,
GenMessage tgt 
)
inlinestatic

Parses a TCP message format (from binary payload) into a general OpenLCB message.

Parameters
srcthe rendered TCP message.
tgtthe output generic message
Returns
false if the message is not well formatted or it is not an OpenLCB message.

Definition at line 117 of file IfTcpImpl.hxx.

◆ render_tcp_message()

static void openlcb::TcpDefs::render_tcp_message ( const GenMessage msg,
NodeID  gateway_node_id,
long long  sequence,
string *  tgt 
)
inlinestatic

Renders a TCP message into a single buffer, ready to transmit.

Parameters
msgis the OpenLCB message to render.
gateway_node_idwill be populated into the message header as the message source (last sending node ID).
sequenceis a 48-bit millisecond value that's monotonic.
targetis the buffer into which to render the message.

Definition at line 56 of file IfTcpImpl.hxx.

Member Data Documentation

◆ MDNS_PROTOCOL_TCP

const char openlcb::TcpDefs::MDNS_PROTOCOL_TCP = "_tcp"
static

Protocol to be used for mDNS broadcast.

Definition at line 46 of file TcpDefs.hxx.

◆ MDNS_SERVICE_NAME_GRIDCONNECT_CAN

const char openlcb::TcpDefs::MDNS_SERVICE_NAME_GRIDCONNECT_CAN = "_openlcb-can"
static

base name of the mDNS Service Name for mDNS broadcast as a client

Definition at line 52 of file TcpDefs.hxx.

◆ MDNS_SERVICE_NAME_GRIDCONNECT_CAN_TCP

const char openlcb::TcpDefs::MDNS_SERVICE_NAME_GRIDCONNECT_CAN_TCP = "_openlcb-can._tcp"
static

complete mDNS broadcast name for a TCP GridConnect protocol client

Definition at line 54 of file TcpDefs.hxx.

◆ MDNS_SERVICE_NAME_HUB

const char openlcb::TcpDefs::MDNS_SERVICE_NAME_HUB = "_openlcb-hub"
static

base name of the mDNS Service Name for mDNS broadcast as a hub

Definition at line 48 of file TcpDefs.hxx.

◆ MDNS_SERVICE_NAME_HUB_TCP

const char openlcb::TcpDefs::MDNS_SERVICE_NAME_HUB_TCP = "_openlcb-hub._tcp"
static

complete mDNS broadcast name for a TCP hub

Definition at line 50 of file TcpDefs.hxx.


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