Back to Serial Studio

MDF Lib: include/mdf/canmessage.h Source File

lib/mdflib/docs/manual/html/canmessage_8h_source.html

3.2.717.4 KB
Original Source

| MDF Lib 2.2

Interface against MDF 3/4 files |

Loading...

Searching...

No Matches

canmessage.h

Go to the documentation of this file.

1/*

2* Copyright 2023 Ingemar Hedvall

3* SPDX-License-Identifier: MIT

4*/

5

12#pragma once

13

14

15#include "mdf/samplerecord.h"

16

17namespace mdf {

19enum class CanErrorType : uint8_t {

20UNKNOWN_ERROR = 0,

21BIT_ERROR = 1,

22FORM_ERROR = 2,

23BIT_STUFFING_ERROR = 3,

24CRC_ERROR = 4,

25ACK_ERROR = 5

26};

27

29enum class MessageType : int {

30CAN_DataFrame,

31CAN_RemoteFrame,

32CAN_ErrorFrame,

33CAN_OverloadFrame,

34};

35

36class IChannel;

37

47class CanMessage {

48 public:

50void MessageId(uint32_t msg_id);

51

53 [[nodiscard]] uint32_t MessageId() const;

54

56 [[nodiscard]] uint32_t CanId() const;

57

58void ExtendedId(bool extended );

59 [[nodiscard]] bool ExtendedId() const;

60

68void Dlc(uint8_t dlc);

69 [[nodiscard]] uint8_t Dlc() const;

70

78void DataLength(size_t data_length);

79 [[nodiscard]] size_t DataLength() const;

80

87void DataBytes(const std::vector<uint8_t>& data);

88

90 [[nodiscard]] const std::vector<uint8_t>& DataBytes() const;

91

93void DataIndex(uint64_t index);

95 [[nodiscard]] uint64_t DataIndex() const;

96

98void Dir(bool transmit );

100 [[nodiscard]] bool Dir() const;

101

102void Srr(bool srr );

103 [[nodiscard]] bool Srr() const;

104

105void Edl(bool edl );

106 [[nodiscard]] bool Edl() const;

107

108void Brs(bool brs );

109 [[nodiscard]] bool Brs() const;

110

111void Esi(bool esi );

112 [[nodiscard]] bool Esi() const;

113

114void Rtr(bool rtr );

115 [[nodiscard]] bool Rtr() const;

116

117void WakeUp(bool wake_up );

118 [[nodiscard]] bool WakeUp() const;

119

120void SingleWire(bool single_wire );

121 [[nodiscard]] bool SingleWire() const;

122

123void BusChannel(uint8_t channel);

124 [[nodiscard]] uint8_t BusChannel() const;

125

126void BitPosition(uint8_t position);

127 [[nodiscard]] uint8_t BitPosition() const;

128

129void ErrorType(CanErrorType error_type);

130 [[nodiscard]] CanErrorType ErrorType() const;

131

132static size_t DlcToLength(uint8_t dlc);

133

134void Reset();

135

137void ToRaw(MessageType msg_type, SampleRecord& sample,

138size_t max_data_length, bool save_index ) const;

139 private:

140 uint32_t message_id_ = 0;

141 uint8_t dlc_ = 0;

142 uint8_t flags_ = 0;

143 uint64_t data_index_ = 0;

144 std::vector<uint8_t> data_bytes_;

145 uint8_t bit_position_ = 0;

146 uint8_t error_type_ = 0;

147

148};

149

150} // namespace mdf

mdf::CanMessage

Helper class when logging CAN and CAN FD messages.

Definition canmessage.h:47

mdf::CanMessage::Esi

void Esi(bool esi)

Error state indicator (CAN FD).

mdf::CanMessage::BitPosition

uint8_t BitPosition() const

Error bit position.

mdf::CanMessage::Rtr

bool Rtr() const

Returns the RTR bit.

mdf::CanMessage::DlcToLength

static size_t DlcToLength(uint8_t dlc)

Return the data length by DLC.

mdf::CanMessage::WakeUp

void WakeUp(bool wake_up)

Indicate a CAN bus wake up status.

mdf::CanMessage::Brs

bool Brs() const

Bit rate switch (CAN FD).

mdf::CanMessage::Dir

bool Dir() const

Returns true if the message was transmitted.

mdf::CanMessage::Esi

bool Esi() const

Error state indicator (CAN FD).

mdf::CanMessage::Srr

bool Srr() const

Returns the SRR bit.

mdf::CanMessage::Edl

void Edl(bool edl)

Extended (CAN FD) data length.

mdf::CanMessage::ExtendedId

