HardFOC Core
API reference
Loading...
Searching...
No Matches
Classes | Enumerations | Functions | Variables
hf::can::record Namespace Reference

Classes

struct  Header
 Datagram header. More...
 

Enumerations

enum class  DecodeError : uint8_t {
  None = 0 , Truncated , BadVersion , BadLength ,
  BadFrame
}
 Why a datagram was rejected. More...
 

Functions

void PutU16 (uint8_t *p, uint16_t v) noexcept
 
void PutU32 (uint8_t *p, uint32_t v) noexcept
 
uint16_t GetU16 (const uint8_t *p) noexcept
 
uint32_t GetU32 (const uint8_t *p) noexcept
 
std::size_t EncodeHeader (uint8_t *out, const Header &h) noexcept
 Write the header; out has kHeaderSize bytes.
 
constexpr std::size_t RecordSize (const CanFrame &f) noexcept
 Bytes the record of f takes.
 
std::size_t EncodeRecord (uint8_t *out, std::size_t cap, const CanFrame &f) noexcept
 Append the record of f.
 
template<typename OnFrame >
DecodeError DecodeDatagram (const uint8_t *p, std::size_t n, Header *header, OnFrame &&on_frame)
 Decode a datagram; on_frame(const CanFrame&) is called per record.
 

Variables

constexpr uint8_t kVersion = 1U
 
constexpr std::size_t kHeaderSize = 8U
 
constexpr std::size_t kRecordHeaderSize = 6U
 
constexpr std::size_t kMaxRecordSize = kRecordHeaderSize + kFdMaxLen
 
constexpr std::size_t kMaxDatagram = 4096U
 
constexpr uint32_t kIdExtBit = 0x80000000U
 
constexpr uint32_t kIdRtrBit = 0x40000000U
 
constexpr uint8_t kRecordFlagMask = frame_flag::kFdf | frame_flag::kBrs | frame_flag::kEsi
 
constexpr uint8_t kDgramKeepAlive = 0x01U
 

Enumeration Type Documentation

◆ DecodeError

enum class hf::can::record::DecodeError : uint8_t
strong

Why a datagram was rejected.

Enumerator
None 
Truncated 

shorter than the header, or a record runs past the end

BadVersion 

ver != 1

BadLength 

record len > 64

BadFrame 

record is not a well-formed frame (flags, id range, length)

Function Documentation

◆ DecodeDatagram()

template<typename OnFrame >
DecodeError hf::can::record::DecodeDatagram ( const uint8_t *  p,
std::size_t  n,
Header *  header,
OnFrame &&  on_frame 
)

Decode a datagram; on_frame(const CanFrame&) is called per record.

The whole datagram is validated before the first callback, so a malformed datagram delivers nothing.

◆ EncodeHeader()

std::size_t hf::can::record::EncodeHeader ( uint8_t *  out,
const Header &  h 
)
inlinenoexcept

Write the header; out has kHeaderSize bytes.

◆ EncodeRecord()

std::size_t hf::can::record::EncodeRecord ( uint8_t *  out,
std::size_t  cap,
const CanFrame &  f 
)
inlinenoexcept

Append the record of f.

Returns
bytes written, or 0 if cap is too small or the frame is malformed

◆ GetU16()

uint16_t hf::can::record::GetU16 ( const uint8_t *  p)
inlinenoexcept

◆ GetU32()

uint32_t hf::can::record::GetU32 ( const uint8_t *  p)
inlinenoexcept

◆ PutU16()

void hf::can::record::PutU16 ( uint8_t *  p,
uint16_t  v 
)
inlinenoexcept

◆ PutU32()

void hf::can::record::PutU32 ( uint8_t *  p,
uint32_t  v 
)
inlinenoexcept

◆ RecordSize()

constexpr std::size_t hf::can::record::RecordSize ( const CanFrame &  f)
constexprnoexcept

Bytes the record of f takes.

Variable Documentation

◆ kDgramKeepAlive

constexpr uint8_t hf::can::record::kDgramKeepAlive = 0x01U
inlineconstexpr

Datagram flag: keep-alive, no records expected.

◆ kHeaderSize

constexpr std::size_t hf::can::record::kHeaderSize = 8U
inlineconstexpr

◆ kIdExtBit

constexpr uint32_t hf::can::record::kIdExtBit = 0x80000000U
inlineconstexpr

◆ kIdRtrBit

constexpr uint32_t hf::can::record::kIdRtrBit = 0x40000000U
inlineconstexpr

◆ kMaxDatagram

constexpr std::size_t hf::can::record::kMaxDatagram = 4096U
inlineconstexpr

Largest datagram this codec emits or accepts (stream length prefix is u16).

◆ kMaxRecordSize

constexpr std::size_t hf::can::record::kMaxRecordSize = kRecordHeaderSize + kFdMaxLen
inlineconstexpr

◆ kRecordFlagMask

constexpr uint8_t hf::can::record::kRecordFlagMask = frame_flag::kFdf | frame_flag::kBrs | frame_flag::kEsi
inlineconstexpr

◆ kRecordHeaderSize

constexpr std::size_t hf::can::record::kRecordHeaderSize = 6U
inlineconstexpr

◆ kVersion

constexpr uint8_t hf::can::record::kVersion = 1U
inlineconstexpr