Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::ConfiguredPulseConsumer Class Reference

OpenLCB Consumer class integrating a simple CDI-based configuration for a single event IDs, and an output GPIO object that will be turned on for a short period of time when the incoming event notifications arrives. More...

#include <ConfiguredConsumer.hxx>

Inheritance diagram for openlcb::ConfiguredPulseConsumer:
ConfigUpdateListener openlcb::SimpleEventHandler openlcb::Polling QMember

Public Member Functions

template<class HW >
 ConfiguredPulseConsumer (Node *node, const PulseConsumerConfig &cfg, const HW &, const Gpio *g=HW::instance())
 
 ConfiguredPulseConsumer (Node *node, const PulseConsumerConfig &cfg, const Gpio *gpio)
 
UpdateAction apply_configuration (int fd, bool initial_load, BarrierNotifiable *done) OVERRIDE
 Notifies the component that there is new configuration available for loading.
 
void factory_reset (int fd) OVERRIDE
 Clears configuration file and resets the configuration settings to factory value.
 
- Public Member Functions inherited from QMember
void init ()
 Initiailize a QMember, in place of a public placement construction.
 

Private Member Functions

void do_register ()
 Registers the event handler with the global event registry.
 
void do_unregister ()
 Removed registration of this event handler from the global event registry.
 
void handle_identify_global (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done) OVERRIDE
 Called on the need of sending out identification messages.
 
void SendConsumerIdentified (EventReport *event, BarrierNotifiable *done)
 
void handle_identify_consumer (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done) OVERRIDE
 Called on another node sending IdentifyConsumer.
 
void handle_event_report (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done) OVERRIDE
 Called on incoming EventReport messages.
 
void poll_33hz (WriteHelper *helper, Notifiable *done) OVERRIDE
 This function will be called approximately 33 times per second by the refresh loop.
 
- Private Member Functions inherited from openlcb::SimpleEventHandler
 IGNOREFN (handle_event_report)
 
 IGNOREFN (handle_consumer_identified)
 
 IGNOREFN (handle_consumer_range_identified)
 
 IGNOREFN (handle_producer_identified)
 
 IGNOREFN (handle_producer_range_identified)
 
 IGNOREFN (handle_identify_consumer)
 
 IGNOREFN (handle_identify_producer)
 
- Private Member Functions inherited from openlcb::EventHandler
virtual void handle_consumer_identified (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)
 Called on another node sending ConsumerIdentified for this event.
 
virtual void handle_consumer_range_identified (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)
 Called on another node sending ConsumerRangeIdentified.
 
virtual void handle_producer_identified (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)
 Called on another node sending ProducerIdentified for this event.
 
virtual void handle_producer_range_identified (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)
 Called on another node sending ProducerRangeIdentified for this event.
 
virtual void handle_identify_producer (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)=0
 Called on another node sending IdentifyProducer.
 

Private Attributes

Nodenode_
 
const Gpiogpio_
 
EventId event_ {0}
 
const PulseConsumerConfig cfg_
 
uint8_t pulseLength_ {1}
 
uint8_t pulseRemaining_ {0}
 

Additional Inherited Members

- Public Types inherited from ConfigUpdateListener
enum  UpdateAction { UPDATED = 0 , REINIT_NEEDED , REBOOT_NEEDED }
 Specifies what additional steps are needed to apply the new configuration. More...
 
- Protected Member Functions inherited from QMember
 QMember ()
 Constructor.
 
 ~QMember ()
 Destructor.
 
- Protected Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 
- Private Types inherited from openlcb::EventHandler
using EventReport = openlcb::EventReport
 
using EventRegistryEntry = openlcb::EventRegistryEntry
 
using EventId = openlcb::EventId
 

Detailed Description

OpenLCB Consumer class integrating a simple CDI-based configuration for a single event IDs, and an output GPIO object that will be turned on for a short period of time when the incoming event notifications arrives.

Useful for driving magnetic coil-based turnouts and signals.

Definition at line 147 of file ConfiguredConsumer.hxx.

Constructor & Destructor Documentation

◆ ConfiguredPulseConsumer() [1/2]

template<class HW >
openlcb::ConfiguredPulseConsumer::ConfiguredPulseConsumer ( Node node,
const PulseConsumerConfig &  cfg,
const HW &  ,
const Gpio g = HW::instance() 
)
inline

Definition at line 153 of file ConfiguredConsumer.hxx.

◆ ConfiguredPulseConsumer() [2/2]

openlcb::ConfiguredPulseConsumer::ConfiguredPulseConsumer ( Node node,
const PulseConsumerConfig &  cfg,
const Gpio gpio 
)
inline

Definition at line 162 of file ConfiguredConsumer.hxx.

◆ ~ConfiguredPulseConsumer()

openlcb::ConfiguredPulseConsumer::~ConfiguredPulseConsumer ( )
inline

Definition at line 171 of file ConfiguredConsumer.hxx.

Member Function Documentation

◆ apply_configuration()

UpdateAction openlcb::ConfiguredPulseConsumer::apply_configuration ( int  fd,
bool  initial_load,
BarrierNotifiable done 
)
inlinevirtual

Notifies the component that there is new configuration available for loading.

