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

Producer implementation for BSD cards. More...

#include <BsdConfiguredProducer.h>

Inheritance diagram for BsdConfiguredProducer:
Collaboration diagram for BsdConfiguredProducer:

Classes

struct  SensorRange
 Holds configured min/max range values for all sensors on a card. More...
 

Public Types

typedef BsdCardConfig CardConfig_type
 
typedef BsdLineConfig LineGroupConfig_type
 

Public Member Functions

template<unsigned NUM_CARDS>
 BsdConfiguredProducer (openlcb::Node *node, const openlcb::RepeatedGroup< CardConfig_type, NUM_CARDS > &configOffset, uint8_t numDevicesPerCard, EventDeviceTypes eventDeviceType, const char *cardDescription) __attribute__((noinline))
 Construct a BSD configured producer. More...
 
UpdateAction apply_configuration (int fd, bool initial_load, BarrierNotifiable *done) override
 Reads CDI, registers events, initializes I²C and debouncers. More...
 
void factory_reset (int fd) override
 Factory reset: defaults + fresh producer Event IDs for each line.
 
bool ensureUniqueI2cOffset (uint8_t cardIndex, uint8_t bus, uint8_t offset)
 

Public Attributes

union I2cCardHelper::EventUserArgsUnion userArgs
 

Protected Member Functions

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.
 
virtual void SendEventIdentified (const openlcb::EventRegistryEntry &registry_entry, openlcb::EventReport *event, BarrierNotifiable *done)
 Sends Producer- or Consumer-Identified for registry_entry. More...
 
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 (uint8_t card, uint8_t pin, bool set)
 
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 _sendSensorRangesIfNeeded (uint8_t cardIndex)
 Initialize (or re-initialize) sending trip level handling and I²C callbacks for one card. More...
 
bool _sendSensorRanges (uint8_t cardIndex)
 Sends the configured min/max distance ranges to a BSD Card. More...
 
bool _updateSensorValues (uint8_t cardIndex)
 Fetch a 2-byte sensor word from a card and split it into globals. More...
 
bool _processShortState (int cardIndex, int deviceIndex)
 Debounce + dispatch SHORT on one line.
 
bool _processOccupancyState (int cardIndex, int deviceIndex)
 Debounce + dispatch OCCUPANCY on one line (suppressed while short is active).
 
void _initI2cCards (bool isProducer)
 Initializes the array of I2C card objects using the configured card type. More...
 

Detailed Description

Producer implementation for BSD cards.

Lifecycle:

  • apply_configuration reads CDI, registers events, initializes I²C helpers and debouncers.
  • See also
    poll_33hz kicks the polling FSM (~33 Hz) which calls
    notify().
  • See also
    notify iterates cards and lines, reading I²C once per card and invoking
    processCardSensors with the “one event per tick” rule.

Definition at line 150 of file BsdConfiguredProducer.h.

Member Typedef Documentation

◆ CardConfig_type

Type for the BSD card CDI configuration entry

Definition at line 153 of file BsdConfiguredProducer.h.

◆ LineGroupConfig_type

Type for the BSD CDI configuration entry

Definition at line 154 of file BsdConfiguredProducer.h.

Constructor & Destructor Documentation

◆ BsdConfiguredProducer()

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

Construct a BSD configured producer.

Template Parameters
NUM_CARDSnumber of BSD cards managed by this instance
Parameters
nodeowning OpenLCB node
configOffsetCDI repeated-group offset for
See also
BsdCardConfig
Parameters
numDevicesPerCardnumber of lines per card
eventDeviceTypedevice type for default event allocation
cardDescriptiontext descripton of the card - "BSD CARD"

Definition at line 165 of file BsdConfiguredProducer.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:

◆ _sendSensorRanges()

bool BsdConfiguredProducer::_sendSensorRanges ( uint8_t  cardIndex)
inlineprivate

Sends the configured min/max distance ranges to a BSD Card.

Copies the contents of

See also
sensorRange_ into a temporary buffer and transmits it over I²C to the specified card. The card uses these thresholds to evaluate sensor distance readings against occupancy detection criteria.
Parameters
cardIndexIndex of the BSD Card to receive the range data.
Returns
true when range sent successfully

Definition at line 398 of file BsdConfiguredProducer.h.

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

◆ _sendSensorRangesIfNeeded()

void BsdConfiguredProducer::_sendSensorRangesIfNeeded ( uint8_t  cardIndex)
inlineprivate

Initialize (or re-initialize) sending trip level handling and I²C callbacks for one card.

Sends the relay's trip level once, clears the resend flag needsRange_, and registers connect/disconnect callbacks so we resend trip level after a reconnect.

Definition at line 368 of file BsdConfiguredProducer.h.

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

◆ _updateSensorValues()

bool BsdConfiguredProducer::_updateSensorValues ( uint8_t  cardIndex)
inlineprivate

Fetch a 2-byte sensor word from a card and split it into globals.

Parameters
cardIndexcard index
Returns
true if the I²C read succeeded (offline cards still return 0 via helper)

Definition at line 421 of file BsdConfiguredProducer.h.

Here is the call graph for this function:

◆ apply_configuration()

UpdateAction BsdConfiguredProducer::apply_configuration ( int  fd,
bool  initial_load,
BarrierNotifiable *  done 
)
inlineoverride

Reads CDI, registers events, initializes I²C and debouncers.

Parameters
fdconfig file descriptor
initial_loadtrue on cold start
donebarrier notifiable
Returns
REINIT_NEEDED to trigger event identify

Definition at line 208 of file BsdConfiguredProducer.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()

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

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 in IoConfiguredPC, OutputConfiguredConsumer, ServoConfiguredConsumer, TurnoutConfiguredPC, and NeoPixelConfiguredConsumer.

Definition at line 392 of file I2cCardHelper.h.

Here is the caller 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:

◆ 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()

virtual void I2cCardHelper::SendEventIdentified ( const openlcb::EventRegistryEntry &  registry_entry,
openlcb::EventReport *  event,
BarrierNotifiable *  done 
)
inlineprotectedvirtualinherited

Sends Producer- or Consumer-Identified for registry_entry.

Identification type is inferred from the registry entry’s packed user args (see

See also
isProducer). Override to customize the MTI or payload.

Reimplemented in TurnoutConfiguredPC.

Definition at line 273 of file I2cCardHelper.h.

Here is the call graph for this function:
Here is the caller 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: