[英]BLE Manufacture Advertise data
在 BLE 制造商數據中,從字節轉換為字符串時,我得到如下數據:
JLG BLE
ÿS7452396��������ÿSPH90234380,100084,������������������。
即使從字節轉換為十六進制,然后將十六進制轉換為字符串打印,也只能像這樣。
十六進制格式:
02010608084A4C4720424C45020A0A0FFF530704373435323339360000000015FF5307504839303233343338302C3130303038342C000000000000000000。
在 ios 制造數據打印這樣
1.原始數據(ASCII):
53070355 52323031 39313130 33315048 39303233 34333830 2c313030 3038342c
2.字符串值:
SUR201911031PH90234380,100084,
所以在 Android 中,我如何打印原始數據和字符串值,如 iOS
我得到這樣的掃描結果
ScanResult{device=D6:23:72:02:69:72, scanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=null, mManufacturerSpecificData={1875=[80, 72, 57, 48, 50, 51, 52, 51, 56, 48, 44, 49, 48, 48, 48, 56, 52, 44]}, mServiceData={}, mTxPowerLevel=10, mDeviceName=JLG BLE], rssi=-59, timestampNanos=34872779608333, eventType=27, primaryPhy=1,secondaryPhy=0,advertisingSid=255,txPower=127,periodicAdvertisingInterval=0}
private ScanCallback mScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
try {
BluetoothDevice btDevice = result.getDevice();
String name = btDevice.getName();
// Log.d("advertisedData",);
if (name != null && name.equalsIgnoreCase(JLGConstants.BLE_NAME)) {
JLGBluetoothManufacturerData bluetoothManufacturerData = new JLGBluetoothManufacturerData();
bluetoothManufacturerData.setBluetoothDevice(result.getDevice());
bluetoothManufacturerData.setRssi(result.getRssi());
Log.e("address",""+result);
if (bluetoothManufactureDataList.isEmpty()) {
String scanHex = "";
SparseArray<byte[]> advertisedData = result.getScanRecord().getManufacturerSpecificData();
ScanRecord advertisedDataBytes = result.getScanRecord();
Log.d("advertisedData hex format",JLGCommonFunctions.bytesToHex(advertisedDataBytes.getBytes()));
Log.d("advertisedData String format",JLGCommonFunctions.bytesToString(advertisedDataBytes.getBytes()));
}
}
} catch (Exception e) {
JLGCommonFunctions.logExceptions(e);
}
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
/*do nothing*/
}
@Override
public void onScanFailed(int errorCode) {
/*do nothing*/
}
};
以下字節在 Android 和 iOS 上接收到的原始數據中:
39303233343338302C3130303038342C
在這部分之前,您的 JLG 外設在 Android 和 iOS 之間對不同的制造商數據進行編碼。
據推測,iOS 數據包括外設的私有 BLE 地址,因為使用 iOS 無法通過使用 CoreBluetooth 的廣告數據包獲取廣告 BLE 外設的私有地址。
如果您的應用需要唯一標識未知的 BLE 外圍設備,則此標識信息必須由外圍設備提供,只要此信息適合廣告數據包即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.