RS(UTC): update pump IC and ISF too

This commit is contained in:
Milos Kozak 2020-11-07 11:32:07 +01:00
parent dac2241baa
commit 9e5da8aad9
3 changed files with 27 additions and 17 deletions

View file

@ -20,8 +20,8 @@ class DanaRS_Packet_Bolus_Get_24_CIR_CF_Array(
override fun handleMessage(data: ByteArray) { override fun handleMessage(data: ByteArray) {
danaPump.units = byteArrayToInt(getBytes(data, DATA_START, 1)) danaPump.units = byteArrayToInt(getBytes(data, DATA_START, 1))
for (i in 0 .. 23) { for (i in 0 .. 23) {
val cf = byteArrayToInt(getBytes(data, DATA_START + 1 + 2 * i, 2)).toDouble() val cir = byteArrayToInt(getBytes(data, DATA_START + 1 + 2 * i, 2)).toDouble()
val cir = if (danaPump.units == DanaPump.UNITS_MGDL) val cf = if (danaPump.units == DanaPump.UNITS_MGDL)
byteArrayToInt(getBytes(data, DATA_START + 1 + 48 + 2 * i, 2)).toDouble() byteArrayToInt(getBytes(data, DATA_START + 1 + 48 + 2 * i, 2)).toDouble()
else else
byteArrayToInt(getBytes(data, DATA_START + 1 + 48 + 2 * i, 2)) / 100.0 byteArrayToInt(getBytes(data, DATA_START + 1 + 48 + 2 * i, 2)) / 100.0

View file

@ -1,11 +1,13 @@
package info.nightscout.androidaps.danars.comm package info.nightscout.androidaps.danars.comm
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.dana.DanaPump
import info.nightscout.androidaps.danars.encryption.BleEncryption import info.nightscout.androidaps.danars.encryption.BleEncryption
import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import javax.inject.Inject import javax.inject.Inject
import kotlin.math.round
class DanaRS_Packet_Bolus_Set_24_CIR_CF_Array( class DanaRS_Packet_Bolus_Set_24_CIR_CF_Array(
injector: HasAndroidInjector, injector: HasAndroidInjector,
@ -25,12 +27,15 @@ class DanaRS_Packet_Bolus_Set_24_CIR_CF_Array(
val cfStart = 24 * 2 val cfStart = 24 * 2
for (i in 0..23) { for (i in 0..23) {
var isf = profile.getIsfMgdlTimeFromMidnight(i * 3600) var isf = profile.getIsfMgdlTimeFromMidnight(i * 3600)
if (danaPump.units == DanaPump.UNITS_MMOL) isf *= 10 if (danaPump.units == DanaPump.UNITS_MMOL) {
val ic = profile.getIcTimeFromMidnight(i * 3600) * 100 isf = Profile.fromMgdlToUnits(isf, Constants.MMOL)
request[2 * i] = (isf.toInt() and 0xff).toByte() isf *= 100
request[2 * i] = (isf.toInt() ushr 8 and 0xff).toByte() }
request[cfStart + 2 * i] = (ic.toInt() and 0xff).toByte() val ic = profile.getIcTimeFromMidnight(i * 3600)
request[cfStart + 2 * i] = (ic.toInt() ushr 8 and 0xff).toByte() request[2 * i] = (round(ic).toInt() and 0xff).toByte()
request[2 * i + 1] = (round(ic).toInt() ushr 8 and 0xff).toByte()
request[cfStart + 2 * i] = (round(isf).toInt() and 0xff).toByte()
request[cfStart + 2 * i + 1] = (round(isf).toInt() ushr 8 and 0xff).toByte()
} }
return request return request
} }

View file

@ -11,6 +11,7 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.dana.DanaPump
import info.nightscout.androidaps.dana.comm.RecordTypes
import info.nightscout.androidaps.dana.events.EventDanaRNewStatus 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
@ -411,6 +412,10 @@ class DanaRSService : DaggerService() {
sendMessage(msgSet) sendMessage(msgSet)
val msgActivate = DanaRS_Packet_Basal_Set_Profile_Number(injector, 0) val msgActivate = DanaRS_Packet_Basal_Set_Profile_Number(injector, 0)
sendMessage(msgActivate) sendMessage(msgActivate)
if (danaPump.profile24) {
val msgProfile = DanaRS_Packet_Bolus_Set_24_CIR_CF_Array(injector, profile)
sendMessage(msgProfile)
}
readPumpStatus() readPumpStatus()
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
return true return true
@ -421,15 +426,15 @@ class DanaRSService : DaggerService() {
if (!isConnected) return result if (!isConnected) return result
var msg: DanaRS_Packet_History_? = null var msg: DanaRS_Packet_History_? = null
when (type) { when (type) {
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_ALARM -> msg = DanaRS_Packet_History_Alarm(injector) RecordTypes.RECORD_TYPE_ALARM -> msg = DanaRS_Packet_History_Alarm(injector)
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_PRIME -> msg = DanaRS_Packet_History_Prime(injector) RecordTypes.RECORD_TYPE_PRIME -> msg = DanaRS_Packet_History_Prime(injector)
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_BASALHOUR -> msg = DanaRS_Packet_History_Basal(injector) RecordTypes.RECORD_TYPE_BASALHOUR -> msg = DanaRS_Packet_History_Basal(injector)
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_BOLUS -> msg = DanaRS_Packet_History_Bolus(injector) RecordTypes.RECORD_TYPE_BOLUS -> msg = DanaRS_Packet_History_Bolus(injector)
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_CARBO -> msg = DanaRS_Packet_History_Carbohydrate(injector) RecordTypes.RECORD_TYPE_CARBO -> msg = DanaRS_Packet_History_Carbohydrate(injector)
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_DAILY -> msg = DanaRS_Packet_History_Daily(injector) RecordTypes.RECORD_TYPE_DAILY -> msg = DanaRS_Packet_History_Daily(injector)
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_GLUCOSE -> msg = DanaRS_Packet_History_Blood_Glucose(injector) RecordTypes.RECORD_TYPE_GLUCOSE -> msg = DanaRS_Packet_History_Blood_Glucose(injector)
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_REFILL -> msg = DanaRS_Packet_History_Refill(injector) RecordTypes.RECORD_TYPE_REFILL -> msg = DanaRS_Packet_History_Refill(injector)
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_SUSPEND -> msg = DanaRS_Packet_History_Suspend(injector) RecordTypes.RECORD_TYPE_SUSPEND -> msg = DanaRS_Packet_History_Suspend(injector)
} }
if (msg != null) { if (msg != null) {
sendMessage(DanaRS_Packet_General_Set_History_Upload_Mode(injector, 1)) sendMessage(DanaRS_Packet_General_Set_History_Upload_Mode(injector, 1))