function process(payload) {
  var advertiserDataLength = payload.length;
  var cursor = 0;
  var advertiserData = {};
  while(cursor < advertiserDataLength) {
    var length = (parseInt(payload.substr(cursor,2),16) + 1) * 2;
    var tag = payload.substr(cursor + 2, 2);
    var data = payload.substr(cursor + 4, length - 4);
    switch(tag) {
      case("01"):
        advertiserData.flags = flags.process(data);
        break;
      case("02"):
        advertiserData.nonComplete16BitUUIDs = uuid.process(data);
        break;
      case("03"):
        advertiserData.complete16BitUUIDs = uuid.process(data);
        break;
      case("04"):
        advertiserData.nonComplete32BitUUIDs = uuid.process(data);
        break;
      case("05"):
        advertiserData.complete32BitUUIDs = uuid.process(data);
        break;
      case("06"):
        advertiserData.nonComplete128BitUUIDs = uuid.process(data);
        break;
      case("07"):
        advertiserData.complete128BitUUIDs = uuid.process(data);
        break;
      case("08"):
        advertiserData.shortenedLocalName = localname.process(data);
        break;
      case("09"):
        advertiserData.completeLocalName = localname.process(data);
        break;
      case("0a"):
        advertiserData.txPower = txpower.process(data);
        break;
      case("0d"):
        advertiserData.classOfDevice = data;
        break;
      case("0e"):
        advertiserData.simplePairingHashC = data;
        break;
      case("0f"):
        advertiserData.simplePairingRandomizerR = data;
        break;
      case("10"):
        advertiserData.securityManagerTKValue = data;
        break;
      case("11"):
        advertiserData.securityManagerOOBFlags = data;
        break;
      case("12"):
        advertiserData.slaveConnectionIntervalRange = data;
        break;
      case("14"):
        advertiserData.solicitation16BitUUIDs = solicitation.process(data);
        break;
      case("15"):
        advertiserData.solicitation128BitUUIDs = solicitation.process(data);
        break;
      case("16"):
        advertiserData.serviceData = servicedata.process(data);
        break;
      case("17"):
        advertiserData.publicTargetAddress = data;
        break;
      case("18"):
        advertiserData.randomTargetAddress = data;
        break;
      case("19"):
        advertiserData.appearance = data;
        break;
      case("1a"):
        advertiserData.advertisingInterval = data;
        break;
      case("1b"):
        advertiserData.leBluetoothDeviceAddress = data;
        break;
      case("1c"):
        advertiserData.leRole = data;
        break;
      case("1d"):
        advertiserData.simplePairingHashC256 = data;
        break;
      case("1e"):
        advertiserData.simplePairingRandomizerR256 = data;
        break;
      case("1f"):
        advertiserData.solicitation32BitUUIDs = data;
        break;
      case("20"):
        advertiserData.serviceData32BitUUID = data;
        break;
      case("21"):
        advertiserData.serviceData128BitUUID = data;
        break;
      case("22"):
        advertiserData.leSecureConnectionsConfirmationValue = data;
        break;
      case("23"):
        advertiserData.leSecureConnectionsRandomValue = data;
        break;
      case("24"):
        advertiserData.uri = data;
        break;
      case("25"):
        advertiserData.indoorPositioning = data;
        break;
      case("26"):
        advertiserData.transportDiscoveryData = data;
        break;
      case("27"):
        advertiserData.leSupportedFeatures = data;
        break;
      case("28"):
        advertiserData.channelMapUpdateInformation = data;
        break;
      case("29"):
        advertiserData.pbAdv = data;
        break;
      case("2a"):
        advertiserData.meshMessage = data;
        break;
      case("2b"):
        advertiserData.meshBeacon = data;
        break;
      case("3d"):
        advertiserData.informationData3D = data;
        break;
      case("ff"):
        advertiserData.manufacturerSpecificData =
                                       manufacturerspecificdata.process(data);
        break;
      default:
        //console.log("Unhandled BLE tag " + tag);
    }
    cursor += length;
  }
  return advertiserData;
}
/**
 * Convert a raw Bluetooth Low Energy advertising packet into its meaningful
 * parts.
 * https://www.bluetooth.org/en-us/specification/assigned-numbers/generic-access-profile
 * @param {string} payload The raw payload as a hexadecimal-string.
 * @return {Object} Semantically meaningful advertising packet.
 */
