StringUtils -> kt

This commit is contained in:
Milos Kozak 2021-12-13 17:31:48 +01:00
parent 78c3810226
commit 946081fb0e
5 changed files with 129 additions and 99 deletions

View file

@ -1,17 +1,16 @@
package info.nightscout.androidaps.plugins.general.tidepool.messages package info.nightscout.androidaps.plugins.general.tidepool.messages
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.utils.StringUtils
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import okhttp3.Credentials import okhttp3.Credentials
class AuthRequestMessage : BaseMessage() { object AuthRequestMessage : BaseMessage() {
companion object {
fun getAuthRequestHeader(sp: SP): String? { fun getAuthRequestHeader(sp: SP): String? {
val username = sp.getStringOrNull(R.string.key_tidepool_username, null) val username = sp.getStringOrNull(R.string.key_tidepool_username, null)
val password = sp.getStringOrNull(R.string.key_tidepool_password, null) val password = sp.getStringOrNull(R.string.key_tidepool_password, null)
return if (StringUtils.emptyString(username) || StringUtils.emptyString(password)) null else Credentials.basic(username!!.trim { it <= ' ' }, password!!) return if (username.isNullOrEmpty() || password.isNullOrEmpty()) null
} else Credentials.basic(username.trim { it <= ' ' }, password)
} }
} }

View file

@ -1,20 +0,0 @@
package info.nightscout.androidaps.utils;
/**
* class contains useful String functions
*/
public class StringUtils {
public static String removeSurroundingQuotes(String string) {
if (string.length() >= 2 && string.charAt(0) == '"'
&& string.charAt(string.length() - 1) == '"') {
string = string.substring(1, string.length() - 1);
}
return string;
}
public static boolean emptyString(final String str) {
return str == null || str.length() == 0;
}
}

View file

@ -0,0 +1,15 @@
package info.nightscout.androidaps.utils
/**
* class contains useful String functions
*/
object StringUtils {
fun removeSurroundingQuotes(input: String): String {
var string = input
if (string.length >= 2 && string[0] == '"' && string[string.length - 1] == '"') {
string = string.substring(1, string.length - 1)
}
return string
}
}

View file

