RC5 Demo
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
RC5Receiver Class Reference

Class that accumulates individual bits into RC5 telegrams. More...

#include <rc5receiver.h>

Inheritance diagram for RC5Receiver:
BitDetector::BitHandler

Classes

class  TelegramHandler
 

Public Member Functions

 RC5Receiver (TimerManager *timerManager, InputPin *samplePin, ExternalInterrupt *extInterrupt, TelegramHandler *handler)
 
void init (void)
 
void deinit (void)
 
virtual void onBitDetected (Bit bit) override
 
virtual void onEvent (const Event &event) override
 

Private Types

enum  EventIds { TELEGRAM_TIMEOUT_ELAPSED }
 Events used by this component. More...
 
enum  State { NOT_INITIALIZED, WAIT_FOR_START_BIT, RECEIVE_BIT_STREAM }
 States of internal state machine. More...
 

Private Member Functions

void setState (State state)
 

Private Attributes

TimerManagerm_timerManager
 Reference to TimerManager. More...
 
TelegramHandlerm_handler
 Reference to TelegramHandler. More...
 
BitDetector m_detector
 BitDetector instance. More...
 
BitBuffer< uint16_t, 14 > m_buffer
 Internal buffer to accumulate bits in telegram. More...
 
OneShotTimer< uint8_t > m_telegramTimeout
 Timer to monitor telegram timeout. More...
 
State m_state
 State of internal state machine. More...
 

Detailed Description

Class that accumulates individual bits into RC5 telegrams.

The RC5Receiver implements the BitHandler interface provided by the BitDetector. It takes the bits and stores them inside a BitBuffer until a set of 14 bits forming a RC5 telegram is complete. Then it is wrapped inside a RC5Telegram instance and passed via the TelegramHandler interface.

When the first bit of a telegram is detected, a 30ms timer is started. In case this timer elapses, reception of the current RC5 telegram is discarded and the BitBuffer is cleared (a regular telegram should not exceed 24,889 ms in length). This makes the application more robust against faulty transmissions and noise on the signal line.

The RC5Receiver implements this state machine:

Member Enumeration Documentation

◆ EventIds

enum RC5Receiver::EventIds
private

Events used by this component.

Enumerator
TELEGRAM_TIMEOUT_ELAPSED 

Event for elapsed telegram timeout.

◆ State

enum RC5Receiver::State
private

States of internal state machine.

Enumerator
NOT_INITIALIZED 

Not initialized.

WAIT_FOR_START_BIT 

Waiting for start bit (1)

RECEIVE_BIT_STREAM 

Receiving remaining bits of telegram.

Constructor & Destructor Documentation

◆ RC5Receiver()

RC5Receiver::RC5Receiver ( TimerManager timerManager,
InputPin *  samplePin,
ExternalInterrupt *  extInterrupt,
TelegramHandler handler 
)
inline

Constructor. Most of the parameters are passed to the BitDetector member.

Parameters
[in]timerManagerTimerManager instance to use
[in]samplePinInputPin connected to TSOP IC
[in]extInterruptExternalInterrupt instance to manage interrupts on samplePin line
[in]handlerHandler that receives the accumulated RC5 telegrams

Member Function Documentation

◆ deinit()

void RC5Receiver::deinit ( void  )
inline

Deinitialization. Enters NOT_INITIALIZED state and deinitializes BitDetector.

◆ init()

void RC5Receiver::init ( void  )
inline

Initialization. Enters WAIT_FOR_START_BIT state and initializes BitDetector.

◆ onBitDetected()

virtual void RC5Receiver::onBitDetected ( Bit  bit)
inlineoverridevirtual

Handler for detected bits. Implements the state transitions triggered by detected bits.

Parameters
[in]bitDetected bit

Implements BitDetector::BitHandler.

◆ onEvent()

virtual void RC5Receiver::onEvent ( const Event &  event)
inlineoverridevirtual

Event handler. Receives the notification event when the timeout elapsed. Implements state transition back to WAIT_FOR_START_BIT.

Parameters
[in]eventEvent to handle

◆ setState()

void RC5Receiver::setState ( State  state)
inlineprivate

Sets internal state machine state. Implements the On Entry actions.

Parameters
[in]stateState to set

Member Data Documentation

◆ m_buffer

BitBuffer<uint16_t,14> RC5Receiver::m_buffer
private

Internal buffer to accumulate bits in telegram.

◆ m_detector

BitDetector RC5Receiver::m_detector
private

BitDetector instance.

◆ m_handler

TelegramHandler* RC5Receiver::m_handler
private

Reference to TelegramHandler.

◆ m_state

State RC5Receiver::m_state
private

State of internal state machine.

◆ m_telegramTimeout

OneShotTimer<uint8_t> RC5Receiver::m_telegramTimeout
private

Timer to monitor telegram timeout.

◆ m_timerManager

TimerManager* RC5Receiver::m_timerManager
private

Reference to TimerManager.


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