AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
can_callbacks.hpp
Go to the documentation of this file.
1//================================================================================================
8//================================================================================================
9
10#ifndef CAN_CALLBACKS_HPP
11#define CAN_CALLBACKS_HPP
12
13#include <functional>
15
16namespace isobus
17{
18 // Forward declare some classes
19 class InternalControlFunction;
20 class ControlFunction;
21
23 enum class AcknowledgementType : std::uint8_t
24 {
25 Positive = 0,
26 Negative = 1,
27 AccessDenied = 2,
28 CannotRespond = 3
29 };
30
33 {
34 Offline,
35 Online
36 };
37
39 using CANLibCallback = void (*)(const CANMessage &message, void *parentPointer);
41 using CANMessageCallback = std::function<void(const CANMessage &message)>;
43 using CANMessageFrameCallback = std::function<bool(std::uint32_t parameterGroupNumber,
44 CANDataSpan data,
45 std::shared_ptr<InternalControlFunction> sourceControlFunction,
46 std::shared_ptr<ControlFunction> destinationControlFunction,
49 using ControlFunctionStateCallback = void (*)(std::shared_ptr<ControlFunction> controlFunction, ControlFunctionState state);
51 using DataChunkCallback = bool (*)(std::uint32_t callbackIndex,
52 std::uint32_t bytesOffset,
53 std::uint32_t numberOfBytesNeeded,
54 std::uint8_t *chunkBuffer,
55 void *parentPointer);
57 using TransmitCompleteCallback = void (*)(std::uint32_t parameterGroupNumber,
58 std::uint32_t dataLength,
59 std::shared_ptr<InternalControlFunction> sourceControlFunction,
60 std::shared_ptr<ControlFunction> destinationControlFunction,
61 bool successful,
62 void *parentPointer);
64 using PGNRequestCallback = bool (*)(std::uint32_t parameterGroupNumber,
65 std::shared_ptr<ControlFunction> requestingControlFunction,
66 bool &acknowledge,
67 AcknowledgementType &acknowledgeType,
68 void *parentPointer);
70 using PGNRequestForRepetitionRateCallback = bool (*)(std::uint32_t parameterGroupNumber,
71 std::shared_ptr<ControlFunction> requestingControlFunction,
72 std::shared_ptr<ControlFunction> targetControlFunction,
73 std::uint32_t repetitionRate,
74 void *parentPointer);
75
78 {
79 public:
85 ParameterGroupNumberCallbackData(std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parentPointer, std::shared_ptr<InternalControlFunction> internalControlFunction);
86
90 bool operator==(const ParameterGroupNumberCallbackData &obj) const;
91
94 std::uint32_t get_parameter_group_number() const;
95
99
102 void *get_parent() const;
103
106 std::shared_ptr<InternalControlFunction> get_internal_control_function() const;
107
108 private:
110 std::uint32_t parameterGroupNumber;
111 void *parent;
112 std::shared_ptr<InternalControlFunction> internalControlFunctionFilter;
113 };
114} // namespace isobus
115
116#endif // CAN_CALLBACKS_HPP
An abstraction of a CAN message, could be > 8 data bytes.
CANPriority
Defines all the CAN frame priorities that can be encoded in a frame ID.
A class that represents a generic CAN message of arbitrary length.
A storage class to hold data about callbacks for a specific PGN.
void * get_parent() const
Returns the parent pointer for this data object.
void * parent
A generic variable that can provide context to which object the callback was meant for.
CANLibCallback callback
The callback that will get called when a matching PGN is received.
std::shared_ptr< InternalControlFunction > get_internal_control_function() const
Returns the ICF being used as a filter for this callback.
CANLibCallback get_callback() const
Returns the callback pointer for this data object.
bool operator==(const ParameterGroupNumberCallbackData &obj) const
Equality operator for this class.
std::uint32_t parameterGroupNumber
The PGN assocuiated with this callback.
ParameterGroupNumberCallbackData(std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parentPointer, std::shared_ptr< InternalControlFunction > internalControlFunction)
A constructor for holding callback data.
std::shared_ptr< InternalControlFunction > internalControlFunctionFilter
An optional way to filter callbacks based on the destination of messages from the partner.
std::uint32_t get_parameter_group_number() const
Returns the PGN associated with this callback data.
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...
DataSpan< const std::uint8_t > CANDataSpan
A read-only span of data for a CAN message.
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.
std::function< bool(std::uint32_t parameterGroupNumber, CANDataSpan data, std::shared_ptr< InternalControlFunction > sourceControlFunction, std::shared_ptr< ControlFunction > destinationControlFunction, CANIdentifier::CANPriority priority)> CANMessageFrameCallback
A callback for communicating CAN message frames.
void(*)(std::uint32_t parameterGroupNumber, std::uint32_t dataLength, std::shared_ptr< InternalControlFunction > sourceControlFunction, std::shared_ptr< ControlFunction > destinationControlFunction, bool successful, void *parentPointer) TransmitCompleteCallback
A callback for when a transmit is completed by the stack.
void(*)(const CANMessage &message, void *parentPointer) CANLibCallback
A callback for control functions to get CAN messages.
bool(*)(std::uint32_t parameterGroupNumber, std::shared_ptr< ControlFunction > requestingControlFunction, bool &acknowledge, AcknowledgementType &acknowledgeType, void *parentPointer) PGNRequestCallback
A callback for handling a PGN request.
bool(*)(std::uint32_t callbackIndex, std::uint32_t bytesOffset, std::uint32_t numberOfBytesNeeded, std::uint8_t *chunkBuffer, void *parentPointer) DataChunkCallback
A callback to get chunks of data for transfer by a protocol.
void(*)(std::shared_ptr< ControlFunction > controlFunction, ControlFunctionState state) ControlFunctionStateCallback
A callback that can inform you when a control function changes state between online and offline.
std::function< void(const CANMessage &message)> CANMessageCallback
A callback for communicating CAN messages.
AcknowledgementType
The types of acknowledgement that can be sent in the Ack PGN.
@ Positive
"ACK" Indicates that the request was completed
@ CannotRespond
Signals to the requestor that we are unable to accept the request for some reason.
@ AccessDenied
Signals to the requestor that their CF is not allowed to request this PGN.
@ Negative
"NACK" Indicates the request was not completed or we do not support the PGN
ControlFunctionState
Enumerates the "online" states of a control function.
@ Online
The CF's address claim state is valid.
@ Offline
The CF's address claim state is not valid.