@ -4,9 +4,8 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.diaconn.DiaconnG8Pump import info.nightscout.androidaps.diaconn.DiaconnG8Pump
import info.nightscout.androidaps.diaconn.R import info.nightscout.androidaps.diaconn.R
import info.nightscout.androidaps.diaconn.pumplog.PumplogUtil import info.nightscout.androidaps.diaconn.pumplog.PumplogUtil
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.utils.StringUtils
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.shared.logging.LTag
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import javax.inject.Inject import javax.inject.Inject
@ -40,7 +39,7 @@ class BasalLimitInquireResponsePacket(injector: HasAndroidInjector) : DiaconnG8P
} }
diaconnG8Pump.maxBasalPerHours = getShortToInt(bufferData).toDouble() / 100.0 // not include tempbasal limit diaconnG8Pump.maxBasalPerHours = getShortToInt(bufferData).toDouble() / 100.0 // not include tempbasal limit
val pumpFirmwareVersion = sp.getString(rh.gs(R.string.pumpversion), "") val pumpFirmwareVersion = sp.getString(rh.gs(R.string.pumpversion), "")
if(!StringUtils.emptyString(pumpFirmwareVersion) && PumplogUtil.isPumpVersionGe(pumpFirmwareVersion, 3, 0)) { if(pumpFirmwareVersion.isNotEmpty() && PumplogUtil.isPumpVersionGe(pumpFirmwareVersion, 3, 0)) {
diaconnG8Pump.maxBasal = diaconnG8Pump.maxBasalPerHours * 2.5 // include tempbasal diaconnG8Pump.maxBasal = diaconnG8Pump.maxBasalPerHours * 2.5 // include tempbasal
} else { } else {
diaconnG8Pump.maxBasal = diaconnG8Pump.maxBasalPerHours * 2.0 // include tempbasal diaconnG8Pump.maxBasal = diaconnG8Pump.maxBasalPerHours * 2.0 // include tempbasal

View file

@ -27,8 +27,6 @@ import info.nightscout.androidaps.interfaces.CommandQueue
import info.nightscout.androidaps.interfaces.Profile 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.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
@ -40,8 +38,9 @@ import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.queue.commands.Command import info.nightscout.androidaps.queue.commands.Command
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.StringUtils
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
@ -54,6 +53,7 @@ import kotlin.math.ceil
import kotlin.math.min import kotlin.math.min
class DiaconnG8Service : DaggerService() { class DiaconnG8Service : DaggerService() {
@Inject lateinit var injector: HasAndroidInjector @Inject lateinit var injector: HasAndroidInjector
@Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var rxBus: RxBus @Inject lateinit var rxBus: RxBus
@ -62,7 +62,7 @@ class DiaconnG8Service : DaggerService() {
@Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var commandQueue: CommandQueue @Inject lateinit var commandQueue: CommandQueue
@Inject lateinit var context: Context @Inject lateinit var context: Context
@Inject lateinit var diaconnG8Plugin : DiaconnG8Plugin @Inject lateinit var diaconnG8Plugin: DiaconnG8Plugin
@Inject lateinit var diaconnG8Pump: DiaconnG8Pump @Inject lateinit var diaconnG8Pump: DiaconnG8Pump
@Inject lateinit var diaconnG8ResponseMessageHashTable: DiaconnG8ResponseMessageHashTable @Inject lateinit var diaconnG8ResponseMessageHashTable: DiaconnG8ResponseMessageHashTable
@Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var activePlugin: ActivePlugin
@ -87,6 +87,7 @@ class DiaconnG8Service : DaggerService() {
} }
inner class LocalBinder : Binder() { inner class LocalBinder : Binder() {
val serviceInstance: DiaconnG8Service val serviceInstance: DiaconnG8Service
get() = this@DiaconnG8Service get() = this@DiaconnG8Service
} }
@ -135,9 +136,9 @@ class DiaconnG8Service : DaggerService() {
val pump = activePlugin.activePump val pump = activePlugin.activePump
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.gettingpumpsettings))) rxBus.send(EventPumpStatusChanged(rh.gs(R.string.gettingpumpsettings)))
val pumpFirmwareVersion = sp.getString(rh.gs(R.string.pumpversion),"") val pumpFirmwareVersion = sp.getString(rh.gs(R.string.pumpversion), "")
if(!StringUtils.emptyString(pumpFirmwareVersion) && PumplogUtil.isPumpVersionGe(pumpFirmwareVersion, 3, 0)) { if (pumpFirmwareVersion.isNotEmpty() && PumplogUtil.isPumpVersionGe(pumpFirmwareVersion, 3, 0)) {
sendMessage(BigAPSMainInfoInquirePacket(injector)) // APS Pump Main Info sendMessage(BigAPSMainInfoInquirePacket(injector)) // APS Pump Main Info
} else { } else {
sendMessage(BasalLimitInquirePacket(injector)) // basal Limit sendMessage(BasalLimitInquirePacket(injector)) // basal Limit
@ -182,7 +183,6 @@ class DiaconnG8Service : DaggerService() {
//If time-diff is very large, warn user until we can synchronize history readings properly //If time-diff is very large, warn user until we can synchronize history readings properly
ErrorHelperActivity.runAlarm(context, rh.gs(R.string.largetimediff), rh.gs(R.string.largetimedifftitle), R.raw.error) ErrorHelperActivity.runAlarm(context, rh.gs(R.string.largetimediff), rh.gs(R.string.largetimedifftitle), R.raw.error)
//de-initialize pump //de-initialize pump
diaconnG8Pump.reset() diaconnG8Pump.reset()
rxBus.send(EventDiaconnG8NewStatus()) rxBus.send(EventDiaconnG8NewStatus())
@ -190,12 +190,12 @@ class DiaconnG8Service : DaggerService() {
return return
} else { } else {
if(!diaconnG8Pump.isTempBasalInProgress) { if (!diaconnG8Pump.isTempBasalInProgress) {
val msgPacket = TimeSettingPacket(injector, dateUtil.now(), offset) val msgPacket = TimeSettingPacket(injector, dateUtil.now(), offset)
sendMessage(msgPacket) sendMessage(msgPacket)
// otp process // otp process
if(!processConfirm(msgPacket.msgType)) return if (!processConfirm(msgPacket.msgType)) return
timeDiff = (diaconnG8Pump.getPumpTime() - System.currentTimeMillis()) / 1000L timeDiff = (diaconnG8Pump.getPumpTime() - System.currentTimeMillis()) / 1000L
aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: $timeDiff seconds") aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: $timeDiff seconds")
@ -215,7 +215,12 @@ class DiaconnG8Service : DaggerService() {
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
val reportFail = Notification(Notification.APPROACHING_DAILY_LIMIT, rh.gs(R.string.approachingdailylimit), Notification.URGENT) val reportFail = Notification(Notification.APPROACHING_DAILY_LIMIT, rh.gs(R.string.approachingdailylimit), Notification.URGENT)
rxBus.send(EventNewNotification(reportFail)) rxBus.send(EventNewNotification(reportFail))
pumpSync.insertAnnouncement(rh.gs(R.string.approachingdailylimit) + ": " + diaconnG8Pump.dailyTotalUnits + "/" + diaconnG8Pump.maxDailyTotalUnits + "U", null, PumpType.DIACONN_G8, diaconnG8Pump.serialNo.toString()) pumpSync.insertAnnouncement(
rh.gs(R.string.approachingdailylimit) + ": " + diaconnG8Pump.dailyTotalUnits + "/" + diaconnG8Pump.maxDailyTotalUnits + "U",
null,
PumpType.DIACONN_G8,
diaconnG8Pump.serialNo.toString()
)
lastApproachingDailyLimit = System.currentTimeMillis() lastApproachingDailyLimit = System.currentTimeMillis()
} }
} }
@ -234,7 +239,7 @@ class DiaconnG8Service : DaggerService() {
sendMessage(LogStatusInquirePacket(injector)) sendMessage(LogStatusInquirePacket(injector))
// pump version check // pump version check
if(diaconnG8Pump.isPumpVersionGe2_63) { if (diaconnG8Pump.isPumpVersionGe2_63) {
sendMessage(IncarnationInquirePacket(injector)) sendMessage(IncarnationInquirePacket(injector))
} }
@ -250,18 +255,18 @@ class DiaconnG8Service : DaggerService() {
var apsLastLogNum = sp.getInt(rh.gs(R.string.apslastLogNum), 0) var apsLastLogNum = sp.getInt(rh.gs(R.string.apslastLogNum), 0)
// if first install app // if first install app
if(apsWrappingCount == 0 && apsLastLogNum == 0 ) { if (apsWrappingCount == 0 && apsLastLogNum == 0) {
pumpLogDefaultSetting() pumpLogDefaultSetting()
} }
// if pump reset // if pump reset
if(apsIncarnationNum != diaconnG8Pump.pumpIncarnationNum) { if (apsIncarnationNum != diaconnG8Pump.pumpIncarnationNum) {
pumpLogDefaultSetting() pumpLogDefaultSetting()
sp.putInt(rh.gs(R.string.apsIncarnationNo), diaconnG8Pump.pumpIncarnationNum) sp.putInt(rh.gs(R.string.apsIncarnationNo), diaconnG8Pump.pumpIncarnationNum)
} }
// if another pump // if another pump
if(pumpSerialNo != diaconnG8Pump.serialNo) { if (pumpSerialNo != diaconnG8Pump.serialNo) {
pumpLogDefaultSetting() pumpLogDefaultSetting()
sp.putInt(rh.gs(R.string.pumpserialno), diaconnG8Pump.serialNo) sp.putInt(rh.gs(R.string.pumpserialno), diaconnG8Pump.serialNo)
} }
@ -270,12 +275,12 @@ class DiaconnG8Service : DaggerService() {
apsLastLogNum = sp.getInt(rh.gs(R.string.apslastLogNum), 0) apsLastLogNum = sp.getInt(rh.gs(R.string.apslastLogNum), 0)
val apsLastNum = apsWrappingCount * 10000 + apsLastLogNum val apsLastNum = apsWrappingCount * 10000 + apsLastLogNum
if((pumpWrappingCount * 10000 + pumpLastNum) < apsLastLogNum ) { if ((pumpWrappingCount * 10000 + pumpLastNum) < apsLastLogNum) {
pumpLogDefaultSetting() pumpLogDefaultSetting()
} }
val start:Int? // log sync startNo val start: Int? // log sync startNo
val end:Int? // log sync endNo val end: Int? // log sync endNo
if (((pumpWrappingCount * 10000 + pumpLastNum) - apsLastNum) > 10000) { if (((pumpWrappingCount * 10000 + pumpLastNum) - apsLastNum) > 10000) {
start = pumpLastNum start = pumpLastNum
end = 10000 end = 10000
@ -292,7 +297,7 @@ class DiaconnG8Service : DaggerService() {
// pump log loop size // pump log loop size
val pumpLogPageSize = 11 val pumpLogPageSize = 11
val loopCount: Int = ceil (((end - start) / 11.0)).toInt() val loopCount: Int = ceil(((end - start) / 11.0)).toInt()
// log sync start! // log sync start!
if (loopCount > 0) { if (loopCount > 0) {
@ -317,7 +322,7 @@ class DiaconnG8Service : DaggerService() {
fun setUserSettings(): PumpEnactResult { fun setUserSettings(): PumpEnactResult {
val result = PumpEnactResult(injector) val result = PumpEnactResult(injector)
val msg: DiaconnG8Packet = when(diaconnG8Pump.setUserOptionType) { val msg: DiaconnG8Packet = when (diaconnG8Pump.setUserOptionType) {
DiaconnG8Pump.ALARM -> SoundSettingPacket(injector, diaconnG8Pump.beepAndAlarm, diaconnG8Pump.alarmIntesity) DiaconnG8Pump.ALARM -> SoundSettingPacket(injector, diaconnG8Pump.beepAndAlarm, diaconnG8Pump.alarmIntesity)
DiaconnG8Pump.LCD -> DisplayTimeoutSettingPacket(injector, diaconnG8Pump.lcdOnTimeSec) DiaconnG8Pump.LCD -> DisplayTimeoutSettingPacket(injector, diaconnG8Pump.lcdOnTimeSec)
DiaconnG8Pump.LANG -> LanguageSettingPacket(injector, diaconnG8Pump.selectedLanguage) DiaconnG8Pump.LANG -> LanguageSettingPacket(injector, diaconnG8Pump.selectedLanguage)
@ -325,9 +330,9 @@ class DiaconnG8Service : DaggerService() {
else -> null else -> null
} ?: return result.success(false) } ?: return result.success(false)
sendMessage(msg ) sendMessage(msg)
// pump confirm // pump confirm
if(diaconnG8Pump.otpNumber == 0) { if (diaconnG8Pump.otpNumber == 0) {
aapsLogger.error(LTag.PUMPCOMM, "otp is not received yet") aapsLogger.error(LTag.PUMPCOMM, "otp is not received yet")
result.success(false) result.success(false)
result.comment("펌프와 연결 상태를 확인해주세요.") result.comment("펌프와 연결 상태를 확인해주세요.")
@ -349,7 +354,7 @@ class DiaconnG8Service : DaggerService() {
val isSpeedSyncToPump = sp.getBoolean("diaconn_g8_isbolusspeedsync", false) val isSpeedSyncToPump = sp.getBoolean("diaconn_g8_isbolusspeedsync", false)
// aps speed check // aps speed check
if(!isSpeedSyncToPump) { if (!isSpeedSyncToPump) {
val msg = BolusSpeedSettingPacket(injector, apsPrefBolusSpeed) val msg = BolusSpeedSettingPacket(injector, apsPrefBolusSpeed)
sendMessage(msg) sendMessage(msg)
sendMessage(AppConfirmSettingPacket(injector, msg.msgType, diaconnG8Pump.otpNumber)) sendMessage(AppConfirmSettingPacket(injector, msg.msgType, diaconnG8Pump.otpNumber))
@ -373,7 +378,7 @@ class DiaconnG8Service : DaggerService() {
if (!diaconnG8Pump.bolusStopped) { if (!diaconnG8Pump.bolusStopped) {
sendMessage(start) sendMessage(start)
// otp process // otp process
if(!processConfirm(start.msgType)) return false if (!processConfirm(start.msgType)) return false
} else { } else {
t.insulin = 0.0 t.insulin = 0.0
return false return false
@ -397,12 +402,12 @@ class DiaconnG8Service : DaggerService() {
val bolusDurationInMSec = (insulin * speed * 1000).toLong() val bolusDurationInMSec = (insulin * speed * 1000).toLong()
val expectedEnd = bolusStart + bolusDurationInMSec + 7500L val expectedEnd = bolusStart + bolusDurationInMSec + 7500L
val totalwaitTime = (expectedEnd - System.currentTimeMillis()) /1000 val totalwaitTime = (expectedEnd - System.currentTimeMillis()) / 1000
while (!diaconnG8Pump.bolusDone) { while (!diaconnG8Pump.bolusDone) {
val waitTime = (expectedEnd - System.currentTimeMillis()) / 1000 val waitTime = (expectedEnd - System.currentTimeMillis()) / 1000
bolusingEvent.status = String.format(rh.gs(R.string.waitingforestimatedbolusend), if(waitTime < 0) 0 else waitTime) bolusingEvent.status = String.format(rh.gs(R.string.waitingforestimatedbolusend), if (waitTime < 0) 0 else waitTime)
var progressPecent = 0 var progressPecent = 0
if(totalwaitTime > waitTime) { if (totalwaitTime > waitTime) {
progressPecent = ((totalwaitTime - waitTime) * 100 / totalwaitTime).toInt() progressPecent = ((totalwaitTime - waitTime) * 100 / totalwaitTime).toInt()
} }
bolusingEvent.percent = min(progressPecent, 100) bolusingEvent.percent = min(progressPecent, 100)
@ -430,7 +435,7 @@ class DiaconnG8Service : DaggerService() {
if (isConnected) { if (isConnected) {
sendMessage(stop) sendMessage(stop)
// otp process // otp process
if(!processConfirm(stop.msgType)) return if (!processConfirm(stop.msgType)) return
while (!diaconnG8Pump.bolusStopped) { while (!diaconnG8Pump.bolusStopped) {
SystemClock.sleep(200) SystemClock.sleep(200)
} }
@ -445,21 +450,21 @@ class DiaconnG8Service : DaggerService() {
// temp state check // temp state check
sendMessage(TempBasalInquirePacket(injector)) sendMessage(TempBasalInquirePacket(injector))
if (diaconnG8Pump.tbStatus ==1 ) { if (diaconnG8Pump.tbStatus == 1) {
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingtempbasal))) rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingtempbasal)))
val msgPacket = TempBasalSettingPacket(injector, 2, diaconnG8Pump.tbTime, diaconnG8Pump.tbInjectRateRatio) val msgPacket = TempBasalSettingPacket(injector, 2, diaconnG8Pump.tbTime, diaconnG8Pump.tbInjectRateRatio)
// tempbasal stop // tempbasal stop
sendMessage(msgPacket) sendMessage(msgPacket)
// otp process // otp process
if(!processConfirm(msgPacket.msgType)) return false if (!processConfirm(msgPacket.msgType)) return false
diaconnG8Pump.tempBasalStart= dateUtil.now() diaconnG8Pump.tempBasalStart = dateUtil.now()
} }
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.settingtempbasal))) rxBus.send(EventPumpStatusChanged(rh.gs(R.string.settingtempbasal)))
val tbInjectRate = ((absoluteRate*100) + 1000).toInt() val tbInjectRate = ((absoluteRate * 100) + 1000).toInt()
val msgTBR = TempBasalSettingPacket(injector, 1, ((durationInHours * 60) / 15).toInt(), tbInjectRate) val msgTBR = TempBasalSettingPacket(injector, 1, ((durationInHours * 60) / 15).toInt(), tbInjectRate)
sendMessage(msgTBR) sendMessage(msgTBR)
// otp process // otp process
if(!processConfirm(msgTBR.msgType)) return false if (!processConfirm(msgTBR.msgType)) return false
// pump tempbasal status inquire // pump tempbasal status inquire
sendMessage(TempBasalInquirePacket(injector)) sendMessage(TempBasalInquirePacket(injector))
loadHistory() loadHistory()
@ -477,13 +482,13 @@ class DiaconnG8Service : DaggerService() {
// temp state check // temp state check
sendMessage(TempBasalInquirePacket(injector)) sendMessage(TempBasalInquirePacket(injector))
if (diaconnG8Pump.tbStatus ==1 ) { if (diaconnG8Pump.tbStatus == 1) {
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingtempbasal))) rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingtempbasal)))
val msgPacket = TempBasalSettingPacket(injector, 2, diaconnG8Pump.tbTime, diaconnG8Pump.tbInjectRateRatio) val msgPacket = TempBasalSettingPacket(injector, 2, diaconnG8Pump.tbTime, diaconnG8Pump.tbInjectRateRatio)
// tempbasal stop // tempbasal stop
sendMessage(msgPacket) sendMessage(msgPacket)
// otp process // otp process
if(!processConfirm(msgPacket.msgType)) return false if (!processConfirm(msgPacket.msgType)) return false
SystemClock.sleep(500) SystemClock.sleep(500)
} }
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.settingtempbasal))) rxBus.send(EventPumpStatusChanged(rh.gs(R.string.settingtempbasal)))
@ -491,7 +496,7 @@ class DiaconnG8Service : DaggerService() {
val msgTBR = TempBasalSettingPacket(injector, 1, 2, tbInjectRate.toInt()) val msgTBR = TempBasalSettingPacket(injector, 1, 2, tbInjectRate.toInt())
sendMessage(msgTBR) sendMessage(msgTBR)
// otp process // otp process
if(!processConfirm(msgTBR.msgType)) return false if (!processConfirm(msgTBR.msgType)) return false
sendMessage(TempBasalInquirePacket(injector)) sendMessage(TempBasalInquirePacket(injector))
loadHistory() loadHistory()
val tbr = pumpSync.expectedPumpState().temporaryBasal val tbr = pumpSync.expectedPumpState().temporaryBasal
@ -505,7 +510,7 @@ class DiaconnG8Service : DaggerService() {
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingtempbasal))) rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingtempbasal)))
// temp state check // temp state check
sendMessage(TempBasalInquirePacket(injector)) sendMessage(TempBasalInquirePacket(injector))
if(diaconnG8Pump.tbStatus == 1) { if (diaconnG8Pump.tbStatus == 1) {
val msgPacket = TempBasalSettingPacket( val msgPacket = TempBasalSettingPacket(
injector, injector,
2, 2,
@ -534,7 +539,7 @@ class DiaconnG8Service : DaggerService() {
val msgExtended = InjectionExtendedBolusSettingPacket(injector, (insulin * 100).toInt(), durationInMinutes, dateUtil.now()) val msgExtended = InjectionExtendedBolusSettingPacket(injector, (insulin * 100).toInt(), durationInMinutes, dateUtil.now())
sendMessage(msgExtended) sendMessage(msgExtended)
// otp process // otp process
if(!processConfirm(msgExtended.msgType)) return false if (!processConfirm(msgExtended.msgType)) return false
//diaconnG8Pump.isExtendedInProgress = true //diaconnG8Pump.isExtendedInProgress = true
loadHistory() loadHistory()
val eb = pumpSync.expectedPumpState().extendedBolus val eb = pumpSync.expectedPumpState().extendedBolus
@ -546,11 +551,11 @@ class DiaconnG8Service : DaggerService() {
fun extendedBolusStop(): Boolean { fun extendedBolusStop(): Boolean {
if (!isConnected) return false if (!isConnected) return false
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingextendedbolus))) rxBus.send(EventPumpStatusChanged(rh.gs(R.string.stoppingextendedbolus)))
val msgType = if(diaconnG8Pump.dualStatus == 1) 0x09.toByte() else 0x08.toByte() val msgType = if (diaconnG8Pump.dualStatus == 1) 0x09.toByte() else 0x08.toByte()
val msgStop = InjectionCancelSettingPacket(injector, msgType) val msgStop = InjectionCancelSettingPacket(injector, msgType)
sendMessage(msgStop) sendMessage(msgStop)
// otp process // otp process
if(!processConfirm(msgStop.msgType)) return false if (!processConfirm(msgStop.msgType)) return false
loadHistory() // pump log sync( db update) loadHistory() // pump log sync( db update)
val eb = pumpSync.expectedPumpState().extendedBolus val eb = pumpSync.expectedPumpState().extendedBolus
diaconnG8Pump.fromExtendedBolus(eb) diaconnG8Pump.fromExtendedBolus(eb)
@ -564,16 +569,48 @@ class DiaconnG8Service : DaggerService() {
val basalList = diaconnG8Pump.buildDiaconnG8ProfileRecord(profile) val basalList = diaconnG8Pump.buildDiaconnG8ProfileRecord(profile)
val requestReqPacket1 = BasalSettingPacket( val requestReqPacket1 = BasalSettingPacket(
injector, 1, 1, (basalList[0] * 100).toInt(), (basalList[1] * 100).toInt(), (basalList[2] * 100).toInt(), (basalList[3] * 100).toInt(), (basalList[4] * 100).toInt(), (basalList[5] * 100).toInt() injector,
1,
1,
(basalList[0] * 100).toInt(),
(basalList[1] * 100).toInt(),
(basalList[2] * 100).toInt(),
(basalList[3] * 100).toInt(),
(basalList[4] * 100).toInt(),
(basalList[5] * 100).toInt()
) )
val requestReqPacket2= BasalSettingPacket( val requestReqPacket2 = BasalSettingPacket(
injector, 1, 2, (basalList[6] * 100).toInt(), (basalList[7] * 100).toInt(), (basalList[8] * 100).toInt(), (basalList[9] * 100).toInt(), (basalList[10] * 100).toInt(), (basalList[11] * 100).toInt() injector,
1,
2,
(basalList[6] * 100).toInt(),
(basalList[7] * 100).toInt(),
(basalList[8] * 100).toInt(),
(basalList[9] * 100).toInt(),
(basalList[10] * 100).toInt(),
(basalList[11] * 100).toInt()
) )
val requestReqPacket3= BasalSettingPacket( val requestReqPacket3 = BasalSettingPacket(
injector, 1, 3, (basalList[12] * 100).toInt(), (basalList[13] * 100).toInt(), (basalList[14] * 100).toInt(), (basalList[15] * 100).toInt(), (basalList[16] * 100).toInt(), (basalList[17] * 100).toInt() injector,
1,
3,
(basalList[12] * 100).toInt(),
(basalList[13] * 100).toInt(),
(basalList[14] * 100).toInt(),
(basalList[15] * 100).toInt(),
(basalList[16] * 100).toInt(),
(basalList[17] * 100).toInt()
) )
val requestReqPacket4= BasalSettingPacket( val requestReqPacket4 = BasalSettingPacket(
injector, 1, 4, (basalList[18] * 100).toInt(), (basalList[19] * 100).toInt(), (basalList[20] * 100).toInt(), (basalList[21] * 100).toInt(), (basalList[22] * 100).toInt(), (basalList[23] * 100).toInt() injector,
1,
4,
(basalList[18] * 100).toInt(),
(basalList[19] * 100).toInt(),
(basalList[20] * 100).toInt(),
(basalList[21] * 100).toInt(),
(basalList[22] * 100).toInt(),
(basalList[23] * 100).toInt()
) )
// setting basal pattern 1,2,3,4 // setting basal pattern 1,2,3,4
sendMessage(requestReqPacket1) sendMessage(requestReqPacket1)
@ -582,7 +619,7 @@ class DiaconnG8Service : DaggerService() {
sendMessage(requestReqPacket4) sendMessage(requestReqPacket4)
// otp process // otp process
if(!processConfirm(requestReqPacket4.msgType)) return false if (!processConfirm(requestReqPacket4.msgType)) return false
// pump saving time about 30 second // pump saving time about 30 second
aapsLogger.debug(LTag.PUMPCOMM, "30 seconds Waiting!!") aapsLogger.debug(LTag.PUMPCOMM, "30 seconds Waiting!!")
SystemClock.sleep(30000) SystemClock.sleep(30000)
@ -590,7 +627,7 @@ class DiaconnG8Service : DaggerService() {
val msgPacket = InjectionBasalSettingPacket(injector, 1) val msgPacket = InjectionBasalSettingPacket(injector, 1)
sendMessage(msgPacket) sendMessage(msgPacket)
// otp process // otp process
if(!processConfirm(msgPacket.msgType)) return false if (!processConfirm(msgPacket.msgType)) return false
readPumpStatus() readPumpStatus()
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
return requestReqPacket4.success() return requestReqPacket4.success()
@ -598,14 +635,14 @@ class DiaconnG8Service : DaggerService() {
private fun pumpLogDefaultSetting() { private fun pumpLogDefaultSetting() {
val apsWrappingCount = diaconnG8Pump.pumpWrappingCount val apsWrappingCount = diaconnG8Pump.pumpWrappingCount
val apsLastLogNum = if(diaconnG8Pump.pumpLastLogNum - 1 < 0 ) 0 else diaconnG8Pump.pumpLastLogNum - 1 val apsLastLogNum = if (diaconnG8Pump.pumpLastLogNum - 1 < 0) 0 else diaconnG8Pump.pumpLastLogNum - 1
sp.putInt(rh.gs(R.string.apslastLogNum), apsLastLogNum) sp.putInt(rh.gs(R.string.apslastLogNum), apsLastLogNum)
sp.putInt(rh.gs(R.string.apsWrappingCount), apsWrappingCount) sp.putInt(rh.gs(R.string.apsWrappingCount), apsWrappingCount)
} }
private fun processConfirm(msgType:Byte) : Boolean { private fun processConfirm(msgType: Byte): Boolean {
// pump confirm // pump confirm
if(diaconnG8Pump.otpNumber == 0) { if (diaconnG8Pump.otpNumber == 0) {
aapsLogger.error(LTag.PUMPCOMM, "otp is not received yet") aapsLogger.error(LTag.PUMPCOMM, "otp is not received yet")
// Comments are made as dialogs are exposed twice each in the event of an error. // Comments are made as dialogs are exposed twice each in the event of an error.