|
|
|
@ -72,6 +72,7 @@ object BleService { |
|
|
|
private var notifyChar: BluetoothGattCharacteristic? = null |
|
|
|
private var writeChar: BluetoothGattCharacteristic? = null |
|
|
|
private var audioChar: BluetoothGattCharacteristic? = null |
|
|
|
private var audioChar1: BluetoothGattCharacteristic? = null |
|
|
|
var recordfile: RecordingFile? = null |
|
|
|
|
|
|
|
// 扫描相关 |
|
|
|
@ -419,6 +420,7 @@ object BleService { |
|
|
|
notifyChar = null |
|
|
|
writeChar = null |
|
|
|
audioChar = null |
|
|
|
audioChar1 = null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -491,6 +493,10 @@ object BleService { |
|
|
|
val audioSvc = g.getService(BleConst.AUDIO_SERVICE_UUID) |
|
|
|
audioChar = audioSvc?.getCharacteristic(BleConst.RECEIVE_AUDIO_CHAR_UUID) |
|
|
|
|
|
|
|
|
|
|
|
// 获取音频服务1特征 |
|
|
|
val audioSvc1 = g.getService(BleConst.AUDIO_SERVICE_UUID1) |
|
|
|
audioChar1 = audioSvc1?.getCharacteristic(BleConst.RECEIVE_AUDIO_CHAR_UUID1) |
|
|
|
if (notifyChar == null || writeChar == null) { |
|
|
|
Log.e(TAG, "未找到主服务所需特征") |
|
|
|
updateConnectionState(BleConst.STATE_ERROR) |
|
|
|
@ -505,6 +511,12 @@ object BleService { |
|
|
|
Log.i(TAG, "音频服务特征找到并设置通知") |
|
|
|
} else { |
|
|
|
Log.w(TAG, "音频服务特征未找到") |
|
|
|
} |
|
|
|
if (audioChar1 != null) { |
|
|
|
setupNotifications(g, audioChar1) |
|
|
|
Log.i(TAG, "音频服务特征找到并设置通知") |
|
|
|
} else { |
|
|
|
Log.w(TAG, "音频服务特征未找到") |
|
|
|
} |
|
|
|
// 设置主服务的通知 |
|
|
|
setupNotifications(g, notifyChar) |
|
|
|
@ -518,10 +530,16 @@ object BleService { |
|
|
|
|
|
|
|
// 根据特征UUID区分处理 |
|
|
|
when (c.uuid) { |
|
|
|
// 音频特征数据 |
|
|
|
BleConst.RECEIVE_AUDIO_CHAR_UUID1 -> { |
|
|
|
|
|
|
|
Log.i(TAG, "RECEIVE_AUDIO_CHAR_UUID1") |
|
|
|
processAudioData(data) |
|
|
|
} |
|
|
|
// 音频特征数据 |
|
|
|
BleConst.RECEIVE_AUDIO_CHAR_UUID -> { |
|
|
|
|
|
|
|
// Log.i(TAG, "收到音频特征数据") |
|
|
|
Log.i(TAG, "RECEIVE_AUDIO_CHAR_UUID") |
|
|
|
processAudioData(data) |
|
|
|
} |
|
|
|
// 通知特征数据(命令和控制) |
|
|
|
|