From 358748654e02771122a6467ed422b59b11887f7e Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Fri, 26 Feb 2021 18:30:59 +0100 Subject: [PATCH] ble: reformat(Ctrl+Alt+L) --- .../driver/comm/OmnipodDashBleManagerImpl.kt | 1 - .../driver/comm/callbacks/BleCommCallbacks.kt | 5 +++-- .../callbacks/DescriptorWriteConfirmation.kt | 4 ++-- .../dash/driver/comm/command/BleCommand.kt | 16 ++++++++-------- .../dash/driver/comm/command/BleCommandNack.kt | 4 +--- .../CouldNotConfirmDescriptorWriteException.kt | 4 ++-- .../exceptions/CouldNotConfirmWriteException.kt | 4 ++-- .../exceptions/DiscoveredInvalidPodException.kt | 6 +++--- .../comm/exceptions/FailedToConnectException.kt | 4 ++-- .../driver/comm/exceptions/ScanFailException.kt | 4 ++-- .../exceptions/UnexpectedCommandException.kt | 4 +--- .../omnipod/dash/driver/comm/ltk/PairMessage.kt | 2 +- .../pump/omnipod/dash/driver/comm/message/Id.kt | 5 ++--- 13 files changed, 29 insertions(+), 34 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 3d39ce0b0f..b46a990e47 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,7 +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(FailedToConnectException::class, CouldNotSendBleException::class, InterruptedException::class, BleIOBusyException::class, TimeoutException::class, CouldNotConfirmWriteException::class, CouldNotEnableNotifications::class, DescriptorNotFoundException::class, CouldNotConfirmDescriptorWriteException::class) private fun connect(podAddress: String): BleIO { // TODO: locking? 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 5580ef31ca..b921f34254 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 @@ -7,10 +7,10 @@ import android.bluetooth.BluetoothGattDescriptor import android.bluetooth.BluetoothProfile import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io.CharacteristicType -import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io.CharacteristicType.Companion.byValue import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.CouldNotConfirmDescriptorWriteException import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.CouldNotConfirmWriteException +import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io.CharacteristicType +import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io.CharacteristicType.Companion.byValue import info.nightscout.androidaps.utils.extensions.toHex import java.util.concurrent.BlockingQueue import java.util.concurrent.CountDownLatch @@ -141,6 +141,7 @@ class BleCommCallbacks(private val aapsLogger: AAPSLogger, private val incomingP } companion object { + private const val WRITE_CONFIRM_TIMEOUT_MS = 10 // the confirmation queue should be empty anyway } } \ No newline at end of file diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/DescriptorWriteConfirmation.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/DescriptorWriteConfirmation.kt index 3c7b4f4f9f..fbbb5b7f1b 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/DescriptorWriteConfirmation.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/DescriptorWriteConfirmation.kt @@ -2,6 +2,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.callbac sealed class DescriptorWriteConfirmation -data class DescriptorWriteConfirmationUUID(val uuid: String): DescriptorWriteConfirmation() +data class DescriptorWriteConfirmationUUID(val uuid: String) : DescriptorWriteConfirmation() -data class DescriptorWriteConfirmationError(val status: Int): DescriptorWriteConfirmation() \ No newline at end of file +data class DescriptorWriteConfirmationError(val status: Int) : DescriptorWriteConfirmation() \ No newline at end of file diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/command/BleCommand.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/command/BleCommand.kt index 3ba0178b2e..a51e738df4 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/command/BleCommand.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/command/BleCommand.kt @@ -2,11 +2,11 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.command open class BleCommand(val data: ByteArray) { - constructor(type: BleCommandType) : this(byteArrayOf(type.value)) {} + constructor(type: BleCommandType) : this(byteArrayOf(type.value)) - constructor(type: BleCommandType, payload: ByteArray): this( + constructor(type: BleCommandType, payload: ByteArray) : this( byteArrayOf(type.value) + payload - ) {} + ) override fun equals(other: Any?): Boolean { if (this === other) return true @@ -22,12 +22,12 @@ open class BleCommand(val data: ByteArray) { } } -class BleCommandRTS(): BleCommand(BleCommandType.RTS) {} +class BleCommandRTS : BleCommand(BleCommandType.RTS) -class BleCommandCTS(): BleCommand(BleCommandType.CTS) {} +class BleCommandCTS : BleCommand(BleCommandType.CTS) -class BleCommandAbort(): BleCommand(BleCommandType.ABORT) {} +class BleCommandAbort : BleCommand(BleCommandType.ABORT) -class BleCommandSuccess(): BleCommand(BleCommandType.SUCCESS) {} +class BleCommandSuccess : BleCommand(BleCommandType.SUCCESS) -class BleCommandFail(): BleCommand(BleCommandType.FAIL) {} +class BleCommandFail : BleCommand(BleCommandType.FAIL) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/command/BleCommandNack.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/command/BleCommandNack.kt index 166ba616e4..14e0705c2b 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/command/BleCommandNack.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/command/BleCommandNack.kt @@ -1,5 +1,3 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.command -import java.nio.ByteBuffer - -class BleCommandNack(idx: Byte): BleCommand(BleCommandType.NACK, byteArrayOf(idx)) +class BleCommandNack(idx: Byte) : BleCommand(BleCommandType.NACK, byteArrayOf(idx)) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/CouldNotConfirmDescriptorWriteException.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/CouldNotConfirmDescriptorWriteException.kt index 2bc86e92a7..75c9f82344 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/CouldNotConfirmDescriptorWriteException.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/CouldNotConfirmDescriptorWriteException.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions class CouldNotConfirmDescriptorWriteException(override val message: String?) : Exception(message) { - constructor(sent: String, confirmed: String): this("Could not confirm write. Sent: {$sent} .Received: ${confirmed}") - constructor(status: Int): this("Could not confirm write. Write status: ${status}") + constructor(sent: String, confirmed: String) : this("Could not confirm write. Sent: {$sent} .Received: ${confirmed}") + constructor(status: Int) : this("Could not confirm write. Write status: ${status}") } \ No newline at end of file diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/CouldNotConfirmWriteException.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/CouldNotConfirmWriteException.kt index a3c15bfb05..9217668e77 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/CouldNotConfirmWriteException.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/CouldNotConfirmWriteException.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions class CouldNotConfirmWriteException(override val message: String?) : Exception(message) { - constructor(sent: ByteArray, confirmed: ByteArray): this("Could not confirm write. Sent: {$sent} .Received: ${confirmed}") - constructor(status: Int): this("Could not confirm write. Write status: ${status}") + constructor(sent: ByteArray, confirmed: ByteArray) : this("Could not confirm write. Sent: {$sent} .Received: ${confirmed}") + constructor(status: Int) : this("Could not confirm write. Write status: ${status}") } \ No newline at end of file diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/DiscoveredInvalidPodException.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/DiscoveredInvalidPodException.kt index f7f6b08630..a4f7b52f75 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/DiscoveredInvalidPodException.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/DiscoveredInvalidPodException.kt @@ -2,7 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.excepti import android.os.ParcelUuid -class DiscoveredInvalidPodException: Exception { - constructor(message: String) : super(message) {} - constructor(message: String, serviceUUIds: List) : super("$message service UUIDs: $serviceUUIds"){} +class DiscoveredInvalidPodException : Exception { + constructor(message: String) : super(message) + constructor(message: String, serviceUUIds: List) : super("$message service UUIDs: $serviceUUIds") } \ No newline at end of file diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/FailedToConnectException.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/FailedToConnectException.kt index c720724ceb..8d6782aadb 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/FailedToConnectException.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/FailedToConnectException.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions open class FailedToConnectException : Exception { - constructor() : super() {} - constructor(message: String?) : super(message) {} + constructor() : super() + constructor(message: String?) : super(message) } \ No newline at end of file diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/ScanFailException.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/ScanFailException.kt index 6c6dcc2f49..ccaaf5a758 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/ScanFailException.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/ScanFailException.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions open class ScanFailException : Exception { - constructor() {} - constructor(errorCode: Int) : super("errorCode$errorCode") {} + constructor() + constructor(errorCode: Int) : super("errorCode$errorCode") } \ No newline at end of file diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/UnexpectedCommandException.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/UnexpectedCommandException.kt index dc7a0d7c27..149909032d 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/UnexpectedCommandException.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/exceptions/UnexpectedCommandException.kt @@ -1,7 +1,5 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.command.BleCommand -import java.lang.Exception -class UnexpectedCommandException(val cmd: BleCommand): Exception("Unexpected command: ${cmd}") { -} \ No newline at end of file +class UnexpectedCommandException(val cmd: BleCommand) : Exception("Unexpected command: ${cmd}") \ No newline at end of file diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/ltk/PairMessage.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/ltk/PairMessage.kt index 1879626479..1e170fc5f1 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/ltk/PairMessage.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/ltk/PairMessage.kt @@ -15,6 +15,6 @@ data class PairMessage( destination = destination, payload = payload, sequenceNumber = sequenceNumber, - sas = true, // TODO: understand why this is true for PairMessages + sas = true // TODO: understand why this is true for PairMessages ), ) \ No newline at end of file diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/Id.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/Id.kt index baa4964c23..ae8c732661 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/Id.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/message/Id.kt @@ -1,7 +1,5 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message -import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.ltk.LTKExchanger import info.nightscout.androidaps.utils.extensions.toHex import java.nio.ByteBuffer @@ -21,11 +19,12 @@ data class Id(val address: ByteArray) { } override fun toString(): String { - val asInt = ByteBuffer.wrap(address).getInt() + val asInt = ByteBuffer.wrap(address).int return "${asInt}/${address.toHex()}" } companion object { + private val PERIPHERAL_NODE_INDEX = 1 // TODO: understand the meaning of this value. It comes from preferences fun fromInt(v: Int): Id {