Data Storage Management API

SDK provide simple APIs to manage data storage. The storage APIs can be used to store data on storage media during unavailability of network or for logging purpose.

API Reference

Header File

Functions

int storage_init(const struct storagecfg_t *cfg)

Initialize storage management library. This function must be called before calling any storage function.

Return

0 on success, negative value on error

Parameters
  • cfg: [in] Storage configuration

int storage_save(int part, void *buffer, int len)

Save data to storage partition

Return

0 on success, negative value on error

Parameters
  • part: [in] Partition index, starting from 0

  • buffer: [in] Buffer to store

  • len: [in] Length of data in buffer

int storage_read(int part, void *buffer, int *len)

Read data from storage partition

Return

0 on success, negative value on error. len is updated with actual data read from storage

Parameters
  • part: [in] Partition index, starting from 0

  • buffer: [out] Pointer to buffer where data is stored

  • len: [out] Size of buffer, on return actual size read is updated

int storage_read_indexed(int part, int index, void *buffer, int *len)

Red data from storage partition indexed. This function can be used to read multiple packets at once. The reading index is 0 based. In FIFO mode 0 points to first packet and in LIFO mode 0 points to last packet. e.g in FIFO mode reading an indexed packet of index 2 will return third packet stored in FIFO order.

Return

0 on success, negative value on error. len is updated with actual data read from storage

Parameters
  • part: [in] Partition index, starting from 0

  • index: [in] Index to read

  • buffer: [out] Pointer to buffer where data is stored

  • len: [out] Size of buffer, on return actual size read is updated

int storage_delete(int part, int count)

Delete data from storage partition

Return

0 on success, negative value on error

Parameters
  • part: [in] Partition index, starting from 0

  • count: [in] Number of packets to delete

int storage_available(int part)

Get storage status

Return

TRUE if offline is pending, FALSE if not data is avilable

Parameters
  • part: [in] Partition index, starting from 0

int storage_getcount(int part)

Get storage data count available in partition

Return

available count

Parameters
  • part: [in] Partition index, starting from 0

int storage_clear(int part)

Delete data in storage partion

Return

0 on success, negative on error

Parameters
  • part: [in] Partition index, starting from 0

int storage_clear_all(void)

Delete all data

Return

int

Structures

struct storagecfg_t

Storage Configuration Structure

Public Members

uint8_t media

Storage Media storage_media_e

uint8_t parts

Number of Storage partition

uint8_t mode

Storage mode storage_mode_e

uint8_t on_full

Action to be taken when storage is full storage_action_e

uint8_t compression

1 to enable compression, 0 for no compression

uint8_t reserved

reserved for future use

uint16_t packet_sz

Approximate Average data packet size

uint32_t max_storage

Maximum number/count of data packets to store

uint32_t resvd_mem

Amount to reserved memory to keep in storage media, 16Kb minimum

Enumerations

enum storage_media_e

Storage media

Values:

enumerator STORAGE_MEDIA_FS

Storage media internal flash memory

enumerator STORAGE_MEDIA_SPIFS

Storage media external SPI Flash

enumerator STORAGE_MEDIA_SD

Storage media SD card

enum storage_mode_e

Storage read/write mode

Values:

enumerator STORAGE_MODE_FIFO

First-in First-out mode

enumerator STORAGE_MODE_LIFO

Last-in First-out mode (not supported yet)

enum storage_action_e

Action to be taken when storage full or reached reserve size

Values:

enumerator STORAGE_ONFULL_DELETE

Delete oldest data

enumerator STORAGE_ONFULL_STOP

Stop further storage