Priority-aware publish-subscribe packet router implementation. More...
#include "spp/core/pubsub/pubsub.h"#include "spp/services/databank/databank.h"#include "spp/util/macros.h"#include "spp/services/log/log.h"#include "spp/core/commonbit.h"#include "spp/services/kpid.h"Go to the source code of this file.
Data Structures | |
| struct | SPP_SERVICES_PUBSUB_Producer_t |
| struct | SPP_SERVICES_PUBSUB_Consumer_t |
Functions | |
| static void | SPP_SERVICES_PUBSUB_sendToMailbox (void) |
| Copies each buffered packet to every consumer whose APID subscription matches, then resets the internal FIFO (head, tail and count back to zero). | |
| static void | SPP_SERVICES_PUBSUB_sortConsumers (void) |
| Sorts the registered consumer array in ascending priority order using insertion sort. Stable — consumers with equal priority retain their registration order. Called once during init before any dispatch. | |
| SPP_RetVal_t | SPP_SERVICES_PUBSUB_registerProducer (const SPP_SERVICE_ProducerContract_t *p_producerData, SPP_Kpid_t *p_assignedKpid) |
| SPP_RetVal_t | SPP_SERVICES_PUBSUB_registerConsumer (const SPP_SERVICE_ConsumerContract_t *p_consumerData, SPP_Kpid_t subscription) |
| void | SPP_SERVICES_PUBSUB_callProducers (void) |
| Calls acquireData on every registered producer. | |
| SPP_RetVal_t | SPP_SERVICES_PUBSUB_publish (SPP_Packet_t *p_pkt) |
| Copies a packet into the internal buffer and returns it to the databank. | |
| void | SPP_SERVICES_PUBSUB_callConsumers (void) |
| Routes all buffered packets to matching consumer mailboxes, then clears the buffer. | |
| spp_uint8_t | SPP_SERVICES_PUBSUB_queueDepth (void) |
| Returns the number of packets currently held in the internal FIFO buffer. | |
| void | SPP_SERVICES_PUBSUB_signalProducerReady (void) |
| Signals that a producer has new data pending. | |
| SPP_RetVal_t | SPP_SERVICES_PUBSUB_init (void) |
| SPP_RetVal_t | SPP_SERVICES_PUBSUB_getProducerInitResult (const SPP_SERVICE_ProducerContract_t *p_producerData, SPP_RetVal_t *p_initResult) |
| SPP_RetVal_t | SPP_SERVICES_PUBSUB_getConsumerInitResult (const SPP_SERVICE_ConsumerContract_t *p_consumerData, SPP_RetVal_t *p_initResult) |
Variables | |
| static SPP_SERVICES_PUBSUB_Producer_t | s_producers [K_SPP_SERVICES_PUBSUB_MAX_PRODUCERS] = {0} |
| static spp_uint16_t | s_registeredProducers = 0U |
| static SPP_SERVICES_PUBSUB_Consumer_t | s_consumers [K_SPP_SERVICES_PUBSUB_MAX_CONSUMERS] = {0} |
| static spp_uint8_t | s_registeredConsumers = 0U |
| static SPP_Packet_t | s_packetBuffer [K_SPP_SERVICES_PUBSUB_BUFFER_SIZE] |
| static spp_uint8_t | s_bufferHead = 0U |
| static spp_uint8_t | s_bufferTail = 0U |
| static spp_uint8_t | s_bufferCount = 0U |
| static volatile spp_bool_t | s_producerReady = false |
Priority-aware publish-subscribe packet router implementation.
Definition in file pubsub.c.
|
static |
Copies each buffered packet to every consumer whose APID subscription matches, then resets the internal FIFO (head, tail and count back to zero).
Iterates the circular packet buffer from head to head+count. For each packet it walks the registered consumer list and performs a bitmask check on suscribeToApid vs primaryHeader.apid. On a match the full SPP_Packet_t is copied by value into the consumer's p_mailBox. When all consumers have been served the buffer is cleared.
Definition at line 271 of file pubsub.c.
References K_SPP_SERVICES_PUBSUB_BUFFER_SIZE, K_SPP_SERVICES_PUBSUB_STEP, s_bufferCount, s_bufferHead, s_consumers, s_packetBuffer, s_registeredConsumers, SPP_Packet_t, and SPP_SERVICES_PUBSUB_sendToMailbox().
Referenced by SPP_SERVICES_PUBSUB_callConsumers(), and SPP_SERVICES_PUBSUB_sendToMailbox().
|
static |
Sorts the registered consumer array in ascending priority order using insertion sort. Stable — consumers with equal priority retain their registration order. Called once during init before any dispatch.
Definition at line 300 of file pubsub.c.
References K_SPP_SERVICES_PUBSUB_OFFSET, K_SPP_SERVICES_PUBSUB_SORT_START_INDEX, K_SPP_SERVICES_PUBSUB_ZERO_INDEX, SPP_SERVICES_PUBSUB_Consumer_t::p_contract, SPP_SERVICE_ConsumerContract_t::priority, s_consumers, s_registeredConsumers, and SPP_SERVICES_PUBSUB_sortConsumers().
Referenced by SPP_SERVICES_PUBSUB_init(), and SPP_SERVICES_PUBSUB_sortConsumers().
| SPP_RetVal_t SPP_SERVICES_PUBSUB_registerProducer | ( | const SPP_SERVICE_ProducerContract_t * | p_producerData, |
| SPP_Kpid_t * | p_assignedKpid ) |
Definition at line 58 of file pubsub.c.
References SPP_SERVICES_PUBSUB_Producer_t::initResult, K_SPP_ERROR, K_SPP_ERROR_NOT_INITIALIZED, K_SPP_ERROR_NULL_POINTER, K_SPP_ERROR_REGISTRY_FULL, K_SPP_OK, K_SPP_SERVICES_PUBSUB_MAX_PRODUCERS, SPP_SERVICES_PUBSUB_Producer_t::kpid, SPP_SERVICES_PUBSUB_Producer_t::p_contract, s_producers, s_registeredProducers, SPP_SERVICES_PUBSUB_registerProducer(), and SPP_Kpid_t::value.
Referenced by CUSTOM_registerConsumerProducer(), and SPP_SERVICES_PUBSUB_registerProducer().
| SPP_RetVal_t SPP_SERVICES_PUBSUB_registerConsumer | ( | const SPP_SERVICE_ConsumerContract_t * | p_consumerData, |
| SPP_Kpid_t | subscription ) |
Definition at line 94 of file pubsub.c.
References SPP_SERVICES_PUBSUB_Consumer_t::initResult, K_SPP_ERROR, K_SPP_ERROR_NOT_INITIALIZED, K_SPP_ERROR_NULL_POINTER, K_SPP_ERROR_REGISTRY_FULL, K_SPP_OK, K_SPP_SERVICES_PUBSUB_MAX_CONSUMERS, SPP_SERVICES_PUBSUB_Consumer_t::p_contract, s_consumers, s_registeredConsumers, SPP_SERVICES_PUBSUB_registerConsumer(), and SPP_SERVICES_PUBSUB_Consumer_t::subcription.
Referenced by SPP_SERVICES_PUBSUB_registerConsumer().
| void SPP_SERVICES_PUBSUB_callProducers | ( | void | ) |
Calls acquireData on every registered producer.
Definition at line 119 of file pubsub.c.
References SPP_SERVICES_PUBSUB_Producer_t::kpid, s_producerReady, s_producers, s_registeredProducers, and SPP_SERVICES_PUBSUB_callProducers().
Referenced by SPP_SERVICES_PUBSUB_callProducers(), and statefunction_bmpPerformanceLoop().
| SPP_RetVal_t SPP_SERVICES_PUBSUB_publish | ( | SPP_Packet_t * | p_pkt | ) |
Copies a packet into the internal buffer and returns it to the databank.
Called by producers after filling a packet. The packet is copied by value into the next free slot of the internal circular buffer; the original is returned to the databank pool immediately. Returns K_SPP_ERROR if the buffer is full (packet is still returned to the pool).
| p_pkt | Packet to publish (ownership transferred — do not use after this call). |
Definition at line 128 of file pubsub.c.
References K_SPP_ERROR, K_SPP_ERROR_NULL_POINTER, K_SPP_OK, K_SPP_SERVICES_PUBSUB_BUFFER_SIZE, K_SPP_SERVICES_PUBSUB_STEP, s_bufferCount, s_bufferTail, s_packetBuffer, SPP_Packet_t, SPP_SERVICES_DATABANK_returnPacket(), and SPP_SERVICES_PUBSUB_publish().
Referenced by action_emitTelemetry(), SPP_SERVICES_BMP390_acquireData(), SPP_SERVICES_BMP390_DUMMY_acquireData(), SPP_SERVICES_ICM20948_acquireData(), and SPP_SERVICES_PUBSUB_publish().
| void SPP_SERVICES_PUBSUB_callConsumers | ( | void | ) |
Routes all buffered packets to matching consumer mailboxes, then clears the buffer.
Definition at line 152 of file pubsub.c.
References K_SPP_SERVICES_PUBSUB_PREEMPT_PRIORITY, s_consumers, s_producerReady, s_registeredConsumers, SPP_SERVICES_PUBSUB_callConsumers(), and SPP_SERVICES_PUBSUB_sendToMailbox().
Referenced by SPP_SERVICES_PUBSUB_callConsumers(), and statefunction_bmpPerformanceLoop().
| spp_uint8_t SPP_SERVICES_PUBSUB_queueDepth | ( | void | ) |
Returns the number of packets currently held in the internal FIFO buffer.
Definition at line 172 of file pubsub.c.
References s_bufferCount, and SPP_SERVICES_PUBSUB_queueDepth().
Referenced by SPP_SERVICES_PUBSUB_queueDepth(), and statefunction_bmpPerformanceLoop().
| void SPP_SERVICES_PUBSUB_signalProducerReady | ( | void | ) |
Signals that a producer has new data pending.
Must be called from within acquireData() as soon as a DRDY flag is detected, so that callConsumers() can preempt consumers with priority > K_SPP_SERVICES_PUBSUB_PREEMPT_PRIORITY.
Definition at line 177 of file pubsub.c.
References s_producerReady, and SPP_SERVICES_PUBSUB_signalProducerReady().
Referenced by SPP_SERVICES_PUBSUB_signalProducerReady().
| SPP_RetVal_t SPP_SERVICES_PUBSUB_init | ( | void | ) |
Definition at line 182 of file pubsub.c.
References SPP_SERVICE_ConsumerContract_t::init, SPP_SERVICE_ProducerContract_t::init, SPP_SERVICES_PUBSUB_Consumer_t::initResult, SPP_SERVICES_PUBSUB_Producer_t::initResult, K_SPP_ERROR, K_SPP_OK, SPP_SERVICES_PUBSUB_Consumer_t::p_contract, SPP_SERVICES_PUBSUB_Producer_t::p_contract, s_consumers, s_producers, s_registeredConsumers, s_registeredProducers, SPP_SERVICES_PUBSUB_init(), and SPP_SERVICES_PUBSUB_sortConsumers().
Referenced by SPP_CORE_init(), and SPP_SERVICES_PUBSUB_init().
| SPP_RetVal_t SPP_SERVICES_PUBSUB_getProducerInitResult | ( | const SPP_SERVICE_ProducerContract_t * | p_producerData, |
| SPP_RetVal_t * | p_initResult ) |
Definition at line 220 of file pubsub.c.
References SPP_SERVICES_PUBSUB_Producer_t::initResult, K_SPP_ERROR, K_SPP_ERROR_NULL_POINTER, K_SPP_OK, s_producers, s_registeredProducers, and SPP_SERVICES_PUBSUB_getProducerInitResult().
Referenced by CUSTOM_initCheck(), and SPP_SERVICES_PUBSUB_getProducerInitResult().
| SPP_RetVal_t SPP_SERVICES_PUBSUB_getConsumerInitResult | ( | const SPP_SERVICE_ConsumerContract_t * | p_consumerData, |
| SPP_RetVal_t * | p_initResult ) |
Definition at line 239 of file pubsub.c.
References SPP_SERVICES_PUBSUB_Consumer_t::initResult, K_SPP_ERROR, K_SPP_ERROR_NULL_POINTER, K_SPP_OK, s_consumers, s_registeredConsumers, and SPP_SERVICES_PUBSUB_getConsumerInitResult().
Referenced by SPP_SERVICES_PUBSUB_getConsumerInitResult().
|
static |
Definition at line 36 of file pubsub.c.
Referenced by SPP_SERVICES_PUBSUB_callProducers(), SPP_SERVICES_PUBSUB_getProducerInitResult(), SPP_SERVICES_PUBSUB_init(), and SPP_SERVICES_PUBSUB_registerProducer().
|
static |
Definition at line 37 of file pubsub.c.
Referenced by SPP_SERVICES_PUBSUB_callProducers(), SPP_SERVICES_PUBSUB_getProducerInitResult(), SPP_SERVICES_PUBSUB_init(), and SPP_SERVICES_PUBSUB_registerProducer().
|
static |
Definition at line 38 of file pubsub.c.
Referenced by SPP_SERVICES_PUBSUB_callConsumers(), SPP_SERVICES_PUBSUB_getConsumerInitResult(), SPP_SERVICES_PUBSUB_init(), SPP_SERVICES_PUBSUB_registerConsumer(), SPP_SERVICES_PUBSUB_sendToMailbox(), and SPP_SERVICES_PUBSUB_sortConsumers().
|
static |
Definition at line 39 of file pubsub.c.
Referenced by SPP_SERVICES_PUBSUB_callConsumers(), SPP_SERVICES_PUBSUB_getConsumerInitResult(), SPP_SERVICES_PUBSUB_init(), SPP_SERVICES_PUBSUB_registerConsumer(), SPP_SERVICES_PUBSUB_sendToMailbox(), and SPP_SERVICES_PUBSUB_sortConsumers().
|
static |
Definition at line 41 of file pubsub.c.
Referenced by SPP_SERVICES_DATALOGGER_consumeData(), SPP_SERVICES_DATALOGGER_deliverToMailbox(), SPP_SERVICES_PUBSUB_publish(), and SPP_SERVICES_PUBSUB_sendToMailbox().
|
static |
Definition at line 42 of file pubsub.c.
Referenced by SPP_SERVICES_PUBSUB_sendToMailbox().
|
static |
Definition at line 43 of file pubsub.c.
Referenced by SPP_SERVICES_PUBSUB_publish().
|
static |
Definition at line 44 of file pubsub.c.
Referenced by SPP_SERVICES_PUBSUB_publish(), SPP_SERVICES_PUBSUB_queueDepth(), and SPP_SERVICES_PUBSUB_sendToMailbox().
|
static |
Definition at line 46 of file pubsub.c.
Referenced by SPP_SERVICES_PUBSUB_callConsumers(), SPP_SERVICES_PUBSUB_callProducers(), and SPP_SERVICES_PUBSUB_signalProducerReady().