Arduino PulseWire Transceiver Library
Loading...
Searching...
No Matches
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
pulsewire::RZCodec Class Reference

#include <RZCodec.h>

Inheritance diagram for pulsewire::RZCodec:
Inheritance graph
[legend]
Collaboration diagram for pulsewire::RZCodec:
Collaboration graph
[legend]

Public Member Functions

 RZCodec (int stopBits=1)
 
 RZCodec (Preamble &preambleDetector, int stopBits=1)
 
CodecEnum getCodecType () const override
 
bool getIdleLevel () const override
 Provides the initial ldle state (low or hith)
 
size_t getEdgeCount () const override
 Get the number of protocol symbols (bits, pulses, etc.) per encoded byte.
 
int getEndOfFrameDelayUs () override
 
void reset () override
 Reset the internal state of the codec.
 
size_t encode (uint8_t byte, Vector< OutputEdge > &output) override
 Fill output vector with protocol-specific OutputSpec(s) for a byte.
 
bool decodeEdge (uint32_t durationUs, bool level, uint8_t &result) override
 Edge-based decoding for protocol-agnostic RX drivers.
 
virtual void init (Preamble &detector, uint32_t shortPulseUs=600, uint32_t longPulseUs=1200, uint32_t toleranceUs=200)
 
virtual bool begin (uint32_t bitFrequencyHz)
 initialization method for codecs that require setup before use (e.g., loading PIO programs, configuring state machines).
 
void setPreamble (Preamble &preamble)
 Set the Preamble Detector object.
 
PreamblegetPreamble ()
 Get the preamble detector associated with this codec.
 
void setFrameSize (uint16_t size)
 Set the Frame Size.
 
uint16_t getFrameSize () const
 Get the configured frame size.
 
const charname () const
 Get the name of the codec type as a string (e.g., "PulseDistance", "Manchester").
 
size_t encodePreamble (Vector< OutputEdge > &output)
 
virtual size_t flushEncoder (Vector< OutputEdge > &output)
 Flush any pending encoder state at end of frame.
 

Protected Types

enum  { WAIT_START , DATA_BITS , STOP_BITS }
 

Protected Member Functions

bool isValidPeriod (uint32_t pulse, uint32_t target, uint32_t tolerance) const
 
bool handleFrameStart (bool level, uint32_t durationUs)
 
bool handleInFrameDecoding (uint32_t durationUs, bool level, uint8_t &result)
 
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), but can be overridden by protocols that require different bit formatting (e.g., Manchester). The output bits are stored in.
 

Protected Attributes

uint8_t _stopBits = 1
 
uint8_t _bitCount = 0
 
uint8_t _byte = 0
 
RingBuffer< OutputEdge_edgeBuffer {32}
 
enum pulsewire::RZCodec:: { ... }  _rxState = WAIT_START
 
uint8_t _rxDataBitCount = 0
 
uint8_t _rxStopBitCount = 0
 
CustomPreambleUs _defaultPreamble
 
Preamble_preamble = &_defaultPreamble
 
uint16_t _bitFrequencyHz = 0
 
uint32_t _bitPeriodUs = 0
 
Vector< OutputEdge_decodeEdgeStream
 
volatile bool _inFrame = false
 
uint16_t _frameSize = 0
 

Detailed Description

Return-to-Zero (RZ) Codec implementation. Each bit is represented by a pulse (high) for half the bit period, then zero (low) for the other half.

Definition at line 12 of file RZCodec.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected

Definition at line 111 of file RZCodec.h.

Constructor & Destructor Documentation

◆ RZCodec() [1/2]

pulsewire::RZCodec::RZCodec ( int  stopBits = 1)
inline

Definition at line 14 of file RZCodec.h.

◆ RZCodec() [2/2]

pulsewire::RZCodec::RZCodec ( Preamble preambleDetector,
int  stopBits = 1 
)
inline

Definition at line 16 of file RZCodec.h.

Member Function Documentation

◆ begin()

virtual bool pulsewire::Codec::begin ( uint32_t  bitFrequencyHz)
inlinevirtualinherited

initialization method for codecs that require setup before use (e.g., loading PIO programs, configuring state machines).

