detekt
This commit is contained in:
parent
5209386fc1
commit
89bcd52994
|
@ -60,7 +60,7 @@ class BleCommCallbacks(
|
|||
fun confirmWrite(expectedPayload: ByteArray, expectedUUID: String, timeoutMs: Long): WriteConfirmation {
|
||||
try {
|
||||
return when (val received = writeQueue.poll(timeoutMs, TimeUnit.MILLISECONDS)) {
|
||||
null -> return WriteConfirmationError("Timeout waiting for writeConfirmation")
|
||||
null -> WriteConfirmationError("Timeout waiting for writeConfirmation")
|
||||
is WriteConfirmationSuccess ->
|
||||
if (expectedPayload.contentEquals(received.payload) &&
|
||||
expectedUUID == received.uuid
|
||||
|
|
|
@ -71,8 +71,8 @@ sealed class BleCommand(val data: ByteArray) {
|
|||
return BleCommandIncorrect("Incorrect command: empty payload", payload)
|
||||
}
|
||||
|
||||
try {
|
||||
return when (BleCommandType.byValue(payload[0])) {
|
||||
return try {
|
||||
when (BleCommandType.byValue(payload[0])) {
|
||||
BleCommandType.RTS ->
|
||||
BleCommandRTS
|
||||
BleCommandType.CTS ->
|
||||
|
@ -91,7 +91,7 @@ sealed class BleCommand(val data: ByteArray) {
|
|||
BleCommandIncorrect("Incorrect command received", payload)
|
||||
}
|
||||
} catch (e: IllegalArgumentException) {
|
||||
return BleCommandIncorrect("Incorrect command payload", payload)
|
||||
BleCommandIncorrect("Incorrect command payload", payload)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ object BleSendSuccess : BleSendResult()
|
|||
data class BleSendErrorSending(val msg: String, val cause: Throwable? = null) : BleSendResult()
|
||||
data class BleSendErrorConfirming(val msg: String, val cause: Throwable? = null) : BleSendResult()
|
||||
|
||||
abstract class BleIO(
|
||||
open class BleIO(
|
||||
private val aapsLogger: AAPSLogger,
|
||||
private val characteristic: BluetoothGattCharacteristic,
|
||||
private val incomingPackets: BlockingQueue<ByteArray>,
|
||||
|
@ -40,12 +40,12 @@ abstract class BleIO(
|
|||
* @return a byte array with the received data or error
|
||||
*/
|
||||
fun receivePacket(timeoutMs: Long = DEFAULT_IO_TIMEOUT_MS): BleReceiveResult {
|
||||
try {
|
||||
val ret = incomingPackets.poll(timeoutMs, TimeUnit.MILLISECONDS)
|
||||
?: return BleReceiveError("Timeout")
|
||||
return BleReceivePayload(ret)
|
||||
return try {
|
||||
val packet = incomingPackets.poll(timeoutMs, TimeUnit.MILLISECONDS)
|
||||
if (packet == null) BleReceiveError("Timeout")
|
||||
else BleReceivePayload(packet)
|
||||
} catch (e: InterruptedException) {
|
||||
return BleReceiveError("Interrupted", cause = e)
|
||||
BleReceiveError("Interrupted", cause = e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -143,9 +143,9 @@ class MessageIO(
|
|||
sendResult is BleSendSuccess ->
|
||||
MessageSendSuccess
|
||||
index == packets.size - 1 && sendResult is BleSendErrorConfirming ->
|
||||
return MessageSendErrorConfirming("Error confirming last DATA packet $sendResult")
|
||||
MessageSendErrorConfirming("Error confirming last DATA packet $sendResult")
|
||||
else ->
|
||||
return MessageSendErrorSending("Error sending DATA: $sendResult")
|
||||
MessageSendErrorSending("Error sending DATA: $sendResult")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class StringLengthPrefixEncoding private constructor() {
|
|||
private const val LENGTH_BYTES = 2
|
||||
|
||||
fun parseKeys(keys: Array<String>, payload: ByteArray): Array<ByteArray> {
|
||||
val ret = Array(keys.size, { ByteArray(0) })
|
||||
val ret = Array(keys.size) { ByteArray(0) }
|
||||
var remaining = payload
|
||||
for ((index, key) in keys.withIndex()) {
|
||||
when {
|
||||
|
|
|
@ -31,7 +31,10 @@ internal class PayloadSplitter(private val payload: ByteArray) {
|
|||
}
|
||||
val middleFragments = (payload.size - FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS) / MiddleBlePacket.CAPACITY
|
||||
val rest =
|
||||
((payload.size - middleFragments * MiddleBlePacket.CAPACITY) - FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS).toByte()
|
||||
(
|
||||
(payload.size - middleFragments * MiddleBlePacket.CAPACITY) -
|
||||
FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS
|
||||
).toByte()
|
||||
ret.add(
|
||||
FirstBlePacket(
|
||||
fullFragments = middleFragments + 1,
|
||||
|
@ -75,7 +78,9 @@ internal class PayloadSplitter(private val payload: ByteArray) {
|
|||
index = (middleFragments + 2).toByte(),
|
||||
size = (rest - LastBlePacket.CAPACITY).toByte(),
|
||||
payload = payload.copyOfRange(
|
||||
middleFragments * MiddleBlePacket.CAPACITY + FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS + LastBlePacket.CAPACITY,
|
||||
middleFragments * MiddleBlePacket.CAPACITY +
|
||||
FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS +
|
||||
LastBlePacket.CAPACITY,
|
||||
payload.size
|
||||
)
|
||||
)
|
||||
|
|
|
@ -65,7 +65,6 @@ internal class LTKExchanger(
|
|||
}
|
||||
|
||||
// No exception throwing after this point. It is possible that the pod saved the LTK
|
||||
//
|
||||
val p0 = msgIO.receiveMessage()
|
||||
if (p0 is MessageReceiveSuccess) {
|
||||
validateP0(p0.msg)
|
||||
|
|
|
@ -3,6 +3,5 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.scan
|
|||
import android.os.ParcelUuid
|
||||
|
||||
class DiscoveredInvalidPodException : Exception {
|
||||
constructor(message: String) : super(message)
|
||||
constructor(message: String, serviceUUIds: List<ParcelUuid?>) : super("$message service UUIDs: $serviceUUIds")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue