How to Send an Audio HEX file to Ble Device

99封情书 提交于 2019-12-01 13:18:16

For send data upper than 20bytes, you need to change the MTU-exchange.

To API LEVEL 21, you can use requestMtu (Android Developer), it negotiates with the peripherical device and you can define until 512 bytes.

The MTU value is defined in peripherical side. Remember the data size that you can send is MTU-3 bytes.

For API LEVEL less than 21, the MTU is pre-defined and you can't modify.

The size limit can be different than 20, I suppose the MTU size is negotiable, thus you should never hard code any assumptions on sizes.

to get it right, firstly inside the onCharacteristicReadRequest you simple check the offset and give all data from that point to the response.

then in onDescriptorWriteRequest, if the preparedWrite is set to true, you need to store the values you get, and combine them once you get onExecuteWrite() called.

Example implementation available at: https://github.com/DrJukka/BLETestStuff/blob/master/MyBLETest/app/src/main/java/org/thaliproject/p2p/mybletest/BLEAdvertiserLollipop.java

One way you could proceed is to split the audio hex in to small pieces of data .You can use Serial Port Profile to send these chunks of data .Once all data are received you can combine and store using some merging algorithm (google it) and later revert it back to an audio hex file .

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