AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | List of all members
isobus::CANMessage Class Reference

A class that represents a generic CAN message of arbitrary length. More...

#include <can_message.hpp>

Collaboration diagram for isobus::CANMessage:
[legend]

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< ControlFunctionget_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< ControlFunctionget_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< ControlFunctionsource
 The source control function of the message.
 
std::shared_ptr< ControlFunctiondestination
 The destination control function of the message.
 
std::uint8_t CANPortIndex
 The CAN channel index associated with the message.
 

Detailed Description

A class that represents a generic CAN message of arbitrary length.

Definition at line 31 of file can_message.hpp.

Member Enumeration Documentation

◆ ByteFormat

enum class isobus::CANMessage::ByteFormat
strong

The different byte formats that can be used when reading bytes from the buffer.

Definition at line 42 of file can_message.hpp.

◆ Type

enum class isobus::CANMessage::Type
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.

Constructor & Destructor Documentation

◆ CANMessage() [1/2]

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.

Parameters
[in]typeThe type of the CAN message
[in]identifierThe CAN ID of the message
[in]dataBufferThe start of the data payload
[in]lengthThe length of the data payload in bytes
[in]sourceThe source control function of the message
[in]destinationThe destination control function of the message
[in]CANPortThe CAN channel index associated with the message

Definition at line 17 of file can_message.cpp.

Here is the caller graph for this function:

◆ CANMessage() [2/2]

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.

Parameters
[in]typeThe type of the CAN message
[in]identifierThe CAN ID of the message
[in]dataThe data payload
[in]sourceThe source control function of the message
[in]destinationThe destination control function of the message
[in]CANPortThe CAN channel index associated with the message

Definition at line 33 of file can_message.cpp.

Member Function Documentation

◆ create_invalid_message()

CANMessage isobus::CANMessage::create_invalid_message ( )
static

Factory method to construct an intentionally invalid CANMessage.

Returns
An invalid CANMessage

Definition at line 48 of file can_message.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_bool_at()

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.

Parameters
[in]byteIndexThe byte index to start reading the boolean from
[in]bitIndexThe bit index to start reading the boolean from, ranging from 0 to 7
[in]lengthThe number of bits to read, maximum of (8 - bitIndex)
Returns
True if (all) the bit(s) are set, false otherwise

Definition at line 322 of file can_message.cpp.

Here is the caller graph for this function:

◆ get_can_port_index()

std::uint8_t isobus::CANMessage::get_can_port_index ( ) const

Returns the CAN channel index associated with the message.

Returns
The CAN channel index associated with the message

Definition at line 118 of file can_message.cpp.

Here is the caller graph for this function:

◆ get_data()

const std::vector< std::uint8_t > & isobus::CANMessage::get_data ( ) const

Gets a reference to the data in the CAN message.

Returns
A reference to the data in the CAN message

Definition at line 58 of file can_message.cpp.

Here is the caller graph for this function:

◆ get_data_custom_length()

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

Parameters
[in]startBitIndexThe index to get the 64-bit unsigned integer from
[in]lengthThe length of bits to extract from the buffer
[in]formatThe byte format to use when reading the integer
Returns
The 64-bit unsigned integer

Definition at line 329 of file can_message.cpp.

◆ get_data_length()

std::uint32_t isobus::CANMessage::get_data_length ( ) const

Returns the length of the data in the CAN message.

Returns
The message data payload length

Definition at line 63 of file can_message.cpp.

Here is the caller graph for this function:

◆ get_destination_control_function()

std::shared_ptr< ControlFunction > isobus::CANMessage::get_destination_control_function ( ) const

Gets the destination control function that the message is to.

Returns
The destination control function that the message is to

Definition at line 78 of file can_message.cpp.

Here is the caller graph for this function:

◆ get_identifier()

CANIdentifier isobus::CANMessage::get_identifier ( ) const

Returns the identifier of the message.

Returns
The identifier of the message

Definition at line 108 of file can_message.cpp.

Here is the caller graph for this function:

◆ get_int16_at()

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.

Parameters
[in]indexThe index to get the 16-bit signed integer from
[in]formatThe byte format to use when reading the integer
Returns
The 16-bit signed integer

Definition at line 174 of file can_message.cpp.

Here is the caller graph for this function:

◆ get_int24_at()

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.

Parameters
[in]indexThe index to get the 24-bit signed integer from
[in]formatThe byte format to use when reading the integer
Returns
The 24-bit signed integer, right aligned into a int32_t

Definition at line 208 of file can_message.cpp.

◆ get_int32_at()

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.

Parameters
[in]indexThe index to get the 32-bit signed integer from
[in]formatThe byte format to use when reading the integer
Returns
The 32-bit signed integer

Definition at line 246 of file can_message.cpp.

Here is the caller graph for this function:

◆ get_int64_at()

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.

Parameters
[in]indexThe index to get the 64-bit signed integer from
[in]formatThe byte format to use when reading the integer
Returns
The 64-bit signed integer

Definition at line 294 of file can_message.cpp.

Here is the caller graph for this function:

◆ get_int8_at()

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.

Parameters
[in]indexThe index to get the byte from
Returns
The 8-bit signed byte

Definition at line 153 of file can_message.cpp.

◆ get_source_control_function()

std::shared_ptr< ControlFunction > isobus::CANMessage::get_source_control_function ( ) const

Gets the source control function that the message is from.

Returns
The source control function that the message is from

Definition at line 68 of file can_message.cpp.

Here is the caller graph for this function:

◆ get_type()

CANMessage::Type isobus::CANMessage::get_type ( ) const

Returns the CAN message type.

Returns
The type of the CAN message

Definition at line 53 of file can_message.cpp.

