feat: add BleRelayManager sendRelayCommand and disconnect
This commit is contained in:
parent
a60f6cdc1c
commit
0f3b695140
1 changed files with 23 additions and 2 deletions
|
|
@ -142,8 +142,29 @@ class BleRelayManager(
|
|||
handler.removeCallbacksAndMessages(null)
|
||||
}
|
||||
|
||||
fun sendRelayCommand(cmd: Byte) {}
|
||||
fun disconnect() {}
|
||||
@SuppressLint("MissingPermission")
|
||||
fun sendRelayCommand(cmd: Byte) {
|
||||
val char = relayCharacteristic ?: return
|
||||
val gatt = bluetoothGatt ?: return
|
||||
val key = hmacKey ?: return
|
||||
|
||||
val packet = buildPacket(cmd, key)
|
||||
char.value = packet
|
||||
char.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
|
||||
gatt.writeCharacteristic(char)
|
||||
seq++
|
||||
if (seq > PrefsHelper.SEQ_MAX) seq = 1
|
||||
PrefsHelper.getPrefs(context).edit().putInt(PrefsHelper.PREF_SEQ, seq).apply()
|
||||
Log.d(TAG, "Sent relay cmd 0x${cmd.toString(16)} (seq=${seq - 1})")
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun disconnect() {
|
||||
handler.removeCallbacks(scanRunnable)
|
||||
scanTimeoutRunnable?.let { handler.removeCallbacks(it) }
|
||||
stopScan()
|
||||
bluetoothGatt?.disconnect()
|
||||
}
|
||||
fun updateKeys() {
|
||||
loadState()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue