BLE : How can i create my own base UUID and alias - uuid

I know i can create my own service with BLE by using a 128 bit UUID using a too like uuidgen on Mac.
But i'm really confused with the way to define an alias and a base UUID for my service.
Indeed, a base UUID need to get the form of:
0x0000xxxx-1213-XYZA-1523-781FEABCD123
and the alias
Service 0x1523 : 0x00001523-1213-XYZA-1523-781FEABCD123
characteristic 0x1524 : 0x00001524-1213-XYZA-1523-781FEABCD123
But when i generate a uuid i get something like:
580663F1-AFF1-457F-9F79-0F2BF3E11892
How can i specify the alias in order to identify the Service and the characteristics ? Do i need to remove the first part ?
Or am i completly wrong and do i need to do something else to get them ?
How do i managed to generate a base UUID like the Bluetooth SIG one ?
Thanks

I guess you are free to define your UUID for your service, you don't need to follow the format you mentioned. If you use 16bit UUID, it will be extended to BLE base uuid. See below question:
What range of Bluetooth UUIDs can be used for vendor defined profiles?
For reference, you can see inside bluez's source tree, plugins/gatt-example.c. For weight service, they are using arbitrary 128-bit UUID. See register_weight_service():
https://github.com/aguedes/bluez/blob/master/plugins/gatt-example.c
Here is the service on the run, connected with gatttool (bluez tool):
attr handle: 0x003c, end grp handle: 0x0040 uuid: 00001806-0000-1000-8000-00805f9b34fb
attr handle: 0x0041, end grp handle: 0x0049 uuid: 0000180e-0000-1000-8000-00805f9b34fb
attr handle: 0x004a, end grp handle: 0x0056 uuid: 00001811-0000-1000-8000-00805f9b34fb
attr handle: 0x0057, end grp handle: 0x005b uuid: 0000a0f0-0000-1000-8000-00805f9b34fb
attr handle: 0xfffa, end grp handle: 0xfffe uuid: feee74dc-a8de-3196-1149-d43596c00a4f
And the characteristics starting from handle 0xfffa:
handle: 0xfffa, uuid: 2800
handle: 0xfffb, uuid: 2802
handle: 0xfffc, uuid: 2803
handle: 0xfffd, uuid: e9258c1e-8962-c4b6-0b45-2c9018f28880
handle: 0xfffe, uuid: 2904
handle: 0xffff, uuid: 2901

Related

D3DKMTOpenAdapterFromDeviceName and DeviceName

I'm looking for the way to communicate with display driver, and found this function, its a bit poorly documented in msdn. I need to use this, because it will return me the handle which later i can use to display the gpu load in my application. But there is a problem, what i did is i looked in my Device Manager, and copied the value of the "the path to the device instance" in my gpu properties. it looks like so:
PCI\VEN_1002&DEV_6798&SUBSYS_04481043&REV_00\4&72ACCB3&0&0008
Here is the example of D3DKMTOpenAdapterFromDeviceName which i found:
D3DKMT_OPENADAPTERFROMDEVICENAME name = { _T("\\\\?\\pci#ven_10de&dev_0a2b&subsys_9072104d&rev_a2#4&12796cb&0&0008#{1ca05180-a699-450a-9a0c-de4fbe3ddd89}") };
HMODULE hGdi32 = LoadLibrary(_T("gdi32.dll"));
PD3DKMTOpenAdapterFromDeviceName D3DKMTOpenAdapterFromDeviceName = (PD3DKMTOpenAdapterFromDeviceName)GetProcAddress(hGdi32, "D3DKMTOpenAdapterFromDeviceName");
NTSTATUS status = D3DKMTOpenAdapterFromDeviceName(&name);
In this example they have some GUID at the end of the device #{1ca05180-a699-450a-9a0c-de4fbe3ddd89}. So which GUID from the device manager properties of my GPU i should use? I tried to use like half of the GUIDS from my VideoCard properties in Device Manager and always get - "STATUS_INVALID_PARAMETER"
{1ca05180-a699-450a-9a0c-de4fbe3ddd89} is the identifier of GUID_DISPLAY_DEVICE_ARRIVAL
So you can compose your name like:
"\\\\?\\" + deviceName + "#{1ca05180-a699-450a-9a0c-de4fbe3ddd89}"
replacing your "\" for #; example with yours:
"\\\\?\\" + "PCI#VEN_1002&DEV_6798&SUBSYS_04481043&REV_00#4&72ACCB3&0&0008"+"#{1ca05180-a699-450a-9a0c-de4fbe3ddd89}"
And then to find this programatically you can do a COM search like this:
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_VideoController"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
And taking PNPDeviceID which is the string you've found at your Device Manager; take in account of being sure it's your currently in use graphic card, as it's possible to have more than one.

