diff --git a/isobus/include/isobus/isobus/can_message.hpp b/isobus/include/isobus/isobus/can_message.hpp index 63fc1f9e..2c1b34cf 100644 --- a/isobus/include/isobus/isobus/can_message.hpp +++ b/isobus/include/isobus/isobus/can_message.hpp @@ -13,11 +13,15 @@ #include "isobus/isobus/can_control_function.hpp" #include "isobus/isobus/can_identifier.hpp" +#include "isobus/utility/data_span.hpp" #include namespace isobus { + /// @brief A read-only span of data provided by a CAN message + using CANDataSpan = DataSpan; + //================================================================================================ /// @class CANMessage /// diff --git a/isobus/include/isobus/isobus/can_network_manager.hpp b/isobus/include/isobus/isobus/can_network_manager.hpp index a10218f7..42478217 100644 --- a/isobus/include/isobus/isobus/can_network_manager.hpp +++ b/isobus/include/isobus/isobus/can_network_manager.hpp @@ -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" @@ -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. @@ -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 data, + CANDataSpan data, std::shared_ptr sourceControlFunction, std::shared_ptr destinationControlFunction, CANIdentifier::CANPriority priority = CANIdentifier::CANPriority::PriorityDefault6, @@ -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. @@ -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 data, + CANDataSpan data, std::shared_ptr sourceControlFunction, CANIdentifier::CANPriority priority = CANIdentifier::CANPriority::PriorityDefault6, TransmitCompleteCallback txCompleteCallback = nullptr, @@ -355,7 +352,7 @@ namespace isobus std::uint8_t destAddress, std::uint32_t parameterGroupNumber, std::uint8_t priority, - DataSpan data, + CANDataSpan data, CANLibBadge) const; /// @brief Processes completed protocol messages. Causes PGN callbacks to trigger. @@ -404,7 +401,7 @@ namespace isobus std::uint8_t destAddress, std::uint32_t parameterGroupNumber, std::uint8_t priority, - DataSpan 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 @@ -478,7 +475,7 @@ namespace isobus std::uint8_t destAddress, std::uint32_t parameterGroupNumber, std::uint8_t priority, - DataSpan 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 diff --git a/isobus/src/can_address_claim_state_machine.cpp b/isobus/src/can_address_claim_state_machine.cpp index 5d8c6a31..605b5638 100644 --- a/isobus/src/can_address_claim_state_machine.cpp +++ b/isobus/src/can_address_claim_state_machine.cpp @@ -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" diff --git a/isobus/src/can_network_manager.cpp b/isobus/src/can_network_manager.cpp index 75665465..ad51960c 100644 --- a/isobus/src/can_network_manager.cpp +++ b/isobus/src/can_network_manager.cpp @@ -122,7 +122,7 @@ namespace isobus void *parentPointer) { return send_can_message(parameterGroupNumber, - DataSpan(dataBuffer, dataLength), + CANDataSpan(dataBuffer, dataLength), sourceControlFunction, destinationControlFunction, priority, @@ -219,7 +219,7 @@ namespace isobus } bool CANNetworkManager::send_can_message(std::uint32_t parameterGroupNumber, - DataSpan data, + CANDataSpan data, std::shared_ptr sourceControlFunction, std::shared_ptr destinationControlFunction, CANIdentifier::CANPriority priority, @@ -310,7 +310,7 @@ namespace isobus void *parentPointer) { return send_can_message(parameterGroupNumber, - DataSpan(data.begin(), data.size()), + CANDataSpan(data.begin(), data.size()), sourceControlFunction, destinationControlFunction, priority, @@ -354,7 +354,7 @@ namespace isobus parentPointer); } - bool isobus::CANNetworkManager::send_can_message_global(std::uint32_t parameterGroupNumber, DataSpan data, std::shared_ptr sourceControlFunction, CANIdentifier::CANPriority priority, TransmitCompleteCallback txCompleteCallback, void *parentPointer) + bool isobus::CANNetworkManager::send_can_message_global(std::uint32_t parameterGroupNumber, CANDataSpan data, std::shared_ptr sourceControlFunction, CANIdentifier::CANPriority priority, TransmitCompleteCallback txCompleteCallback, void *parentPointer) { return send_can_message(parameterGroupNumber, data, @@ -368,7 +368,7 @@ namespace isobus bool isobus::CANNetworkManager::send_can_message_global(std::uint32_t parameterGroupNumber, std::initializer_list data, std::shared_ptr sourceControlFunction, CANIdentifier::CANPriority priority, TransmitCompleteCallback txCompleteCallback, void *parentPointer) { return send_can_message(parameterGroupNumber, - DataSpan(data.begin(), data.size()), + CANDataSpan(data.begin(), data.size()), sourceControlFunction, nullptr, // To denote a global message we pass a null destination priority, @@ -429,7 +429,7 @@ namespace isobus std::uint8_t destAddress, std::uint32_t parameterGroupNumber, std::uint8_t priority, - DataSpan data, + CANDataSpan data, CANLibBadge) const { return send_can_message_raw(portIndex, sourceAddress, destAddress, parameterGroupNumber, priority, data); @@ -931,7 +931,7 @@ namespace isobus std::uint8_t destAddress, std::uint32_t parameterGroupNumber, std::uint8_t priority, - DataSpan data) const + CANDataSpan data) const { CANMessageFrame txFrame; txFrame.identifier = DEFAULT_IDENTIFIER; @@ -1207,7 +1207,7 @@ namespace isobus std::uint8_t destAddress, std::uint32_t parameterGroupNumber, std::uint8_t priority, - DataSpan data) const + CANDataSpan data) const { CANMessageFrame tempFrame = construct_frame(portIndex, sourceAddress, destAddress, parameterGroupNumber, priority, data); bool retVal = false; diff --git a/isobus/include/isobus/isobus/can_message_data.hpp b/utility/include/isobus/utility/data_span.hpp similarity index 95% rename from isobus/include/isobus/isobus/can_message_data.hpp rename to utility/include/isobus/utility/data_span.hpp index 5930969b..b1f5947d 100644 --- a/isobus/include/isobus/isobus/can_message_data.hpp +++ b/utility/include/isobus/utility/data_span.hpp @@ -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 #include @@ -101,4 +101,4 @@ namespace isobus } }; } -#endif // CAN_MESSAGE_DATA_HPP +#endif // DATA_SPAN_HPP