diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt index 3d9ba70948..1d1244f4ef 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/OmnipodDashBleManagerImpl.kt @@ -134,8 +134,8 @@ class OmnipodDashBleManagerImpl @Inject constructor( // emitter.onNext(PodEvent.EstablishingSession) - val EapAkaExchanger = EapAkaExchanger(aapsLogger, msgIO, ltk) - val sessionKeys = EapAkaExchanger.negotiateSessionKeys() + val eapAkaExchanger = EapAkaExchanger(aapsLogger, msgIO, ltk) + val sessionKeys = eapAkaExchanger.negotiateSessionKeys() aapsLogger.info(LTag.PUMPCOMM, "CK: ${sessionKeys.ck.toHex()}") aapsLogger.info(LTag.PUMPCOMM, "noncePrefix: ${sessionKeys.noncePrefix.toHex()}") aapsLogger.info(LTag.PUMPCOMM, "SQN: ${sessionKeys.sqn.toHex()}") diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/BleCommCallbacks.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/BleCommCallbacks.kt index 8330b6b08c..c1d50aa890 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/BleCommCallbacks.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/BleCommCallbacks.kt @@ -45,18 +45,18 @@ class BleCommCallbacks( } @Throws(InterruptedException::class) - fun waitForConnection(timeout_ms: Int) { - connected.await(timeout_ms.toLong(), TimeUnit.MILLISECONDS) + fun waitForConnection(timeoutMs: Int) { + connected.await(timeoutMs.toLong(), TimeUnit.MILLISECONDS) } @Throws(InterruptedException::class) - fun waitForServiceDiscovery(timeout_ms: Int) { - serviceDiscoveryComplete.await(timeout_ms.toLong(), TimeUnit.MILLISECONDS) + fun waitForServiceDiscovery(timeoutMs: Int) { + serviceDiscoveryComplete.await(timeoutMs.toLong(), TimeUnit.MILLISECONDS) } @Throws(InterruptedException::class, TimeoutException::class, CouldNotConfirmWriteException::class) - fun confirmWrite(expectedPayload: ByteArray, timeout_ms: Int) { - val received: CharacteristicWriteConfirmation = writeQueue.poll(timeout_ms.toLong(), TimeUnit.MILLISECONDS) + fun confirmWrite(expectedPayload: ByteArray, timeoutMs: Int) { + val received: CharacteristicWriteConfirmation = writeQueue.poll(timeoutMs.toLong(), TimeUnit.MILLISECONDS) ?: throw TimeoutException() when (received) { @@ -116,9 +116,9 @@ class BleCommCallbacks( } @Throws(InterruptedException::class, CouldNotConfirmDescriptorWriteException::class) - fun confirmWriteDescriptor(descriptorUUID: String, timeout_ms: Int) { + fun confirmWriteDescriptor(descriptorUUID: String, timeoutMs: Int) { val confirmed: DescriptorWriteConfirmation = descriptorWriteQueue.poll( - timeout_ms.toLong(), + timeoutMs.toLong(), TimeUnit.MILLISECONDS ) ?: throw TimeoutException() diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/BleIO.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/BleIO.kt index 33e3068342..ecb249042a 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/BleIO.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/BleIO.kt @@ -81,7 +81,16 @@ class BleIO( * Called before sending a new message. * The incoming queues should be empty, so we log when they are not. */ - fun flushIncomingQueues() {} + fun flushIncomingQueues() { + for (chr in CharacteristicType.values()) { + do { + val found = incomingPackets[chr]?.poll() + found?.let { + aapsLogger.warn(LTag.PUMPBTCOMM, "BleIO: CMD queue not empty, flushing: {${found.toHex()}") + } + } while (found != null) + } + } /** * Enable intentions on the characteristics. diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/MessagePacket.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/MessagePacket.kt index fa7b994d8c..eba676f388 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/MessagePacket.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/MessagePacket.kt @@ -70,8 +70,8 @@ data class MessagePacket( companion object { - private val MAGIC_PATTERN = "TW" // all messages start with this string - private val HEADER_SIZE = 16 + private const val MAGIC_PATTERN = "TW" // all messages start with this string + private const val HEADER_SIZE = 16 fun parse(payload: ByteArray): MessagePacket { if (payload.size < HEADER_SIZE) { diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Milenage.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Milenage.kt index 9d2b4e87ec..ba10b74db1 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Milenage.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Milenage.kt @@ -12,7 +12,7 @@ class Milenage( private val aapsLogger: AAPSLogger, private val k: ByteArray, val sqn: ByteArray, - val _rand: ByteArray? = null + private val randParam: ByteArray? = null ) { init { @@ -27,10 +27,10 @@ class Milenage( cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec) } - val rand = _rand ?: ByteArray(KEY_SIZE) + val rand = randParam ?: ByteArray(KEY_SIZE) init { - if (_rand == null) { + if (randParam == null) { val random = SecureRandom() random.nextBytes(rand) }