format: klintFormat
This commit is contained in:
parent
ada3560f49
commit
c9beb21404
8 changed files with 25 additions and 29 deletions
|
@ -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 SessionEstablishmentException(val msg: String) : Exception(msg)
|
class SessionEstablishmentException(val msg: String) : Exception(msg)
|
||||||
|
|
|
@ -29,7 +29,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
|
||||||
firstPacket.size < FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS ->
|
firstPacket.size < FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS ->
|
||||||
throw IncorrectPacketException(0, firstPacket)
|
throw IncorrectPacketException(0, firstPacket)
|
||||||
|
|
||||||
fullFragments == 0 -> {
|
fullFragments == 0 -> {
|
||||||
crc = ByteBuffer.wrap(firstPacket.copyOfRange(2, 6)).int.toUnsignedLong()
|
crc = ByteBuffer.wrap(firstPacket.copyOfRange(2, 6)).int.toUnsignedLong()
|
||||||
val rest = firstPacket[6]
|
val rest = firstPacket[6]
|
||||||
val end = min(rest + FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS, BlePacket.MAX_SIZE)
|
val end = min(rest + FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS, BlePacket.MAX_SIZE)
|
||||||
|
@ -41,10 +41,10 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// With middle packets
|
// With middle packets
|
||||||
firstPacket.size < BlePacket.MAX_SIZE ->
|
firstPacket.size < BlePacket.MAX_SIZE ->
|
||||||
throw IncorrectPacketException(0, firstPacket)
|
throw IncorrectPacketException(0, firstPacket)
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
fragments.add(
|
fragments.add(
|
||||||
firstPacket.copyOfRange(
|
firstPacket.copyOfRange(
|
||||||
FirstBlePacket.HEADER_SIZE_WITH_MIDDLE_PACKETS,
|
FirstBlePacket.HEADER_SIZE_WITH_MIDDLE_PACKETS,
|
||||||
|
@ -65,7 +65,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
|
||||||
}
|
}
|
||||||
expectedIndex++
|
expectedIndex++
|
||||||
when {
|
when {
|
||||||
idx < fullFragments -> { // this is a middle fragment
|
idx < fullFragments -> { // this is a middle fragment
|
||||||
if (packet.size < BlePacket.MAX_SIZE) {
|
if (packet.size < BlePacket.MAX_SIZE) {
|
||||||
throw IncorrectPacketException(idx.toByte(), packet)
|
throw IncorrectPacketException(idx.toByte(), packet)
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
|
||||||
fragments.add(packet.copyOfRange(LastBlePacket.HEADER_SIZE, packet.size))
|
fragments.add(packet.copyOfRange(LastBlePacket.HEADER_SIZE, packet.size))
|
||||||
}
|
}
|
||||||
|
|
||||||
idx > fullFragments -> { // this is the extra fragment
|
idx > fullFragments -> { // this is the extra fragment
|
||||||
val size = packet[1].toInt()
|
val size = packet[1].toInt()
|
||||||
if (packet.size < LastOptionalPlusOneBlePacket.HEADER_SIZE + size) {
|
if (packet.size < LastOptionalPlusOneBlePacket.HEADER_SIZE + size) {
|
||||||
throw IncorrectPacketException(idx.toByte(), packet)
|
throw IncorrectPacketException(idx.toByte(), packet)
|
||||||
|
|
|
@ -18,15 +18,15 @@ class StringLengthPrefixEncoding {
|
||||||
var remaining = payload
|
var remaining = payload
|
||||||
for ((index, key) in keys.withIndex()) {
|
for ((index, key) in keys.withIndex()) {
|
||||||
when {
|
when {
|
||||||
remaining.size < key.length ->
|
remaining.size < key.length ->
|
||||||
throw MessageIOException("Payload too short: ${payload.toHex()} for key: $key")
|
throw MessageIOException("Payload too short: ${payload.toHex()} for key: $key")
|
||||||
!(remaining.copyOfRange(0, key.length).decodeToString() == key) ->
|
!(remaining.copyOfRange(0, key.length).decodeToString() == key) ->
|
||||||
throw MessageIOException("Key not found: $key in ${payload.toHex()}")
|
throw MessageIOException("Key not found: $key in ${payload.toHex()}")
|
||||||
// last key can be empty, no length
|
// last key can be empty, no length
|
||||||
index == keys.size - 1 && remaining.size == key.length ->
|
index == keys.size - 1 && remaining.size == key.length ->
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
remaining.size < key.length + LENGTH_BYTES ->
|
remaining.size < key.length + LENGTH_BYTES ->
|
||||||
throw MessageIOException("Length not found: for $key in ${payload.toHex()}")
|
throw MessageIOException("Length not found: for $key in ${payload.toHex()}")
|
||||||
}
|
}
|
||||||
remaining = remaining.copyOfRange(key.length, remaining.size)
|
remaining = remaining.copyOfRange(key.length, remaining.size)
|
||||||
|
|
|
@ -21,7 +21,8 @@ class BleDiscoveredDevice(val scanResult: ScanResult, private val scanRecord: Sc
|
||||||
throw DiscoveredInvalidPodException(
|
throw DiscoveredInvalidPodException(
|
||||||
"The first exposed service UUID should be 4024, got " + extractUUID16(
|
"The first exposed service UUID should be 4024, got " + extractUUID16(
|
||||||
serviceUuids[0]
|
serviceUuids[0]
|
||||||
), serviceUuids
|
),
|
||||||
|
serviceUuids
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// TODO understand what is serviceUUIDs[1]. 0x2470. Alarms?
|
// TODO understand what is serviceUUIDs[1]. 0x2470. Alarms?
|
||||||
|
|
|
@ -44,7 +44,7 @@ sealed class EapAkaAttribute {
|
||||||
ret.add(EapAkaAttributeRes.parse(tail.copyOfRange(2, size)))
|
ret.add(EapAkaAttributeRes.parse(tail.copyOfRange(2, size)))
|
||||||
EapAkaAttributeType.AT_CUSTOM_IV ->
|
EapAkaAttributeType.AT_CUSTOM_IV ->
|
||||||
ret.add(EapAkaAttributeCustomIV.parse(tail.copyOfRange(2, size)))
|
ret.add(EapAkaAttributeCustomIV.parse(tail.copyOfRange(2, size)))
|
||||||
else ->
|
else ->
|
||||||
throw MessageIOException("Could not parse EAP attributes: ${payload.toHex()}. Expecting only AT_RES or CUSTOM_IV attribute types from the POD")
|
throw MessageIOException("Could not parse EAP attributes: ${payload.toHex()}. Expecting only AT_RES or CUSTOM_IV attribute types from the POD")
|
||||||
}
|
}
|
||||||
tail = tail.copyOfRange(size, tail.size)
|
tail = tail.copyOfRange(size, tail.size)
|
||||||
|
@ -94,7 +94,6 @@ data class EapAkaAttributeRes(val payload: ByteArray) : EapAkaAttribute() {
|
||||||
|
|
||||||
override fun toByteArray(): ByteArray {
|
override fun toByteArray(): ByteArray {
|
||||||
return byteArrayOf(EapAkaAttributeType.AT_RES.type, SIZE, 0, PAYLOAD_SIZE_BITS) + payload
|
return byteArrayOf(EapAkaAttributeType.AT_RES.type, SIZE, 0, PAYLOAD_SIZE_BITS) + payload
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -73,12 +73,11 @@ class EapAkaExchanger(private val aapsLogger: AAPSLogger, private val msgIO: Mes
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processChallengeResponse(challengeResponse: MessagePacket) {
|
private fun processChallengeResponse(challengeResponse: MessagePacket) {
|
||||||
//TODO verify that identifier matches identifer from the Challenge
|
// TODO verify that identifier matches identifer from the Challenge
|
||||||
val eapMsg = EapMessage.parse(aapsLogger, challengeResponse.payload)
|
val eapMsg = EapMessage.parse(aapsLogger, challengeResponse.payload)
|
||||||
if (eapMsg.attributes.size != 2) {
|
if (eapMsg.attributes.size != 2) {
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "EAP-AKA: got RES message: $eapMsg")
|
aapsLogger.debug(LTag.PUMPBTCOMM, "EAP-AKA: got RES message: $eapMsg")
|
||||||
throw SessionEstablishmentException("Expecting two attributes, got: ${eapMsg.attributes.size}")
|
throw SessionEstablishmentException("Expecting two attributes, got: ${eapMsg.attributes.size}")
|
||||||
|
|
||||||
}
|
}
|
||||||
for (attr in eapMsg.attributes) {
|
for (attr in eapMsg.attributes) {
|
||||||
when (attr) {
|
when (attr) {
|
||||||
|
@ -88,11 +87,10 @@ class EapAkaExchanger(private val aapsLogger: AAPSLogger, private val msgIO: Mes
|
||||||
}
|
}
|
||||||
is EapAkaAttributeCustomIV ->
|
is EapAkaAttributeCustomIV ->
|
||||||
nodeIV = attr.payload.copyOfRange(0, IV_SIZE)
|
nodeIV = attr.payload.copyOfRange(0, IV_SIZE)
|
||||||
else ->
|
else ->
|
||||||
throw SessionEstablishmentException("Unknown attribute received: ${attr}")
|
throw SessionEstablishmentException("Unknown attribute received: $attr")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun eapSuccess(): MessagePacket {
|
private fun eapSuccess(): MessagePacket {
|
||||||
|
@ -119,4 +117,3 @@ class EapAkaExchanger(private val aapsLogger: AAPSLogger, private val msgIO: Mes
|
||||||
private const val IV_SIZE = 4
|
private const val IV_SIZE = 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -471,17 +471,17 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
private fun updateRefreshStatusButton() {
|
private fun updateRefreshStatusButton() {
|
||||||
buttonBinding.buttonRefreshStatus.isEnabled =
|
buttonBinding.buttonRefreshStatus.isEnabled =
|
||||||
podStateManager.isUniqueIdSet && podStateManager.activationProgress.isAtLeast(
|
podStateManager.isUniqueIdSet && podStateManager.activationProgress.isAtLeast(
|
||||||
ActivationProgress.PHASE_1_COMPLETED
|
ActivationProgress.PHASE_1_COMPLETED
|
||||||
) &&
|
) &&
|
||||||
isQueueEmpty()
|
isQueueEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateResumeDeliveryButton() {
|
private fun updateResumeDeliveryButton() {
|
||||||
if (podStateManager.isPodRunning && (
|
if (podStateManager.isPodRunning && (
|
||||||
podStateManager.isSuspended || commandQueue.isCustomCommandInQueue(
|
podStateManager.isSuspended || commandQueue.isCustomCommandInQueue(
|
||||||
CommandResumeDelivery::class.java
|
CommandResumeDelivery::class.java
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
buttonBinding.buttonResumeDelivery.visibility = View.VISIBLE
|
buttonBinding.buttonResumeDelivery.visibility = View.VISIBLE
|
||||||
buttonBinding.buttonResumeDelivery.isEnabled = isQueueEmpty()
|
buttonBinding.buttonResumeDelivery.isEnabled = isQueueEmpty()
|
||||||
|
@ -492,10 +492,10 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
|
|
||||||
private fun updateSilenceAlertsButton() {
|
private fun updateSilenceAlertsButton() {
|
||||||
if (isAutomaticallySilenceAlertsEnabled() && podStateManager.isPodRunning && (
|
if (isAutomaticallySilenceAlertsEnabled() && podStateManager.isPodRunning && (
|
||||||
podStateManager.activeAlerts!!.size > 0 || commandQueue.isCustomCommandInQueue(
|
podStateManager.activeAlerts!!.size > 0 || commandQueue.isCustomCommandInQueue(
|
||||||
CommandAcknowledgeAlerts::class.java
|
CommandAcknowledgeAlerts::class.java
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
buttonBinding.buttonSilenceAlerts.visibility = View.VISIBLE
|
buttonBinding.buttonSilenceAlerts.visibility = View.VISIBLE
|
||||||
buttonBinding.buttonSilenceAlerts.isEnabled = isQueueEmpty()
|
buttonBinding.buttonSilenceAlerts.isEnabled = isQueueEmpty()
|
||||||
|
@ -507,10 +507,10 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
private fun updateSuspendDeliveryButton() {
|
private fun updateSuspendDeliveryButton() {
|
||||||
// If the Pod is currently suspended, we show the Resume delivery button instead.
|
// If the Pod is currently suspended, we show the Resume delivery button instead.
|
||||||
if (isSuspendDeliveryButtonEnabled() && podStateManager.isPodRunning && (
|
if (isSuspendDeliveryButtonEnabled() && podStateManager.isPodRunning && (
|
||||||
!podStateManager.isSuspended || commandQueue.isCustomCommandInQueue(
|
!podStateManager.isSuspended || commandQueue.isCustomCommandInQueue(
|
||||||
CommandSuspendDelivery::class.java
|
CommandSuspendDelivery::class.java
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
buttonBinding.buttonSuspendDelivery.visibility = View.VISIBLE
|
buttonBinding.buttonSuspendDelivery.visibility = View.VISIBLE
|
||||||
buttonBinding.buttonSuspendDelivery.isEnabled =
|
buttonBinding.buttonSuspendDelivery.isEnabled =
|
||||||
|
|
|
@ -47,5 +47,4 @@ class MilenageTest {
|
||||||
Assert.assertEquals(m.ck.toHex(), "8dd4b3ceb849a01766e37f9d86045c39")
|
Assert.assertEquals(m.ck.toHex(), "8dd4b3ceb849a01766e37f9d86045c39")
|
||||||
Assert.assertEquals(m.autn.toHex(), "0e0264d056fcb9b9752227365a090955")
|
Assert.assertEquals(m.autn.toHex(), "0e0264d056fcb9b9752227365a090955")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue