From 9170cc6f76723d6013d7c0a4b9f1e6093ec44e09 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Fri, 26 Feb 2021 17:06:03 +0100 Subject: [PATCH] move the test code to "connect" this is wrong, for now I just need an easy way to test the initial handshake --- .../driver/comm/OmnipodDashBleManagerImpl.kt | 26 +++++++++---------- .../action/DashInitializePodViewModel.kt | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) 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 243cb0f59b..3d39ce0b0f 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 @@ -31,19 +31,6 @@ class OmnipodDashBleManagerImpl @Inject constructor(private val context: Context private val bluetoothManager: BluetoothManager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager private val bluetoothAdapter: BluetoothAdapter = bluetoothManager.adapter - @Throws(InterruptedException::class, ScanFailException::class, FailedToConnectException::class, CouldNotSendBleException::class, BleIOBusyException::class, TimeoutException::class, CouldNotConfirmWriteException::class, CouldNotEnableNotifications::class, DescriptorNotFoundException::class, CouldNotConfirmDescriptorWriteException::class) - fun activateNewPod() { - aapsLogger.info(LTag.PUMPBTCOMM, "starting new pod activation") - val podScanner = PodScanner(aapsLogger, bluetoothAdapter) - val podAddress = podScanner.scanForPod(PodScanner.SCAN_FOR_SERVICE_UUID, PodScanner.POD_ID_NOT_ACTIVATED).scanResult.device.address - // For tests: this.podAddress = "B8:27:EB:1D:7E:BB"; - val bleIO = connect(podAddress) - val msgIO = MessageIO(aapsLogger, bleIO) - val ltkExchanger = LTKExchanger(aapsLogger, msgIO) - val ltk = ltkExchanger.negociateLTKAndNonce() - - aapsLogger.info(LTag.PUMPCOMM, "Got LTK and Nonce Prefix: ${ltk}") - } @Throws(FailedToConnectException::class, CouldNotSendBleException::class, InterruptedException::class, BleIOBusyException::class, TimeoutException::class, CouldNotConfirmWriteException::class, CouldNotEnableNotifications::class, DescriptorNotFoundException::class, CouldNotConfirmDescriptorWriteException::class) private fun connect(podAddress: String): BleIO { @@ -84,8 +71,19 @@ class OmnipodDashBleManagerImpl @Inject constructor(private val context: Context TODO("not implemented") } + @Throws(InterruptedException::class, ScanFailException::class, FailedToConnectException::class, CouldNotSendBleException::class, BleIOBusyException::class, TimeoutException::class, CouldNotConfirmWriteException::class, CouldNotEnableNotifications::class, DescriptorNotFoundException::class, CouldNotConfirmDescriptorWriteException::class) override fun connect() { - TODO("not implemented") + // TODO: this is wrong and I know it + aapsLogger.info(LTag.PUMPBTCOMM, "starting new pod activation") + val podScanner = PodScanner(aapsLogger, bluetoothAdapter) + val podAddress = podScanner.scanForPod(PodScanner.SCAN_FOR_SERVICE_UUID, PodScanner.POD_ID_NOT_ACTIVATED).scanResult.device.address + // For tests: this.podAddress = "B8:27:EB:1D:7E:BB"; + val bleIO = connect(podAddress) + val msgIO = MessageIO(aapsLogger, bleIO) + val ltkExchanger = LTKExchanger(aapsLogger, msgIO) + val ltk = ltkExchanger.negociateLTKAndNonce() + + aapsLogger.info(LTag.PUMPCOMM, "Got LTK and Nonce Prefix: ${ltk}") } override fun disconnect() { diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt index 692a75df06..44ae7232a5 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/wizard/activation/viewmodel/action/DashInitializePodViewModel.kt @@ -26,7 +26,7 @@ class DashInitializePodViewModel @Inject constructor(private val aapsLogger: AAP // TODO FIRST STEP OF ACTIVATION AsyncTask.execute { try { - bleManager.activateNewPod() + bleManager.connect() } catch (e: Exception) { aapsLogger.error(LTag.PUMP, "TEST ACTIVATE Exception" + e.toString() + ExceptionUtils.getStackTrace(e))