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. */
23static spp_uint16_t s_blocksWritten = 0; /**< Number of blocks written to the current sector. */
25
26
27/* ----------------------------------------------------------------
28 * STATIC FUNCTIONS DECLARATIONS
29 * ---------------------------------------------------------------- */
33
34/* ----------------------------------------------------------------
35 * VARIABLES
36 * ---------------------------------------------------------------- */
39 .p_nameConsumer = "datalogger",
40 .tiemoutMs = K_DATALOGGER_TIMEOUT_MS,
41 .suscribeToApid = 0U,
45};
46
47/* ----------------------------------------------------------------
48 * PUBLIC FUNCTIONS
49 * ---------------------------------------------------------------- */
54
59
60/* ----------------------------------------------------------------
61 * STATIC FUNCTIONS
62 * ---------------------------------------------------------------- */
63/**
64 * @brief Initialise the SD card and open the log file for writing.
65 * @return K_SPP_OK on success, K_SPP_ERROR on mount or file-open failure.
66 */
68{
70 if (p_fsmErrors == NULL)
71 {
73 }
74 /* Init the variables */
76 s_packetIndex = 0;
78
79 /* Init SPI for SD card */
82 {
83 p_fsmErrors->dataloggerInitError = 1;
84 return s_initStatus;
85 }
86 return K_SPP_OK;
87}
88
89/**
90 * @brief Receive a packet from the pub/sub router into the consumer mailbox.
91 * @param p_pkt Packet dispatched by the router.
92 * @return K_SPP_OK on success, K_SPP_ERROR_NULL_POINTER if p_pkt is NULL.
93 */
95{
96 /* Copy the packets into the buffer*/
99 return K_SPP_OK;
100}
101
102/**
103 * @brief Consume a packet from the mailbox and write it to the SD card log file.
104 * @param p_data Unused (context pointer reserved for future use).
105 * @return K_SPP_OK on success, K_SPP_ERROR if the file is not open or write fails.
106 */
const SPP_SERVICE_ConsumerContract_t * SPP_SERVICES_DATALOGGER_getConsumerContract(void)
Definition datalogger.c:50
SPP_RetVal_t SPP_SERVICES_DATALOGGER_getInitStatus(void)
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)
Consume a packet from the mailbox and write it to the SD card log file.
Definition datalogger.c:107
static spp_uint8_t s_packetIndex
Definition datalogger.c:21
static const SPP_SERVICE_ConsumerContract_t g_dataloggerConsumerContract
Definition datalogger.c:37
static SPP_RetVal_t SPP_SERVICES_DATALOGGER_init(void)
Initialise the SD card and open the log file for writing.
Definition datalogger.c:67
static SPP_RetVal_t s_initStatus
Definition datalogger.c:24
static SPP_RetVal_t SPP_SERVICES_DATALOGGER_deliverToMailbox(const SPP_Packet_t packet)
Receive a packet from the pub/sub router into the consumer mailbox.
Definition datalogger.c:94
SD card packet logger service.
#define K_DATALOGGER_CONSUMER_PRIO
Definition datalogger.h:17
#define K_DATALOGGER_FIRST_SECTOR
Definition datalogger.h:21
#define K_DATALOGGER_TIMEOUT_MS
Definition datalogger.h:18
#define K_DATALOGGER_BUFFER_SIZE
Definition datalogger.h:22
spp_uint16_t * SPP_CORE_FSM_getErrorsBit(void)
Get the pointer to the FSM errors bit.
Definition fsm.c:33
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:41
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
@ K_SPP_ERROR_NULL_POINTER
Definition returnTypes.h:30
SPP SPI HAL API — dispatches through the registered HAL port.
SPP_RetVal_t SPP_HAL_STORAGE_init(void)
Definition storage.c:18
SPP_RetVal_t SPP_HAL_STORAGE_write(const void *p_buffer, spp_uint32_t first_block, spp_uint16_t count)
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:43
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