This commit is contained in:
Milos Kozak 2021-10-08 09:42:11 +02:00
parent 59ecd1818d
commit ddc37324a8
13 changed files with 526 additions and 345 deletions

View file

@ -127,7 +127,7 @@
</codeStyleSettings> </codeStyleSettings>
<codeStyleSettings language="kotlin"> <codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
<option name="RIGHT_MARGIN" value="120" /> <option name="RIGHT_MARGIN" value="200" />
<option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" /> <option name="LINE_COMMENT_AT_FIRST_COLUMN" value="false" />
<option name="LINE_COMMENT_ADD_SPACE" value="true" /> <option name="LINE_COMMENT_ADD_SPACE" value="true" />
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" /> <option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />

View file

@ -18,6 +18,7 @@ import org.joda.time.DateTimeZone
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONException import org.json.JSONException
import org.json.JSONObject import org.json.JSONObject
import java.security.InvalidParameterException
import java.text.DecimalFormat import java.text.DecimalFormat
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
@ -25,6 +26,7 @@ import javax.inject.Singleton
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
import kotlin.math.roundToInt import kotlin.math.roundToInt
import kotlin.math.roundToLong
@Singleton @Singleton
class DanaPump @Inject constructor( class DanaPump @Inject constructor(
@ -34,11 +36,13 @@ class DanaPump @Inject constructor(
private val injector: HasAndroidInjector private val injector: HasAndroidInjector
) { ) {
@Suppress("unused")
enum class ErrorState(val code: Int) { enum class ErrorState(val code: Int) {
NONE(0x00), NONE(0x00),
SUSPENDED(0x01), SUSPENDED(0x01),
DAILYMAX(0x02), DAILY_MAX(0x02),
BOLUSBLOCK(0x04), BOLUS_BLOCK(0x04),
ORDERDELIVERING(0x08), ORDERDELIVERING(0x08),
NOPRIME(0x10); NOPRIME(0x10);
@ -104,8 +108,6 @@ class DanaPump @Inject constructor(
var pumpSuspended = false var pumpSuspended = false
var calculatorEnabled = false var calculatorEnabled = false
var dailyTotalUnits = 0.0 var dailyTotalUnits = 0.0
var dailyTotalBolusUnits = 0.0 // RS only
var dailyTotalBasalUnits = 0.0 // RS only
var decRatio = 0 // RS v3: [%] for pump IOB calculation var decRatio = 0 // RS v3: [%] for pump IOB calculation
var maxDailyTotalUnits = 0 var maxDailyTotalUnits = 0
var bolusStep = 0.1 var bolusStep = 0.1
@ -147,7 +149,8 @@ class DanaPump @Inject constructor(
fun temporaryBasalToString(): String { fun temporaryBasalToString(): String {
if (!isTempBasalInProgress) return "" if (!isTempBasalInProgress) return ""
val passedMin = ((min(dateUtil.now(), tempBasalStart + tempBasalDuration) - tempBasalStart) / 60.0 / 1000).roundToInt() val passedMin =
((min(dateUtil.now(), tempBasalStart + tempBasalDuration) - tempBasalStart) / 60.0 / 1000).roundToInt()
return tempBasalPercent.toString() + "% @" + return tempBasalPercent.toString() + "% @" +
dateUtil.timeString(tempBasalStart) + dateUtil.timeString(tempBasalStart) +
" " + passedMin + "/" + T.msecs(tempBasalDuration).mins() + "'" " " + passedMin + "/" + T.msecs(tempBasalDuration).mins() + "'"
@ -183,7 +186,7 @@ class DanaPump @Inject constructor(
extendedBolusAmount = 0.0 extendedBolusAmount = 0.0
} }
} }
val extendedBolusPassedMinutes: Int private val extendedBolusPassedMinutes: Int
get() = T.msecs(max(0, dateUtil.now() - extendedBolusStart)).mins().toInt() get() = T.msecs(max(0, dateUtil.now() - extendedBolusStart)).mins().toInt()
val extendedBolusRemainingMinutes: Int val extendedBolusRemainingMinutes: Int
get() = max(T.msecs(extendedBolusStart + extendedBolusDuration - dateUtil.now()).mins().toInt(), 0) get() = max(T.msecs(extendedBolusStart + extendedBolusDuration - dateUtil.now()).mins().toInt(), 0)
@ -237,8 +240,8 @@ class DanaPump @Inject constructor(
var nightCF = 0.0 var nightCF = 0.0
// Profile I // Profile I
var cf24 = Array<Double>(24) { 0.0 } var cf24 = Array(24) { 0.0 }
var cir24 = Array<Double>(24) { 0.0 } var cir24 = Array(24) { 0.0 }
//var pumpProfiles = arrayOf<Array<Double>>() //var pumpProfiles = arrayOf<Array<Double>>()
var pumpProfiles: Array<Array<Double>>? = null var pumpProfiles: Array<Array<Double>>? = null
@ -263,7 +266,7 @@ class DanaPump @Inject constructor(
var cannulaVolume = 0 var cannulaVolume = 0
var refillAmount = 0 var refillAmount = 0
var target = 0 // mgdl 40~400 mmol 2.2~22 => 220~2200 var target = 0 // mgdl 40~400 mmol 2.2~22 => 220~2200
var userOptionsFrompump: ByteArray? = null var userOptionsFromPump: ByteArray? = null
var initialBolusAmount = 0.0 var initialBolusAmount = 0.0
// Bolus settings // Bolus settings
@ -273,7 +276,7 @@ class DanaPump @Inject constructor(
return if (units == UNITS_MGDL) Constants.MGDL else Constants.MMOL return if (units == UNITS_MGDL) Constants.MGDL else Constants.MMOL
} }
var bolusStartErrorCode: Int = 0 // last start bolus erroCode var bolusStartErrorCode: Int = 0 // last start bolus errorCode
var bolusingTreatment: EventOverviewBolusProgress.Treatment? = null // actually delivered treatment var bolusingTreatment: EventOverviewBolusProgress.Treatment? = null // actually delivered treatment
var bolusAmountToBeDelivered = 0.0 // amount to be delivered var bolusAmountToBeDelivered = 0.0 // amount to be delivered
var bolusProgressLastTimeStamp: Long = 0 // timestamp of last bolus progress message var bolusProgressLastTimeStamp: Long = 0 // timestamp of last bolus progress message
@ -297,19 +300,24 @@ class DanaPump @Inject constructor(
json.put("defaultProfile", PROFILE_PREFIX + (activeProfile + 1)) json.put("defaultProfile", PROFILE_PREFIX + (activeProfile + 1))
json.put("store", store) json.put("store", store)
profile.put("dia", Constants.defaultDIA) profile.put("dia", Constants.defaultDIA)
val carbratios = JSONArray() val carbRatios = JSONArray()
if (!profile24) { if (!profile24) {
carbratios.put(JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCIR)) carbRatios.put(JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCIR))
carbratios.put(JSONObject().put("time", "06:00").put("timeAsSeconds", 6 * 3600).put("value", morningCIR)) carbRatios.put(JSONObject().put("time", "06:00").put("timeAsSeconds", 6 * 3600).put("value", morningCIR))
carbratios.put(JSONObject().put("time", "11:00").put("timeAsSeconds", 11 * 3600).put("value", afternoonCIR)) carbRatios.put(JSONObject().put("time", "11:00").put("timeAsSeconds", 11 * 3600).put("value", afternoonCIR))
carbratios.put(JSONObject().put("time", "14:00").put("timeAsSeconds", 17 * 3600).put("value", eveningCIR)) carbRatios.put(JSONObject().put("time", "14:00").put("timeAsSeconds", 17 * 3600).put("value", eveningCIR))
carbratios.put(JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCIR)) carbRatios.put(JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCIR))
} else { // 24 values } else { // 24 values
for (i in 0..23) { for (i in 0..23) {
carbratios.put(JSONObject().put("time", String.format("%02d", i) + ":00").put("timeAsSeconds", i * 3600).put("value", cir24[i])) carbRatios.put(
JSONObject()
.put("time", String.format("%02d", i) + ":00")
.put("timeAsSeconds", i * 3600)
.put("value", cir24[i])
)
} }
} }
profile.put("carbratio", carbratios) profile.put("carbratio", carbRatios)
val sens = JSONArray() val sens = JSONArray()
if (!profile24) { if (!profile24) {
sens.put(JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCF)) sens.put(JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCF))
@ -319,7 +327,12 @@ class DanaPump @Inject constructor(
sens.put(JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCF)) sens.put(JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCF))
} else { // 24 values } else { // 24 values
for (i in 0..23) { for (i in 0..23) {
sens.put(JSONObject().put("time", String.format("%02d", i) + ":00").put("timeAsSeconds", i * 3600).put("value", cf24[i])) sens.put(
JSONObject()
.put("time", String.format("%02d", i) + ":00")
.put("timeAsSeconds", i * 3600)
.put("value", cf24[i])
)
} }
} }
profile.put("sens", sens) profile.put("sens", sens)
@ -334,11 +347,32 @@ class DanaPump @Inject constructor(
} else { } else {
df.format(h.toLong()) + ":00" df.format(h.toLong()) + ":00"
} }
basals.put(JSONObject().put("time", time).put("timeAsSeconds", h * basalIncrement).put("value", it[activeProfile][h])) basals.put(
JSONObject()
.put("time", time)
.put("timeAsSeconds", h * basalIncrement)
.put("value", it[activeProfile][h])
)
} }
profile.put("basal", basals) profile.put("basal", basals)
profile.put("target_low", JSONArray().put(JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", currentTarget))) profile.put(
profile.put("target_high", JSONArray().put(JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", currentTarget))) "target_low",
JSONArray().put(
JSONObject()
.put("time", "00:00")
.put("timeAsSeconds", 0)
.put("value", currentTarget)
)
)
profile.put(
"target_high",
JSONArray().put(
JSONObject()
.put("time", "00:00")
.put("timeAsSeconds", 0)
.put("value", currentTarget)
)
)
profile.put("units", if (units == UNITS_MGDL) Constants.MGDL else Constants.MMOL) profile.put("units", if (units == UNITS_MGDL) Constants.MGDL else Constants.MMOL)
store.put(PROFILE_PREFIX + (activeProfile + 1), profile) store.put(PROFILE_PREFIX + (activeProfile + 1), profile)
} catch (e: JSONException) { } catch (e: JSONException) {
@ -356,7 +390,7 @@ class DanaPump @Inject constructor(
for (hour in 0..23) { for (hour in 0..23) {
//Some values get truncated to the next lower one. //Some values get truncated to the next lower one.
// -> round them to two decimals and make sure we are a small delta larger (that will get truncated) // -> round them to two decimals and make sure we are a small delta larger (that will get truncated)
val value = Math.round(100.0 * nsProfile.getBasalTimeFromMidnight((hour * 60 * 60))) / 100.0 + 0.00001 val value = (100.0 * nsProfile.getBasalTimeFromMidnight((hour * 60 * 60))).roundToLong() / 100.0 + 0.00001
aapsLogger.debug(LTag.PUMP, "NS basal value for $hour:00 is $value") aapsLogger.debug(LTag.PUMP, "NS basal value for $hour:00 is $value")
record[hour] = value record[hour] = value
} }
@ -367,7 +401,10 @@ class DanaPump @Inject constructor(
get() = password == sp.getInt(R.string.key_danar_password, -2) get() = password == sp.getInt(R.string.key_danar_password, -2)
val isRSPasswordOK: Boolean val isRSPasswordOK: Boolean
get() = rsPassword.equals(sp.getString(R.string.key_danars_password, ""), ignoreCase = true) || ignoreUserPassword get() = rsPassword.equals(
sp.getString(R.string.key_danars_password, ""),
ignoreCase = true
) || ignoreUserPassword
fun reset() { fun reset() {
aapsLogger.debug(LTag.PUMP, "DanaRPump reset") aapsLogger.debug(LTag.PUMP, "DanaRPump reset")
@ -410,6 +447,34 @@ class DanaPump @Inject constructor(
else -> PumpType.USER else -> PumpType.USER
} }
// v2, RS history entries
enum class HistoryEntry(val value: Int) {
TEMP_START(1),
TEMP_STOP(2),
EXTENDED_START(3),
EXTENDED_STOP(4),
BOLUS(5),
DUAL_BOLUS(6),
DUAL_EXTENDED_START(7),
DUAL_EXTENDED_STOP(8),
SUSPEND_ON(9),
SUSPEND_OFF(10),
REFILL(11),
PRIME(12),
PROFILE_CHANGE(13),
CARBS(14),
PRIME_CANNULA(15),
TIME_CHANGE(16)
;
companion object {
fun fromInt(value: Int) = values().firstOrNull { it.value == value } ?: throw InvalidParameterException()
}
}
companion object { companion object {
const val UNITS_MGDL = 0 const val UNITS_MGDL = 0
@ -420,24 +485,6 @@ class DanaPump @Inject constructor(
const val DELIVERY_EXT_BOLUS = 0x08 const val DELIVERY_EXT_BOLUS = 0x08
const val PROFILE_PREFIX = "DanaR-" const val PROFILE_PREFIX = "DanaR-"
// v2 history entries
const val TEMPSTART = 1
const val TEMPSTOP = 2
const val EXTENDEDSTART = 3
const val EXTENDEDSTOP = 4
const val BOLUS = 5
const val DUALBOLUS = 6
const val DUALEXTENDEDSTART = 7
const val DUALEXTENDEDSTOP = 8
const val SUSPENDON = 9
const val SUSPENDOFF = 10
const val REFILL = 11
const val PRIME = 12
const val PROFILECHANGE = 13
const val CARBS = 14
const val PRIMECANNULA = 15
const val TIMECHANGE = 16
// Dana R btModel // Dana R btModel
const val DOMESTIC_MODEL = 0x01 const val DOMESTIC_MODEL = 0x01
const val EXPORT_MODEL = 0x03 const val EXPORT_MODEL = 0x03

View file

@ -67,7 +67,7 @@ class MessageHashTableRv2 @Inject constructor(
put(MsgCheckValue_v2(injector)) // 0xF0F1 CMD_PUMP_CHECK_VALUE put(MsgCheckValue_v2(injector)) // 0xF0F1 CMD_PUMP_CHECK_VALUE
put(MsgStatusAPS_v2(injector)) // 0xE001 CMD_PUMPSTATUS_APS put(MsgStatusAPS_v2(injector)) // 0xE001 CMD_PUMPSTATUS_APS
put(MsgSetAPSTempBasalStart_v2(injector, 0, false, false)) // 0xE002 CMD_PUMPSET_APSTEMP put(MsgSetAPSTempBasalStart_v2(injector, 0, false, false)) // 0xE002 CMD_PUMPSET_APSTEMP
put(MsgHistoryEvents_v2(injector)) // 0xE003 CMD_GET_HISTORY put(MsgHistoryEventsV2(injector)) // 0xE003 CMD_GET_HISTORY
put(MsgSetHistoryEntry_v2(injector, 0, 0, 0, 0)) // 0xE004 CMD_SET_HISTORY_ENTRY put(MsgSetHistoryEntry_v2(injector, 0, 0, 0, 0)) // 0xE004 CMD_SET_HISTORY_ENTRY
} }

View file

@ -0,0 +1,276 @@
package info.nightscout.androidaps.danaRv2.comm
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.dana.DanaPump
import info.nightscout.androidaps.danar.R
import info.nightscout.androidaps.danar.comm.MessageBase
import info.nightscout.androidaps.events.EventPumpStatusChanged
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.utils.T
import java.util.*
class MsgHistoryEventsV2 constructor(
injector: HasAndroidInjector,
var from: Long = 0
) : MessageBase(injector) {
companion object {
var messageBuffer = arrayListOf<ByteArray>() // for reversing order of incoming messages
}
init {
SetCommand(0xE003)
if (from > dateUtil.now()) {
aapsLogger.error("Asked to load from the future")
from = 0
}
if (from == 0L) {
AddParamByte(0.toByte())
AddParamByte(1.toByte())
AddParamByte(1.toByte())
AddParamByte(0.toByte())
AddParamByte(0.toByte())
} else {
val gFrom = GregorianCalendar()
gFrom.timeInMillis = from
AddParamDate(gFrom)
}
aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + dateUtil.dateAndTimeString(from))
danaPump.historyDoneReceived = false
messageBuffer = arrayListOf()
}
override fun handleMessage(data: ByteArray) {
val recordCode = intFromBuff(data, 0, 1).toByte()
// Last record
if (recordCode == 0xFF.toByte()) {
aapsLogger.debug(LTag.PUMPCOMM, "Last record received")
val array: Array<ByteArray> = messageBuffer.toTypedArray()
val sorted = array.sortedArrayWith { s1: ByteArray, s2: ByteArray -> (dateTime(s1) - dateTime(s2)).toInt() }
for (message in sorted) processMessage(message)
danaPump.historyDoneReceived = true
} else messageBuffer.add(data)
}
fun dateTime(data: ByteArray): Long =
dateTimeSecFromBuff(data, 1) // 6 bytes
fun processMessage(bytes: ByteArray) {
val recordCode = intFromBuff(bytes, 0, 1).toByte()
// Last record
if (recordCode == 0xFF.toByte()) {
return
}
val datetime = dateTimeSecFromBuff(bytes, 1) // 6 bytes
val param1 = intFromBuff(bytes, 7, 2)
val param2 = intFromBuff(bytes, 9, 2)
val status: String
when (DanaPump.HistoryEntry.fromInt(recordCode.toInt())) {
DanaPump.HistoryEntry.TEMP_START -> {
aapsLogger.debug(
LTag.PUMPBTCOMM,
"EVENT TEMP_START ($recordCode) " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Ratio: " + param1 + "% Duration: " + param2 + "min"
)
val temporaryBasalInfo = temporaryBasalStorage.findTemporaryBasal(datetime, param1.toDouble())
pumpSync.syncTemporaryBasalWithPumpId(
timestamp = datetime,
rate = param1.toDouble(),
duration = T.mins(param2.toLong()).msecs(),
isAbsolute = false,
type = temporaryBasalInfo?.type,
pumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber
)
status = "TEMP_START " + dateUtil.timeString(datetime)
}
DanaPump.HistoryEntry.TEMP_STOP -> {
aapsLogger.debug(
LTag.PUMPBTCOMM,
"EVENT TEMP_STOP ($recordCode) " + dateUtil.dateAndTimeString(datetime)
)
pumpSync.syncStopTemporaryBasalWithPumpId(
timestamp = datetime,
endPumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber
)
status = "TEMP_STOP " + dateUtil.timeString(datetime)
}
DanaPump.HistoryEntry.EXTENDED_START -> {
val newRecord = pumpSync.syncExtendedBolusWithPumpId(
timestamp = datetime,
amount = param1 / 100.0,
duration = T.mins(param2.toLong()).msecs(),
isEmulatingTB = false,
pumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber
)
aapsLogger.debug(
LTag.PUMPBTCOMM,
(if (newRecord) "**NEW** " else "") + "EVENT EXTENDED_START (" + recordCode + ") "
+ dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min"
)
status = "EXTENDED_START " + dateUtil.timeString(datetime)
}
DanaPump.HistoryEntry.EXTENDED_STOP -> {
val newRecord = pumpSync.syncStopExtendedBolusWithPumpId(
timestamp = datetime,
endPumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber
)
aapsLogger.debug(
LTag.PUMPBTCOMM,
(if (newRecord) "**NEW** " else "") + "EVENT EXTENDED_STOP (" + recordCode + ") "
+ dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min"
)
status = "EXTENDED_STOP " + dateUtil.timeString(datetime)
}
DanaPump.HistoryEntry.BOLUS -> {
val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0)
val newRecord = pumpSync.syncBolusWithPumpId(
timestamp = datetime,
amount = param1 / 100.0,
type = detailedBolusInfo?.bolusType,
pumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber
)
aapsLogger.debug(
LTag.PUMPBTCOMM,
(if (newRecord) "**NEW** " else "") + "EVENT BOLUS (" + recordCode + ") "
+ dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min"
)
status = "BOLUS " + dateUtil.timeString(datetime)
}
DanaPump.HistoryEntry.DUAL_BOLUS -> {
val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0)
val newRecord = pumpSync.syncBolusWithPumpId(
timestamp = datetime,
amount = param1 / 100.0,
type = detailedBolusInfo?.bolusType,
pumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber
)
aapsLogger.debug(
LTag.PUMPBTCOMM,
(if (newRecord) "**NEW** " else "") + "EVENT DUAL_BOLUS (" + recordCode + ") "
+ dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min"
)
status = "DUAL_BOLUS " + dateUtil.timeString(datetime)
}
DanaPump.HistoryEntry.DUAL_EXTENDED_START -> {
val newRecord = pumpSync.syncExtendedBolusWithPumpId(
timestamp = datetime,
amount = param1 / 100.0,
duration = T.mins(param2.toLong()).msecs(),
isEmulatingTB = false,
pumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber
)
aapsLogger.debug(
LTag.PUMPBTCOMM,
(if (newRecord) "**NEW** " else "") + "EVENT DUAL_EXTENDED_START (" + recordCode + ") "
+ dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min"
)
status = "DUAL_EXTENDED_START " + dateUtil.timeString(datetime)
}
DanaPump.HistoryEntry.DUAL_EXTENDED_STOP -> {
val newRecord = pumpSync.syncStopExtendedBolusWithPumpId(
timestamp = datetime,
endPumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber
)
aapsLogger.debug(
LTag.PUMPBTCOMM,
(if (newRecord) "**NEW** " else "") + "EVENT DUAL_EXTENDED_STOP (" + recordCode + ") "
+ dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min"
)
status = "DUAL_EXTENDED_STOP " + dateUtil.timeString(datetime)
}
DanaPump.HistoryEntry.SUSPEND_ON -> {
aapsLogger.debug(
LTag.PUMPBTCOMM,
"EVENT SUSPEND_ON (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")"
)
status = "SUSPEND_ON " + dateUtil.timeString(datetime)
}
DanaPump.HistoryEntry.SUSPEND_OFF -> {
aapsLogger.debug(
LTag.PUMPBTCOMM,
"EVENT SUSPEND_OFF (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")"
)
status = "SUSPEND_OFF " + dateUtil.timeString(datetime)
}
DanaPump.HistoryEntry.REFILL -> {
aapsLogger.debug(
LTag.PUMPBTCOMM,
"EVENT REFILL (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U"
)
status = "REFILL " + dateUtil.timeString(datetime)
}
DanaPump.HistoryEntry.PRIME -> {
aapsLogger.debug(
LTag.PUMPBTCOMM,
"EVENT PRIME (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U"
)
status = "PRIME " + dateUtil.timeString(datetime)
}
DanaPump.HistoryEntry.PROFILE_CHANGE -> {
aapsLogger.debug(
LTag.PUMPBTCOMM,
"EVENT PROFILE_CHANGE (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " No: " + param1 + " CurrentRate: " + param2 / 100.0 + "U/h"
)
status = "PROFILE_CHANGE " + dateUtil.timeString(datetime)
}
DanaPump.HistoryEntry.CARBS -> {
val newRecord = pumpSync.syncCarbsWithTimestamp(
timestamp = datetime,
amount = param1.toDouble(),
pumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber
)
aapsLogger.debug(
LTag.PUMPBTCOMM,
(if (newRecord) "**NEW** " else "") + "EVENT CARBS (" + recordCode + ") " + dateUtil.dateAndTimeString(
datetime
) + " (" + datetime + ")" + " Carbs: " + param1 + "g"
)
status = "CARBS " + dateUtil.timeString(datetime)
}
else -> {
aapsLogger.debug(
LTag.PUMPBTCOMM,
"Event: " + recordCode + " " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2
)
status = "UNKNOWN " + dateUtil.timeString(datetime)
}
}
if (datetime > danaPump.lastEventTimeLoaded) danaPump.lastEventTimeLoaded = datetime
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.processinghistory) + ": " + status))
}
}

