NHS31xx SW API
compress: compression / decompression module

Detailed Description

This block of code allows an application to perform losless compression and uncompression on arbitrary chunks of data.
It will:

The Compress module will use both EEPROM and FLASH to store bits of data. The newest samples are always stored in EEPROM; when the reserved space in EEPROM is full, all the data is moved to FLASH, and the EEPROM is reused. Writing samples always means appending them to the already written samples; it is not possible to edit the already written stream of bits. When reading back again, the user can control the starting read position using a sequence number. It is automatically deduced where the corresponding sample is written, whether it is compressed, and what needs to be done to be able to return the requested sample(s).

It is expected that each application that requires this module includes it and configures the diversity settings of the module according to its specific needs.

Diversity
This module supports diversity: settings to tweak the effectiveness of the compression. Check Diversity Settings for all diversity parameters.
Memory Requirements
The memory requirements are defined by the diversity settings. Check COMPRESS_WINDOW_BITS and COMPRESS_USE_INDEX.
How to use the module
  1. To compress, simply call Compress_Encode. No preparation or initialization is necessary.
  2. To uncompress, call Compress_Decod. No preparation or initialization is necessary.
  3. Compress_Decode o Compress_Encode is an identity function.
Example
uint8_t data[1234];
/* ... fill in 1234 bytes of data ... */
/* Compression is a one function call: */
uint8_t compressed[1234];
int compressedSize = Compress_Encode(data, 1234, compressed, 1234);
/* compressedSize is now a number less than 1234.*/
/* Retrieving the original data back is again a one function call: */
uint8_t uncompressed[1234];
int uncompressedSize = Compress_Decode(compressed, compressedSize, uncompressed, 1234);
/* uncompressedSize is now equal to 1234.*/
/* all bytes in uncompressed are now identical to the bytes in data.*/

Modules

 Diversity Settings
 

Functions

int Compress_Encode (const uint8_t *input, int inputLength, uint8_t *output, int outputLength)
 
int Compress_Decode (const uint8_t *input, int inputLength, uint8_t *output, int outputLength)
 

Function Documentation

◆ Compress_Encode()

int Compress_Encode ( const uint8_t *  input,
int  inputLength,
uint8_t *  output,
int  outputLength 
)

Compresses a contiguous array of bytes.

Parameters
inputpointer to the array where all bytes to encode can be found. No alignment is enforced.
inputLengthThe number of bytes to encode, starting from input.
outputpointer to the array where the encoded end result will be written to. No alignment is enforced.
outputLengthSize in bytes of the available output array.
Returns
Size in bytes of the used output bytes. An output size of 0 indicates an error: the output buffer may or may not have been written to, but none of the bytes may be used for further processing.
Note
The output, when a valid size has been returned, cannot be split up and decoded in chunks; decoding is only possible when providing the full array with all the now-encoded bytes.

◆ Compress_Decode()

int Compress_Decode ( const uint8_t *  input,
int  inputLength,
uint8_t *  output,
int  outputLength 
)

Uncompresses a contiguous array of bytes.

Parameters
inputpointer to the array where the encoded bytes to uncompress can be found. No alignment is enforced.
inputLengthThe number of bytes to decode, starting from input. This value must be equal to the returnvalue of a previous call to Compress_Encode.
outputpointer to the array where the decoded bytes will be written to. No alignment is enforced.
outputLengthSize in bytes of the available output array.
Returns
Size in bytes of the used output bytes. An output size of 0 indicates an error: the output buffer may or may not have been written to, but none of the bytes may be used for further processing.
Note
The output length, when a valid size has been returned, will be equal to the value of inputLength during a previous call to Compress_Encode.