bool ExtendedId() const

Returns the extended CAN ID.

mdf::CanMessage::BusChannel

uint8_t BusChannel() const

Bus channel.

mdf::CanMessage::Srr

void Srr(bool srr)

Sets the SRR bit. *‍/.

mdf::CanMessage::SingleWire

void SingleWire(bool single_wire)

Indicate a single wire CAN bus.

mdf::CanMessage::Dlc

uint8_t Dlc() const

Returns the CAN message length code.

mdf::CanMessage::DataBytes

const std::vector< uint8_t > & DataBytes() const

Returns a reference to the payload data bytes.

mdf::CanMessage::DataIndex

uint64_t DataIndex() const

Internal function for the VLSD data offset.

mdf::CanMessage::CanId

uint32_t CanId() const

29/11 bit CAN message ID. Note that bit 31 is not used.

mdf::CanMessage::DataLength

void DataLength(size_t data_length)

Sets number of data bytes.

mdf::CanMessage::Edl

bool Edl() const

Extended (CAN FD) data length.

mdf::CanMessage::Rtr

void Rtr(bool rtr)

Sets the RTR bit (remote frame).

mdf::CanMessage::Dlc

void Dlc(uint8_t dlc)

Sets the CAM message data length code.

mdf::CanMessage::DataLength

size_t DataLength() const

Returns number of data bytes.

mdf::CanMessage::DataBytes

void DataBytes(const std::vector< uint8_t > &data)

Sets the payload data bytes.

mdf::CanMessage::MessageId

void MessageId(uint32_t msg_id)

CAN message ID. Note that bit 31 indicate extended ID.

mdf::CanMessage::ErrorType

CanErrorType ErrorType() const

Type of error.

mdf::CanMessage::Brs

void Brs(bool brs)

Bit rate switch (CAN FD).

mdf::CanMessage::BusChannel

void BusChannel(uint8_t channel)

Bus channel.

mdf::CanMessage::DataIndex

void DataIndex(uint64_t index)

Internal function for storing VLSD data offset.

mdf::CanMessage::ErrorType

void ErrorType(CanErrorType error_type)

Type of error.

mdf::CanMessage::BitPosition

void BitPosition(uint8_t position)

Error bit position (error frame).

mdf::CanMessage::SingleWire

bool SingleWire() const

Indicate a single wire CAN bus.

mdf::CanMessage::ExtendedId

void ExtendedId(bool extended)

Sets the extended CAN ID bit.

mdf::CanMessage::Reset

void Reset()

Reset all flags an payload data buffers.

mdf::CanMessage::ToRaw

void ToRaw(MessageType msg_type, SampleRecord &sample, size_t max_data_length, bool save_index) const

Creates an MDF sample record. Used primarily internally.

mdf::CanMessage::WakeUp

bool WakeUp() const

Indicate a CAN bus wake up message.

mdf::CanMessage::MessageId

uint32_t MessageId() const

CAN message ID. Note that bit 31 indicate extended ID.

mdf::CanMessage::Dir

void Dir(bool transmit)

If set true, the message was transmitted.

mdf

Main namespace for the MDF library.

Definition canmessage.h:17

mdf::CanErrorType

CanErrorType

Enumerate yhat defines type of CAN bus error.

Definition canmessage.h:19

mdf::CanErrorType::BIT_STUFFING_ERROR

@ BIT_STUFFING_ERROR

Bit stuffing error.

mdf::CanErrorType::FORM_ERROR

@ FORM_ERROR

CAN format error.

mdf::CanErrorType::UNKNOWN_ERROR

@ UNKNOWN_ERROR

Unspecified error.

mdf::CanErrorType::BIT_ERROR

@ BIT_ERROR

CAN bit error.

mdf::CanErrorType::ACK_ERROR

@ ACK_ERROR

Acknowledgement error.

mdf::CanErrorType::CRC_ERROR

@ CRC_ERROR

Checksum error.

mdf::MessageType

MessageType

Enumerate that defines type of CAN messages.

Definition canmessage.h:29

mdf::MessageType::CAN_RemoteFrame

@ CAN_RemoteFrame

Remote frame message.

mdf::MessageType::CAN_OverloadFrame

@ CAN_OverloadFrame

Overload frame message.

mdf::MessageType::CAN_ErrorFrame

@ CAN_ErrorFrame

Error message.

mdf::MessageType::CAN_DataFrame

@ CAN_DataFrame

Normal CAN message.

samplerecord.h

mdf::SampleRecord

Simple record buffer structure.

Definition samplerecord.h:20


Generated by 1.12.0