3#include "pulse/SignalBase.h"
4#include "pulse/codecs/Codec.h"
5#include "pulse/tools/Vector.h"
26 CodecEnum
getCodecType()
const override {
return CodecEnum::Manchester; }
30 if (_preamble == &_defaultPreamble) {
31 _defaultPreamble.clear();
33 _defaultPreamble.addEdge(
true,
halfBit);
94 for (
int i = 0;
i < 8; ++
i) {
112 OutputEdge newEdge{level, durationUs};
113 assert(_preamble !=
nullptr);
115 if (_preamble->preambleLength() == 0) {
117 _decodeEdgeStream.
clear();
121 }
else if (_preamble->
detect(newEdge)) {
124 _decodeEdgeStream.
clear();
133 bool rc = decodeByte(_decodeEdgeStream, result);
135 _decodeEdgeStream.
clear();
141 bool decodeByte(Vector<OutputEdge>& edges, uint8_t& result) {
145 uint8_t&
byte = result;
148 for (
int i = 0; i < 8; ++i) {
149 bool b0 = edges[i * 2].level;
150 bool b1 = edges[i * 2 + 1].level;
152 if (b0 == 1 && b1 == 0) {
153 byte |= (1 << (7 - i));
154 }
else if (b0 == 0 && b1 == 1) {
158 Logger::error(
"Invalid Manchester pair at bit %d: b0=%d, b1=%d", i, b0,
180 first.pulseUs = _bitPeriodUs / 2;
182 second.pulseUs = _bitPeriodUs / 2;
185 first.pulseUs = _bitPeriodUs / 2;
187 second.pulseUs = _bitPeriodUs / 2;
Abstract base class for IR protocol encoding and decoding.
virtual bool getIdleLevel() const
Provides the initial ldle state (low or hith)
virtual void encodeByte(uint8_t byte, std::vector< bool > &bits) const
Encode a byte to protocol bitstream. Default implementation encodes to raw bits (MSB first),...
virtual bool begin(uint32_t bitFrequencyHz)
initialization method for codecs that require setup before use (e.g., loading PIO programs,...
virtual void reset()
Reset the internal state of the codec.
static void debug(const char *format,...)
Log a debug message with formatting.
static void error(const char *format,...)
Log an error message with formatting.
Manchester encoding/decoding utility class for IR communication.
virtual size_t encode(uint8_t byte, Vector< OutputEdge > &output)
Fill output vector with protocol-specific OutputSpec(s) for a byte.
bool decodeEdge(uint32_t durationUs, bool level, uint8_t &result) override
Decode incoming edges to reconstruct bytes. Handles multiple edges per bit for noise tolerance by ave...
bool begin(uint32_t bitFrequencyHz) override
initialization method for codecs that require setup before use (e.g., loading PIO programs,...
int getEndOfFrameDelayUs() override
Get delay to mark End Of Frame in us.
CodecEnum getCodecType() const override
size_t getEdgeCount() const override
Get the number of edges used to encode a byte (16 for Manchester).
size_t encodeBit(bool bit, Vector< OutputEdge > &output)
Fill output vector with Manchester OutputSpec(s) for a bit.
Abstract base class for preamble detection and generation.
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.
size_t capacity() const
Current allocated capacity.
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.
size_t size() const
Number of elements in vector.
Specifies a single IR signal segment for protocol-agnostic transmission.