AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
isobus::CANNetworkManager Class Reference

The main CAN network manager object, handles protocol management and updating other stack components. Provides an interface for sending CAN messages. More...

#include <can_network_manager.hpp>

Collaboration diagram for isobus::CANNetworkManager:
[legend]

Public Member Functions

void initialize ()
 Initializer function for the network manager.
 
std::shared_ptr< ControlFunctionget_control_function (std::uint8_t channelIndex, std::uint8_t address, CANLibBadge< AddressClaimStateMachine >) const
 Called only by the stack, returns a control function based on certain port and address.
 
void add_global_parameter_group_number_callback (std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parent)
 This is how you register a callback for any PGN destined for the global address (0xFF)
 
void remove_global_parameter_group_number_callback (std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parent)
 This is how you remove a callback for any PGN destined for the global address (0xFF)
 
std::size_t get_number_global_parameter_group_number_callbacks () const
 Returns the number of global PGN callbacks that have been registered with the network manager.
 
void add_any_control_function_parameter_group_number_callback (std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parent)
 Registers a callback for ANY control function sending the associated PGN.
 
void remove_any_control_function_parameter_group_number_callback (std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parent)
 This is how you remove a callback added with add_any_control_function_parameter_group_number_callback.
 
EventDispatcher< CANMessage > & get_transmitted_message_event_dispatcher ()
 Returns the network manager's event dispatcher for notifying consumers whenever a message is transmitted by our application.
 
std::shared_ptr< InternalControlFunctionget_internal_control_function (std::shared_ptr< ControlFunction > controlFunction)
 Returns an internal control function if the passed-in control function is an internal type.
 
float get_estimated_busload (std::uint8_t canChannel)
 Returns an estimated busload between 0.0f and 100.0f.
 
bool send_can_message (std::uint32_t parameterGroupNumber, const std::uint8_t *dataBuffer, std::uint32_t dataLength, std::shared_ptr< InternalControlFunction > sourceControlFunction, std::shared_ptr< ControlFunction > destinationControlFunction=nullptr, CANIdentifier::CANPriority priority=CANIdentifier::CANPriority::PriorityDefault6, TransmitCompleteCallback txCompleteCallback=nullptr, void *parentPointer=nullptr, DataChunkCallback frameChunkCallback=nullptr)
 This is the main way to send a CAN message of any length.
 
void update ()
 The main update function for the network manager. Updates all protocols.
 
void process_receive_can_message_frame (const CANMessageFrame &rxFrame)
 Used to tell the network manager when frames are received on the bus.
 
void process_transmitted_can_message_frame (const CANMessageFrame &txFrame)
 Used to tell the network manager when frames are emitted on the bus.
 
void on_control_function_destroyed (std::shared_ptr< ControlFunction > controlFunction, CANLibBadge< ControlFunction >)
 Informs the network manager that a control function object has been destroyed, so that it can be purged from the network manager.
 
void on_control_function_created (std::shared_ptr< ControlFunction > controlFunction, CANLibBadge< ControlFunction >)
 Informs the network manager that a control function object has been created, so that it can be added to the network manager.
 
void on_control_function_created (std::shared_ptr< ControlFunction > controlFunction, CANLibBadge< InternalControlFunction >)
 Informs the network manager that a control function object has been created, so that it can be added to the network manager.
 
void on_control_function_created (std::shared_ptr< ControlFunction > controlFunction, CANLibBadge< PartneredControlFunction >)
 Informs the network manager that a control function object has been created, so that it can be added to the network manager.
 
void add_control_function_status_change_callback (ControlFunctionStateCallback callback)
 Use this to get a callback when a control function goes online or offline. This could be useful if you want event driven notifications for when your partners are disconnected from the bus.
 
void remove_control_function_status_change_callback (ControlFunctionStateCallback callback)
 Used to remove callbacks added with add_control_function_status_change_callback.
 
const std::list< std::shared_ptr< InternalControlFunction > > & get_internal_control_functions () const
 Gets all the internal control functions that are currently registered in the network manager.
 
const std::list< std::shared_ptr< PartneredControlFunction > > & get_partnered_control_functions () const
 Gets all the partnered control functions that are currently registered in the network manager.
 
std::list< std::shared_ptr< ControlFunction > > get_control_functions (bool includingOffline) const
 Gets all the control functions that are known to the network manager.
 
std::list< std::shared_ptr< TransportProtocolSessionBase > > get_active_transport_protocol_sessions (std::uint8_t canPortIndex) const
 Gets all the active transport protocol sessions that are currently active.
 
std::unique_ptr< FastPacketProtocol > & get_fast_packet_protocol (std::uint8_t canPortIndex)
 Returns the class instance of the NMEA2k fast packet protocol. Use this to register for FP multipacket messages.
 
HeartbeatInterfaceget_heartbeat_interface (std::uint8_t canPortIndex)
 Returns an interface which can be used to manage ISO11783-7 heartbeat messages.
 
CANNetworkConfigurationget_configuration ()
 Returns the configuration of this network manager.
 
EventDispatcher< std::shared_ptr< InternalControlFunction > > & get_address_violation_event_dispatcher ()
 Returns the network manager's event dispatcher for notifying consumers whenever an address violation occurs involving an internal control function.
 

Static Public Attributes

static CANNetworkManager CANNetwork
 Static singleton of the one network manager. Use this to access stack functionality.
 

Protected Member Functions

bool add_protocol_parameter_group_number_callback (std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parentPointer)
 Adds a PGN callback for a protocol class.
 
bool remove_protocol_parameter_group_number_callback (std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parentPointer)
 Removes a PGN callback for a protocol class.
 
bool send_can_message_raw (std::uint32_t portIndex, std::uint8_t sourceAddress, std::uint8_t destAddress, std::uint32_t parameterGroupNumber, std::uint8_t priority, const void *data, std::uint32_t size, CANLibBadge< AddressClaimStateMachine >) const
 Sends a CAN message using raw addresses. Used only by the stack.
 
