Contiki 3.x
Functions
store.h File Reference

Convenience layer for storing readings and the config. More...

#include "contiki.h"
#include <stdint.h>
#include <stdbool.h>
#include "settings.pb.h"
#include "readings.pb.h"

Go to the source code of this file.

Functions

void store_init (void)
 Initialize the data store. More...
 
uint16_t store_save_sample (Sample *sample)
 Store a sample in the flash. More...
 
bool store_get_sample (uint16_t id, Sample *sample)
 Get a given sample from the flash,. More...
 
uint8_t store_get_raw_sample (uint16_t id, uint8_t buffer[Sample_size])
 Get a given sample from the flash, in the form of an encoded protocol buffer. More...
 
bool store_get_latest_sample (Sample *sample)
 Get the most recent sample from the flash. More...
 
uint8_t store_get_latest_raw_sample (uint8_t buffer[Sample_size])
 Get the most recent sample from the flash, in the form of an encoded protocol buffer. More...
 
uint16_t store_get_latest_sample_id (void)
 Get the identifer of the most recent sample stored. More...
 
bool store_delete_sample (uint16_t id)
 Delete a given sample from the flash. More...
 
bool store_save_config (SensorConfig *config)
 Save the configuration to flash. More...
 
bool store_get_config (SensorConfig *config)
 Get the configuration from the flash. More...
 
uint8_t store_get_raw_config (uint8_t buffer[SensorConfig_size])
 Get the configuration from the flash. More...
 

Detailed Description

Convenience layer for storing readings and the config.

Implements locking, and SPI sharing with the CC1120 driver.

Every sample is assigned a unique id for it's lifetime on flash. The id of a sample may be reused once it has been deleted. The store allows deleting any given sample, by gracefully dealing with files that do not exist.

Callers are always responsible for allocating the required memory.

Author
Arthur Fabre af1g1.nosp@m.2@ec.nosp@m.s.sot.nosp@m.on.a.nosp@m.c.uk

Definition in file store.h.

Function Documentation

bool store_delete_sample ( uint16_t  id)

Delete a given sample from the flash.

Parameters
idThe id of the sample to delete.
Returns
true on success, false otherwise.

Definition at line 174 of file store.c.

Referenced by res_delete_handler().

bool store_get_config ( SensorConfig *  config)

Get the configuration from the flash.

Parameters
*config.The configuration to write to.
Returns
true on success, false otherwise.

Definition at line 249 of file store.c.

uint8_t store_get_latest_raw_sample ( uint8_t  buffer[Sample_size])

Get the most recent sample from the flash, in the form of an encoded protocol buffer.

Parameters
bufferAn allocated buffer at last Sample_size big to which the sample protocol buffer will be written.
Returns
The number of bytes written to the buffer on success, false otherwise.

Definition at line 135 of file store.c.

Referenced by res_get_handler().

bool store_get_latest_sample ( Sample *  sample)

Get the most recent sample from the flash.

Parameters
*sampleThe Sample to write the sample to.
Returns
true on success, false otherwise.

Definition at line 131 of file store.c.

uint16_t store_get_latest_sample_id ( void  )

Get the identifer of the most recent sample stored.

Returns
The identifier of the latest sample.

Definition at line 170 of file store.c.

uint8_t store_get_raw_config ( uint8_t  buffer[SensorConfig_size])

Get the configuration from the flash.

Parameters
Anallocated buffer at least SensorConfig_size big to which the config protocol buffer will be written.
Returns
The number of bytes written to the buffer on success, false otherwise.

Definition at line 262 of file store.c.

Referenced by store_get_config().

uint8_t store_get_raw_sample ( uint16_t  id,
uint8_t  buffer[Sample_size] 
)

Get a given sample from the flash, in the form of an encoded protocol buffer.

Parameters
idThe id of the sample.
bufferAn allocated buffer at least Samle_size big to which the sample protocol buffer will be written.
Returns
The number of bytes written to the buffer on success, false otherwise.

Definition at line 155 of file store.c.

Referenced by res_get_handler(), store_get_latest_raw_sample(), and store_get_sample().

bool store_get_sample ( uint16_t  id,
Sample *  sample 
)

Get a given sample from the flash,.

Parameters
idThe id of the sample.
*sampleThe Sample to write the sample to.
Returns
true on success, false otherwise.

Definition at line 139 of file store.c.

Referenced by store_get_latest_sample().

void store_init ( void  )

Initialize the data store.

Includes finding the latest reading.

Definition at line 339 of file store.c.

bool store_save_config ( SensorConfig *  config)

Save the configuration to flash.

Parameters
*configThe configuration to save.
Returns
true on success, false otherwise.

Definition at line 220 of file store.c.

uint16_t store_save_sample ( Sample *  sample)

Store a sample in the flash.

This will also set sample's id field.

Parameters
*sampleThe sample to save.
Returns
A unique id for the sample on success, false on failure.

Definition at line 100 of file store.c.