The call is made on the main executor, so the call must not block. Reading the given EEPROM device should be fine. Asynchronous operations may be implemented by using a special return status RETRY: the runner will call the same method on the same component once more after the done callback is invoked. This allows implementing state machines.

Parameters
fdis the file descriptor for the EEPROM file. The current offset in this file is unspecified, callees must do lseek.
initial_loadis true if this is the first load upon starting the binary.
donemust be notified when the call and its dependent actions are complete. No other configuration component will be called until the done callback is invoked.
Returns
any necessary action. If returns UPDATED, then assumes that the configuration change was applied. If returns RETRY, then the same call will be made again after the notifiable is called. If return REINIT_NEEDED or REBOOT_NEEDED then at the end of the configuration update process the node will be reinitialized or rebooted accordingly.

Implements ConfigUpdateListener.

Definition at line 177 of file ConfiguredConsumer.hxx.

◆ do_register()

void openlcb::ConfiguredPulseConsumer::do_register ( )
inlineprivate

Registers the event handler with the global event registry.

Definition at line 202 of file ConfiguredConsumer.hxx.

◆ do_unregister()

void openlcb::ConfiguredPulseConsumer::do_unregister ( )
inlineprivate

Removed registration of this event handler from the global event registry.

Definition at line 210 of file ConfiguredConsumer.hxx.

◆ factory_reset()

void openlcb::ConfiguredPulseConsumer::factory_reset ( int  fd)
inlinevirtual

Clears configuration file and resets the configuration settings to factory value.

Parameters
fdis the file descriptor for the EEPROM file. The current offset in this file is unspecified, callees must do lseek.

Implements ConfigUpdateListener.

Definition at line 194 of file ConfiguredConsumer.hxx.

◆ handle_event_report()

void openlcb::ConfiguredPulseConsumer::handle_event_report ( const EventRegistryEntry registry_entry,
EventReport event,
BarrierNotifiable done 
)
inlineprivatevirtual

Called on incoming EventReport messages.

Parameters
eventstores information about the incoming message. Filled: src_node, event. Mask is always 1 (filled in). state is not filled in.
registry_entrygives the registry entry for which the current handler is being called.
donemust be notified when the processing is done.

Implements openlcb::EventHandler.

Definition at line 249 of file ConfiguredConsumer.hxx.

◆ handle_identify_consumer()

void openlcb::ConfiguredPulseConsumer::handle_identify_consumer ( const EventRegistryEntry registry_entry,
EventReport event,
BarrierNotifiable done 
)
inlineprivatevirtual

Called on another node sending IdentifyConsumer.

Parameters
eventstores information about the incoming message. Filled: src_node, event, mask=1. Not filled: state.
registry_entrygives the registry entry for which the current handler is being called.
donemust be notified when the processing is done.

Implements openlcb::EventHandler.

Definition at line 239 of file ConfiguredConsumer.hxx.

◆ handle_identify_global()

void openlcb::ConfiguredPulseConsumer::handle_identify_global ( const EventRegistryEntry registry_entry,
EventReport event,
BarrierNotifiable done 
)
inlineprivatevirtual

Called on the need of sending out identification messages.

Parameters
eventis NULL. This happens on startup, or when a global or addressed IdentifyGlobal message arrives. Might have destination node id!
registry_entrygives the registry entry for which the current handler is being called.
donemust be notified when the processing is done.

Implements openlcb::EventHandler.

Definition at line 217 of file ConfiguredConsumer.hxx.

◆ poll_33hz()

void openlcb::ConfiguredPulseConsumer::poll_33hz ( WriteHelper helper,
Notifiable done 
)
inlineprivatevirtual

This function will be called approximately 33 times per second by the refresh loop.

It must notify done when it is finished using the writehelper.

Implements openlcb::Polling.

Definition at line 260 of file ConfiguredConsumer.hxx.

◆ SendConsumerIdentified()

void openlcb::ConfiguredPulseConsumer::SendConsumerIdentified ( EventReport event,
BarrierNotifiable done 
)
inlineprivate

Definition at line 228 of file ConfiguredConsumer.hxx.

Member Data Documentation

◆ cfg_

const PulseConsumerConfig openlcb::ConfiguredPulseConsumer::cfg_
private

Definition at line 277 of file ConfiguredConsumer.hxx.

◆ event_

EventId openlcb::ConfiguredPulseConsumer::event_ {0}
private

Definition at line 276 of file ConfiguredConsumer.hxx.

◆ gpio_

const Gpio* openlcb::ConfiguredPulseConsumer::gpio_
private

Definition at line 275 of file ConfiguredConsumer.hxx.

◆ node_

Node* openlcb::ConfiguredPulseConsumer::node_
private

Definition at line 274 of file ConfiguredConsumer.hxx.

◆ pulseLength_

uint8_t openlcb::ConfiguredPulseConsumer::pulseLength_ {1}
private

Definition at line 278 of file ConfiguredConsumer.hxx.

◆ pulseRemaining_

uint8_t openlcb::ConfiguredPulseConsumer::pulseRemaining_ {0}
private

Definition at line 279 of file ConfiguredConsumer.hxx.


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