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

Implementation of the OpenLCB interface abstraction for the CAN-bus interface standard. More...

#include <IfCan.hxx>

Inheritance diagram for openlcb::IfCan:
openlcb::If CanIf Service

Public Member Functions

 IfCan (ExecutorBase *executor, CanHubFlow *device, int local_alias_cache_size, int remote_alias_cache_size, int local_nodes_count)
 Creates a CAN interface.
 
void add_addressed_message_support ()
 Adds support to this interface for addressed NMRAnet messages (both sending and receiving).
 
AliasCachelocal_aliases ()
 
AliasCacheremote_aliases ()
 
AliasAllocatoralias_allocator ()
 
void set_alias_allocator (AliasAllocator *a)
 Sets the alias allocator for this If. Takes ownership of pointer.
 
void send_global_alias_enquiry (Node *source)
 Sends a global alias enquiry packet.
 
void add_owned_flow (Executable *e) override
 Transfers ownership of a module to the interface.
 
bool matching_node (NodeHandle expected, NodeHandle actual) override
 
void delete_local_node (Node *node) override
 Removes a local node from this interface.
 
Nodelookup_local_node_handle (NodeHandle handle) override
 Looks up a node ID in the local nodes' registry.
 
NodeID get_default_node_id () override
 
- Public Member Functions inherited from openlcb::If
 If (ExecutorBase *executor, int local_nodes_count)
 Constructs an NMRAnet interface.
 
virtual ~If ()
 Destructor.
 
MessageHandlerglobal_message_write_flow ()
 
MessageHandleraddressed_message_write_flow ()
 
MessageDispatchFlowdispatcher ()
 
void add_local_node (Node *node)
 Registers a new local node on this interface.
 
Nodelookup_local_node (NodeID id)
 Looks up a node ID in the local nodes' registry.
 
Nodefirst_local_node ()
 
Nodenext_local_node (NodeID previous)
 Iterator helper on the local nodes map.
 
void set_tx_hook (std::function< void()> hook)
 Sets a transmit hook.
 
StreamTransportstream_transport ()
 
void set_stream_transport (StreamTransport *s)
 Adds the necessary object for this interface to support stream transport.
 
- Public Member Functions inherited from Service
 Service (ExecutorBase *e)
 Constructor.
 
 ~Service ()
 Destructor.
 
ExecutorBaseexecutor ()
 
- Public Member Functions inherited from CanIf
 CanIf (Service *service, CanHubFlow *device)
 Constructor.
 
Serviceservice ()
 
FrameDispatchFlowframe_dispatcher ()
 
OutgoingFrameHandlerframe_write_flow ()
 
OutgoingFrameHandlerloopback_frame_write_flow ()
 

Private Member Functions

void canonicalize_handle (NodeHandle *h) override
 Canonicalizes the node handle: fills in id and/or alias from the maps the interface holds internally.
 
 DISALLOW_COPY_AND_ASSIGN (IfCan)
 

Private Attributes

AliasCache localAliases_
 Aliases we know are owned by local (virtual or proxied) nodes.
 
AliasCache remoteAliases_
 Aliases we know are owned by remote nodes on this If.
 
std::vector< std::unique_ptr< Executable > > ownedFlows_
 Various implementation control flows that this interface owns.
 
std::unique_ptr< AliasAllocatoraliasAllocator_
 Owns the alias allocator module.
 

Friends

class CanFrameWriteFlow
 

Additional Inherited Members

- Public Types inherited from openlcb::If
typedef DispatchFlow< Buffer< GenMessage >, 4 > MessageDispatchFlow
 Type of the dispatcher of incoming NMRAnet messages.
 
- Public Types inherited from CanIf
typedef DispatchFlow< Buffer< CanMessageData >, 4 > FrameDispatchFlow
 Type of the dispatcher responsible for routing incoming frames to the frome handlers.
 
- Protected Member Functions inherited from openlcb::If
void remove_local_node_from_map (Node *node)
 
- Protected Attributes inherited from openlcb::If
MessageHandlerglobalWriteFlow_
 Allocator containing the global write flows.
 
MessageHandleraddressedWriteFlow_
 Allocator containing the addressed write flows.
 

Detailed Description

Implementation of the OpenLCB interface abstraction for the CAN-bus interface standard.

This contains the parsers for CAN frames, dispatcher for the different frame types, the alias mapping tables (both local and remote nodes), and the flows responsible for sending outgoing messages. Inherits handling of the MTI-indexed messages from the base class If.

Definition at line 64 of file IfCan.hxx.

Constructor & Destructor Documentation

◆ IfCan()

openlcb::IfCan::IfCan ( ExecutorBase executor,
CanHubFlow device,
int  local_alias_cache_size,
int  remote_alias_cache_size,
int  local_nodes_count 
)

Creates a CAN interface.

Parameters
executorwill be used to process incoming (and outgoing) messages.
deviceis a CanHub. The interface will add a member to this pipe to handle incoming and outgoing traffic. The caller should add the necessary hardware device, GridConnect bridge or mock interface to this pipe (before this constructor or else outgoing packets might be lost).
local_alias_cache_sizetells the number of aliases to keep track of for nocal virtual nodes and proxied nodes.
remote_alias_cache_sizetells the number of aliases to keep track of for remote nodes on the bus.
local_nodes_countis the maximum number of virtual nodes that this interface will support.