◆ get_uint16_at()

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.

Parameters
[in]indexThe index to get the 16-bit unsigned integer from
[in]formatThe byte format to use when reading the integer
Returns
The 16-bit unsigned integer

Definition at line 158 of file can_message.cpp.

Here is the caller graph for this function:

◆ get_uint24_at()

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.

Parameters
[in]indexThe index to get the 24-bit unsigned integer from
[in]formatThe byte format to use when reading the integer
Returns
The 24-bit unsigned integer, right aligned into a uint32_t

Definition at line 190 of file can_message.cpp.

Here is the caller graph for this function:

◆ get_uint32_at()

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.

Parameters
[in]indexThe index to get the 32-bit unsigned integer from
[in]formatThe byte format to use when reading the integer
Returns
The 32-bit unsigned integer

Definition at line 226 of file can_message.cpp.

Here is the caller graph for this function:

◆ get_uint64_at()

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.

Parameters
[in]indexThe index to get the 64-bit unsigned integer from
[in]formatThe byte format to use when reading the integer
Returns
The 64-bit unsigned integer

Definition at line 266 of file can_message.cpp.

Here is the caller graph for this function:

◆ get_uint8_at()

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.

Parameters
[in]indexThe index to get the byte from
Returns
The 8-bit unsigned byte

Definition at line 148 of file can_message.cpp.

Here is the caller graph for this function:

◆ has_valid_destination_control_function()

bool isobus::CANMessage::has_valid_destination_control_function ( ) const

Returns whether the message is sent to a specific device on the bus.

Returns
True if the destination of the message is valid, false otherwise

Definition at line 83 of file can_message.cpp.

Here is the caller graph for this function:

◆ has_valid_source_control_function()

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.

Returns
True if the source of the message is valid, false otherwise

Definition at line 73 of file can_message.cpp.

Here is the caller graph for this function:

◆ is_broadcast()

bool isobus::CANMessage::is_broadcast ( ) const

Returns whether the message is sent as a broadcast message / to all devices on the bus.

Returns
True if the destination of the message is everyone, false otherwise

Definition at line 88 of file can_message.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_destination()

bool isobus::CANMessage::is_destination ( std::shared_ptr< ControlFunction > controlFunction) const

Returns whether the message is destined for the control function.

Parameters
[in]controlFunctionThe control function to check
Returns
True if the message is destined for the control function, false otherwise

Definition at line 98 of file can_message.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_destination_our_device()

bool isobus::CANMessage::is_destination_our_device ( ) const

Returns whether the message is destined for our device on the bus.

Returns
True if the message is destined for our device, false otherwise

Definition at line 93 of file can_message.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_parameter_group_number()

bool isobus::CANMessage::is_parameter_group_number ( CANLibParameterGroupNumber parameterGroupNumber) const

Compares the identifier of the message to the parameter group number (PGN) supplied.

Parameters
[in]parameterGroupNumberThe parameter group number to compare to
Returns
True if the message identifier matches the parameter group number, false otherwise

Definition at line 113 of file can_message.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_source()

bool isobus::CANMessage::is_source ( std::shared_ptr< ControlFunction > controlFunction) const

Returns whether the message is originated from the control function.

Parameters
[in]controlFunctionThe control function to check
Returns
True if the message is originated from the control function, false otherwise

Definition at line 103 of file can_message.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_data() [1/2]

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.

Parameters
[in]dataBufferThe data payload
[in]lengththe length of the data payload in bytes

Definition at line 123 of file can_message.cpp.

◆ set_data() [2/2]

void isobus::CANMessage::set_data ( std::uint8_t dataByte,
const std::uint32_t insertPosition )

Sets one byte of data in the message data payload.

Parameters
[in]dataByteOne byte of data
[in]insertPositionThe position in the message at which to insert the data byte

Definition at line 131 of file can_message.cpp.

◆ set_data_size()

void isobus::CANMessage::set_data_size ( std::uint32_t length)

Sets the size of the data payload.

Parameters
[in]lengthThe desired length of the data payload

Definition at line 138 of file can_message.cpp.

◆ set_identifier()

void isobus::CANMessage::set_identifier ( const CANIdentifier & value)

Sets the CAN ID of the message.

Parameters
[in]valueThe CAN ID for the message

Definition at line 143 of file can_message.cpp.

Member Data Documentation

◆ ABSOLUTE_MAX_MESSAGE_LENGTH

const std::uint32_t isobus::CANMessage::ABSOLUTE_MAX_MESSAGE_LENGTH = 117440505
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.

Returns
The maximum length of any CAN message as defined by ETP in ISO11783

Definition at line 52 of file can_message.hpp.

◆ CANPortIndex

std::uint8_t isobus::CANMessage::CANPortIndex
private

The CAN channel index associated with the message.

Definition at line 267 of file can_message.hpp.

◆ data

std::vector<std::uint8_t> isobus::CANMessage::data
private

A data buffer for the message, used when not using data chunk callbacks.

Definition at line 264 of file can_message.hpp.

◆ destination

std::shared_ptr<ControlFunction> isobus::CANMessage::destination
private

The destination control function of the message.

Definition at line 266 of file can_message.hpp.

◆ identifier

CANIdentifier isobus::CANMessage::identifier
private

The CAN ID of the message.

Definition at line 263 of file can_message.hpp.

◆ messageType

Type isobus::CANMessage::messageType
private

The internal message type associated with the message.

Definition at line 262 of file can_message.hpp.

◆ source

std::shared_ptr<ControlFunction> isobus::CANMessage::source
private

The source control function of the message.

Definition at line 265 of file can_message.hpp.


The documentation for this class was generated from the following files: