AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
|
A class that handles the ISO11783/J1939 transport protocol. More...
#include <can_transport_protocol.hpp>
Classes | |
class | TransportProtocolSession |
A storage object to keep track of session information internally. More... | |
Public Types | |
enum class | StateMachineState { None , SendBroadcastAnnounce , SendRequestToSend , WaitForClearToSend , SendClearToSend , WaitForDataTransferPacket , SendDataTransferPackets , WaitForEndOfMessageAcknowledge } |
The states that a TP session could be in. Used for the internal state machine. More... | |
enum class | ConnectionAbortReason : std::uint8_t { Reserved = 0 , AlreadyInCMSession = 1 , SystemResourcesNeeded = 2 , Timeout = 3 , ClearToSendReceivedWhileTransferInProgress = 4 , MaximumRetransmitRequestLimitReached = 5 , UnexpectedDataTransferPacketReceived = 6 , BadSequenceNumber = 7 , DuplicateSequenceNumber = 8 , TotalMessageSizeTooBig = 9 , AnyOtherError = 250 } |
A list of all defined abort reasons in ISO11783. More... | |
Public Member Functions | |
TransportProtocolManager (const CANMessageFrameCallback &sendCANFrameCallback, const CANMessageCallback &canMessageReceivedCallback, const CANNetworkConfiguration *configuration) | |
The constructor for the TransportProtocolManager, for advanced use only. In most cases, you should use the CANNetworkManager::send_can_message() function to transmit messages. | |
void | update () |
Updates all sessions managed by this protocol manager instance. | |
bool | has_session (std::shared_ptr< ControlFunction > source, std::shared_ptr< ControlFunction > destination) |
Checks if the source and destination control function have an active session/connection. | |
const std::vector< std::shared_ptr< TransportProtocolSession > > & | get_sessions () const |
Gets all the active transport protocol sessions that are currently active. | |
void | process_message (const CANMessage &message) |
A generic way for a protocol to process a received message. | |
bool | protocol_transmit_message (std::uint32_t parameterGroupNumber, std::unique_ptr< CANMessageData > &data, std::shared_ptr< ControlFunction > source, std::shared_ptr< ControlFunction > destination, TransmitCompleteCallback sessionCompleteCallback, void *parentPointer) |
The network manager calls this to see if the protocol can accept a long CAN message for processing. | |
Static Public Attributes | |
static constexpr std::uint32_t | REQUEST_TO_SEND_MULTIPLEXOR = 0x10 |
(16) TP.CM_RTS Multiplexor | |
static constexpr std::uint32_t | CLEAR_TO_SEND_MULTIPLEXOR = 0x11 |
(17) TP.CM_CTS Multiplexor | |
static constexpr std::uint32_t | END_OF_MESSAGE_ACKNOWLEDGE_MULTIPLEXOR = 0x13 |
(19) TP.CM_EOM_ACK Multiplexor | |
static constexpr std::uint32_t | BROADCAST_ANNOUNCE_MESSAGE_MULTIPLEXOR = 0x20 |
(32) TP.BAM Multiplexor | |
static constexpr std::uint32_t | CONNECTION_ABORT_MULTIPLEXOR = 0xFF |
(255) Abort multiplexor | |
static constexpr std::uint32_t | MAX_PROTOCOL_DATA_LENGTH = 1785 |
The max number of bytes that this protocol can transfer. | |
static constexpr std::uint16_t | T1_TIMEOUT_MS = 750 |
The t1 timeout as defined by the standard. | |
static constexpr std::uint16_t | T2_T3_TIMEOUT_MS = 1250 |
The t2/t3 timeouts as defined by the standard. | |
static constexpr std::uint16_t | T4_TIMEOUT_MS = 1050 |
The t4 timeout as defined by the standard. | |
static constexpr std::uint8_t | R_TIMEOUT_MS = 200 |
The Tr Timeout as defined by the standard. | |
static constexpr std::uint8_t | SEQUENCE_NUMBER_DATA_INDEX = 0 |
The index of the sequence number in a frame. | |
static constexpr std::uint8_t | PROTOCOL_BYTES_PER_FRAME = 7 |
The number of payload bytes per frame minus overhead of sequence number. | |
Private Member Functions | |
bool | abort_session (std::shared_ptr< TransportProtocolSession > &session, ConnectionAbortReason reason) |
Aborts the session with the specified abort reason. Sends a CAN message. | |
bool | send_abort (std::shared_ptr< InternalControlFunction > sender, std::shared_ptr< ControlFunction > receiver, std::uint32_t parameterGroupNumber, ConnectionAbortReason reason) const |
Send an abort with no corresponding session with the specified abort reason. Sends a CAN message. | |
void | close_session (std::shared_ptr< TransportProtocolSession > &session, bool successful) |
Gracefully closes a session to prepare for a new session. | |
bool | send_broadcast_announce_message (std::shared_ptr< TransportProtocolSession > &session) const |
Sends the "broadcast announce" message. | |
bool | send_request_to_send (std::shared_ptr< TransportProtocolSession > &session) const |
Sends the "request to send" message as part of initiating a transmit. | |
bool | send_clear_to_send (std::shared_ptr< TransportProtocolSession > &session) const |
Sends the "clear to send" message. | |
bool | send_end_of_session_acknowledgement (std::shared_ptr< TransportProtocolSession > &session) const |
Sends the "end of message acknowledgement" message for the provided session. | |
void | send_data_transfer_packets (std::shared_ptr< TransportProtocolSession > &session) |
Sends data transfer packets for the specified TransportProtocolSession. | |
void | process_broadcast_announce_message (const std::shared_ptr< ControlFunction > source, std::uint32_t parameterGroupNumber, std::uint16_t totalMessageSize, std::uint8_t totalNumberOfPackets) |
Processes a broadcast announce message. | |
void | process_request_to_send (const std::shared_ptr< ControlFunction > source, const std::shared_ptr< ControlFunction > destination, std::uint32_t parameterGroupNumber, std::uint16_t totalMessageSize, std::uint8_t totalNumberOfPackets, std::uint8_t clearToSendPacketMax) |
Processes a request to send a message over the CAN transport protocol. | |
void | process_clear_to_send (const std::shared_ptr< ControlFunction > source, const std::shared_ptr< ControlFunction > destination, std::uint32_t parameterGroupNumber, std::uint8_t packetsToBeSent, std::uint8_t nextPacketNumber) |
Processes the Clear To Send (CTS) message. | |
void | process_end_of_session_acknowledgement (const std::shared_ptr< ControlFunction > source, const std::shared_ptr< ControlFunction > destination, std::uint32_t parameterGroupNumber) |
Processes the end of session acknowledgement. | |
void | process_abort (const std::shared_ptr< ControlFunction > source, const std::shared_ptr< ControlFunction > destination, std::uint32_t parameterGroupNumber, TransportProtocolManager::ConnectionAbortReason reason) |
Processes an abort message in the CAN transport protocol. | |
void | process_connection_management_message (const CANMessage &message) |
Processes a connection management message. | |
void | process_data_transfer_message (const CANMessage &message) |
Processes a data transfer message. | |
std::shared_ptr< TransportProtocolSession > | get_session (std::shared_ptr< ControlFunction > source, std::shared_ptr< ControlFunction > destination) |
Gets a TP session from the passed in source and destination combination. | |
void | update_state_machine (std::shared_ptr< TransportProtocolSession > &session) |
Update the state machine for the passed in session. | |
Private Attributes | |
std::vector< std::shared_ptr< TransportProtocolSession > > | activeSessions |
A list of all active TP sessions. | |
const CANMessageFrameCallback | sendCANFrameCallback |
A callback for sending a CAN frame. | |
const CANMessageCallback | canMessageReceivedCallback |
A callback for when a complete CAN message is received using the TP protocol. | |
const CANNetworkConfiguration * | configuration |
The configuration to use for this protocol. | |
A class that handles the ISO11783/J1939 transport protocol.
This class handles transmission and reception of CAN messages up to 1785 bytes. Both broadcast and connection mode are supported. Simply call CANNetworkManager::send_can_message()
with an appropriate data length, and the protocol will be automatically selected to be used.
Definition at line 31 of file can_transport_protocol.hpp.
|
strong |
A list of all defined abort reasons in ISO11783.
Definition at line 48 of file can_transport_protocol.hpp.
|
strong |
The states that a TP session could be in. Used for the internal state machine.
Definition at line 35 of file can_transport_protocol.hpp.
isobus::TransportProtocolManager::TransportProtocolManager | ( | const CANMessageFrameCallback & | sendCANFrameCallback, |
const CANMessageCallback & | canMessageReceivedCallback, | ||
const CANNetworkConfiguration * | configuration ) |
The constructor for the TransportProtocolManager, for advanced use only. In most cases, you should use the CANNetworkManager::send_can_message() function to transmit messages.
[in] | sendCANFrameCallback | A callback for sending a CAN frame to hardware |
[in] | canMessageReceivedCallback | A callback for when a complete CAN message is received using the TP protocol |
[in] | configuration | The configuration to use for this protocol |
Definition at line 123 of file can_transport_protocol.cpp.
|
private |
Aborts the session with the specified abort reason. Sends a CAN message.
[in] | session | The session to abort |
[in] | reason | The reason we're aborting the session |
Definition at line 835 of file can_transport_protocol.cpp.
|
private |
Gracefully closes a session to prepare for a new session.
[in] | session | The session to close |
[in] | successful | Denotes if the session was successful |
Definition at line 881 of file can_transport_protocol.cpp.
|
private |
Gets a TP session from the passed in source and destination combination.
[in] | source | The source control function for the session |
[in] | destination | The destination control function for the session |
Definition at line 1000 of file can_transport_protocol.cpp.
const std::vector< std::shared_ptr< TransportProtocolManager::TransportProtocolSession > > & isobus::TransportProtocolManager::get_sessions | ( | ) | const |
Gets all the active transport protocol sessions that are currently active.
Definition at line 1009 of file can_transport_protocol.cpp.
bool isobus::TransportProtocolManager::has_session | ( | std::shared_ptr< ControlFunction > | source, |
std::shared_ptr< ControlFunction > | destination ) |
Checks if the source and destination control function have an active session/connection.
[in] | source | The source control function for the session |
[in] | destination | The destination control function for the session |
Definition at line 993 of file can_transport_protocol.cpp.
|
private |
Processes an abort message in the CAN transport protocol.
[in] | source | The shared pointer to the source control function. |
[in] | destination | The shared pointer to the destination control function. |
[in] | parameterGroupNumber | The PGN (Parameter Group Number) of the message. |
[in] | reason | The reason for the connection abort. |
Definition at line 324 of file can_transport_protocol.cpp.
|
private |
Processes a broadcast announce message.
[in] | source | The source control function that sent the broadcast announce message. |
[in] | parameterGroupNumber | The Parameter Group Number of the broadcast announce message. |
[in] | totalMessageSize | The total size of the broadcast announce message. |
[in] | totalNumberOfPackets | The total number of packets in the broadcast announce message. |
Definition at line 132 of file can_transport_protocol.cpp.
|
private |
Processes the Clear To Send (CTS) message.
[in] | source | The shared pointer to the source control function. |
[in] | destination | The shared pointer to the destination control function. |
[in] | parameterGroupNumber | The Parameter Group Number (PGN) of the message. |
[in] | packetsToBeSent | The number of packets to be sent. |
[in] | nextPacketNumber | The next packet number. |
Definition at line 253 of file can_transport_protocol.cpp.
|
private |
Processes a connection management message.
[in] | message | The CAN message to be processed. |
Definition at line 358 of file can_transport_protocol.cpp.
|
private |
Processes a data transfer message.
[in] | message | The CAN message to be processed. |
Definition at line 468 of file can_transport_protocol.cpp.
|
private |
Processes the end of session acknowledgement.
[in] | source | The source control function. |
[in] | destination | The destination control function. |
[in] | parameterGroupNumber | The parameter group number. |
Definition at line 299 of file can_transport_protocol.cpp.
void isobus::TransportProtocolManager::process_message | ( | const CANMessage & | message | ) |
A generic way for a protocol to process a received message.
[in] | message | A received CAN message |
Definition at line 557 of file can_transport_protocol.cpp.
|
private |
Processes a request to send a message over the CAN transport protocol.
[in] | source | The shared pointer to the source control function. |
[in] | destination | The shared pointer to the destination control function. |
[in] | parameterGroupNumber | The Parameter Group Number of the message. |
[in] | totalMessageSize | The total size of the message in bytes. |
[in] | totalNumberOfPackets | The total number of packets to be sent. |
[in] | clearToSendPacketMax | The maximum number of clear to send packets that can be sent. |
Definition at line 186 of file can_transport_protocol.cpp.
bool isobus::TransportProtocolManager::protocol_transmit_message | ( | std::uint32_t | parameterGroupNumber, |
std::unique_ptr< CANMessageData > & | data, | ||
std::shared_ptr< ControlFunction > | source, | ||
std::shared_ptr< ControlFunction > | destination, | ||
TransmitCompleteCallback | sessionCompleteCallback, | ||
void * | parentPointer ) |
The network manager calls this to see if the protocol can accept a long CAN message for processing.
[in] | parameterGroupNumber | The PGN of the message |
[in] | data | The data to be sent |
[in] | source | The source control function |
[in] | destination | The destination control function |
[in] | sessionCompleteCallback | A callback for when the protocol completes its work |
[in] | parentPointer | A generic context object for the tx complete and chunk callbacks |
Definition at line 582 of file can_transport_protocol.cpp.
|
private |
Send an abort with no corresponding session with the specified abort reason. Sends a CAN message.
[in] | sender | The sender of the abort |
[in] | receiver | The receiver of the abort |
[in] | parameterGroupNumber | The PGN of the TP "session" we're aborting |
[in] | reason | The reason we're aborting the session |
Definition at line 859 of file can_transport_protocol.cpp.
|
private |
Sends the "broadcast announce" message.
[in] | session | The session for which we're sending the BAM |
Definition at line 893 of file can_transport_protocol.cpp.
|
private |
Sends the "clear to send" message.
[in] | session | The session for which we're sending the CTS |
Definition at line 931 of file can_transport_protocol.cpp.
|
private |
Sends data transfer packets for the specified TransportProtocolSession.
[in] | session | The TransportProtocolSession for which to send data transfer packets. |
Definition at line 660 of file can_transport_protocol.cpp.
|
private |
Sends the "end of message acknowledgement" message for the provided session.
[in] | session | The session for which we're sending the EOM ACK |
Definition at line 969 of file can_transport_protocol.cpp.
|
private |
Sends the "request to send" message as part of initiating a transmit.
[in] | session | The session for which we're sending the RTS |
Definition at line 912 of file can_transport_protocol.cpp.
void isobus::TransportProtocolManager::update | ( | ) |
Updates all sessions managed by this protocol manager instance.
Definition at line 637 of file can_transport_protocol.cpp.
|
private |
Update the state machine for the passed in session.
[in] | session | The session to update |
Definition at line 725 of file can_transport_protocol.cpp.
|
private |
A list of all active TP sessions.
Definition at line 317 of file can_transport_protocol.hpp.
|
staticconstexpr |
(32) TP.BAM Multiplexor
Definition at line 163 of file can_transport_protocol.hpp.
|
private |
A callback for when a complete CAN message is received using the TP protocol.
Definition at line 319 of file can_transport_protocol.hpp.
|
staticconstexpr |
(17) TP.CM_CTS Multiplexor
Definition at line 161 of file can_transport_protocol.hpp.
|
private |
The configuration to use for this protocol.
Definition at line 320 of file can_transport_protocol.hpp.
|
staticconstexpr |
(255) Abort multiplexor
Definition at line 164 of file can_transport_protocol.hpp.
|
staticconstexpr |
(19) TP.CM_EOM_ACK Multiplexor
Definition at line 162 of file can_transport_protocol.hpp.
|
staticconstexpr |
The max number of bytes that this protocol can transfer.
Definition at line 165 of file can_transport_protocol.hpp.
|
staticconstexpr |
The number of payload bytes per frame minus overhead of sequence number.
Definition at line 171 of file can_transport_protocol.hpp.
|
staticconstexpr |
The Tr Timeout as defined by the standard.
Definition at line 169 of file can_transport_protocol.hpp.
|
staticconstexpr |
(16) TP.CM_RTS Multiplexor
Definition at line 160 of file can_transport_protocol.hpp.
|
private |
A callback for sending a CAN frame.
Definition at line 318 of file can_transport_protocol.hpp.
|
staticconstexpr |
The index of the sequence number in a frame.
Definition at line 170 of file can_transport_protocol.hpp.
|
staticconstexpr |
The t1 timeout as defined by the standard.
Definition at line 166 of file can_transport_protocol.hpp.
|
staticconstexpr |
The t2/t3 timeouts as defined by the standard.
Definition at line 167 of file can_transport_protocol.hpp.
|
staticconstexpr |
The t4 timeout as defined by the standard.
Definition at line 168 of file can_transport_protocol.hpp.