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

SimpleStack with a CAN-bus based interface and IO functions for CAN-bus. More...

#include <SimpleStack.hxx>

Inheritance diagram for openlcb::SimpleCanStackBase:
openlcb::SimpleStackBase openlcb::SimpleCanStack openlcb::SimpleTrainCanStack

Classes

class  CanPhysicalIf
 
class  WithStreamSupport
 Helper class to add stream support straight after construction. More...
 

Public Member Functions

 SimpleCanStackBase (const openlcb::NodeID node_id)
 
CanHubFlowcan_hub ()
 
void add_can_port_blocking (const char *device)
 Adds a CAN bus port with synchronous driver API.
 
void add_gridconnect_port (const char *path, Notifiable *on_exit=nullptr)
 Adds a gridconnect port to the CAN bus.
 
void start_tcp_hub_server (int port=12021)
 Starts a TCP server on the specified port in listening mode.
 
GcTcpHubget_tcp_hub_server ()
 Retrieve the instance of the GridConnect Hub server, which was started with start_tcp_hub_server().
 
void shutdown_tcp_hub_server ()
 Shuts down the GridConnect Hub server, if previously started.
 
void connect_tcp_gridconnect_hub (const char *host, int port)
 Connects to a CAN hub using TCP with the gridconnect protocol.
 
void print_all_packets (bool timestamped=false)
 Causes all CAN packets to be printed to stdout.
 
HubFlowgridconnect_hub ()
 Returns the hub to be used for gridconnect-format CANbus.
 
IfCanif_can ()
 
void add_stream_support ()
 Enables stream transport in the interface and in the memory config protocol.
 
- Public Member Functions inherited from openlcb::SimpleStackBase
 SimpleStackBase (std::function< std::unique_ptr< PhysicalIf >()> create_if_helper)
 
Executor< EXECUTOR_PRIORITIES > * executor ()
 
Serviceservice ()
 
Ififace ()
 
DatagramServicedg_service ()
 
SimpleInfoFlowinfo_flow ()
 Accessor for clients that have their custom SNIP-like handler.
 
virtual Nodenode ()=0
 
MemoryConfigHandlermemory_config_handler ()
 
ConfigUpdateServiceconfig_service ()
 
void set_tx_activity_led (const Gpio *led, long long period=MSEC_TO_NSEC(33))
 Adds an activiy LED which will be flashed every time a message is sent from this node to the network.
 
void restart_stack ()
 Reinitializes the node.
 
void loop_executor (bool delay_start=false)
 Donates the current thread to the executor.
 
void start_after_delay ()
 Call this function when you used delay_start upon starting the executor.
 
void start_executor_thread (const char *name, int priority, size_t stack_size, bool delay_start=false)
 Instructs the executor to create a new thread and run in there.
 
int create_config_file_if_needed (const InternalConfigData &ofs, uint16_t expected_version, unsigned file_size)
 Tries to open the config file; if not existant, the size too small, or the version number is mismatched, then creates a new file of the given size with all 0xFF bytes inside.
 
int check_version_and_factory_reset (const InternalConfigData &ofs, uint16_t expected_version, bool force=false)
 Checks the version information in the EEPROM and performs a factory reset if incorrect or if force is set.
 
void send_event (uint64_t event_id)
 Helper function to send an event report to the bus.
 
void send_message_to (Defs::MTI mti, NodeHandle dst, const string &payload=EMPTY_PAYLOAD)
 Sends an addressed message to the bus.
 
virtual uint64_t get_pip ()
 Get the PIP response value.
 

Protected Member Functions

void start_iface (bool restart) override
 Helper function for start_stack et al.
 
- Protected Member Functions inherited from openlcb::SimpleStackBase
void start_stack (bool delay_start)
 Call this function once after the actual IO ports are set up.
 
virtual void start_node ()=0
 Hook for clients to initialize the node-specific components.
 
void default_start_node ()
 Exports the memory config spaces that are typically used for a complex node.
 

Private Member Functions

std::unique_ptr< PhysicalIfcreate_if (const openlcb::NodeID node_id)
 Constructor helper function.
 

Private Attributes

std::unique_ptr< GcTcpHubgcHubServer_
 Holds the ownership of the TCP hub server (if one was created).
 

Additional Inherited Members

- Static Public Member Functions inherited from openlcb::SimpleStackBase
static void factory_reset_all_events (const InternalConfigData &ofs, uint64_t node_id, int fd)
 Overwrites all events in the eeprom with a brand new event ID.
 
static void set_event_offsets (const vector< uint16_t > *offsets)
 Call this function at the beginning of appl_main, just before {} or { create_config_file_if_needed} if the list of event offsets are dyamically created instead of statically linked.
 
- Static Public Attributes inherited from openlcb::SimpleStackBase
static const unsigned EXECUTOR_PRIORITIES = 5
 
- Protected Attributes inherited from openlcb::SimpleStackBase
Executor< EXECUTOR_PRIORITIES > executor_ {NO_THREAD()}
 This executor's threads will be handled.
 
Service service_ {&executor_}
 Default service on the particular executor.
 
std::unique_ptr< PhysicalIfifaceHolder_
 Pointer to the polymorphic implementation of the OpenLCB If.
 
Ififace_ {ifaceHolder_->iface()}
 The OpenLCB interface object. Owned by ifaceHolder_;.
 
DatagramServicedatagramService_ {ifaceHolder_->datagram_service()}
 The datagram service bound to the interface object.
 
