detekt
This commit is contained in:
parent
89bcd52994
commit
470b21aad4
6 changed files with 18 additions and 18 deletions
|
@ -61,7 +61,7 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
||||||
emitter.onNext(PodEvent.CommandSendNotConfirmed(cmd))
|
emitter.onNext(PodEvent.CommandSendNotConfirmed(cmd))
|
||||||
}
|
}
|
||||||
|
|
||||||
when (val readResult = session.readAndAckCommandResponse()) {
|
when (val readResult = session.readAndAckResponse()) {
|
||||||
is CommandReceiveSuccess ->
|
is CommandReceiveSuccess ->
|
||||||
emitter.onNext(PodEvent.ResponseReceived(readResult.result))
|
emitter.onNext(PodEvent.ResponseReceived(readResult.result))
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,8 @@ class BleCommCallbacks(
|
||||||
} else {
|
} else {
|
||||||
aapsLogger.warn(
|
aapsLogger.warn(
|
||||||
LTag.PUMPBTCOMM,
|
LTag.PUMPBTCOMM,
|
||||||
"Could not confirm write. Got " + received.payload.toHex() + ".Excepted: " + expectedPayload.toHex()
|
"Could not confirm write. Got " + received.payload.toHex() +
|
||||||
|
".Excepted: " + expectedPayload.toHex()
|
||||||
)
|
)
|
||||||
WriteConfirmationError("Received incorrect writeConfirmation")
|
WriteConfirmationError("Received incorrect writeConfirmation")
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,27 +153,27 @@ class MessageIO(
|
||||||
val peekCmd = cmdBleIO.peekCommand()
|
val peekCmd = cmdBleIO.peekCommand()
|
||||||
?: return MessageSendSuccess
|
?: return MessageSendSuccess
|
||||||
|
|
||||||
when (val receivedCmd = BleCommand.parse(peekCmd)) {
|
return 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())
|
MessageSendErrorSending(received.toString())
|
||||||
}
|
} else {
|
||||||
|
|
||||||
val sendResult = dataBleIO.sendAndConfirmPacket(packets[receivedCmd.idx.toInt()].toByteArray())
|
val sendResult = dataBleIO.sendAndConfirmPacket(packets[receivedCmd.idx.toInt()].toByteArray())
|
||||||
return handleSendResult(sendResult, index, packets)
|
handleSendResult(sendResult, index, packets)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BleCommandSuccess -> {
|
BleCommandSuccess -> {
|
||||||
if (index != packets.size) {
|
if (index != packets.size)
|
||||||
return MessageSendErrorSending("Received SUCCESS before sending all the data. $index")
|
MessageSendErrorSending("Received SUCCESS before sending all the data. $index")
|
||||||
}
|
else
|
||||||
return MessageSendSuccess
|
MessageSendSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
else ->
|
else ->
|
||||||
return MessageSendErrorSending("Received unexpected command: ${peekCmd.toHex()}")
|
MessageSendErrorSending("Received unexpected command: ${peekCmd.toHex()}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,6 @@ data class FirstBlePacket(
|
||||||
}
|
}
|
||||||
if (payload[0].toInt() != 0) {
|
if (payload[0].toInt() != 0) {
|
||||||
// most likely we lost the first packet.
|
// most likely we lost the first packet.
|
||||||
// TODO: try to recover with NACKs?
|
|
||||||
throw IncorrectPacketException(payload, 0)
|
throw IncorrectPacketException(payload, 0)
|
||||||
}
|
}
|
||||||
val fullFragments = payload[1].toInt()
|
val fullFragments = payload[1].toInt()
|
||||||
|
|
|
@ -62,7 +62,7 @@ class Session(
|
||||||
CommandSendErrorSending(errMsg)
|
CommandSendErrorSending(errMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun readAndAckCommandResponse(): CommandReceiveResult {
|
fun readAndAckResponse(): CommandReceiveResult {
|
||||||
var responseMsgPacket: MessagePacket? = null
|
var responseMsgPacket: MessagePacket? = null
|
||||||
for (i in 0..MAX_TRIES) {
|
for (i in 0..MAX_TRIES) {
|
||||||
val responseMsg = msgIO.receiveMessage()
|
val responseMsg = msgIO.receiveMessage()
|
||||||
|
@ -72,9 +72,9 @@ class Session(
|
||||||
}
|
}
|
||||||
responseMsgPacket = responseMsg.msg
|
responseMsgPacket = responseMsg.msg
|
||||||
}
|
}
|
||||||
if (responseMsgPacket == null) {
|
|
||||||
return CommandReceiveError("Could not read response")
|
responseMsgPacket
|
||||||
}
|
?: return CommandReceiveError("Could not read response")
|
||||||
|
|
||||||
val decrypted = enDecrypt.decrypt(responseMsgPacket)
|
val decrypted = enDecrypt.decrypt(responseMsgPacket)
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Received response: $decrypted")
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Received response: $decrypted")
|
||||||
|
|
|
@ -75,7 +75,7 @@ class SessionEstablisher(
|
||||||
|
|
||||||
val eapMsg = EapMessage(
|
val eapMsg = EapMessage(
|
||||||
code = EapCode.REQUEST,
|
code = EapCode.REQUEST,
|
||||||
identifier = identifier, // TODO: find what value we need here, it's probably random
|
identifier = identifier,
|
||||||
attributes = attributes
|
attributes = attributes
|
||||||
)
|
)
|
||||||
return MessagePacket(
|
return MessagePacket(
|
||||||
|
|
Loading…
Reference in a new issue