AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
|
A class that represents a generic CAN message of arbitrary length. More...
#include <can_message.hpp>
Public Types | |
enum class | Type { Transmit , Receive } |
The internal message type. More... | |
enum class | ByteFormat { LittleEndian , BigEndian } |
The different byte formats that can be used when reading bytes from the buffer. More... | |
Public Member Functions | |
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. | |
CANMessage (Type type, CANIdentifier identifier, std::vector< std::uint8_t > data, std::shared_ptr< ControlFunction > source, std::shared_ptr< ControlFunction > destination, std::uint8_t CANPort) | |
Construct a CAN message from the parameters supplied. | |
Type | get_type () const |
Returns the CAN message type. | |
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. | |
std::shared_ptr< ControlFunction > | get_source_control_function () const |
Gets the source control function that the message is from. | |
bool | has_valid_source_control_function () const |
Returns whether the message is sent by a device that claimed its address on the bus. | |
std::shared_ptr< ControlFunction > | get_destination_control_function () const |
Gets the destination control function that the message is to. | |
bool | has_valid_destination_control_function () const |
Returns whether the message is sent to a specific device on the bus. | |
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. | |
bool | is_destination (std::shared_ptr< ControlFunction > controlFunction) const |
Returns whether the message is destined for the control function. | |
bool | is_source (std::shared_ptr< ControlFunction > controlFunction) const |
Returns whether the message is originated from the control function. | |
CANIdentifier | get_identifier () const |
Returns the identifier 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::uint8_t | get_can_port_index () const |
Returns the CAN channel index associated with the message. | |
void | set_data (const std::uint8_t *dataBuffer, std::uint32_t length) |
Sets the message data to the value supplied. Creates a copy. | |
void | set_data (std::uint8_t dataByte, const std::uint32_t insertPosition) |
Sets one byte of data in the message data payload. | |
void | set_data_size (std::uint32_t length) |
Sets the size of the data payload. | |
void | set_identifier (const CANIdentifier &value) |
Sets the CAN ID of the message. | |
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 between 0 and 255. | |
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 between -128 and 127. | |
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 a value between 0 and 65535. | |
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 value between -32768 and 32767. | |
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. A 24-bit number can hold a value between 0 and 16,777,215. | |
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. A 24-bit number can hold a value between -8388608 and 8388607. | |
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 a value between 0 and 4294967295. | |
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 value between -2147483648 and 2147483647. | |
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 a value between 0 and 18446744073709551615. | |
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 value between -9223372036854775808 and 9223372036854775807. | |
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::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? Because we do not know the length and it could be 10 bits or 54 so better to convert everything into 64 bit. | |
Static Public Member Functions | |
static CANMessage | create_invalid_message () |
Factory method to construct an intentionally invalid CANMessage. | |
Static Public Attributes | |
static const std::uint32_t | ABSOLUTE_MAX_MESSAGE_LENGTH = 117440505 |
ISO11783-3 defines this: The maximum number of packets that can be sent in a single connection with extended transport protocol is restricted by the extended data packet offset (3 bytes). This yields a maximum message size of (2^24-1 packets) x (7 bytes/packet) = 117440505 bytes. | |
Private Attributes | |
Type | messageType |
The internal message type associated with the message. | |
CANIdentifier | identifier |
The CAN ID of the message. | |
std::vector< std::uint8_t > | data |
A data buffer for the message, used when not using data chunk callbacks. | |
std::shared_ptr< ControlFunction > | source |
The source control function of the message. | |
std::shared_ptr< ControlFunction > | destination |
The destination control function of the message. | |
std::uint8_t | CANPortIndex |
The CAN channel index associated with the message. | |
A class that represents a generic CAN message of arbitrary length.
Definition at line 31 of file can_message.hpp.
|
strong |
The different byte formats that can be used when reading bytes from the buffer.
Definition at line 42 of file can_message.hpp.
|
strong |
The internal message type.
Enumerator | |
---|---|
Transmit | Message is to be transmitted from the stack. |
Receive | Message is being received. |
Definition at line 35 of file can_message.hpp.
isobus::CANMessage::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.
[in] | type | The type of the CAN message |
[in] | identifier | The CAN ID of the message |
[in] | dataBuffer | The start of the data payload |
[in] | length | The length of the data payload in bytes |
[in] | source | The source control function of the message |
[in] | destination | The destination control function of the message |
[in] | CANPort | The CAN channel index associated with the message |
Definition at line 17 of file can_message.cpp.
isobus::CANMessage::CANMessage | ( | Type | type, |
CANIdentifier | identifier, | ||
std::vector< std::uint8_t > | data, | ||
std::shared_ptr< ControlFunction > | source, | ||
std::shared_ptr< ControlFunction > | destination, | ||
std::uint8_t | CANPort ) |
Construct a CAN message from the parameters supplied.
[in] | type | The type of the CAN message |
[in] | identifier | The CAN ID of the message |
[in] | data | The data payload |
[in] | source | The source control function of the message |
[in] | destination | The destination control function of the message |
[in] | CANPort | The CAN channel index associated with the message |
Definition at line 33 of file can_message.cpp.
|
static |
Factory method to construct an intentionally invalid CANMessage.
Definition at line 48 of file can_message.cpp.
bool isobus::CANMessage::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.
This function will return whether the bit(s) at the specified index in the buffer is/are (all) equal to 1.
[in] | byteIndex | The byte index to start reading the boolean from |
[in] | bitIndex | The bit index to start reading the boolean from, ranging from 0 to 7 |
[in] | length | The number of bits to read, maximum of (8 - bitIndex) |
Definition at line 322 of file can_message.cpp.
std::uint8_t isobus::CANMessage::get_can_port_index | ( | ) | const |
Returns the CAN channel index associated with the message.
Definition at line 118 of file can_message.cpp.
const std::vector< std::uint8_t > & isobus::CANMessage::get_data | ( | ) | const |
Gets a reference to the data in the CAN message.
Definition at line 58 of file can_message.cpp.
std::uint64_t isobus::CANMessage::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? Because we do not know the length and it could be 10 bits or 54 so better to convert everything into 64 bit.
This function will return 8 bytes at a specified index in the buffer but custom bit length We are iterating by full bytes (assembling a full byte) and shifting it into the final 64-bit value to return
[in] | startBitIndex | The index to get the 64-bit unsigned integer from |
[in] | length | The length of bits to extract from the buffer |
[in] | format | The byte format to use when reading the integer |
Definition at line 329 of file can_message.cpp.
std::uint32_t isobus::CANMessage::get_data_length | ( | ) | const |
Returns the length of the data in the CAN message.
Definition at line 63 of file can_message.cpp.
std::shared_ptr< ControlFunction > isobus::CANMessage::get_destination_control_function | ( | ) | const |
Gets the destination control function that the message is to.
Definition at line 78 of file can_message.cpp.
CANIdentifier isobus::CANMessage::get_identifier | ( | ) | const |
Returns the identifier of the message.
Definition at line 108 of file can_message.cpp.
std::int16_t isobus::CANMessage::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 value between -32768 and 32767.
This function will return the 2 bytes at the specified index in the buffer.
[in] | index | The index to get the 16-bit signed integer from |
[in] | format | The byte format to use when reading the integer |
Definition at line 174 of file can_message.cpp.
std::int32_t isobus::CANMessage::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. A 24-bit number can hold a value between -8388608 and 8388607.
This function will return the 3 bytes at the specified index in the buffer.
[in] | index | The index to get the 24-bit signed integer from |
[in] | format | The byte format to use when reading the integer |
Definition at line 208 of file can_message.cpp.
std::int32_t isobus::CANMessage::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 value between -2147483648 and 2147483647.
This function will return the 4 bytes at the specified index in the buffer.
[in] | index | The index to get the 32-bit signed integer from |
[in] | format | The byte format to use when reading the integer |
Definition at line 246 of file can_message.cpp.
std::int64_t isobus::CANMessage::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 value between -9223372036854775808 and 9223372036854775807.
This function will return the 8 bytes at the specified index in the buffer.
[in] | index | The index to get the 64-bit signed integer from |
[in] | format | The byte format to use when reading the integer |
Definition at line 294 of file can_message.cpp.
std::int8_t isobus::CANMessage::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 between -128 and 127.
This function will return the byte at the specified index in the buffer.
[in] | index | The index to get the byte from |
Definition at line 153 of file can_message.cpp.
std::shared_ptr< ControlFunction > isobus::CANMessage::get_source_control_function | ( | ) | const |
Gets the source control function that the message is from.
Definition at line 68 of file can_message.cpp.
CANMessage::Type isobus::CANMessage::get_type | ( | ) | const |
Returns the CAN message type.
Definition at line 53 of file can_message.cpp.
std::uint16_t isobus::CANMessage::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 a value between 0 and 65535.
This function will return the 2 bytes at the specified index in the buffer.
[in] | index | The index to get the 16-bit unsigned integer from |
[in] | format | The byte format to use when reading the integer |
Definition at line 158 of file can_message.cpp.
std::uint32_t isobus::CANMessage::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. A 24-bit number can hold a value between 0 and 16,777,215.
This function will return the 3 bytes at the specified index in the buffer.
[in] | index | The index to get the 24-bit unsigned integer from |
[in] | format | The byte format to use when reading the integer |
Definition at line 190 of file can_message.cpp.
std::uint32_t isobus::CANMessage::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 a value between 0 and 4294967295.
This function will return the 4 bytes at the specified index in the buffer.
[in] | index | The index to get the 32-bit unsigned integer from |
[in] | format | The byte format to use when reading the integer |
Definition at line 226 of file can_message.cpp.
std::uint64_t isobus::CANMessage::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 a value between 0 and 18446744073709551615.
This function will return the 8 bytes at the specified index in the buffer.
[in] | index | The index to get the 64-bit unsigned integer from |
[in] | format | The byte format to use when reading the integer |
Definition at line 266 of file can_message.cpp.
std::uint8_t isobus::CANMessage::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 between 0 and 255.
This function will return the byte at the specified index in the buffer.
[in] | index | The index to get the byte from |
Definition at line 148 of file can_message.cpp.
bool isobus::CANMessage::has_valid_destination_control_function | ( | ) | const |
Returns whether the message is sent to a specific device on the bus.
Definition at line 83 of file can_message.cpp.
bool isobus::CANMessage::has_valid_source_control_function | ( | ) | const |
Returns whether the message is sent by a device that claimed its address on the bus.
Definition at line 73 of file can_message.cpp.
bool isobus::CANMessage::is_broadcast | ( | ) | const |
Returns whether the message is sent as a broadcast message / to all devices on the bus.
Definition at line 88 of file can_message.cpp.
bool isobus::CANMessage::is_destination | ( | std::shared_ptr< ControlFunction > | controlFunction | ) | const |
Returns whether the message is destined for the control function.
[in] | controlFunction | The control function to check |
Definition at line 98 of file can_message.cpp.
bool isobus::CANMessage::is_destination_our_device | ( | ) | const |
Returns whether the message is destined for our device on the bus.
Definition at line 93 of file can_message.cpp.
bool isobus::CANMessage::is_parameter_group_number | ( | CANLibParameterGroupNumber | parameterGroupNumber | ) | const |
Compares the identifier of the message to the parameter group number (PGN) supplied.
[in] | parameterGroupNumber | The parameter group number to compare to |
Definition at line 113 of file can_message.cpp.
bool isobus::CANMessage::is_source | ( | std::shared_ptr< ControlFunction > | controlFunction | ) | const |
Returns whether the message is originated from the control function.
[in] | controlFunction | The control function to check |
Definition at line 103 of file can_message.cpp.
void isobus::CANMessage::set_data | ( | const std::uint8_t * | dataBuffer, |
std::uint32_t | length ) |
Sets the message data to the value supplied. Creates a copy.
[in] | dataBuffer | The data payload |
[in] | length | the length of the data payload in bytes |
Definition at line 123 of file can_message.cpp.
void isobus::CANMessage::set_data | ( | std::uint8_t | dataByte, |
const std::uint32_t | insertPosition ) |
Sets one byte of data in the message data payload.
[in] | dataByte | One byte of data |
[in] | insertPosition | The position in the message at which to insert the data byte |
Definition at line 131 of file can_message.cpp.
void isobus::CANMessage::set_data_size | ( | std::uint32_t | length | ) |
Sets the size of the data payload.
[in] | length | The desired length of the data payload |
Definition at line 138 of file can_message.cpp.
void isobus::CANMessage::set_identifier | ( | const CANIdentifier & | value | ) |
Sets the CAN ID of the message.
[in] | value | The CAN ID for the message |
Definition at line 143 of file can_message.cpp.
|
static |
ISO11783-3 defines this: The maximum number of packets that can be sent in a single connection with extended transport protocol is restricted by the extended data packet offset (3 bytes). This yields a maximum message size of (2^24-1 packets) x (7 bytes/packet) = 117440505 bytes.
Definition at line 52 of file can_message.hpp.
|
private |
The CAN channel index associated with the message.
Definition at line 267 of file can_message.hpp.
|
private |
A data buffer for the message, used when not using data chunk callbacks.
Definition at line 264 of file can_message.hpp.
|
private |
The destination control function of the message.
Definition at line 266 of file can_message.hpp.
|
private |
The CAN ID of the message.
Definition at line 263 of file can_message.hpp.
|
private |
The internal message type associated with the message.
Definition at line 262 of file can_message.hpp.
|
private |
The source control function of the message.
Definition at line 265 of file can_message.hpp.