67 explicit CanDataFrame(
const std::shared_ptr<IBusMessage>& message);
97 [[nodiscard]] uint32_t
CanId()
const;
118 void Dlc(uint8_t dlc) { dlc_ = dlc;};
127 [[nodiscard]] uint8_t
Dlc()
const {
return dlc_;};
130 void Crc(uint32_t crc) { crc_ = crc;};
133 [[nodiscard]] uint32_t
Crc()
const {
return crc_;};
154 [[nodiscard]]
const std::vector<uint8_t>&
DataBytes()
const;
159 [[nodiscard]]
bool Dir()
const;
162 [[nodiscard]]
bool Srr()
const;
165 [[nodiscard]]
bool Edl()
const;
168 [[nodiscard]]
bool Brs()
const;
171 [[nodiscard]]
bool Esi()
const;
174 [[nodiscard]]
bool Rtr()
const;
183 [[nodiscard]]
bool R0()
const;
186 [[nodiscard]]
bool R1()
const;
205 void ToRaw(std::vector<uint8_t>& dest)
const override;
212 void FromRaw(
const std::vector<uint8_t>& source)
override;
214 uint32_t message_id_ = 0;
216 std::bitset<16> flags_;
217 std::vector<uint8_t> data_bytes_;
218 uint16_t bit_position_ = 0;
220 uint32_t frame_duration_ = 0;
bool SingleWire() const
Indicate a single wire CAN bus.
void ToRaw(std::vector< uint8_t > &dest) const override
Serialize the message.
bool R0() const
Optional R0 flag.
void CanId(uint32_t can_id)
Returns the 11/27 bit CAN ID.
void WakeUp(bool wake_up)
Indicate a CAN bus wake up status.
uint32_t Crc() const
Returns the CRC code.
Definition candataframe.h:133
uint8_t DataLength() const
Returns number of data bytes.
bool Dir() const
Returns true if the message was transmitted.
uint32_t CanId() const
29/11 bit CAN message ID. Note that bit 31 is not used.
uint32_t FrameDuration() const
Frame duration in nano-seconds.
void Edl(bool edl)
Extended (CAN FD) data length.
void Brs(bool brs)
Bit rate switch (CAN FD).
void DataLength(uint8_t data_length)
Sets number of data bytes.
bool Esi() const
Error state indicator (CAN FD).
void Dlc(uint8_t dlc)
Sets the CAN message data length code.
Definition candataframe.h:118
uint32_t MessageId() const
DBC message ID. Note that bit 31 indicate extended ID.
void Dir(bool transmit)
If set true, the message was transmitted.
bool Rtr() const
Returns the RTR bit.
void Crc(uint32_t crc)
Sets the CRC code.
Definition candataframe.h:130
CanDataFrame(const std::shared_ptr< IBusMessage > &message)
Create a message from a raw byte array.
void SingleWire(bool single_wire)
Indicate a single wire CAN bus.
void Srr(bool srr)
Sets the SRR bit. */.
void R1(bool flag)
Optional R1 flag.
const std::vector< uint8_t > & DataBytes() const
Returns a reference to the payload data bytes.
void ExtendedId(bool extended)
Set true if the CAN ID uses 20-bit addressing.
bool Brs() const
Bit rate switch (CAN FD).
void MessageId(uint32_t msg_id)
DBC message ID. Note that bit 31 indicate extended ID.
void Rtr(bool rtr)
Sets the RTR bit (remote frame).
void R0(bool flag)
Optional R0 flag.
static size_t DlcToLength(uint8_t dlc)
Return the data length by DLC.
void DataBytes(const std::vector< uint8_t > &data)
Sets the payload data bytes.
bool Srr() const
Returns the SRR bit.
CanDataFrame()
Deafult constructor.
bool WakeUp() const
Indicate a CAN bus wake up message.
void FrameDuration(uint32_t duration)
Frame duration in nano-seconds.
bool Edl() const
Extended (CAN FD) data length.
bool ExtendedId() const
Returns true if the CAN ID uses 29-bit addressing,.
bool R1() const
Optional R1 flag.
uint8_t Dlc() const
Returns the data length code (DLC).
Definition candataframe.h:127
void FromRaw(const std::vector< uint8_t > &source) override
Deserialize the message.
void Esi(bool esi)
Error state indicator (CAN FD).
Defines an interface against a bus message.
Main namespace for the MDF library.
Definition buslogstream.h:24
CanErrorType
Enumerate yhat defines type of CAN bus error.
Definition candataframe.h:21
@ BIT_STUFFING_ERROR
Bit stuffing error.
Definition candataframe.h:25
@ FORM_ERROR
CAN format error.
Definition candataframe.h:24
@ UNKNOWN_ERROR
Unspecified error.
Definition candataframe.h:22
@ BIT_ERROR
CAN bit error.
Definition candataframe.h:23
@ ACK_ERROR
Acknowledgement error.
Definition candataframe.h:27
@ CRC_ERROR
Checksum error.
Definition candataframe.h:26