What is a UUID?

博客介绍了UUID生成原理,其包含对主机首块网卡硬件地址的引用以确保空间唯一性,有时间戳保证时间唯一性,还有随机组件。提到可用uuidgen命令生成UUID,还说明了应用程序员可通过uuidgen命令结合接口定义语言文件让应用用UUID永久标识,最后给出IDL文件编译示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UUID stands for a Universal Unique IDentifier. These are 128 bit numbers assigned to any object within a DCE cell which is guaranteed to be unique. The mechanism used to guarantee that UUIDs are Unique is through combinations of hardware addresses, time stamps and random seeds.

There is a reference in the UUID to the hardware address of the first network card on the host which generated the UUID - this reference is intended to ensure the UUID will be unique in space as the MAC address of every network card is assigned by a single global authority and is guaranteed to be unique. (Alternate addresses might be a problem here, but the author has not tested creating a UUID on a machine with an alternate address set)

The next component is a timestamp which, as DCE always moves clocks forward, will be unique in time.

Just in case some part of the above goes wrong, there is a random component placed into the UUID as a catch-all for uniqueness.

The timestamp component though is one of the reasons why DCE does not react well to clocks going backwards.

A UUID may be generated using the uuidgen command, the following is an example of a generated UUID:-
58f202ac-22cf-11d1-b12d-002035b29092

This has come from a machine with the hardware address shown in the output of the command below:-
lscfg -vl ent0
DEVICE LOCATION DESCRIPTION
ent0 01-01 IBM ISA Ethernet Adapter
Network Address.............002035B29092
From this it may be observed that the Network address of the ethernet adapter matches the last portion of the uuid.

Application programmers may make their applications permanently identified with a UUID by creating their Interface Definition Language file with the uuidgen command, giving it the "-i" option. An example is given below.
[
uuid(5a389ad2-22dd-11d1-aa77-002035b29092),
version(1.0)
]
interface INTERFACENAME
{
}

The programmer would take this file, change the interfacename to one of their own devising then add the prototypes for the C functions they are going to implement over the network in their cell.
[
uuid(5a389ad2-22dd-11d1-aa77-002035b29092),
version(1.0)
]
interface computron
{
error_t debit_account( [ in ] long account_number,
[ in ] long amount,
[ in,out] long *balance);
error_t credit_account( [ in ] long account_number,
[ in ] long amount,
[ in,out] long *balance);
}

Would be an example of a more complete IDL file, which itself would be compiled into a useful form using the idl compiler, with the command
idl computron.idl
which would create object files which should be linked with the server and client programs to implement the distributed application.

### Bluetooth Low Energy (BLE) UUID Usage and Definition UUIDs (Universally Unique Identifiers) play a critical role in the functionality of BLE devices by uniquely identifying services, characteristics, and descriptors within the protocol stack. A UUID is typically represented as a 128-bit number but often shortened into 16-bit or 32-bit variants when possible to save space on resource-constrained devices. #### Standard vs Custom UUIDs The Bluetooth Special Interest Group (SIG) maintains a list of standard UUIDs that represent common profiles, services, and characteristics. These predefined UUIDs simplify interoperability between different BLE-enabled devices. For example, the Heart Rate Service has an assigned 16-bit UUID `0x180D` corresponding to its full 128-bit representation defined by the SIG[^1]. Developers may also define custom UUIDs for proprietary applications not covered under existing standards. #### Structure of UUIDs A complete UUID consists of five sections separated by hyphens (-), following this format: `xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx`, where M indicates version information while N specifies variant details. In practice though, many BLE implementations utilize shorter forms such as: ```csharp // Example C# code showing how you might declare these values. ushort heartRateServiceUuid = 0x180D; ushort deviceInformationServiceUuid = 0x180A; ``` When defining your own service or characteristic outside official specifications, ensure uniqueness through random generation tools unless explicitly basing off known patterns from other vendors' products. #### Practical Application Scenario Consider developing firmware targeting Nordic Semiconductor's nRF5 SDK using SEGGER J-Link debugger hardware alongside their desktop application suite including Programmer tool mentioned earlier [^3]. Here’s what setting up basic communication could look like programmatically: ```cpp #include "ble.h" #include "nrf_sdm.h" void ble_uuid_init(void){ uint32_t err_code; // Initialize base UUID structure based upon company identifier prefix allocation rules set forth by bluetooth sig guidelines. ble_uuid128_t app_base_uuid = {YOUR_COMPANY_BASE_UUID}; err_code = sd_ble_uuid_vs_add(&app_base_uuid, &custom_service.uuid_type); APP_ERROR_CHECK(err_code); } int main(){ ble_event_t evt; ble_stack_init(); gap_params_init(); gatt_init(); ble_uuid_init(); advertising_start(); while(true){ if(nrf_sdh_soc_evt_get(&evt)){ ble_dispatch(&evt); } } } ``` This snippet demonstrates initializing user-defined UUID types before starting advertisements so peers scanning nearby know available capabilities offered via those endpoints once connected successfully according established procedures outlined previously regarding attribute exchange mechanisms facilitated primarily thanks att/gatt layers introduced initially here too!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值