Definition at line 708 of file IfCan.cxx.

◆ ~IfCan()

openlcb::IfCan::~IfCan ( )

Definition at line 742 of file IfCan.cxx.

Member Function Documentation

◆ add_addressed_message_support()

void openlcb::IfCan::add_addressed_message_support ( )

Adds support to this interface for addressed NMRAnet messages (both sending and receiving).

Definition at line 783 of file IfCan.cxx.

◆ add_owned_flow()

void openlcb::IfCan::add_owned_flow ( Executable e)
overridevirtual

Transfers ownership of a module to the interface.

It will be brought down in the destructor. The destruction order is guaranteed such that all supporting structures are still available when the flow is destryed, but incoming messages can not come in anymore.

Todo:
(balazs.racz) revise whether this needs to be virtual.

Implements openlcb::If.

Definition at line 746 of file IfCan.cxx.

◆ alias_allocator()

AliasAllocator * openlcb::IfCan::alias_allocator ( )
inline
Returns
the alias cache for remote nodes on this IF

Definition at line 110 of file IfCan.hxx.

◆ canonicalize_handle()

void openlcb::IfCan::canonicalize_handle ( NodeHandle h)
overrideprivatevirtual

Canonicalizes the node handle: fills in id and/or alias from the maps the interface holds internally.

Noop for TCP interface. Must be called on the interface executor.

Reimplemented from openlcb::If.

Definition at line 806 of file IfCan.cxx.

◆ delete_local_node()

void openlcb::IfCan::delete_local_node ( Node node)
overridevirtual

Removes a local node from this interface.

This function must be called from the interface's executor.

Parameters
nodeis the node to delete. The node will not be freed, just removed from the data structures.

Implements openlcb::If.

Definition at line 793 of file IfCan.cxx.

◆ get_default_node_id()

NodeID openlcb::IfCan::get_default_node_id ( )
overridevirtual
Returns
the node ID of the default node on this interface. For TCP interfaces this is the gateway node ID, for CAN interfaces this is the node ID used for alias allocation on the CAN-bus.

Implements openlcb::If.

Definition at line 855 of file IfCan.cxx.

◆ local_aliases()

AliasCache * openlcb::IfCan::local_aliases ( )
inline
Returns
the alias cache for local nodes (vnodes and proxies)

Definition at line 96 of file IfCan.hxx.

◆ lookup_local_node_handle()

Node * openlcb::IfCan::lookup_local_node_handle ( NodeHandle  handle)
overridevirtual

Looks up a node ID in the local nodes' registry.

This function must be called from the interface's executor.

Parameters
handleis the NodeHandle representing a target node.
Returns
the node pointer or NULL if the node is not local registered.

Reimplemented from openlcb::If.

Definition at line 846 of file IfCan.cxx.

◆ matching_node()

bool openlcb::IfCan::matching_node ( NodeHandle  expected,
NodeHandle  actual 
)
overridevirtual
Returns
true if the two node handles match as far as we can tell without doing any network traffic.

Implements openlcb::If.

Definition at line 828 of file IfCan.cxx.

◆ remote_aliases()

AliasCache * openlcb::IfCan::remote_aliases ( )
inline
Returns
the alias cache for remote nodes on this IF

Definition at line 103 of file IfCan.hxx.

◆ send_global_alias_enquiry()

void openlcb::IfCan::send_global_alias_enquiry ( Node source)

Sends a global alias enquiry packet.

This will also clear the remote alias cache (in this node and in all other OpenMRN-based nodes on the bus) and let it re-populate from the responses coming back. This call should be used very sparingly because of the effect it has on the entire bus.

Parameters
sourcea local node to use for sending this message out. Must be already initialized.

Definition at line 756 of file IfCan.cxx.

◆ set_alias_allocator()

void openlcb::IfCan::set_alias_allocator ( AliasAllocator a)

Sets the alias allocator for this If. Takes ownership of pointer.

Definition at line 751 of file IfCan.cxx.

Friends And Related Symbol Documentation

◆ CanFrameWriteFlow

friend class CanFrameWriteFlow
friend

Definition at line 140 of file IfCan.hxx.

Member Data Documentation

◆ aliasAllocator_

std::unique_ptr<AliasAllocator> openlcb::IfCan::aliasAllocator_
private

Owns the alias allocator module.

Definition at line 157 of file IfCan.hxx.

◆ localAliases_

AliasCache openlcb::IfCan::localAliases_
private

Aliases we know are owned by local (virtual or proxied) nodes.

This member must only be accessed from the If's executor.

Definition at line 146 of file IfCan.hxx.

◆ ownedFlows_

std::vector<std::unique_ptr<Executable> > openlcb::IfCan::ownedFlows_
private

Various implementation control flows that this interface owns.

Definition at line 154 of file IfCan.hxx.

◆ remoteAliases_

AliasCache openlcb::IfCan::remoteAliases_
private

Aliases we know are owned by remote nodes on this If.

This member must only be accessed from the If's executor.

Definition at line 151 of file IfCan.hxx.


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