11#ifndef CAN_MESSAGE_HPP
12#define CAN_MESSAGE_HPP
17#include "isobus/utility/data_span.hpp"
64 const std::uint8_t *dataBuffer,
66 std::shared_ptr<ControlFunction>
source,
68 std::uint8_t CANPort);
79 std::vector<std::uint8_t>
data,
80 std::shared_ptr<ControlFunction>
source,
82 std::uint8_t CANPort);
94 const std::vector<std::uint8_t> &
get_data()
const;
127 bool is_destination(std::shared_ptr<ControlFunction> controlFunction)
const;
132 bool is_source(std::shared_ptr<ControlFunction> controlFunction)
const;
150 void set_data(
const std::uint8_t *dataBuffer, std::uint32_t length);
155 void set_data(std::uint8_t dataByte,
const std::uint32_t insertPosition);
170 std::uint8_t
get_uint8_at(
const std::uint32_t index)
const;
177 std::int8_t
get_int8_at(
const std::uint32_t index)
const;
185 std::uint16_t
get_uint16_at(
const std::uint32_t index,
const ByteFormat format = ByteFormat::LittleEndian)
const;
193 std::int16_t
get_int16_at(
const std::uint32_t index,
const ByteFormat format = ByteFormat::LittleEndian)
const;
201 std::uint32_t
get_uint24_at(
const std::uint32_t index,
const ByteFormat format = ByteFormat::LittleEndian)
const;
209 std::int32_t
get_int24_at(
const std::uint32_t index,
const ByteFormat format = ByteFormat::LittleEndian)
const;
217 std::uint32_t
get_uint32_at(
const std::uint32_t index,
const ByteFormat format = ByteFormat::LittleEndian)
const;
225 std::int32_t
get_int32_at(
const std::uint32_t index,
const ByteFormat format = ByteFormat::LittleEndian)
const;
233 std::uint64_t
get_uint64_at(
const std::uint32_t index,
const ByteFormat format = ByteFormat::LittleEndian)
const;
241 std::int64_t
get_int64_at(
const std::uint32_t index,
const ByteFormat format = ByteFormat::LittleEndian)
const;
249 bool get_bool_at(
const std::uint32_t byteIndex,
const std::uint8_t bitIndex,
const std::uint8_t length = 1)
const;
259 std::uint64_t
get_data_custom_length(
const std::uint32_t startBitIndex,
const std::uint32_t length,
const ByteFormat format = ByteFormat::LittleEndian)
const;
264 std::vector<std::uint8_t>
data;
Defines a base class to represent a generic ISOBUS control function.
Defines some PGNs that are used in the library or are very common.
A representation of a classical CAN identifier with utility functions for ectracting values that are ...
A utility class that allows easy interpretation of a 32 bit CAN identifier.
A class that represents a generic CAN message of arbitrary length.
std::int16_t get_int16_at(const std::uint32_t index, const ByteFormat format=ByteFormat::LittleEndian) const
Get a 16-bit signed integer from the buffer at a specific index. A 16-bit signed integer can hold a v...
bool is_source(std::shared_ptr< ControlFunction > controlFunction) const
Returns whether the message is originated from the control function.
static const std::uint32_t ABSOLUTE_MAX_MESSAGE_LENGTH
ISO11783-3 defines this: The maximum number of packets that can be sent in a single connection with e...
std::shared_ptr< ControlFunction > source
The source control function of the message.
Type
The internal message type.
@ Receive
Message is being received.
@ Transmit
Message is to be transmitted from the stack.
bool is_destination(std::shared_ptr< ControlFunction > controlFunction) const
Returns whether the message is destined for the control function.
bool has_valid_destination_control_function() const
Returns whether the message is sent to a specific device on the bus.
std::int32_t get_int24_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 int32_t) at a specific index....
Type messageType
The internal message type associated with the message.
Type get_type() const
Returns the CAN message type.
static CANMessage create_invalid_message()
Factory method to construct an intentionally invalid CANMessage.
ByteFormat
The different byte formats that can be used when reading bytes from the buffer.
void set_data(const std::uint8_t *dataBuffer, std::uint32_t length)
Sets the message data to the value supplied. Creates a copy.
std::uint8_t get_can_port_index() const
Returns the CAN channel index associated with the message.
const std::vector< std::uint8_t > & get_data() const
Gets a reference to the data in the CAN message.
std::uint32_t get_data_length() const
Returns the length of the data in the CAN message.
bool has_valid_source_control_function() const
Returns whether the message is sent by a device that claimed its address on the bus.
void set_data_size(std::uint32_t length)
Sets the size of the data payload.
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::uint64_t get_data_custom_length(const std::uint32_t startBitIndex, const std::uint32_t length, const ByteFormat format=ByteFormat::LittleEndian) const
Get a 64-bit unsinged integer from the buffer at a specific index but custom length Why 64 bit?...
CANIdentifier identifier
The CAN ID of the message.
std::shared_ptr< ControlFunction > get_source_control_function() const
Gets the source control function that the message is from.
std::uint8_t get_uint8_at(const std::uint32_t index) const
Get a 8-bit unsigned byte from the buffer at a specific index. A 8-bit unsigned byte can hold a value...
std::shared_ptr< ControlFunction > destination
The destination control function of the message.
bool is_parameter_group_number(CANLibParameterGroupNumber parameterGroupNumber) const
Compares the identifier of the message to the parameter group number (PGN) supplied.
std::vector< std::uint8_t > data
A data buffer for the message, used when not using data chunk callbacks.
void set_identifier(const CANIdentifier &value)
Sets the CAN ID of the message.
std::int32_t get_int32_at(const std::uint32_t index, const ByteFormat format=ByteFormat::LittleEndian) const
Get a 32-bit signed integer from the buffer at a specific index. A 32-bit signed integer can hold a v...
std::int8_t get_int8_at(const std::uint32_t index) const
Get a 8-bit signed byte from the buffer at a specific index. A 8-bit signed byte can hold a value bet...
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::int64_t get_int64_at(const std::uint32_t index, const ByteFormat format=ByteFormat::LittleEndian) const
Get a 64-bit signed integer from the buffer at a specific index. A 64-bit signed integer can hold a v...
std::uint8_t CANPortIndex
The CAN channel index associated with the message.
bool get_bool_at(const std::uint32_t byteIndex, const std::uint8_t bitIndex, const std::uint8_t length=1) const
Get a bit-boolean from the buffer at a specific index.
std::uint32_t get_uint32_at(const std::uint32_t index, const ByteFormat format=ByteFormat::LittleEndian) const
Get a 32-bit unsigned integer from the buffer at a specific index. A 32-bit unsigned integer can hold...
CANMessage(Type type, CANIdentifier identifier, const std::uint8_t *dataBuffer, std::uint32_t length, std::shared_ptr< ControlFunction > source, std::shared_ptr< ControlFunction > destination, std::uint8_t CANPort)
Construct a CAN message from the parameters supplied.
std::shared_ptr< ControlFunction > get_destination_control_function() const
Gets the destination control function that the message is to.
bool is_broadcast() const
Returns whether the message is sent as a broadcast message / to all devices on the bus.
bool is_destination_our_device() const
Returns whether the message is destined for our device on the bus.
std::uint64_t get_uint64_at(const std::uint32_t index, const ByteFormat format=ByteFormat::LittleEndian) const
Get a 64-bit unsigned integer from the buffer at a specific index. A 64-bit unsigned integer can hold...
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...
CANLibParameterGroupNumber
PGNs commonly used by the CAN stack.
DataSpan< const std::uint8_t > CANDataSpan
A read-only span of data for a CAN message.