PocketMagic

PocketMagic

Where Technology meets magic


Android
47 Posts
BlackBerry
4 Posts
Electronics
69 Posts
Hardware
123 Posts
High Voltage
49 Posts
Image processing
2 Posts
iPhone
4 Posts
Linux
2 Posts
Nuclear
20 Posts
Optics
11 Posts
Photography
7 Posts
Photoshop
3 Posts
Research
19 Posts
Reviews
18 Posts
Robotics
8 Posts
Security
7 Posts
Software
76 Posts
Symbian
2 Posts
Tubes
20 Posts
Windows
3 Posts
Windows Mobile
11 Posts

Top Articles!       See PocketMagic on Facebook


Building a robot – Part 2 | 8855 Views | Rate 67.08
Building a robot – Part 2
uRADMonitor - Online Radiation monitoring station | 16104 Views | Rate 66.82
uRADMonitor - Online Radiation monitoring station
Bluetooth and iOS - Use Bluetooth in your iPhone apps | 22073 Views | Rate 65.3
Bluetooth and iOS - Use Bluetooth in your iPhone apps
NMEA GPS Library for AVR Microcontrollers | 5823 Views | Rate 51.08
NMEA GPS Library for AVR Microcontrollers
Programmatically Injecting Events on Android - Part 2 | 6546 Views | Rate 46.76
Programmatically Injecting Events on Android - Part 2
Simple Switched power Supplies | 19063 Views | Rate 46.05
Simple Switched power Supplies
Capacitor Discharge Microspot Welder / Cutter | 13210 Views | Rate 38.85
Capacitor Discharge Microspot Welder / Cutter
Coil Winding machine counter with Atmega8 and Reed relay | 968 Views | Rate 38.72
Coil Winding machine counter with Atmega8 and Reed relay

 
  

Android BluetoothClass Major Service Classes, Minor and Major Device Classes


By Radu Motisan Posted on October 26th, 2011 , 1081 Views (Rate 1.8)



  

By default, the currently limited (2011) Android Bluetooth SDK, only offers access to the Major Class value of any given Bluetooth device (API getMajorDeviceClass() ), while the Minor class is only returned as a combination with the Major class (API getDeviceClass() ).

For a given Bluetooth Device (BluetoothDevice device;), one can get the Major Bluetooth class like this:

  1.  
  2. int deviceBTMajorClass = device.getBluetoothClass().getMajorDeviceClass();
  3.  

Then this integer variable can be used to determine the type of the device used:

  1.  
  2. private String getBTMajorDeviceClass(int major){
  3. switch(major){
  4. case BluetoothClass.Device.Major.AUDIO_VIDEO: return "AUDIO_VIDEO";
  5. case BluetoothClass.Device.Major.COMPUTER: return "COMPUTER";
  6. case BluetoothClass.Device.Major.HEALTH: return "HEALTH";
  7. case BluetoothClass.Device.Major.IMAGING: return "IMAGING";
  8. case BluetoothClass.Device.Major.MISC: return "MISC";
  9. case BluetoothClass.Device.Major.NETWORKING: return "NETWORKING";
  10. case BluetoothClass.Device.Major.PERIPHERAL: return "PERIPHERAL";
  11. case BluetoothClass.Device.Major.PHONE: return "PHONE";
  12. case BluetoothClass.Device.Major.TOY: return "TOY";
  13. case BluetoothClass.Device.Major.UNCATEGORIZED: return "UNCATEGORIZED";
  14. case BluetoothClass.Device.Major.WEARABLE: return "AUDIO_VIDEO";
  15. default: return "unknown!";
  16. }
  17. }
  18.  

The Bluetooth class (format type 00) is defined as a 3 Octet Integer. Please open the specifications here:
cod_definition

The Android SDK getMajorDeviceClass() API returns an integer corresponding to bits 12-11-10-9-8.
The getDeviceClass() API returns all the lower 12bits, as an integer corresponding to 12-11-10-9-8-7-6-5-4-3-2-1 .

Here are a few examples:
Bluetooth Device: Plantronics 590 A2DP Bluetooth Headset
getMajorDeviceClass: 1024
getDeviceClass:1028
Bits: (octet 3 missing) - (0 0 0 0 0 1 0 0) - (0 0 0 0 0 1 0 0)
Looking in the cod_definition.pdf attached above, on page 3, you will see that octet 2 indicates the Major Class Audio Video, and for the Audio Video Major Class, the Minor class (0 0 0 0 0 1) indicates a "Wearable Headset Device" (page 5).

Bluetooth Device: BeeWi BBK200 Mini Bluetooth Keyboard
getMajorDeviceClass: 1280
getDeviceClass:1344
Bits: (octet 3 missing) - (0 0 1 0 0 1 0 1) - (0 1 0 0 0 0 0 0)
Major class, (0 0 1 0 1) indicates Peripheral, and the Minor class (0 1) indicates a "Keyboard" (page 5, bottom).

To extract the minor class , you will need to take into account which major class was defined, because depending on the Major class, the minor class has a variable width. For Major class "Audio Video" the minor class was defined in bits 7->2, while for Major class "Peripheral", the minor class uses only two bits, 7->6.

You will need to write several functions like: GetAudioVideoMinorClass, GetPeripheralMinorClass and so on. One would look like:

  1.  
  2. int GetAudioVideoMinorClass(int cod) {
  3. return (cod & 0xFF) >> 2; // we only want the last 8 bits, then we shift to the right to only get the first 6
  4. }
  5.  

The Bluetooth COD specs also define a "Bluetooth Major service class". This one should be defined in OCTET 3, but Android's limited SDK only returns the Major device class and Minor device class (octet 2) and (octet 1).
Surprisingly, the info we need is there:

  1.  
  2. device.getBluetoothClass().toString()
  3.  

Contains all the three octets. For Plantronics 590, the string is: 0x240404 (it's hex). Changing that into binary shows:
00100100 00000100 00000100
Page 2 in Bluetooth cod specs, indicates bit 21 is "21 Audio (Speaker, Microphone, Headset service, ...)".
This bluetooth device also has bit 18 set, meaning Rendering (Printing, Speaker, ...) .


  

More on PocketMagic:

Atmega8 and enc28J60 for ethernet support | 8837 Views | Rate 27.27
Atmega8 and enc28J60 for ethernet support
How to make metallic sodium | 1424 Views | Rate 26.87
How to make metallic sodium
Tube: USN-5J29 | 1083 Views | Rate 25.79
Tube: USN-5J29
How to set the AVR Fusebits | 2540 Views | Rate 25.4
How to set the AVR Fusebits
Tube: GP-5 (ГП-5) | 630 Views | Rate 25.2
Tube: GP-5 (ГП-5)
Dual H-Bridge for controlling two motors | 2096 Views | Rate 24.95
Dual H-Bridge for controlling two motors

Thank you for commenting. Your comment won't show until approved, which can take some time.

Please copy the string LZaBjC to the field below: