Skip to content

Commit

Permalink
feat: rework NMEA2000 fast packet protocol to match TP/ETP
Browse files Browse the repository at this point in the history
  • Loading branch information
GwnDaan committed Feb 20, 2024
1 parent c35c5b8 commit 53b69db
Show file tree
Hide file tree
Showing 17 changed files with 533 additions and 769 deletions.
6 changes: 3 additions & 3 deletions examples/nmea2000/fast_packet_protocol/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int main()

auto TestInternalECU = isobus::InternalControlFunction::create(TestDeviceNAME, 0x1C, 0);

isobus::CANNetworkManager::CANNetwork.get_fast_packet_protocol().register_multipacket_message_callback(0x1F001, nmea2k_callback, nullptr);
isobus::CANNetworkManager::CANNetwork.get_fast_packet_protocol(0)->register_multipacket_message_callback(0x1F001, nmea2k_callback, nullptr);

// Wait to make sure address claiming is done. The time is arbitrary.
//! @todo Check this instead of assuming it is done
Expand All @@ -106,13 +106,13 @@ int main()
while (running)
{
// Send a fast packet message
isobus::CANNetworkManager::CANNetwork.get_fast_packet_protocol().send_multipacket_message(0x1F001, testMessageData, TEST_MESSAGE_LENGTH, TestInternalECU, nullptr, isobus::CANIdentifier::CANPriority::PriorityLowest7, nmea2k_transmit_complete_callback);
isobus::CANNetworkManager::CANNetwork.get_fast_packet_protocol(0)->send_multipacket_message(0x1F001, testMessageData, TEST_MESSAGE_LENGTH, TestInternalECU, nullptr, isobus::CANIdentifier::CANPriority::PriorityLowest7, nmea2k_transmit_complete_callback);

// Sleep for a while
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
}

isobus::CANHardwareInterface::stop();
isobus::CANNetworkManager::CANNetwork.get_fast_packet_protocol().remove_multipacket_message_callback(0x1F001, nmea2k_callback, nullptr);
isobus::CANNetworkManager::CANNetwork.get_fast_packet_protocol(0)->remove_multipacket_message_callback(0x1F001, nmea2k_callback, nullptr);
return 0;
}
2 changes: 0 additions & 2 deletions isobus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ set(ISOBUS_INCLUDE_DIR "include/isobus/isobus")
# Set source files
set(ISOBUS_SRC
"can_NAME.cpp"
"can_protocol.cpp"
"can_identifier.cpp"
"can_control_function.cpp"
"can_message.cpp"
Expand Down Expand Up @@ -53,7 +52,6 @@ prepend(ISOBUS_SRC ${ISOBUS_SRC_DIR} ${ISOBUS_SRC})
# Set the include files
set(ISOBUS_INCLUDE
"can_NAME.hpp"
"can_protocol.hpp"
"can_badge.hpp"
"can_identifier.hpp"
"can_control_function.hpp"
Expand Down
23 changes: 5 additions & 18 deletions isobus/include/isobus/isobus/can_callbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ namespace isobus
std::uint32_t repetitionRate,
void *parentPointer);

//================================================================================================
/// @class ParameterGroupNumberCallbackData
///
/// @brief A storage class to hold data about PGN callbacks.
//================================================================================================
/// @brief A storage class to hold data about callbacks for a specific PGN
class ParameterGroupNumberCallbackData
{
public:
Expand All @@ -87,20 +83,11 @@ namespace isobus
/// @param[in] internalControlFunction An internal control function to use as an additional filter for the callback
ParameterGroupNumberCallbackData(std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parentPointer, std::shared_ptr<InternalControlFunction> internalControlFunction);

/// @brief A copy constructor for holding callback data
/// @param[in] oldObj The object to copy from
ParameterGroupNumberCallbackData(const ParameterGroupNumberCallbackData &oldObj);

/// @brief Equality operator for this class
/// @param[in] obj The object to check equality against
/// @returns true if the objects have equivalent data
bool operator==(const ParameterGroupNumberCallbackData &obj) const;

/// @brief Assignment operator for this class
/// @param[in] obj The object to assign data from
/// @returns The lhs of the operator
ParameterGroupNumberCallbackData &operator=(const ParameterGroupNumberCallbackData &obj);

/// @brief Returns the PGN associated with this callback data
/// @returns The PGN associated with this callback data
std::uint32_t get_parameter_group_number() const;
Expand All @@ -118,10 +105,10 @@ namespace isobus
std::shared_ptr<InternalControlFunction> get_internal_control_function() const;

private:
CANLibCallback mCallback; ///< The callback that will get called when a matching PGN is received
std::uint32_t mParameterGroupNumber; ///< The PGN assocuiated with this callback
void *mParent; ///< A generic variable that can provide context to which object the callback was meant for
std::shared_ptr<InternalControlFunction> mInternalControlFunctionFilter; ///< An optional way to filter callbacks based on the destination of messages from the partner
CANLibCallback callback; ///< The callback that will get called when a matching PGN is received
std::uint32_t parameterGroupNumber; ///< The PGN assocuiated with this callback
void *parent; ///< A generic variable that can provide context to which object the callback was meant for
std::shared_ptr<InternalControlFunction> internalControlFunctionFilter; ///< An optional way to filter callbacks based on the destination of messages from the partner
};
} // namespace isobus