View file

@ -1,214 +0,0 @@
package info.nightscout.androidaps.danaRv2.comm
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.dana.DanaPump
import info.nightscout.androidaps.danar.R
import info.nightscout.androidaps.danar.comm.MessageBase
import info.nightscout.androidaps.events.EventPumpStatusChanged
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.utils.T
import java.util.*
class MsgHistoryEvents_v2 constructor(
injector: HasAndroidInjector,
var from: Long = 0
) : MessageBase(injector) {
companion object {
var messageBuffer = arrayListOf<ByteArray>() // for reversing order of incoming messages
}
init {
SetCommand(0xE003)
if (from > dateUtil.now()) {
aapsLogger.error("Asked to load from the future")
from = 0
}
if (from == 0L) {
AddParamByte(0.toByte())
AddParamByte(1.toByte())
AddParamByte(1.toByte())
AddParamByte(0.toByte())
AddParamByte(0.toByte())
} else {
val gfrom = GregorianCalendar()
gfrom.timeInMillis = from
AddParamDate(gfrom)
}
aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + dateUtil.dateAndTimeString(from))
danaPump.historyDoneReceived = false
messageBuffer = arrayListOf()
}
override fun handleMessage(data: ByteArray) {
val recordCode = intFromBuff(data, 0, 1).toByte()
// Last record
if (recordCode == 0xFF.toByte()) {
aapsLogger.debug(LTag.PUMPCOMM, "Last record received")
val array: Array<ByteArray> = messageBuffer.toTypedArray()
val sorted = array.sortedArrayWith { s1: ByteArray, s2: ByteArray -> (dateTime(s1) - dateTime(s2)).toInt() }
for (message in sorted) processMessage(message)
danaPump.historyDoneReceived = true
} else messageBuffer.add(data)
}
fun dateTime(data: ByteArray): Long =
dateTimeSecFromBuff(data, 1) // 6 bytes
fun processMessage(bytes: ByteArray) {
val recordCode = intFromBuff(bytes, 0, 1).toByte()
// Last record
if (recordCode == 0xFF.toByte()) {
return
}
val datetime = dateTimeSecFromBuff(bytes, 1) // 6 bytes
val param1 = intFromBuff(bytes, 7, 2)
val param2 = intFromBuff(bytes, 9, 2)
val status: String
when (recordCode.toInt()) {
DanaPump.TEMPSTART -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT TEMPSTART (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Ratio: " + param1 + "% Duration: " + param2 + "min")
val temporaryBasalInfo = temporaryBasalStorage.findTemporaryBasal(datetime, param1.toDouble())
pumpSync.syncTemporaryBasalWithPumpId(
timestamp = datetime,
rate = param1.toDouble(),
duration = T.mins(param2.toLong()).msecs(),
isAbsolute = false,
type = temporaryBasalInfo?.type,
pumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber)
status = "TEMPSTART " + dateUtil.timeString(datetime)
}
DanaPump.TEMPSTOP -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT TEMPSTOP (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime))
pumpSync.syncStopTemporaryBasalWithPumpId(
timestamp = datetime,
endPumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber)
status = "TEMPSTOP " + dateUtil.timeString(datetime)
}
DanaPump.EXTENDEDSTART -> {
val newRecord = pumpSync.syncExtendedBolusWithPumpId(
timestamp = datetime,
amount = param1 / 100.0,
duration = T.mins(param2.toLong()).msecs(),
isEmulatingTB = false,
pumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber)
aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT EXTENDEDSTART (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min")
status = "EXTENDEDSTART " + dateUtil.timeString(datetime)
}
DanaPump.EXTENDEDSTOP -> {
val newRecord = pumpSync.syncStopExtendedBolusWithPumpId(
timestamp = datetime,
endPumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber)
aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT EXTENDEDSTOP (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min")
status = "EXTENDEDSTOP " + dateUtil.timeString(datetime)
}
DanaPump.BOLUS -> {
val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0)
val newRecord = pumpSync.syncBolusWithPumpId(
timestamp = datetime,
amount = param1 / 100.0,
type = detailedBolusInfo?.bolusType,
pumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber)
aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT BOLUS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min")
status = "BOLUS " + dateUtil.timeString(datetime)
}
DanaPump.DUALBOLUS -> {
val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0)
val newRecord = pumpSync.syncBolusWithPumpId(
timestamp = datetime,
amount = param1 / 100.0,
type = detailedBolusInfo?.bolusType,
pumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber)
aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT DUALBOLUS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min")
status = "DUALBOLUS " + dateUtil.timeString(datetime)
}
DanaPump.DUALEXTENDEDSTART -> {
val newRecord = pumpSync.syncExtendedBolusWithPumpId(
timestamp = datetime,
amount = param1 / 100.0,
duration = T.mins(param2.toLong()).msecs(),
isEmulatingTB = false,
pumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber)
aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT DUALEXTENDEDSTART (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min")
status = "DUALEXTENDEDSTART " + dateUtil.timeString(datetime)
}
DanaPump.DUALEXTENDEDSTOP -> {
val newRecord = pumpSync.syncStopExtendedBolusWithPumpId(
timestamp = datetime,
endPumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber)
aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min")
status = "DUALEXTENDEDSTOP " + dateUtil.timeString(datetime)
}
DanaPump.SUSPENDON -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT SUSPENDON (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")")
status = "SUSPENDON " + dateUtil.timeString(datetime)
}
DanaPump.SUSPENDOFF -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT SUSPENDOFF (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")")
status = "SUSPENDOFF " + dateUtil.timeString(datetime)
}
DanaPump.REFILL -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT REFILL (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U")
status = "REFILL " + dateUtil.timeString(datetime)
}
DanaPump.PRIME -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT PRIME (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U")
status = "PRIME " + dateUtil.timeString(datetime)
}
DanaPump.PROFILECHANGE -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT PROFILECHANGE (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " No: " + param1 + " CurrentRate: " + param2 / 100.0 + "U/h")
status = "PROFILECHANGE " + dateUtil.timeString(datetime)
}
DanaPump.CARBS -> {
val newRecord = pumpSync.syncCarbsWithTimestamp(
timestamp = datetime,
amount = param1.toDouble(),
pumpId = datetime,
pumpType = PumpType.DANA_RV2,
pumpSerial = danaPump.serialNumber)
aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT CARBS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g")
status = "CARBS " + dateUtil.timeString(datetime)
}
else -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "Event: " + recordCode + " " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2)
status = "UNKNOWN " + dateUtil.timeString(datetime)
}
}
if (datetime > danaPump.lastEventTimeLoaded) danaPump.lastEventTimeLoaded = datetime
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.processinghistory) + ": " + status))
}
}

