|
Open Model Railroad Network (OpenMRN)
|
Implementation of the OpenLCB interface abstraction for the CAN-bus interface standard. More...
#include <IfCan.hxx>
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). | |
| AliasCache * | local_aliases () |
| AliasCache * | remote_aliases () |
| AliasAllocator * | alias_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. | |
| Node * | lookup_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. | |
| MessageHandler * | global_message_write_flow () |
| MessageHandler * | addressed_message_write_flow () |
| MessageDispatchFlow * | dispatcher () |
| void | add_local_node (Node *node) |
| Registers a new local node on this interface. | |
| Node * | lookup_local_node (NodeID id) |
| Looks up a node ID in the local nodes' registry. | |
| Node * | first_local_node () |
| Node * | next_local_node (NodeID previous) |
| Iterator helper on the local nodes map. | |
| void | set_tx_hook (std::function< void()> hook) |
| Sets a transmit hook. | |
| StreamTransport * | stream_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. | |
| ExecutorBase * | executor () |
Public Member Functions inherited from CanIf | |
| CanIf (Service *service, CanHubFlow *device) | |
| Constructor. | |
| Service * | service () |
| FrameDispatchFlow * | frame_dispatcher () |
| OutgoingFrameHandler * | frame_write_flow () |
| OutgoingFrameHandler * | loopback_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< AliasAllocator > | aliasAllocator_ |
| 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 | |
| MessageHandler * | globalWriteFlow_ |
| Allocator containing the global write flows. | |
| MessageHandler * | addressedWriteFlow_ |
| Allocator containing the addressed write flows. | |
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.
| 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.
| executor | will be used to process incoming (and outgoing) messages. |
| device | is 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_size | tells the number of aliases to keep track of for nocal virtual nodes and proxied nodes. |
| remote_alias_cache_size | tells the number of aliases to keep track of for remote nodes on the bus. |
| local_nodes_count | is the maximum number of virtual nodes that this interface will support. |
| void openlcb::IfCan::add_addressed_message_support | ( | ) |
|
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.
Implements openlcb::If.
|
inline |
|
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.
|
overridevirtual |
Removes a local node from this interface.
This function must be called from the interface's executor.
| node | is the node to delete. The node will not be freed, just removed from the data structures. |
Implements openlcb::If.
|
overridevirtual |
Implements openlcb::If.
|
inline |
|
overridevirtual |
Looks up a node ID in the local nodes' registry.
This function must be called from the interface's executor.
| handle | is the NodeHandle representing a target node. |
Reimplemented from openlcb::If.
|
overridevirtual |
Implements openlcb::If.
|
inline |
| 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.
| source | a local node to use for sending this message out. Must be already initialized. |
| void openlcb::IfCan::set_alias_allocator | ( | AliasAllocator * | a | ) |
|
friend |
|
private |
|
private |
|
private |
|
private |