14#include "isobus/utility/to_string.hpp"
23 myControlFunction(internalControlFunction)
25 assert(
nullptr !=
myControlFunction &&
"ParameterGroupNumberRequestProtocol::ParameterGroupNumberRequestProtocol() called with nullptr internalControlFunction");
38 std::array<std::uint8_t, PGN_REQUEST_LENGTH> buffer;
40 buffer[0] =
static_cast<std::uint8_t
>(pgn & 0xFF);
41 buffer[1] =
static_cast<std::uint8_t
>((pgn >> 8) & 0xFF);
42 buffer[2] =
static_cast<std::uint8_t
>((pgn >> 16) & 0xFF);
53 std::array<std::uint8_t, CAN_DATA_LENGTH> buffer;
55 buffer[0] =
static_cast<std::uint8_t
>(pgn & 0xFF);
56 buffer[1] =
static_cast<std::uint8_t
>((pgn >> 8) & 0xFF);
57 buffer[2] =
static_cast<std::uint8_t
>((pgn >> 16) & 0xFF);
58 buffer[3] =
static_cast<std::uint8_t
>(repetitionRate_ms & 0xFF);
59 buffer[4] =
static_cast<std::uint8_t
>((repetitionRate_ms >> 8) & 0xFF);
142 callbackFunction(callback),
143 pgn(parameterGroupNumber),
144 parent(parentPointer)
149 callbackFunction(callback),
150 pgn(parameterGroupNumber),
151 parent(parentPointer)
173 case static_cast<std::uint32_t
>(CANLibParameterGroupNumber::RequestForRepetitionRate):
183 if (((repetitionRateCallback.pgn == requestedPGN) ||
184 (
static_cast<std::uint32_t
>(isobus::CANLibParameterGroupNumber::Any) == repetitionRateCallback.pgn)) &&
199 LOG_WARNING(
"[PR]: Received a malformed or broadcast request for repetition rate message. The message will not be processed.");
204 case static_cast<std::uint32_t
>(CANLibParameterGroupNumber::ParameterGroupNumberRequest):
208 bool shouldAck =
false;
210 bool anyCallbackProcessed =
false;
217 if (((pgnRequestCallback.pgn == requestedPGN) ||
218 (
static_cast<std::uint32_t
>(isobus::CANLibParameterGroupNumber::Any) == pgnRequestCallback.pgn)) &&
219 (pgnRequestCallback.callbackFunction(requestedPGN, message.
get_source_control_function(), shouldAck, ackType, pgnRequestCallback.parent)))
222 anyCallbackProcessed =
true;
243 LOG_WARNING(
"[PR]: NACK-ing PGN request for PGN " +
244 isobus::to_string(requestedPGN) +
245 " because no callback could handle it.");
250 LOG_WARNING(
"[PR]: Received a malformed PGN request message. The message will not be processed.");
263 if (
nullptr != parent)
273 if (
nullptr != destination)
275 std::array<std::uint8_t, CAN_DATA_LENGTH> buffer;
277 buffer[0] =
static_cast<std::uint8_t
>(type);
281 buffer[4] = destination->get_address();
282 buffer[5] =
static_cast<std::uint8_t
>(parameterGroupNumber & 0xFF);
283 buffer[6] =
static_cast<std::uint8_t
>((parameterGroupNumber >> 8) & 0xFF);
284 buffer[7] =
static_cast<std::uint8_t
>((parameterGroupNumber >> 16) & 0xFF);
Defines some PGNs that are used in the library or are very common.
A protocol that handles PGN requests.
A class that acts as a logging sink. The intent is that someone could make their own derived class of...
This is a way to protect functions on public interfaces from being accessed by objects that shouldn't...
std::uint32_t get_parameter_group_number() const
Returns the PGN encoded in the identifier.
std::uint8_t get_destination_address() const
Returns the destination address of the frame encoded in the identifier.
A class that represents a generic CAN message of arbitrary length.
std::uint32_t get_data_length() const
Returns the length of the data in the CAN message.
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::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.
static CANNetworkManager CANNetwork
Static singleton of the one network manager. Use this to access stack functionality.
bool remove_protocol_parameter_group_number_callback(std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parentPointer)
Removes a PGN callback for a protocol class.
bool add_protocol_parameter_group_number_callback(std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parentPointer)
Adds a PGN callback for a protocol class.
bool send_can_message(std::uint32_t parameterGroupNumber, const std::uint8_t *dataBuffer, std::uint32_t dataLength, std::shared_ptr< InternalControlFunction > sourceControlFunction, std::shared_ptr< ControlFunction > destinationControlFunction=nullptr, CANIdentifier::CANPriority priority=CANIdentifier::CANPriority::PriorityDefault6, TransmitCompleteCallback txCompleteCallback=nullptr, void *parentPointer=nullptr, DataChunkCallback frameChunkCallback=nullptr)
This is the main way to send a CAN message of any length.
A storage class for holding PGN callbacks and their associated PGN.
PGNRequestCallbackInfo(PGNRequestCallback callback, std::uint32_t parameterGroupNumber, void *parentPointer)
Constructor for PGNRequestCallbackInfo.
std::uint32_t pgn
The PGN associated with the callback.
PGNRequestCallback callbackFunction
The actual callback.
bool operator==(const PGNRequestCallbackInfo &obj) const
A utility function for determining if the data in the object is equal to another object.
void * parent
Pointer to the class that registered the callback, or nullptr
A storage class for holding PGN callbacks and their associated PGN.
std::uint32_t pgn
The PGN associated with the callback.
PGNRequestForRepetitionRateCallback callbackFunction
The actual callback.
bool operator==(const PGNRequestForRepetitionRateCallbackInfo &obj) const
A utility function for determining if the data in the object is equal to another object.
void * parent
Pointer to the class that registered the callback, or nullptr
PGNRequestForRepetitionRateCallbackInfo(PGNRequestForRepetitionRateCallback callback, std::uint32_t parameterGroupNumber, void *parentPointer)
Constructor for PGNRequestCallbackInfo.
A protocol that handles PGN requests.
std::shared_ptr< InternalControlFunction > myControlFunction
The internal control function that this protocol will send from.
Mutex pgnRequestMutex
A mutex to protect the callback lists.
std::vector< PGNRequestCallbackInfo > pgnRequestCallbacks
A list of all registered PGN callbacks and the PGN associated with each callback.
bool remove_pgn_request_callback(std::uint32_t pgn, PGNRequestCallback callback, void *parentPointer)
Removes a previously registered PGN request callback.
void process_message(const CANMessage &message)
A generic way for a protocol to process a received message.
static constexpr std::uint8_t PGN_REQUEST_LENGTH
The CAN data length of a PGN request.
bool register_pgn_request_callback(std::uint32_t pgn, PGNRequestCallback callback, void *parentPointer)
Registers for a callback on receipt of a PGN request.
bool remove_request_for_repetition_rate_callback(std::uint32_t pgn, PGNRequestForRepetitionRateCallback callback, void *parentPointer)
Removes a callback for repetition rate requests.
bool register_request_for_repetition_rate_callback(std::uint32_t pgn, PGNRequestForRepetitionRateCallback callback, void *parentPointer)
Registers for a callback on receipt of a request for repetition rate.
ParameterGroupNumberRequestProtocol(std::shared_ptr< InternalControlFunction > internalControlFunction, CANLibBadge< InternalControlFunction >)
The constructor for this protocol.
std::vector< PGNRequestForRepetitionRateCallbackInfo > repetitionRateCallbacks
A list of all registered request for repetition rate callbacks and the PGN associated with the callba...
~ParameterGroupNumberRequestProtocol()
The destructor for this protocol.
std::size_t get_number_registered_pgn_request_callbacks() const
Returns the number of PGN request callbacks that have been registered with this protocol instance.
static bool request_repetition_rate(std::uint32_t pgn, std::uint16_t repetitionRate_ms, std::shared_ptr< InternalControlFunction > source, std::shared_ptr< ControlFunction > destination)
Sends a PGN request for repetition rate.
std::size_t get_number_registered_request_for_repetition_rate_callbacks() const
Returns the number of PGN request for repetition rate callbacks that have been registered with this p...
static bool request_parameter_group_number(std::uint32_t pgn, std::shared_ptr< InternalControlFunction > source, std::shared_ptr< ControlFunction > destination)
Sends a PGN request to the specified control function.
bool send_acknowledgement(AcknowledgementType type, std::uint32_t parameterGroupNumber, std::shared_ptr< ControlFunction > destination) const
Sends a message using the acknowledgement PGN.
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...
bool(*)(std::uint32_t parameterGroupNumber, std::shared_ptr< ControlFunction > requestingControlFunction, std::shared_ptr< ControlFunction > targetControlFunction, std::uint32_t repetitionRate, void *parentPointer) PGNRequestForRepetitionRateCallback
A callback for handling a request for repetition rate for a specific PGN.
constexpr std::uint8_t CAN_DATA_LENGTH
The length of a classical CAN frame.
constexpr std::uint8_t BROADCAST_CAN_ADDRESS
The global/broadcast CAN address.
bool(*)(std::uint32_t parameterGroupNumber, std::shared_ptr< ControlFunction > requestingControlFunction, bool &acknowledge, AcknowledgementType &acknowledgeType, void *parentPointer) PGNRequestCallback
A callback for handling a PGN request.
AcknowledgementType
The types of acknowledgement that can be sent in the Ack PGN.
@ Negative
"NACK" Indicates the request was not completed or we do not support the PGN