×
Namespaces

Variants
Actions

How to handle Bluetooth class of devices (CoD)

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: mahbub_s60 (30 Jun 2009)
Last edited: hamishwillee (31 May 2013)


Introduction

This article describes how we can get information about remote class of devices (CoD). CoD means what kind of devices is the remote device is, what kind of services it provides etc. In Symbian C++, TBTDeviceClass is used to implement the concept of CoD. TBTDeviceClass class has been declared in btdevice.h file that is publicly available.

How to Retrieve the CoD

Here we describe how to get the CoD by BTLinkManager. Following code example shows how we get the information.

void CBTInquiryObject::ConstructL()
{
 
_LIT(KBTLinkManagerName,"BTLinkManager");
TProtocolDesc pInfo;
TProtocolName protocolName;
protocolName.Copy( KBTLinkManagerName );
 
User::LeaveIfError( iSocketServer.Connect());
User::LeaveIfError( iSocketServer.FindProtocol( protocolName, pInfo));
User::LeaveIfError( iHostResolver.Open(iSocketServer,pInfo.iAddrFamily,pInfo.iProtocol));
 
iInquirySockAddr.SetAction(KHostResInquiry + KHostResName + KHostResIgnoreCache);
iInquirySockAddr.SetIAC(KGIAC);
}

We get our RunL() called and in RunL() retrieve the CoD information by the following code.

void CBTInquiryObject::RunL()
{
if( iStatus == KErrNone)
{
TInquirySockAddr& sa = TInquirySockAddr::Cast( iEntry().iAddr );
TBuf<24> DeviceAddress(0);
TBuf<40> DeviceName(0);
 
sa.BTAddr().GetReadable(DeviceAddress);
DeviceName.Copy(iEntry().iName);
 
TBuf8<48> DeviceAddress8(0);
TBuf8<80> DeviceName8(0);
DeviceAddress8.Copy(DeviceAddress);
DeviceName8.Copy(DeviceName);
iObserver.LogExtraL(DeviceAddress8, DeviceName8, sa.MajorServiceClass(), sa.MajorClassOfDevice(), sa.MinorClassOfDevice());
// Get next device if no previous errors
iHostResolver.Next( iEntry, iStatus );
SetActive();
}
else
{
TBuf8<12> complete(0);
complete.Copy(_L8("_Complete_")); // just to tell the observer that inquiry is complete
iObserver.LogInfoL( complete,iStatus.Int() );
}
}


Following code classify the CoD as described in btdevice.h.