Expand Down
8 changes: 3 additions & 5 deletions isobus/include/isobus/isobus/can_network_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ namespace isobus

/// @brief Returns the class instance of the NMEA2k fast packet protocol.
/// Use this to register for FP multipacket messages
/// @param[in] canPortIndex The CAN channel index to get the fast packet protocol for
/// @returns The class instance of the NMEA2k fast packet protocol.
FastPacketProtocol &get_fast_packet_protocol();
std::unique_ptr<FastPacketProtocol> &get_fast_packet_protocol(std::uint8_t canPortIndex);

/// @brief Returns the configuration of this network manager
/// @returns The configuration class for this network manager
Expand All @@ -207,7 +208,6 @@ namespace isobus
friend class DiagnosticProtocol; ///< Allows the diagnostic protocol to access the protected functions on the network manager
friend class ParameterGroupNumberRequestProtocol; ///< Allows the PGN request protocol to access the network manager protected functions
friend class FastPacketProtocol; ///< Allows the FP protocol to access the network manager protected functions
friend class CANLibProtocol; ///< Allows the CANLib protocol base class functions to access the network manager protected functions

/// @brief Adds a PGN callback for a protocol class
/// @param[in] parameterGroupNumber The PGN to register for
Expand Down Expand Up @@ -245,8 +245,6 @@ namespace isobus
/// @param[in] message The completed protocol message
void protocol_message_callback(const CANMessage &message);

std::vector<CANLibProtocol *> protocolList; ///< A list of all created protocol classes

private:
/// @brief Constructor for the network manager. Sets default values for members
CANNetworkManager();
Expand Down Expand Up @@ -380,7 +378,7 @@ namespace isobus
CANNetworkConfiguration configuration; ///< The configuration for this network manager
std::array<std::unique_ptr<TransportProtocolManager>, CAN_PORT_MAXIMUM> transportProtocols; ///< One instance of the transport protocol manager for each channel
std::array<std::unique_ptr<ExtendedTransportProtocolManager>, CAN_PORT_MAXIMUM> extendedTransportProtocols; ///< One instance of the extended transport protocol manager for each channel
FastPacketProtocol fastPacketProtocol; ///< Instance of the fast packet protocol
std::array<std::unique_ptr<FastPacketProtocol>, CAN_PORT_MAXIMUM> fastPacketProtocol; ///< One instance of the fast packet protocol for each channel

std::array<std::deque<std::uint32_t>, CAN_PORT_MAXIMUM> busloadMessageBitsHistory; ///< Stores the approximate number of bits processed on each channel over multiple previous time windows
std::array<std::uint32_t, CAN_PORT_MAXIMUM> currentBusloadBitAccumulator; ///< Accumulates the approximate number of bits processed on each channel during the current time window
Expand Down
95 changes: 0 additions & 95 deletions isobus/include/isobus/isobus/can_protocol.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion isobus/include/isobus/isobus/can_transport_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ namespace isobus
/// @param[in] message The CAN message to be processed.
void process_data_transfer_message(const CANMessage &message);

/// @brief Gets a TP session from the passed in source and destination and PGN combination
/// @brief Gets a TP session from the passed in source and destination combination
/// @param[in] source The source control function for the session
/// @param[in] destination The destination control function for the session
/// @returns a matching session, or nullptr if no session matched the supplied parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#define ISOBUS_DIAGNOSTIC_PROTOCOL_HPP

#include "isobus/isobus/can_internal_control_function.hpp"
#include "isobus/isobus/can_protocol.hpp"
#include "isobus/isobus/isobus_functionalities.hpp"
#include "isobus/utility/processing_flags.hpp"

Expand Down
1 change: 0 additions & 1 deletion isobus/include/isobus/isobus/isobus_functionalities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include "isobus/isobus/can_internal_control_function.hpp"
#include "isobus/isobus/can_parameter_group_number_request_protocol.hpp"
#include "isobus/isobus/can_protocol.hpp"
#include "isobus/utility/processing_flags.hpp"
#include "isobus/utility/thread_synchronization.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "isobus/isobus/can_NAME.hpp"
#include "isobus/isobus/can_internal_control_function.hpp"
#include "isobus/isobus/can_message.hpp"
#include "isobus/isobus/can_protocol.hpp"
#include "isobus/utility/event_dispatcher.hpp"
#include "isobus/utility/processing_flags.hpp"

Expand Down
Loading

0 comments on commit 53b69db

Please sign in to comment.