4#include "TransceiverConfig.h"
5#include "pulse/tools/Logger.h"
6#include "pulse/tools/Vector.h"
45 _history.
reserve(preambleLength());
49 void reset() { _history.
clear(); }
53 Logger::debug(
"Preamble Detecting edge: level=%s, pulseUs=%d",
edge.level ?
"HIGH" :
"LOW",
55 size_t N = preambleLength();
56 if (
N == 0)
return true;
59 if (_history.
size() <
N) {
60 Logger::debug(
"Not enough edges for preamble detection: %d/%d",
65 for (
size_t i = 0;
i <
N; ++
i) {
66 if (_history[
i].level != _expected[
i].level) {
67 Logger::debug(
"Invalid level idx %d: expected %s, got %s - %d us",
i,
68 _expected[
i].level ?
"HIGH" :
"LOW",
69 _history[
i].level ?
"HIGH" :
"LOW ",
76 if (!
inRange(_history[
i].pulseUs, _expected[
i].pulseUs,
tol)) {
77 Logger::debug(
"Invalid pulse duration: expected %d us, got %d us",
78 _expected[
i].pulseUs, _history[
i].pulseUs);
91 virtual size_t preambleLength()
const = 0;
118 size_t preambleLength()
const override {
return 0; }
138 void addEdge(
bool level,
uint32_t pulseUs) {
147 void clear() { _expected.
clear(); }
149 for (
const auto&
edge : _expected) {
152 return _expected.
size();
154 size_t preambleLength()
const override {
return _expected.
size(); }
174 for (
auto&
edge : _expected) {
209 _history.
reserve(_runInCycles * 2 + 1);
210 _expected.
reserve(_runInCycles * 2 + 1);
212 _bitPeriod = 1000000 / _freqHz;
218 for (
uint8_t i = 0;
i < _runInCycles * 2; ++
i) {
219 addEdge(level, _bitPeriod);
CustomPreambleUs: Allows users to define their own preamble by setting expected edges....
int getEdges(Vector< OutputEdge > &output) const override
Returns the expected preamble edges for this protocol.
CustomPreamble: Allows users to define their own preamble by setting expected edges....
static void debug(const char *format,...)
Log a debug message with formatting.
Custom Manchester preamble detector: run-in of alternating edges plus unique start pulse.
A Preamble implementation for NRZ protocols: alternating edges at full bit period,...
NoPreamble: For protocols that do not require a preamble. Always returns true for detect,...
bool detect(const pulsewire::OutputEdge &edge) override
Detects if the incoming edge matches the expected preamble pattern.
int getEdges(pulsewire::Vector< pulsewire::OutputEdge > &output) const override
Returns the expected preamble edges for this protocol.
Abstract base class for preamble detection and generation.
bool inRange(uint32_t value, uint32_t target, uint32_t tolerance) const
virtual int getEdges(pulsewire::Vector< pulsewire::OutputEdge > &output) const =0
Returns the expected preamble edges for this protocol.
virtual bool detect(const OutputEdge &edge)
Detects if the incoming edge matches the expected preamble pattern.
Small, header-only vector replacement for non-STL environments.
iterator begin()
Iterator to first element.
void clear()
Remove all elements.
void push_back(const T &value)
Add element to end of vector.
void reserve(size_t cap)
Reserve space for at least cap elements.
iterator erase(iterator pos)
Erase single element at iterator pos, return iterator to next element.
size_t size() const
Number of elements in vector.
Specifies a single IR signal segment for protocol-agnostic transmission.