ktLintFormat
This commit is contained in:
parent
b630c4d21a
commit
6c9aa90679
15 changed files with 39 additions and 28 deletions
|
@ -166,10 +166,14 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
||||||
|
|
||||||
emitter.onNext(PodEvent.Pairing)
|
emitter.onNext(PodEvent.Pairing)
|
||||||
val ltkExchanger = LTKExchanger(
|
val ltkExchanger = LTKExchanger(
|
||||||
aapsLogger, conn.msgIO, myId, podId, Id.fromLong(
|
aapsLogger,
|
||||||
PodScanner
|
conn.msgIO,
|
||||||
.POD_ID_NOT_ACTIVATED
|
myId,
|
||||||
)
|
podId,
|
||||||
|
Id.fromLong(
|
||||||
|
PodScanner
|
||||||
|
.POD_ID_NOT_ACTIVATED
|
||||||
|
)
|
||||||
)
|
)
|
||||||
val pairResult = ltkExchanger.negotiateLTK()
|
val pairResult = ltkExchanger.negotiateLTK()
|
||||||
emitter.onNext(PodEvent.Paired(podId))
|
emitter.onNext(PodEvent.Paired(podId))
|
||||||
|
|
|
@ -63,7 +63,8 @@ class BleCommCallbacks(
|
||||||
null -> return WriteConfirmationError("Timeout waiting for writeConfirmation")
|
null -> return WriteConfirmationError("Timeout waiting for writeConfirmation")
|
||||||
is WriteConfirmationSuccess ->
|
is WriteConfirmationSuccess ->
|
||||||
if (expectedPayload.contentEquals(received.payload) &&
|
if (expectedPayload.contentEquals(received.payload) &&
|
||||||
expectedUUID == received.uuid) {
|
expectedUUID == received.uuid
|
||||||
|
) {
|
||||||
received
|
received
|
||||||
} else {
|
} else {
|
||||||
aapsLogger.warn(
|
aapsLogger.warn(
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
||||||
|
|
||||||
class BusyException : Exception("Bluetooth busy")
|
class BusyException : Exception("Bluetooth busy")
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
||||||
|
|
||||||
class CouldNotSendCommandException(val msg: String = "Could not send command") : Exception(msg)
|
class CouldNotSendCommandException(val msg: String = "Could not send command") : Exception(msg)
|
||||||
|
|
|
@ -3,4 +3,3 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.excepti
|
||||||
open class FailedToConnectException : Exception {
|
open class FailedToConnectException : Exception {
|
||||||
constructor(message: String? = null) : super("Failed to connect: ${message ?: ""}")
|
constructor(message: String? = null) : super("Failed to connect: ${message ?: ""}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
||||||
|
|
||||||
class NotConnectedException(val msg: String) : Exception(msg)
|
class NotConnectedException(val msg: String) : Exception(msg)
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
||||||
|
|
||||||
class PairingException(val msg: String) : Exception(msg)
|
class PairingException(val msg: String) : Exception(msg)
|
||||||
|
|
|
@ -66,10 +66,13 @@ abstract class BleIO(
|
||||||
return BleSendErrorSending("Could not writeCharacteristic on {$type.name}")
|
return BleSendErrorSending("Could not writeCharacteristic on {$type.name}")
|
||||||
}
|
}
|
||||||
|
|
||||||
return when (val confirmation = bleCommCallbacks.confirmWrite(
|
return when (
|
||||||
payload, type.value,
|
val confirmation = bleCommCallbacks.confirmWrite(
|
||||||
DEFAULT_IO_TIMEOUT_MS
|
payload,
|
||||||
)) {
|
type.value,
|
||||||
|
DEFAULT_IO_TIMEOUT_MS
|
||||||
|
)
|
||||||
|
) {
|
||||||
is WriteConfirmationError ->
|
is WriteConfirmationError ->
|
||||||
BleSendErrorConfirming(confirmation.msg)
|
BleSendErrorConfirming(confirmation.msg)
|
||||||
is WriteConfirmationSuccess ->
|
is WriteConfirmationSuccess ->
|
||||||
|
@ -127,5 +130,3 @@ abstract class BleIO(
|
||||||
const val DEFAULT_IO_TIMEOUT_MS = 1000.toLong()
|
const val DEFAULT_IO_TIMEOUT_MS = 1000.toLong()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -51,4 +51,3 @@ class CmdBleIO(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,4 +14,4 @@ class IncomingPackets {
|
||||||
CharacteristicType.CMD -> dataQueue
|
CharacteristicType.CMD -> dataQueue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ class MessageIO(
|
||||||
|
|
||||||
when (val receivedCmd = BleCommand.parse(peekCmd)) {
|
when (val receivedCmd = BleCommand.parse(peekCmd)) {
|
||||||
is BleCommandNack -> {
|
is BleCommandNack -> {
|
||||||
//// Consume NACK
|
// // Consume NACK
|
||||||
val received = cmdBleIO.receivePacket()
|
val received = cmdBleIO.receivePacket()
|
||||||
if (received !is BleReceivePayload) {
|
if (received !is BleReceivePayload) {
|
||||||
return MessageSendErrorSending(received.toString())
|
return MessageSendErrorSending(received.toString())
|
||||||
|
|
|
@ -55,7 +55,7 @@ data class FirstBlePacket(
|
||||||
throw IncorrectPacketException(payload, 0)
|
throw IncorrectPacketException(payload, 0)
|
||||||
}
|
}
|
||||||
val fullFragments = payload[1].toInt()
|
val fullFragments = payload[1].toInt()
|
||||||
require(fullFragments < MAX_FRAGMENTS) { "Received more than ${MAX_FRAGMENTS} fragments" }
|
require(fullFragments < MAX_FRAGMENTS) { "Received more than $MAX_FRAGMENTS fragments" }
|
||||||
when {
|
when {
|
||||||
// Without middle packets
|
// Without middle packets
|
||||||
payload.size < HEADER_SIZE_WITHOUT_MIDDLE_PACKETS ->
|
payload.size < HEADER_SIZE_WITHOUT_MIDDLE_PACKETS ->
|
||||||
|
@ -196,7 +196,6 @@ data class LastOptionalPlusOneBlePacket(
|
||||||
),
|
),
|
||||||
size = size.toByte(),
|
size = size.toByte(),
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val HEADER_SIZE = 2
|
private const val HEADER_SIZE = 2
|
||||||
|
|
|
@ -48,7 +48,7 @@ internal class LTKExchanger(
|
||||||
val sps2 = sps2()
|
val sps2 = sps2()
|
||||||
val sp2Result = msgIO.sendMessage(sps2.messagePacket)
|
val sp2Result = msgIO.sendMessage(sps2.messagePacket)
|
||||||
if (sp1Result !is MessageSendSuccess) {
|
if (sp1Result !is MessageSendSuccess) {
|
||||||
throw PairingException("Could not send sps2: ${sp2Result}")
|
throw PairingException("Could not send sps2: $sp2Result")
|
||||||
}
|
}
|
||||||
|
|
||||||
val podSps2 = msgIO.receiveMessage()
|
val podSps2 = msgIO.receiveMessage()
|
||||||
|
|
|
@ -49,12 +49,20 @@ class Connection(val podDevice: BluetoothDevice, private val aapsLogger: AAPSLog
|
||||||
private val discoverer = ServiceDiscoverer(aapsLogger, gattConnection, bleCommCallbacks)
|
private val discoverer = ServiceDiscoverer(aapsLogger, gattConnection, bleCommCallbacks)
|
||||||
private val discoveredCharacteristics = discoverer.discoverServices()
|
private val discoveredCharacteristics = discoverer.discoverServices()
|
||||||
private val cmdBleIO = CmdBleIO(
|
private val cmdBleIO = CmdBleIO(
|
||||||
aapsLogger, discoveredCharacteristics[CharacteristicType.CMD]!!, incomingPackets
|
aapsLogger,
|
||||||
.cmdQueue, gattConnection, bleCommCallbacks
|
discoveredCharacteristics[CharacteristicType.CMD]!!,
|
||||||
|
incomingPackets
|
||||||
|
.cmdQueue,
|
||||||
|
gattConnection,
|
||||||
|
bleCommCallbacks
|
||||||
)
|
)
|
||||||
private val dataBleIO = DataBleIO(
|
private val dataBleIO = DataBleIO(
|
||||||
aapsLogger, discoveredCharacteristics[CharacteristicType.DATA]!!, incomingPackets
|
aapsLogger,
|
||||||
.dataQueue, gattConnection, bleCommCallbacks
|
discoveredCharacteristics[CharacteristicType.DATA]!!,
|
||||||
|
incomingPackets
|
||||||
|
.dataQueue,
|
||||||
|
gattConnection,
|
||||||
|
bleCommCallbacks
|
||||||
)
|
)
|
||||||
val msgIO = MessageIO(aapsLogger, cmdBleIO, dataBleIO)
|
val msgIO = MessageIO(aapsLogger, cmdBleIO, dataBleIO)
|
||||||
var session: Session? = null
|
var session: Session? = null
|
||||||
|
@ -123,4 +131,4 @@ class Connection(val podDevice: BluetoothDevice, private val aapsLogger: AAPSLog
|
||||||
|
|
||||||
private const val CONNECT_TIMEOUT_MS = 7000
|
private const val CONNECT_TIMEOUT_MS = 7000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ class SessionEstablisher(
|
||||||
if (eapMsg.attributes.size == 1 && eapMsg.attributes[0] is EapAkaAttributeClientErrorCode) {
|
if (eapMsg.attributes.size == 1 && eapMsg.attributes[0] is EapAkaAttributeClientErrorCode) {
|
||||||
throw SessionEstablishmentException(
|
throw SessionEstablishmentException(
|
||||||
"Received CLIENT_ERROR_CODE for EAP-AKA challenge: ${
|
"Received CLIENT_ERROR_CODE for EAP-AKA challenge: ${
|
||||||
eapMsg.attributes[0].toByteArray().toHex()
|
eapMsg.attributes[0].toByteArray().toHex()
|
||||||
}"
|
}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue