Model Railroad System  2.2.1
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
lcc::CANGridConnect Class Reference

Base class to connect to a CAN bus using GridConnect formatted message over. More...

Public Member Functions

 CANGridConnect (name,...)
 Constructor: create a connection to a Grid Connect CAN bus. More...
 
 getAliasOfNID (nid)
 Fetch the alias of a NID. More...
 
 getNIDofAlias (alias)
 Get the NID of the alias. More...
 
 getAllNIDs ()
 Get all known NIDs. More...
 
 getAllAliases ()
 Get all known aliases. More...
 
 updateAliasMap (nid, alias)
 Update the alias map with the specificed Node ID and Alias. More...
 
 populateAliasMap ()
 Send an AME. More...
 
 setMessageHandler (handler)
 Set the message handler. More...
 
 sendMessage (...)
 Send a message on the OpenLCB bus. More...
 
 sendOpenLCBMessage (message)
 Send a message on the OpenLCB bus. More...
 
 reserveAlias (canalias)
 Reserve an alias. More...
 

Private Member Functions

 _sendDatagram (message)
 Send a datagram message. More...
 
 _reserveMyAlias ()
 Reserve my alias. More...
 
 _timedout ()
 Timeout method. More...
 
 _flags0 (srcid, r, doff)
 Method to deal with possible multipart messages, with partitular handling of multi-part Simple Node Info messages. More...
 
 _messageReader (message)
 Handling incoming messages. More...
 
 _sendmessage (canmessage)
 Send a low-level CAN bus message using the Grid Connect format. More...
 

Static Private Member Functions

static listeq (a, b)
 Compare two lists. More...
 
static getBits (top, bottom, bytelist)
 Get the selected bitfield. More...
 
static countNUL (list)
 Count NUL bytes in a byte buffer. More...
 
static listeq (a, b)
 Compare two lists. More...
 

Private Attributes

 parent
 Parent instance. More...
 
 gcmessage
 GridConnectMessage component. More...
 
 gcreply
 GridConnectReply component. More...
 
 mtidetail
 MTIDetail component. More...
 
 mtiheader
 MTIHeader component. More...
 
 canheader
 CANHeader component. More...
 
 messagehandler
 Message handler. More...
 
 datagrambuffers
 Datagram buffers. More...
 
 messagebuffers
 General message buffers (for multi frame messages) More...
 
 simplenodeflags
 Simple node info flags. More...
 
 mycanalias
 My CanAlias component. More...
 
 aliasMap
 Alias to NID map. More...
 
 nidMap
 NID to alias map. More...
 
 _timeout
 Timeout flag. More...
 
 _timeoutFlag
 Timeout or error message received flag. More...
 

Static Private Attributes

static NIDPATTERN
 The regexp for breaking up the Node ID into bytes. More...
 

Detailed Description

Base class to connect to a CAN bus using GridConnect formatted message over.

Options:

Constructor & Destructor Documentation

◆ CANGridConnect()

lcc::CANGridConnect::CANGridConnect ( name  ,
  ... 
)

Constructor: create a connection to a Grid Connect CAN bus.

Connect to the CAN bus via a Grid Connect CAN bus.

Parameters
nameThe name of the instance.
...The options:
  • -parent The parent instance. Contains the low-level read and write methods.
  • -nid The Node ID that the computer will assume in the format of hh:hh:hh:hh:hh:hh which is a 48 bit number expressed as 6 pairs of hexadecimal digits separacted by colons (:).
  • -eventhandler This is a script prefix that is run on incoming messages. The current message as a binary CanMessage is appended.
  • -promisciousmode Promiscious mode flag. If true all messages are handled, whether they are addressed to this node or not.

Member Function Documentation

◆ _flags0()

lcc::CANGridConnect::_flags0 ( srcid  ,
,
doff   
)
private

Method to deal with possible multipart messages, with partitular handling of multi-part Simple Node Info messages.

Parameters
srcidThe source alias of the message.

◆ _messageReader()

lcc::CANGridConnect::_messageReader ( message  )
private

Handling incoming messages.

Handle control (CAN) messages here. OpenLCB messages are assembled possibly from multiple CAN messages and then dispatched to the upper level message handler.

◆ _reserveMyAlias()

lcc::CANGridConnect::_reserveMyAlias ( )
private

Reserve my alias.

Returns
A boolean value indicating a successfully reserved alias (true) or failure (false).

◆ _sendDatagram()

lcc::CANGridConnect::_sendDatagram ( message  )
private

Send a datagram message.

A possibly multi-part datagram message is sent.

Parameters
messageThe OpenLCB message to send.

◆ _sendmessage()

lcc::CANGridConnect::_sendmessage ( canmessage  )
private

Send a low-level CAN bus message using the Grid Connect format.

Parameters
canmessageThe (binary) CANMessage to send.

◆ _timedout()

lcc::CANGridConnect::_timedout ( )
private

Timeout method.

Called on timeout.

◆ countNUL()

static lcc::CANGridConnect::countNUL ( list  )
staticprivate

Count NUL bytes in a byte buffer.

