LCC Fusion Project 1.0
LCC Automation
Loading...
Searching...
No Matches
TurnoutConfiguredPC Class Reference

Consumer class for all turnout motors, for all turnout cards. More...

#include <TurnoutConfiguredPC.h>

Inheritance diagram for TurnoutConfiguredPC:
Collaboration diagram for TurnoutConfiguredPC:

Public Types

typedef TurnoutCardConfig CardConfig_type
 
typedef TurnoutConfig TurnoutConfig_type
 

Public Member Functions

template<unsigned NUM_CARDS>
 TurnoutConfiguredPC (openlcb::Node *pNode, const openlcb::RepeatedGroup< CardConfig_type, NUM_CARDS > &configOffset, uint8_t numDevicesPerCard, EventDeviceTypes eventDeviceType, const char *cardDescription) __attribute__((noinline))
 constructor More...
 
 ~TurnoutConfiguredPC ()
 destructor
 
UpdateAction apply_configuration (int fd, bool initial_load, BarrierNotifiable *done) OVERRIDE
 Invoked on initial load of CDI and when CDI is udpated. Register configured events with OpenMRN. More...
 
void factory_reset (int fd) OVERRIDE
 Reset CDI configuration entries to their initial (default) values. More...
 
bool ensureUniqueI2cOffset (uint8_t cardIndex, uint8_t bus, uint8_t offset)
 

Public Attributes

union I2cCardHelper::EventUserArgsUnion userArgs
 

Protected Member Functions

void drive_pin (uint8_t card, uint8_t pin, bool set) override
 
void _do_unregister ()
 Unregisters this event handler from the global registry.
 
void handle_identify_consumer (const openlcb::EventRegistryEntry &registry_entry, openlcb::EventReport *event, BarrierNotifiable *done) OVERRIDE
 Process request to identify produced events.
 
void handle_identify_producer (const openlcb::EventRegistryEntry &registry_entry, openlcb::EventReport *event, BarrierNotifiable *done) OVERRIDE
 Process request to identify produced events.
 
void applyI2cInfo (int fd, uint8_t cardIndex, i2cInfoConfig_type cfgI2cInfoRef)
 sets up the MCP card's I2C connection using the user provided (CDI) configuration information (bus and address offset) More...
 
void resetCardInfo (int fd, cardInfoConfig_type cfgI2cInfoRef)
 resets the card configuration information (description field). More...
 
void resetI2cInfo (int fd, i2cInfoConfig_type cfgI2cInfoRef)
 resets the card's I2C configuration information (bus and address fields). More...
 
virtual void drive_pin_ext (uint8_t card, uint8_t pin, bool set, uint8_t intArg)
 
EventUserArgsUnion unpack_user_args (const openlcb::EventRegistryEntry &re) const
 Small helper to unpack our 4-byte user_arg payload from the registry entry.
 
void handle_event_report (const openlcb::EventRegistryEntry &registry_entry, openlcb::EventReport *event, BarrierNotifiable *done) OVERRIDE
 

Private Member Functions

void SendEventIdentified (const openlcb::EventRegistryEntry &registry_entry, openlcb::EventReport *event, BarrierNotifiable *done) OVERRIDE
 Sends out a either a Producer or Consumer Identified message for the given registration entry Identification is based on the corresponding event's pin direction; producer identified if pin diredction is INPUT, otherwise consumer for pin direction = OUTPUT. More...
 
void _setPowerOnState (uint8_t cardNum, uint8_t pinNum, DefaultDeviceSettings::DeviceStates state)
 Sets the power-on state for a specific pin on a specific card. More...
 
void _initI2cCards (bool isProducer)
 Initializes the array of I2C card objects using the configured card type. More...
 

Private Attributes

DefaultDeviceSettings defaultDeviceSettings_
 Shadow copy of the event IDs produced by each of the UOD cards.
 

Detailed Description

Consumer class for all turnout motors, for all turnout cards.

Definition at line 106 of file TurnoutConfiguredPC.h.

Member Typedef Documentation

◆ CardConfig_type

typedef TurnoutCardConfig TurnoutConfiguredPC::CardConfig_type

Type for turnout card configuration entry

Definition at line 109 of file TurnoutConfiguredPC.h.

◆ TurnoutConfig_type

Type for turnout configuration entry

Definition at line 110 of file TurnoutConfiguredPC.h.

Constructor & Destructor Documentation

◆ TurnoutConfiguredPC()