View file

@ -17,7 +17,7 @@ import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.danaRv2.DanaRv2Plugin; import info.nightscout.androidaps.danaRv2.DanaRv2Plugin;
import info.nightscout.androidaps.danaRv2.comm.MessageHashTableRv2; import info.nightscout.androidaps.danaRv2.comm.MessageHashTableRv2;
import info.nightscout.androidaps.danaRv2.comm.MsgCheckValue_v2; import info.nightscout.androidaps.danaRv2.comm.MsgCheckValue_v2;
import info.nightscout.androidaps.danaRv2.comm.MsgHistoryEvents_v2; import info.nightscout.androidaps.danaRv2.comm.MsgHistoryEventsV2;
import info.nightscout.androidaps.danaRv2.comm.MsgSetAPSTempBasalStart_v2; import info.nightscout.androidaps.danaRv2.comm.MsgSetAPSTempBasalStart_v2;
import info.nightscout.androidaps.danaRv2.comm.MsgSetHistoryEntry_v2; import info.nightscout.androidaps.danaRv2.comm.MsgSetHistoryEntry_v2;
import info.nightscout.androidaps.danar.R; import info.nightscout.androidaps.danar.R;
@ -344,7 +344,8 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
if (carbs > 0) { if (carbs > 0) {
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(injector, carbtime, carbs); MsgSetCarbsEntry msg = new MsgSetCarbsEntry(injector, carbtime, carbs);
mSerialIOThread.sendMessage(msg); mSerialIOThread.sendMessage(msg);
MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(injector, DanaPump.CARBS, carbtime, carbs, 0); MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(injector,
DanaPump.HistoryEntry.CARBS.getValue(), carbtime, carbs, 0);
mSerialIOThread.sendMessage(msgSetHistoryEntry_v2); mSerialIOThread.sendMessage(msgSetHistoryEntry_v2);
danaPump.lastHistoryFetched = Math.min(danaPump.lastHistoryFetched, carbtime - T.Companion.mins(1).msecs()); danaPump.lastHistoryFetched = Math.min(danaPump.lastHistoryFetched, carbtime - T.Companion.mins(1).msecs());
} }
@ -413,7 +414,8 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
if (!isConnected()) return false; if (!isConnected()) return false;
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(injector, time, amount); MsgSetCarbsEntry msg = new MsgSetCarbsEntry(injector, time, amount);
mSerialIOThread.sendMessage(msg); mSerialIOThread.sendMessage(msg);
MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(injector, DanaPump.CARBS, time, amount, 0); MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(injector,
DanaPump.HistoryEntry.CARBS.getValue(), time, amount, 0);
mSerialIOThread.sendMessage(msgSetHistoryEntry_v2); mSerialIOThread.sendMessage(msgSetHistoryEntry_v2);
danaPump.lastHistoryFetched = Math.min(danaPump.lastHistoryFetched, time - T.Companion.mins(1).msecs()); danaPump.lastHistoryFetched = Math.min(danaPump.lastHistoryFetched, time - T.Companion.mins(1).msecs());
return true; return true;
@ -430,7 +432,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
if (!isConnected()) if (!isConnected())
return new PumpEnactResult(injector).success(false); return new PumpEnactResult(injector).success(false);
SystemClock.sleep(300); SystemClock.sleep(300);
MsgHistoryEvents_v2 msg = new MsgHistoryEvents_v2(injector, danaPump.lastHistoryFetched); MsgHistoryEventsV2 msg = new MsgHistoryEventsV2(injector, danaPump.lastHistoryFetched);
aapsLogger.debug(LTag.PUMP, "Loading event history from: " + dateUtil.dateAndTimeString(danaPump.lastHistoryFetched)); aapsLogger.debug(LTag.PUMP, "Loading event history from: " + dateUtil.dateAndTimeString(danaPump.lastHistoryFetched));
mSerialIOThread.sendMessage(msg); mSerialIOThread.sendMessage(msg);

