replace deprecated calls

This commit is contained in:
Milos Kozak 2020-03-29 21:21:01 +02:00
parent df03a8a2c0
commit 0fa6273725
13 changed files with 163 additions and 127 deletions

View file

@ -25,8 +25,8 @@ open class MsgHistoryAll(
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
val dailyBasal = intFromBuff(bytes, 4, 2) * 0.01 val dailyBasal = intFromBuff(bytes, 4, 2) * 0.01
val dailyBolus = intFromBuff(bytes, 6, 2) * 0.01 val dailyBolus = intFromBuff(bytes, 6, 2) * 0.01
val paramByte5 = intFromBuff(bytes, 4, 1).toByte() //val paramByte5 = intFromBuff(bytes, 4, 1).toByte()
val paramByte6 = intFromBuff(bytes, 5, 1).toByte() //val paramByte6 = intFromBuff(bytes, 5, 1).toByte()
val paramByte7 = intFromBuff(bytes, 6, 1).toByte() val paramByte7 = intFromBuff(bytes, 6, 1).toByte()
val paramByte8 = intFromBuff(bytes, 7, 1).toByte() val paramByte8 = intFromBuff(bytes, 7, 1).toByte()
val value = intFromBuff(bytes, 8, 2).toDouble() val value = intFromBuff(bytes, 8, 2).toDouble()

View file

@ -4,6 +4,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import org.joda.time.DateTime
import java.util.* import java.util.*
class MsgSettingPumpTime( class MsgSettingPumpTime(
@ -17,14 +18,14 @@ class MsgSettingPumpTime(
} }
override fun handleMessage(bytes: ByteArray) { override fun handleMessage(bytes: ByteArray) {
val time = Date( val time = DateTime(
100 + intFromBuff(bytes, 5, 1), 2000 + intFromBuff(bytes, 5, 1),
intFromBuff(bytes, 4, 1) - 1, intFromBuff(bytes, 4, 1),
intFromBuff(bytes, 3, 1), intFromBuff(bytes, 3, 1),
intFromBuff(bytes, 2, 1), intFromBuff(bytes, 2, 1),
intFromBuff(bytes, 1, 1), intFromBuff(bytes, 1, 1),
intFromBuff(bytes, 0, 1) intFromBuff(bytes, 0, 1)
).time ).millis
aapsLogger.debug(LTag.PUMPCOMM, "Pump time: " + DateUtil.dateAndTimeString(time) + " Phone time: " + Date()) aapsLogger.debug(LTag.PUMPCOMM, "Pump time: " + DateUtil.dateAndTimeString(time) + " Phone time: " + Date())
danaRPump.pumpTime = time danaRPump.pumpTime = time
} }

View file

@ -5,6 +5,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import org.joda.time.DateTime
import java.util.* import java.util.*
class DanaRS_Packet_Bolus_Get_Step_Bolus_Information( class DanaRS_Packet_Bolus_Get_Step_Bolus_Information(
@ -18,32 +19,15 @@ class DanaRS_Packet_Bolus_Get_Step_Bolus_Information(
} }
override fun handleMessage(data: ByteArray) { override fun handleMessage(data: ByteArray) {
var dataIndex = DATA_START val error = intFromBuff(data, 0, 1)
var dataSize = 1 val bolusType = intFromBuff(data, 1, 1)
val error = byteArrayToInt(getBytes(data, dataIndex, dataSize)) danaRPump.initialBolusAmount = intFromBuff(data, 2, 2) / 100.0
dataIndex += dataSize val hours = intFromBuff(data, 4, 1)
dataSize = 1 val minutes = intFromBuff(data, 5, 1)
val bolusType = byteArrayToInt(getBytes(data, dataIndex, dataSize)) danaRPump.lastBolusTime = DateTime.now().withHourOfDay(hours).withMinuteOfHour(minutes).millis
dataIndex += dataSize danaRPump.lastBolusAmount = intFromBuff(data, 6, 2) / 100.0
dataSize = 2 danaRPump.maxBolus = intFromBuff(data, 8, 2) / 100.0
danaRPump.initialBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0 danaRPump.bolusStep = intFromBuff(data, 10, 1) / 100.0
val lbt = Date() // it doesn't provide day only hour+min, workaround: expecting today
dataIndex += dataSize
dataSize = 1
lbt.hours = byteArrayToInt(getBytes(data, dataIndex, dataSize))
dataIndex += dataSize
dataSize = 1
lbt.minutes = byteArrayToInt(getBytes(data, dataIndex, dataSize))
danaRPump.lastBolusTime = lbt.time
dataIndex += dataSize
dataSize = 2
danaRPump.lastBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0
dataIndex += dataSize
dataSize = 2
danaRPump.maxBolus = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0
dataIndex += dataSize
dataSize = 1
danaRPump.bolusStep = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0
failed = error != 0 failed = error != 0
aapsLogger.debug(LTag.PUMPCOMM, "Result: $error") aapsLogger.debug(LTag.PUMPCOMM, "Result: $error")
aapsLogger.debug(LTag.PUMPCOMM, "BolusType: $bolusType") aapsLogger.debug(LTag.PUMPCOMM, "BolusType: $bolusType")

View file

@ -1,11 +1,11 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import java.util.* import org.joda.time.DateTime
class DanaRS_Packet_General_Get_More_Information( class DanaRS_Packet_General_Get_More_Information(
private val aapsLogger: AAPSLogger, private val aapsLogger: AAPSLogger,
@ -22,37 +22,21 @@ class DanaRS_Packet_General_Get_More_Information(
failed = true failed = true
return return
} }
var dataIndex = DATA_START danaRPump.iob = intFromBuff(data, 0, 2) / 100.0
var dataSize = 2 danaRPump.dailyTotalUnits = intFromBuff(data, 2, 2) / 100.0
danaRPump.iob = byteArrayToInt(getBytes(data, dataIndex, dataSize)).toDouble() danaRPump.isExtendedInProgress = intFromBuff(data, 4, 1) == 0x01
dataIndex += dataSize danaRPump.extendedBolusRemainingMinutes = intFromBuff(data, 5, 2)
dataSize = 2 // val remainRate = intFromBuff(data, 7, 2) / 100.0
danaRPump.dailyTotalUnits = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0 val hours = intFromBuff(data, 9, 1)
dataIndex += dataSize val minutes = intFromBuff(data, 10, 1)
dataSize = 1 danaRPump.lastBolusTime = DateTime.now().withHourOfDay(hours).withMinuteOfHour(minutes).millis
danaRPump.isExtendedInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01 danaRPump.lastBolusAmount = intFromBuff(data, 11, 2) / 100.0
dataIndex += dataSize
dataSize = 2
danaRPump.extendedBolusRemainingMinutes = byteArrayToInt(getBytes(data, dataIndex, dataSize))
dataIndex += dataSize
dataSize = 2
//val remainRate = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0
val lastBolusTime = Date() // it doesn't provide day only hour+min, workaround: expecting today
dataIndex += dataSize
dataSize = 1
lastBolusTime.hours = byteArrayToInt(getBytes(data, dataIndex, dataSize))
dataIndex += dataSize
dataSize = 1
lastBolusTime.minutes = byteArrayToInt(getBytes(data, dataIndex, dataSize))
dataIndex += dataSize
dataSize = 2
danaRPump.lastBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)).toDouble()
// On DanaRS DailyUnits can't be more than 160 // On DanaRS DailyUnits can't be more than 160
if (danaRPump.dailyTotalUnits > 160) failed = true if (danaRPump.dailyTotalUnits > 160) failed = true
aapsLogger.debug(LTag.PUMPCOMM, "Daily total units: " + danaRPump.dailyTotalUnits.toString() + " U") aapsLogger.debug(LTag.PUMPCOMM, "Daily total units: " + danaRPump.dailyTotalUnits.toString() + " U")
aapsLogger.debug(LTag.PUMPCOMM, "Is extended in progress: " + danaRPump.isExtendedInProgress) aapsLogger.debug(LTag.PUMPCOMM, "Is extended in progress: " + danaRPump.isExtendedInProgress)
aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus remaining minutes: " + danaRPump.extendedBolusRemainingMinutes) aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus remaining minutes: " + danaRPump.extendedBolusRemainingMinutes)
aapsLogger.debug(LTag.PUMPCOMM, "Last bolus time: " + DateUtil.dateAndTimeAndSecondsString(lastBolusTime.time)) aapsLogger.debug(LTag.PUMPCOMM, "Last bolus time: " + DateUtil.dateAndTimeAndSecondsString(danaRPump.lastBolusTime))
aapsLogger.debug(LTag.PUMPCOMM, "Last bolus amount: " + danaRPump.lastBolusAmount) aapsLogger.debug(LTag.PUMPCOMM, "Last bolus amount: " + danaRPump.lastBolusAmount)
} }

View file

@ -8,6 +8,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes
import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import org.joda.time.DateTime
import java.util.* import java.util.*
abstract class DanaRS_Packet_History_( abstract class DanaRS_Packet_History_(
@ -25,6 +26,7 @@ abstract class DanaRS_Packet_History_(
var done = false var done = false
var totalCount = 0 var totalCount = 0
val danaRHistoryRecord = DanaRHistoryRecord()
init { init {
val cal = GregorianCalendar() val cal = GregorianCalendar()
@ -79,14 +81,13 @@ abstract class DanaRS_Packet_History_(
val historySecond = byteArrayToInt(getBytes(data, DATA_START + 6, 1)) val historySecond = byteArrayToInt(getBytes(data, DATA_START + 6, 1))
val paramByte7 = historySecond.toByte() val paramByte7 = historySecond.toByte()
val dailyBolus: Double = ((data[DATA_START + 6].toInt() and 0xFF shl 8) + (data[DATA_START + 7].toInt() and 0xFF)) * 0.01 val dailyBolus: Double = ((data[DATA_START + 6].toInt() and 0xFF shl 8) + (data[DATA_START + 7].toInt() and 0xFF)) * 0.01
val date = Date(100 + historyYear, historyMonth - 1, historyDay) val date = DateTime(2000 + historyYear, historyMonth, historyDay, 0, 0)
val datetime = Date(100 + historyYear, historyMonth - 1, historyDay, historyHour, historyMinute) val datetime = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute)
val datetimewihtsec = Date(100 + historyYear, historyMonth - 1, historyDay, historyHour, historyMinute, historySecond) val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
val historyCode = byteArrayToInt(getBytes(data, DATA_START + 7, 1)) val historyCode = byteArrayToInt(getBytes(data, DATA_START + 7, 1))
val paramByte8 = historyCode.toByte() val paramByte8 = historyCode.toByte()
val value: Int = (data[DATA_START + 8].toInt() and 0xFF shl 8) + (data[DATA_START + 9].toInt() and 0xFF) val value: Int = (data[DATA_START + 8].toInt() and 0xFF shl 8) + (data[DATA_START + 9].toInt() and 0xFF)
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + DateUtil.dateAndTimeString(datetimewihtsec) + " Code: " + historyCode + " Value: " + value) aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + DateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
val danaRHistoryRecord = DanaRHistoryRecord()
danaRHistoryRecord.setBytes(data) danaRHistoryRecord.setBytes(data)
// danaRHistoryRecord.recordCode is different from DanaR codes // danaRHistoryRecord.recordCode is different from DanaR codes
// set in switch for every type // set in switch for every type
@ -94,7 +95,7 @@ abstract class DanaRS_Packet_History_(
when (recordCode) { when (recordCode) {
0x02 -> { 0x02 -> {
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_BOLUS danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_BOLUS
danaRHistoryRecord.recordDate = datetime.time danaRHistoryRecord.recordDate = datetime.millis
when (0xF0 and paramByte8.toInt()) { when (0xF0 and paramByte8.toInt()) {
0xA0 -> { 0xA0 -> {
danaRHistoryRecord.bolusType = "DS" danaRHistoryRecord.bolusType = "DS"
@ -125,7 +126,7 @@ abstract class DanaRS_Packet_History_(
0x03 -> { 0x03 -> {
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_DAILY danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_DAILY
messageType += "dailyinsulin" messageType += "dailyinsulin"
danaRHistoryRecord.recordDate = date.time danaRHistoryRecord.recordDate = date.millis
danaRHistoryRecord.recordDailyBasal = dailyBasal danaRHistoryRecord.recordDailyBasal = dailyBasal
danaRHistoryRecord.recordDailyBolus = dailyBolus danaRHistoryRecord.recordDailyBolus = dailyBolus
} }
@ -133,49 +134,49 @@ abstract class DanaRS_Packet_History_(
0x04 -> { 0x04 -> {
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_PRIME danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_PRIME
messageType += "prime" messageType += "prime"
danaRHistoryRecord.recordDate = datetimewihtsec.time danaRHistoryRecord.recordDate = datetimewihtsec.millis
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
} }
0x05 -> { 0x05 -> {
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_REFILL danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_REFILL
messageType += "refill" messageType += "refill"
danaRHistoryRecord.recordDate = datetimewihtsec.time danaRHistoryRecord.recordDate = datetimewihtsec.millis
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
} }
0x0b -> { 0x0b -> {
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_BASALHOUR danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_BASALHOUR
messageType += "basal hour" messageType += "basal hour"
danaRHistoryRecord.recordDate = datetimewihtsec.time danaRHistoryRecord.recordDate = datetimewihtsec.millis
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
} }
0x99 -> { 0x99 -> {
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_TEMP_BASAL danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_TEMP_BASAL
messageType += "tb" messageType += "tb"
danaRHistoryRecord.recordDate = datetimewihtsec.time danaRHistoryRecord.recordDate = datetimewihtsec.millis
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
} }
0x06 -> { 0x06 -> {
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_GLUCOSE danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_GLUCOSE
messageType += "glucose" messageType += "glucose"
danaRHistoryRecord.recordDate = datetimewihtsec.time danaRHistoryRecord.recordDate = datetimewihtsec.millis
danaRHistoryRecord.recordValue = value.toDouble() danaRHistoryRecord.recordValue = value.toDouble()
} }
0x07 -> { 0x07 -> {
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_CARBO danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_CARBO
messageType += "carbo" messageType += "carbo"
danaRHistoryRecord.recordDate = datetimewihtsec.time danaRHistoryRecord.recordDate = datetimewihtsec.millis
danaRHistoryRecord.recordValue = value.toDouble() danaRHistoryRecord.recordValue = value.toDouble()
} }
0x0a -> { 0x0a -> {
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_ALARM danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_ALARM
messageType += "alarm" messageType += "alarm"
danaRHistoryRecord.recordDate = datetimewihtsec.time danaRHistoryRecord.recordDate = datetimewihtsec.millis
var strAlarm = "None" var strAlarm = "None"
when (paramByte8.toInt()) { when (paramByte8.toInt()) {
67 -> strAlarm = "Check" 67 -> strAlarm = "Check"
@ -190,7 +191,7 @@ abstract class DanaRS_Packet_History_(
0x09 -> { 0x09 -> {
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_SUSPEND danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_SUSPEND
messageType += "suspend" messageType += "suspend"
danaRHistoryRecord.recordDate = datetimewihtsec.time danaRHistoryRecord.recordDate = datetimewihtsec.millis
var strRecordValue = "Off" var strRecordValue = "Off"
if (paramByte8.toInt() == 79) strRecordValue = "On" if (paramByte8.toInt() == 79) strRecordValue = "On"
danaRHistoryRecord.stringRecordValue = strRecordValue danaRHistoryRecord.stringRecordValue = strRecordValue

View file

@ -1,11 +1,11 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import java.util.* import org.joda.time.DateTime
class DanaRS_Packet_Option_Get_Pump_Time( class DanaRS_Packet_Option_Get_Pump_Time(
private val aapsLogger: AAPSLogger, private val aapsLogger: AAPSLogger,
@ -36,10 +36,9 @@ class DanaRS_Packet_Option_Get_Pump_Time(
dataIndex += dataSize dataIndex += dataSize
dataSize = 1 dataSize = 1
val sec = byteArrayToInt(getBytes(data, dataIndex, dataSize)) val sec = byteArrayToInt(getBytes(data, dataIndex, dataSize))
val time = Date(100 + year, month - 1, day, hour, min, sec) val time = DateTime(2000 + year, month, day, hour, min, sec)
danaRPump.pumpTime = time.time danaRPump.pumpTime = time.millis
failed = year == month && month == day && day == hour && hour == min && min == sec && sec == 1 aapsLogger.debug(LTag.PUMPCOMM, "Pump time " + DateUtil.dateAndTimeString(time.millis))
aapsLogger.debug(LTag.PUMPCOMM, "Pump time " + DateUtil.dateAndTimeString(time))
} }
override fun handleMessageNotReceived() { override fun handleMessageNotReceived() {

View file

@ -1,10 +1,10 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import java.util.* import org.joda.time.DateTime
class DanaRS_Packet_Option_Set_Pump_Time( class DanaRS_Packet_Option_Set_Pump_Time(
private val aapsLogger: AAPSLogger, private val aapsLogger: AAPSLogger,
@ -19,14 +19,14 @@ class DanaRS_Packet_Option_Set_Pump_Time(
} }
override fun getRequestParams(): ByteArray { override fun getRequestParams(): ByteArray {
val date = Date(time) val date = DateTime(time)
val request = ByteArray(6) val request = ByteArray(6)
request[0] = (date.year - 100 and 0xff).toByte() request[0] = (date.year - 2000 and 0xff).toByte()
request[1] = (date.month + 1 and 0xff).toByte() request[1] = (date.monthOfYear and 0xff).toByte()
request[2] = (date.date and 0xff).toByte() request[2] = (date.dayOfMonth and 0xff).toByte()
request[3] = (date.hours and 0xff).toByte() request[3] = (date.hourOfDay and 0xff).toByte()
request[4] = (date.minutes and 0xff).toByte() request[4] = (date.minuteOfHour and 0xff).toByte()
request[5] = (date.seconds and 0xff).toByte() request[5] = (date.secondOfMinute and 0xff).toByte()
return request return request
} }

View file

@ -4,6 +4,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase
@Suppress("UNUSED_PARAMETER")
class MsgSetAPSTempBasalStart_v2( class MsgSetAPSTempBasalStart_v2(
private val aapsLogger: AAPSLogger, private val aapsLogger: AAPSLogger,
private var percent: Int, private var percent: Int,

View file

@ -5,6 +5,7 @@ import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
import java.util.*
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest() @PrepareForTest()
@ -12,14 +13,26 @@ class DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest : DanaRSTestBase() {
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump) val packet = DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump)
Assert.assertEquals(null, packet.requestParams)
// test message decoding val array = createArray(13, 0.toByte()) // 11 + 2
packet.handleMessage(createArray(34, 0.toByte())) putByteToArray(array, 0, 2) // error 2
Assert.assertEquals(false, packet.failed) putByteToArray(array, 1, 3) // bolus type 3
packet.handleMessage(createArray(34, 1.toByte())) putIntToArray(array, 2, 600) // initial bolus amount 6
val valueRequested: Int = (1 and 0x000000FF shl 8) + (1 and 0x000000FF) putByteToArray(array, 4, 13) // 13h
Assert.assertEquals(valueRequested / 100.0, danaRPump.lastBolusAmount, 0.0) putByteToArray(array, 5, 20) // 20min
Assert.assertEquals(true, packet.failed) putIntToArray(array, 6, 1250) // last bolus amount 12.5
putIntToArray(array, 8, 2500) // max bolus 25
putByteToArray(array, 10, 100) // bolus step 1
packet.handleMessage(array)
Assert.assertTrue(packet.failed)
Assert.assertEquals(6.0, danaRPump.initialBolusAmount, 0.01)
val lastBolus = Date(danaRPump.lastBolusTime)
Assert.assertEquals(13, lastBolus.hours)
Assert.assertEquals(20, lastBolus.minutes)
Assert.assertEquals(12.5, danaRPump.lastBolusAmount, 0.01)
Assert.assertEquals(25.0, danaRPump.maxBolus, 0.01)
Assert.assertEquals(1.0, danaRPump.bolusStep, 0.01)
Assert.assertEquals("BOLUS__GET_STEP_BOLUS_INFORMATION", packet.friendlyName) Assert.assertEquals("BOLUS__GET_STEP_BOLUS_INFORMATION", packet.friendlyName)
} }
} }

View file

@ -3,25 +3,39 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
import java.util.*
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_General_Get_More_InformationTest : DanaRSTestBase() { class DanaRS_Packet_General_Get_More_InformationTest : DanaRSTestBase() {
@Test fun runTest() { @Test fun runTest() {
var packet = DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump) var packet = DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump)
Assert.assertEquals(null, packet.requestParams)
// test message decoding packet.handleMessage(createArray(14, 0.toByte()))
// test for the length message Assert.assertTrue(packet.failed)
packet.handleMessage(createArray(13, 0.toByte()))
Assert.assertEquals(true, packet.failed)
packet = DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump) packet = DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump)
packet.handleMessage(createArray(15, 0.toByte())) val array = createArray(15, 0.toByte()) // 13 + 2
Assert.assertEquals(false, packet.failed) putIntToArray(array, 0, 600) // iob 6
packet.handleMessage(createArray(15, 161.toByte())) putIntToArray(array, 2, 1250) // daily units 12.5
Assert.assertEquals(true, packet.failed) putByteToArray(array, 4, 1) // is extended in progress
putIntToArray(array, 5, 150) // extended remaining minutes 150
putByteToArray(array, 9, 15) // hours 15
putByteToArray(array, 10, 25) // minutes 25
putIntToArray(array, 11, 170) // last bolus manout 1.70
packet.handleMessage(array)
Assert.assertFalse(packet.failed)
Assert.assertEquals(6.0, danaRPump.iob, 0.01)
Assert.assertEquals(12.5, danaRPump.dailyTotalUnits, 0.01)
Assert.assertTrue(danaRPump.isExtendedInProgress)
Assert.assertEquals(150, danaRPump.extendedBolusRemainingMinutes)
val lastBolus = Date(danaRPump.lastBolusTime)
Assert.assertEquals(15, lastBolus.hours)
Assert.assertEquals(25, lastBolus.minutes)
Assert.assertEquals(1.7, danaRPump.lastBolusAmount, 0.01)
Assert.assertEquals("REVIEW__GET_MORE_INFORMATION", packet.friendlyName) Assert.assertEquals("REVIEW__GET_MORE_INFORMATION", packet.friendlyName)
} }
} }

View file

@ -1,17 +1,52 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.db.DatabaseHelper
import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes
import org.junit.Assert import org.junit.Assert
import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.powermock.api.mockito.PowerMockito
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
import java.util.*
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest() @PrepareForTest(MainApp::class)
class DanaRS_Packet_History_AlarmTest : DanaRSTestBase() { class DanaRS_Packet_History_AlarmTest : DanaRSTestBase() {
@Test fun runTest() { @Mock lateinit var databaseHelper: DatabaseHelper
val packet = DanaRS_Packet_History_Alarm(aapsLogger, rxBus, System.currentTimeMillis())
@Before
fun mock() {
PowerMockito.mockStatic(MainApp::class.java)
`when`(MainApp.getDbHelper()).thenReturn(databaseHelper)
}
@Test
fun runTest() {
val packet = DanaRS_Packet_History_Alarm(aapsLogger, rxBus, 0)
val array = createArray(12, 0.toByte()) // 10 + 2
putByteToArray(array, 0, 0x0A) // record code alarm
putByteToArray(array, 1, 19) // year 2019
putByteToArray(array, 2, 2) // month february
putByteToArray(array, 3, 4) // day 4
putByteToArray(array, 4, 20) // hour 20
putByteToArray(array, 5, 11) // min 11
putByteToArray(array, 6, 35) // second 35
putByteToArray(array, 7, 79) // occlusion
putByteToArray(array, 8, 1) // value
putByteToArray(array, 9, 100) // value
packet.handleMessage(array)
Assert.assertEquals(RecordTypes.RECORD_TYPE_ALARM, packet.danaRHistoryRecord.recordCode)
Assert.assertEquals(Date(119, 1, 4, 20, 11, 35).time, packet.danaRHistoryRecord.recordDate)
Assert.assertEquals("Occlusion", packet.danaRHistoryRecord.recordAlarm)
Assert.assertEquals(3.56, packet.danaRHistoryRecord.recordValue, 0.01)
Assert.assertEquals("REVIEW__ALARM", packet.friendlyName) Assert.assertEquals("REVIEW__ALARM", packet.friendlyName)
} }
} }

View file

@ -1,25 +1,26 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import org.joda.time.DateTime
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Option_Get_Pump_TimeTest : DanaRSTestBase() { class DanaRS_Packet_Option_Get_Pump_TimeTest : DanaRSTestBase() {
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump) val packet = DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump)
// test params val array = createArray(8, 0.toByte()) // 6 + 2
Assert.assertEquals(null, packet.requestParams) putByteToArray(array, 0, 19) // year 2019
// test message decoding putByteToArray(array, 1, 2) // month february
packet.handleMessage(createArray(8, 0.toByte())) putByteToArray(array, 2, 4) // day 4
Assert.assertEquals(false, packet.failed) putByteToArray(array, 3, 20) // hour 20
// this should fail putByteToArray(array, 4, 11) // min 11
packet.handleMessage(createArray(8, 1.toByte())) putByteToArray(array, 5, 35) // second 35
Assert.assertEquals(true, packet.failed)
packet.handleMessage(array)
Assert.assertEquals(DateTime(2019, 2, 4, 20, 11, 35).millis, danaRPump.pumpTime)
Assert.assertEquals("OPTION__GET_PUMP_TIME", packet.friendlyName) Assert.assertEquals("OPTION__GET_PUMP_TIME", packet.friendlyName)
} }
} }

View file

@ -1,22 +1,25 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.utils.DateUtil
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
import java.util.* import java.util.*
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Option_Set_Pump_TimeTest : DanaRSTestBase() { class DanaRS_Packet_Option_Set_Pump_TimeTest : DanaRSTestBase() {
@Test fun runTest() { @Test fun runTest() {
val packet = DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, DateUtil.now()) val date = Date()
val packet = DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, date.time)
// test params // test params
val params = packet.requestParams val params = packet.requestParams
Assert.assertEquals((Date().date and 0xff).toByte(), params[2]) Assert.assertEquals((date.year - 100 and 0xff).toByte(), params[0]) // 2019 -> 19
Assert.assertEquals((date.month + 1 and 0xff).toByte(), params[1])
Assert.assertEquals((date.date and 0xff).toByte(), params[2])
Assert.assertEquals((date.hours and 0xff).toByte(), params[3])
Assert.assertEquals((date.minutes and 0xff).toByte(), params[4])
Assert.assertEquals((date.seconds and 0xff).toByte(), params[5])
// test message decoding // test message decoding
packet.handleMessage(createArray(3, 0.toByte())) packet.handleMessage(createArray(3, 0.toByte()))
Assert.assertEquals(false, packet.failed) Assert.assertEquals(false, packet.failed)