AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
can_transport_protocol_base.hpp
Go to the documentation of this file.
1//================================================================================================
8//================================================================================================
9
10#ifndef CAN_TRANSPORT_PROTOCOL_BASE_HPP
11#define CAN_TRANSPORT_PROTOCOL_BASE_HPP
12
16
17namespace isobus
18{
21 {
22 public:
24 enum class Direction
25 {
26 Transmit,
27 Receive
28 };
29
40 std::unique_ptr<CANMessageData> data,
41 std::uint32_t parameterGroupNumber,
42 std::uint32_t totalMessageSize,
43 std::shared_ptr<ControlFunction> source,
44 std::shared_ptr<ControlFunction> destination,
46 void *parentPointer);
47
51
56
58 virtual ~TransportProtocolSessionBase() = default;
59
63
70 bool operator==(const TransportProtocolSessionBase &obj) const;
71
76 bool matches(std::shared_ptr<ControlFunction> other_source, std::shared_ptr<ControlFunction> other_destination) const;
77
80 CANMessageData &get_data() const;
81
84 std::uint32_t get_message_length() const;
85
88 virtual std::uint32_t get_total_bytes_transferred() const = 0;
89
93
96 std::shared_ptr<ControlFunction> get_source() const;
97
100 std::shared_ptr<ControlFunction> get_destination() const;
101
104 std::uint32_t get_parameter_group_number() const;
105
106 protected:
108 void update_timestamp();
109
112 std::uint32_t get_time_since_last_update() const;
113
116 void complete(bool success) const;
117
118 private:
120 std::uint32_t parameterGroupNumber;
121 std::unique_ptr<CANMessageData> data;
122 std::shared_ptr<ControlFunction> source;
123 std::shared_ptr<ControlFunction> destination;
124 std::uint32_t timestamp_ms = 0;
125
126 std::uint32_t totalMessageSize;
127
129 void *parent = nullptr;
130 };
131} // namespace isobus
132
133#endif // CAN_TRANSPORT_PROTOCOL_BASE_HPP
Defines a base class to represent a generic ISOBUS control function.
An abstraction of a CAN message, could be > 8 data bytes.
An interface class that represents data payload of a CAN message of arbitrary length.
A interface class that represents data payload of a CAN message of arbitrary length.
An object to keep track of session information internally.
std::shared_ptr< ControlFunction > destination
The destination control function.
std::uint32_t get_time_since_last_update() const
Get the time that has passed since the last update of the timestamp.
std::uint32_t get_message_length() const
Get the total number of bytes that will be sent or received in this session.
std::shared_ptr< ControlFunction > get_destination() const
Get the control function that is receiving the message.
bool operator==(const TransportProtocolSessionBase &obj) const
A useful way to compare session objects to each other for equality,.
CANMessageData & get_data() const
Get the data buffer for the session.
TransportProtocolSessionBase & operator=(TransportProtocolSessionBase &&other)=default
The move assignment operator.
Direction get_direction() const
Get the direction of the session.
std::uint32_t get_parameter_group_number() const
Get the parameter group number of the message.
Direction direction
The direction of the session.
bool matches(std::shared_ptr< ControlFunction > other_source, std::shared_ptr< ControlFunction > other_destination) const
Checks if the source and destination control functions match the given control functions.
std::shared_ptr< ControlFunction > get_source() const
Get the control function that is sending the message.
Direction
Enumerates the possible session directions.
@ Transmit
We are transmitting a message.
std::shared_ptr< ControlFunction > source
The source control function.
virtual std::uint32_t get_total_bytes_transferred() const =0
Get the number of bytes that have been sent or received in this session.
TransportProtocolSessionBase(TransportProtocolSessionBase::Direction direction, std::unique_ptr< CANMessageData > data, std::uint32_t parameterGroupNumber, std::uint32_t totalMessageSize, std::shared_ptr< ControlFunction > source, std::shared_ptr< ControlFunction > destination, TransmitCompleteCallback sessionCompleteCallback, void *parentPointer)
The constructor for a session.
TransmitCompleteCallback sessionCompleteCallback
A callback that is to be called when the session is completed.
std::uint32_t parameterGroupNumber
The PGN of the message.
std::uint32_t timestamp_ms
A timestamp used to track session timeouts.
std::uint32_t totalMessageSize
The total size of the message in bytes (the maximum size of a message is from ETP and can fit in an u...
void update_timestamp()
Update the timestamp of the session.
std::unique_ptr< CANMessageData > data
The data buffer for the message.
void * parent
A generic context variable that helps identify what object callbacks are destined for....
void complete(bool success) const
Complete the session.
float get_percentage_bytes_transferred() const
Get the percentage of bytes that have been sent or received in this session.
TransportProtocolSessionBase(TransportProtocolSessionBase &&other)=default
The move constructor.
virtual ~TransportProtocolSessionBase()=default
The destructor for a session.
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...
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.