Solaris Software
Loading...
Searching...
No Matches
datalogger.c
Go to the documentation of this file.
1/**
2 * @file datalogger.c
3 * @brief SD card packet logger — SPP consumer service implementation.
4 */
5
7
9#include "spp/hal/spi/spi.h"
10#include "spp/core/packet.h"
12#include "spp/core/types.h"
14
15#include <string.h>
16
17/* ----------------------------------------------------------------
18* CONSTANTS
19* ---------------------------------------------------------------- */
21static spp_uint8_t s_packetIndex = 0; /**< Index of the next packet to be written to the buffer. */
22static spp_uint32_t s_currentDataSector = 0; /**< Current sector of the data log. */
24 K_DATALOGGER_BUFFER_SIZE / K_DATALOGGER_SECTOR_SIZE; /**< Number of blocks written to the current sector. */
26
27
28/* ----------------------------------------------------------------
29 * STATIC FUNCTIONS DECLARATIONS
30 * ---------------------------------------------------------------- */
34
35/* ----------------------------------------------------------------
36 * VARIABLES
37 * ---------------------------------------------------------------- */
40 .p_nameConsumer = "datalogger",
41 .tiemoutMs = K_DATALOGGER_TIMEOUT_MS,
45};
46
47/* ----------------------------------------------------------------
48 * PUBLIC FUNCTIONS
49 * ---------------------------------------------------------------- */
54
59
60/* ----------------------------------------------------------------
61 * STATIC FUNCTIONS
62 * ---------------------------------------------------------------- */
63
64/**
65 * @brief Initializes the SD card storage and resets the logging indices.
66 * @return Result returned by the storage HAL initialization.
67 */
69{
70 /* Init the variables */
72 s_packetIndex = 0;
73
74 /* Initialize SD card storage. */
77 {
78 return s_initStatus;
79 }
80 return K_SPP_OK;
81}
82
83/**
84 * @brief Copies a received packet into the internal logging buffer.
85 * @param packet Packet dispatched by PUBSUB.
86 * @return K_SPP_OK.
87 */
89{
90 /* Copy the packets into the buffer*/
93 return K_SPP_OK;
94}
95
96/**
97 * @brief Writes the buffered packets to consecutive SD card sectors when full.
98 *
99 * On successful writing, advances the sector index and resets the buffer.
100 * On failure, retains the buffered packets for a later attempt.
101 *
102 * @param p_data Unused.
103 * @return K_SPP_OK, regardless of the storage write result.
104 */
const SPP_SERVICE_ConsumerContract_t * SPP_SERVICES_DATALOGGER_getConsumerContract(void)
Returns the datalogger consumer contract.
Definition datalogger.c:50
SPP_RetVal_t SPP_SERVICES_DATALOGGER_getInitStatus(void)
Returns the stored SD card initialization status.
Definition datalogger.c:55
static spp_uint32_t s_currentDataSector
Definition datalogger.c:22
static spp_uint16_t s_blocksWritten
Definition datalogger.c:23
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_uint8_t s_packetIndex
Definition datalogger.c:21
static const SPP_SERVICE_ConsumerContract_t g_dataloggerConsumerContract
Definition datalogger.c:38
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
SD card packet logger service.
#define K_DATALOGGER_CONSUMER_PRIO
Definition datalogger.h:17
#define K_DATALOGGER_FIRST_SECTOR
Definition datalogger.h:20
#define K_DATALOGGER_BUFFER_PACKETS
Definition datalogger.h:22
#define K_DATALOGGER_SECTOR_SIZE
Definition datalogger.h:19
#define K_DATALOGGER_TIMEOUT_MS
Definition datalogger.h:18
#define K_DATALOGGER_BUFFER_SIZE
Definition datalogger.h:21
Finite State Machine (FSM) module for the SPP core.
SPP logging service.
Solaris Packet Protocol (SPP) packet structure definitions.
SPP_Packet_t
Definition packet.h:79
#define K_SPP_TOTAL_PACKET_SIZE
Definition packet.h:29
static SPP_Packet_t s_packetBuffer[K_SPP_SERVICES_PUBSUB_BUFFER_SIZE]
Definition pubsub.c:37
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition returnTypes.h:24
@ K_SPP_ERROR_NOT_INITIALIZED
Definition returnTypes.h:31
@ K_SPP_OK
Definition returnTypes.h:25
static SPP_RetVal_t s_initStatus
Definition uart.c:32
SPP SPI HAL API — dispatches through the registered HAL port.
SPP_RetVal_t SPP_HAL_STORAGE_init(void)
Initializes the storage device through the registered HAL port.
Definition storage.c:18
SPP_RetVal_t SPP_HAL_STORAGE_write(const void *p_buffer, spp_uint32_t first_block, spp_uint16_t count)
Writes consecutive storage blocks through the HAL.
Definition storage.c:38
SPP storage HAL API — dispatches through the registered HAL port.
Describes the contract of a consumer module. This module needs to have:
Definition service.h:40
Portable integer types and SPI/storage configuration types for SPP.
uint16_t spp_uint16_t
Definition types.h:29
uint32_t spp_uint32_t
Definition types.h:31
uint8_t spp_uint8_t
Definition types.h:27