AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
can_transport_protocol_base.cpp
1//================================================================================================
8//================================================================================================
9
12#include "isobus/utility/system_timing.hpp"
13
14namespace isobus
15{
17 std::unique_ptr<CANMessageData> data,
18 std::uint32_t parameterGroupNumber,
19 std::uint32_t totalMessageSize,
20 std::shared_ptr<ControlFunction> source,
21 std::shared_ptr<ControlFunction> destination,
22 TransmitCompleteCallback sessionCompleteCallback,
23 void *parentPointer) :
24 direction(direction),
25 parameterGroupNumber(parameterGroupNumber),
26 data(std::move(data)),
27 source(source),
28 destination(destination),
29 totalMessageSize(totalMessageSize),
30 sessionCompleteCallback(sessionCompleteCallback),
31 parent(parentPointer)
32 {
33 }
34
40 bool TransportProtocolSessionBase::matches(std::shared_ptr<ControlFunction> other_source, std::shared_ptr<ControlFunction> other_destination) const
41 {
42 return ((source == other_source) && (destination == other_destination));
43 }
44
49
54
56 {
57 return totalMessageSize;
58 }
59
60 std::shared_ptr<ControlFunction> TransportProtocolSessionBase::get_source() const
61 {
62 return source;
63 }
64
66 {
67 if (0 == get_message_length())
68 {
69 return 0.0f;
70 }
71 return static_cast<float>(get_total_bytes_transferred()) / static_cast<float>(get_message_length()) * 100.0f;
72 }
73
74 std::shared_ptr<ControlFunction> TransportProtocolSessionBase::get_destination() const
75 {
76 return destination;
77 }
78
83
85 {
86 timestamp_ms = SystemTiming::get_timestamp_ms();
87 }
88
90 {
91 return SystemTiming::get_time_elapsed_ms(timestamp_ms);
92 }
93
95 {
97 {
100 std::static_pointer_cast<InternalControlFunction>(source),
102 success,
103 parent);
104 }
105 }
106}
A representation of an ISOBUS ECU that we can send from. Use this class when defining your own contro...
Abstract base class for CAN transport protocols.
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.
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.
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.