Parameters
listThe list of bytes to search.
Returns
The number of NUL (0) bytes in the list.

◆ getAliasOfNID()

lcc::CANGridConnect::getAliasOfNID ( nid  )

Fetch the alias of a NID.

Parameters
nidA full NID of the form hh:hh:hh:hh:hh:hh
Returns
The node's alias or the empty string if not known.

◆ getAllAliases()

lcc::CANGridConnect::getAllAliases ( )

Get all known aliases.

Returns
All known aliases.

◆ getAllNIDs()

lcc::CANGridConnect::getAllNIDs ( )

Get all known NIDs.

Returns
All known NIDS.

◆ getBits()

static lcc::CANGridConnect::getBits ( top  ,
bottom  ,
bytelist   
)
staticprivate

Get the selected bitfield.

Extract the bits from a list of 6 8-bit (byte) numbers representing a 48 bit number.

Parameters
topTopmost (highest) bit number.
bottomBottommost (lowest) bit number.
bytelistList of 6 bytes.
Returns
An integer value.

◆ getNIDofAlias()

lcc::CANGridConnect::getNIDofAlias ( alias  )

Get the NID of the alias.

Parameters
aliasThe alias to look up.
Returns
The NID of the alias or the empty string if not known.

◆ listeq() [1/2]

static lcc::CANGridConnect::listeq ( ,
 
)
staticprivate

Compare two lists.

Compares two lists for equality.

Parameters
aFirst list to compare.
bSecond list to compare.
Returns
A boolean value: true if the lists are the same, false if not.

◆ listeq() [2/2]

static lcc::CANGridConnect::listeq ( ,
 
)
staticprivate

Compare two lists.

Compares two lists for equality.

Parameters
aFirst list to compare.
bSecond list to compare.
Returns
A boolean value: true if the lists are the same, false if not.

◆ populateAliasMap()

lcc::CANGridConnect::populateAliasMap ( )

Send an AME.

◆ reserveAlias()

lcc::CANGridConnect::reserveAlias ( canalias  )

Reserve an alias.

Sends out CID messages and eventually RID and AMD messages, if there are no errors.

Parameters
canaliasA CanAlias object.
Returns
A boolean value indicating a successfully reserved alias (true) or failure (false).

◆ sendMessage()

lcc::CANGridConnect::sendMessage (   ...)

Send a message on the OpenLCB bus.

Parameters
...Message options. See OpenLCBMessage for possible options.

◆ sendOpenLCBMessage()

lcc::CANGridConnect::sendOpenLCBMessage ( message  )

Send a message on the OpenLCB bus.

Parameters
messageAn OpenLCBMessage.

◆ setMessageHandler()

lcc::CANGridConnect::setMessageHandler ( handler  )

Set the message handler.

Generally called from the upper level class to gain access to incoming messages asyncronously.

Parameters
handlerThe new handler procedure.
Returns
The old handler or the empty string if there was no old handler.

◆ updateAliasMap()

lcc::CANGridConnect::updateAliasMap ( nid  ,
alias   
)

Update the alias map with the specificed Node ID and Alias.

Parameters
nidAn OpenLCB Node ID.
aliasA 12-bit CAN Alias.

Member Data Documentation

◆ _timeout

lcc::CANGridConnect::_timeout
private

Timeout flag.

◆ _timeoutFlag

lcc::CANGridConnect::_timeoutFlag
private

Timeout or error message received flag.

◆ aliasMap

lcc::CANGridConnect::aliasMap
private

Alias to NID map.

◆ canheader

lcc::CANGridConnect::canheader
private

CANHeader component.

This component is used to extract and pack fields from and to a CAN header at a CAN Header level.

◆ datagrambuffers

lcc::CANGridConnect::datagrambuffers
private

Datagram buffers.

◆ gcmessage

lcc::CANGridConnect::gcmessage
private

GridConnectMessage component.

This component is used to encode CAN Messages in Grid Connect Message format for transmission.

◆ gcreply

lcc::CANGridConnect::gcreply
private

GridConnectReply component.

This component is used to decode received Grid Connect Messages into binary CAN Messages.

◆ messagebuffers

lcc::CANGridConnect::messagebuffers
private

General message buffers (for multi frame messages)

◆ messagehandler

lcc::CANGridConnect::messagehandler
private

Message handler.

◆ mtidetail

lcc::CANGridConnect::mtidetail
private

MTIDetail component.

This component is used to extract and pack fields from and to a CAN header at a MTI detail level

◆ mtiheader

lcc::CANGridConnect::mtiheader
private

MTIHeader component.

This component is used to extract and pack fields from and to a CAN header at a MTI header level.

◆ mycanalias

lcc::CANGridConnect::mycanalias
private

My CanAlias component.

◆ nidMap

lcc::CANGridConnect::nidMap
private

NID to alias map.

◆ NIDPATTERN

lcc::CANGridConnect::NIDPATTERN
staticprivate

The regexp for breaking up the Node ID into bytes.

◆ parent

lcc::CANGridConnect::parent
private

Parent instance.

◆ simplenodeflags

lcc::CANGridConnect::simplenodeflags
private

Simple node info flags.