AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
can_message_data.hpp
Go to the documentation of this file.
1//================================================================================================
8//================================================================================================
9
10#ifndef CAN_MESSAGE_DATA_HPP
11#define CAN_MESSAGE_DATA_HPP
12
16#include "isobus/utility/data_span.hpp"
17
18#include <cstdint>
19#include <memory>
20#include <vector>
21
22namespace isobus
23{
26 {
27 public:
29 virtual ~CANMessageData() = default;
30
33 virtual std::size_t size() const = 0;
34
38 virtual std::uint8_t get_byte(std::size_t index) = 0;
39
43 virtual std::unique_ptr<CANMessageData> copy_if_not_owned(std::unique_ptr<CANMessageData> self) const = 0;
44 };
45
48 , public std::vector<std::uint8_t>
49 {
50 public:
53 explicit CANMessageDataVector(std::size_t size);
54
57 explicit CANMessageDataVector(const std::vector<std::uint8_t> &data);
58
62 CANMessageDataVector(const std::uint8_t *data, std::size_t size);
63
66 std::size_t size() const override;
67
71 std::uint8_t get_byte(std::size_t index) override;
72
76 void set_byte(std::size_t index, std::uint8_t value);
77
80 CANDataSpan data() const;
81
85 std::unique_ptr<CANMessageData> copy_if_not_owned(std::unique_ptr<CANMessageData> self) const override;
86 };
87
91 , public CANDataSpan
92 {
93 public:
97 CANMessageDataView(const std::uint8_t *ptr, std::size_t len);
98
101 std::size_t size() const override;
102
106 std::uint8_t get_byte(std::size_t index) override;
107
110 CANDataSpan data() const;
111
115 std::unique_ptr<CANMessageData> copy_if_not_owned(std::unique_ptr<CANMessageData> self) const override;
116 };
117
120 {
121 public:
127 CANMessageDataCallback(std::size_t size,
129 void *parentPointer = nullptr,
130 std::size_t chunkSize = 7);
131
134 std::size_t size() const override;
135
139 std::uint8_t get_byte(std::size_t index) override;
140
144 std::unique_ptr<CANMessageData> copy_if_not_owned(std::unique_ptr<CANMessageData> self) const override;
145
146 private:
147 std::size_t totalSize;
150 std::vector<std::uint8_t> buffer;
151 std::size_t bufferSize;
152 std::size_t dataOffset = 0;
153 bool initialized = false;
154 };
155} // namespace isobus
156
157#endif // CAN_MESSAGE_DATA_HPP
An object to represent common callbacks used within this CAN stack.
Defines a base class to represent a generic ISOBUS control function.
An abstraction of a CAN message, could be > 8 data bytes.
A class that represents data of a CAN message by using a callback function.
std::size_t dataOffset
The offset of the data in the buffer.
bool initialized
Whether the buffer has been initialized.
std::size_t bufferSize
The size of the buffer.
std::size_t size() const override
Get the size of the data.
CANMessageDataCallback(std::size_t size, DataChunkCallback callback, void *parentPointer=nullptr, std::size_t chunkSize=7)
Constructor for transport data that uses a callback function.
std::uint8_t get_byte(std::size_t index) override
Get the byte at the given index.
std::vector< std::uint8_t > buffer
The buffer to store the data chunks.
DataChunkCallback callback
The callback function to be called for each data chunk.
std::size_t totalSize
The total size of the data.
void * parentPointer
The parent object that gets passed to the callback function.
std::unique_ptr< CANMessageData > copy_if_not_owned(std::unique_ptr< CANMessageData > self) const override
If the data isn't owned by this class, make a copy of the data.
A class that represents data of a CAN message by holding a vector of bytes.
CANMessageDataVector(std::size_t size)
Construct a new CANMessageDataVector object.
std::size_t size() const override
Get the size of the data.
std::unique_ptr< CANMessageData > copy_if_not_owned(std::unique_ptr< CANMessageData > self) const override
If the data isn't owned by this class, make a copy of the data.
CANDataSpan data() const
Get the data span.
void set_byte(std::size_t index, std::uint8_t value)
Set the byte at the given index.
std::uint8_t get_byte(std::size_t index) override
Get the byte at the given index.
A class that represents data of a CAN message by holding a view of an array of bytes....
CANMessageDataView(const std::uint8_t *ptr, std::size_t len)
Construct a new CANMessageDataView object.
std::uint8_t get_byte(std::size_t index) override
Get the byte at the given index.
std::unique_ptr< CANMessageData > copy_if_not_owned(std::unique_ptr< CANMessageData > self) const override
If the data isn't owned by this class, make a copy of the data.
CANDataSpan data() const
Get the data span.
std::size_t size() const override
Get the size of the data.
A interface class that represents data payload of a CAN message of arbitrary length.
virtual std::unique_ptr< CANMessageData > copy_if_not_owned(std::unique_ptr< CANMessageData > self) const =0
If the data isn't owned by this class, make a copy of the data.
virtual ~CANMessageData()=default
Default destructor.
virtual std::uint8_t get_byte(std::size_t index)=0
Get the byte at the given index.
virtual std::size_t size() const =0
Get the size of the 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 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.