Reimplemented in pulsewire::RecorderCodec, pulsewire::DifferentialManchesterCodec, pulsewire::ManchesterCodec, pulsewire::PulseDistanceCodec, and pulsewire::PulseWidthCodec.

Definition at line 70 of file Codec.h.

◆ decodeEdge()

bool pulsewire::RZCodec::decodeEdge ( uint32_t  durationUs,
bool  level,
uint8_t result 
)
inlineoverridevirtual

Edge-based decoding for protocol-agnostic RX drivers.

Called on each signal edge (duration since last edge, new level, minUs, maxUs). The codec maintains its own state and assembles frames internally.

Parameters
durationUsTime in microseconds since last edge.
levelNew logic level after the edge (true = HIGH, false = LOW).
frameBufferOutput buffer for decoded frame (if available).
frameBufferSizeSize of frameBuffer (bytes).
frameLenSet to decoded frame length if a frame is available.
Returns
True if a complete frame is decoded and available in frameBuffer.

Implements pulsewire::Codec.

Definition at line 81 of file RZCodec.h.

◆ encode()

size_t pulsewire::RZCodec::encode ( uint8_t  byte,
Vector< OutputEdge > &  output 
)
inlineoverridevirtual

Fill output vector with protocol-specific OutputSpec(s) for a byte.

Encodes the byte to protocol bits and appends OutputSpec(s) for each bit.

Parameters
byteThe byte to encode.
outputVector to append OutputSpec(s).
Returns
Number of OutputSpec entries added.

Implements pulsewire::Codec.

Definition at line 39 of file RZCodec.h.

◆ encodeByte()

virtual void pulsewire::Codec::encodeByte ( uint8_t  byte,
std::vector< bool > &  bits 
) const
inlineprotectedvirtualinherited

Encode a byte to protocol bitstream. Default implementation encodes to raw bits (MSB first), but can be overridden by protocols that require different bit formatting (e.g., Manchester). The output bits are stored in.

Parameters
byteThe input byte to encode.
bitsOutput buffer for encoded bits (protocol-specific format).

Definition at line 204 of file Codec.h.

◆ encodePreamble()

size_t pulsewire::Codec::encodePreamble ( Vector< OutputEdge > &  output)
inlineinherited

Definition at line 157 of file Codec.h.

◆ flushEncoder()

virtual size_t pulsewire::Codec::flushEncoder ( Vector< OutputEdge > &  output)
inlinevirtualinherited

Flush any pending encoder state at end of frame.

Some codecs (e.g., Miller) accumulate pending duration that must be output at the end of the frame. This method outputs any remaining pending state. Default implementation does nothing.

Parameters
outputVector to append OutputSpec(s).
Returns
Number of OutputSpec entries added.

Reimplemented in pulsewire::MillerCodec.

Definition at line 185 of file Codec.h.

◆ getCodecType()

CodecEnum pulsewire::RZCodec::getCodecType ( ) const
inlineoverridevirtual

Get the codec type (e.g., PulseDistance, Manchester) for this Codec instance.

Implements pulsewire::Codec.

Definition at line 21 of file RZCodec.h.

◆ getEdgeCount()

size_t pulsewire::RZCodec::getEdgeCount ( ) const
inlineoverridevirtual

Get the number of protocol symbols (bits, pulses, etc.) per encoded byte.

Returns
Number of protocol symbols per byte.

Implements pulsewire::Codec.

Definition at line 25 of file RZCodec.h.

◆ getEndOfFrameDelayUs()

int pulsewire::RZCodec::getEndOfFrameDelayUs ( )
inlineoverridevirtual

Provide the end of frame delay in microseconds for this protocol, used by RX driver to

Implements pulsewire::Codec.

Definition at line 27 of file RZCodec.h.

◆ getFrameSize()

uint16_t pulsewire::Codec::getFrameSize ( ) const
inlineinherited

Get the configured frame size.

Definition at line 120 of file Codec.h.

◆ getIdleLevel()

bool pulsewire::RZCodec::getIdleLevel ( ) const
inlineoverridevirtual

Provides the initial ldle state (low or hith)

Reimplemented from pulsewire::Codec.

Definition at line 23 of file RZCodec.h.

◆ getPreamble()

Preamble & pulsewire::Codec::getPreamble ( )
inlineinherited

