This tutorial shows you how to retrieve and process the data from a Bluetooth Extended Inquiry Response (EIR).
This tutorial shows you how to retrieve the EIR data and how to access the various types of data within it.
Basic Procedure
The high level steps to access the EIR are shown here:
This tutorial assumes that
you have your device correctly configured, active and with Bluetooth
enabled and the Bluetooth Stack initialised. iResult
is in scope and contains a TNameEntry object
as the result of a successful Inquiry request. See Inquiring About Remote
Devices.
Note: When the Inquiry Request is
made, set the aDoEIR
flag to specify that Extended
Inquire Response data is required. The Bluetooth Stack will set the aDoEIR
flag if an older version of the API (non-EIR) is
used.
Create an object to hold the Extended Inquiry Response data
Use access functions to retrieve the various kinds of data
Get the Bluetooth device local name
Note: The device local name may
be truncated if it is too long to fit in the EIR data packet. If the
name is not truncated then the isNameComplete
flag
will be set to TRUE
.
TBool isNameComplete; TInt error = KErrNone; TInt length = 0; // Get name // This length could be used to create the TBuf to be passed into GetDeviceName() length = eir.GetDeviceNameLength(); TBuf<255> name; if(length >= 0) { // name will contain a Unicode encoded 16-bit string error = eir.GetDeviceName(name, isNameComplete); } else { error = length; } if(error == KErrNone) // we have name here { if(isNameComplete == EFalse) { iHROutputConsole->Printf(_L("%d Bytes [Partial] Name: "), length); } else { iHROutputConsole->Printf(_L("%d Bytes [Complete] Name: "), length); } iHROutputConsole->Printf(_L("%S \n"),&name); }
Get the Transmission Power level
// Get TxPowerLevel TInt8 txPowerLevel; error = eir.GetTxPowerLevel(txPowerLevel); if(error == KErrNone) // TxPowerLevel present { iHROutputConsole->Printf(_L("TxPowerLevel: %ddBm\n"), txPowerLevel); }
Get the Service Class UUIDs.
// Get UUIDs RExtendedInquiryResponseUUIDContainer uuidContainer; error = eir.GetServiceClassUuids(uuidContainer); if(error >= KErrNone) { RArray<TUUID> uuids; TInt uuidCount = uuidContainer.UUIDs().Count(); if(uuidCount > 0) { iHROutputConsole->Printf(_L("*** UUID Count: %d\n"), uuidCount); TInt i; for(i=0;i<uuidCount;i++) { TInt j; TPtrC8 uuid(uuidContainer.UUIDs()[i].ShortestForm()); // Treat it as a big endian for(j=0;j<uuid.Length();j++) { iHROutputConsole->Printf(_L("%02X"), uuid[j]); } iHROutputConsole->Printf(_L(" \n")); } } }
Get Manufacturer Specific data.
Note: This data is entirely defined by the individual Manufacturer.
// Get Manufacturer Specific Data length = eir.GetVendorSpecificDataLength(); TBuf8<255> msd; if(length > 0) { error = eir.GetVendorSpecificData(msd); } else { error = length; } if(error == KErrNone) // we have Manufacturer Specific Data here { // This conversion is for display reason, in a real world this may not be necessary as // Manufacturer specific data can be just raw 8-bit data, however GetDeviceName() is // different as it always return Unicode encoded 16-bit string error = CnvUtfConverter::ConvertToUnicodeFromUtf8(name, msd); if(error >= KErrNone && length > 0) { iHROutputConsole->Printf(_L("%d Bytes Manufacturer Specific Data: %S\n"), length, &name); } } }