Files
Toyota-AVC-LAN/src/avclan/frame.hpp
T
Allen Hill 5208e083f3 Redesign (simplify) top-level avclan interface to use expected/nullable unique_ptr
- Peripheral::read/send now return `expected<unique_ptr<Frame>, Error>`
for a unified success/error interface.
- Peripheral::route returns `expected<unique_ptr<Frame>, Error>` to
distinguish intent: (intentional) non-response vs unable to respond
- Other functions with optional message semantics (handle,poll,react)
return a unique_ptr whose ownership-state indicates response intent
(i.e. send new message)

Bundled necessary changes:
- Switch Frame allocation from global to local (enabled via member
  function new/delete)
- Add new header-library tl::expected to shim avr-libstdcpp

Unrelated: Defensive `continue` added after `route`, to reduce Bus
activity check latency

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 14:47:47 -07:00

54 lines
1.5 KiB
C++

// copyright (C) 2006 Marcin Slonicki <marcin@softservice.com.pl>
// copyright (C) 2007 Louis Frigon
// Copyright (C) 2015 Allen Hill <allenofthehills@gmail.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <cstdint>
#include "avclan.h"
#if defined(AVCLAN_FRAME_POOL_N)
#include <cstddef>
#include <new>
#endif
namespace avclan {
enum class Device : uint8_t;
struct Frame {
struct Print {
bool print : 1 = false; // print at all
bool binary : 1 = false; // if printing, format as binary instead of text
bool verbose : 1 = false; // include extra context in error reports
};
using Error = detail::Error;
static constexpr int MAXLENGTH = 32;
static constexpr int MIN_SIZE = 7;
Error::Parse parse(const uint8_t *bytes, uint8_t len);
void print(Print print) const;
#if defined(AVCLAN_FRAME_POOL_N)
// O(1) heapless pooled allocation. Only `new (std::nothrow) Frame` is
// supported.
static void *operator new(std::size_t) = delete;
static void *operator new(std::size_t, const std::nothrow_t &) noexcept;
// NOLINTNEXTLINE(misc-new-delete-overloads) false-positive
static void operator delete(void *) noexcept;
#endif
// reaction has a Device-defined interpretation, with the sole invariant that
// 0 == inactive/non-sendable frame
uint8_t reaction = 0;
Device owning_device = NoDevice;
bool is_unicast;
uint16_t controller_addr; // formerly "master"
uint16_t peripheral_addr; // formerly "slave"
uint8_t control = 0xF;
uint8_t length = 0;
uint8_t data[MAXLENGTH];
};
} // namespace avclan