Get the preamble detector associated with this codec.

Returns
Reference to the Preamble instance used for preamble detection.

Definition at line 100 of file Codec.h.

◆ handleFrameStart()

bool pulsewire::RZCodec::handleFrameStart ( bool  level,
uint32_t  durationUs 
)
inlineprotected

Definition at line 122 of file RZCodec.h.

◆ handleInFrameDecoding()

bool pulsewire::RZCodec::handleInFrameDecoding ( uint32_t  durationUs,
bool  level,
uint8_t result 
)
inlineprotected

Definition at line 141 of file RZCodec.h.

◆ init()

virtual void pulsewire::Codec::init ( Preamble detector,
uint32_t  shortPulseUs = 600,
uint32_t  longPulseUs = 1200,
uint32_t  toleranceUs = 200 
)
inlinevirtualinherited

Used by IRTransceiver to initialize codec with protocol-specific parameters

Reimplemented in pulsewire::PulseWidthCodec, pulsewire::PulseDistanceCodec, and pulsewire::RecorderCodec.

Definition at line 63 of file Codec.h.

◆ isValidPeriod()

bool pulsewire::RZCodec::isValidPeriod ( uint32_t  pulse,
uint32_t  target,
uint32_t  tolerance 
) const
inlineprotected

Definition at line 116 of file RZCodec.h.

◆ name()

const char * pulsewire::Codec::name ( ) const
inlineinherited

Get the name of the codec type as a string (e.g., "PulseDistance", "Manchester").

Definition at line 135 of file Codec.h.

◆ reset()

void pulsewire::RZCodec::reset ( )
inlineoverridevirtual

Reset the internal state of the codec.

Reimplemented from pulsewire::Codec.

Definition at line 29 of file RZCodec.h.

◆ setFrameSize()

void pulsewire::Codec::setFrameSize ( uint16_t  size)
inlineinherited

Set the Frame Size.

Parameters
size

Definition at line 114 of file Codec.h.

◆ setPreamble()

void pulsewire::Codec::setPreamble ( Preamble preamble)
inlineinherited

Set the Preamble Detector object.

Parameters
preamble

Definition at line 94 of file Codec.h.

Field Documentation

◆ _bitCount

uint8_t pulsewire::RZCodec::_bitCount = 0
protected

Definition at line 108 of file RZCodec.h.

◆ _bitFrequencyHz

uint16_t pulsewire::Codec::_bitFrequencyHz = 0
protectedinherited

Definition at line 190 of file Codec.h.

◆ _bitPeriodUs

uint32_t pulsewire::Codec::_bitPeriodUs = 0
protectedinherited

Definition at line 191 of file Codec.h.

◆ _byte

uint8_t pulsewire::RZCodec::_byte = 0
protected

Definition at line 109 of file RZCodec.h.

◆ _decodeEdgeStream

Vector<OutputEdge> pulsewire::Codec::_decodeEdgeStream
protectedinherited

Definition at line 192 of file Codec.h.

◆ _defaultPreamble

CustomPreambleUs pulsewire::Codec::_defaultPreamble
protectedinherited

Definition at line 188 of file Codec.h.

◆ _edgeBuffer

RingBuffer<OutputEdge> pulsewire::RZCodec::_edgeBuffer {32}
protected

Definition at line 110 of file RZCodec.h.

◆ _frameSize

uint16_t pulsewire::Codec::_frameSize = 0
protectedinherited

Definition at line 194 of file Codec.h.

◆ _inFrame

volatile bool pulsewire::Codec::_inFrame = false
protectedinherited

Definition at line 193 of file Codec.h.

◆ _preamble

Preamble* pulsewire::Codec::_preamble = &_defaultPreamble
protectedinherited

Definition at line 189 of file Codec.h.

◆ _rxDataBitCount

uint8_t pulsewire::RZCodec::_rxDataBitCount = 0
protected

Definition at line 112 of file RZCodec.h.

◆ _rxStopBitCount

uint8_t pulsewire::RZCodec::_rxStopBitCount = 0
protected

Definition at line 113 of file RZCodec.h.

◆ _stopBits

uint8_t pulsewire::RZCodec::_stopBits = 1
protected

Definition at line 107 of file RZCodec.h.


The documentation for this class was generated from the following file: