Solaris Software
Loading...
Searching...
No Matches
datalogger.c File Reference

SD card packet logger — SPP consumer service implementation. More...

#include "spp/services/datalogger/datalogger.h"
#include "spp/hal/storage/storage.h"
#include "spp/hal/spi/spi.h"
#include "spp/core/packet.h"
#include "spp/services/log/log.h"
#include "spp/core/types.h"
#include "spp/services/fsm/fsm.h"
#include <string.h>
Include dependency graph for datalogger.c:

Go to the source code of this file.

Functions

static SPP_RetVal_t SPP_SERVICES_DATALOGGER_init (void)
 Initializes the SD card storage and resets the logging indices.
static SPP_RetVal_t SPP_SERVICES_DATALOGGER_deliverToMailbox (const SPP_Packet_t packet)
 Copies a received packet into the internal logging buffer.
static SPP_RetVal_t SPP_SERVICES_DATALOGGER_consumeData (void *p_data)
 Writes the buffered packets to consecutive SD card sectors when full.
const SPP_SERVICE_ConsumerContract_t * SPP_SERVICES_DATALOGGER_getConsumerContract (void)
 Returns the datalogger consumer contract.
SPP_RetVal_t SPP_SERVICES_DATALOGGER_getInitStatus (void)
 Returns the stored SD card initialization status.

Variables

static SPP_Packet_t s_packetBuffer [K_DATALOGGER_BUFFER_PACKETS]
static spp_uint8_t s_packetIndex = 0
static spp_uint32_t s_currentDataSector = 0
static spp_uint16_t s_blocksWritten
static SPP_RetVal_t s_initStatus = K_SPP_ERROR_NOT_INITIALIZED
static const SPP_SERVICE_ConsumerContract_t g_dataloggerConsumerContract

Detailed Description

SD card packet logger — SPP consumer service implementation.

Definition in file datalogger.c.

Function Documentation

◆ SPP_SERVICES_DATALOGGER_init()

SPP_RetVal_t SPP_SERVICES_DATALOGGER_init ( void )
static

Initializes the SD card storage and resets the logging indices.

Returns
Result returned by the storage HAL initialization.

Definition at line 68 of file datalogger.c.

References K_DATALOGGER_FIRST_SECTOR, K_SPP_OK, s_currentDataSector, s_initStatus, s_packetIndex, SPP_HAL_STORAGE_init(), and SPP_SERVICES_DATALOGGER_init().

Referenced by SPP_SERVICES_DATALOGGER_init().

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

◆ SPP_SERVICES_DATALOGGER_deliverToMailbox()

SPP_RetVal_t SPP_SERVICES_DATALOGGER_deliverToMailbox ( const SPP_Packet_t packet)
static

Copies a received packet into the internal logging buffer.

Parameters
packetPacket dispatched by PUBSUB.
Returns
K_SPP_OK.

Definition at line 88 of file datalogger.c.

References K_SPP_OK, s_packetBuffer, s_packetIndex, SPP_Packet_t, and SPP_SERVICES_DATALOGGER_deliverToMailbox().

Referenced by SPP_SERVICES_DATALOGGER_deliverToMailbox().

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

◆ SPP_SERVICES_DATALOGGER_consumeData()

SPP_RetVal_t SPP_SERVICES_DATALOGGER_consumeData ( void * p_data)
static

Writes the buffered packets to consecutive SD card sectors when full.

On successful writing, advances the sector index and resets the buffer. On failure, retains the buffered packets for a later attempt.

Parameters
p_dataUnused.
Returns
K_SPP_OK, regardless of the storage write result.

Definition at line 105 of file datalogger.c.

References K_DATALOGGER_BUFFER_SIZE, K_SPP_OK, K_SPP_TOTAL_PACKET_SIZE, s_blocksWritten, s_currentDataSector, s_packetBuffer, s_packetIndex, SPP_HAL_STORAGE_write(), and SPP_SERVICES_DATALOGGER_consumeData().

Referenced by SPP_SERVICES_DATALOGGER_consumeData().

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

◆ SPP_SERVICES_DATALOGGER_getConsumerContract()

const SPP_SERVICE_ConsumerContract_t * SPP_SERVICES_DATALOGGER_getConsumerContract ( void )

Returns the datalogger consumer contract.

Returns
Pointer to the statically allocated consumer contract.

Definition at line 50 of file datalogger.c.

References g_dataloggerConsumerContract, and SPP_SERVICES_DATALOGGER_getConsumerContract().

Referenced by CUSTOM_registerConsumerProducer(), guard_startInitializationOfModules(), and SPP_SERVICES_DATALOGGER_getConsumerContract().

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

◆ SPP_SERVICES_DATALOGGER_getInitStatus()

SPP_RetVal_t SPP_SERVICES_DATALOGGER_getInitStatus ( void )

Returns the stored SD card initialization status.

Returns
K_SPP_ERROR_NOT_INITIALIZED before initialization, or the result returned by the storage HAL.

Definition at line 55 of file datalogger.c.

References s_initStatus, and SPP_SERVICES_DATALOGGER_getInitStatus().

Referenced by SPP_SERVICES_DATALOGGER_getInitStatus().

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

Variable Documentation

◆ s_packetBuffer

SPP_Packet_t s_packetBuffer[K_DATALOGGER_BUFFER_PACKETS]
static

Definition at line 20 of file datalogger.c.

◆ s_packetIndex

spp_uint8_t s_packetIndex = 0
static

Index of the next packet to be written to the buffer.

Definition at line 21 of file datalogger.c.

Referenced by SPP_SERVICES_DATALOGGER_consumeData(), SPP_SERVICES_DATALOGGER_deliverToMailbox(), and SPP_SERVICES_DATALOGGER_init().

◆ s_currentDataSector

spp_uint32_t s_currentDataSector = 0
static

Current sector of the data log.

Definition at line 22 of file datalogger.c.

Referenced by SPP_SERVICES_DATALOGGER_consumeData(), and SPP_SERVICES_DATALOGGER_init().

◆ s_blocksWritten

spp_uint16_t s_blocksWritten
static
Initial value:
=
#define K_DATALOGGER_SECTOR_SIZE
Definition datalogger.h:19
#define K_DATALOGGER_BUFFER_SIZE
Definition datalogger.h:21

Number of blocks written to the current sector.

Definition at line 23 of file datalogger.c.

Referenced by SPP_SERVICES_DATALOGGER_consumeData().

◆ s_initStatus

Definition at line 25 of file datalogger.c.

◆ g_dataloggerConsumerContract

const SPP_SERVICE_ConsumerContract_t g_dataloggerConsumerContract
static
Initial value:
= {
.p_nameConsumer = "datalogger",
}
static SPP_RetVal_t SPP_SERVICES_DATALOGGER_consumeData(void *p_data)
Writes the buffered packets to consecutive SD card sectors when full.
Definition datalogger.c:105
static SPP_RetVal_t SPP_SERVICES_DATALOGGER_init(void)
Initializes the SD card storage and resets the logging indices.
Definition datalogger.c:68
static SPP_RetVal_t SPP_SERVICES_DATALOGGER_deliverToMailbox(const SPP_Packet_t packet)
Copies a received packet into the internal logging buffer.
Definition datalogger.c:88
#define K_DATALOGGER_CONSUMER_PRIO
Definition datalogger.h:17
#define K_DATALOGGER_TIMEOUT_MS
Definition datalogger.h:18

Definition at line 38 of file datalogger.c.

Referenced by SPP_SERVICES_DATALOGGER_getConsumerContract().