How to get Interfaces belongs to IID's, IConnectionPoint, IConnectionPointContainer in ANSI C

I've created a Connection between client and COM Object with help from IConnectionPoint & IConnectionPointContainer.
data->pApp->lpVtbl->QueryInterface(data->pApp, &IID_IUnknown, (void**)&data->pUnknown));
data->pUnknown->lpVtbl->QueryInterface(data->pUnknown, &IID_IConnectionPointContainer, (void**)&data->pConnectionPointContainer));
data->pConnectionPointContainer->lpVtbl->FindConnectionPoint(data->pConnectionPointContainer, &DIID__IApplicationEvents, &data->pConnectionPoint));
data->pConnectionPoint->lpVtbl->Advise(data->pConnectionPoint, (IUnknown*)sink, &sink->dwCookie));
I've already implemented QueryInterface, AddRef & Release.
If the COM Object will execute QueryInterface I printf the riid.
IID: 0x3 - 0x0 - 0x0 - 0x764D3E14
This-Objekt: 0030EC4C, ppvObject: 0030E2D4
IID: 0x3 - 0x0 - 0x0 - 0x764D3E14
This-Objekt: 0030EC4C, ppvObject: 0030E294
...
How can I find out which Interfaces belong to the IID's?
EDIT:
I would love to compare the IIDs to something i know using the suggested IsEqualGUID
but i do not know what interfaces are called by my target application.
if(IsEqualGUID(iid, &IID_IThisIsWhatIAmLookingFor))
I try to find out what interface the numbers i get are belonging to, so i try to find the interface IID_IThisIsWhatIAmLookingFor based on the numbers i get. Implementing this is the next step for me.
How can I find out which Interfaces belong to the IID's?
You cannot tell IID from interface pointer you are holding. In code, you typically manage pointers in the variables specific to certain interfaces, and you obtain the values there using respective IIDs.
What you however can is another QueryInterface call with IID of interest. Note that you cannot assume that you get the same pointer every time, unless IID is IID_IUnknown.
If you are lucky, the interface is Automation compatible and a Typelib exists. In this case, the registry contains an entry HKEY_CLASSES_ROOT\Interface\{00000000-0000-0000-0000-000000000000}\TypeLib, pointing to an entry below HRCR\Typelib, which references a .tlb file that you can import.
The alternative is entering the IID into Google in the various typical forms:
00000000-0000-0000-0000-000000000000
00000000-0000-0000-0000-0000-00000000

Named properties for CALENDER items

I want to know whether I have to fetch PropertyID for PidLidAppointmentDuration using GetNamesFromIDs(), like the way we do for Named-Property.
http://msdn.microsoft.com/en-us/library/cc433490%28v=exchg.80%29.aspx
2.11 PidLidAppointmentDuration
Canonical name: PidLidAppointmentDuration
Description: Specifies the length of the event, in minutes.
Property set: PSETID_Appointment {00062002-0000-0000-C000-000000000046}
Property long ID (LID): 0x00008213
Data type: PtypInteger32, 0x0003
Here microsoft gives PropertyID right way. So can I use 0x8213 directly without calling GetNamesFromIDs(). More importantly, will 0x8213 work in every environment.
Thanks
Ramesh
This is not at all what it means: property id here is what you pass (along with the GUID) when calling GetIdsFromNames.

PAPI and native events

Is it possible to find the set of native events (CPU counter registers) that maps to a PAPI event ?
If you have papi installed, you can use papi_avail to get the native events. For example,
papi_avail -e PAPI_TOT_INS
Event name: PAPI_TOT_INS
Event Code: 0x80000032
Number of Native Events: 1
Short Description: |Instr completed|
Long Description: |Instructions completed|
Developer's Notes: ||
Derived Type: |NOT_DERIVED|
Postfix Processing String: ||
Native Code[0]: 0x40000002 |INSTRUCTION_RETIRED|
Number of Register Values: 0
Native Event Description: |Number of instructions at retirement|
-Ganesh
I think you mean
papi_native_avail
With PAPI_event_name_to_code(...) you can add your event to your eventset for example.
In order to quickly see and export all available mappings from preset events to native events use papi_decode -a command. The output is in the CSV format. An example from my CPU:
pc#pc ~> papi_decode -a
name,derived,postfix,short_descr,long_descr,note,[native,...]
PAPI_L1_DCM,NOT_DERIVED,,"L1D cache misses","Level 1 data cache misses",,L1D:REPLACEMENT
PAPI_L1_ICM,NOT_DERIVED,,"L1I cache misses","Level 1 instruction cache misses",,L2_RQSTS:ALL_CODE_RD
PAPI_L2_DCM,DERIVED_SUB,,"L2D cache misses","Level 2 data cache misses",,LLC_REFERENCES,L2_RQSTS:CODE_RD_MISS
(...)