View file

@ -9,20 +9,20 @@ class MsgSetUserOptions(
init { init {
SetCommand(0x330B) SetCommand(0x330B)
if (danaPump.userOptionsFrompump == null) { if (danaPump.userOptionsFromPump == null) {
// No options set -> Exiting // No options set -> Exiting
aapsLogger.debug(LTag.PUMPCOMM, "NO USER OPTIONS LOADED EXITING!") aapsLogger.debug(LTag.PUMPCOMM, "NO USER OPTIONS LOADED EXITING!")
} else { } else {
danaPump.userOptionsFrompump!![0] = if( danaPump.timeDisplayType24) 0.toByte() else 1.toByte() danaPump.userOptionsFromPump!![0] = if( danaPump.timeDisplayType24) 0.toByte() else 1.toByte()
danaPump.userOptionsFrompump!![1] = if (danaPump.buttonScrollOnOff) 1.toByte() else 0.toByte() danaPump.userOptionsFromPump!![1] = if (danaPump.buttonScrollOnOff) 1.toByte() else 0.toByte()
danaPump.userOptionsFrompump!![2] = danaPump.beepAndAlarm.toByte() danaPump.userOptionsFromPump!![2] = danaPump.beepAndAlarm.toByte()
danaPump.userOptionsFrompump!![3] = danaPump.lcdOnTimeSec.toByte() danaPump.userOptionsFromPump!![3] = danaPump.lcdOnTimeSec.toByte()
danaPump.userOptionsFrompump!![4] = danaPump.backlightOnTimeSec.toByte() danaPump.userOptionsFromPump!![4] = danaPump.backlightOnTimeSec.toByte()
danaPump.userOptionsFrompump!![5] = danaPump.selectedLanguage.toByte() danaPump.userOptionsFromPump!![5] = danaPump.selectedLanguage.toByte()
danaPump.userOptionsFrompump!![8] = danaPump.units.toByte() danaPump.userOptionsFromPump!![8] = danaPump.units.toByte()
danaPump.userOptionsFrompump!![9] = danaPump.shutdownHour.toByte() danaPump.userOptionsFromPump!![9] = danaPump.shutdownHour.toByte()
danaPump.userOptionsFrompump!![27] = danaPump.lowReservoirRate.toByte() danaPump.userOptionsFromPump!![27] = danaPump.lowReservoirRate.toByte()
for (element in danaPump.userOptionsFrompump!!) { for (element in danaPump.userOptionsFromPump!!) {
AddParamByte(element) AddParamByte(element)
} }
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")

View file

@ -15,7 +15,7 @@ class MsgSettingUserOptions(
override fun handleMessage(packet: ByteArray) { override fun handleMessage(packet: ByteArray) {
val bytes = getDataBytes(packet, packet.size - 10) val bytes = getDataBytes(packet, packet.size - 10)
danaPump.userOptionsFrompump = bytes.copyOf(bytes.size) // saving pumpDataBytes to use it in MsgSetUserOptions danaPump.userOptionsFromPump = bytes.copyOf(bytes.size) // saving pumpDataBytes to use it in MsgSetUserOptions
for (pos in bytes.indices) { for (pos in bytes.indices) {
aapsLogger.debug(LTag.PUMPCOMM, "[" + pos + "]" + bytes[pos]) aapsLogger.debug(LTag.PUMPCOMM, "[" + pos + "]" + bytes[pos])
} }

View file

@ -4,7 +4,7 @@ import dagger.Module
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.danaRKorean.comm.* import info.nightscout.androidaps.danaRKorean.comm.*
import info.nightscout.androidaps.danaRv2.comm.MsgCheckValue_v2 import info.nightscout.androidaps.danaRv2.comm.MsgCheckValue_v2
import info.nightscout.androidaps.danaRv2.comm.MsgHistoryEvents_v2 import info.nightscout.androidaps.danaRv2.comm.MsgHistoryEventsV2
import info.nightscout.androidaps.danaRv2.comm.MsgSetAPSTempBasalStart_v2 import info.nightscout.androidaps.danaRv2.comm.MsgSetAPSTempBasalStart_v2
import info.nightscout.androidaps.danaRv2.comm.MsgSetHistoryEntry_v2 import info.nightscout.androidaps.danaRv2.comm.MsgSetHistoryEntry_v2
import info.nightscout.androidaps.danaRv2.comm.MsgStatusAPS_v2 import info.nightscout.androidaps.danaRv2.comm.MsgStatusAPS_v2
@ -69,7 +69,7 @@ abstract class DanaRCommModule {
@ContributesAndroidInjector abstract fun contributesMsgHistoryNew(): MsgHistoryNew @ContributesAndroidInjector abstract fun contributesMsgHistoryNew(): MsgHistoryNew
@ContributesAndroidInjector abstract fun contributesMsgCheckValue_v2(): MsgCheckValue_v2 @ContributesAndroidInjector abstract fun contributesMsgCheckValue_v2(): MsgCheckValue_v2
@ContributesAndroidInjector abstract fun contributesMsgHistoryEvents_v2(): MsgHistoryEvents_v2 @ContributesAndroidInjector abstract fun contributesMsgHistoryEventsV2(): MsgHistoryEventsV2
@ContributesAndroidInjector abstract fun contributesMsgSetAPSTempBasalStart_v2(): MsgSetAPSTempBasalStart_v2 @ContributesAndroidInjector abstract fun contributesMsgSetAPSTempBasalStart_v2(): MsgSetAPSTempBasalStart_v2
@ContributesAndroidInjector abstract fun contributesMsgSetHistoryEntry_v2(): MsgSetHistoryEntry_v2 @ContributesAndroidInjector abstract fun contributesMsgSetHistoryEntry_v2(): MsgSetHistoryEntry_v2
@ContributesAndroidInjector abstract fun contributesMsgStatusAPS_v2(): MsgStatusAPS_v2 @ContributesAndroidInjector abstract fun contributesMsgStatusAPS_v2(): MsgStatusAPS_v2

View file

@ -1,6 +1,6 @@
package info.nightscout.androidaps.plugins.pump.danaRv2.comm package info.nightscout.androidaps.plugins.pump.danaRv2.comm
import info.nightscout.androidaps.danaRv2.comm.MsgHistoryEvents_v2 import info.nightscout.androidaps.danaRv2.comm.MsgHistoryEventsV2
import info.nightscout.androidaps.plugins.pump.danaR.comm.DanaRTestBase import info.nightscout.androidaps.plugins.pump.danaR.comm.DanaRTestBase
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
@ -8,7 +8,7 @@ import org.junit.Test
class MsgHistoryEventsRv2Test : DanaRTestBase() { class MsgHistoryEventsRv2Test : DanaRTestBase() {
@Test fun runTest() { @Test fun runTest() {
val packet = MsgHistoryEvents_v2(injector, 0) val packet = MsgHistoryEventsV2(injector, 0)
// test message decoding // test message decoding
val array = createArray(100, 2) val array = createArray(100, 2)

View file

@ -11,7 +11,6 @@ import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.TemporaryBasalStorage import info.nightscout.androidaps.plugins.pump.common.bolusInfo.TemporaryBasalStorage
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
@ -85,10 +84,16 @@ open class DanaRSPacketAPSHistoryEvents(
// sometimes TB is marked as canceled immediately // sometimes TB is marked as canceled immediately
// but on pump is running // but on pump is running
// at least on Model: 05 Protocol: 10 Code: 10 // at least on Model: 05 Protocol: 10 Code: 10
if (index > 0 && recordCode(message) == DanaPump.TEMPSTOP) { if (index > 0 && recordCode(message) == DanaPump.HistoryEntry.TEMP_STOP.value) {
val previous = sorted[index - 1] val previous = sorted[index - 1]
if (recordCode(previous) == DanaPump.TEMPSTART && dateTime(message) == dateTime(previous)) { if (recordCode(previous) == DanaPump.HistoryEntry.TEMP_START.value && dateTime(message) == dateTime
aapsLogger.debug(LTag.PUMPCOMM, "SKIPPING EVENT TEMPSTOP (" + recordCode(message) + ") " + dateUtil.dateAndTimeString(dateTime(message)) + " (" + dateTime(message) + ")") (previous)
) {
aapsLogger.debug(
LTag.PUMPCOMM,
"SKIPPING EVENT TEMP_STOP (" + recordCode(message) + ") "
+ dateUtil.dateAndTimeString(dateTime(message)) + " (" + dateTime(message) + ")"
)
continue continue
} }
} }
@ -127,8 +132,8 @@ open class DanaRSPacketAPSHistoryEvents(
pumpId = datetime * 2 + id pumpId = datetime * 2 + id
} }
val status: String val status: String
when (recordCode) { when (DanaPump.HistoryEntry.fromInt(recordCode)) {
DanaPump.TEMPSTART -> { DanaPump.HistoryEntry.TEMP_START -> {
val temporaryBasalInfo = temporaryBasalStorage.findTemporaryBasal(datetime, param1.toDouble()) val temporaryBasalInfo = temporaryBasalStorage.findTemporaryBasal(datetime, param1.toDouble())
val newRecord = pumpSync.syncTemporaryBasalWithPumpId( val newRecord = pumpSync.syncTemporaryBasalWithPumpId(
timestamp = datetime, timestamp = datetime,
@ -138,22 +143,30 @@ open class DanaRSPacketAPSHistoryEvents(
type = temporaryBasalInfo?.type, type = temporaryBasalInfo?.type,
pumpId = pumpId, pumpId = pumpId,
pumpType = danaPump.pumpType(), pumpType = danaPump.pumpType(),
pumpSerial = danaPump.serialNumber) pumpSerial = danaPump.serialNumber
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + (if (newRecord) "**NEW** " else "") + "EVENT TEMPSTART (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Ratio: " + param1 + "% Duration: " + param2 + "min") )
status = "TEMPSTART " + dateUtil.timeString(datetime) aapsLogger.debug(
LTag.PUMPCOMM,
"[$pumpId] ${if (newRecord) "**NEW** " else ""}EVENT TEMP_START ($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime) Ratio: $param1% Duration: ${param2}min"
)
status = "TEMP_START " + dateUtil.timeString(datetime)
} }
DanaPump.TEMPSTOP -> { DanaPump.HistoryEntry.TEMP_STOP -> {
val newRecord = pumpSync.syncStopTemporaryBasalWithPumpId( val newRecord = pumpSync.syncStopTemporaryBasalWithPumpId(
timestamp = datetime, timestamp = datetime,
endPumpId = pumpId, endPumpId = pumpId,
pumpType = danaPump.pumpType(), pumpType = danaPump.pumpType(),
pumpSerial = danaPump.serialNumber) pumpSerial = danaPump.serialNumber
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + (if (newRecord) "**NEW** " else "") + "EVENT TEMPSTOP (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")") )
status = "TEMPSTOP " + dateUtil.timeString(datetime) aapsLogger.debug(
LTag.PUMPCOMM,
"[$pumpId] ${if (newRecord) "**NEW** " else ""}EVENT TEMP_STOP ($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime)"
)
status = "TEMP_STOP " + dateUtil.timeString(datetime)
} }
DanaPump.EXTENDEDSTART -> { DanaPump.HistoryEntry.EXTENDED_START -> {
val newRecord = pumpSync.syncExtendedBolusWithPumpId( val newRecord = pumpSync.syncExtendedBolusWithPumpId(
timestamp = datetime, timestamp = datetime,
amount = param1 / 100.0, amount = param1 / 100.0,
@ -161,22 +174,30 @@ open class DanaRSPacketAPSHistoryEvents(
isEmulatingTB = false, isEmulatingTB = false,
pumpId = pumpId, pumpId = pumpId,
pumpType = danaPump.pumpType(), pumpType = danaPump.pumpType(),
pumpSerial = danaPump.serialNumber) pumpSerial = danaPump.serialNumber
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + (if (newRecord) "**NEW** " else "") + "EVENT EXTENDEDSTART (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min") )
status = "EXTENDEDSTART " + dateUtil.timeString(datetime) aapsLogger.debug(
LTag.PUMPCOMM,
"[$pumpId] ${if (newRecord) "**NEW** " else ""}EVENT EXTENDED_START ($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime) Amount: ${param1 / 100.0}U Duration: ${param2}min"
)
status = "EXTENDED_START " + dateUtil.timeString(datetime)
} }
DanaPump.EXTENDEDSTOP -> { DanaPump.HistoryEntry.EXTENDED_STOP -> {
val newRecord = pumpSync.syncStopExtendedBolusWithPumpId( val newRecord = pumpSync.syncStopExtendedBolusWithPumpId(
timestamp = datetime, timestamp = datetime,
endPumpId = pumpId, endPumpId = pumpId,
pumpType = danaPump.pumpType(), pumpType = danaPump.pumpType(),
pumpSerial = danaPump.serialNumber) pumpSerial = danaPump.serialNumber
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + (if (newRecord) "**NEW** " else "") + "EVENT EXTENDEDSTOP (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min") )
status = "EXTENDEDSTOP " + dateUtil.timeString(datetime) aapsLogger.debug(
LTag.PUMPCOMM,
"[$pumpId] ${if (newRecord) "**NEW** " else ""}EVENT EXTENDED_STOP ($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime) Delivered: ${param1 / 100.0}U RealDuration: ${param2}min"
)
status = "EXTENDED_STOP " + dateUtil.timeString(datetime)
} }
DanaPump.BOLUS -> { DanaPump.HistoryEntry.BOLUS -> {
val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0) val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0)
val newRecord = pumpSync.syncBolusWithPumpId( val newRecord = pumpSync.syncBolusWithPumpId(
timestamp = datetime, timestamp = datetime,
@ -184,12 +205,16 @@ open class DanaRSPacketAPSHistoryEvents(
type = detailedBolusInfo?.bolusType, type = detailedBolusInfo?.bolusType,
pumpId = pumpId, pumpId = pumpId,
pumpType = danaPump.pumpType(), pumpType = danaPump.pumpType(),
pumpSerial = danaPump.serialNumber) pumpSerial = danaPump.serialNumber
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + (if (newRecord) "**NEW** " else "") + "EVENT BOLUS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U ") )
aapsLogger.debug(
LTag.PUMPCOMM,
"[$pumpId] ${if (newRecord) "**NEW** " else ""}EVENT BOLUS ($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime) Bolus: ${param1 / 100.0}U "
)
status = "BOLUS " + dateUtil.timeString(datetime) status = "BOLUS " + dateUtil.timeString(datetime)
} }
DanaPump.DUALBOLUS -> { DanaPump.HistoryEntry.DUAL_BOLUS -> {
val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0) val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0)
val newRecord = pumpSync.syncBolusWithPumpId( val newRecord = pumpSync.syncBolusWithPumpId(
timestamp = datetime, timestamp = datetime,
@ -197,12 +222,16 @@ open class DanaRSPacketAPSHistoryEvents(
type = detailedBolusInfo?.bolusType, type = detailedBolusInfo?.bolusType,
pumpId = pumpId, pumpId = pumpId,
pumpType = danaPump.pumpType(), pumpType = danaPump.pumpType(),
pumpSerial = danaPump.serialNumber) pumpSerial = danaPump.serialNumber
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + (if (newRecord) "**NEW** " else "") + "EVENT DUALBOLUS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min") )
status = "DUALBOLUS " + dateUtil.timeString(datetime) aapsLogger.debug(
LTag.PUMPCOMM,
"[$pumpId] ${if (newRecord) "**NEW** " else ""}EVENT DUAL_BOLUS ($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime) Bolus: ${param1 / 100.0}U Duration: ${param2}min"
)
status = "DUAL_BOLUS " + dateUtil.timeString(datetime)
} }
DanaPump.DUALEXTENDEDSTART -> { DanaPump.HistoryEntry.DUAL_EXTENDED_START -> {
val newRecord = pumpSync.syncExtendedBolusWithPumpId( val newRecord = pumpSync.syncExtendedBolusWithPumpId(
timestamp = datetime, timestamp = datetime,
amount = param1 / 100.0, amount = param1 / 100.0,
@ -210,32 +239,46 @@ open class DanaRSPacketAPSHistoryEvents(
isEmulatingTB = false, isEmulatingTB = false,
pumpId = pumpId, pumpId = pumpId,
pumpType = danaPump.pumpType(), pumpType = danaPump.pumpType(),
pumpSerial = danaPump.serialNumber) pumpSerial = danaPump.serialNumber
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + (if (newRecord) "**NEW** " else "") + "EVENT DUALEXTENDEDSTART (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min") )
status = "DUALEXTENDEDSTART " + dateUtil.timeString(datetime) aapsLogger.debug(
LTag.PUMPCOMM,
"[$pumpId] ${if (newRecord) "**NEW** " else ""}EVENT DUAL_EXTENDED_START ($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime) Amount: ${param1 / 100.0}U Duration: ${param2}min"
)
status = "DUAL_EXTENDED_START " + dateUtil.timeString(datetime)
} }
DanaPump.DUALEXTENDEDSTOP -> { DanaPump.HistoryEntry.DUAL_EXTENDED_STOP -> {
val newRecord = pumpSync.syncStopExtendedBolusWithPumpId( val newRecord = pumpSync.syncStopExtendedBolusWithPumpId(
timestamp = datetime, timestamp = datetime,
endPumpId = pumpId, endPumpId = pumpId,
pumpType = danaPump.pumpType(), pumpType = danaPump.pumpType(),
pumpSerial = danaPump.serialNumber) pumpSerial = danaPump.serialNumber
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + (if (newRecord) "**NEW** " else "") + "EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min") )
status = "DUALEXTENDEDSTOP " + dateUtil.timeString(datetime) aapsLogger.debug(
LTag.PUMPCOMM,
"[$pumpId] ${if (newRecord) "**NEW** " else ""}EVENT DUAL_EXTENDED_STOP ($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime) Delivered: ${param1 / 100.0}U RealDuration: ${param2}min"
)
status = "DUAL_EXTENDED_STOP " + dateUtil.timeString(datetime)
} }
DanaPump.SUSPENDON -> { DanaPump.HistoryEntry.SUSPEND_ON -> {
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + "EVENT SUSPENDON (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")") aapsLogger.debug(
status = "SUSPENDON " + dateUtil.timeString(datetime) LTag.PUMPCOMM,
"[$pumpId] EVENT SUSPEND_ON ($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime)"
)
status = "SUSPEND_ON " + dateUtil.timeString(datetime)
} }
DanaPump.SUSPENDOFF -> { DanaPump.HistoryEntry.SUSPEND_OFF -> {
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + "EVENT SUSPENDOFF (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")") aapsLogger.debug(
status = "SUSPENDOFF " + dateUtil.timeString(datetime) LTag.PUMPCOMM,
"[$pumpId] EVENT SUSPEND_OFF ($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime)"
)
status = "SUSPEND_OFF " + dateUtil.timeString(datetime)
} }
DanaPump.REFILL -> { DanaPump.HistoryEntry.REFILL -> {
if (sp.getBoolean(R.string.key_rs_loginsulinchange, true)) { if (sp.getBoolean(R.string.key_rs_loginsulinchange, true)) {
val newRecord = pumpSync.insertTherapyEventIfNewWithTimestamp( val newRecord = pumpSync.insertTherapyEventIfNewWithTimestamp(
timestamp = datetime, timestamp = datetime,
@ -244,33 +287,46 @@ open class DanaRSPacketAPSHistoryEvents(
pumpType = danaPump.pumpType(), pumpType = danaPump.pumpType(),
pumpSerial = danaPump.serialNumber pumpSerial = danaPump.serialNumber
) )
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + (if (newRecord) "**NEW** " else "") + "EVENT REFILL (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") aapsLogger.debug(
LTag.PUMPCOMM,
"[$pumpId] ${if (newRecord) "**NEW** " else ""}EVENT REFILL ($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime) Amount: ${param1 / 100.0}U"
)
} }
status = "REFILL " + dateUtil.timeString(datetime) status = "REFILL " + dateUtil.timeString(datetime)
} }
DanaPump.PRIME -> { DanaPump.HistoryEntry.PRIME -> {
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + "EVENT PRIME (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") aapsLogger.debug(
LTag.PUMPCOMM,
"[$pumpId] EVENT PRIME ($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime) Amount: ${param1 / 100.0}U"
)
status = "PRIME " + dateUtil.timeString(datetime) status = "PRIME " + dateUtil.timeString(datetime)
} }
DanaPump.PROFILECHANGE -> { DanaPump.HistoryEntry.PROFILE_CHANGE -> {
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + "EVENT PROFILECHANGE (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " No: " + param1 + " CurrentRate: " + param2 / 100.0 + "U/h") aapsLogger.debug(
status = "PROFILECHANGE " + dateUtil.timeString(datetime) LTag.PUMPCOMM,
"[$pumpId] EVENT PROFILE_CHANGE ($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime) No: $param1 CurrentRate: ${param2 / 100.0}U/h"
)
status = "PROFILE_CHANGE " + dateUtil.timeString(datetime)
} }
DanaPump.CARBS -> { DanaPump.HistoryEntry.CARBS -> {
val newRecord = pumpSync.syncCarbsWithTimestamp( val newRecord = pumpSync.syncCarbsWithTimestamp(
timestamp = datetime, timestamp = datetime,
amount = param1.toDouble(), amount = param1.toDouble(),
pumpId = pumpId, pumpId = pumpId,
pumpType = danaPump.pumpType(), pumpType = danaPump.pumpType(),
pumpSerial = danaPump.serialNumber) pumpSerial = danaPump.serialNumber
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + (if (newRecord) "**NEW** " else "") + "EVENT CARBS (" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g") )
aapsLogger.debug(
LTag.PUMPCOMM,
"[$pumpId] ${if (newRecord) "**NEW** " else ""}EVENT CARBS ($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime) Carbs: ${param1}g"
)
status = "CARBS " + dateUtil.timeString(datetime) status = "CARBS " + dateUtil.timeString(datetime)
} }
DanaPump.PRIMECANNULA -> { DanaPump.HistoryEntry.PRIME_CANNULA -> {
if (sp.getBoolean(R.string.key_rs_logcanulachange, true)) { if (sp.getBoolean(R.string.key_rs_logcanulachange, true)) {
val newRecord = pumpSync.insertTherapyEventIfNewWithTimestamp( val newRecord = pumpSync.insertTherapyEventIfNewWithTimestamp(
timestamp = datetime, timestamp = datetime,
@ -279,19 +335,28 @@ open class DanaRSPacketAPSHistoryEvents(
pumpType = danaPump.pumpType(), pumpType = danaPump.pumpType(),
pumpSerial = danaPump.serialNumber pumpSerial = danaPump.serialNumber
) )
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + (if (newRecord) "**NEW** " else "") + "EVENT PRIMECANNULA(" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U") aapsLogger.debug(
LTag.PUMPCOMM,
"[$pumpId] ${if (newRecord) "**NEW** " else ""}EVENT PRIME_CANNULA($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime) Amount: ${param1 / 100.0}U"
)
} }
status = "PRIMECANNULA " + dateUtil.timeString(datetime) status = "PRIME_CANNULA " + dateUtil.timeString(datetime)
} }
DanaPump.TIMECHANGE -> { DanaPump.HistoryEntry.TIME_CHANGE -> {
val oldDateTime = intFromBuffMsbLsb(data, 7, 4) * 1000L val oldDateTime = intFromBuffMsbLsb(data, 7, 4) * 1000L
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + "EVENT TIMECHANGE(" + recordCode + ") " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Previous: " + dateUtil.dateAndTimeString(oldDateTime)) aapsLogger.debug(
status = "TIMECHANGE " + dateUtil.timeString(datetime) LTag.PUMPCOMM,
"[$pumpId] EVENT TIME_CHANGE($recordCode) ${dateUtil.dateAndTimeString(datetime)} ($datetime) Previous: ${dateUtil.dateAndTimeString(oldDateTime)}"
)
status = "TIME_CHANGE " + dateUtil.timeString(datetime)
} }
else -> { else -> {
aapsLogger.debug(LTag.PUMPCOMM, "[" + pumpId + "] " + "Event: " + recordCode + " " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2) aapsLogger.debug(
LTag.PUMPCOMM,
"[$pumpId] Event: $recordCode ${dateUtil.dateAndTimeString(datetime)} ($datetime) Param1: $param1 Param2: $param2"
)
status = "UNKNOWN " + dateUtil.timeString(datetime) status = "UNKNOWN " + dateUtil.timeString(datetime)
} }
} }

View file

@ -20,7 +20,7 @@ class DanaRSPacketAPSSetEventHistory(
init { init {
opCode = BleEncryption.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY opCode = BleEncryption.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY
if ((packetType == DanaPump.CARBS || packetType == DanaPump.BOLUS) && param1 <= 0) this.param1 = 0 if ((packetType == DanaPump.HistoryEntry.CARBS.value || packetType == DanaPump.HistoryEntry.BOLUS.value) && param1 <= 0) param1 = 0
aapsLogger.debug(LTag.PUMPCOMM, "Set history entry: " + dateUtil.dateAndTimeString(time) + " type: " + packetType + " param1: " + param1 + " param2: " + param2) aapsLogger.debug(LTag.PUMPCOMM, "Set history entry: " + dateUtil.dateAndTimeString(time) + " type: " + packetType + " param1: " + param1 + " param2: " + param2)
} }

View file

@ -16,7 +16,6 @@ import info.nightscout.androidaps.dana.events.EventDanaRNewStatus
import info.nightscout.androidaps.danars.DanaRSPlugin import info.nightscout.androidaps.danars.DanaRSPlugin
import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.danars.R
import info.nightscout.androidaps.danars.comm.* import info.nightscout.androidaps.danars.comm.*
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.dialogs.BolusProgressDialog import info.nightscout.androidaps.dialogs.BolusProgressDialog
import info.nightscout.androidaps.events.EventAppExit import info.nightscout.androidaps.events.EventAppExit
@ -25,6 +24,7 @@ import info.nightscout.androidaps.events.EventProfileSwitchChanged
import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.events.EventPumpStatusChanged
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
@ -44,6 +44,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.plusAssign
import org.joda.time.DateTime import org.joda.time.DateTime
import org.joda.time.DateTimeZone import org.joda.time.DateTimeZone
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -79,11 +80,10 @@ class DanaRSService : DaggerService() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
disposable.add(rxBus disposable += rxBus
.toObservable(EventAppExit::class.java) .toObservable(EventAppExit::class.java)
.observeOn(aapsSchedulers.io) .observeOn(aapsSchedulers.io)
.subscribe({ stopSelf() }, fabricPrivacy::logException) .subscribe({ stopSelf() }, fabricPrivacy::logException)
)
} }
override fun onDestroy() { override fun onDestroy() {
@ -204,7 +204,12 @@ class DanaRSService : DaggerService() {
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
val reportFail = Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT) val reportFail = Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT)
rxBus.send(EventNewNotification(reportFail)) rxBus.send(EventNewNotification(reportFail))
pumpSync.insertAnnouncement(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaPump.dailyTotalUnits + "/" + danaPump.maxDailyTotalUnits + "U", null, danaPump.pumpType(), danaPump.serialNumber) pumpSync.insertAnnouncement(
resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaPump.dailyTotalUnits + "/" + danaPump.maxDailyTotalUnits + "U",
null,
danaPump.pumpType(),
danaPump.serialNumber
)
lastApproachingDailyLimit = System.currentTimeMillis() lastApproachingDailyLimit = System.currentTimeMillis()
} }
} }
@ -260,7 +265,7 @@ class DanaRSService : DaggerService() {
if (carbs > 0) { if (carbs > 0) {
// MsgSetCarbsEntry msg = new MsgSetCarbsEntry(carbTime, carbs); #### // MsgSetCarbsEntry msg = new MsgSetCarbsEntry(carbTime, carbs); ####
// sendMessage(msg); // sendMessage(msg);
val msgSetHistoryEntryV2 = DanaRSPacketAPSSetEventHistory(injector, DanaPump.CARBS, carbTime, carbs, 0) val msgSetHistoryEntryV2 = DanaRSPacketAPSSetEventHistory(injector, DanaPump.HistoryEntry.CARBS.value, carbTime, carbs, 0)
sendMessage(msgSetHistoryEntryV2) sendMessage(msgSetHistoryEntryV2)
danaPump.lastHistoryFetched = min(danaPump.lastHistoryFetched, carbTime - T.mins(1).msecs()) danaPump.lastHistoryFetched = min(danaPump.lastHistoryFetched, carbTime - T.mins(1).msecs())
} }