ConfigUpdateFlow configUpdateFlow_ {iface()}
 Calls the config listeners with the configuration FD.
 
InitializeFlow initFlow_ {&service_}
 The initialization flow takes care for node startup duties.
 
EventService eventService_ {iface()}
 Dispatches event protocol requests to the event handlers.
 
SimpleInfoFlow infoFlow_ {iface()}
 General flow for simple info requests.
 
MemoryConfigHandler memoryConfigHandler_
 
std::unique_ptr< HubFlowgcHub_
 All packets are forwarded to this hub in gridconnect format, if needed.
 
std::unique_ptr< GCAdapterBasegcAdapter_
 Bridge between canHub_ and gcHub_. Lazily initialized.
 
std::vector< std::unique_ptr< Destructable > > additionalComponents_
 Stores and keeps ownership of optional components.
 

Detailed Description

SimpleStack with a CAN-bus based interface and IO functions for CAN-bus.

Definition at line 315 of file SimpleStack.hxx.

Constructor & Destructor Documentation

◆ SimpleCanStackBase()

openlcb::SimpleCanStackBase::SimpleCanStackBase ( const openlcb::NodeID  node_id)

Definition at line 70 of file SimpleStack.cxx.

Member Function Documentation

◆ add_can_port_blocking()

void openlcb::SimpleCanStackBase::add_can_port_blocking ( const char *  device)
inline

Adds a CAN bus port with synchronous driver API.

Definition at line 330 of file SimpleStack.hxx.

◆ add_gridconnect_port()

void openlcb::SimpleCanStackBase::add_gridconnect_port ( const char *  path,
Notifiable on_exit = nullptr 
)

Adds a gridconnect port to the CAN bus.

Definition at line 416 of file SimpleStack.cxx.

◆ add_stream_support()

void openlcb::SimpleCanStackBase::add_stream_support ( )

Enables stream transport in the interface and in the memory config protocol.

Definition at line 104 of file SimpleStack.cxx.

◆ can_hub()

CanHubFlow * openlcb::SimpleCanStackBase::can_hub ( )
inline
Returns
the CanHubFlow to which this stack is talking to. This hub flow usually has two members: the interface object from the software stack and the hardware connection via which to connect to the physical bus (which may be a device driver or a gridconnect protocol converter).

Definition at line 324 of file SimpleStack.hxx.

◆ connect_tcp_gridconnect_hub()

void openlcb::SimpleCanStackBase::connect_tcp_gridconnect_hub ( const char *  host,
int  port 
)
inline

Connects to a CAN hub using TCP with the gridconnect protocol.

Definition at line 412 of file SimpleStack.hxx.

◆ create_if()

std::unique_ptr< SimpleStackBase::PhysicalIf > openlcb::SimpleCanStackBase::create_if ( const openlcb::NodeID  node_id)
private

Constructor helper function.

Creates the specific objects needed for the CAN interface to function. Will be called exactly once by the constructor of the base class.

Definition at line 75 of file SimpleStack.cxx.

◆ get_tcp_hub_server()

GcTcpHub * openlcb::SimpleCanStackBase::get_tcp_hub_server ( )
inline

Retrieve the instance of the GridConnect Hub server, which was started with start_tcp_hub_server().

Returns
the TCP hub server, or nullptr if no server was ever started.

Definition at line 400 of file SimpleStack.hxx.

◆ gridconnect_hub()

HubFlow * openlcb::SimpleCanStackBase::gridconnect_hub ( )
inline

Returns the hub to be used for gridconnect-format CANbus.

You can inject text CAN packets to this hub, add printers and in general connect devices and sockets using the gridconnect protocol to talk CANbus.

The actual gridconnect parser / renderer objects will be created upon the first call to this function.

Definition at line 433 of file SimpleStack.hxx.

◆ if_can()

IfCan * openlcb::SimpleCanStackBase::if_can ( )
inline

Definition at line 444 of file SimpleStack.hxx.

◆ print_all_packets()

void openlcb::SimpleCanStackBase::print_all_packets ( bool  timestamped = false)
inline

Causes all CAN packets to be printed to stdout.

Definition at line 420 of file SimpleStack.hxx.

◆ shutdown_tcp_hub_server()

void openlcb::SimpleCanStackBase::shutdown_tcp_hub_server ( )
inline

Shuts down the GridConnect Hub server, if previously started.

Definition at line 406 of file SimpleStack.hxx.

◆ start_iface()

void openlcb::SimpleCanStackBase::start_iface ( bool  restart)
overrideprotectedvirtual

Helper function for start_stack et al.

Implements openlcb::SimpleStackBase.

Definition at line 226 of file SimpleStack.cxx.

◆ start_tcp_hub_server()

void openlcb::SimpleCanStackBase::start_tcp_hub_server ( int  port = 12021)
inline

Starts a TCP server on the specified port in listening mode.

Each incoming connection will be assumed to be in gridconnect protocol and will be added to the gridconnect hub.

@TODO (balazs.racz) make this more efficient by rendering to string only once for all connections.

Definition at line 390 of file SimpleStack.hxx.

Member Data Documentation

◆ gcHubServer_

std::unique_ptr<GcTcpHub> openlcb::SimpleCanStackBase::gcHubServer_
private

Holds the ownership of the TCP hub server (if one was created).

Definition at line 518 of file SimpleStack.hxx.


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