AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
|
A class that handles the ISO11783 extended transport protocol. More...
#include <can_extended_transport_protocol.hpp>
Classes | |
class | ExtendedTransportProtocolSession |
A storage object to keep track of session information internally. More... | |
Public Types | |
enum class | StateMachineState { None , SendRequestToSend , WaitForClearToSend , SendClearToSend , WaitForDataPacketOffset , SendDataPacketOffset , WaitForDataTransferPacket , SendDataTransferPackets , WaitForEndOfMessageAcknowledge } |
The states that a ETP 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 , UnexpectedDataPacketOffsetReceived = 9 , UnexpectedDataPacketOffsetPGN = 10 , DataPacketOffsetExceedsClearToSend = 11 , BadDataPacketOffset = 12 , UnexpectedClearToSendPGN = 14 , NumberOfClearToSendPacketsExceedsMessage = 15 , AnyOtherError = 250 } |
A list of all defined abort reasons in ISO11783. More... | |
Public Member Functions | |
ExtendedTransportProtocolManager (const CANMessageFrameCallback &sendCANFrameCallback, const CANMessageCallback &canMessageReceivedCallback, const CANNetworkConfiguration *configuration) | |
The constructor for the ExtendedTransportProtocolManager, 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< ExtendedTransportProtocolSession > > & | 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 = 0x14 |
(20) ETP.CM_RTS Multiplexor | |
static constexpr std::uint32_t | CLEAR_TO_SEND_MULTIPLEXOR = 0x15 |
(21) ETP.CM_CTS Multiplexor | |
static constexpr std::uint32_t | DATA_PACKET_OFFSET_MULTIPLXOR = 0x16 |
(22) ETP.CM_DPO Multiplexor | |
static constexpr std::uint32_t | END_OF_MESSAGE_ACKNOWLEDGE_MULTIPLEXOR = 0x17 |
(23) TP.CM_EOMA Multiplexor | |
static constexpr std::uint32_t | CONNECTION_ABORT_MULTIPLEXOR = 0xFF |
(255) Abort multiplexor | |
static constexpr std::uint32_t | MAX_PROTOCOL_DATA_LENGTH = 117440505 |
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 | TR_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< ExtendedTransportProtocolSession > &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< ExtendedTransportProtocolSession > &session, bool successful) |
Gracefully closes a session to prepare for a new session. | |
bool | send_request_to_send (std::shared_ptr< ExtendedTransportProtocolSession > &session) const |
Sends the "request to send" message as part of initiating a transmit. | |
bool | send_clear_to_send (std::shared_ptr< ExtendedTransportProtocolSession > &session) const |
Sends the "clear to send" message. | |
bool | send_data_packet_offset (std::shared_ptr< ExtendedTransportProtocolSession > &session) const |
Sends the "data packet offset" message for the provided session. | |
bool | send_end_of_session_acknowledgement (std::shared_ptr< ExtendedTransportProtocolSession > &session) const |
Sends the "end of message acknowledgement" message for the provided session. | |
void | send_data_transfer_packets (std::shared_ptr< ExtendedTransportProtocolSession > &session) const |
Sends data transfer packets for the specified ExtendedTransportProtocolSession. | |
void | process_request_to_send (const std::shared_ptr< ControlFunction > source, const std::shared_ptr< ControlFunction > destination, std::uint32_t parameterGroupNumber, std::uint32_t totalMessageSize) |
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::uint32_t nextPacketNumber) |
Processes the Clear To Send (CTS) message. | |
void | process_data_packet_offset (const std::shared_ptr< ControlFunction > source, const std::shared_ptr< ControlFunction > destination, std::uint32_t parameterGroupNumber, std::uint8_t numberOfPackets, std::uint32_t packetOffset) |
Processes the Data Packet Offset (DPO) message. | |
void | process_end_of_session_acknowledgement (const std::shared_ptr< ControlFunction > source, const std::shared_ptr< ControlFunction > destination, std::uint32_t parameterGroupNumber, std::uint32_t numberOfBytesTransferred) |
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, ExtendedTransportProtocolManager::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< ExtendedTransportProtocolSession > | get_session (std::shared_ptr< ControlFunction > source, std::shared_ptr< ControlFunction > destination) |
Gets a ETP session from the passed in source and destination and PGN combination. | |
void | update_state_machine (std::shared_ptr< ExtendedTransportProtocolSession > &session) |
Update the state machine for the passed in session. | |
Private Attributes | |
std::vector< std::shared_ptr< ExtendedTransportProtocolSession > > | activeSessions |
A list of all active ETP 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 ETP protocol. | |
const CANNetworkConfiguration * | configuration |
The configuration to use for this protocol. | |
A class that handles the ISO11783 extended transport protocol.
This class handles transmission and reception of CAN messages more than 1785 bytes. Simply call Simply call CANNetworkManager::send_can_message()
with an appropriate data length, and the protocol will be automatically selected to be used.
Definition at line 25 of file can_extended_transport_protocol.hpp.
|
strong |
A list of all defined abort reasons in ISO11783.
Definition at line 43 of file can_extended_transport_protocol.hpp.
|
strong |
The states that a ETP session could be in. Used for the internal state machine.
Definition at line 29 of file can_extended_transport_protocol.hpp.
isobus::ExtendedTransportProtocolManager::ExtendedTransportProtocolManager | ( | const CANMessageFrameCallback & | sendCANFrameCallback, |
const CANMessageCallback & | canMessageReceivedCallback, | ||
const CANNetworkConfiguration * | configuration ) |
The constructor for the ExtendedTransportProtocolManager, 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 ETP protocol |
[in] | configuration | The configuration to use for this protocol |
Definition at line 122 of file can_extended_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 728 of file can_extended_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 774 of file can_extended_transport_protocol.cpp.
|
private |
Gets a ETP session from the passed in source and destination and PGN combination.
[in] | source | The source control function for the session |
[in] | destination | The destination control function for the session |
Definition at line 910 of file can_extended_transport_protocol.cpp.
const std::vector< std::shared_ptr< ExtendedTransportProtocolManager::ExtendedTransportProtocolSession > > & isobus::ExtendedTransportProtocolManager::get_sessions | ( | ) | const |
Gets all the active transport protocol sessions that are currently active.
Definition at line 919 of file can_extended_transport_protocol.cpp.
bool isobus::ExtendedTransportProtocolManager::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 903 of file can_extended_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 306 of file can_extended_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 181 of file can_extended_transport_protocol.cpp.
|
private |
Processes a connection management message.
[in] | message | The CAN message to be processed. |
Definition at line 334 of file can_extended_transport_protocol.cpp.
|
private |
Processes the Data Packet Offset (DPO) 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] | numberOfPackets | The number of packets that will follow. |
[in] | packetOffset | The packet offset (always 1 less than CTS next packet number) |
Definition at line 227 of file can_extended_transport_protocol.cpp.
|
private |
Processes a data transfer message.
[in] | message | The CAN message to be processed. |
Definition at line 408 of file can_extended_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. |
[in] | numberOfBytesTransferred | The number of bytes transferred. |
Definition at line 279 of file can_extended_transport_protocol.cpp.
void isobus::ExtendedTransportProtocolManager::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 491 of file can_extended_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. |
Definition at line 131 of file can_extended_transport_protocol.cpp.
bool isobus::ExtendedTransportProtocolManager::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 516 of file can_extended_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 ETP "session" we're aborting |
[in] | reason | The reason we're aborting the session |
Definition at line 752 of file can_extended_transport_protocol.cpp.
|
private |
Sends the "clear to send" message.
[in] | session | The session for which we're sending the CTS |
Definition at line 804 of file can_extended_transport_protocol.cpp.
|
private |
Sends the "data packet offset" message for the provided session.
[in] | session | The session for which we're sending the DPO |
Definition at line 836 of file can_extended_transport_protocol.cpp.
|
private |
Sends data transfer packets for the specified ExtendedTransportProtocolSession.
[in] | session | The ExtendedTransportProtocolSession for which to send data transfer packets. |
Definition at line 584 of file can_extended_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 880 of file can_extended_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 785 of file can_extended_transport_protocol.cpp.
void isobus::ExtendedTransportProtocolManager::update | ( | ) |
Updates all sessions managed by this protocol manager instance.
Definition at line 561 of file can_extended_transport_protocol.cpp.
|
private |
Update the state machine for the passed in session.
[in] | session | The session to update |
Definition at line 637 of file can_extended_transport_protocol.cpp.
|
private |
A list of all active ETP sessions.
Definition at line 303 of file can_extended_transport_protocol.hpp.
|
private |
A callback for when a complete CAN message is received using the ETP protocol.
Definition at line 305 of file can_extended_transport_protocol.hpp.
|
staticconstexpr |
(21) ETP.CM_CTS Multiplexor
Definition at line 147 of file can_extended_transport_protocol.hpp.
|
private |
The configuration to use for this protocol.
Definition at line 306 of file can_extended_transport_protocol.hpp.
|
staticconstexpr |
(255) Abort multiplexor
Definition at line 150 of file can_extended_transport_protocol.hpp.
|
staticconstexpr |
(22) ETP.CM_DPO Multiplexor
Definition at line 148 of file can_extended_transport_protocol.hpp.
|
staticconstexpr |
(23) TP.CM_EOMA Multiplexor
Definition at line 149 of file can_extended_transport_protocol.hpp.
|
staticconstexpr |
The max number of bytes that this protocol can transfer.
Definition at line 151 of file can_extended_transport_protocol.hpp.
|
staticconstexpr |
The number of payload bytes per frame minus overhead of sequence number.
Definition at line 157 of file can_extended_transport_protocol.hpp.
|
staticconstexpr |
(20) ETP.CM_RTS Multiplexor
Definition at line 146 of file can_extended_transport_protocol.hpp.
|
private |
A callback for sending a CAN frame.
Definition at line 304 of file can_extended_transport_protocol.hpp.
|
staticconstexpr |
The index of the sequence number in a frame.
Definition at line 156 of file can_extended_transport_protocol.hpp.
|
staticconstexpr |
The t1 timeout as defined by the standard.
Definition at line 152 of file can_extended_transport_protocol.hpp.
|
staticconstexpr |
The t2/t3 timeouts as defined by the standard.
Definition at line 153 of file can_extended_transport_protocol.hpp.
|
staticconstexpr |
The t4 timeout as defined by the standard.
Definition at line 154 of file can_extended_transport_protocol.hpp.
|
staticconstexpr |
The Tr Timeout as defined by the standard.
Definition at line 155 of file can_extended_transport_protocol.hpp.