Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef _IMPL_UNIQUE_ID_H_
00037 #define _IMPL_UNIQUE_ID_H_ 1
00038
00046 #include <ros/ros.h>
00047
00048 #include <boost/uuid/uuid_generators.hpp>
00049
00050 namespace unique_id
00051 {
00052
00054 namespace impl
00055 {
00056
00057 static boost::uuids::string_generator genString;
00058
00059
00060 static boost::uuids::random_generator genRandom;
00061
00062
00063 static const std::string url_namespace =
00064 "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
00065
00066
00067 static const boost::uuids::uuid url_namespace_uuid =
00068 genString(url_namespace);
00069
00070
00071 static boost::uuids::name_generator genURL(url_namespace_uuid);
00072
00073
00074 static boost::uuids::uuid genTime(ros::Time uuid_time, uint64_t hw_addr)
00075 {
00076
00077
00078
00079
00080 uint64_t offset = 122192928000000000;
00081
00082 uint64_t num_hundred_epoch = static_cast<uint64_t>(uuid_time.sec) / (1e-9 * 100) +
00083 static_cast<uint64_t>(uuid_time.nsec) / 100;
00084
00085
00086 uint64_t num_hundred_rfc = num_hundred_epoch + offset;
00087
00088 uint32_t time_low = static_cast<uint32_t>(num_hundred_rfc);
00089 uint16_t time_mid = static_cast<uint16_t>(num_hundred_rfc >> 32);
00090 uint16_t version = 0x1000;
00091 uint16_t time_hi_and_version = static_cast<uint16_t>(num_hundred_rfc >> (32 + 16)) | version;
00092
00093
00094 uint16_t clock_seq_and_reserved = (rand() % (1 << 14)) | 0x8000;
00095
00096 boost::uuids::uuid uu = {
00097 static_cast<uint8_t>(time_low >> 24), static_cast<uint8_t>(time_low >> 16),
00098 static_cast<uint8_t>(time_low >> 8), static_cast<uint8_t>(time_low),
00099 static_cast<uint8_t>(time_mid >> 8), static_cast<uint8_t>(time_mid),
00100 static_cast<uint8_t>(time_hi_and_version >> 8),
00101 static_cast<uint8_t>(time_hi_and_version),
00102 static_cast<uint8_t>(clock_seq_and_reserved >> 8),
00103 static_cast<uint8_t>(clock_seq_and_reserved),
00104 static_cast<uint8_t>(hw_addr >> 40), static_cast<uint8_t>(hw_addr >> 32),
00105 static_cast<uint8_t>(hw_addr >> 24), static_cast<uint8_t>(hw_addr >> 16),
00106 static_cast<uint8_t>(hw_addr >> 8), static_cast<uint8_t>(hw_addr)
00107 };
00108 return uu;
00109 }
00110
00111 }
00112
00113 }
00114
00115 #endif // _IMPL_UNIQUE_ID_H_