Skip to content

Commit

Permalink
refactor(core): add CANDataSpan for span of CAN data
Browse files Browse the repository at this point in the history
  • Loading branch information
GwnDaan committed Nov 21, 2023
1 parent f7166f4 commit ce892de
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
4 changes: 4 additions & 0 deletions isobus/include/isobus/isobus/can_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@

#include "isobus/isobus/can_control_function.hpp"
#include "isobus/isobus/can_identifier.hpp"
#include "isobus/utility/data_span.hpp"

#include <vector>

namespace isobus
{
/// @brief A read-only span of data provided by a CAN message
using CANDataSpan = DataSpan<const std::uint8_t>;

//================================================================================================
/// @class CANMessage
///
Expand Down
13 changes: 5 additions & 8 deletions isobus/include/isobus/isobus/can_network_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "isobus/isobus/can_identifier.hpp"
#include "isobus/isobus/can_internal_control_function.hpp"
#include "isobus/isobus/can_message.hpp"
#include "isobus/isobus/can_message_data.hpp"
#include "isobus/isobus/can_message_frame.hpp"
#include "isobus/isobus/can_network_configuration.hpp"
#include "isobus/isobus/can_transport_protocol.hpp"
Expand Down Expand Up @@ -103,7 +102,6 @@ namespace isobus
float get_estimated_busload(std::uint8_t canChannel);

/// @brief Sends a CAN message with the specified parameter group number and data buffer to the specified destination control function.
/// @deprecated Use the `send_can_message` function with a DataSpan instead.
/// @details 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
/// @param parameterGroupNumber The parameter group number of the CAN message.
Expand Down Expand Up @@ -158,7 +156,7 @@ namespace isobus
/// @param parentPointer A pointer to the parent object that gets passed to the txCompleteCallback.
/// @return True if the message is successfully enqueued, false otherwise.
bool send_can_message(std::uint32_t parameterGroupNumber,
DataSpan<const std::uint8_t> data,
CANDataSpan data,
std::shared_ptr<InternalControlFunction> sourceControlFunction,
std::shared_ptr<ControlFunction> destinationControlFunction,
CANIdentifier::CANPriority priority = CANIdentifier::CANPriority::PriorityDefault6,
Expand All @@ -185,7 +183,6 @@ namespace isobus
void *parentPointer = nullptr);

/// @brief Broadcast a CAN message with the specified parameter group number and data buffer. (Destination Address=0xFF)
/// @deprecated Use the `send_can_message_global` function with a DataSpan instead.
/// @details This function will automatically choose an appropriate transport protocol if needed.
/// @param parameterGroupNumber The parameter group number of the CAN message.
/// @param dataBuffer The data buffer containing the data to be sent.
Expand Down Expand Up @@ -231,7 +228,7 @@ namespace isobus
/// @param parentPointer A pointer to the parent object that gets passed to the txCompleteCallback.
/// @return True if the message is successfully enqueued, false otherwise.
bool send_can_message_global(std::uint32_t parameterGroupNumber,
DataSpan<const std::uint8_t> data,
CANDataSpan data,
std::shared_ptr<InternalControlFunction> sourceControlFunction,
CANIdentifier::CANPriority priority = CANIdentifier::CANPriority::PriorityDefault6,
TransmitCompleteCallback txCompleteCallback = nullptr,
Expand Down Expand Up @@ -355,7 +352,7 @@ namespace isobus
std::uint8_t destAddress,
std::uint32_t parameterGroupNumber,
std::uint8_t priority,
DataSpan<const std::uint8_t> data,
CANDataSpan data,
CANLibBadge<AddressClaimStateMachine>) const;

/// @brief Processes completed protocol messages. Causes PGN callbacks to trigger.
Expand Down Expand Up @@ -404,7 +401,7 @@ namespace isobus
std::uint8_t destAddress,
std::uint32_t parameterGroupNumber,
std::uint8_t priority,
DataSpan<const std::uint8_t> data) const;
CANDataSpan data) const;

/// @brief Returns a control function based on a CAN address and channel index
/// @param[in] channelIndex The CAN channel index of the CAN message being processed
Expand Down Expand Up @@ -478,7 +475,7 @@ namespace isobus
std::uint8_t destAddress,
std::uint32_t parameterGroupNumber,
std::uint8_t priority,
DataSpan<const std::uint8_t> data) const;
CANDataSpan data) const;

