2022-06-16 03:46:28 -04:00
|
|
|
#pragma once
|
|
|
|
//
|
|
|
|
// FILE: Adler16.cpp
|
|
|
|
// AUTHOR: Rob Tillaart
|
2023-01-16 10:33:37 -05:00
|
|
|
// VERSION: 0.2.3
|
2022-06-16 03:46:28 -04:00
|
|
|
// DATE: 2022-06-15
|
|
|
|
// PURPOSE: Arduino Library for calculating Adler-16 checksum
|
|
|
|
// URL: https://github.com/RobTillaart/Adler
|
2023-01-16 10:33:37 -05:00
|
|
|
// https://en.wikipedia.org/wiki/Adler-32
|
2022-06-16 03:46:28 -04:00
|
|
|
// (no Adler16 reference, implementation is experimental)
|
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
|
|
|
|
|
2023-01-16 10:33:37 -05:00
|
|
|
#define ADLER16_LIB_VERSION (F("0.2.3"))
|
2022-06-16 03:46:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
// largest prime below 2^8
|
|
|
|
const uint16_t ADLER16_MOD_PRIME = 251;
|
|
|
|
|
|
|
|
class Adler16
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Adler16();
|
|
|
|
|
2022-09-21 03:34:38 -04:00
|
|
|
void begin(uint16_t s1 = 1, uint16_t s2 = 0);
|
2022-06-16 03:46:28 -04:00
|
|
|
|
2023-01-16 10:33:37 -05:00
|
|
|
|
2022-09-21 03:34:38 -04:00
|
|
|
void add(uint8_t value);
|
|
|
|
// returns current Adler value
|
|
|
|
uint16_t add(uint8_t * array, uint16_t length);
|
2022-06-16 03:46:28 -04:00
|
|
|
// trade PROGMEM for speed
|
2022-09-21 03:34:38 -04:00
|
|
|
// returns current Adler value
|
|
|
|
uint16_t addFast(uint8_t * array, uint16_t length);
|
2022-06-16 03:46:28 -04:00
|
|
|
|
2023-01-16 10:33:37 -05:00
|
|
|
|
2022-06-16 03:46:28 -04:00
|
|
|
// wrappers for strings
|
2022-09-21 03:34:38 -04:00
|
|
|
void add(char value);
|
|
|
|
// returns current Adler value
|
|
|
|
uint16_t add(char * array, uint16_t length);
|
|
|
|
// returns current Adler value
|
|
|
|
uint16_t addFast(char * array, uint16_t length);
|
2022-06-16 03:46:28 -04:00
|
|
|
|
2023-01-16 10:33:37 -05:00
|
|
|
|
2022-09-21 03:34:38 -04:00
|
|
|
// returns current Adler value
|
2022-06-16 03:46:28 -04:00
|
|
|
uint16_t getAdler();
|
2022-09-21 03:34:38 -04:00
|
|
|
uint16_t count();
|
2022-06-16 03:46:28 -04:00
|
|
|
|
2023-01-16 10:33:37 -05:00
|
|
|
|
2022-06-16 03:46:28 -04:00
|
|
|
private:
|
|
|
|
uint16_t _s1;
|
|
|
|
uint16_t _s2;
|
|
|
|
uint32_t _count;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-01-16 10:33:37 -05:00
|
|
|
// -- END OF FILE --
|
2022-06-16 03:46:28 -04:00
|
|
|
|
|
|
|
|