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 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?

View file

@ -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
}
}

View file

@ -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()
data class DescriptorWriteConfirmationError(val status: Int) : DescriptorWriteConfirmation()

View file

@ -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)

View file

@ -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))

View file

@ -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}")
}

View file

@ -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}")
}

View file

@ -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<ParcelUuid?>) : super("$message service UUIDs: $serviceUUIds"){}
class DiscoveredInvalidPodException : Exception {
constructor(message: String) : super(message)
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
open class FailedToConnectException : Exception {
constructor() : super() {}
constructor(message: String?) : super(message) {}
constructor() : super()
constructor(message: String?) : super(message)
}

View file

@ -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")
}

View file

@ -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}") {
}
class UnexpectedCommandException(val cmd: BleCommand) : Exception("Unexpected command: ${cmd}")

View file

@ -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
),
)

View file

@ -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 {