Better detect failed encryption
This commit is contained in:
parent
6979919a29
commit
8d3ad42ff7
1 changed files with 12 additions and 1 deletions
|
@ -19,6 +19,8 @@ import info.nightscout.androidaps.plugins.pump.danaRS.activities.EnterPinActivit
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity
|
import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTable
|
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTable
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet
|
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet
|
||||||
|
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Etc_Keep_Connection
|
||||||
|
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_General_Get_Pump_Check
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption
|
import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess
|
import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess
|
||||||
import info.nightscout.androidaps.utils.ToastUtils
|
import info.nightscout.androidaps.utils.ToastUtils
|
||||||
|
@ -72,6 +74,7 @@ class BLEComm @Inject internal constructor(
|
||||||
var isConnected = false
|
var isConnected = false
|
||||||
var isConnecting = false
|
var isConnecting = false
|
||||||
private var encryptedDataRead = false
|
private var encryptedDataRead = false
|
||||||
|
private var encryptedCommandSent = false
|
||||||
private var uartRead: BluetoothGattCharacteristic? = null
|
private var uartRead: BluetoothGattCharacteristic? = null
|
||||||
private var uartWrite: BluetoothGattCharacteristic? = null
|
private var uartWrite: BluetoothGattCharacteristic? = null
|
||||||
|
|
||||||
|
@ -99,6 +102,7 @@ class BLEComm @Inject internal constructor(
|
||||||
isConnected = false
|
isConnected = false
|
||||||
v3Encryption = false
|
v3Encryption = false
|
||||||
encryptedDataRead = false
|
encryptedDataRead = false
|
||||||
|
encryptedCommandSent = false
|
||||||
isConnecting = true
|
isConnecting = true
|
||||||
val device = bluetoothAdapter?.getRemoteDevice(address)
|
val device = bluetoothAdapter?.getRemoteDevice(address)
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
|
@ -121,7 +125,7 @@ class BLEComm @Inject internal constructor(
|
||||||
fun disconnect(from: String) {
|
fun disconnect(from: String) {
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "disconnect from: $from")
|
aapsLogger.debug(LTag.PUMPBTCOMM, "disconnect from: $from")
|
||||||
|
|
||||||
if (!encryptedDataRead && v3Encryption) {
|
if (!encryptedDataRead && encryptedCommandSent && v3Encryption) {
|
||||||
// there was no response from pump after started encryption
|
// there was no response from pump after started encryption
|
||||||
// assume pairing keys are invalid
|
// assume pairing keys are invalid
|
||||||
sp.remove(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName)
|
sp.remove(resourceHelper.gs(R.string.key_danars_v3_randompairingkey) + danaRSPlugin.mDeviceName)
|
||||||
|
@ -143,6 +147,7 @@ class BLEComm @Inject internal constructor(
|
||||||
bluetoothGatt?.disconnect()
|
bluetoothGatt?.disconnect()
|
||||||
isConnected = false
|
isConnected = false
|
||||||
encryptedDataRead = false
|
encryptedDataRead = false
|
||||||
|
encryptedCommandSent = false
|
||||||
SystemClock.sleep(2000)
|
SystemClock.sleep(2000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,6 +207,7 @@ class BLEComm @Inject internal constructor(
|
||||||
isConnecting = false
|
isConnecting = false
|
||||||
isConnected = false
|
isConnected = false
|
||||||
encryptedDataRead = false
|
encryptedDataRead = false
|
||||||
|
encryptedCommandSent = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bluetoothGatt?.setCharacteristicNotification(characteristic, enabled)
|
bluetoothGatt?.setCharacteristicNotification(characteristic, enabled)
|
||||||
|
@ -216,6 +222,7 @@ class BLEComm @Inject internal constructor(
|
||||||
isConnecting = false
|
isConnecting = false
|
||||||
isConnected = false
|
isConnected = false
|
||||||
encryptedDataRead = false
|
encryptedDataRead = false
|
||||||
|
encryptedCommandSent = false
|
||||||
return@Runnable
|
return@Runnable
|
||||||
}
|
}
|
||||||
characteristic.value = data
|
characteristic.value = data
|
||||||
|
@ -241,6 +248,7 @@ class BLEComm @Inject internal constructor(
|
||||||
isConnecting = false
|
isConnecting = false
|
||||||
isConnected = false
|
isConnected = false
|
||||||
encryptedDataRead = false
|
encryptedDataRead = false
|
||||||
|
encryptedCommandSent = false
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return bluetoothGatt?.services
|
return bluetoothGatt?.services
|
||||||
|
@ -275,6 +283,7 @@ class BLEComm @Inject internal constructor(
|
||||||
isConnecting = false
|
isConnecting = false
|
||||||
v3Encryption = false
|
v3Encryption = false
|
||||||
encryptedDataRead = false
|
encryptedDataRead = false
|
||||||
|
encryptedCommandSent = false
|
||||||
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED))
|
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED))
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Device was disconnected " + gatt.device.name) //Device was disconnected
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Device was disconnected " + gatt.device.name) //Device was disconnected
|
||||||
}
|
}
|
||||||
|
@ -527,6 +536,7 @@ class BLEComm @Inject internal constructor(
|
||||||
isConnected = true
|
isConnected = true
|
||||||
isConnecting = false
|
isConnecting = false
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Connect !!")
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Connect !!")
|
||||||
|
// Send one message to confirm communication
|
||||||
} else {
|
} else {
|
||||||
context.startActivity(Intent(context, EnterPinActivity::class.java).also { it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
|
context.startActivity(Intent(context, EnterPinActivity::class.java).also { it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Request pairing keys !!")
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Request pairing keys !!")
|
||||||
|
@ -616,6 +626,7 @@ class BLEComm @Inject internal constructor(
|
||||||
|
|
||||||
// the rest of packets
|
// the rest of packets
|
||||||
fun sendMessage(message: DanaRS_Packet) {
|
fun sendMessage(message: DanaRS_Packet) {
|
||||||
|
encryptedCommandSent = true
|
||||||
processedMessage = message
|
processedMessage = message
|
||||||
val command = byteArrayOf(message.type.toByte(), message.opCode.toByte())
|
val command = byteArrayOf(message.type.toByte(), message.opCode.toByte())
|
||||||
val params = message.requestParams
|
val params = message.requestParams
|
||||||
|
|
Loading…
Reference in a new issue