template<unsigned NUM_CARDS>
TurnoutConfiguredPC::TurnoutConfiguredPC ( openlcb::Node *  pNode,
const openlcb::RepeatedGroup< CardConfig_type, NUM_CARDS > &  configOffset,
uint8_t  numDevicesPerCard,
EventDeviceTypes  eventDeviceType,
const char *  cardDescription 
)
inline

constructor

Parameters
pNodeOpenLCB node object from the stack
configOffsetrepeated group object from the configuration space that represents all the events for each turnout motor, for all turnout cards
numDevicesPerCardnumber of turnouts configured for each Turnout Card.
eventDeviceTypeEventDeviceTypes value identify the type of device, used when setting default event ID
cardDescriptionis the human-friendly card description for log messages and debug output ( e.g. "Turnout Card").
Usage:
REGISTER_CARD(TurnoutConfiguredPC, cfg.turnoutCardsSeg().turnoutCardConfig(), "Consumer/Producer", "Turnout Card", NUM_TURNOUTS_PER_CARD, EventDeviceTypes::TURNOUT)
#define REGISTER_CARD(_ClassName, _CdiCardConfig, _CardType, _CardDescription, _CardNumDevices, _Card_Event_Type)
creates a unqiue name for the objects used in registering the card, then registers the card
Consumer class for all turnout motors, for all turnout cards.

Definition at line 127 of file TurnoutConfiguredPC.h.

Member Function Documentation

◆ _initI2cCards()

void I2cCardHelper::_initI2cCards ( bool  isProducer)
inlineprivateinherited

Initializes the array of I2C card objects using the configured card type.

Allocates and initializes each I2C card in the array to the type specified by the cardType_ member. If isProducer is true, registers each card's polling callback.

Parameters
isProducerTrue if the card is used as a producer and requires polling.

Definition at line 460 of file I2cCardHelper.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _setPowerOnState()

void TurnoutConfiguredPC::_setPowerOnState ( uint8_t  cardNum,
uint8_t  pinNum,
DefaultDeviceSettings::DeviceStates  state 
)
inlineprivate

Sets the power-on state for a specific pin on a specific card.

This function configures the initial state of a pin (on, off, or previous state) when the system powers on. It supports three initial states: ON (active), OFF (inactive), and PREVIOUS (the state before the last power down). For the PREVIOUS state, it reads the saved state from a persistent storage I2cCardHelper::pinStates[cardNum]. The function updates the I2cCardHelper::pinStates[cardNum] element to reflect the current state for future reference if the state is ON or OFF.

Parameters
cardNumThe card number on which the pin resides. This is used to index into the i2cCards array of I2C card helpers.
pinNumThe pin number to set the state for. This should be within the valid range for the card.
stateThe desired initial state of the pin specified by the DefaultDeviceSettings::DeviceStates enum.

Definition at line 362 of file TurnoutConfiguredPC.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ apply_configuration()

UpdateAction TurnoutConfiguredPC::apply_configuration ( int  fd,
bool  initial_load,
BarrierNotifiable *  done 
)
inline

Invoked on initial load of CDI and when CDI is udpated. Register configured events with OpenMRN.

Parameters
fdfile descriptor used to access CDI data
initial_loadis true when CDI is loaded after a reboot
done

Definition at line 159 of file TurnoutConfiguredPC.h.

Here is the call graph for this function:

◆ applyI2cInfo()

void I2cCardHelper::applyI2cInfo ( int  fd,
uint8_t  cardIndex,
i2cInfoConfig_type  cfgI2cInfoRef 
)
inlineprotectedinherited

sets up the MCP card's I2C connection using the user provided (CDI) configuration information (bus and address offset)

Note
producer/consumers apply_configuration() callback invoke this method to initialize the I2C / MCP connection information for the card
all I2C connected cards have CDI section for user provided bus and address information (which must match the settings of the I2C enabeled card)
HOOK: Typical call site is within your apply_configuration() loop:
  • read bus & offset from CDI
  • initialize the corresponding i2cCards[cardIndex]
Parameters
fdfile handle to access the CDI configuration information (provided by openmrn)
cardIndexspecifies which card the configuration is for. Used to update the i2cCards[] array and initialize the connection
cfgI2cInfoRefoffset into the intenal configuration space for the CDI configuration for the MCP card

Definition at line 295 of file I2cCardHelper.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drive_pin()

void TurnoutConfiguredPC::drive_pin ( uint8_t  card,
uint8_t  pin,
bool  set 
)
inlineoverrideprotectedvirtual

Hook for consumers: drive one output pin (simple case). Default does nothing; simple consumers override this.

Parameters
cardcard index (as stored in user_arg)
pinpin index (as stored in user_arg)
setdesired logical state from the event semantics (SET/ON = true, CLR/OFF = false)

Reimplemented from I2cCardHelper.

Definition at line 281 of file TurnoutConfiguredPC.h.

Here is the call graph for this function:

◆ drive_pin_ext()

virtual void I2cCardHelper::drive_pin_ext ( uint8_t  card,
uint8_t  pin,
bool  set,
uint8_t  intArg 
)
inlineprotectedvirtualinherited

Extended hook for consumers that also need the CDI intArg (e.g., audio message index). Default forwards to drive_pin(...) so existing consumers remain unchanged.

Reimplemented in AudioConfiguredConsumer.

Definition at line 402 of file I2cCardHelper.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ensureUniqueI2cOffset()

bool I2cCardHelper::ensureUniqueI2cOffset ( uint8_t  cardIndex,
uint8_t  bus,
uint8_t  offset 
)
inlineinherited

Check for duplicate offsets on the same I2C bus. Automatically resets the tracker on the first call per config pass.

Remarks
Call this once per card during your apply_configuration loop, with the CDI values.
Parameters
cardIndexIndex of the card in the config loop.
busI2C bus number (0 or 1).
offsetI2C offset (0–7).
Returns
true if this (bus, offset) was already claimed.

Definition at line 183 of file I2cCardHelper.h.

Here is the caller graph for this function:

◆ factory_reset()

void TurnoutConfiguredPC::factory_reset ( int  fd)
inline

Reset CDI configuration entries to their initial (default) values.

Parameters
fdused to access the CDI information in the file system

Definition at line 244 of file TurnoutConfiguredPC.h.

Here is the call graph for this function:

◆ handle_event_report()

void I2cCardHelper::handle_event_report ( const openlcb::EventRegistryEntry &  registry_entry,
openlcb::EventReport *  event,
BarrierNotifiable *  done 
)
inlineprotectedinherited

Default consumer handler: maps an incoming Event Report to (card,pin,set,intArg) and calls drive_pin_ext(...). Producers are ignored.

Definition at line 418 of file I2cCardHelper.h.

Here is the call graph for this function:

◆ resetCardInfo()

void I2cCardHelper::resetCardInfo ( int  fd,
cardInfoConfig_type  cfgI2cInfoRef 
)
inlineprotectedinherited

resets the card configuration information (description field).

Note
invoke from the consumer/producer factory_reset() to reset the card configuration
Parameters
fdfile handle to access the CDI configuration information (provided by openmrn)
cfgI2cInfoRefoffset into the intenal configuration space for the CDI configuration block for the card's info (description, etc)

Definition at line 309 of file I2cCardHelper.h.

Here is the caller graph for this function:

◆ resetI2cInfo()

void I2cCardHelper::resetI2cInfo ( int  fd,
i2cInfoConfig_type  cfgI2cInfoRef 
)
inlineprotectedinherited

resets the card's I2C configuration information (bus and address fields).

Note
invoke from the consumer/producer factory_reset() to reset the card configuration
Parameters
fdfile handle to access the CDI configuration information (provided by openmrn)
cfgI2cInfoRefoffset into the intenal configuration space for the CDI configuration for card's I2C info (bus/offset)

Definition at line 321 of file I2cCardHelper.h.

Here is the caller graph for this function:

◆ SendEventIdentified()

void TurnoutConfiguredPC::SendEventIdentified ( const openlcb::EventRegistryEntry &  registry_entry,
openlcb::EventReport *  event,
BarrierNotifiable *  done 
)
inlineprivatevirtual

Sends out a either a Producer or Consumer Identified message for the given registration entry Identification is based on the corresponding event's pin direction; producer identified if pin diredction is INPUT, otherwise consumer for pin direction = OUTPUT.

Parameters
registry_entrycontains information about the event, including the 'user' argument set during apply_configuration()
eventobject handle for the event
done

Reimplemented from I2cCardHelper.

Definition at line 330 of file TurnoutConfiguredPC.h.

Here is the call graph for this function:

Member Data Documentation

◆ userArgs

union I2cCardHelper::EventUserArgsUnion I2cCardHelper::userArgs
inherited

event arguments


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