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

194 lines
6.0 KiB
Markdown
Raw Normal View History

2022-06-14 09:20:04 -04:00
[![Arduino CI](https://github.com/RobTillaart/UUID/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/UUID/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/UUID/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/UUID/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/UUID/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/UUID/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/UUID.svg?maxAge=3600)](https://github.com/RobTillaart/UUID/releases)
# UUID
Arduino library for generating UUID strings.
## Description
2022-06-15 01:34:09 -04:00
This **experimental** library provides a UUID generator.
A UUID is an Universally Unique IDentifier of 128 bits.
2022-11-27 03:39:34 -05:00
These are typically written in the following format, defined in RFC-4122.
2022-06-14 09:20:04 -04:00
2022-06-15 01:34:09 -04:00
```
0ac82d02-002b-4ccb-b96c-1c7839cbc4c0
^ ^
```
2022-06-14 09:20:04 -04:00
2022-06-15 01:34:09 -04:00
The length is 32 hexadecimal digits + four hyphens = 36 characters.
Note that the hexadecimal digits are lower case.
2022-06-14 09:20:04 -04:00
2022-11-27 03:39:34 -05:00
The 0.1.1 version of the lib tries to follow the RFC-4122,
2022-06-15 01:34:09 -04:00
for version 4 (random generated) and variant 1.
In the format above the version 4 is indicated by the first arrow and must be 4.
The variant 1 is at the position of the second arrow.
2022-11-27 03:39:34 -05:00
This nibble must be 8, 9, A or B.
2022-06-15 01:34:09 -04:00
All the remaining bits are random.
2022-06-14 09:20:04 -04:00
2022-06-15 01:34:09 -04:00
The basis for the UUID class is a Marsaglia pseudo random number generator.
This PRNG must be seeded with two real random uint32_t to get real random UUID's.
2022-11-27 03:39:34 -05:00
Regular reseeding with external entropy improves randomness.
2022-06-15 01:34:09 -04:00
Often one sees also the term GUID = Globally Unique Identifier.
Tested on Arduino UNO only.
2022-06-14 09:20:04 -04:00
2022-06-15 01:34:09 -04:00
- https://en.wikipedia.org/wiki/Universally_unique_identifier
- https://www.ietf.org/rfc/rfc4122.txt
2022-06-14 09:20:04 -04:00
## Interface
2022-06-15 01:34:09 -04:00
### UUID class
2022-06-14 09:20:04 -04:00
Use **\#include "UUID.h"**
2022-06-15 01:34:09 -04:00
The UUID class has only a few methods.
- **UUID()** Constructor, initializes internals an generates a default UUID.
2022-06-14 09:20:04 -04:00
- **void seed(uint32_t s1, uint32_t s2 = 0)** reseeds the internal
pseudo random number generator.
2022-06-15 01:34:09 -04:00
It is mandatory to set s1 while s2 is optional.
The combination {0, 0} is not allowed and overruled in software.
- **void generate()** generates a new UUID depending on the mode.
- **UUID_MODE_RANDOM**: all UUID bits are random.
- **UUID_MODE_VARIANT4**: the UUID (tries to) conform to version 4 variant 1. See above.
2022-06-14 09:20:04 -04:00
- **char \* toCharArray()** returns a pointer to a char buffer
2022-06-15 01:34:09 -04:00
representing the last generated UUID.
Multiple subsequent calls to **toCharArray()** gives the same UUID
until **generate()** is called again.
### Mode
Only two modi are supported. Default is the **UUID_MODE_VARIANT4**.
2022-11-27 03:39:34 -05:00
This is conform RFC-4122.
2022-06-15 01:34:09 -04:00
- **void setVariant4Mode()** set mode to **UUID_MODE_VARIANT4**.
- **void setRandomMode()** set mode to **UUID_MODE_RANDOM**.
- **uint8_t getMode()** returns mode set.
2022-06-14 09:20:04 -04:00
### Printable
The UUID class implements the printable interface.
2022-06-15 01:34:09 -04:00
This allows one to print the UUID object directly over Serial and any other
stream implementing the Print interface. Think Ethernet or SD card.
2022-06-14 09:20:04 -04:00
```cpp
UUID uuid;
Serial.println(uuid);
2022-06-15 01:34:09 -04:00
// gives same output as
Serial.println(uuid.toCharArray());
```
2022-06-14 09:20:04 -04:00
2022-06-15 01:34:09 -04:00
## Performance
2022-06-14 09:20:04 -04:00
Not tested ESP32 (and many other platforms) yet.
2022-06-15 01:34:09 -04:00
2022-06-15 04:31:57 -04:00
Performance measured with **UUID_test.ino** shows the following times:
2022-06-15 01:34:09 -04:00
2022-06-14 09:20:04 -04:00
2022-06-16 03:37:59 -04:00
#### microseconds per byte
2022-11-27 03:39:34 -05:00
| Version | Function | UNO 16 MHz | ESP32 240 MHz |
|:---------:|:--------------|:------------:|:---------------:|
| 0.1.0 | seed | 4 us | |
| 0.1.0 | generate | 412 us | |
| 0.1.0 | toCharArray | 4 us | |
| 0.1.1 | seed | 4 us | |
| 0.1.1 | generate | 248 us | |
| 0.1.1 | toCharArray | 4 us | |
| 0.1.2 | generate | 156 us | |
| 0.1.3 | generate | 120 us | |
| | | | |
| 0.1.4 | seed | 4 us | 3 us |
| 0.1.4 | generate | 120 us | 14 us |
| 0.1.4 | toCharArray | 4 us | 0 us |
2022-06-15 04:31:57 -04:00
2022-11-27 03:39:34 -05:00
Note: generating the 16 random bytes already takes ~40 us (UNO).
2022-06-15 01:34:09 -04:00
2022-06-14 09:20:04 -04:00
2022-06-16 03:37:59 -04:00
#### UUID's per second
2022-06-14 09:20:04 -04:00
2022-11-27 03:39:34 -05:00
indicative maximum performance (see example sketch)
2022-06-15 04:31:57 -04:00
2022-11-27 03:39:34 -05:00
| Version | UNO 16 MHz | ESP32 240 MHz | notes |
|:---------:|:------------:|:---------------:|:-----------:|
| 0.1.0 | 2000++ | | both modi |
| 0.1.1 | 4000++ | | both modi |
| 0.1.2 | 6400++ | | both modi |
| 0.1.3 | 8200++ | | both modi |
| | | | |
| 0.1.4 | 8268 | 31970 | VARIANT4 |
| 0.1.4 | 8418 | 34687 | RANDOM |
2022-06-14 09:20:04 -04:00
2022-11-27 03:39:34 -05:00
Note that these maxima are not realistic e.g. for a server.
Other tasks need to be done too (listening, transfer etc.).
2022-06-14 09:20:04 -04:00
## Operation
See examples.
## Future
### General
- improve documentation
- external random input needed
2022-06-15 01:34:09 -04:00
- background
2022-06-14 09:20:04 -04:00
- test other platforms
- investigate entropy harvesting
- freeRAM, micros, timers, RAM, USB-ID, ...
2022-06-15 04:31:57 -04:00
- compile constants __DATE__ and __TIME__
2022-11-27 03:39:34 -05:00
- see example
2022-06-15 01:34:09 -04:00
- GUID as derived class?
- (further identical?)
2022-06-14 09:20:04 -04:00
2022-11-27 03:39:34 -05:00
2022-06-14 09:20:04 -04:00
### Functions
- add **setUpperCase()** and **setLowerCase()**, **isUpperCase()**
- one bool flag
2022-06-15 01:34:09 -04:00
- binary output in a byte array
- **getBinary(uint8_t \* array)**
- need to store them from generate.
2022-06-14 09:20:04 -04:00
### Examples
- ESP32 UUID server
- using timing of the calls as entropy !
- RTC for entropy
2022-06-15 01:34:09 -04:00
- EEPROM to store last seeds?
2022-06-14 09:20:04 -04:00
### Fixes / optimizations
- reduce footprint
- can the buffer be reduced?
- smaller random generator?
2022-11-27 03:39:34 -05:00
- move code to .h so compiler can optimize more?
2022-06-14 09:20:04 -04:00
2022-06-15 01:34:09 -04:00
### Won't
- support for { and }
- add **setSeparator(char)** and **getSeparator()** ?
- minus is the specification.