void protocol_message_callback (const CANMessage &message)
 Processes completed protocol messages. Causes PGN callbacks to trigger.
 

Private Member Functions

 CANNetworkManager ()
 Constructor for the network manager. Sets default values for members.
 
void update_address_table (const CANMessage &message)
 Updates the internal address table based on a received CAN message.
 
void update_internal_cfs ()
 Updates the internal address table based on updates to internal cfs addresses.
 
void update_busload (std::uint8_t channelIndex, std::uint32_t numberOfBitsProcessed)
 Processes a CAN message's contribution to the current busload.
 
void update_busload_history ()
 Updates the stored bit accumulators for calculating the bus load over a multiple sample windows.
 
void update_control_functions (const CANMessageFrame &rxFrame)
 Creates new control function classes based on the frames coming in from the bus.
 
void update_new_partners ()
 Checks if new partners have been created and matches them to existing control functions.
 
CANMessageFrame construct_frame (std::uint32_t portIndex, std::uint8_t sourceAddress, std::uint8_t destAddress, std::uint32_t parameterGroupNumber, std::uint8_t priority, const void *data, std::uint32_t size) const
 Builds a CAN frame from a frame's discrete components.
 
std::shared_ptr< ControlFunctionget_control_function (std::uint8_t channelIndex, std::uint8_t address) const
 Returns a control function based on a CAN address and channel index.
 
CANMessage get_next_can_message_from_rx_queue ()
 Get the next CAN message from the received message queue, and remove it from the queue.
 
CANMessage get_next_can_message_from_tx_queue ()
 Get the next CAN message from the received message queue, and remove it from the queue.
 
void on_control_function_created (std::shared_ptr< ControlFunction > controlFunction)
 Informs the network manager that a control function object has been created.
 
void process_any_control_function_pgn_callbacks (const CANMessage &currentMessage)
 Processes a can message for callbacks added with add_any_control_function_parameter_group_number_callback.
 
void process_can_message_for_address_violations (const CANMessage &currentMessage)
 Validates that a CAN message has not caused an address violation. If a violation is found, the network manager will notify the affected address claim state machine to re-claim as is required by ISO 11783-5, and will attempt to activate a DTC that is defined in ISO 11783-5.
 
void process_control_function_state_change_callback (std::shared_ptr< ControlFunction > controlFunction, ControlFunctionState state)
 Checks the control function state callback list to see if we need to call a control function state callback.
 
void process_protocol_pgn_callbacks (const CANMessage &currentMessage)
 Processes a can message for callbacks added with add_protocol_parameter_group_number_callback.
 
void process_can_message_for_global_and_partner_callbacks (const CANMessage &message)
 Matches a CAN message to any matching PGN callback, and calls that callback.
 
void process_can_message_for_commanded_address (const CANMessage &message)
 Processes a CAN message to see if it's a commanded address message, and if it is, it attempts to set the relevant CF's address to the new value.
 
void process_rx_messages ()
 Processes the internal received message queue.
 
void process_tx_messages ()
 Processes the internal transmitted message queue.
 
void prune_inactive_control_functions ()
 Checks to see if any control function didn't claim during a round of address claiming and removes it if needed.
 
bool send_can_message_raw (std::uint32_t portIndex, std::uint8_t sourceAddress, std::uint8_t destAddress, std::uint32_t parameterGroupNumber, std::uint8_t priority, const void *data, std::uint32_t size) const
 Sends a CAN message using raw addresses. Used only by the stack.
 
ParameterGroupNumberCallbackData get_global_parameter_group_number_callback (std::uint32_t index) const
 Gets a PGN callback for the global address by index.
 

Private Attributes

CANNetworkConfiguration configuration
 The configuration for this network manager.
 
std::array< std::unique_ptr< TransportProtocolManager >, CAN_PORT_MAXIMUMtransportProtocols
 One instance of the transport protocol manager for each channel.
 
std::array< std::unique_ptr< ExtendedTransportProtocolManager >, CAN_PORT_MAXIMUMextendedTransportProtocols
 One instance of the extended transport protocol manager for each channel.
 
std::array< std::unique_ptr< FastPacketProtocol >, CAN_PORT_MAXIMUMfastPacketProtocol
 One instance of the fast packet protocol for each channel.
 
std::array< std::unique_ptr< HeartbeatInterface >, CAN_PORT_MAXIMUMheartBeatInterfaces
 Manages ISOBUS heartbeat requests, one per channel.
 
std::array< std::deque< std::uint32_t >, CAN_PORT_MAXIMUMbusloadMessageBitsHistory
 Stores the approximate number of bits processed on each channel over multiple previous time windows.
 
std::array< std::uint32_t, CAN_PORT_MAXIMUMcurrentBusloadBitAccumulator
 Accumulates the approximate number of bits processed on each channel during the current time window.
 
std::array< std::uint32_t, CAN_PORT_MAXIMUMlastAddressClaimRequestTimestamp_ms
 Stores timestamps for when the last request for the address claim PGN was received. Used to prune stale CFs.
 
std::array< std::array< std::shared_ptr< ControlFunction >, NULL_CAN_ADDRESS >, CAN_PORT_MAXIMUMcontrolFunctionTable
 Table to maintain address to NAME mappings.
 
std::list< std::shared_ptr< ControlFunction > > inactiveControlFunctions
 A list of the control function that currently don't have a valid address.
 
std::list< std::shared_ptr< InternalControlFunction > > internalControlFunctions
 A list of the internal control functions.
 
std::list< std::shared_ptr< PartneredControlFunction > > partneredControlFunctions
 A list of the partnered control functions.
 