/// @brief Gets a PGN callback for the global address by index
/// @param[in] index The index of the callback to get
Expand Down
1 change: 0 additions & 1 deletion isobus/src/can_address_claim_state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//================================================================================================
#include "isobus/isobus/can_address_claim_state_machine.hpp"
#include "isobus/isobus/can_general_parameter_group_numbers.hpp"
#include "isobus/isobus/can_message_data.hpp"
#include "isobus/isobus/can_network_manager.hpp"
#include "isobus/isobus/can_stack_logger.hpp"
#include "isobus/utility/system_timing.hpp"
Expand Down
16 changes: 8 additions & 8 deletions isobus/src/can_network_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace isobus
void *parentPointer)
{
return send_can_message(parameterGroupNumber,
DataSpan<const std::uint8_t>(dataBuffer, dataLength),
CANDataSpan(dataBuffer, dataLength),
sourceControlFunction,
destinationControlFunction,
priority,
Expand Down Expand Up @@ -219,7 +219,7 @@ namespace isobus
}

bool CANNetworkManager::send_can_message(std::uint32_t parameterGroupNumber,
DataSpan<const std::uint8_t> data,
CANDataSpan data,
std::shared_ptr<InternalControlFunction> sourceControlFunction,
std::shared_ptr<ControlFunction> destinationControlFunction,
CANIdentifier::CANPriority priority,
Expand Down Expand Up @@ -310,7 +310,7 @@ namespace isobus
void *parentPointer)
{
return send_can_message(parameterGroupNumber,
DataSpan<const std::uint8_t>(data.begin(), data.size()),
CANDataSpan(data.begin(), data.size()),
sourceControlFunction,
destinationControlFunction,
priority,
Expand Down Expand Up @@ -354,7 +354,7 @@ namespace isobus
parentPointer);
}

bool isobus::CANNetworkManager::send_can_message_global(std::uint32_t parameterGroupNumber, DataSpan<const std::uint8_t> data, std::shared_ptr<InternalControlFunction> sourceControlFunction, CANIdentifier::CANPriority priority, TransmitCompleteCallback txCompleteCallback, void *parentPointer)
bool isobus::CANNetworkManager::send_can_message_global(std::uint32_t parameterGroupNumber, CANDataSpan data, std::shared_ptr<InternalControlFunction> sourceControlFunction, CANIdentifier::CANPriority priority, TransmitCompleteCallback txCompleteCallback, void *parentPointer)
{
return send_can_message(parameterGroupNumber,
data,
Expand All @@ -368,7 +368,7 @@ namespace isobus
bool isobus::CANNetworkManager::send_can_message_global(std::uint32_t parameterGroupNumber, std::initializer_list<std::uint8_t> data, std::shared_ptr<InternalControlFunction> sourceControlFunction, CANIdentifier::CANPriority priority, TransmitCompleteCallback txCompleteCallback, void *parentPointer)
{
return send_can_message(parameterGroupNumber,
DataSpan<const std::uint8_t>(data.begin(), data.size()),
CANDataSpan(data.begin(), data.size()),
sourceControlFunction,
nullptr, // To denote a global message we pass a null destination
priority,
Expand Down Expand Up @@ -429,7 +429,7 @@ namespace isobus
std::uint8_t destAddress,
std::uint32_t parameterGroupNumber,
std::uint8_t priority,
DataSpan<const std::uint8_t> data,
CANDataSpan data,
CANLibBadge<AddressClaimStateMachine>) const
{
return send_can_message_raw(portIndex, sourceAddress, destAddress, parameterGroupNumber, priority, data);
Expand Down Expand Up @@ -931,7 +931,7 @@ namespace isobus
std::uint8_t destAddress,
std::uint32_t parameterGroupNumber,
std::uint8_t priority,
DataSpan<const std::uint8_t> data) const
CANDataSpan data) const
{
CANMessageFrame txFrame;
txFrame.identifier = DEFAULT_IDENTIFIER;
Expand Down Expand Up @@ -1207,7 +1207,7 @@ namespace isobus
std::uint8_t destAddress,
std::uint32_t parameterGroupNumber,
std::uint8_t priority,
DataSpan<const std::uint8_t> data) const
CANDataSpan data) const
{
CANMessageFrame tempFrame = construct_frame(portIndex, sourceAddress, destAddress, parameterGroupNumber, priority, data);
bool retVal = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//================================================================================================
/// @file can_message_data.hpp
///
/// @brief Contains common types and functions for working with the data of a CAN message.
/// @brief Contains common types and functions for working with an arbitrary amount of items.
/// @author Daan Steenbergen
///
/// @copyright 2022 Open Agriculture
/// @copyright 2023 Open Agriculture
//================================================================================================
#ifndef CAN_MESSAGE_DATA_HPP
#define CAN_MESSAGE_DATA_HPP
#ifndef DATA_SPAN_HPP
#define DATA_SPAN_HPP

#include <array>
#include <cstddef>
Expand Down Expand Up @@ -101,4 +101,4 @@ namespace isobus
}
};
}
#endif // CAN_MESSAGE_DATA_HPP
#endif // DATA_SPAN_HPP

0 comments on commit ce892de

Please sign in to comment.