Remove redundant qualifiers

This commit is contained in:
Bart Sopers 2021-02-26 10:26:30 +01:00
parent 04cd03f99f
commit 29617b5d8c
11 changed files with 19 additions and 19 deletions

View file

@ -7,7 +7,7 @@ enum class BleCommandType(val value: Byte) {
@JvmStatic
fun byValue(value: Byte): BleCommandType =
BleCommandType.values().firstOrNull { it.value == value }
values().firstOrNull { it.value == value }
?: throw IllegalArgumentException("Unknown BleCommandType: $value")
}
}

View file

@ -13,8 +13,8 @@ class GetVersionCommand internal constructor(uniqueId: Int, sequenceNumber: Shor
//
//
override val encoded: ByteArray
get() = HeaderEnabledCommand.Companion.appendCrc(ByteBuffer.allocate(LENGTH + HeaderEnabledCommand.Companion.HEADER_LENGTH) //
.put(HeaderEnabledCommand.Companion.encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
get() = appendCrc(ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
.put(commandType.value) //
.put(BODY_LENGTH) //
.putInt(uniqueId) //

View file

@ -47,8 +47,8 @@ class ProgramBasalCommand internal constructor(private val interlockCommand: Pro
}
val basalCommand = buffer.array()
val interlockCommand = interlockCommand.encoded
val header: ByteArray = HeaderEnabledCommand.Companion.encodeHeader(uniqueId, sequenceNumber, (basalCommand.size + interlockCommand!!.size).toShort(), multiCommandFlag)
return HeaderEnabledCommand.appendCrc(ByteBuffer.allocate(basalCommand.size + interlockCommand.size + header.size) //
val header: ByteArray = encodeHeader(uniqueId, sequenceNumber, (basalCommand.size + interlockCommand!!.size).toShort(), multiCommandFlag)
return appendCrc(ByteBuffer.allocate(basalCommand.size + interlockCommand.size + header.size) //
.put(header) //
.put(interlockCommand) //
.put(basalCommand) //

View file

@ -35,8 +35,8 @@ class ProgramBolusCommand internal constructor(private val interlockCommand: Pro
.putInt(0) // Delay between tenth extended pulses in usec
.array()
val interlockCommand = interlockCommand.encoded
val header: ByteArray = HeaderEnabledCommand.Companion.encodeHeader(uniqueId, sequenceNumber, (bolusCommand.size + interlockCommand!!.size).toShort(), multiCommandFlag)
return HeaderEnabledCommand.Companion.appendCrc(ByteBuffer.allocate(header.size + interlockCommand.size + bolusCommand.size) //
val header: ByteArray = encodeHeader(uniqueId, sequenceNumber, (bolusCommand.size + interlockCommand!!.size).toShort(), multiCommandFlag)
return appendCrc(ByteBuffer.allocate(header.size + interlockCommand.size + bolusCommand.size) //
.put(header) //
.put(interlockCommand) //
.put(bolusCommand) //

View file

@ -84,8 +84,8 @@ class ProgramTempBasalCommand protected constructor(private val interlockCommand
}
val tempBasalCommand = buffer.array()
val interlockCommand = interlockCommand.encoded
val header: ByteArray = HeaderEnabledCommand.Companion.encodeHeader(uniqueId, sequenceNumber, (tempBasalCommand.size + interlockCommand!!.size).toShort(), multiCommandFlag)
return HeaderEnabledCommand.Companion.appendCrc(ByteBuffer.allocate(header.size + interlockCommand.size + tempBasalCommand.size) //
val header: ByteArray = encodeHeader(uniqueId, sequenceNumber, (tempBasalCommand.size + interlockCommand!!.size).toShort(), multiCommandFlag)
return appendCrc(ByteBuffer.allocate(header.size + interlockCommand.size + tempBasalCommand.size) //
.put(header) //
.put(interlockCommand) //
.put(tempBasalCommand) //

View file

@ -19,8 +19,8 @@ class SetUniqueIdCommand internal constructor(uniqueId: Int, sequenceNumber: Sho
//
//
override val encoded: ByteArray
get() = HeaderEnabledCommand.Companion.appendCrc(ByteBuffer.allocate(LENGTH + HeaderEnabledCommand.Companion.HEADER_LENGTH) //
.put(HeaderEnabledCommand.Companion.encodeHeader(DEFAULT_UNIQUE_ID, sequenceNumber, LENGTH, multiCommandFlag)) //
get() = appendCrc(ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
.put(encodeHeader(DEFAULT_UNIQUE_ID, sequenceNumber, LENGTH, multiCommandFlag)) //
.put(commandType.value) //
.put(BODY_LENGTH) //
.putInt(uniqueId) //

View file

@ -12,8 +12,8 @@ class SilenceAlertsCommand internal constructor(uniqueId: Int, sequenceNumber: S
override val encoded: ByteArray
get() =
HeaderEnabledCommand.Companion.appendCrc(ByteBuffer.allocate(LENGTH + HeaderEnabledCommand.Companion.HEADER_LENGTH) //
.put(HeaderEnabledCommand.Companion.encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
appendCrc(ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
.put(commandType.value) //
.put(BODY_LENGTH) //
.putInt(nonce) //

View file

@ -13,8 +13,8 @@ class StopDeliveryCommand internal constructor(uniqueId: Int, sequenceNumber: Sh
override val encoded: ByteArray
get() {
return HeaderEnabledCommand.Companion.appendCrc(ByteBuffer.allocate(LENGTH + HeaderEnabledCommand.Companion.HEADER_LENGTH) //
.put(HeaderEnabledCommand.Companion.encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
return appendCrc(ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
.put(commandType.value) //
.put(BODY_LENGTH) //
.putInt(nonce) //

View file

@ -204,11 +204,11 @@ class AlarmStatusResponse(encoded: ByteArray) : AdditionalStatusResponseBase(Add
messageLength = (encoded[1].toInt() and 0xff).toShort()
additionalStatusResponseType = encoded[2]
podStatus = PodStatus.byValue((encoded[3] and 0x0f))
deliveryStatus = DeliveryStatus.Companion.byValue((encoded[4] and 0x0f))
deliveryStatus = DeliveryStatus.byValue((encoded[4] and 0x0f))
bolusPulsesRemaining = (ByteBuffer.wrap(byteArrayOf(encoded[5], encoded[6])).short and 2047)
sequenceNumberOfLastProgrammingCommand = (encoded[7] and 0x0f).toShort()
totalPulsesDelivered = ByteBuffer.wrap(byteArrayOf(encoded[8], encoded[9])).short
alarmType = AlarmType.Companion.byValue(encoded[10])
alarmType = AlarmType.byValue(encoded[10])
alarmTime = ByteBuffer.wrap(byteArrayOf(encoded[11], encoded[12])).short
reservoirPulsesRemaining = ByteBuffer.wrap(byteArrayOf(encoded[13], encoded[14])).short
minutesSinceActivation = ByteBuffer.wrap(byteArrayOf(encoded[15], encoded[16])).short

View file

@ -9,7 +9,7 @@ class DefaultStatusResponse(encoded: ByteArray) : ResponseBase(ResponseType.DEFA
// TODO: Here is a lot of bitshifting that had to be changed. we should go over it.
private val messageType: Byte = encoded[0]
private val deliveryStatus: DeliveryStatus = DeliveryStatus.byValue((encoded[1].toInt() shr 4 and 0x0f).toByte())
private val podStatus: PodStatus = PodStatus.Companion.byValue((encoded[1] and 0x0f) as Byte)
private val podStatus: PodStatus = PodStatus.byValue((encoded[1] and 0x0f) as Byte)
private val totalPulsesDelivered: Short = ((encoded[2] and 0x0f shl 12 or (encoded[3].toInt() and 0xff shl 1) or (encoded[4].toInt() and 0xff ushr 7)).toShort())
private val sequenceNumberOfLastProgrammingCommand: Short = (encoded[4] ushr 3 and 0x0f).toShort()
private val bolusPulsesRemaining: Short = ((encoded[4] and 0x07 shl 10 or (encoded[5].toInt() and 0xff) and 2047).toShort())

View file

@ -53,7 +53,7 @@ class NakResponse(encoded: ByteArray) : ResponseBase(ResponseType.NAK_RESPONSE,
init {
messageType = encoded[0]
messageLength = encoded[1].toShort()
nakErrorType = NakErrorType.Companion.byValue(encoded[2])
nakErrorType = NakErrorType.byValue(encoded[2])
val byte3 = encoded[3]
val byte4 = encoded[4]
if (nakErrorType == NakErrorType.ILLEGAL_SECURITY_CODE) {