std::list< ParameterGroupNumberCallbackDataprotocolPGNCallbacks
 A list of PGN callback registered by CAN protocols.
 
std::queue< CANMessagereceivedMessageQueue
 A queue of received messages to process.
 
std::queue< CANMessagetransmittedMessageQueue
 A queue of transmitted messages to process (already sent, so changes to the message won't affect the bus)
 
std::list< ControlFunctionStateCallbackcontrolFunctionStateCallbacks
 List of all control function state callbacks.
 
std::vector< ParameterGroupNumberCallbackDataglobalParameterGroupNumberCallbacks
 A list of all global PGN callbacks.
 
std::vector< ParameterGroupNumberCallbackDataanyControlFunctionParameterGroupNumberCallbacks
 A list of all global PGN callbacks.
 
EventDispatcher< CANMessagemessageTransmittedEventDispatcher
 An event dispatcher for notifying consumers about transmitted messages by our application.
 
EventDispatcher< std::shared_ptr< InternalControlFunction > > addressViolationEventDispatcher
 An event dispatcher for notifying consumers about address violations.
 
Mutex receivedMessageQueueMutex
 A mutex for receive messages thread safety.
 
Mutex protocolPGNCallbacksMutex
 A mutex for PGN callback thread safety.
 
Mutex anyControlFunctionCallbacksMutex
 Mutex to protect the "any CF" callbacks.
 
Mutex busloadUpdateMutex
 A mutex that protects the busload metrics since we calculate it on our own thread.
 
Mutex controlFunctionStatusCallbacksMutex
 A Mutex that protects access to the control function status callback list.
 
Mutex transmittedMessageQueueMutex
 A mutex for protecting the transmitted message queue.
 
std::uint32_t busloadUpdateTimestamp_ms = 0
 Tracks a time window for determining approximate busload.
 
std::uint32_t updateTimestamp_ms = 0
 Keeps track of the last time the CAN stack was update in milliseconds.
 
bool initialized = false
 True if the network manager has been initialized by the update function.
 

Static Private Attributes

static constexpr std::uint32_t BUSLOAD_SAMPLE_WINDOW_MS = 1000
 Using a 1s window to average the bus load, otherwise it's very erratic.
 
static constexpr std::uint32_t BUSLOAD_UPDATE_FREQUENCY_MS = 100
 Bus load bit accumulation happens over a 100ms window.
 

Friends

class AddressClaimStateMachine
 Allows the network manager to work closely with the address claiming process.
 
class ExtendedTransportProtocolManager
 Allows the network manager to access the ETP manager.
 
class TransportProtocolManager
 Allows the network manager to work closely with the transport protocol manager object.
 
class DiagnosticProtocol
 Allows the diagnostic protocol to access the protected functions on the network manager.
 
class ParameterGroupNumberRequestProtocol
 Allows the PGN request protocol to access the network manager protected functions.
 
class FastPacketProtocol
 Allows the FP protocol to access the network manager protected functions.
 

Detailed Description

The main CAN network manager object, handles protocol management and updating other stack components. Provides an interface for sending CAN messages.

Definition at line 48 of file can_network_manager.hpp.

Constructor & Destructor Documentation

◆ CANNetworkManager()

isobus::CANNetworkManager::CANNetworkManager ( )
private

Constructor for the network manager. Sets default values for members.

Definition at line 496 of file can_network_manager.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ add_any_control_function_parameter_group_number_callback()

void isobus::CANNetworkManager::add_any_control_function_parameter_group_number_callback ( std::uint32_t parameterGroupNumber,
CANLibCallback callback,
void * parent )

Registers a callback for ANY control function sending the associated PGN.

Parameters
[in]parameterGroupNumberThe PGN you want to register for
[in]callbackThe callback that will be called when parameterGroupNumber is received from any control function
[in]parentA generic context variable that helps identify what object the callback is destined for. Can be nullptr if you don't want to use it.

Definition at line 70 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ add_control_function_status_change_callback()

void isobus::CANNetworkManager::add_control_function_status_change_callback ( ControlFunctionStateCallback callback)

Use this to get a callback when a control function goes online or offline. This could be useful if you want event driven notifications for when your partners are disconnected from the bus.

Parameters
[in]callbackThe callback you want to be called when the any control function changes state

Definition at line 378 of file can_network_manager.cpp.

◆ add_global_parameter_group_number_callback()

void isobus::CANNetworkManager::add_global_parameter_group_number_callback ( std::uint32_t parameterGroupNumber,
CANLibCallback callback,
void * parent )

This is how you register a callback for any PGN destined for the global address (0xFF)

Parameters
[in]parameterGroupNumberThe PGN you want to register for
[in]callbackThe callback that will be called when parameterGroupNumber is received from the global address (0xFF)
[in]parentA generic context variable that helps identify what object the callback is destined for. Can be nullptr if you don't want to use it.

Definition at line 50 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ add_protocol_parameter_group_number_callback()

bool isobus::CANNetworkManager::add_protocol_parameter_group_number_callback ( std::uint32_t parameterGroupNumber,
CANLibCallback callback,
void * parentPointer )
protected

Adds a PGN callback for a protocol class.

Parameters
[in]parameterGroupNumberThe PGN to register for
[in]callbackThe callback to call when the PGN is received
[in]parentPointerA generic context variable that helps identify what object the callback was destined for
Returns
true if the callback was added, otherwise false

Definition at line 464 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ construct_frame()

CANMessageFrame isobus::CANNetworkManager::construct_frame ( std::uint32_t portIndex,
std::uint8_t sourceAddress,
std::uint8_t destAddress,
std::uint32_t parameterGroupNumber,
std::uint8_t priority,
const void * data,
std::uint32_t size ) const
private

Builds a CAN frame from a frame's discrete components.

Parameters
[in]portIndexThe CAN channel index of the CAN message being processed
[in]sourceAddressThe source address to send the CAN message from
[in]destAddressThe destination address to send the message to
[in]parameterGroupNumberThe PGN to use when sending the message
[in]priorityThe CAN priority of the message being sent
[in]dataA pointer to the data buffer to send from
[in]sizeThe size of the message to send
Returns
The constructed frame based on the inputs

Definition at line 811 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ get_active_transport_protocol_sessions()

std::list< std::shared_ptr< TransportProtocolSessionBase > > isobus::CANNetworkManager::get_active_transport_protocol_sessions ( std::uint8_t canPortIndex) const

Gets all the active transport protocol sessions that are currently active.

Note
The list returns pointers to the transport protocol sessions, but they can disappear at any time
Parameters
[in]canPortIndexThe CAN channel index to get the transport protocol sessions for
Returns
A list of all the active transport protocol sessions

Definition at line 435 of file can_network_manager.cpp.

◆ get_address_violation_event_dispatcher()

EventDispatcher< std::shared_ptr< InternalControlFunction > > & isobus::CANNetworkManager::get_address_violation_event_dispatcher ( )

Returns the network manager's event dispatcher for notifying consumers whenever an address violation occurs involving an internal control function.

Returns
An event dispatcher which can be used to get notified about address violations

Definition at line 459 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ get_configuration()

CANNetworkConfiguration & isobus::CANNetworkManager::get_configuration ( )

Returns the configuration of this network manager.

Returns
The configuration class for this network manager

Definition at line 454 of file can_network_manager.cpp.

◆ get_control_function() [1/2]

std::shared_ptr< ControlFunction > isobus::CANNetworkManager::get_control_function ( std::uint8_t channelIndex,
std::uint8_t address ) const
private

Returns a control function based on a CAN address and channel index.

Parameters
[in]channelIndexThe CAN channel index of the CAN message being processed
[in]addressThe CAN address associated with a control function
Returns
A control function matching the address and CAN port passed in

Definition at line 871 of file can_network_manager.cpp.

◆ get_control_function() [2/2]

std::shared_ptr< ControlFunction > isobus::CANNetworkManager::get_control_function ( std::uint8_t channelIndex,
std::uint8_t address,
CANLibBadge< AddressClaimStateMachine >  ) const

Called only by the stack, returns a control function based on certain port and address.

Parameters
[in]channelIndexCAN Channel index of the control function
[in]addressAddress of the control function
Returns
A control function that matches the parameters, or nullptr if no match was found

Definition at line 45 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_control_functions()

std::list< std::shared_ptr< ControlFunction > > isobus::CANNetworkManager::get_control_functions ( bool includingOffline) const

Gets all the control functions that are known to the network manager.

Parameters
[in]includingOfflineIf true, all control functions are returned, otherwise only online control functions are returned
Returns
A list of all the control functions

Definition at line 412 of file can_network_manager.cpp.

◆ get_estimated_busload()

float isobus::CANNetworkManager::get_estimated_busload ( std::uint8_t canChannel)

Returns an estimated busload between 0.0f and 100.0f.

This calculates busload over a 1 second window.

Note
This function averages between best and worst case bit-stuffing. This may be more or less aggressive than the actual amount of bit stuffing. Knowing the actual amount of bit stuffing is impossible, so this should only be used as an estimate.
Parameters
[in]canChannelThe channel to estimate the bus load for
Returns
Estimated busload over the last 1 second

Definition at line 104 of file can_network_manager.cpp.

◆ get_fast_packet_protocol()

std::unique_ptr< FastPacketProtocol > & isobus::CANNetworkManager::get_fast_packet_protocol ( std::uint8_t canPortIndex)

Returns the class instance of the NMEA2k fast packet protocol. Use this to register for FP multipacket messages.

Parameters
[in]canPortIndexThe CAN channel index to get the fast packet protocol for
Returns
The class instance of the NMEA2k fast packet protocol.

Definition at line 443 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ get_global_parameter_group_number_callback()

ParameterGroupNumberCallbackData isobus::CANNetworkManager::get_global_parameter_group_number_callback ( std::uint32_t index) const
private

Gets a PGN callback for the global address by index.

Parameters
[in]indexThe index of the callback to get
Returns
A structure containing the global PGN callback data

Definition at line 244 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_heartbeat_interface()

HeartbeatInterface & isobus::CANNetworkManager::get_heartbeat_interface ( std::uint8_t canPortIndex)

Returns an interface which can be used to manage ISO11783-7 heartbeat messages.

Parameters
[in]canPortIndexThe index of the CAN channel associated to the interface you're requesting
Returns
ISO11783-7 heartbeat interface

Definition at line 448 of file can_network_manager.cpp.

◆ get_internal_control_function()

std::shared_ptr< InternalControlFunction > isobus::CANNetworkManager::get_internal_control_function ( std::shared_ptr< ControlFunction > controlFunction)

Returns an internal control function if the passed-in control function is an internal type.

Parameters
[in]controlFunctionThe control function to get the internal control function from
Returns
An internal control function casted from the passed in control function

Definition at line 92 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ get_internal_control_functions()

const std::list< std::shared_ptr< InternalControlFunction > > & isobus::CANNetworkManager::get_internal_control_functions ( ) const

Gets all the internal control functions that are currently registered in the network manager.

Returns
A list of all the internal control functions

Definition at line 402 of file can_network_manager.cpp.

◆ get_next_can_message_from_rx_queue()

CANMessage isobus::CANNetworkManager::get_next_can_message_from_rx_queue ( )
private

Get the next CAN message from the received message queue, and remove it from the queue.

Note
This will only ever get an 8 byte message because they are directly translated from CAN frames.
Returns
The message that was at the front of the queue, or an invalid message if the queue is empty

Definition at line 882 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_next_can_message_from_tx_queue()

CANMessage isobus::CANNetworkManager::get_next_can_message_from_tx_queue ( )
private

Get the next CAN message from the received message queue, and remove it from the queue.

Note
This will only ever get an 8 byte message because they are directly translated from CAN frames.
Returns
The message that was at the front of the queue, or an invalid message if the queue is empty

Definition at line 894 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_number_global_parameter_group_number_callbacks()

std::size_t isobus::CANNetworkManager::get_number_global_parameter_group_number_callbacks ( ) const

Returns the number of global PGN callbacks that have been registered with the network manager.

Returns
The number of global PGN callbacks that have been registered with the network manager

Definition at line 65 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ get_partnered_control_functions()

const std::list< std::shared_ptr< PartneredControlFunction > > & isobus::CANNetworkManager::get_partnered_control_functions ( ) const

Gets all the partnered control functions that are currently registered in the network manager.

Returns
A list of all the partnered control functions

Definition at line 407 of file can_network_manager.cpp.

◆ get_transmitted_message_event_dispatcher()

EventDispatcher< CANMessage > & isobus::CANNetworkManager::get_transmitted_message_event_dispatcher ( )

Returns the network manager's event dispatcher for notifying consumers whenever a message is transmitted by our application.

Returns
An event dispatcher which can be used to get notified about transmitted messages

Definition at line 87 of file can_network_manager.cpp.

◆ initialize()

void isobus::CANNetworkManager::initialize ( )

Initializer function for the network manager.

Definition at line 31 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_control_function_created() [1/4]

void isobus::CANNetworkManager::on_control_function_created ( std::shared_ptr< ControlFunction > controlFunction)
private

Informs the network manager that a control function object has been created.

Parameters
[in]controlFunctionThe control function that was created

Definition at line 906 of file can_network_manager.cpp.

◆ on_control_function_created() [2/4]

void isobus::CANNetworkManager::on_control_function_created ( std::shared_ptr< ControlFunction > controlFunction,
CANLibBadge< ControlFunction >  )

Informs the network manager that a control function object has been created, so that it can be added to the network manager.

Parameters
[in]controlFunctionThe control function that was created

Definition at line 362 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_control_function_created() [3/4]

void isobus::CANNetworkManager::on_control_function_created ( std::shared_ptr< ControlFunction > controlFunction,
CANLibBadge< InternalControlFunction >  )

Informs the network manager that a control function object has been created, so that it can be added to the network manager.

Parameters
[in]controlFunctionThe control function that was created

Definition at line 367 of file can_network_manager.cpp.

Here is the call graph for this function:

◆ on_control_function_created() [4/4]

void isobus::CANNetworkManager::on_control_function_created ( std::shared_ptr< ControlFunction > controlFunction,
CANLibBadge< PartneredControlFunction >  )

Informs the network manager that a control function object has been created, so that it can be added to the network manager.

Parameters
[in]controlFunctionThe control function that was created

Definition at line 373 of file can_network_manager.cpp.

Here is the call graph for this function:

◆ on_control_function_destroyed()

void isobus::CANNetworkManager::on_control_function_destroyed ( std::shared_ptr< ControlFunction > controlFunction,
CANLibBadge< ControlFunction >  )

Informs the network manager that a control function object has been destroyed, so that it can be purged from the network manager.

Parameters
[in]controlFunctionThe control function that was destroyed

Definition at line 312 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_any_control_function_pgn_callbacks()

void isobus::CANNetworkManager::process_any_control_function_pgn_callbacks ( const CANMessage & currentMessage)
private

Processes a can message for callbacks added with add_any_control_function_parameter_group_number_callback.

Parameters
[in]currentMessageThe message to process

Definition at line 918 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_can_message_for_address_violations()

void isobus::CANNetworkManager::process_can_message_for_address_violations ( const CANMessage & currentMessage)
private

Validates that a CAN message has not caused an address violation. If a violation is found, the network manager will notify the affected address claim state machine to re-claim as is required by ISO 11783-5, and will attempt to activate a DTC that is defined in ISO 11783-5.

Note
Address violation occurs when two CFs are using the same source address.
Parameters
[in]currentMessageThe message to process

Definition at line 932 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_can_message_for_commanded_address()

void isobus::CANNetworkManager::process_can_message_for_commanded_address ( const CANMessage & message)
private

Processes a CAN message to see if it's a commanded address message, and if it is, it attempts to set the relevant CF's address to the new value.

Note
Changing the address will resend the address claim message if the target was an internal control function.
Parameters
[in]messageThe message to process

Definition at line 1017 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_can_message_for_global_and_partner_callbacks()

void isobus::CANNetworkManager::process_can_message_for_global_and_partner_callbacks ( const CANMessage & message)
private

Matches a CAN message to any matching PGN callback, and calls that callback.

Parameters
[in]messageA pointer to a CAN message to be processed

Definition at line 973 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_control_function_state_change_callback()

void isobus::CANNetworkManager::process_control_function_state_change_callback ( std::shared_ptr< ControlFunction > controlFunction,
ControlFunctionState state )
private

Checks the control function state callback list to see if we need to call a control function state callback.

Parameters
[in]controlFunctionThe controlFunction whose state has changed
[in]stateThe new state of the control function

Definition at line 952 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ process_protocol_pgn_callbacks()

void isobus::CANNetworkManager::process_protocol_pgn_callbacks ( const CANMessage & currentMessage)
private

Processes a can message for callbacks added with add_protocol_parameter_group_number_callback.

Parameters
[in]currentMessageThe message to process

Definition at line 961 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_receive_can_message_frame()

void isobus::CANNetworkManager::process_receive_can_message_frame ( const CANMessageFrame & rxFrame)

Used to tell the network manager when frames are received on the bus.

Parameters
[in]rxFrameFrame to process

Definition at line 270 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_rx_messages()

void isobus::CANNetworkManager::process_rx_messages ( )
private

Processes the internal received message queue.

Definition at line 1038 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_transmitted_can_message_frame()

void isobus::CANNetworkManager::process_transmitted_can_message_frame ( const CANMessageFrame & txFrame)

Used to tell the network manager when frames are emitted on the bus.

Parameters
[in]txFrameThe frame that was just emitted onto the bus

Definition at line 292 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_tx_messages()

void isobus::CANNetworkManager::process_tx_messages ( )
private

Processes the internal transmitted message queue.

Definition at line 1061 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ protocol_message_callback()

void isobus::CANNetworkManager::protocol_message_callback ( const CANMessage & message)
protected

Processes completed protocol messages. Causes PGN callbacks to trigger.

Parameters
[in]messageThe completed protocol message

Definition at line 1118 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prune_inactive_control_functions()

void isobus::CANNetworkManager::prune_inactive_control_functions ( )
private

Checks to see if any control function didn't claim during a round of address claiming and removes it if needed.

Definition at line 1073 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_any_control_function_parameter_group_number_callback()

void isobus::CANNetworkManager::remove_any_control_function_parameter_group_number_callback ( std::uint32_t parameterGroupNumber,
CANLibCallback callback,
void * parent )

This is how you remove a callback added with add_any_control_function_parameter_group_number_callback.

Parameters
[in]parameterGroupNumberThe PGN of the callback to remove
[in]callbackThe callback that will be removed
[in]parentA generic context variable that helps identify what object the callback was destined for

Definition at line 76 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ remove_control_function_status_change_callback()

void isobus::CANNetworkManager::remove_control_function_status_change_callback ( ControlFunctionStateCallback callback)

Used to remove callbacks added with add_control_function_status_change_callback.

Parameters
[in]callbackThe callback you want to remove

Definition at line 387 of file can_network_manager.cpp.

◆ remove_global_parameter_group_number_callback()

void isobus::CANNetworkManager::remove_global_parameter_group_number_callback ( std::uint32_t parameterGroupNumber,
CANLibCallback callback,
void * parent )

This is how you remove a callback for any PGN destined for the global address (0xFF)

Parameters
[in]parameterGroupNumberThe PGN of the callback to remove
[in]callbackThe callback that will be removed
[in]parentA generic context variable that helps identify what object the callback was destined for

Definition at line 55 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ remove_protocol_parameter_group_number_callback()

bool isobus::CANNetworkManager::remove_protocol_parameter_group_number_callback ( std::uint32_t parameterGroupNumber,
CANLibCallback callback,
void * parentPointer )
protected

Removes a PGN callback for a protocol class.

Parameters
[in]parameterGroupNumberThe PGN to register for
[in]callbackThe callback to call when the PGN is received
[in]parentPointerA generic context variable that helps identify what object the callback was destined for
Returns
true if the callback was removed, otherwise false

Definition at line 477 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ send_can_message()

bool isobus::CANNetworkManager::send_can_message ( std::uint32_t parameterGroupNumber,
const std::uint8_t * dataBuffer,
std::uint32_t dataLength,
std::shared_ptr< InternalControlFunction > sourceControlFunction,
std::shared_ptr< ControlFunction > destinationControlFunction = nullptr,
CANIdentifier::CANPriority priority = CANIdentifier::CANPriority::PriorityDefault6,
TransmitCompleteCallback txCompleteCallback = nullptr,
void * parentPointer = nullptr,
DataChunkCallback frameChunkCallback = nullptr )

This is the main way to send a CAN message of any length.

This function will automatically choose an appropriate transport protocol if needed. If you don't specify a destination (or use nullptr) you message will be sent as a broadcast if it is valid to do so. You can also get a callback on success or failure of the transmit.

Parameters
[in]parameterGroupNumberThe PGN to use when sending the message
[in]dataBufferA pointer to the data buffer to send from
[in]dataLengthThe size of the message to send
[in]sourceControlFunctionThe control function that is sending the message
[in]destinationControlFunctionThe control function that the message is destined for or nullptr if broadcast
[in]priorityThe CAN priority of the message being sent
[in]txCompleteCallbackA callback to be called when the message is sent or fails to send
[in]parentPointerA generic context variable that helps identify what object the callback is destined for
[in]frameChunkCallbackA callback which can be supplied to have the tack call you back to get chunks of the message as they are sent
Returns
true if the message was sent, otherwise false
Todo
Allow sending 8 byte message with the frameChunkCallback

Definition at line 119 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_can_message_raw() [1/2]

bool isobus::CANNetworkManager::send_can_message_raw ( std::uint32_t portIndex,
std::uint8_t sourceAddress,
std::uint8_t destAddress,
std::uint32_t parameterGroupNumber,
std::uint8_t priority,
const void * data,
std::uint32_t size ) const
private

Sends a CAN message using raw addresses. Used only by the stack.

Parameters
[in]portIndexThe CAN channel index to send the message from
[in]sourceAddressThe source address to send the CAN message from
[in]destAddressThe destination address to send the message to
[in]parameterGroupNumberThe PGN to use when sending the message
[in]priorityThe CAN priority of the message being sent
[in]dataA pointer to the data buffer to send from
[in]sizeThe size of the message to send
Returns
true if the message was sent, otherwise false

Definition at line 1105 of file can_network_manager.cpp.

Here is the call graph for this function:

◆ send_can_message_raw() [2/2]

bool isobus::CANNetworkManager::send_can_message_raw ( std::uint32_t portIndex,
std::uint8_t sourceAddress,
std::uint8_t destAddress,
std::uint32_t parameterGroupNumber,
std::uint8_t priority,
const void * data,
std::uint32_t size,
CANLibBadge< AddressClaimStateMachine >  ) const
protected

Sends a CAN message using raw addresses. Used only by the stack.

Parameters
[in]portIndexThe CAN channel index to send the message from
[in]sourceAddressThe source address to send the CAN message from
[in]destAddressThe destination address to send the message to
[in]parameterGroupNumberThe PGN to use when sending the message
[in]priorityThe CAN priority of the message being sent
[in]dataA pointer to the data buffer to send from
[in]sizeThe size of the message to send
Returns
true if the message was sent, otherwise false

Definition at line 232 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update()

void isobus::CANNetworkManager::update ( )

The main update function for the network manager. Updates all protocols.

Definition at line 194 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_address_table()

void isobus::CANNetworkManager::update_address_table ( const CANMessage & message)
private

Updates the internal address table based on a received CAN message.

Parameters
[in]messageA message being received by the stack

Definition at line 527 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_busload()

void isobus::CANNetworkManager::update_busload ( std::uint8_t channelIndex,
std::uint32_t numberOfBitsProcessed )
private

Processes a CAN message's contribution to the current busload.

Parameters
[in]channelIndexThe CAN channel index associated to the message being processed
[in]numberOfBitsProcessedThe number of bits to add to the busload calculation

Definition at line 635 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ update_busload_history()

void isobus::CANNetworkManager::update_busload_history ( )
private

Updates the stored bit accumulators for calculating the bus load over a multiple sample windows.

Definition at line 641 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ update_control_functions()

void isobus::CANNetworkManager::update_control_functions ( const CANMessageFrame & rxFrame)
private

Creates new control function classes based on the frames coming in from the bus.

Parameters
[in]rxFrameRaw frames coming in from the bus

Definition at line 660 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_internal_cfs()

void isobus::CANNetworkManager::update_internal_cfs ( )
private

Updates the internal address table based on updates to internal cfs addresses.

Definition at line 602 of file can_network_manager.cpp.

Here is the caller graph for this function:

◆ update_new_partners()

void isobus::CANNetworkManager::update_new_partners ( )
private

Checks if new partners have been created and matches them to existing control functions.

Definition at line 767 of file can_network_manager.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ AddressClaimStateMachine

friend class AddressClaimStateMachine
friend

Allows the network manager to work closely with the address claiming process.

Definition at line 211 of file can_network_manager.hpp.

◆ DiagnosticProtocol

friend class DiagnosticProtocol
friend

Allows the diagnostic protocol to access the protected functions on the network manager.

Definition at line 214 of file can_network_manager.hpp.

◆ ExtendedTransportProtocolManager

friend class ExtendedTransportProtocolManager
friend

Allows the network manager to access the ETP manager.

Definition at line 212 of file can_network_manager.hpp.

◆ FastPacketProtocol

friend class FastPacketProtocol
friend

Allows the FP protocol to access the network manager protected functions.

Definition at line 216 of file can_network_manager.hpp.

◆ ParameterGroupNumberRequestProtocol

Allows the PGN request protocol to access the network manager protected functions.

Definition at line 215 of file can_network_manager.hpp.

◆ TransportProtocolManager

friend class TransportProtocolManager
friend

Allows the network manager to work closely with the transport protocol manager object.

Definition at line 213 of file can_network_manager.hpp.

Member Data Documentation

◆ addressViolationEventDispatcher

EventDispatcher<std::shared_ptr<InternalControlFunction> > isobus::CANNetworkManager::addressViolationEventDispatcher
private

An event dispatcher for notifying consumers about address violations.

Definition at line 406 of file can_network_manager.hpp.

◆ anyControlFunctionCallbacksMutex

Mutex isobus::CANNetworkManager::anyControlFunctionCallbacksMutex
private

Mutex to protect the "any CF" callbacks.

Definition at line 409 of file can_network_manager.hpp.

◆ anyControlFunctionParameterGroupNumberCallbacks

std::vector<ParameterGroupNumberCallbackData> isobus::CANNetworkManager::anyControlFunctionParameterGroupNumberCallbacks
private

A list of all global PGN callbacks.

Definition at line 404 of file can_network_manager.hpp.

◆ BUSLOAD_SAMPLE_WINDOW_MS

constexpr std::uint32_t isobus::CANNetworkManager::BUSLOAD_SAMPLE_WINDOW_MS = 1000
staticconstexprprivate

Using a 1s window to average the bus load, otherwise it's very erratic.

Definition at line 381 of file can_network_manager.hpp.

◆ BUSLOAD_UPDATE_FREQUENCY_MS

constexpr std::uint32_t isobus::CANNetworkManager::BUSLOAD_UPDATE_FREQUENCY_MS = 100
staticconstexprprivate

Bus load bit accumulation happens over a 100ms window.

Definition at line 382 of file can_network_manager.hpp.

◆ busloadMessageBitsHistory

std::array<std::deque<std::uint32_t>, CAN_PORT_MAXIMUM> isobus::CANNetworkManager::busloadMessageBitsHistory
private

Stores the approximate number of bits processed on each channel over multiple previous time windows.

Definition at line 390 of file can_network_manager.hpp.

◆ busloadUpdateMutex

Mutex isobus::CANNetworkManager::busloadUpdateMutex
private

A mutex that protects the busload metrics since we calculate it on our own thread.

Definition at line 410 of file can_network_manager.hpp.

◆ busloadUpdateTimestamp_ms

std::uint32_t isobus::CANNetworkManager::busloadUpdateTimestamp_ms = 0
private

Tracks a time window for determining approximate busload.

Definition at line 413 of file can_network_manager.hpp.

◆ CANNetwork

CANNetworkManager isobus::CANNetworkManager::CANNetwork
static

Static singleton of the one network manager. Use this to access stack functionality.

Definition at line 51 of file can_network_manager.hpp.

◆ configuration

CANNetworkConfiguration isobus::CANNetworkManager::configuration
private

The configuration for this network manager.

Definition at line 384 of file can_network_manager.hpp.

◆ controlFunctionStateCallbacks

std::list<ControlFunctionStateCallback> isobus::CANNetworkManager::controlFunctionStateCallbacks
private

List of all control function state callbacks.

Definition at line 402 of file can_network_manager.hpp.

◆ controlFunctionStatusCallbacksMutex

Mutex isobus::CANNetworkManager::controlFunctionStatusCallbacksMutex
private

A Mutex that protects access to the control function status callback list.

Definition at line 411 of file can_network_manager.hpp.

◆ controlFunctionTable

std::array<std::array<std::shared_ptr<ControlFunction>, NULL_CAN_ADDRESS>, CAN_PORT_MAXIMUM> isobus::CANNetworkManager::controlFunctionTable
private

Table to maintain address to NAME mappings.

Definition at line 394 of file can_network_manager.hpp.

◆ currentBusloadBitAccumulator

std::array<std::uint32_t, CAN_PORT_MAXIMUM> isobus::CANNetworkManager::currentBusloadBitAccumulator
private

Accumulates the approximate number of bits processed on each channel during the current time window.

Definition at line 391 of file can_network_manager.hpp.

◆ extendedTransportProtocols

std::array<std::unique_ptr<ExtendedTransportProtocolManager>, CAN_PORT_MAXIMUM> isobus::CANNetworkManager::extendedTransportProtocols
private

One instance of the extended transport protocol manager for each channel.

Definition at line 386 of file can_network_manager.hpp.

◆ fastPacketProtocol

std::array<std::unique_ptr<FastPacketProtocol>, CAN_PORT_MAXIMUM> isobus::CANNetworkManager::fastPacketProtocol
private

One instance of the fast packet protocol for each channel.

Definition at line 387 of file can_network_manager.hpp.

◆ globalParameterGroupNumberCallbacks

std::vector<ParameterGroupNumberCallbackData> isobus::CANNetworkManager::globalParameterGroupNumberCallbacks
private

A list of all global PGN callbacks.

Definition at line 403 of file can_network_manager.hpp.

◆ heartBeatInterfaces

std::array<std::unique_ptr<HeartbeatInterface>, CAN_PORT_MAXIMUM> isobus::CANNetworkManager::heartBeatInterfaces
private

Manages ISOBUS heartbeat requests, one per channel.

Definition at line 388 of file can_network_manager.hpp.

◆ inactiveControlFunctions

std::list<std::shared_ptr<ControlFunction> > isobus::CANNetworkManager::inactiveControlFunctions
private

A list of the control function that currently don't have a valid address.

Definition at line 395 of file can_network_manager.hpp.

◆ initialized

bool isobus::CANNetworkManager::initialized = false
private

True if the network manager has been initialized by the update function.

Definition at line 415 of file can_network_manager.hpp.

◆ internalControlFunctions

std::list<std::shared_ptr<InternalControlFunction> > isobus::CANNetworkManager::internalControlFunctions
private

A list of the internal control functions.

Definition at line 396 of file can_network_manager.hpp.

◆ lastAddressClaimRequestTimestamp_ms

std::array<std::uint32_t, CAN_PORT_MAXIMUM> isobus::CANNetworkManager::lastAddressClaimRequestTimestamp_ms
private

Stores timestamps for when the last request for the address claim PGN was received. Used to prune stale CFs.

Definition at line 392 of file can_network_manager.hpp.

◆ messageTransmittedEventDispatcher

EventDispatcher<CANMessage> isobus::CANNetworkManager::messageTransmittedEventDispatcher
private

An event dispatcher for notifying consumers about transmitted messages by our application.

Definition at line 405 of file can_network_manager.hpp.

◆ partneredControlFunctions

std::list<std::shared_ptr<PartneredControlFunction> > isobus::CANNetworkManager::partneredControlFunctions
private

A list of the partnered control functions.

Definition at line 397 of file can_network_manager.hpp.

◆ protocolPGNCallbacks

std::list<ParameterGroupNumberCallbackData> isobus::CANNetworkManager::protocolPGNCallbacks
private

A list of PGN callback registered by CAN protocols.

Definition at line 399 of file can_network_manager.hpp.

◆ protocolPGNCallbacksMutex

Mutex isobus::CANNetworkManager::protocolPGNCallbacksMutex
private

A mutex for PGN callback thread safety.

Definition at line 408 of file can_network_manager.hpp.

◆ receivedMessageQueue

std::queue<CANMessage> isobus::CANNetworkManager::receivedMessageQueue
private

A queue of received messages to process.

Definition at line 400 of file can_network_manager.hpp.

◆ receivedMessageQueueMutex

Mutex isobus::CANNetworkManager::receivedMessageQueueMutex
private

A mutex for receive messages thread safety.

Definition at line 407 of file can_network_manager.hpp.

◆ transmittedMessageQueue

std::queue<CANMessage> isobus::CANNetworkManager::transmittedMessageQueue
private

A queue of transmitted messages to process (already sent, so changes to the message won't affect the bus)

Definition at line 401 of file can_network_manager.hpp.

◆ transmittedMessageQueueMutex

Mutex isobus::CANNetworkManager::transmittedMessageQueueMutex
private

A mutex for protecting the transmitted message queue.

Definition at line 412 of file can_network_manager.hpp.

◆ transportProtocols

std::array<std::unique_ptr<TransportProtocolManager>, CAN_PORT_MAXIMUM> isobus::CANNetworkManager::transportProtocols
private

One instance of the transport protocol manager for each channel.

Definition at line 385 of file can_network_manager.hpp.

◆ updateTimestamp_ms

std::uint32_t isobus::CANNetworkManager::updateTimestamp_ms = 0
private

Keeps track of the last time the CAN stack was update in milliseconds.

Definition at line 414 of file can_network_manager.hpp.


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