GY-63_MS5611/libraries/LUHN/LUHN.h

48 lines
957 B
C
Raw Normal View History

2022-12-29 10:15:53 -05:00
#pragma once
//
// FILE: LUHN.h
// AUTHOR: Rob Tillaart
2022-12-30 06:21:53 -05:00
// VERSION: 0.1.1
2022-12-29 10:15:53 -05:00
// DATE: 2022-12-24
// PURPOSE: Arduino Library for calculating LUHN checksum.
// URL: https://github.com/RobTillaart/LUHN
#include "Arduino.h"
2022-12-30 06:21:53 -05:00
#define LUHN_LIB_VERSION (F("0.1.1"))
2022-12-29 10:15:53 -05:00
class LUHN
{
public:
LUHN();
2022-12-30 06:21:53 -05:00
// CHECK
2022-12-29 10:15:53 -05:00
// buffer == \0 terminated
bool isValid(const char * buffer);
bool isValid(char * buffer);
char generateChecksum(char * buffer);
2022-12-30 06:21:53 -05:00
// GENERATE A PRODUCT ID WITH LUHN CHECKSUM
2022-12-29 10:15:53 -05:00
void randomize(uint32_t a, uint32_t b);
bool generate(char * buffer, uint8_t length, char * prefix);
2022-12-30 06:21:53 -05:00
// STREAM INTERFACE
char add(char c);
char reset();
2022-12-29 10:15:53 -05:00
protected:
uint32_t m_w = 1; // random generator parameter
uint32_t m_z = 2; // random generator parameter
uint8_t Marsaglia_mod10();
2022-12-30 06:21:53 -05:00
uint8_t _luhn = 0;
uint16_t _count = 0;
2022-12-29 10:15:53 -05:00
};
// -- END OF FILE --