SinricPro Library
SinricProMessageid.h
1 /*
2  * Copyright (c) 2019 Sinric. All rights reserved.
3  * Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
4  *
5  * This file is part of the Sinric Pro (https://github.com/sinricpro/)
6  */
7 
8 #ifndef __MESSAGEID_H__
9 #define __MESSAGEID_H__
10 
11 class MessageID {
12 public:
13  MessageID();
14  const String& getID() { return _id; }
15 private:
16  String _id;
17 };
18 
19 MessageID::MessageID() {
20  _id = "";
21  for (byte i=0; i<16; i++) {
22  byte rnd = random(255);
23  if (i==4) _id += "-";
24  if (i==6) { _id += "-"; rnd = 0x40 | (0x0F & rnd); } // 0100xxxx to set version 4
25  if (i==8) { _id += "-"; rnd = 0x80 | (0x3F & rnd); } // 10xxxxxx to set reserved bits
26  if (i==10) _id += "-";
27  byte high_nibble = rnd >> 4;
28  byte low_nibble = rnd & 0x0f;
29  _id += "0123456789abcdef"[high_nibble];
30  _id += "0123456789abcdef"[low_nibble];
31  }
32 }
33 
34 #endif // __MESSAGEID_H__