AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
|
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>
Public Member Functions | |
void | initialize () |
Initializer function for the network manager. | |
std::shared_ptr< ControlFunction > | 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. | |
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< InternalControlFunction > | get_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. | |
HeartbeatInterface & | get_heartbeat_interface (std::uint8_t canPortIndex) |
Returns an interface which can be used to manage ISO11783-7 heartbeat messages. | |
CANNetworkConfiguration & | get_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< ControlFunction > | get_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 ¤tMessage) |
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 ¤tMessage) |
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 ¤tMessage) |
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_MAXIMUM > | transportProtocols |
One instance of the transport protocol manager for each channel. | |
std::array< std::unique_ptr< ExtendedTransportProtocolManager >, CAN_PORT_MAXIMUM > | extendedTransportProtocols |
One instance of the extended transport protocol manager for each channel. | |
std::array< std::unique_ptr< FastPacketProtocol >, CAN_PORT_MAXIMUM > | fastPacketProtocol |
One instance of the fast packet protocol for each channel. | |
std::array< std::unique_ptr< HeartbeatInterface >, CAN_PORT_MAXIMUM > | heartBeatInterfaces |
Manages ISOBUS heartbeat requests, one per channel. | |
std::array< std::deque< std::uint32_t >, CAN_PORT_MAXIMUM > | busloadMessageBitsHistory |
Stores the approximate number of bits processed on each channel over multiple previous time windows. | |
std::array< std::uint32_t, CAN_PORT_MAXIMUM > | currentBusloadBitAccumulator |
Accumulates the approximate number of bits processed on each channel during the current time window. | |
std::array< std::uint32_t, CAN_PORT_MAXIMUM > | lastAddressClaimRequestTimestamp_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_MAXIMUM > | controlFunctionTable |
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< ParameterGroupNumberCallbackData > | protocolPGNCallbacks |
A list of PGN callback registered by CAN protocols. | |
std::queue< CANMessage > | receivedMessageQueue |
A queue of received messages to process. | |
std::queue< CANMessage > | transmittedMessageQueue |
A queue of transmitted messages to process (already sent, so changes to the message won't affect the bus) | |
std::list< ControlFunctionStateCallback > | controlFunctionStateCallbacks |
List of all control function state callbacks. | |
std::vector< ParameterGroupNumberCallbackData > | globalParameterGroupNumberCallbacks |
A list of all global PGN callbacks. | |
std::vector< ParameterGroupNumberCallbackData > | anyControlFunctionParameterGroupNumberCallbacks |
A list of all global PGN callbacks. | |
EventDispatcher< CANMessage > | messageTransmittedEventDispatcher |
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. | |
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.
|
private |
Constructor for the network manager. Sets default values for members.
Definition at line 496 of file can_network_manager.cpp.
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.
[in] | parameterGroupNumber | The PGN you want to register for |
[in] | callback | The callback that will be called when parameterGroupNumber is received from any control function |
[in] | parent | A 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.
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.
[in] | callback | The callback you want to be called when the any control function changes state |
Definition at line 378 of file can_network_manager.cpp.
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)
[in] | parameterGroupNumber | The PGN you want to register for |
[in] | callback | The callback that will be called when parameterGroupNumber is received from the global address (0xFF) |
[in] | parent | A 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.
|
protected |
Adds a PGN callback for a protocol class.
[in] | parameterGroupNumber | The PGN to register for |
[in] | callback | The callback to call when the PGN is received |
[in] | parentPointer | A generic context variable that helps identify what object the callback was destined for |
true
if the callback was added, otherwise false
Definition at line 464 of file can_network_manager.cpp.
|
private |
Builds a CAN frame from a frame's discrete components.
[in] | portIndex | The CAN channel index of the CAN message being processed |
[in] | sourceAddress | The source address to send the CAN message from |
[in] | destAddress | The destination address to send the message to |
[in] | parameterGroupNumber | The PGN to use when sending the message |
[in] | priority | The CAN priority of the message being sent |
[in] | data | A pointer to the data buffer to send from |
[in] | size | The size of the message to send |
Definition at line 811 of file can_network_manager.cpp.
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.
[in] | canPortIndex | The CAN channel index to get the transport protocol sessions for |
Definition at line 435 of file can_network_manager.cpp.
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.
Definition at line 459 of file can_network_manager.cpp.
CANNetworkConfiguration & isobus::CANNetworkManager::get_configuration | ( | ) |
Returns the configuration of this network manager.
Definition at line 454 of file can_network_manager.cpp.
|
private |
Returns a control function based on a CAN address and channel index.
[in] | channelIndex | The CAN channel index of the CAN message being processed |
[in] | address | The CAN address associated with a control function |
Definition at line 871 of file can_network_manager.cpp.
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.
[in] | channelIndex | CAN Channel index of the control function |
[in] | address | Address of the control function |
Definition at line 45 of file can_network_manager.cpp.
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.
[in] | includingOffline | If true, all control functions are returned, otherwise only online control functions are returned |
Definition at line 412 of file can_network_manager.cpp.
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.
[in] | canChannel | The channel to estimate the bus load for |
Definition at line 104 of file can_network_manager.cpp.
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.
[in] | canPortIndex | The CAN channel index to get the fast packet protocol for |
Definition at line 443 of file can_network_manager.cpp.
|
private |
Gets a PGN callback for the global address by index.
[in] | index | The index of the callback to get |
Definition at line 244 of file can_network_manager.cpp.
HeartbeatInterface & isobus::CANNetworkManager::get_heartbeat_interface | ( | std::uint8_t | canPortIndex | ) |
Returns an interface which can be used to manage ISO11783-7 heartbeat messages.
[in] | canPortIndex | The index of the CAN channel associated to the interface you're requesting |
Definition at line 448 of file can_network_manager.cpp.
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.
[in] | controlFunction | The control function to get the internal control function from |
Definition at line 92 of file can_network_manager.cpp.
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.
Definition at line 402 of file can_network_manager.cpp.
|
private |
Get the next CAN message from the received message queue, and remove it from the queue.
Definition at line 882 of file can_network_manager.cpp.
|
private |
Get the next CAN message from the received message queue, and remove it from the queue.
Definition at line 894 of file can_network_manager.cpp.
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.
Definition at line 65 of file can_network_manager.cpp.
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.
Definition at line 407 of file can_network_manager.cpp.
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.
Definition at line 87 of file can_network_manager.cpp.
void isobus::CANNetworkManager::initialize | ( | ) |
Initializer function for the network manager.
Definition at line 31 of file can_network_manager.cpp.
|
private |
Informs the network manager that a control function object has been created.
[in] | controlFunction | The control function that was created |
Definition at line 906 of file can_network_manager.cpp.
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.
[in] | controlFunction | The control function that was created |
Definition at line 362 of file can_network_manager.cpp.
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.
[in] | controlFunction | The control function that was created |
Definition at line 367 of file can_network_manager.cpp.
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.
[in] | controlFunction | The control function that was created |
Definition at line 373 of file can_network_manager.cpp.
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.
[in] | controlFunction | The control function that was destroyed |
Definition at line 312 of file can_network_manager.cpp.
|
private |
Processes a can message for callbacks added with add_any_control_function_parameter_group_number_callback.
[in] | currentMessage | The message to process |
Definition at line 918 of file can_network_manager.cpp.
|
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.
[in] | currentMessage | The message to process |
Definition at line 932 of file can_network_manager.cpp.
|
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.
[in] | message | The message to process |
Definition at line 1017 of file can_network_manager.cpp.
|
private |
Matches a CAN message to any matching PGN callback, and calls that callback.
[in] | message | A pointer to a CAN message to be processed |
Definition at line 973 of file can_network_manager.cpp.
|
private |
Checks the control function state callback list to see if we need to call a control function state callback.
[in] | controlFunction | The controlFunction whose state has changed |
[in] | state | The new state of the control function |
Definition at line 952 of file can_network_manager.cpp.
|
private |
Processes a can message for callbacks added with add_protocol_parameter_group_number_callback.
[in] | currentMessage | The message to process |
Definition at line 961 of file can_network_manager.cpp.
void isobus::CANNetworkManager::process_receive_can_message_frame | ( | const CANMessageFrame & | rxFrame | ) |
Used to tell the network manager when frames are received on the bus.
[in] | rxFrame | Frame to process |
Definition at line 270 of file can_network_manager.cpp.
|
private |
Processes the internal received message queue.
Definition at line 1038 of file can_network_manager.cpp.
void isobus::CANNetworkManager::process_transmitted_can_message_frame | ( | const CANMessageFrame & | txFrame | ) |
Used to tell the network manager when frames are emitted on the bus.
[in] | txFrame | The frame that was just emitted onto the bus |
Definition at line 292 of file can_network_manager.cpp.
|
private |
Processes the internal transmitted message queue.
Definition at line 1061 of file can_network_manager.cpp.
|
protected |
Processes completed protocol messages. Causes PGN callbacks to trigger.
[in] | message | The completed protocol message |
Definition at line 1118 of file can_network_manager.cpp.
|
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.
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.
[in] | parameterGroupNumber | The PGN of the callback to remove |
[in] | callback | The callback that will be removed |
[in] | parent | A generic context variable that helps identify what object the callback was destined for |
Definition at line 76 of file can_network_manager.cpp.
void isobus::CANNetworkManager::remove_control_function_status_change_callback | ( | ControlFunctionStateCallback | callback | ) |
Used to remove callbacks added with add_control_function_status_change_callback.
[in] | callback | The callback you want to remove |
Definition at line 387 of file can_network_manager.cpp.
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)
[in] | parameterGroupNumber | The PGN of the callback to remove |
[in] | callback | The callback that will be removed |
[in] | parent | A generic context variable that helps identify what object the callback was destined for |
Definition at line 55 of file can_network_manager.cpp.
|
protected |
Removes a PGN callback for a protocol class.
[in] | parameterGroupNumber | The PGN to register for |
[in] | callback | The callback to call when the PGN is received |
[in] | parentPointer | A generic context variable that helps identify what object the callback was destined for |
true
if the callback was removed, otherwise false
Definition at line 477 of file can_network_manager.cpp.
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.
[in] | parameterGroupNumber | The PGN to use when sending the message |
[in] | dataBuffer | A pointer to the data buffer to send from |
[in] | dataLength | The size of the message to send |
[in] | sourceControlFunction | The control function that is sending the message |
[in] | destinationControlFunction | The control function that the message is destined for or nullptr if broadcast |
[in] | priority | The CAN priority of the message being sent |
[in] | txCompleteCallback | A callback to be called when the message is sent or fails to send |
[in] | parentPointer | A generic context variable that helps identify what object the callback is destined for |
[in] | frameChunkCallback | A callback which can be supplied to have the tack call you back to get chunks of the message as they are sent |
true
if the message was sent, otherwise false
Definition at line 119 of file can_network_manager.cpp.
|
private |
Sends a CAN message using raw addresses. Used only by the stack.
[in] | portIndex | The CAN channel index to send the message from |
[in] | sourceAddress | The source address to send the CAN message from |
[in] | destAddress | The destination address to send the message to |
[in] | parameterGroupNumber | The PGN to use when sending the message |
[in] | priority | The CAN priority of the message being sent |
[in] | data | A pointer to the data buffer to send from |
[in] | size | The size of the message to send |
true
if the message was sent, otherwise false
Definition at line 1105 of file can_network_manager.cpp.
|
protected |
Sends a CAN message using raw addresses. Used only by the stack.
[in] | portIndex | The CAN channel index to send the message from |
[in] | sourceAddress | The source address to send the CAN message from |
[in] | destAddress | The destination address to send the message to |
[in] | parameterGroupNumber | The PGN to use when sending the message |
[in] | priority | The CAN priority of the message being sent |
[in] | data | A pointer to the data buffer to send from |
[in] | size | The size of the message to send |
true
if the message was sent, otherwise false
Definition at line 232 of file can_network_manager.cpp.
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.
|
private |
Updates the internal address table based on a received CAN message.
[in] | message | A message being received by the stack |
Definition at line 527 of file can_network_manager.cpp.
|
private |
Processes a CAN message's contribution to the current busload.
[in] | channelIndex | The CAN channel index associated to the message being processed |
[in] | numberOfBitsProcessed | The number of bits to add to the busload calculation |
Definition at line 635 of file can_network_manager.cpp.
|
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.
|
private |
Creates new control function classes based on the frames coming in from the bus.
[in] | rxFrame | Raw frames coming in from the bus |
Definition at line 660 of file can_network_manager.cpp.
|
private |
Updates the internal address table based on updates to internal cfs addresses.
Definition at line 602 of file can_network_manager.cpp.
|
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.
|
friend |
Allows the network manager to work closely with the address claiming process.
Definition at line 211 of file can_network_manager.hpp.
|
friend |
Allows the diagnostic protocol to access the protected functions on the network manager.
Definition at line 214 of file can_network_manager.hpp.
|
friend |
Allows the network manager to access the ETP manager.
Definition at line 212 of file can_network_manager.hpp.
|
friend |
Allows the FP protocol to access the network manager protected functions.
Definition at line 216 of file can_network_manager.hpp.
|
friend |
Allows the PGN request protocol to access the network manager protected functions.
Definition at line 215 of file can_network_manager.hpp.
|
friend |
Allows the network manager to work closely with the transport protocol manager object.
Definition at line 213 of file can_network_manager.hpp.
|
private |
An event dispatcher for notifying consumers about address violations.
Definition at line 406 of file can_network_manager.hpp.
|
private |
Mutex to protect the "any CF" callbacks.
Definition at line 409 of file can_network_manager.hpp.
|
private |
A list of all global PGN callbacks.
Definition at line 404 of file can_network_manager.hpp.
|
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.
|
staticconstexprprivate |
Bus load bit accumulation happens over a 100ms window.
Definition at line 382 of file can_network_manager.hpp.
|
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.
|
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.
|
private |
Tracks a time window for determining approximate busload.
Definition at line 413 of file can_network_manager.hpp.
|
static |
Static singleton of the one network manager. Use this to access stack functionality.
Definition at line 51 of file can_network_manager.hpp.
|
private |
The configuration for this network manager.
Definition at line 384 of file can_network_manager.hpp.
|
private |
List of all control function state callbacks.
Definition at line 402 of file can_network_manager.hpp.
|
private |
A Mutex that protects access to the control function status callback list.
Definition at line 411 of file can_network_manager.hpp.
|
private |
Table to maintain address to NAME mappings.
Definition at line 394 of file can_network_manager.hpp.
|
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.
|
private |
One instance of the extended transport protocol manager for each channel.
Definition at line 386 of file can_network_manager.hpp.
|
private |
One instance of the fast packet protocol for each channel.
Definition at line 387 of file can_network_manager.hpp.
|
private |
A list of all global PGN callbacks.
Definition at line 403 of file can_network_manager.hpp.
|
private |
Manages ISOBUS heartbeat requests, one per channel.
Definition at line 388 of file can_network_manager.hpp.
|
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.
|
private |
True if the network manager has been initialized by the update function.
Definition at line 415 of file can_network_manager.hpp.
|
private |
A list of the internal control functions.
Definition at line 396 of file can_network_manager.hpp.
|
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.
|
private |
An event dispatcher for notifying consumers about transmitted messages by our application.
Definition at line 405 of file can_network_manager.hpp.
|
private |
A list of the partnered control functions.
Definition at line 397 of file can_network_manager.hpp.
|
private |
A list of PGN callback registered by CAN protocols.
Definition at line 399 of file can_network_manager.hpp.
|
private |
A mutex for PGN callback thread safety.
Definition at line 408 of file can_network_manager.hpp.
|
private |
A queue of received messages to process.
Definition at line 400 of file can_network_manager.hpp.
|
private |
A mutex for receive messages thread safety.
Definition at line 407 of file can_network_manager.hpp.
|
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.
|
private |
A mutex for protecting the transmitted message queue.
Definition at line 412 of file can_network_manager.hpp.
|
private |
One instance of the transport protocol manager for each channel.
Definition at line 385 of file can_network_manager.hpp.
|
private |
Keeps track of the last time the CAN stack was update in milliseconds.
Definition at line 414 of file can_network_manager.hpp.