Arduino PulseWire Transceiver Library
Loading...
Searching...
No Matches
RecorderCodec.h
1#pragma once
2#include "Codec.h"
3
4namespace pulsewire {
5
11class RecorderCodec : public Codec {
12 public:
13 RecorderCodec(Codec& ref) : _ref(ref) {}
14
15 void init(Preamble& detector, uint32_t shortPulseUs = 600,
16 uint32_t longPulseUs = 1200, uint32_t toleranceUs = 200) override {
17 _ref.init(detector, shortPulseUs, longPulseUs, toleranceUs);
18 }
19 void setFrameSize(uint16_t size) {
20 _ref.setFrameSize(size);
21 _recordedEdges.reserve(size * getEdgeCount());
22 }
23
24 bool decodeEdge(uint32_t durationUs, bool level, uint8_t& result) override {
25 _recordedEdges.push_back({level, durationUs});
26 return _ref.decodeEdge(durationUs, level, result);
27 }
28 bool begin(uint32_t bitFrequencyHz) {
29 //_recordedEdges.clear();
30 return _ref.begin(bitFrequencyHz);
31 }
32
33 CodecEnum getCodecType() const override { return _ref.getCodecType(); }
34
35 virtual size_t getEdgeCount() const { return _ref.getEdgeCount(); }
36
37 Vector<OutputEdge>& getRecordedEdges() { return _recordedEdges; }
38
39 void clear() { _recordedEdges.clear(); }
40
41 size_t encodeBit(bool bit, Vector<OutputEdge>& output) {
42 return _ref.encodeBit(bit, output);
43 };
44
45 bool decodeByte(Vector<OutputEdge>& edges, uint8_t& result) override {
46 return _ref.decodeByte(edges, result);
47 };
48
49 void encodeByte(uint8_t byte, std::vector<bool>& bits) const override {
50 _ref.encodeByte(byte, bits);
51 }
52
53 int getEndOfFrameDelayUs() override { return _ref.getEndOfFrameDelayUs(); }
54
55 protected:
56 Codec& _ref;
57 Vector<OutputEdge> _recordedEdges;
58
59// bool bitMatch(uint32_t duration, bool bit) const override {
60// return _ref.bitMatch(duration, bit);
61// }
62};
63
64} // namespace pulsewire
Abstract base class for IR protocol encoding and decoding.
Definition Codec.h:41
virtual bool decodeEdge(uint32_t durationUs, bool level, uint8_t &result)
Edge-based decoding for protocol-agnostic RX drivers.
Definition Codec.h:106
virtual bool begin(uint32_t bitFrequencyHz)
initialization method for codecs that require setup before use (e.g., loading PIO programs,...
Definition Codec.h:56
virtual size_t encodeBit(bool bit, Vector< OutputEdge > &output)
Fill output vector with protocol-specific OutputSpec(s) for a bit.
Definition Codec.h:184
virtual int getEndOfFrameDelayUs()=0
Provide the end of frame delay in microseconds for this protocol, used by RX driver to.
virtual void init(Preamble &detector, uint32_t shortPulseUs=600, uint32_t longPulseUs=1200, uint32_t toleranceUs=200)
Definition Codec.h:49
virtual CodecEnum getCodecType() const =0
instance.
virtual bool decodeByte(Vector< OutputEdge > &edges, uint8_t &result)=0
Decode edges into a byte.
virtual size_t getEdgeCount() const =0
Get the number of protocol symbols (bits, pulses, etc.) per encoded byte.
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),...
Definition Codec.h:194
Abstract base class for preamble detection and generation.
Definition Preamble.h:40
Codec Wrapper that records all edges passed to decodeEdge() for later analysis or testing.
int getEndOfFrameDelayUs() override
Provide the end of frame delay in microseconds for this protocol, used by RX driver to.
virtual size_t getEdgeCount() const
Get the number of protocol symbols (bits, pulses, etc.) per encoded byte.
bool decodeEdge(uint32_t durationUs, bool level, uint8_t &result) override
Edge-based decoding for protocol-agnostic RX drivers.
void encodeByte(uint8_t byte, std::vector< bool > &bits) const override
Encode a byte to protocol bitstream. Default implementation encodes to raw bits (MSB first),...
void init(Preamble &detector, uint32_t shortPulseUs=600, uint32_t longPulseUs=1200, uint32_t toleranceUs=200) override
size_t encodeBit(bool bit, Vector< OutputEdge > &output)
Fill output vector with protocol-specific OutputSpec(s) for a bit.
bool decodeByte(Vector< OutputEdge > &edges, uint8_t &result) override
Decode edges into a byte.
CodecEnum getCodecType() const override
instance.
bool begin(uint32_t bitFrequencyHz)
initialization method for codecs that require setup before use (e.g., loading PIO programs,...
Small, header-only vector replacement for non-STL environments.
Definition Vector.h:29