Abstract base class representing a generic bus message.
More...
#include "bus/ibusmessage.h"
|
| IBusMessage (BusMessageType type) |
virtual void | ToRaw (std::vector< uint8_t > &dest) const |
| Serialize the message.
|
virtual void | FromRaw (const std::vector< uint8_t > &source) |
| Deserialize the message.
|
BusMessageType | Type () const |
| Returns type of message.
|
void | Version (uint16_t version) |
| Sets the vewrsion number for a message.
|
uint16_t | Version () const |
| Returns the version number of the message.
|
uint32_t | Size () const |
| Returns the total size of the message.
|
bool | Valid () const |
| Returns true if the message is valid.
|
void | Timestamp (uint64_t timestamp) |
| Sets the absolute time.
|
uint64_t | Timestamp () const |
| Retuns the timestampe.
|
void | BusChannel (uint16_t channel) |
| Sets the source channel.
|
uint16_t | BusChannel () const |
| Returns the bus channel number.
|
|
void | Size (uint32_t size) const |
| Sets the total size of the message.
|
void | Valid (bool valid) const |
| Sets the message valid or invalid.
|
This abstract base class is used to implement generic bus messages. A message must have a specific type and a version. The type and version, defines how the message is serialized. The serialization are done with the ToRaw() and FromRaw() functions. These functions are abstract and have to be implemented by the derived class.
The serialization of a bus message have a header which has the same length. The header is according to table below and uses little endian byte order.
Bus Message Header
Byte (Bits) Offset | Description | Size |
0 | Type of Message (enumerate) | uint16_t |
2 | Version Number | uint16_t |
4 | Length of the message | uint32_t |
8 | Timestamp ns since 1970 | uint64_t |
16 | Bus Channel | uint16_t |
◆ IBusMessage()
Contructor that creates a type of message.
This constructor should not be used by end-user but it is used for testing purpose.
- Parameters
-
◆ BusChannel() [1/2]
uint16_t bus::IBusMessage::BusChannel |
( |
| ) |
const |
|
inlinenodiscard |
The bus channel is a number that defines the source of the message. The source is typical a physical driver channel and not defining any ECU device.
Note that many manufactures of CAN communication cards, name the first channel as 'Channel 1' but uses channel 0 in its software. This causes a lot of problems and it doesn't help that the channel number randomly changes between computer restarts. It is recommended to start the channel number at 1 and assign the first channel, the 'Channel 1' name. The channel name should be assoiated with the device driver serial number instead of its internal channel number.
- Returns
- Bus channel number.
◆ BusChannel() [2/2]
void bus::IBusMessage::BusChannel |
( |
uint16_t | channel | ) |
|
|
inline |
The bus channel is a number that defines the source of the message. The source is typical a physical driver channel and not defining any ECU device.
Note that many manufactures of CAN communication card, name the first channel as 'Channel 1' but uses channel 0 in its software. This causes a lot of problems and it doesn't help that the channel number randomly changes between computer restarts. It is recommended to start the channel number at 1 and assign the first channel, the 'Channel 1' name. The channel name should be assoiated with the device driver serial number instead of its internal channel number.
- Parameters
-
channel | Bus channel number. |
◆ Create()
Creates a message by its type. This fucntion is used by subscriber when deserialize a message.
- Parameters
-
- Returns
- Smart pointer to IBussMessage object.
◆ FromRaw()
virtual void bus::IBusMessage::FromRaw |
( |
const std::vector< uint8_t > & | source | ) |
|
|
virtual |
This function desrialize a message from an byte array.
- Parameters
-
Reimplemented in bus::CanDataFrame.
◆ Size() [1/2]
uint32_t bus::IBusMessage::Size |
( |
| ) |
const |
|
inlinenodiscard |
The function return number of total message bytes, not the paylod data size.
- Returns
- Number of total message bytes.
◆ Size() [2/2]
void bus::IBusMessage::Size |
( |
uint32_t | size | ) |
const |
|
inlineprotected |
This function set the messsage size when serialize and deserialize the message.
- Parameters
-
size | Message size (butes). |
◆ Timestamp() [1/2]
uint64_t bus::IBusMessage::Timestamp |
( |
| ) |
const |
|
inlinenodiscard |
The timestamp is defined as nanoseconds since midnight 1970-01-01. The timezone is always UTC.
- Returns
- Time since 1970.
◆ Timestamp() [2/2]
void bus::IBusMessage::Timestamp |
( |
uint64_t | timestamp | ) |
|
|
inline |
Sets the timestamp for the message. The time is number of nanoseconds from midnight 1970-01-01. The timezone is always UTC.
- Parameters
-
timestamp | Nanoseconds sinncs 1970. |
◆ ToRaw()
virtual void bus::IBusMessage::ToRaw |
( |
std::vector< uint8_t > & | dest | ) |
const |
|
virtual |
The function serialize a message to a byte array. This array is later used by the communication interfaces for transfer the message in shared ememroy or TCP/IP. The destination array is sized by the function.
- Parameters
-
Reimplemented in bus::CanDataFrame.
◆ Type()
◆ Valid() [1/2]
bool bus::IBusMessage::Valid |
( |
| ) |
const |
|
inlinenodiscard |
The message can be set invalid if the serialization or deserialization fails. olle
- Returns
- True if the message is valid.
◆ Valid() [2/2]
void bus::IBusMessage::Valid |
( |
bool | valid | ) |
const |
|
inlineprotected |
Sets the message valid or invalid. By default the message is set valid (true).
- Parameters
-
valid | Valid is true while invalid is false. |
◆ Version() [1/2]
uint16_t bus::IBusMessage::Version |
( |
| ) |
const |
|
inlinenodiscard |
Rarely used function but used by the serialization and deserialization functions.
- Returns
- Version number.
◆ Version() [2/2]
void bus::IBusMessage::Version |
( |
uint16_t | version | ) |
|
|
inline |
This function should rarely be used but defines the version of the message. This is used by the serialization and deserialization functions. The version is changed when properties are added.
- Parameters
-
The documentation for this class was generated from the following file: