How to get BluetoothGattCharacteristic value format type?

[亡魂溺海] 提交于 2019-12-05 03:49:29

问题


While developing an application for IOT tried communicating with a BLE peripheral device. Using BLE Lollipop API.

Each BluetoothGattService can provide different BluetoothGattCharacteristic, each representing a certain value which can be Read, Write or Notified.

Value is communicated in various formats. But there is no way to know which format a particular Characteristic is encoded in.

I thought this mKeySize could be a solution but, it is neither accessible nor being used inside BluetoothGattCharacteristic to determine any value output.

 /**
 * Returns the deisred key size.
 * @hide
 */
/*package*/ int getKeySize() {
    return mKeySize;
}

I made use of following functions to check out desired output.

   String getStringValue (int offset)
   getIntValue(int formatType, int offset)
   getFloatValue(int formatType, int offset)

But they were only useful in certain cases where communicated data was not complex e.g

DeviceName -> (getStringValue)

BatteryLevel ->(getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8,0))

They were easy bait but characteristics like Peripheral Preferred Connection Parameters nowhere to be recognized.

I have already used a static hashmap to retrieve Specification Name based on their assigned number which seems to grow bigger in size to include all adapted BLE profile.

I would like to know are there any better methods available to fetch BluetoothGattCharacteristics value appropriately?

Also, there are different ways to write characteristic value and at certain places specific value, how should I approach this uncertainty?

Check out this android application BLEScanner, to a major extent can perform Read and Write.

来源:https://stackoverflow.com/questions/37432958/how-to-get-bluetoothgattcharacteristic-value-format-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!