Skip to content

Commit

Permalink
tests(tp): add RTS overwrites session test
Browse files Browse the repository at this point in the history
And made limit number of packets per CTS configurable
  • Loading branch information
GwnDaan committed Dec 13, 2023
1 parent cd6a836 commit b7ebe5a
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 29 deletions.
12 changes: 11 additions & 1 deletion isobus/include/isobus/isobus/can_network_configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace isobus
/// @returns The max number of concurrent TP sessions
std::uint32_t get_max_number_transport_protocol_sessions() const;

/// @brief Sets the minimum time to wait between sending BAM frames
/// @brief Sets the minimum time to wait between sending BAM frames (default is 50 ms)
/// @details The acceptable range as defined by ISO-11783 is 10 to 200 ms.
/// This is a minumum time, so if you set it to some value, like 10 ms, the
/// stack will attempt to transmit it as close to that time as it can, but it is
Expand Down Expand Up @@ -73,13 +73,23 @@ namespace isobus
/// @returns The max number of frames to use in transport protocols in each network manager update
std::uint8_t get_max_number_of_network_manager_protocol_frames_per_update() const;

/// @brief Set the the number of packets per CTS message for TP sessions. The default
/// is 16. Note that the receiving control function may not support this limitation, or choose
/// to ignore it and use a different number of packets per CTS packet.
void set_number_of_packets_per_cts_message(std::uint8_t numberPackets);

/// @brief Get the the number of packets per CTS packet for TP sessions.
/// @returns The number of packets per CTS packet for TP sessions.
std::uint8_t get_number_of_packets_per_cts_message() const;

private:
static constexpr std::uint8_t DEFAULT_BAM_PACKET_DELAY_TIME_MS = 50; ///< The default time between BAM frames, as defined by J1939

std::uint32_t maxNumberTransportProtocolSessions = 4; ///< The max number of TP sessions allowed
std::uint32_t minimumTimeBetweenTransportProtocolBAMFrames = DEFAULT_BAM_PACKET_DELAY_TIME_MS; ///< The configurable time between BAM frames
std::uint8_t extendedTransportProtocolMaxNumberOfFramesPerEDPO = 0xFF; ///< Used to control throttling of ETP sessions.
std::uint8_t networkManagerMaxFramesToSendPerUpdate = 0xFF; ///< Used to control the max number of transport layer frames added to the driver queue per network manager update
std::uint8_t numberOfPacketsPerCTSMessage = 16; ///< The number of packets per CTS message for TP sessions
};
} // namespace isobus

Expand Down
1 change: 1 addition & 0 deletions isobus/include/isobus/isobus/can_transport_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ namespace isobus
std::unique_ptr<CANMessageData> data,
std::shared_ptr<ControlFunction> source,
std::shared_ptr<ControlFunction> destination,
std::uint8_t clearToSendPacketMax,
TransmitCompleteCallback sessionCompleteCallback,
void *parentPointer);

Expand Down
10 changes: 10 additions & 0 deletions isobus/src/can_network_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ namespace isobus
{
return networkManagerMaxFramesToSendPerUpdate;
}

void CANNetworkConfiguration::set_number_of_packets_per_cts_message(std::uint8_t numberFrames)
{
numberOfPacketsPerCTSMessage = numberFrames;
}

std::uint8_t CANNetworkConfiguration::get_number_of_packets_per_cts_message() const
{
return numberOfPacketsPerCTSMessage;
}
}
16 changes: 10 additions & 6 deletions isobus/src/can_transport_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,10 @@ namespace isobus
std::unique_ptr<CANMessageData> data,
std::shared_ptr<ControlFunction> source,
std::shared_ptr<ControlFunction> destination,
std::uint8_t clearToSendPacketMax,
TransmitCompleteCallback sessionCompleteCallback,
void *parentPointer)
{
constexpr std::uint8_t MAX_PACKETS_PER_SEGMENT = 16; //! @todo: make this configurable, the standard recommends 16

auto totalMessageSize = data->size();
auto totalPacketCount = static_cast<std::uint8_t>(totalMessageSize / PROTOCOL_BYTES_PER_FRAME);
if (0 != (totalMessageSize % PROTOCOL_BYTES_PER_FRAME))
Expand All @@ -135,7 +134,7 @@ namespace isobus
parameterGroupNumber,
totalMessageSize,
totalPacketCount,
MAX_PACKETS_PER_SEGMENT,
clearToSendPacketMax,
source,
destination,
sessionCompleteCallback,
Expand Down Expand Up @@ -279,6 +278,12 @@ namespace isobus

auto data = std::make_unique<CANMessageDataVector>(totalMessageSize);

if (clearToSendPacketMax > configuration->get_number_of_packets_per_cts_message())
{
CANStackLogger::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.", clearToSendPacketMax, configuration->get_number_of_packets_per_cts_message());
clearToSendPacketMax = configuration->get_number_of_packets_per_cts_message();
}

TransportProtocolSession newSession = TransportProtocolSession::create_receive_session(parameterGroupNumber,
totalMessageSize,
totalNumberOfPackets,
Expand Down Expand Up @@ -357,8 +362,7 @@ namespace isobus
}
else
{
CANStackLogger::warn("[TP]: Received End Of Message Acknowledgement for 0x%05X while no session existed for this source and destination, sending abort.", parameterGroupNumber);
send_abort(std::static_pointer_cast<InternalControlFunction>(destination), source, parameterGroupNumber, ConnectionAbortReason::AnyOtherError);
CANStackLogger::warn("[TP]: Received End Of Message Acknowledgement for 0x%05X while no session existed for this source and destination, ignoring.", parameterGroupNumber);
}
}

Expand All @@ -378,7 +382,6 @@ namespace isobus
}
session = get_session(destination, source);
if ((nullptr != session) && (session->get_parameter_group_number() == parameterGroupNumber))

{
foundSession = true;
CANStackLogger::error("[TP]: Received an abort (reason=%hu) for a tx session for parameterGroupNumber 0x%05X", static_cast<std::uint8_t>(reason), parameterGroupNumber);
Expand Down Expand Up @@ -642,6 +645,7 @@ namespace isobus
std::move(data),
source,
destination,
configuration->get_number_of_packets_per_cts_message(),
sessionCompleteCallback,
parentPointer);

Expand Down
Loading

0 comments on commit b7ebe5a

Please sign in to comment.