2022-06-14 09:20:04 -04:00
|
|
|
#pragma once
|
|
|
|
//
|
|
|
|
// FILE: UUID.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2022-11-27 03:39:34 -05:00
|
|
|
// VERSION: 0.1.4
|
2022-06-14 09:20:04 -04:00
|
|
|
// DATE: 2022-06-14
|
|
|
|
// PURPOSE: Arduino Library for generating UUID's
|
|
|
|
// URL: https://github.com/RobTillaart/UUID
|
2022-06-15 01:34:09 -04:00
|
|
|
// https://en.wikipedia.org/wiki/Universally_unique_identifier
|
2022-06-14 09:20:04 -04:00
|
|
|
//
|
2022-06-15 01:34:09 -04:00
|
|
|
// e.g. 20d24650-d900-e34f-de49-8964ab3eb46d
|
2022-06-14 09:20:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "Printable.h"
|
|
|
|
|
|
|
|
|
2022-11-27 03:39:34 -05:00
|
|
|
#define UUID_LIB_VERSION (F("0.1.4"))
|
2022-06-15 01:34:09 -04:00
|
|
|
|
|
|
|
// TODO an enum?
|
2022-11-27 03:39:34 -05:00
|
|
|
const uint8_t UUID_MODE_VARIANT4 = 0;
|
|
|
|
const uint8_t UUID_MODE_RANDOM = 1;
|
2022-06-14 09:20:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CLASS VERSION
|
|
|
|
//
|
|
|
|
class UUID : public Printable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UUID();
|
|
|
|
|
|
|
|
// at least one seed value is mandatory, two is better.
|
|
|
|
void seed(uint32_t s1, uint32_t s2 = 0);
|
|
|
|
// generate a new UUID
|
|
|
|
void generate();
|
|
|
|
// make a UUID string
|
|
|
|
char * toCharArray();
|
|
|
|
|
2022-06-15 04:31:57 -04:00
|
|
|
// MODE
|
2022-06-15 01:34:09 -04:00
|
|
|
void setVariant4Mode() { _mode = UUID_MODE_VARIANT4; };
|
|
|
|
void setRandomMode() { _mode = UUID_MODE_RANDOM; };
|
|
|
|
uint8_t getMode() { return _mode; };
|
|
|
|
|
2022-06-14 09:20:04 -04:00
|
|
|
// Printable interface
|
|
|
|
size_t printTo(Print& p) const;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Marsaglia 'constants' + function
|
|
|
|
uint32_t _m_w = 1;
|
|
|
|
uint32_t _m_z = 2;
|
|
|
|
uint32_t _random();
|
|
|
|
|
|
|
|
// UUID in string format
|
|
|
|
char _buffer[37];
|
2022-06-15 01:34:09 -04:00
|
|
|
uint8_t _mode = UUID_MODE_VARIANT4;
|
2022-06-14 09:20:04 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-11-27 03:39:34 -05:00
|
|
|
// -- END OF FILE --
|
2022-06-14 09:20:04 -04:00
|
|
|
|