22#include "pw_assert/assert.h"
23#include "pw_bytes/span.h"
24#include "pw_checksum/crc32.h"
25#include "pw_hdlc/internal/protocol.h"
26#include "pw_result/result.h"
27#include "pw_status/status.h"
39 static constexpr size_t kMinContentSizeBytes =
40 kMinAddressSize + kControlSize + kFcsSize;
44 constexpr uint64_t address()
const {
return address_; }
46 constexpr std::byte control()
const {
return control_; }
54 : data_(data), address_(address), control_(control) {}
73 last_read_bytes_index_(0),
74 current_frame_size_(0),
75 state_(State::kInterFrame) {}
106 static constexpr size_t RequiredBufferSizeForFrameSize(
107 size_t max_frame_size) {
110 return max_frame_size < Frame::kMinContentSizeBytes
111 ? Frame::kMinContentSizeBytes
112 : max_frame_size - 2;
117 template <
typename F,
typename... Args>
119 for (std::byte b : data) {
121 if (result.status() != Status::Unavailable()) {
122 callback(std::forward<Args>(args)..., result);
128 size_t max_size()
const {
return buffer_.size(); }
132 state_ = State::kInterFrame;
145 current_frame_size_ = 0;
146 last_read_bytes_index_ = 0;
150 void AppendByte(std::byte new_byte);
152 Status CheckFrame()
const;
154 bool VerifyFrameCheckSequence()
const;
162 std::array<std::byte,
sizeof(uint32_t)> last_read_bytes_;
163 size_t last_read_bytes_index_;
166 checksum::Crc32 fcs_;
168 size_t current_frame_size_;
174template <
size_t kSizeBytes>
189 static constexpr size_t max_size() {
return kSizeBytes; }
192 static_assert(kSizeBytes >= Frame::kMinContentSizeBytes);
194 std::array<std::byte, kSizeBytes> frame_buffer_;
Definition: decoder.h:175
Result< Frame > Process(std::byte new_byte)
Parses a single byte of an HDLC stream.
void Process(ConstByteSpan data, F &&callback, Args &&... args)
Processes a span of data and calls the provided callback with each frame or error.
Definition: decoder.h:118
DecoderBuffer & operator=(DecoderBuffer &&)=delete
DecoderBuffer(DecoderBuffer &&)=delete
Serial comms library.
Definition: decoder.h:29