mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.4 UUID
This commit is contained in:
parent
9e34db6025
commit
7fd4dabcc8
@ -1,3 +1,18 @@
|
||||
platforms:
|
||||
rpipico:
|
||||
board: rp2040:rp2040:rpipico
|
||||
package: rp2040:rp2040
|
||||
gcc:
|
||||
features:
|
||||
defines:
|
||||
- ARDUINO_ARCH_RP2040
|
||||
warnings:
|
||||
flags:
|
||||
|
||||
packages:
|
||||
rp2040:rp2040:
|
||||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
@ -7,8 +22,8 @@ compile:
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
- esp8266
|
||||
# - mega2560
|
||||
|
||||
- rpipico
|
||||
libraries:
|
||||
# - "printHelpers"
|
||||
|
33
libraries/UUID/CHANGELOG.md
Normal file
33
libraries/UUID/CHANGELOG.md
Normal file
@ -0,0 +1,33 @@
|
||||
# Change Log UUID
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.4] - 2022-11-26
|
||||
- Add RP2040 support to build-CI.
|
||||
- Add CHANGELOG.md
|
||||
- update readme.md
|
||||
- add ESP32 measurements
|
||||
- minor edits
|
||||
|
||||
## [0.1.3] - 2022-06-15
|
||||
- improve performance generate() again
|
||||
|
||||
## [0.1.2] - 2022-06-15
|
||||
- fix version number
|
||||
- improve performance generate()
|
||||
|
||||
## [0.1.1] - 2022-06-15
|
||||
- improve performance generate()
|
||||
- minor edits in readme.md
|
||||
- fix bug in generator
|
||||
- define UUID_MODE_VARIANT4
|
||||
- define UUID_MODE_RANDOM
|
||||
|
||||
|
||||
## [0.1.0] - 2022-06-14
|
||||
- initial version
|
||||
|
@ -15,7 +15,7 @@ Arduino library for generating UUID strings.
|
||||
|
||||
This **experimental** library provides a UUID generator.
|
||||
A UUID is an Universally Unique IDentifier of 128 bits.
|
||||
These are typically written in the following format, defined in RFC 4122.
|
||||
These are typically written in the following format, defined in RFC-4122.
|
||||
|
||||
```
|
||||
0ac82d02-002b-4ccb-b96c-1c7839cbc4c0
|
||||
@ -25,15 +25,16 @@ These are typically written in the following format, defined in RFC 4122.
|
||||
The length is 32 hexadecimal digits + four hyphens = 36 characters.
|
||||
Note that the hexadecimal digits are lower case.
|
||||
|
||||
The 0.1.1 version of the lib tries to follow the RFC4122,
|
||||
The 0.1.1 version of the lib tries to follow the RFC-4122,
|
||||
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.
|
||||
This nibble must be 8,9, a or b.
|
||||
This nibble must be 8, 9, A or B.
|
||||
All the remaining bits are random.
|
||||
|
||||
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.
|
||||
Regular reseeding with external entropy improves randomness.
|
||||
|
||||
Often one sees also the term GUID = Globally Unique Identifier.
|
||||
|
||||
@ -69,6 +70,7 @@ until **generate()** is called again.
|
||||
### Mode
|
||||
|
||||
Only two modi are supported. Default is the **UUID_MODE_VARIANT4**.
|
||||
This is conform RFC-4122.
|
||||
|
||||
- **void setVariant4Mode()** set mode to **UUID_MODE_VARIANT4**.
|
||||
- **void setRandomMode()** set mode to **UUID_MODE_RANDOM**.
|
||||
@ -101,32 +103,41 @@ Performance measured with **UUID_test.ino** shows the following times:
|
||||
|
||||
#### microseconds per byte
|
||||
|
||||
| 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 | |
|
||||
| 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 |
|
||||
|
||||
Note: generating the 16 random bytes already takes ~40 us.
|
||||
Note: generating the 16 random bytes already takes ~40 us (UNO).
|
||||
|
||||
|
||||
#### UUID's per second
|
||||
|
||||
| Version | UNO 16 MHz | ESP32 240 MHz | notes |
|
||||
|:-------:|:------------:|:---------------:|:------:|
|
||||
| 0.1.0 | 2000++ | |
|
||||
| 0.1.1 | 4000++ | | generate both modes
|
||||
| 0.1.2 | 6400++ | | generate both modes
|
||||
| 0.1.3 | 8200++ | | generate both modes
|
||||
indicative maximum performance (see example sketch)
|
||||
|
||||
| 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 |
|
||||
|
||||
|
||||
Note that this maximum is not realistic e.g. for a server where also
|
||||
other tasks need to be done (listening, transfer etc).
|
||||
Note that these maxima are not realistic e.g. for a server.
|
||||
Other tasks need to be done too (listening, transfer etc.).
|
||||
|
||||
|
||||
## Operation
|
||||
@ -145,9 +156,11 @@ See examples.
|
||||
- investigate entropy harvesting
|
||||
- freeRAM, micros, timers, RAM, USB-ID, ...
|
||||
- compile constants __DATE__ and __TIME__
|
||||
- see example
|
||||
- GUID as derived class?
|
||||
- (further identical?)
|
||||
|
||||
|
||||
### Functions
|
||||
|
||||
- add **setUpperCase()** and **setLowerCase()**, **isUpperCase()**
|
||||
@ -169,6 +182,7 @@ See examples.
|
||||
- reduce footprint
|
||||
- can the buffer be reduced?
|
||||
- smaller random generator?
|
||||
- move code to .h so compiler can optimize more?
|
||||
|
||||
### Won't
|
||||
|
||||
|
@ -1,22 +1,11 @@
|
||||
//
|
||||
// FILE: UUID.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.3
|
||||
// VERSION: 0.1.4
|
||||
// DATE: 2022-06-14
|
||||
// PURPOSE: Arduino Library for generating UUID's
|
||||
// URL: https://github.com/RobTillaart/UUID
|
||||
// https://en.wikipedia.org/wiki/Universally_unique_identifier
|
||||
//
|
||||
// HISTORY
|
||||
// 0.1.0 2022-06-14 initial version
|
||||
// 0.1.1 2022-06-15 improve performance generate()
|
||||
// minor edits in readme.md
|
||||
// fix bug in generator
|
||||
// define UUID_MODE_VARIANT4
|
||||
// define UUID_MODE_RANDOM
|
||||
// 0.1.2 2022-06-15 fix version number
|
||||
// improve performance generate()
|
||||
// 0.1.3 2022-06-16 improve performance generate() again
|
||||
|
||||
|
||||
#include "UUID.h"
|
||||
@ -32,7 +21,7 @@ UUID::UUID()
|
||||
|
||||
void UUID::seed(uint32_t s1, uint32_t s2)
|
||||
{
|
||||
// set Marsaglia constants, prevent 0 as value
|
||||
// set Marsaglia constants, prevent 0 as value
|
||||
if (s1 == 0) s1 = 1;
|
||||
if (s2 == 0) s2 = 2;
|
||||
_m_w = s1;
|
||||
@ -43,22 +32,27 @@ void UUID::seed(uint32_t s1, uint32_t s2)
|
||||
// check version 0.1.1 for more readable code
|
||||
void UUID::generate()
|
||||
{
|
||||
uint32_t _ar[4];
|
||||
uint32_t ar[4];
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
_ar[i] = _random();
|
||||
ar[i] = _random();
|
||||
// store binary version globally ?
|
||||
// _ar[i] = ar[i];
|
||||
}
|
||||
|
||||
|
||||
// Conforming to RFC 4122 Specification
|
||||
// - byte 7: four most significant bits ==> 0100 --> always 4
|
||||
// - byte 9: two most significant bits ==> 10 --> always {8, 9, A, B}.
|
||||
//
|
||||
// patch bits for version 1 and variant 4 here
|
||||
if (_mode == UUID_MODE_VARIANT4)
|
||||
{
|
||||
_ar[1] &= 0xFFF0FFFF; // remove 4 bits.
|
||||
_ar[1] |= 0x00040000; // variant 4
|
||||
_ar[2] &= 0xFFFFFFF3; // remove 2 bits
|
||||
_ar[2] |= 0x00000008; // version 1
|
||||
ar[1] &= 0xFFF0FFFF; // remove 4 bits.
|
||||
ar[1] |= 0x00040000; // variant 4
|
||||
ar[2] &= 0xFFFFFFF3; // remove 2 bits
|
||||
ar[2] |= 0x00000008; // version 1
|
||||
}
|
||||
|
||||
// store globally ?
|
||||
|
||||
// process 16 bytes build up the char array.
|
||||
for (uint8_t i = 0, j = 0; i < 16; i++)
|
||||
@ -72,12 +66,12 @@ void UUID::generate()
|
||||
|
||||
// process one byte at the time instead of a nibble
|
||||
uint8_t nr = i / 4;
|
||||
uint8_t xx = _ar[nr];
|
||||
uint8_t ch = xx & 0xF;
|
||||
uint8_t xx = ar[nr];
|
||||
uint8_t ch = xx & 0x0F;
|
||||
_buffer[j++] = (ch < 10) ? '0' + ch : ('a' - 10) + ch;
|
||||
|
||||
ch = (xx >> 4) & 0xF;
|
||||
_ar[nr] >>= 8;
|
||||
|
||||
ch = (xx >> 4) & 0x0F;
|
||||
ar[nr] >>= 8;
|
||||
_buffer[j++] = (ch < 10) ? '0' + ch : ('a' - 10) + ch;
|
||||
}
|
||||
_buffer[36] = 0;
|
||||
@ -90,16 +84,23 @@ char * UUID::toCharArray()
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
//
|
||||
// PRINTING
|
||||
//
|
||||
size_t UUID::printTo(Print& p) const
|
||||
{
|
||||
return p.print(_buffer);
|
||||
};
|
||||
|
||||
|
||||
// An example of a simple pseudo-random number generator is the
|
||||
// Multiply-with-carry method invented by George Marsaglia.
|
||||
// two initializers (not null)
|
||||
//////////////////////////////////////////////////
|
||||
//
|
||||
// RANDOM GENERATOR MARSAGLIA
|
||||
//
|
||||
// An example of a simple pseudo-random number generator is the
|
||||
// Multiply-with-carry method invented by George Marsaglia.
|
||||
// two initializers (not null)
|
||||
uint32_t UUID::_random()
|
||||
{
|
||||
_m_z = 36969L * (_m_z & 65535L) + (_m_z >> 16);
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: UUID.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.3
|
||||
// VERSION: 0.1.4
|
||||
// DATE: 2022-06-14
|
||||
// PURPOSE: Arduino Library for generating UUID's
|
||||
// URL: https://github.com/RobTillaart/UUID
|
||||
@ -15,11 +15,11 @@
|
||||
#include "Printable.h"
|
||||
|
||||
|
||||
#define UUID_LIB_VERSION (F("0.1.3"))
|
||||
#define UUID_LIB_VERSION (F("0.1.4"))
|
||||
|
||||
// TODO an enum?
|
||||
#define UUID_MODE_VARIANT4 0
|
||||
#define UUID_MODE_RANDOM 1
|
||||
const uint8_t UUID_MODE_VARIANT4 = 0;
|
||||
const uint8_t UUID_MODE_RANDOM = 1;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
@ -59,5 +59,5 @@ private:
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -3,11 +3,14 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "UUID.h"
|
||||
|
||||
|
||||
UUID uuid;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
@ -0,0 +1,18 @@
|
||||
IDE: 1.8.19
|
||||
PLATFORM: UNO - 16 MHz
|
||||
|
||||
UUID_performance.ino
|
||||
UUID_LIB_VERSION: 0.1.4
|
||||
Generate 4: 8268 uuid's per second.
|
||||
Generate R: 8418 uuid's per second.
|
||||
|
||||
=====================================
|
||||
|
||||
IDE: 1.8.19
|
||||
PLATFORM: ESP32 - 240 MHz
|
||||
|
||||
UUID_performance.ino
|
||||
UUID_LIB_VERSION: 0.1.4
|
||||
Generate 4: 31951 uuid's per second.
|
||||
Generate R: 34688 uuid's per second.
|
||||
|
@ -104,4 +104,5 @@ uint32_t extractEntropy()
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -22,7 +22,8 @@ void setup()
|
||||
Serial.println("UUID_test.ino");
|
||||
Serial.print("UUID_LIB_VERSION: ");
|
||||
Serial.println(UUID_LIB_VERSION);
|
||||
|
||||
delay(100);
|
||||
|
||||
start = micros();
|
||||
uuid.seed(2);
|
||||
stop = micros();
|
||||
|
27
libraries/UUID/examples/UUID_test/output_0.1.4.txt
Normal file
27
libraries/UUID/examples/UUID_test/output_0.1.4.txt
Normal file
@ -0,0 +1,27 @@
|
||||
UUID_LIB_VERSION: 0.1.4
|
||||
seed: 8
|
||||
generate: 120
|
||||
toCharArray: 4
|
||||
UUID: 0ac82d02-002b-4ccb-b96c-1c7839cbc4c0
|
||||
UUID: d7652208-bd86-400d-93eb-eeafc12fe18d
|
||||
UUID: cf48f771-f39b-4fdd-a324-acad1c7ac596
|
||||
UUID: f74404e9-3cf4-4769-8c15-1a278e126987
|
||||
UUID: 4fe109d9-09d6-41e0-885a-b4ee716d1f5d
|
||||
|
||||
|
||||
===========================================
|
||||
|
||||
(ESP32 - 240 MHz)
|
||||
|
||||
UUID_test.ino
|
||||
UUID_LIB_VERSION: 0.1.4
|
||||
seed: 3
|
||||
generate: 14
|
||||
toCharArray: 0
|
||||
UUID: 0ac82d02-002b-4ccb-b96c-1c7839cbc4c0
|
||||
UUID: d7652208-bd86-400d-93eb-eeafc12fe18d
|
||||
UUID: cf48f771-f39b-4fdd-a324-acad1c7ac596
|
||||
UUID: f74404e9-3cf4-4769-8c15-1a278e126987
|
||||
UUID: 4fe109d9-09d6-41e0-885a-b4ee716d1f5d
|
||||
|
||||
|
@ -14,7 +14,6 @@ setRandomMode KEYWORD2
|
||||
getMode KEYWORD2
|
||||
|
||||
|
||||
|
||||
# Constants (LITERAL1)
|
||||
UUID_LIB_VERSION LITERAL1
|
||||
UUID_MODE_RANDOM LITERAL1
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/UUID.git"
|
||||
},
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=UUID
|
||||
version=0.1.3
|
||||
version=0.1.4
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for generating UUID's. (experimental).
|
||||
|
Loading…
Reference in New Issue
Block a user