Convert a raw Bluetooth Low Energy advertising packet into its meaningful
parts.
Convert a raw Bluetooth Low Energy advertising packet into its meaningful parts .
function process(payload) {
  var advertiserDataLength = payload.length;
  var cursor = 0;
  var advertiserData = {};
  while(cursor < advertiserDataLength) {
    var length = (parseInt(payload.substr(cursor,2),16) + 1) * 2;
    var tag = payload.substr(cursor + 2, 2);
    var data = payload.substr(cursor + 4, length - 4);
    switch(tag) {
      case("01"):
        advertiserData.flags = flags.process(data);
        break;
      case("02"):
        advertiserData.nonComplete16BitUUIDs = uuid.process(data);
        break;
      case("03"):
        advertiserData.complete16BitUUIDs = uuid.process(data);
        break;
      case("04"):
        advertiserData.nonComplete32BitUUIDs = uuid.process(data);
        break;
      case("05"):
        advertiserData.complete32BitUUIDs = uuid.process(data);
        break;
      case("06"):
        advertiserData.nonComplete128BitUUIDs = uuid.process(data);
        break;
      case("07"):
        advertiserData.complete128BitUUIDs = uuid.process(data);
        break;
      case("08"):
        advertiserData.shortenedLocalName = localname.process(data);
        break;
      case("09"):
        advertiserData.completeLocalName = localname.process(data);
        break;
      case("0a"):
        advertiserData.txPower = txpower.process(data);
        break;
      case("0d"):
        advertiserData.classOfDevice = data;
        break;
      case("0e"):
        advertiserData.simplePairingHashC = data;
        break;
      case("0f"):
        advertiserData.simplePairingRandomizerR = data;
        break;
      case("10"):
        advertiserData.securityManagerTKValue = data;
        break;
      case("11"):
        advertiserData.securityManagerOOBFlags = data;
        break;
      case("12"):
        advertiserData.slaveConnectionIntervalRange = data;
        break;
      case("14"):
        advertiserData.solicitation16BitUUIDs = solicitation.process(data);
        break;
      case("15"):
        advertiserData.solicitation128BitUUIDs = solicitation.process(data);
        break;
      case("16"):
        advertiserData.serviceData = servicedata.process(data);
        break;
      case("17"):
        advertiserData.publicTargetAddress = data;
        break;
      case("18"):
        advertiserData.randomTargetAddress = data;
        break;
      case("19"):
        advertiserData.appearance = data;
        break;
      case("1a"):
        advertiserData.advertisingInterval = data;
        break;
      case("1b"):
        advertiserData.leBluetoothDeviceAddress = data;
        break;
      case("1c"):
        advertiserData.leRole = data;
        break;
      case("1d"):
        advertiserData.simplePairingHashC256 = data;
        break;
      case("1e"):
        advertiserData.simplePairingRandomizerR256 = data;
        break;
      case("1f"):
        advertiserData.solicitation32BitUUIDs = data;
        break;
      case("20"):
        advertiserData.serviceData32BitUUID = data;
        break;
      case("21"):
        advertiserData.serviceData128BitUUID = data;
        break;
      case("22"):
        advertiserData.leSecureConnectionsConfirmationValue = data;
        break;
      case("23"):
        advertiserData.leSecureConnectionsRandomValue = data;
        break;
      case("24"):
        advertiserData.uri = data;
        break;
      case("25"):
        advertiserData.indoorPositioning = data;
        break;
      case("26"):
        advertiserData.transportDiscoveryData = data;
        break;
      case("27"):
        advertiserData.leSupportedFeatures = data;
        break;
      case("28"):
        advertiserData.channelMapUpdateInformation = data;
        break;
      case("29"):
        advertiserData.pbAdv = data;
        break;
      case("2a"):
        advertiserData.meshMessage = data;
        break;
      case("2b"):
        advertiserData.meshBeacon = data;
        break;
      case("3d"):
        advertiserData.informationData3D = data;
        break;
      case("ff"):
        advertiserData.manufacturerSpecificData =
                                       manufacturerspecificdata.process(data);
        break;
      default:
    }
    cursor += length;
  }
  return advertiserData;
}
function process ( payload ) { var advertiserDataLength = payload . length ; var cursor = 0 ; var advertiserData = { } ; while ( cursor < advertiserDataLength ) { var length = ( parseInt ( payload . substr ( cursor , 2 ) , 16 ) + 1 ) * 2 ; var tag = payload . substr ( cursor + 2 , 2 ) ; var data = payload . substr ( cursor + 4 , length - 4 ) ; switch ( tag ) { case ( "01" ) : advertiserData . flags = flags . process ( data ) ; break ; case ( "02" ) : advertiserData . nonComplete16BitUUIDs = uuid . process ( data ) ; break ; case ( "03" ) : advertiserData . complete16BitUUIDs = uuid . process ( data ) ; break ; case ( "04" ) : advertiserData . nonComplete32BitUUIDs = uuid . process ( data ) ; break ; case ( "05" ) : advertiserData . complete32BitUUIDs = uuid . process ( data ) ; break ; case ( "06" ) : advertiserData . nonComplete128BitUUIDs = uuid . process ( data ) ; break ; case ( "07" ) : advertiserData . complete128BitUUIDs = uuid . process ( data ) ; break ; case ( "08" ) : advertiserData . shortenedLocalName = localname . process ( data ) ; break ; case ( "09" ) : advertiserData . completeLocalName = localname . process ( data ) ; break ; case ( "0a" ) : advertiserData . txPower = txpower . process ( data ) ; break ; case ( "0d" ) : advertiserData . classOfDevice = data ; break ; case ( "0e" ) : advertiserData . simplePairingHashC = data ; break ; case ( "0f" ) : advertiserData . simplePairingRandomizerR = data ; break ; case ( "10" ) : advertiserData . securityManagerTKValue = data ; break ; case ( "11" ) : advertiserData . securityManagerOOBFlags = data ; break ; case ( "12" ) : advertiserData . slaveConnectionIntervalRange = data ; break ; case ( "14" ) : advertiserData . solicitation16BitUUIDs = solicitation . process ( data ) ; break ; case ( "15" ) : advertiserData . solicitation128BitUUIDs = solicitation . process ( data ) ; break ; case ( "16" ) : advertiserData . serviceData = servicedata . process ( data ) ; break ; case ( "17" ) : advertiserData . publicTargetAddress = data ; break ; case ( "18" ) : advertiserData . randomTargetAddress = data ; break ; case ( "19" ) : advertiserData . appearance = data ; break ; case ( "1a" ) : advertiserData . advertisingInterval = data ; break ; case ( "1b" ) : advertiserData . leBluetoothDeviceAddress = data ; break ; case ( "1c" ) : advertiserData . leRole = data ; break ; case ( "1d" ) : advertiserData . simplePairingHashC256 = data ; break ; case ( "1e" ) : advertiserData . simplePairingRandomizerR256 = data ; break ; case ( "1f" ) : advertiserData . solicitation32BitUUIDs = data ; break ; case ( "20" ) : advertiserData . serviceData32BitUUID = data ; break ; case ( "21" ) : advertiserData . serviceData128BitUUID = data ; break ; case ( "22" ) : advertiserData . leSecureConnectionsConfirmationValue = data ; break ; case ( "23" ) : advertiserData . leSecureConnectionsRandomValue = data ; break ; case ( "24" ) : advertiserData . uri = data ; break ; case ( "25" ) : advertiserData . indoorPositioning = data ; break ; case ( "26" ) : advertiserData . transportDiscoveryData = data ; break ; case ( "27" ) : advertiserData . leSupportedFeatures = data ; break ; case ( "28" ) : advertiserData . channelMapUpdateInformation = data ; break ; case ( "29" ) : advertiserData . pbAdv = data ; break ; case ( "2a" ) : advertiserData . meshMessage = data ; break ; case ( "2b" ) : advertiserData . meshBeacon = data ; break ; case ( "3d" ) : advertiserData . informationData3D = data ; break ; case ( "ff" ) : advertiserData . manufacturerSpecificData = manufacturerspecificdata . process ( data ) ; break ; default : } cursor += length ; } return advertiserData ; }
Convert a raw Bluetooth Low Energy advertising packet into its meaningful
 parts.
Convert a raw Bluetooth Low Energy advertising packet into its meaningful parts .
//console.log("Unhandled BLE tag " + tag);