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

Differential Manchester encoding/decoding utility class for IR communication. More...

#include <DifferentialManchesterCodec.h>

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

Public Member Functions

 DifferentialManchesterCodec (Preamble &preambleDetector)
 
bool begin (uint16_t bitFrequencyHz) override
 initialization method for codecs that require setup before use (e.g., loading PIO programs, configuring state machines).
 
CodecEnum getCodecType () const override
 instance.
 
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 averaging edge durations and applying decodeEdge() logic to the average. This allows for robust decoding even in noisy environments where multiple edges may be detected.
 
int getEndOfFrameDelayUs () override
 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)
 
PreamblegetPreamble ()
 Get the preamble detector associated with this codec.
 
void setPreamble (Preamble &preamble)
 Set the Preamble Detector object.
 
size_t encodePreamble (Vector< OutputEdge > &output)
 
virtual size_t encode (uint8_t byte, Vector< OutputEdge > &output)
 Fill output vector with protocol-specific OutputSpec(s) for a byte.
 
void setFrameSize (uint16_t size)
 
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.
 
const charname () const
 Get the name of the codec type as a string (e.g., "PulseDistance", "Manchester").
 

Protected Member Functions

size_t encodeBit (bool bit, Vector< OutputEdge > &output) override
 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.
 
void reset () override
 
bool getIdleLevel () const override
 Provides the initial ldle state (low or hith)
 
size_t getEdgeCount () const override
 Get the number of edges used to encode a byte (16 for Manchester).
 

Protected Attributes

bool _lastLevelEncode = false
 
bool _lastLevelDecode = false
 
CustomPreambleUs _defaultPreamble
 
Preamble_preamble = &_defaultPreamble
 
uint16_t _bitFrequencyHz = 0
 
uint32_t _bitPeriodUs = 0
 
Vector< OutputEdge_decodeEdgeStream
 
volatile bool _inFrame = false
 

Detailed Description

Differential Manchester encoding/decoding utility class for IR communication.

Definition at line 14 of file DifferentialManchesterCodec.h.

Constructor & Destructor Documentation

◆ DifferentialManchesterCodec()

pulsewire::DifferentialManchesterCodec::DifferentialManchesterCodec ( Preamble preambleDetector)
inline

Definition at line 16 of file DifferentialManchesterCodec.h.

Member Function Documentation

◆ begin()

bool pulsewire::DifferentialManchesterCodec::begin ( uint16_t  bitFrequencyHz)
inlineoverridevirtual

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

Reimplemented from pulsewire::Codec.

Definition at line 19 of file DifferentialManchesterCodec.h.

◆ decodeByte()

bool pulsewire::DifferentialManchesterCodec::decodeByte ( Vector< OutputEdge > &  edges,
uint8_t result 
)
inlineoverrideprotectedvirtual

Decode edges into a byte.

Implements pulsewire::Codec.

Definition at line 55 of file DifferentialManchesterCodec.h.

◆ decodeEdge()

bool pulsewire::ManchesterCodec::decodeEdge ( uint32_t  durationUs,
bool  level,
uint8_t result 
)
inlineoverridevirtualinherited

Decode incoming edges to reconstruct bytes. Handles multiple edges per bit for noise tolerance by averaging edge durations and applying decodeEdge() logic to the average. This allows for robust decoding even in noisy environments where multiple edges may be detected.

Parameters
durationUs
level
result
Returns
true
false

Reimplemented from pulsewire::Codec.

Definition at line 50 of file ManchesterCodec.h.

◆ encode()

virtual size_t pulsewire::Codec::encode ( uint8_t  byte,
Vector< OutputEdge > &  output 
)
inlinevirtualinherited

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.

Reimplemented in pulsewire::NRZCodec.

Definition at line 162 of file Codec.h.

◆ encodeBit()

size_t pulsewire::DifferentialManchesterCodec::encodeBit ( bool  bit,
Vector< OutputEdge > &  output 
)
inlineoverrideprotectedvirtual

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

Parameters
bitThe bit to encode (true/false).
outputVector to append OutputSpec(s).
Returns
Number of OutputSpec entries added.

Reimplemented from pulsewire::Codec.

Definition at line 31 of file DifferentialManchesterCodec.h.

◆ encodeByte()

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

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).

Reimplemented in pulsewire::RecorderCodec.

Definition at line 194 of file Codec.h.

◆ encodePreamble()

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

Definition at line 146 of file Codec.h.

◆ getCodecType()

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

instance.

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

Implements pulsewire::Codec.

Definition at line 24 of file DifferentialManchesterCodec.h.

◆ getEdgeCount()

size_t pulsewire::ManchesterCodec::getEdgeCount ( ) const
inlineoverrideprotectedvirtualinherited

Get the number of edges used to encode a byte (16 for Manchester).

Implements pulsewire::Codec.

Definition at line 78 of file ManchesterCodec.h.

◆ getEndOfFrameDelayUs()

int pulsewire::ManchesterCodec::getEndOfFrameDelayUs ( )
inlineoverridevirtualinherited

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

Implements pulsewire::Codec.

Definition at line 72 of file ManchesterCodec.h.

◆ getIdleLevel()

bool pulsewire::DifferentialManchesterCodec::getIdleLevel ( ) const
inlineoverrideprotectedvirtual

Provides the initial ldle state (low or hith)

Reimplemented from pulsewire::Codec.

Definition at line 84 of file DifferentialManchesterCodec.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 77 of file Codec.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 49 of file Codec.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 218 of file Codec.h.

◆ reset()

void pulsewire::DifferentialManchesterCodec::reset ( )
inlineoverrideprotectedvirtual

Reimplemented from pulsewire::Codec.

Definition at line 78 of file DifferentialManchesterCodec.h.

◆ setFrameSize()

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

Definition at line 173 of file Codec.h.

◆ setPreamble()

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

Set the Preamble Detector object.

Parameters
preamble

Definition at line 84 of file Codec.h.

Field Documentation

◆ _bitFrequencyHz

uint16_t pulsewire::Codec::_bitFrequencyHz = 0
protectedinherited

Definition at line 224 of file Codec.h.

◆ _bitPeriodUs

uint32_t pulsewire::Codec::_bitPeriodUs = 0
protectedinherited

Definition at line 225 of file Codec.h.

◆ _decodeEdgeStream

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

Definition at line 226 of file Codec.h.

◆ _defaultPreamble

CustomPreambleUs pulsewire::Codec::_defaultPreamble
protectedinherited

Definition at line 222 of file Codec.h.

◆ _inFrame

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

Definition at line 227 of file Codec.h.

◆ _lastLevelDecode

bool pulsewire::DifferentialManchesterCodec::_lastLevelDecode = false
protected

Definition at line 90 of file DifferentialManchesterCodec.h.

◆ _lastLevelEncode

bool pulsewire::DifferentialManchesterCodec::_lastLevelEncode = false
protected

Definition at line 89 of file DifferentialManchesterCodec.h.

◆ _preamble

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

Definition at line 223 of file Codec.h.


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