ble: reformat(Ctrl+Alt+L)

This commit is contained in:
Andrei Vereha 2021-02-26 18:30:59 +01:00
parent 9170cc6f76
commit 358748654e
13 changed files with 29 additions and 34 deletions

View file

@ -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 bluetoothManager: BluetoothManager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
private val bluetoothAdapter: BluetoothAdapter = bluetoothManager.adapter 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) @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 { private fun connect(podAddress: String): BleIO {
// TODO: locking? // TODO: locking?

View file

@ -7,10 +7,10 @@ import android.bluetooth.BluetoothGattDescriptor
import android.bluetooth.BluetoothProfile import android.bluetooth.BluetoothProfile
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag 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.CouldNotConfirmDescriptorWriteException
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.CouldNotConfirmWriteException 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 info.nightscout.androidaps.utils.extensions.toHex
import java.util.concurrent.BlockingQueue import java.util.concurrent.BlockingQueue
import java.util.concurrent.CountDownLatch import java.util.concurrent.CountDownLatch
@ -141,6 +141,7 @@ class BleCommCallbacks(private val aapsLogger: AAPSLogger, private val incomingP
} }
companion object { companion object {
private const val WRITE_CONFIRM_TIMEOUT_MS = 10 // the confirmation queue should be empty anyway private const val WRITE_CONFIRM_TIMEOUT_MS = 10 // the confirmation queue should be empty anyway
} }
} }

View file

@ -2,11 +2,11 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.command
open class BleCommand(val data: ByteArray) { 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 byteArrayOf(type.value) + payload
) {} )
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true 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)

View file

@ -1,5 +1,3 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.command 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))

View file

@ -3,6 +3,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.excepti
import android.os.ParcelUuid import android.os.ParcelUuid
class DiscoveredInvalidPodException : Exception { class DiscoveredInvalidPodException : Exception {
constructor(message: String) : super(message) {} constructor(message: String) : super(message)
constructor(message: String, serviceUUIds: List<ParcelUuid?>) : super("$message service UUIDs: $serviceUUIds"){} constructor(message: String, serviceUUIds: List<ParcelUuid?>) : super("$message service UUIDs: $serviceUUIds")
} }

View file

@ -1,6 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
open class FailedToConnectException : Exception { open class FailedToConnectException : Exception {
constructor() : super() {} constructor() : super()
constructor(message: String?) : super(message) {} constructor(message: String?) : super(message)
} }

View file

@ -1,6 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
open class ScanFailException : Exception { open class ScanFailException : Exception {
constructor() {} constructor()
constructor(errorCode: Int) : super("errorCode$errorCode") {} constructor(errorCode: Int) : super("errorCode$errorCode")
} }

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.command.BleCommand 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}") { class UnexpectedCommandException(val cmd: BleCommand) : Exception("Unexpected command: ${cmd}")
}

View file

@ -15,6 +15,6 @@ data class PairMessage(
destination = destination, destination = destination,
payload = payload, payload = payload,
sequenceNumber = sequenceNumber, sequenceNumber = sequenceNumber,
sas = true, // TODO: understand why this is true for PairMessages sas = true // TODO: understand why this is true for PairMessages
), ),
) )

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message 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 info.nightscout.androidaps.utils.extensions.toHex
import java.nio.ByteBuffer import java.nio.ByteBuffer
@ -21,11 +19,12 @@ data class Id(val address: ByteArray) {
} }
override fun toString(): String { override fun toString(): String {
val asInt = ByteBuffer.wrap(address).getInt() val asInt = ByteBuffer.wrap(address).int
return "${asInt}/${address.toHex()}" return "${asInt}/${address.toHex()}"
} }
companion object { companion object {
private val PERIPHERAL_NODE_INDEX = 1 // TODO: understand the meaning of this value. It comes from preferences private val PERIPHERAL_NODE_INDEX = 1 // TODO: understand the meaning of this value. It comes from preferences
fun fromInt(v: Int): Id { fun fromInt(v: Int): Id {