18#include "isobus/utility/system_timing.hpp"
19#include "isobus/utility/to_string.hpp"
27 TransportProtocolSessionBase(direction, std::move(data), parameterGroupNumber, totalMessageSize, source, destination, sessionCompleteCallback, parentPointer),
28 clearToSendPacketCountMax(clearToSendPacketMax)
45 return (
nullptr == get_destination());
51 if (transferred > get_message_length())
53 transferred = get_message_length();
66 std::uint8_t packetsSinceCTS = get_last_packet_number() - lastAcknowledgedPacketNumber;
67 return clearToSendPacketCount - packetsSinceCTS;
72 clearToSendPacketCount = value;
78 return clearToSendPacketCount;
83 return clearToSendPacketCountMax;
88 return lastSequenceNumber;
93 return lastSequenceNumber;
98 lastSequenceNumber = value;
104 lastAcknowledgedPacketNumber = value;
110 return get_total_number_of_packets() - get_last_packet_number();
118 totalNumberOfPackets++;
120 return totalNumberOfPackets;
133 std::uint32_t parameterGroupNumber,
134 std::uint16_t totalMessageSize,
135 std::uint8_t totalNumberOfPackets)
141 LOG_WARNING(
"[TP]: Ignoring Broadcast Announcement Message (BAM) for 0x%05X, configured maximum number of sessions reached.",
142 parameterGroupNumber);
146 LOG_WARNING(
"[TP]: Ignoring Broadcast Announcement Message (BAM) for 0x%05X, message size (%hu) is greater than the maximum (%hu).",
147 parameterGroupNumber,
154 if (
nullptr != oldSession)
156 LOG_WARNING(
"[TP]: Received Broadcast Announcement Message (BAM) while a session already existed for this source (%hu), overwriting for 0x%05X...",
157 source->get_address(),
158 parameterGroupNumber);
164 parameterGroupNumber,
172 if (newSession->get_total_number_of_packets() != totalNumberOfPackets)
174 LOG_WARNING(
"[TP]: Received Broadcast Announcement Message (BAM) for 0x%05X with a bad number of packets, aborting...", parameterGroupNumber);
181 LOG_DEBUG(
"[TP]: New rx broadcast message session for 0x%05X. Source: %hu", parameterGroupNumber, source->get_address());
187 const std::shared_ptr<ControlFunction> destination,
188 std::uint32_t parameterGroupNumber,
189 std::uint16_t totalMessageSize,
190 std::uint8_t totalNumberOfPackets,
191 std::uint8_t clearToSendPacketMax)
196 LOG_WARNING(
"[TP]: Replying with abort to Request To Send (RTS) for 0x%05X, configured maximum number of sessions reached.", parameterGroupNumber);
201 auto oldSession =
get_session(source, destination);
202 if (
nullptr != oldSession)
204 if (oldSession->get_parameter_group_number() != parameterGroupNumber)
206 LOG_ERROR(
"[TP]: Received Request To Send (RTS) while a session already existed for this source and destination, aborting for 0x%05X...",
207 parameterGroupNumber);
212 LOG_WARNING(
"[TP]: Received Request To Send (RTS) while a session already existed for this source and destination and parameterGroupNumber, overwriting for 0x%05X...",
213 parameterGroupNumber);
222 LOG_DEBUG(
"[TP]: Received Request To Send (RTS) with a CTS packet count of %hu, which is greater than the configured maximum of %hu, using the configured maximum instead.",
223 clearToSendPacketMax,
230 parameterGroupNumber,
232 clearToSendPacketMax,
238 if (newSession->get_total_number_of_packets() != totalNumberOfPackets)
240 LOG_ERROR(
"[TP]: Received Request To Send (RTS) for 0x%05X with a bad number of packets, aborting...", parameterGroupNumber);
247 LOG_DEBUG(
"[TP]: New rx session for 0x%05X. Source: %hu, destination: %hu", parameterGroupNumber, source->get_address(), destination->get_address());
254 const std::shared_ptr<ControlFunction> destination,
255 std::uint32_t parameterGroupNumber,
256 std::uint8_t packetsToBeSent,
257 std::uint8_t nextPacketNumber)
260 if (
nullptr != session)
262 if (session->get_parameter_group_number() != parameterGroupNumber)
264 LOG_ERROR(
"[TP]: Received a Clear To Send (CTS) message for 0x%05X while a session already existed for this source and destination, sending abort for both...", parameterGroupNumber);
268 else if (nextPacketNumber > session->get_total_number_of_packets())
270 LOG_ERROR(
"[TP]: Received a Clear To Send (CTS) message for 0x%05X with a bad sequence number, aborting...", parameterGroupNumber);
276 LOG_WARNING(
"[TP]: Received a Clear To Send (CTS) message for 0x%05X, but not expecting one, aborting session.", parameterGroupNumber);
281 session->set_acknowledged_packet_number(nextPacketNumber - 1);
282 session->set_cts_number_of_packets(packetsToBeSent);
286 if (0 != packetsToBeSent)
295 LOG_WARNING(
"[TP]: Received Clear To Send (CTS) for 0x%05X while no session existed for this source and destination, ignoring...", parameterGroupNumber);
300 const std::shared_ptr<ControlFunction> destination,
301 std::uint32_t parameterGroupNumber)
304 if (
nullptr != session)
310 LOG_DEBUG(
"[TP]: Completed tx session for 0x%05X from %hu", parameterGroupNumber, source->get_address());
315 LOG_WARNING(
"[TP]: Received an End Of Message Acknowledgement message for 0x%05X, but not expecting one, ignoring.", parameterGroupNumber);
320 LOG_WARNING(
"[TP]: Received End Of Message Acknowledgement for 0x%05X while no session existed for this source and destination, ignoring.", parameterGroupNumber);
325 const std::shared_ptr<ControlFunction> destination,
326 std::uint32_t parameterGroupNumber,
329 bool foundSession =
false;
332 if ((
nullptr != session) && (session->get_parameter_group_number() == parameterGroupNumber))
335 LOG_ERROR(
"[TP]: Received an abort (reason=%hu) for an rx session for parameterGroupNumber 0x%05X",
336 static_cast<std::uint8_t
>(reason),
337 parameterGroupNumber);
341 if ((
nullptr != session) && (session->get_parameter_group_number() == parameterGroupNumber))
344 LOG_ERROR(
"[TP]: Received an abort (reason=%hu) for a tx session for parameterGroupNumber 0x%05X",
345 static_cast<std::uint8_t
>(reason),
346 parameterGroupNumber);
352 LOG_WARNING(
"[TP]: Received an abort (reason=%hu) with no matching session for parameterGroupNumber 0x%05X",
353 static_cast<std::uint8_t
>(reason),
354 parameterGroupNumber);
362 LOG_WARNING(
"[TP]: Received a Connection Management message of invalid length %hu", message.
get_data_length());
375 const auto totalNumberOfPackets = message.
get_uint8_at(3);
377 parameterGroupNumber,
379 totalNumberOfPackets);
383 LOG_WARNING(
"[TP]: Received a Broadcast Announcement Message (BAM) with a non-global destination, ignoring");
392 LOG_WARNING(
"[TP]: Received a Request to Send (RTS) message with a global destination, ignoring");
397 const auto totalNumberOfPackets = message.
get_uint8_at(3);
398 const auto clearToSendPacketMax = message.
get_uint8_at(4);
401 parameterGroupNumber,
403 totalNumberOfPackets,
404 clearToSendPacketMax);
413 LOG_WARNING(
"[TP]: Received a Clear to Send (CTS) message with a global destination, ignoring");
421 parameterGroupNumber,
432 LOG_WARNING(
"[TP]: Received an End of Message Acknowledge message with a global destination, ignoring");
438 parameterGroupNumber);
447 LOG_WARNING(
"[TP]: Received an Abort message with a global destination, ignoring");
454 parameterGroupNumber,
462 LOG_WARNING(
"[TP]: Bad Mux in Transport Protocol Connection Management message");
472 LOG_WARNING(
"[TP]: Received a Data Transfer message of invalid length %hu", message.
get_data_length());
482 if (
nullptr != session)
486 LOG_WARNING(
"[TP]: Received a Data Transfer message from %hu while not expecting one, sending abort", source->get_address());
489 else if (sequenceNumber == session->get_last_sequence_number())
491 LOG_ERROR(
"[TP]: Aborting rx session for 0x%05X due to duplicate sequence number", session->get_parameter_group_number());
494 else if (sequenceNumber == (session->get_last_sequence_number() + 1))
503 if (currentDataIndex < session->get_message_length())
514 session->set_last_sequency_number(sequenceNumber);
515 if (session->get_number_of_remaining_packets() == 0)
525 session->get_parameter_group_number(),
528 source->get_address());
538 LOG_DEBUG(
"[TP]: Completed rx session for 0x%05X from %hu", session->get_parameter_group_number(), source->get_address());
540 else if (session->get_cts_number_of_packets_remaining() == 0)
547 LOG_ERROR(
"[TP]: Aborting rx session for 0x%05X due to bad sequence number", session->get_parameter_group_number());
553 LOG_WARNING(
"[TP]: Received a Data Transfer message from %hu with no matching session, ignoring...", source->get_address());
564 case static_cast<std::uint32_t
>(CANLibParameterGroupNumber::TransportProtocolConnectionManagement):
570 case static_cast<std::uint32_t
>(CANLibParameterGroupNumber::TransportProtocolDataTransfer):
583 std::unique_ptr<CANMessageData> &data,
584 std::shared_ptr<ControlFunction> source,
585 std::shared_ptr<ControlFunction> destination,
595 else if ((
nullptr == source) || (!source->get_address_valid()) ||
has_session(source, destination))
602 data = data->copy_if_not_owned(std::move(data));
603 auto dataLength =
static_cast<std::uint16_t
>(data->size());
607 parameterGroupNumber,
612 sessionCompleteCallback,
615 if (session->is_broadcast())
619 LOG_DEBUG(
"[TP]: New broadcast tx session for 0x%05X. Source: %hu",
620 parameterGroupNumber,
621 source->get_address());
627 LOG_DEBUG(
"[TP]: New tx session for 0x%05X. Source: %hu, destination: %hu",
628 parameterGroupNumber,
629 source->get_address(),
630 destination->get_address());
643 if (!session->get_source()->get_address_valid())
645 LOG_WARNING(
"[TP]: Closing active session as the source control function is no longer valid");
648 else if (!session->is_broadcast() && !session->get_destination()->get_address_valid())
650 LOG_WARNING(
"[TP]: Closing active session as the destination control function is no longer valid");
662 std::array<std::uint8_t, CAN_DATA_LENGTH> buffer;
663 std::uint8_t framesToSend = session->get_cts_number_of_packets_remaining();
664 if (session->is_broadcast())
674 for (std::uint8_t i = 0; i < framesToSend; i++)
676 buffer[0] = session->get_last_sequence_number() + 1;
681 std::uint16_t index = dataOffset + j;
682 if (index < session->get_message_length())
684 buffer[1 + j] = session->get_data().get_byte(index);
688 buffer[1 + j] = 0xFF;
692 if (
sendCANFrameCallback(
static_cast<std::uint32_t
>(CANLibParameterGroupNumber::TransportProtocolDataTransfer),
694 std::static_pointer_cast<InternalControlFunction>(session->get_source()),
695 session->get_destination(),
698 session->set_last_sequency_number(session->get_last_sequence_number() + 1);
707 if (session->get_number_of_remaining_packets() == 0)
709 if (session->is_broadcast())
711 LOG_DEBUG(
"[TP]: Completed broadcast tx session for 0x%05X", session->get_parameter_group_number());
719 else if ((session->get_cts_number_of_packets_remaining() == 0) && !session->is_broadcast())
727 switch (session->state)
754 LOG_ERROR(
"[TP]: Timeout tx session for 0x%05X (expected CTS)", session->get_parameter_group_number());
755 if (session->get_cts_number_of_packets() > 0)
793 if (session->is_broadcast())
798 LOG_WARNING(
"[TP]: Broadcast rx session timeout");
802 else if (session->get_cts_number_of_packets_remaining() == session->get_cts_number_of_packets())
807 LOG_ERROR(
"[TP]: Timeout for destination-specific rx session (expected first data frame)");
816 LOG_ERROR(
"[TP]: Timeout for destination-specific rx session (expected sequential data frame)");
827 LOG_ERROR(
"[TP]: Timeout tx session for 0x%05X (expected EOMA)", session->get_parameter_group_number());
838 std::shared_ptr<InternalControlFunction> myControlFunction;
839 std::shared_ptr<ControlFunction> partnerControlFunction;
842 myControlFunction = std::static_pointer_cast<InternalControlFunction>(session->get_source());
843 partnerControlFunction = session->get_destination();
847 myControlFunction = std::static_pointer_cast<InternalControlFunction>(session->get_destination());
848 partnerControlFunction = session->get_source();
851 if ((
nullptr != myControlFunction) && (
nullptr != partnerControlFunction))
853 retVal =
send_abort(myControlFunction, partnerControlFunction, session->get_parameter_group_number(), reason);
860 std::shared_ptr<ControlFunction> receiver,
861 std::uint32_t parameterGroupNumber,
864 const std::array<std::uint8_t, CAN_DATA_LENGTH> buffer{
866 static_cast<std::uint8_t
>(reason),
870 static_cast<std::uint8_t
>(parameterGroupNumber & 0xFF),
871 static_cast<std::uint8_t
>((parameterGroupNumber >> 8) & 0xFF),
872 static_cast<std::uint8_t
>((parameterGroupNumber >> 16) & 0xFF)
874 return sendCANFrameCallback(
static_cast<std::uint32_t
>(CANLibParameterGroupNumber::TransportProtocolConnectionManagement),
883 session->complete(successful);
889 LOG_DEBUG(
"[TP]: Session Closed");
895 const std::array<std::uint8_t, CAN_DATA_LENGTH> buffer{
897 static_cast<std::uint8_t
>(session->get_message_length() & 0xFF),
898 static_cast<std::uint8_t
>((session->get_message_length() >> 8) & 0xFF),
899 session->get_total_number_of_packets(),
901 static_cast<std::uint8_t
>(session->get_parameter_group_number() & 0xFF),
902 static_cast<std::uint8_t
>((session->get_parameter_group_number() >> 8) & 0xFF),
903 static_cast<std::uint8_t
>((session->get_parameter_group_number() >> 16) & 0xFF)
905 return sendCANFrameCallback(
static_cast<std::uint32_t
>(CANLibParameterGroupNumber::TransportProtocolConnectionManagement),
907 std::static_pointer_cast<InternalControlFunction>(session->get_source()),
914 const std::array<std::uint8_t, CAN_DATA_LENGTH> buffer{
916 static_cast<std::uint8_t
>(session->get_message_length() & 0xFF),
917 static_cast<std::uint8_t
>((session->get_message_length() >> 8) & 0xFF),
918 session->get_total_number_of_packets(),
919 session->get_rts_number_of_packet_limit(),
920 static_cast<std::uint8_t
>(session->get_parameter_group_number() & 0xFF),
921 static_cast<std::uint8_t
>((session->get_parameter_group_number() >> 8) & 0xFF),
922 static_cast<std::uint8_t
>((session->get_parameter_group_number() >> 16) & 0xFF)
924 return sendCANFrameCallback(
static_cast<std::uint32_t
>(CANLibParameterGroupNumber::TransportProtocolConnectionManagement),
926 std::static_pointer_cast<InternalControlFunction>(session->get_source()),
927 session->get_destination(),
935 std::uint8_t packetsThisSegment = session->get_number_of_remaining_packets();
936 if (packetsThisSegment > session->get_rts_number_of_packet_limit())
938 packetsThisSegment = session->get_rts_number_of_packet_limit();
940 else if (packetsThisSegment > 16)
943 packetsThisSegment = 16;
946 const std::array<std::uint8_t, CAN_DATA_LENGTH> buffer{
949 static_cast<std::uint8_t
>(session->get_last_packet_number() + 1),
952 static_cast<std::uint8_t
>(session->get_parameter_group_number() & 0xFF),
953 static_cast<std::uint8_t
>((session->get_parameter_group_number() >> 8) & 0xFF),
954 static_cast<std::uint8_t
>((session->get_parameter_group_number() >> 16) & 0xFF)
956 retVal =
sendCANFrameCallback(
static_cast<std::uint32_t
>(CANLibParameterGroupNumber::TransportProtocolConnectionManagement),
958 std::static_pointer_cast<InternalControlFunction>(session->get_destination()),
959 session->get_source(),
963 session->set_cts_number_of_packets(packetsThisSegment);
964 session->set_acknowledged_packet_number(session->get_last_packet_number());
971 std::uint32_t messageLength = session->get_message_length();
972 std::uint32_t parameterGroupNumber = session->get_parameter_group_number();
974 const std::array<std::uint8_t, CAN_DATA_LENGTH> buffer{
976 static_cast<std::uint8_t
>(messageLength & 0xFF),
977 static_cast<std::uint8_t
>((messageLength >> 8) & 0xFF),
978 session->get_total_number_of_packets(),
980 static_cast<std::uint8_t
>(parameterGroupNumber & 0xFF),
981 static_cast<std::uint8_t
>((parameterGroupNumber >> 8) & 0xFF),
982 static_cast<std::uint8_t
>((parameterGroupNumber >> 16) & 0xFF),
985 return sendCANFrameCallback(
static_cast<std::uint32_t
>(CANLibParameterGroupNumber::TransportProtocolConnectionManagement),
987 std::static_pointer_cast<InternalControlFunction>(session->get_destination()),
989 session->get_source(),
995 return std::any_of(
activeSessions.begin(),
activeSessions.end(), [&](
const std::shared_ptr<TransportProtocolManager::TransportProtocolSession> &session) {
996 return session->matches(source, destination);
1001 std::shared_ptr<ControlFunction> destination)
1003 auto result = std::find_if(
activeSessions.begin(),
activeSessions.end(), [&](
const std::shared_ptr<TransportProtocolManager::TransportProtocolSession> &session) {
1004 return session->matches(source, destination);
Defines some PGNs that are used in the library or are very common.
A representation of an ISOBUS ECU that we can send from. Use this class when defining your own contro...
An abstraction of a CAN message, could be > 8 data bytes.
A class that acts as a logging sink. The intent is that someone could make their own derived class of...
A protocol that handles the ISO11783/J1939 transport protocol. It handles both the broadcast version ...
A utility class that allows easy interpretation of a 32 bit CAN identifier.
@ PriorityLowest7
The lowest priority.
@ PriorityDefault6
The default priority.
std::uint32_t get_parameter_group_number() const
Returns the PGN encoded in the identifier.
static constexpr std::uint8_t GLOBAL_ADDRESS
The broadcast CAN address.
@ Extended
Frame is a modern 29 bit ID CAN frame.
A class that represents data of a CAN message by holding a vector of bytes.
void set_byte(std::size_t index, std::uint8_t value)
Set the byte at the given index.
A class that represents a generic CAN message of arbitrary length.
@ Receive
Message is being received.
std::uint32_t get_data_length() const
Returns the length of the data in the CAN message.
bool has_valid_source_control_function() const
Returns whether the message is sent by a device that claimed its address on the bus.
std::uint32_t get_uint24_at(const std::uint32_t index, const ByteFormat format=ByteFormat::LittleEndian) const
Get a right-aligned 24-bit integer from the buffer (returned as a uint32_t) at a specific index....
std::shared_ptr< ControlFunction > get_source_control_function() const
Gets the source control function that the message is from.
std::uint8_t get_uint8_at(const std::uint32_t index) const
Get a 8-bit unsigned byte from the buffer at a specific index. A 8-bit unsigned byte can hold a value...
std::uint16_t get_uint16_at(const std::uint32_t index, const ByteFormat format=ByteFormat::LittleEndian) const
Get a 16-bit unsigned integer from the buffer at a specific index. A 16-bit unsigned integer can hold...
CANIdentifier get_identifier() const
Returns the identifier of the message.
std::shared_ptr< ControlFunction > get_destination_control_function() const
Gets the destination control function that the message is to.
bool is_broadcast() const
Returns whether the message is sent as a broadcast message / to all devices on the bus.
bool is_destination_our_device() const
Returns whether the message is destined for our device on the bus.
A class that defines stack-wide configuration data. You can set the values in there to suit your spec...
std::uint8_t get_max_number_of_network_manager_protocol_frames_per_update() const
Returns the max number of data frames the stack will send from each transport layer protocol,...
std::uint8_t get_number_of_packets_per_cts_message() const
Get the the number of packets per CTS packet for TP sessions.
std::uint32_t get_max_number_transport_protocol_sessions() const
Returns the max number of concurrent TP sessions.
std::uint32_t get_minimum_time_between_transport_protocol_bam_frames() const
Returns the minimum time to wait between sending BAM frames.
void set_acknowledged_packet_number(std::uint8_t value)
Set the last acknowledged packet number by the receiver.
TransportProtocolSession(TransportProtocolSessionBase::Direction direction, std::unique_ptr< CANMessageData > data, std::uint32_t parameterGroupNumber, std::uint16_t totalMessageSize, std::uint8_t clearToSendPacketMax, std::shared_ptr< ControlFunction > source, std::shared_ptr< ControlFunction > destination, TransmitCompleteCallback sessionCompleteCallback, void *parentPointer)
The constructor for a session, for advanced use only. In most cases, you should use the CANNetworkMan...
std::uint8_t get_cts_number_of_packets_remaining() const
Get the number of packets to be sent in response to the current CTS.
void set_state(StateMachineState value)
Set the state of the session.
StateMachineState get_state() const
Get the state of the session.
std::uint32_t get_total_bytes_transferred() const override
Get the number of bytes that have been sent or received in this session.
std::uint8_t get_cts_number_of_packets() const
Get the number of packets that can be sent in response to the current CTS.
std::uint8_t get_rts_number_of_packet_limit() const
Get the maximum number of packets that can be sent per CTS as indicated by the RTS message.
std::uint16_t get_message_length() const
Get the total number of bytes that will be sent or received in this session.
void set_cts_number_of_packets(std::uint8_t value)
Set the number of packets to be sent in response to the curent CTS.
std::uint8_t get_last_sequence_number() const
Get the last sequence number that was processed.
bool is_broadcast() const
Get whether or not this session is a broadcast session (BAM)
std::uint8_t get_number_of_remaining_packets() const
Get the number of packets that remain to be sent or received in this session.
std::uint8_t get_total_number_of_packets() const
Get the total number of packets that will be sent or received in this session.
std::uint8_t get_last_packet_number() const
Get the last packet number that was processed.
void set_last_sequency_number(std::uint8_t value)
Set the last sequence number that will be processed.
void process_connection_management_message(const CANMessage &message)
Processes a connection management message.
static constexpr std::uint32_t REQUEST_TO_SEND_MULTIPLEXOR
(16) TP.CM_RTS Multiplexor
static constexpr std::uint32_t END_OF_MESSAGE_ACKNOWLEDGE_MULTIPLEXOR
(19) TP.CM_EOM_ACK Multiplexor
bool send_broadcast_announce_message(std::shared_ptr< TransportProtocolSession > &session) const
Sends the "broadcast announce" message.
bool send_end_of_session_acknowledgement(std::shared_ptr< TransportProtocolSession > &session) const
Sends the "end of message acknowledgement" message for the provided session.
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 constexpr std::uint32_t MAX_PROTOCOL_DATA_LENGTH
The max number of bytes that this protocol can transfer.
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_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.
const CANMessageFrameCallback sendCANFrameCallback
A callback for sending a CAN frame.
static constexpr std::uint32_t BROADCAST_ANNOUNCE_MESSAGE_MULTIPLEXOR
(32) TP.BAM Multiplexor
TransportProtocolManager(const CANMessageFrameCallback &sendCANFrameCallback, const CANMessageCallback &canMessageReceivedCallback, const CANNetworkConfiguration *configuration)
The constructor for the TransportProtocolManager, for advanced use only. In most cases,...
ConnectionAbortReason
A list of all defined abort reasons in ISO11783.
@ DuplicateSequenceNumber
Re-received a sequence number we've already processed.
@ BadSequenceNumber
Incorrect sequence number was received and cannot be recovered.
@ AlreadyInCMSession
We are already in a connection mode session and can't support another.
@ ClearToSendReceivedWhileTransferInProgress
A CTS was received while already processing the last CTS.
@ AnyOtherError
Any reason not defined in the standard.
@ Timeout
General timeout.
@ UnexpectedDataTransferPacketReceived
A data packet was received outside the proper state.
bool send_request_to_send(std::shared_ptr< TransportProtocolSession > &session) const
Sends the "request to send" message as part of initiating a transmit.
static constexpr std::uint16_t T1_TIMEOUT_MS
The t1 timeout as defined by the standard.
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.
const std::vector< std::shared_ptr< TransportProtocolSession > > & get_sessions() const
Gets all the active transport protocol sessions that are currently active.
static constexpr std::uint32_t CLEAR_TO_SEND_MULTIPLEXOR
(17) TP.CM_CTS Multiplexor
const CANMessageCallback canMessageReceivedCallback
A callback for when a complete CAN message is received using the TP protocol.
bool abort_session(std::shared_ptr< TransportProtocolSession > &session, ConnectionAbortReason reason)
Aborts the session with the specified abort reason. Sends a CAN message.
std::vector< std::shared_ptr< TransportProtocolSession > > activeSessions
A list of all active TP sessions.
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_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 close_session(std::shared_ptr< TransportProtocolSession > &session, bool successful)
Gracefully closes a session to prepare for a new session.
void send_data_transfer_packets(std::shared_ptr< TransportProtocolSession > &session)
Sends data transfer packets for the specified TransportProtocolSession.
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.
static constexpr std::uint8_t SEQUENCE_NUMBER_DATA_INDEX
The index of the sequence number in a frame.
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.
static constexpr std::uint8_t PROTOCOL_BYTES_PER_FRAME
The number of payload bytes per frame minus overhead of sequence number.
void update_state_machine(std::shared_ptr< TransportProtocolSession > &session)
Update the state machine for the passed in session.
static constexpr std::uint16_t T2_T3_TIMEOUT_MS
The t2/t3 timeouts as defined by the standard.
void process_message(const CANMessage &message)
A generic way for a protocol to process a received message.
bool send_clear_to_send(std::shared_ptr< TransportProtocolSession > &session) const
Sends the "clear to send" message.
StateMachineState
The states that a TP session could be in. Used for the internal state machine.
@ SendBroadcastAnnounce
We are sending the broadcast announce message (BAM)
@ WaitForEndOfMessageAcknowledge
We are waiting for an end of message acknowledgement.
@ SendClearToSend
We are sending clear to send message.
@ SendRequestToSend
We are sending the request to send message.
@ WaitForDataTransferPacket
We are waiting for data transfer packets.
@ WaitForClearToSend
We are waiting for a clear to send message.
@ None
Protocol session is not in progress.
@ SendDataTransferPackets
A Tx data session is in progress.
void update()
Updates all sessions managed by this protocol manager instance.
void process_data_transfer_message(const CANMessage &message)
Processes a data transfer message.
const CANNetworkConfiguration * configuration
The configuration to use for this protocol.
static constexpr std::uint32_t CONNECTION_ABORT_MULTIPLEXOR
(255) Abort multiplexor
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.
An object to keep track of session information internally.
std::uint32_t get_message_length() const
Get the total number of bytes that will be sent or received in this session.
Direction
Enumerates the possible session directions.
@ Receive
We are receiving a message.
@ Transmit
We are transmitting a message.
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...
DataSpan< const std::uint8_t > CANDataSpan
A read-only span of data for a CAN message.
std::function< bool(std::uint32_t parameterGroupNumber, CANDataSpan data, std::shared_ptr< InternalControlFunction > sourceControlFunction, std::shared_ptr< ControlFunction > destinationControlFunction, CANIdentifier::CANPriority priority)> CANMessageFrameCallback
A callback for communicating CAN message frames.
void(*)(std::uint32_t parameterGroupNumber, std::uint32_t dataLength, std::shared_ptr< InternalControlFunction > sourceControlFunction, std::shared_ptr< ControlFunction > destinationControlFunction, bool successful, void *parentPointer) TransmitCompleteCallback
A callback for when a transmit is completed by the stack.
constexpr std::uint8_t CAN_DATA_LENGTH
The length of a classical CAN frame.
std::function< void(const CANMessage &message)> CANMessageCallback
A callback for communicating CAN messages.