|
|
|
@ -75,6 +75,7 @@ object BleService { |
|
|
|
private var notifyChar: BluetoothGattCharacteristic? = null |
|
|
|
private var writeChar: BluetoothGattCharacteristic? = null |
|
|
|
private var audioChar: BluetoothGattCharacteristic? = null |
|
|
|
private var callAudioChar: BluetoothGattCharacteristic? = null |
|
|
|
private var callWriteChar: BluetoothGattCharacteristic? = null |
|
|
|
var recordfile: RecordingFile? = null |
|
|
|
var recordfile1: RecordingFile? = null |
|
|
|
@ -702,6 +703,7 @@ object BleService { |
|
|
|
notifyChar = null |
|
|
|
writeChar = null |
|
|
|
audioChar = null |
|
|
|
callAudioChar = null |
|
|
|
callWriteChar = null |
|
|
|
} |
|
|
|
} |
|
|
|
@ -849,6 +851,7 @@ object BleService { |
|
|
|
// 获取通话音频服务特征 |
|
|
|
val callAudioSvc = g.getService(BleConst.CALL_AUDIO_SERVICE_UUID) |
|
|
|
callWriteChar = callAudioSvc?.getCharacteristic(BleConst.CALL_WRITE_AUDIO_CHAR_UUID) |
|
|
|
callAudioChar = callAudioSvc?.getCharacteristic(BleConst.CALL_RECEIVE_AUDIO_CHAR_UUID) |
|
|
|
if (callWriteChar == null) { |
|
|
|
Log.e(TAG, "未找到通话音频主服务所需特征") |
|
|
|
updateConnectionState(BleConst.STATE_ERROR) |
|
|
|
@ -860,12 +863,15 @@ object BleService { |
|
|
|
callWriteChar?.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE |
|
|
|
//要先设置音频服务的通知,否则接收不到 |
|
|
|
// 设置音频服务的通知(如果存在) |
|
|
|
if (audioChar != null) { |
|
|
|
setupNotifications(g, audioChar) |
|
|
|
Log.i(TAG, "音频服务特征找到并设置通知") |
|
|
|
if (callAudioChar != null && notifyChar != null) { |
|
|
|
setupNotifications(g, callAudioChar) |
|
|
|
setupNotifications(g, notifyChar) |
|
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "通话音频服务特征找到并设置通知") |
|
|
|
|
|
|
|
} else { |
|
|
|
Log.w(TAG, "音频服务特征未找到") |
|
|
|
Log.w(TAG, "通话音频服务特征未找到") |
|
|
|
} |
|
|
|
|
|
|
|
setupNotifications(g, notifyChar) |
|
|
|
@ -884,6 +890,12 @@ object BleService { |
|
|
|
// 音频特征数据 |
|
|
|
BleConst.RECEIVE_AUDIO_CHAR_UUID -> { |
|
|
|
|
|
|
|
// 统计接收到的字节数 |
|
|
|
bytesReceivedInCurrentSecond += data.size |
|
|
|
processAudioData(data) |
|
|
|
} |
|
|
|
BleConst.CALL_RECEIVE_AUDIO_CHAR_UUID -> { |
|
|
|
|
|
|
|
// 统计接收到的字节数 |
|
|
|
bytesReceivedInCurrentSecond += data.size |
|
|
|
processAudioData(data) |
|
|
|
|