void CHemeBTBrowserDetailView::LogExtraL(TDesC8 & address, TDesC8 & name, TUint16 aMajServClass,TUint aMajDeviceClass,TUint8 aMinDeviceClass, TDes & aBuf)
{
 
enum TBluetoothDeviceType {EComputer,EPhone,ELANAccessPoint,EAudioVideo, EUnknown};
TBluetoothDeviceType deviceType=EPhone;
 
aBuf.Append(_L("Major Service Class: "));
if (aMajServClass & 0x0001)
aBuf.AppendFormat(_L(" Limited Discoverable Mode "));
 
if (aMajServClass & 0x008)
aBuf.AppendFormat(_L(" Positioning "));
 
if (aMajServClass & 0x0010)
aBuf.AppendFormat(_L(" Networking "));
if (aMajServClass & 0x0020)
aBuf.AppendFormat(_L(" Rendering "));
if (aMajServClass & 0x0040)
aBuf.AppendFormat(_L(" Capturing "));
if (aMajServClass & 0x0080)
aBuf.AppendFormat(_L(" Object Transfer "));
if (aMajServClass & 0x0100)
aBuf.AppendFormat(_L(" Audio "));
if (aMajServClass & 0x0200)
aBuf.AppendFormat(_L(" Telephony "));
if (aMajServClass & 0x0400)
aBuf.AppendFormat(_L(" Information "));
 
 
// Major Device Class is one of these
deviceType=EUnknown;
aBuf.Append(_L("Major Device Class: "));
if (aMajDeviceClass == 0x00)
{
deviceType=EUnknown;
aBuf.AppendFormat(_L(" Miscellaneous"));
}
else if (aMajDeviceClass == 0x01)
{
deviceType=EComputer;
aBuf.AppendFormat(_L(" Computer "));
}
else if (aMajDeviceClass == 0x02)
{
deviceType=EPhone;
aBuf.AppendFormat(_L(" Phone "));
}
else if (aMajDeviceClass == 0x03)
{
deviceType=ELANAccessPoint;
aBuf.AppendFormat(_L(" LAN Access Point "));
}
else if (aMajDeviceClass == 0x04)
{
deviceType=EAudioVideo;
aBuf.AppendFormat(_L(" AudioVideo "));
}
else if (aMajDeviceClass == 0x05)
{
aBuf.AppendFormat(_L(" Peripheral "));
}
else if (aMajDeviceClass == 0x06)
{
aBuf.AppendFormat(_L(" Imaging"));
}
else
{
aBuf.AppendFormat(_L(" Unknown"));
}
 
 
// Minor Device Class
aBuf.Append(_L("Minor Device Class: "));
switch (deviceType)
{
case EComputer:
if (aMinDeviceClass == 0x00)
aBuf.AppendFormat(_L(" Unclassified "));
else if (aMinDeviceClass == 0x01)
aBuf.AppendFormat(_L(" Desktop Computer "));
else if (aMinDeviceClass == 0x02)
aBuf.AppendFormat(_L(" Server Computer "));
else if (aMinDeviceClass == 0x03)
aBuf.AppendFormat(_L(" Laptop "));
else if (aMinDeviceClass == 0x04)
aBuf.AppendFormat(_L(" Handheld Computer "));
else if (aMinDeviceClass == 0x05)
aBuf.AppendFormat(_L(" Palm Computer "));
else if (aMinDeviceClass == 0x06)
aBuf.AppendFormat(_L(" Wearable computer "));
else
aBuf.AppendFormat(_L(" Unknown device type "));
break;
 
case EPhone:
if (aMinDeviceClass == 0x00)
aBuf.AppendFormat(_L(" Unclassified "));
else if (aMinDeviceClass == 0x01)
aBuf.AppendFormat(_L(" Cellular Phone"));
else if (aMinDeviceClass == 0x02)
aBuf.AppendFormat(_L(" Cordless Phone"));
else if (aMinDeviceClass == 0x03)
aBuf.AppendFormat(_L(" Smart Phone "));
else if (aMinDeviceClass == 0x04)
aBuf.AppendFormat(_L(" Modem Phone"));
else if (aMinDeviceClass == 0x05)
aBuf.AppendFormat(_L(" ISDN Phone"));
else
aBuf.AppendFormat(_L(" Unknown device type "));
break;
 
case ELANAccessPoint:
if (aMinDeviceClass == 0x00)
aBuf.AppendFormat(_L(" 0% utilized "));
else if (aMinDeviceClass == 0x08)
aBuf.AppendFormat(_L(" 1-17% utilized "));
else if (aMinDeviceClass == 0x10)
aBuf.AppendFormat(_L(" 17-33% utilized "));
else if (aMinDeviceClass == 0x18)
aBuf.AppendFormat(_L(" 33-50% utilized "));
else if (aMinDeviceClass == 0x20)
aBuf.AppendFormat(_L(" 50-67% utilized "));
else if (aMinDeviceClass == 0x28)
aBuf.AppendFormat(_L(" 67-83% utilized "));
else if (aMinDeviceClass == 0x30)
aBuf.AppendFormat(_L(" 83-99% utilized "));
else if (aMinDeviceClass == 0x38)
aBuf.AppendFormat(_L(" 100% utilized "));
else
aBuf.AppendFormat(_L(" Unknown utilisation "));
break;
 
case EAudioVideo:
if (aMinDeviceClass == 0x00)
aBuf.AppendFormat(_L(" Unclassified "));
else if (aMinDeviceClass == 0x01)
aBuf.AppendFormat(_L(" Headset Profile "));
else if (aMinDeviceClass == 0x02)
aBuf.AppendFormat(_L(" Handsfree "));
else if (aMinDeviceClass == 0x04)
aBuf.AppendFormat(_L(" MicroPhone "));
else if (aMinDeviceClass == 0x05)
aBuf.AppendFormat(_L(" Loudspeaker "));
else if (aMinDeviceClass == 0x06)
aBuf.AppendFormat(_L(" Head Phone "));
else
aBuf.AppendFormat(_L(" Other Audio Video type "));
break;
default:
aBuf.AppendFormat(_L(" Unknown "));
 
break;
}
}
This page was last modified on 31 May 2013, at 02:27.
45 page views in the last 30 days.
×