How to find which device is attached to a USB-serial port in Linux using C?

We are making a device and it has 8 serial ports. It runs on the Monta Vista Pro5 kernel. And we are working in C.
Suppose: A device gets attached to ttyUSB0, ttyUSB1 and ttyUSB2. The next device gets connected to ttyUSB3 and another to ttyUSB4. How can I know which device gets attached to which port ?? ie ttyUSB0 or ttyUSB1 or so on. Is there a way to directly query the device and find which port it is attached to. Or, in C, open ttyUSB0, query it somehow and get some reply as to which device it is ??
A rather complicated way: do a stat of, say /dev/ttyUSB0. Get the device number. And search for this in /proc/bus/usb/devices and find the vendor id or something to identify the device.
Or: Is there some way to reserve ttyUSB0,ttyUSB1 and ttyUSB2 for one device, ttyUSB3 for another and so on when they are plugged in ? This way I will know which device is connected to which port.
Help please..... :)
Thanks in advance.
Nubin Stanley
You can use udev rules to create symbolic links just to your device:
(these rules go in /etc/udev/rules.d/-name.rules -- look at your udev documentation
KERNEL=="ttyUSB*", ATTRS{idVendor}=="<vendorid>", MODE="0666", SYMLINK+="mydev"
You have to specify your vendor id and/or product id for your device. Then those devices will be available at /dev/mydev in the above example.
You can also use various other parameters to create appropriate unique symbolic links for your use. Check udev man page.
Here's my code, based on Alex Robinson's, but without global "except":
import os
from os.path import join
def find_tty_usb(idVendor, idProduct):
"""find_tty_usb('067b', '2302') -> '/dev/ttyUSB0'"""
# Note: if searching for a lot of pairs, it would be much faster to search
# for the enitre lot at once instead of going over all the usb devices
# each time.
for dnbase in os.listdir('/sys/bus/usb/devices'):
dn = join('/sys/bus/usb/devices', dnbase)
if not os.path.exists(join(dn, 'idVendor')):
continue
idv = open(join(dn, 'idVendor')).read().strip()
if idv != idVendor:
continue
idp = open(join(dn, 'idProduct')).read().strip()
if idp != idProduct:
continue
for subdir in os.listdir(dn):
if subdir.startswith(dnbase+':'):
for subsubdir in os.listdir(join(dn, subdir)):
if subsubdir.startswith('ttyUSB'):
return join('/dev', subsubdir)
This Python code seems to find the /dev/ttyUSB number for the given vendor ID and product ID. Not hard to translate it to C. Parsing the output from hwinfo --usb can do the trick, too. The regx is:
"\s\sVendor:\susb\s0x([0-9a-f]{4}).*?\s\sDevice:\susb\s0x([0-9a-f]{4}).*?\s\sDevice\sFile:\s/dev/ttyUSB([0-9]+)"
import glob
import os
import re
def find_usb_tty(vendor_id = None, product_id = None) :
tty_devs = []
for dn in glob.glob('/sys/bus/usb/devices/*') :
try :
vid = int(open(os.path.join(dn, "idVendor" )).read().strip(), 16)
pid = int(open(os.path.join(dn, "idProduct")).read().strip(), 16)
if ((vendor_id is None) or (vid == vendor_id)) and ((product_id is None) or (pid == product_id)) :
dns = glob.glob(os.path.join(dn, os.path.basename(dn) + "*"))
for sdn in dns :
for fn in glob.glob(os.path.join(sdn, "*")) :
if re.search(r"\/ttyUSB[0-9]+$", fn) :
#tty_devs.append("/dev" + os.path.basename(fn))
tty_devs.append(os.path.join("/dev", os.path.basename(fn)))
pass
pass
pass
pass
except ( ValueError, TypeError, AttributeError, OSError, IOError ) :
pass
pass
return tty_devs
print find_usb_tty()
The best way to do this is would be to use libusb, but if that doesn't give you enough information about your devices (which it may not), then you'll have to use the /proc filesystem which the kernel makes available, specifically /proc/bus/usb/.
Have a read of this information on /proc/bus/usb: in particular on /proc/bus/usb/devices. But as you say, this is all a bit hacky!

Resources