From 7502824a1b68ce10c5ee9a3d3a49c05f47f5f178 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Sat, 5 Mar 2022 22:27:16 +0000 Subject: [PATCH] - added Aidex implementation (doesn't work yet) --- app/src/main/AndroidManifest.xml | 4 + .../activities/MyPreferenceFragment.kt | 9 +- .../nightscout/androidaps/di/PluginsModule.kt | 6 ++ .../androidaps/plugins/source/AidexPlugin.kt | 101 ++++++++++++++++++ .../androidaps/receivers/DataReceiver.kt | 3 + .../nightscout/androidaps/services/Intents.kt | 23 ++++ app/src/main/res/values/strings.xml | 6 ++ .../database/entities/GlucoseValue.kt | 1 + 8 files changed, 147 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/source/AidexPlugin.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a163b3729c..b8b5d99d97 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,6 +34,10 @@ + + + + () + glucoseValues += CgmSourceTransaction.TransactionGlucoseValue( + timestamp = bundle.getLong(Intents.AIDEX_TIMESTAMP, 0), + value = if (bundle.getString(Intents.AIDEX_BG_TYPE, "mg/dl").equals("mg/dl")) bundle.getDouble(Intents.AIDEX_BG_VALUE, 0.0) else bundle.getDouble(Intents.AIDEX_BG_VALUE, 0.0) * Constants.MMOLL_TO_MGDL, + raw = null, + noise = null, + trendArrow = GlucoseValue.TrendArrow.fromString(bundle.getString(Intents.AIDEX_BG_SLOPE_NAME)), + sourceSensor = GlucoseValue.SourceSensor.AIDEX + ) + repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null)) + .doOnError { + aapsLogger.error(LTag.DATABASE, "Error while saving values from Xdrip", it) + ret = Result.failure(workDataOf("Error" to it.toString())) + } + .blockingGet() + .also { savedValues -> + savedValues.all().forEach { + aapsLogger.debug(LTag.DATABASE, "Inserted bg $it") + } + } + return ret + } + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.kt b/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.kt index 6be6a5ad2e..a65c77a569 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.kt @@ -67,6 +67,9 @@ open class DataReceiver : DaggerBroadcastReceiver() { Intents.DEXCOM_BG -> OneTimeWorkRequest.Builder(DexcomPlugin.DexcomWorker::class.java) .setInputData(dataWorker.storeInputData(bundle, intent)).build() + Intents.AIDEX_NEW_BG_ESTIMATE -> + OneTimeWorkRequest.Builder(AidexPlugin.AidexWorker::class.java) + .setInputData(dataWorker.storeInputData(bundle, intent)).build() else -> null }?.let { request -> dataWorker.enqueue(request) } } diff --git a/app/src/main/java/info/nightscout/androidaps/services/Intents.kt b/app/src/main/java/info/nightscout/androidaps/services/Intents.kt index bf3a8d3695..87c74bcb47 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/Intents.kt +++ b/app/src/main/java/info/nightscout/androidaps/services/Intents.kt @@ -31,6 +31,29 @@ interface Intents { const val POCTECH_BG = "com.china.poctech.data" const val TOMATO_BG = "com.fanqies.tomatofn.BgEstimate" + // Aidex -> AAPS + var AIDEX_NEW_BG_ESTIMATE = "com.microtechmd.cgms.aidex.BgEstimate" + + // DATA + // DATA + /** + * BG Type: Can be either mmol/l or mg/dl + */ + var AIDEX_BG_TYPE = "com.microtechmd.cgms.aidex.BgType" + var AIDEX_BG_VALUE = "com.microtechmd.cgms.aidex.BgValue" + + /** + * BG Slope Name: following values are valid: + * "DoubleUp", "SingleUp", "FortyFiveUp", "Flat", "FortyFiveDown", "SingleDown", + * "DoubleDown", "NotComputable", "RateOutOfRange" + */ + var AIDEX_BG_SLOPE_NAME = "com.microtechmd.cgms.aidex.BgSlopeName" + var AIDEX_TIMESTAMP = "com.microtechmd.cgms.aidex.Time" // epoch in ms + + var AIDEX_TRANSMITTER_SN = "com.microtechmd.cgms.aidex.TransmitterSerialNumber" + var AIDEX_SENSOR_ID = "com.microtechmd.cgms.aidex.SensorId" + + // Broadcast status const val AAPS_BROADCAST = "info.nightscout.androidaps.status" } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 07bf55f635..438ab04f7f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1222,4 +1222,10 @@ Hide loop Show loop %1$d selected + + GlucoRx Aidex + Aidex + Receive BG values from GlucoRx Aidex CGMS. + + diff --git a/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt b/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt index 241485a254..00979a554c 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt @@ -111,6 +111,7 @@ data class GlucoseValue( GLUNOVO_NATIVE("Glunovo"), MM_600_SERIES("MM600Series"), EVERSENSE("Eversense"), + AIDEX("GlucoRx Aidex"), RANDOM("Random"), UNKNOWN("Unknown"),