GY-63_MS5611/libraries/Adler/README.md

229 lines
7.0 KiB
Markdown
Raw Normal View History

2022-01-27 06:18:16 -05:00
[![Arduino CI](https://github.com/RobTillaart/Adler/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/Adler/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/Adler/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/Adler/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/Adler/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Adler/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/Adler.svg?maxAge=3600)](https://github.com/RobTillaart/Adler/releases)
# Adler
2022-06-16 03:46:28 -04:00
Arduino Library for Adler-32 and experimental Adler-16 checksum.
2022-01-27 06:18:16 -05:00
## Description
2022-06-16 03:46:28 -04:00
This library provides a Adler32 checksum of a data array.
Furthermore since 0.2.0 an experimental Adler-16 implementation is added.
2022-09-21 03:34:38 -04:00
This one is often faster as it uses a smaller checksum than the Adler32.
The price is that Adler16 is less sensitive than the Adler32.
Still it will have its niches where it will be useful.
2022-01-27 06:18:16 -05:00
Relates to https://github.com/RobTillaart/CRC
Relates to https://github.com/RobTillaart/Fletcher
Tested on Arduino UNO only.
2022-06-16 03:46:28 -04:00
0.2.0 is a breaking change, file names have been changed to be more
in line with the CRC library.
- Adler.h for the static functions
- Adler32.h for the Adler32 class
- Adler16.h for the Adler16 class.
2022-01-27 06:18:16 -05:00
## Interface
2022-06-16 03:46:28 -04:00
### Adler class
2022-01-27 06:18:16 -05:00
2022-06-16 03:46:28 -04:00
Use **\#include "Adler32.h"** or **\#include "Adler16.h"**
The interface for the Adler16 is very similar.
2022-01-27 06:18:16 -05:00
- **Adler32()** Constructor, initializes internals.
- **void begin(uint8_t s1 = 1, uint8_t s2 = 0)** resets the internals.
optional setting start values for s1 and s2. Note this is not part of the standard.
This allows a restart from a specific index in a buffer.
- **void add(uint8_t value)** add a single value to the checksum.
2022-09-21 03:34:38 -04:00
- **uint32_t add(const uint8_t \* array, uint8_t length)** add an array of values to the checksum.
Returns the current checksum.
- **uint32_t addFast(const uint8_t \* array, uint8_t length)** add an array of values to the checksum.
Is faster by trading PROGMEM for performance.
Returns the current checksum.
2022-01-27 06:18:16 -05:00
- **uint32_t getAdler()** get the current checksum.
2022-09-21 03:34:38 -04:00
- **uint32_t count()** get the number of items added. Merely a debugging feature,
can overflow without affecting checksum.
2022-01-27 06:18:16 -05:00
The class is typically used for streaming very large blocks of data,
optional with intermediate checksum tests.
2022-06-16 03:46:28 -04:00
## Performance Adler32
2022-01-27 06:18:16 -05:00
2022-09-21 03:34:38 -04:00
Only tested on UNO and ESP32 yet.
If you have data of other platforms, please let me know.
2022-01-27 06:18:16 -05:00
2022-06-16 03:46:28 -04:00
Numbers measured with **Adler32_performance.ino**.
### add(value)
The **add(value)** adds one byte and does a subtraction
instead of a modulo.
| Version | Function | UNO 16 MHz | ESP32 240 MHz |
|:-------:|:---------|:----------:|:-------------:|
2022-09-21 03:34:38 -04:00
| 0.1.0 | add | 5.6 us | |
| 0.1.2 | add | 6.6 us | |
| 0.2.0 | add | 5.9 us | 1.7 us |
2022-06-16 03:46:28 -04:00
### add(lorem) 868 chars
The **add(array, length)** is a straightforward loop
over the array and has a small footprint.
2022-06-14 09:28:07 -04:00
2022-06-16 03:46:28 -04:00
| Version | Function | UNO 16 MHz | ESP32 240 MHz |
|:-------:|:---------|:----------:|:-------------:|
2022-09-21 03:34:38 -04:00
| 0.1.0 | add | | |
| 0.1.2 | add | 6392 us | |
| 0.2.0 | add | 5748 us | 145 us |
2022-06-14 09:28:07 -04:00
2022-06-16 03:46:28 -04:00
Note: **add()** is about 6.6 us per byte.
2022-06-14 09:28:07 -04:00
2022-06-16 03:46:28 -04:00
### addFast(lorem) 868 chars
2022-06-14 09:28:07 -04:00
2022-06-16 03:46:28 -04:00
The **addFast(array, length)** is faster than the
2022-09-21 03:34:38 -04:00
reference **add(array, length)** and uses 108 bytes more (UNO).
2022-06-16 03:46:28 -04:00
So the function has a larger footprint.
Depending on your needs, choose performance or footprint.
2022-06-14 09:28:07 -04:00
See **Adler32_performance_addFast.ino**
2022-01-27 06:18:16 -05:00
2022-06-16 03:46:28 -04:00
| Version | Function | UNO 16 MHz | ESP32 240 MHz |
|:-------:|:---------|:----------:|:-------------:|
| 0.1.0 | addFast | | |
| 0.1.2 | addFast | 1348 us | |
2022-09-21 03:34:38 -04:00
| 0.2.0 | addFast | 1348 us | 66 us |
2022-06-16 03:46:28 -04:00
Note: **addFast()** is less than 2 us per byte.
## Performance Adler16
2022-09-21 03:34:38 -04:00
Only tested on UNO and ESP32 yet.
If you have data of other platforms, please let me know.
2022-06-16 03:46:28 -04:00
Numbers measured with **Adler16_performance.ino**.
### add(value)
The **add(value)** adds one byte and does a subtraction
instead of a modulo.
| Version | Function | UNO 16 MHz | ESP32 240 MHz |
|:-------:|:---------|:----------:|:-------------:|
2022-09-21 03:34:38 -04:00
| 0.2.0 | add | 4.0 us | 1.8 us |
2022-06-16 03:46:28 -04:00
The per byte performance of the Adler16 (on UNO) is faster
than the Adler32 **add(value)**. The reason is that a 16 bit
subtraction on an UNO is faster than a 32 bit subtraction.
### add(lorem) 868 chars
The **add(array, length)** is a straightforward loop
over the array and has a small footprint.
| Version | Function | UNO 16 MHz | ESP32 240 MHz |
|:-------:|:---------|:----------:|:-------------:|
2022-09-21 03:34:38 -04:00
| 0.2.0 | add | 4040 us | 160 us |
2022-06-16 03:46:28 -04:00
Note: **add()** is about 6.6 us per byte.
### addFast(lorem) 868 chars
The **addFast(array, length)** is faster than the
reference **add(array, length)**.
| Version | Function | UNO 16 MHz | ESP32 240 MHz |
|:-------:|:---------|:----------:|:-------------:|
2022-09-21 03:34:38 -04:00
| 0.2.0 | addFast | 1968 us | 79 us |
2022-06-16 03:46:28 -04:00
The gain of the faster 16 bit modulo meets the frequency of
doing the modulo more often.
2022-01-27 06:18:16 -05:00
## Interface static functions
2022-06-16 03:46:28 -04:00
The functions are straightforward.
2022-01-27 06:18:16 -05:00
Use **\#include "Adler.h"**
- **uint32_t adler32(uint8_t \*data, uint16_t length)** length in units of 1 byte = 8 bits.
2022-06-16 03:46:28 -04:00
- **uint16_t adler16(uint8_t \*data, uint16_t length)** length in units of 1 byte = 8 bits.
2022-01-27 06:18:16 -05:00
2022-06-16 03:46:28 -04:00
The functions are typically used for an in memory buffer to calculate the checksum once.
Think of packets in a network, records in a database, or a checksum for an configuration in EEPROM.
2022-01-27 06:18:16 -05:00
2022-06-16 03:46:28 -04:00
### Performance
2022-01-27 06:18:16 -05:00
2022-09-21 03:34:38 -04:00
Only tested on UNO and ESP32 yet.
If you have data of other platforms, please let me know.
2022-01-27 06:18:16 -05:00
2022-06-16 03:46:28 -04:00
Numbers measured with **Adler_performance.ino**.
2022-01-27 06:18:16 -05:00
Lorem Ipsum text = 868 bytes.
2022-06-16 03:46:28 -04:00
| Version | Function | UNO 16 MHz | ESP32 240 MHz |
|:-------:|:---------|:----------:|:-------------:|
| 0.1.0 | Adler32 | 1116 us | |
| 0.1.2 | Adler32 | 1116 us | |
2022-09-21 03:34:38 -04:00
| 0.2.0 | Adler32 | 1116 us | 60 us |
| 0.2.0 | Adler16 | 1736 us | 75 us |
2022-01-27 06:18:16 -05:00
2022-09-21 03:34:38 -04:00
#### UNO
2022-01-27 06:18:16 -05:00
2022-06-16 03:46:28 -04:00
Adler32 average 1116 / 868 = 1.29 us per byte.
Adler16 average 1736 / 868 = 2.00 us per byte. (~1.5x slower !)
2022-01-27 06:18:16 -05:00
2022-06-16 03:46:28 -04:00
Adler16 does more often the modulo math as it reaches halfway uint16_t
faster than Adler32 reaches halfway uint32_t.
2022-06-14 09:28:07 -04:00
2022-09-21 03:34:38 -04:00
As the Adler16 is less performant as the Adler32 (on all tested platforms),
it is often the best to use the 32 bit version.
2022-06-14 09:28:07 -04:00
2022-01-27 06:18:16 -05:00
## Operation
See examples.
2022-06-14 09:28:07 -04:00
## Future
2022-01-27 06:18:16 -05:00
2022-06-16 03:46:28 -04:00
- Adler64 ?
2022-09-21 03:34:38 -04:00
- would need a large prime (which) => 4294967291
- max uint32_t = 4.294.967.296
- max uint32_t prime = 4.294.967.291
- need printHelpers library for printing.
- only on request.
2022-06-16 03:46:28 -04:00
#### Wont
- do the string wrappers need strlen() ? parameter.
- yes, as string can be processed partially.
2022-09-21 03:34:38 -04:00
- no return value for **add(value)**
- would create too much overhead for repeated calls.
2022-06-16 03:46:28 -04:00
2022-01-27 06:18:16 -05:00