Android Open Source - BLEConnector B L E Advertising Parser






From Project

Back to project page BLEConnector.

License

The source code is released under:

MIT License

If you think the Android project BLEConnector listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.felhr.bleconnector;
/*from   www .  j a  v a 2  s  .  co m*/
import java.util.ArrayList;
import java.util.List;

public class BLEAdvertisingParser 
{
  private final static int AD_INCOMPLETE_16UUID_SERVICES = 0x02;
  private final static int AD_COMPLETE_16UUID_SERVICES = 0x03;
  private final static int AD_INCOMPLETE_128UUID_SERVICES = 0x06;
  private final static int AD_COMPLETE_128UUID_SERVICES = 0x07;
  
  private BLEAdvertisingParser()
  {
    
  }
  
  public static String[] parseUUIDS(byte[] advPacket)
  {
    List<String> uuidsList = new ArrayList<String>();
    int lengthAdv = advPacket.length;
    int i = 0;
    if(lengthAdv != 0)
    {
      while(i < lengthAdv)
      {
        int lengthData = advPacket[i];
        int type =  advPacket[i+1];
        int j = i + lengthData;
        switch(type)
        {
        case AD_INCOMPLETE_16UUID_SERVICES:
          while(j <= i-lengthData)
          {
            int service = advPacket[j-1] << 8 | advPacket[j];
            uuidsList.add(Integer.toHexString(service));
            j-=2;
          }
          break;
        case AD_COMPLETE_16UUID_SERVICES:
          while(j <= i-lengthData)
          {
            int service = advPacket[j-1] << 8 | advPacket[j];
            uuidsList.add(Integer.toHexString(service));
            j-=2;
          }
          break;
        case AD_INCOMPLETE_128UUID_SERVICES:
          break;
        case AD_COMPLETE_128UUID_SERVICES:
          break;
        default:
          break;
        }
        i = i + lengthData;
      }
      
      return (String[]) uuidsList.toArray();
    }else
    {
      return null;
    }
  }
  
}




Java Source Code List

com.felhr.bleconnector.BLEAdvertisingParser.java
com.felhr.bleconnector.BLEBuffer.java
com.felhr.bleconnector.BLEConnectedDevice.java
com.felhr.bleconnector.BLEConnectedDevices.java
com.felhr.bleconnector.BLEConnector.java
com.felhr.bleconnector.BLEDevice.java