Publish-subscribe packet router. More...
#include "spp/core/packet.h"#include "spp/core/types.h"#include "spp/core/returnTypes.h"#include "spp/services/service.h"#include "spp/util/macros.h"Go to the source code of this file.
Macros | |
| #define | K_SPP_SERVICES_PUBSUB_MAX_PRODUCERS (5U) |
| #define | K_SPP_SERVICES_PUBSUB_MAX_CONSUMERS (5U) |
| #define | K_SPP_SERVICES_PUBSUB_BUFFER_SIZE (128U) |
| #define | K_SPP_SERVICES_PUBSUB_PREEMPT_PRIORITY (1U) |
| #define | K_SPP_SERVICES_PUBSUB_STEP (1U) |
| #define | K_SPP_SERVICES_PUBSUB_SORT_START_INDEX (1U) |
| #define | K_SPP_SERVICES_PUBSUB_OFFSET (1U) |
| #define | K_SPP_SERVICES_PUBSUB_ZERO_INDEX (0) |
Publish-subscribe packet router.
Definition in file pubsub.h.
| #define K_SPP_SERVICES_PUBSUB_MAX_PRODUCERS (5U) |
Definition at line 19 of file pubsub.h.
Referenced by SPP_SERVICES_PUBSUB_registerProducer().
| #define K_SPP_SERVICES_PUBSUB_MAX_CONSUMERS (5U) |
Definition at line 20 of file pubsub.h.
Referenced by SPP_SERVICES_PUBSUB_registerConsumer().
| #define K_SPP_SERVICES_PUBSUB_BUFFER_SIZE (128U) |
Internal packet buffer depth.
Definition at line 21 of file pubsub.h.
Referenced by SPP_SERVICES_PUBSUB_publish(), and SPP_SERVICES_PUBSUB_sendToMailbox().
| #define K_SPP_SERVICES_PUBSUB_PREEMPT_PRIORITY (1U) |
Definition at line 22 of file pubsub.h.
Referenced by SPP_SERVICES_PUBSUB_callConsumers().
| #define K_SPP_SERVICES_PUBSUB_STEP (1U) |
Step to increment circular buffer index.
Definition at line 24 of file pubsub.h.
Referenced by SPP_SERVICES_PUBSUB_publish(), and SPP_SERVICES_PUBSUB_sendToMailbox().
| #define K_SPP_SERVICES_PUBSUB_SORT_START_INDEX (1U) |
Starting index for insertion sort.
Definition at line 25 of file pubsub.h.
Referenced by SPP_SERVICES_PUBSUB_sortConsumers().
| #define K_SPP_SERVICES_PUBSUB_OFFSET (1U) |
Array index offset.
Definition at line 26 of file pubsub.h.
Referenced by SPP_SERVICES_PUBSUB_sortConsumers().
| #define K_SPP_SERVICES_PUBSUB_ZERO_INDEX (0) |
Zero index/value for comparisons.
Definition at line 27 of file pubsub.h.
Referenced by 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().
| 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_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_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().
| 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_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().