From 527952276fbef0314bf907bbb4112baf388814f2 Mon Sep 17 00:00:00 2001 From: miyeongkim Date: Wed, 4 May 2022 13:23:09 +0900 Subject: [PATCH] add columns to DiaconnHistoryRecord table --- .../1.json | 25 +++++- .../diaconn/api/DiaconnLogUploader.kt | 4 +- .../diaconn/database/DiaconnHistoryRecord.kt | 5 +- .../database/DiaconnHistoryRecordDao.kt | 3 + .../packet/BigLogInquireResponsePacket.kt | 86 +++++++++++++++++-- .../diaconn/service/DiaconnG8Service.kt | 80 +++++++---------- 6 files changed, 141 insertions(+), 62 deletions(-) diff --git a/diaconn/schemas/info.nightscout.androidaps.diaconn.database.DiaconnHistoryDatabase/1.json b/diaconn/schemas/info.nightscout.androidaps.diaconn.database.DiaconnHistoryDatabase/1.json index b6e405a524..e1745bce91 100644 --- a/diaconn/schemas/info.nightscout.androidaps.diaconn.database.DiaconnHistoryDatabase/1.json +++ b/diaconn/schemas/info.nightscout.androidaps.diaconn.database.DiaconnHistoryDatabase/1.json @@ -2,11 +2,11 @@ "formatVersion": 1, "database": { "version": 1, - "identityHash": "698b023da2f9efdc0351236c43eb20b6", + "identityHash": "d604d25c3edbdf18cc5a39121cf5a779", "entities": [ { "tableName": "diaconnHistory", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`timestamp` INTEGER NOT NULL, `code` INTEGER NOT NULL, `value` REAL NOT NULL, `bolusType` TEXT NOT NULL, `stringValue` TEXT NOT NULL, `duration` INTEGER NOT NULL, `dailyBasal` REAL NOT NULL, `dailyBolus` REAL NOT NULL, `alarm` TEXT NOT NULL, PRIMARY KEY(`timestamp`))", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`timestamp` INTEGER NOT NULL, `code` INTEGER NOT NULL, `value` REAL NOT NULL, `bolusType` TEXT NOT NULL, `stringValue` TEXT NOT NULL, `duration` INTEGER NOT NULL, `dailyBasal` REAL NOT NULL, `dailyBolus` REAL NOT NULL, `alarm` TEXT NOT NULL, `lognum` INTEGER NOT NULL, `wrappingCount` INTEGER NOT NULL, `pumpUid` TEXT NOT NULL, PRIMARY KEY(`timestamp`))", "fields": [ { "fieldPath": "timestamp", @@ -61,6 +61,24 @@ "columnName": "alarm", "affinity": "TEXT", "notNull": true + }, + { + "fieldPath": "lognum", + "columnName": "lognum", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "wrappingCount", + "columnName": "wrappingCount", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "pumpUid", + "columnName": "pumpUid", + "affinity": "TEXT", + "notNull": true } ], "primaryKey": { @@ -77,6 +95,7 @@ "code", "timestamp" ], + "orders": [], "createSql": "CREATE INDEX IF NOT EXISTS `index_diaconnHistory_code_timestamp` ON `${TABLE_NAME}` (`code`, `timestamp`)" } ], @@ -86,7 +105,7 @@ "views": [], "setupQueries": [ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", - "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '698b023da2f9efdc0351236c43eb20b6')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'd604d25c3edbdf18cc5a39121cf5a779')" ] } } \ No newline at end of file diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/api/DiaconnLogUploader.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/api/DiaconnLogUploader.kt index e4b26986dd..bcc35fcb18 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/api/DiaconnLogUploader.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/api/DiaconnLogUploader.kt @@ -1,7 +1,5 @@ package info.nightscout.androidaps.diaconn.api -import android.content.Context -import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.LTag import retrofit2.Retrofit @@ -21,7 +19,7 @@ class DiaconnLogUploader @Inject constructor ( private var retrofit: Retrofit? = null fun getRetrofitInstance(): Retrofit? { - //aapsLogger.debug(LTag.PUMPCOMM, "Diaconn pump logs upload BASE_URL : $BASE_URL") + aapsLogger.debug(LTag.PUMPCOMM, "diaconn pump logs upload instance") if (retrofit == null) { retrofit = Retrofit.Builder() .baseUrl(BASE_URL) diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/database/DiaconnHistoryRecord.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/database/DiaconnHistoryRecord.kt index 46d7e28e89..45a4b35779 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/database/DiaconnHistoryRecord.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/database/DiaconnHistoryRecord.kt @@ -15,5 +15,8 @@ data class DiaconnHistoryRecord( var duration: Int = 0, var dailyBasal: Double = 0.0, var dailyBolus: Double = 0.0, - var alarm: String = "" + var alarm: String = "", + var lognum: Int = 0, + var wrappingCount: Int = 0, + var pumpUid: String = "" ) diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/database/DiaconnHistoryRecordDao.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/database/DiaconnHistoryRecordDao.kt index 5115d3d1b8..9e5a7eb8eb 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/database/DiaconnHistoryRecordDao.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/database/DiaconnHistoryRecordDao.kt @@ -14,4 +14,7 @@ abstract class DiaconnHistoryRecordDao { @Insert(onConflict = OnConflictStrategy.REPLACE) abstract fun createOrUpdate(diaconnHistoryRecord: DiaconnHistoryRecord) + + @Query( "SELECT * from $TABLE_DIACONN_HISTORY WHERE pumpUid = :pumpUid ORDER BY timestamp DESC LIMIT 1" ) + abstract fun getLastRecord(pumpUid: String): DiaconnHistoryRecord? } diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/BigLogInquireResponsePacket.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/BigLogInquireResponsePacket.kt index 099a562435..f224d7d834 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/BigLogInquireResponsePacket.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/packet/BigLogInquireResponsePacket.kt @@ -1,12 +1,15 @@ package info.nightscout.androidaps.diaconn.packet -import android.app.Application import android.content.Context import dagger.android.HasAndroidInjector import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.diaconn.DiaconnG8Pump import info.nightscout.androidaps.diaconn.R -import info.nightscout.androidaps.diaconn.api.* +import info.nightscout.androidaps.diaconn.api.ApiResponse +import info.nightscout.androidaps.diaconn.api.DiaconnApiService +import info.nightscout.androidaps.diaconn.api.DiaconnLogUploader +import info.nightscout.androidaps.diaconn.api.PumpLog +import info.nightscout.androidaps.diaconn.api.PumpLogDto import info.nightscout.androidaps.diaconn.common.RecordTypes import info.nightscout.androidaps.diaconn.database.DiaconnHistoryRecord import info.nightscout.androidaps.diaconn.database.DiaconnHistoryRecordDao @@ -15,19 +18,18 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.PumpDescription import info.nightscout.androidaps.interfaces.PumpSync -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBus 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.defs.PumpType import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.shared.logging.LTag import info.nightscout.shared.sharedPreferences.SP import org.apache.commons.lang3.time.DateUtils import org.joda.time.DateTime import retrofit2.Call import retrofit2.Response -import java.lang.Exception import java.util.* import javax.inject.Inject @@ -118,8 +120,6 @@ class BigLogInquireResponsePacket( // APS Local history sync start diaconnG8Pump.apsWrappingCount = wrapingCount diaconnG8Pump.apslastLogNum = logNum - sp.putInt(rh.gs(R.string.apslastLogNum), logNum) - sp.putInt(rh.gs(R.string.apsWrappingCount), wrapingCount) when(pumplogKind) { @@ -143,6 +143,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.duration = logItem.getInjectTime() diaconnG8HistoryRecord.bolusType = "M" // meal bolus diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_logmealsuccess) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) if (!newRecord && detailedBolusInfo != null) { // detailedInfo can be from another similar record. Reinsert @@ -171,6 +174,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.duration = logItem.getInjectTime() diaconnG8HistoryRecord.bolusType = "M" // Meal bolus diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_logmealfail) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) if (!newRecord && detailedBolusInfo != null) { // detailedInfo can be from another similar record. Reinsert @@ -200,6 +206,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.duration = logItem.getInjectTime() diaconnG8HistoryRecord.bolusType = "B" // bolus diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_logsuccess) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) if (!newRecord && detailedBolusInfo != null) { // detailedInfo can be from another similar record. Reinsert @@ -231,6 +240,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.duration = logItem.getInjectTime() diaconnG8HistoryRecord.bolusType = "B" // bolus diaconnG8HistoryRecord.stringValue = getReasonName(pumplogKind, logItem.reason) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) if (!newRecord && detailedBolusInfo != null) { // detailedInfo can be from another similar record. Reinsert @@ -259,6 +271,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.duration = logItem.getInjectTime() diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_logsquarestart) diaconnG8HistoryRecord.bolusType = "E" // Extended + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "EXTENDEDBOLUSSTART " + dateUtil.timeString(logDateTime) } @@ -273,6 +288,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.duration = logItem.getInjectTime() diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_logsquaresuccess) diaconnG8HistoryRecord.bolusType = "E" // Extended + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "EXTENDEDBOLUSEND " + dateUtil.timeString(logDateTime) } @@ -294,6 +312,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.duration = logItem.getInjectTime() diaconnG8HistoryRecord.stringValue = getReasonName(pumplogKind, logItem.reason) diaconnG8HistoryRecord.bolusType = "E" + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "EXTENDEDBOLUSFAIL " + dateUtil.timeString(logDateTime) } @@ -320,6 +341,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.duration = logItem.getInjectTime() * 10 // (1~30) 1:10min 30:300min diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_logdualsquarestart) diaconnG8HistoryRecord.bolusType = "D" // Extended + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "DUALEXTENTEDSTART " + dateUtil.timeString(logDateTime) @@ -350,6 +374,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.duration = logItem.getInjectTime() diaconnG8HistoryRecord.bolusType = "D" // bolus diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_logdualnormalsuccess) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) if (!newRecord && detailedBolusInfo != null) { // detailedInfo can be from another similar record. Reinsert @@ -370,6 +397,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.duration = logItem.getInjectTime() diaconnG8HistoryRecord.bolusType = "D" diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_logdualsquaresuccess) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "DUALBOLUS SQUARESUCCESS " + dateUtil.timeString(logDateTime) } @@ -392,6 +422,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.duration = logItem.getInjectTime() diaconnG8HistoryRecord.bolusType = "D" diaconnG8HistoryRecord.stringValue = getReasonName(pumplogKind, logItem.reason) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "DUALBOLUS FAIL " + dateUtil.timeString(logDateTime) } @@ -405,6 +438,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.timestamp = logDateTime diaconnG8HistoryRecord.value = logItem.beforeAmount / 100.0 diaconnG8HistoryRecord.stringValue = "TB before: ${logItem.beforeAmount / 100.0} / TB after: ${logItem.afterAmount / 100.0}" + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "1HOUR BASAL " + dateUtil.dateAndTimeString(logDateTime) } @@ -417,6 +453,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.code = RecordTypes.RECORD_TYPE_SUSPEND diaconnG8HistoryRecord.timestamp = logDateTime diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_lgosuspend, logItem.getBasalPattern()) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "SUSPEND " + dateUtil.timeString(logDateTime) } @@ -429,6 +468,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.code = RecordTypes.RECORD_TYPE_SUSPEND diaconnG8HistoryRecord.timestamp = logDateTime diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_lgorelease, logItem.getBasalPattern()) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "SUSPENDRELEASE " + dateUtil.timeString(logDateTime) } @@ -452,6 +494,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.timestamp = logDateTime diaconnG8HistoryRecord.value = logItem.remainAmount / 100.0 diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_loginjectorprime, logItem.primeAmount / 100.0) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "INSULINCHANGE " + dateUtil.timeString(logDateTime) } @@ -478,6 +523,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.timestamp = logDateTime diaconnG8HistoryRecord.value = logItem.remainAmount / 100.0 diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_logtubeprime, logItem.primeAmount / 100.0) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "TUBECHANGE " + dateUtil.timeString(logDateTime) } @@ -512,7 +560,9 @@ class BigLogInquireResponsePacket( if (recordMap["basal"]!! > 0.0) { diaconnG8HistoryRecord.dailyBasal = recordMap["basal"]!! } - + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) //If it is a TDD, store it for stats also. @@ -559,7 +609,9 @@ class BigLogInquireResponsePacket( if (recordMap["bolus"]!! > 0.0) { diaconnG8HistoryRecord.dailyBolus = recordMap["bolus"]!! } - + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) //If it is a TDD, store it for stats also. @@ -597,6 +649,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.timestamp = logDateTime diaconnG8HistoryRecord.value = logItem.remainAmount / 100.0 diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_logneedleprime, logItem.primeAmount / 100.0) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "NEEDLECHANGE " + dateUtil.timeString(logDateTime) } @@ -634,6 +689,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.duration = logItem.tbTime * 15 diaconnG8HistoryRecord.value = absoluteRate diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_logtempstart) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "TEMPSTART " + dateUtil.timeString(logDateTime) } @@ -664,6 +722,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.timestamp = logDateTime diaconnG8HistoryRecord.value = absoluteRate diaconnG8HistoryRecord.stringValue = getReasonName(pumplogKind, logItem.reason) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "TEMPSTOP " + dateUtil.timeString(logDateTime) } @@ -677,6 +738,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.code = RecordTypes.RECORD_TYPE_ALARM diaconnG8HistoryRecord.timestamp = logDateTime diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_logbatteryshorage) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "BATTERYALARM " + dateUtil.timeString(logDateTime) } @@ -692,6 +756,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.timestamp = logDateTime diaconnG8HistoryRecord.value = logItem.amount / 100.0 diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_logalarmblock, getReasonName(pumplogKind, logItem.reason)) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "BLOCKALARM " + dateUtil.timeString(logDateTime) } @@ -707,6 +774,9 @@ class BigLogInquireResponsePacket( diaconnG8HistoryRecord.timestamp = logDateTime diaconnG8HistoryRecord.value = logItem.remain.toDouble() diaconnG8HistoryRecord.stringValue = rh.gs(R.string.diaconn_g8_loginsulinshorage) + diaconnG8HistoryRecord.lognum = logNum + diaconnG8HistoryRecord.wrappingCount = wrapingCount + diaconnG8HistoryRecord.pumpUid = diaconnG8Pump.pumpUid diaconnHistoryRecordDao.createOrUpdate(diaconnG8HistoryRecord) status = "SHORTAGEALARM " + dateUtil.timeString(logDateTime) } diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/service/DiaconnG8Service.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/service/DiaconnG8Service.kt index b553e3a212..43caae85d4 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/service/DiaconnG8Service.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/service/DiaconnG8Service.kt @@ -16,6 +16,7 @@ import info.nightscout.androidaps.diaconn.DiaconnG8Pump import info.nightscout.androidaps.diaconn.R import info.nightscout.androidaps.diaconn.api.DiaconnApiService import info.nightscout.androidaps.diaconn.api.DiaconnLogUploader +import info.nightscout.androidaps.diaconn.database.DiaconnHistoryRecordDao import info.nightscout.androidaps.diaconn.events.EventDiaconnG8NewStatus import info.nightscout.androidaps.diaconn.events.EventDiaconnG8PumpLogReset import info.nightscout.androidaps.diaconn.packet.* @@ -78,6 +79,7 @@ class DiaconnG8Service : DaggerService() { @Inject lateinit var dateUtil: DateUtil @Inject lateinit var aapsSchedulers: AapsSchedulers @Inject lateinit var diaconnLogUploader: DiaconnLogUploader + @Inject lateinit var diaconnHistoryRecordDao: DiaconnHistoryRecordDao private val disposable = CompositeDisposable() private val mBinder: IBinder = LocalBinder() @@ -90,13 +92,6 @@ class DiaconnG8Service : DaggerService() { .observeOn(aapsSchedulers.io) .subscribe({ stopSelf() }) { fabricPrivacy.logException(it) } ) - disposable.add(rxBus - .toObservable(EventDiaconnG8PumpLogReset::class.java) - .observeOn(aapsSchedulers.io) - .subscribe { - pumpLogResetAfterPrefImport() - } - ) } inner class LocalBinder : Binder() { @@ -146,9 +141,6 @@ class DiaconnG8Service : DaggerService() { fun readPumpStatus() { try { - - aapsLogger.error(LTag.PUMPCOMM, "패키지 명!!! : "+context.packageManager.getPackageInfo(context.packageName, 0).versionName) - val pump = activePlugin.activePump rxBus.send(EventPumpStatusChanged(rh.gs(R.string.gettingpumpsettings))) @@ -247,6 +239,7 @@ class DiaconnG8Service : DaggerService() { } fun loadHistory(): PumpEnactResult { + if (!diaconnG8Plugin.isInitialized()) { val result = PumpEnactResult(injector).success(false) result.comment = "pump not initialized" @@ -260,6 +253,16 @@ class DiaconnG8Service : DaggerService() { } val result = PumpEnactResult(injector) + var apsLastLogNum = 9999 + var apsWrappingCount = -1 + // get saved last loginfo + val diaconnHistoryRecord = diaconnHistoryRecordDao.getLastRecord(diaconnG8Pump.pumpUid) + aapsLogger.error(LTag.PUMPCOMM, "diaconnHistoryRecord :: $diaconnHistoryRecord") + + if(diaconnHistoryRecord != null) { + apsLastLogNum = diaconnHistoryRecord.lognum + apsWrappingCount = diaconnHistoryRecord.wrappingCount + } // pump log status val pumpLastNum = diaconnG8Pump.pumpLastLogNum @@ -267,37 +270,31 @@ class DiaconnG8Service : DaggerService() { val apsIncarnationNum = sp.getInt(rh.gs(R.string.apsIncarnationNo), 65536) // aps last log num val pumpSerialNo = sp.getInt(rh.gs(R.string.pumpserialno), 0) - var apsWrappingCount = sp.getInt(rh.gs(R.string.apsWrappingCount), 0) - var apsLastLogNum = sp.getInt(rh.gs(R.string.apslastLogNum), 0) + // if first install app - if (apsWrappingCount == 0 && apsLastLogNum == 0) { - pumpLogDefaultSetting() + if (apsWrappingCount == -1 && apsLastLogNum == 9999 ) { + apsWrappingCount = pumpWrappingCount + apsLastLogNum = if (pumpLastNum - 1 < 0) 0 else pumpLastNum -2 } - - // if pump reset - if (apsIncarnationNum != diaconnG8Pump.pumpIncarnationNum) { - pumpLogDefaultSetting() - sp.putInt(rh.gs(R.string.apsIncarnationNo), diaconnG8Pump.pumpIncarnationNum) - } - // if another pump if (pumpSerialNo != diaconnG8Pump.serialNo) { - pumpLogDefaultSetting() + apsWrappingCount = pumpWrappingCount + apsLastLogNum = if (pumpLastNum - 1 < 0) 0 else pumpLastNum -2 sp.putInt(rh.gs(R.string.pumpserialno), diaconnG8Pump.serialNo) } - - apsWrappingCount = sp.getInt(rh.gs(R.string.apsWrappingCount), 0) - apsLastLogNum = sp.getInt(rh.gs(R.string.apslastLogNum), 0) - - aapsLogger.debug(LTag.PUMPCOMM, "apsWrappingCount : $apsWrappingCount, apsLastLogNum : $apsLastLogNum") - - if ((pumpWrappingCount * 10000 + pumpLastNum) < apsLastLogNum) { - pumpLogDefaultSetting() + // if pump reset + if (apsIncarnationNum != diaconnG8Pump.pumpIncarnationNum) { + apsWrappingCount = pumpWrappingCount + apsLastLogNum = if (pumpLastNum - 1 < 0) 0 else pumpLastNum -2 + sp.putInt(R.string.apsIncarnationNo, apsIncarnationNum) } + aapsLogger.debug(LTag.PUMPCOMM, "apsWrappingCount : $apsWrappingCount, apsLastLogNum : $apsLastLogNum") + // pump log loop size val pumpLogPageSize = 11 - val (start, end, loopSize) = getLogLoopCount(apsLastLogNum, apsWrappingCount, pumpLastNum, pumpWrappingCount) + val (start, end, loopSize) = getLogLoopCount(apsLastLogNum, apsWrappingCount, pumpLastNum, pumpWrappingCount, false) + aapsLogger.debug(LTag.PUMPCOMM, "loopinfo start : $start, end : $end, loopSize : $loopSize") // log sync start! if (loopSize > 0) { for (i in 0 until loopSize) { @@ -330,7 +327,7 @@ class DiaconnG8Service : DaggerService() { aapsLogger.debug(LTag.PUMPCOMM, "platformLogNo: $platformLogNo, platformWrappingCount: $platformWrappingCount") // 페이지 사이즈로 처리할 때 루핑 횟수 계산 - val (platformStart, platformEnd, platformLoopSize) = getLogLoopCount(platformLogNo, platformWrappingCount, pumpLastNum, pumpWrappingCount) + val (platformStart, platformEnd, platformLoopSize) = getLogLoopCount(platformLogNo, platformWrappingCount, pumpLastNum, pumpWrappingCount, true) if(platformLoopSize > 0) { diaconnG8Pump.isPlatformUploadStarted = true for (i in 0 until platformLoopSize) { @@ -351,17 +348,18 @@ class DiaconnG8Service : DaggerService() { return result } - private fun getLogLoopCount(lastLogNum: Int, wrappingCount: Int, pumpLastNum: Int, pumpWrappingCount: Int): Triple { + private fun getLogLoopCount(lastLogNum: Int, wrappingCount: Int, pumpLastNum: Int, pumpWrappingCount: Int, isPlatform: Boolean): Triple { val start: Int// log sync start number val end: Int // log sync end number1311 + aapsLogger.debug(LTag.PUMPCOMM, "lastLogNum : $lastLogNum, wrappingCount : $wrappingCount , pumpLastNum: $pumpLastNum, pumpWrappingCount : $pumpWrappingCount") - if (pumpWrappingCount * 10000 + pumpLastNum - lastLogNum > 10000) { + if ((pumpWrappingCount * 10000 + pumpLastNum - lastLogNum > 10000 && isPlatform)) { start = pumpLastNum end = 10000 } else if (pumpWrappingCount > wrappingCount && lastLogNum < 9999) { start = (lastLogNum + 1) end = 10000 - } else if (pumpWrappingCount > wrappingCount && lastLogNum >= 9999) { + } else if (pumpWrappingCount > wrappingCount && lastLogNum >= 9999 && isPlatform) { start = 0 // 처음부터 시작 end = pumpLastNum } else { @@ -694,18 +692,6 @@ class DiaconnG8Service : DaggerService() { return requestReqPacket4.success() } - private fun pumpLogDefaultSetting() { - val apsWrappingCount = diaconnG8Pump.pumpWrappingCount - 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.apsWrappingCount), apsWrappingCount) - } - - private fun pumpLogResetAfterPrefImport() { - sp.putInt(rh.gs(R.string.apslastLogNum), 0) - sp.putInt(rh.gs(R.string.apsWrappingCount), 0) - } - private fun processConfirm(msgType: Byte): Boolean { // pump confirm if (diaconnG8Pump.otpNumber == 0) {