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 {
20 UNKNOWN_ERROR = 0,
21 BIT_ERROR = 1,
22 FORM_ERROR = 2,
24 CRC_ERROR = 4,
25 ACK_ERROR = 5
26};
27
35
36class IChannel;
37
48 public:
50 void MessageId(uint32_t msg_id);
51
53 [[nodiscard]] uint32_t MessageId() const;
54
56 [[nodiscard]] uint32_t CanId() const;
57
58 void ExtendedId(bool extended );
59 [[nodiscard]] bool ExtendedId() const;
60
68 void Dlc(uint8_t dlc);
69 [[nodiscard]] uint8_t Dlc() const;
70
78 void DataLength(size_t data_length);
79 [[nodiscard]] size_t DataLength() const;
80
87 void DataBytes(const std::vector<uint8_t>& data);
88
90 [[nodiscard]] const std::vector<uint8_t>& DataBytes() const;
91
93 void DataIndex(uint64_t index);
95 [[nodiscard]] uint64_t DataIndex() const;
96
98 void Dir(bool transmit );
100 [[nodiscard]] bool Dir() const;
101
102 void Srr(bool srr );
103 [[nodiscard]] bool Srr() const;
104
105 void Edl(bool edl );
106 [[nodiscard]] bool Edl() const;
107
108 void Brs(bool brs );
109 [[nodiscard]] bool Brs() const;
110
111 void Esi(bool esi );
112 [[nodiscard]] bool Esi() const;
113
114 void Rtr(bool rtr );
115 [[nodiscard]] bool Rtr() const;
116
117 void WakeUp(bool wake_up );
118 [[nodiscard]] bool WakeUp() const;
119
120 void SingleWire(bool single_wire );
121 [[nodiscard]] bool SingleWire() const;
122
123 void BusChannel(uint8_t channel);
124 [[nodiscard]] uint8_t BusChannel() const;
125
126 void BitPosition(uint8_t position);
127 [[nodiscard]] uint8_t BitPosition() const;
128
129 void ErrorType(CanErrorType error_type);
130 [[nodiscard]] CanErrorType ErrorType() const;
131
132 static size_t DlcToLength(uint8_t dlc);
133
134 void Reset();
135
137 void ToRaw(MessageType msg_type, SampleRecord& sample,
138 size_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
Helper class when logging CAN and CAN FD messages.
Definition canmessage.h:47
void Esi(bool esi)
Error state indicator (CAN FD).
uint8_t BitPosition() const
Error bit position.
bool Rtr() const
Returns the RTR bit.
static size_t DlcToLength(uint8_t dlc)
Return the data length by DLC.
void WakeUp(bool wake_up)
Indicate a CAN bus wake up status.
bool Brs() const
Bit rate switch (CAN FD).
bool Dir() const
Returns true if the message was transmitted.
bool Esi() const
Error state indicator (CAN FD).
bool Srr() const
Returns the SRR bit.
void Edl(bool edl)
Extended (CAN FD) data length.
bool ExtendedId() const
Returns the extended CAN ID.
uint8_t BusChannel() const
Bus channel.
void Srr(bool srr)
Sets the SRR bit. *‍/.
void SingleWire(bool single_wire)
Indicate a single wire CAN bus.
uint8_t Dlc() const
Returns the CAN message length code.
const std::vector< uint8_t > & DataBytes() const
Returns a reference to the payload data bytes.
uint64_t DataIndex() const
Internal function for the VLSD data offset.
uint32_t CanId() const
29/11 bit CAN message ID. Note that bit 31 is not used.
void DataLength(size_t data_length)
Sets number of data bytes.
bool Edl() const
Extended (CAN FD) data length.
void Rtr(bool rtr)
Sets the RTR bit (remote frame).
void Dlc(uint8_t dlc)
Sets the CAM message data length code.
size_t DataLength() const
Returns number of data bytes.
void DataBytes(const std::vector< uint8_t > &data)
Sets the payload data bytes.
void MessageId(uint32_t msg_id)
CAN message ID. Note that bit 31 indicate extended ID.
CanErrorType ErrorType() const
Type of error.
void Brs(bool brs)
Bit rate switch (CAN FD).
void BusChannel(uint8_t channel)
Bus channel.
void DataIndex(uint64_t index)
Internal function for storing VLSD data offset.
void ErrorType(CanErrorType error_type)
Type of error.
void BitPosition(uint8_t position)
Error bit position (error frame).
bool SingleWire() const
Indicate a single wire CAN bus.
void ExtendedId(bool extended)
Sets the extended CAN ID bit.
void Reset()
Reset all flags an payload data buffers.
void ToRaw(MessageType msg_type, SampleRecord &sample, size_t max_data_length, bool save_index) const
Creates an MDF sample record. Used primarily internally.
bool WakeUp() const
Indicate a CAN bus wake up message.
uint32_t MessageId() const
CAN message ID. Note that bit 31 indicate extended ID.
void Dir(bool transmit)
If set true, the message was transmitted.
Main namespace for the MDF library.
Definition canmessage.h:17
CanErrorType
Enumerate yhat defines type of CAN bus error.
Definition canmessage.h:19
@ BIT_STUFFING_ERROR
Bit stuffing error.
@ FORM_ERROR
CAN format error.
@ UNKNOWN_ERROR
Unspecified error.
@ BIT_ERROR
CAN bit error.
@ ACK_ERROR
Acknowledgement error.
@ CRC_ERROR
Checksum error.
MessageType
Enumerate that defines type of CAN messages.
Definition canmessage.h:29
@ CAN_RemoteFrame
Remote frame message.
@ CAN_OverloadFrame
Overload frame message.
@ CAN_ErrorFrame
Error message.
@ CAN_DataFrame
Normal CAN message.
Simple record buffer structure.
Definition samplerecord.h:20