- added Aidex implementation (doesn't work yet)
This commit is contained in:
parent
6b526f1a9c
commit
7502824a1b
8 changed files with 147 additions and 6 deletions
|
@ -34,6 +34,10 @@
|
|||
<!-- To receive data from xdrip. -->
|
||||
<uses-permission android:name="com.eveningoutpost.dexdrip.permissions.RECEIVE_BG_ESTIMATE" />
|
||||
|
||||
<!-- To receive data from Aidex -->
|
||||
<uses-permission android:name="com.microtechmd.cgms.aidex.permissions.RECEIVE_BG_ESTIMATE" />
|
||||
|
||||
|
||||
<application
|
||||
android:name=".MainApp"
|
||||
android:allowBackup="true"
|
||||
|
|
|
@ -43,12 +43,7 @@ import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
|
|||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin
|
||||
import info.nightscout.androidaps.plugins.source.DexcomPlugin
|
||||
import info.nightscout.androidaps.plugins.source.EversensePlugin
|
||||
import info.nightscout.androidaps.plugins.source.GlimpPlugin
|
||||
import info.nightscout.androidaps.plugins.source.PoctechPlugin
|
||||
import info.nightscout.androidaps.plugins.source.TomatoPlugin
|
||||
import info.nightscout.androidaps.plugins.source.GlunovoPlugin
|
||||
import info.nightscout.androidaps.plugins.source.*
|
||||
import info.nightscout.shared.SafeParse
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog.show
|
||||
import info.nightscout.androidaps.utils.protection.PasswordCheck
|
||||
|
@ -92,6 +87,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
|
|||
@Inject lateinit var poctechPlugin: PoctechPlugin
|
||||
@Inject lateinit var tomatoPlugin: TomatoPlugin
|
||||
@Inject lateinit var glunovoPlugin: GlunovoPlugin
|
||||
@Inject lateinit var aidexPlugin: AidexPlugin
|
||||
@Inject lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin
|
||||
@Inject lateinit var statusLinePlugin: StatusLinePlugin
|
||||
@Inject lateinit var tidepoolPlugin: TidepoolPlugin
|
||||
|
@ -168,6 +164,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
|
|||
addPreferencesFromResourceIfEnabled(tomatoPlugin, rootKey)
|
||||
addPreferencesFromResourceIfEnabled(glunovoPlugin, rootKey)
|
||||
addPreferencesFromResourceIfEnabled(poctechPlugin, rootKey)
|
||||
addPreferencesFromResourceIfEnabled(aidexPlugin, rootKey)
|
||||
addPreferencesFromResourceIfEnabled(glimpPlugin, rootKey)
|
||||
addPreferencesFromResourceIfEnabled(loopPlugin, rootKey, config.APS)
|
||||
addPreferencesFromResourceIfEnabled(openAPSAMAPlugin, rootKey, config.APS)
|
||||
|
|
|
@ -357,6 +357,12 @@ abstract class PluginsModule {
|
|||
@IntKey(460)
|
||||
abstract fun bindTomatoPlugin(plugin: TomatoPlugin): PluginBase
|
||||
|
||||
@Binds
|
||||
@AllConfigs
|
||||
@IntoMap
|
||||
@IntKey(465)
|
||||
abstract fun bindAidexPlugin(plugin: AidexPlugin): PluginBase
|
||||
|
||||
@Binds
|
||||
@AllConfigs
|
||||
@IntoMap
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
package info.nightscout.androidaps.plugins.source
|
||||
|
||||
import android.content.Context
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
import androidx.work.workDataOf
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.database.entities.GlucoseValue
|
||||
import info.nightscout.androidaps.database.transactions.CgmSourceTransaction
|
||||
import info.nightscout.androidaps.interfaces.BgSource
|
||||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import info.nightscout.androidaps.receivers.DataWorker
|
||||
import info.nightscout.androidaps.services.Intents
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class AidexPlugin @Inject constructor(
|
||||
injector: HasAndroidInjector,
|
||||
rh: ResourceHelper,
|
||||
aapsLogger: AAPSLogger
|
||||
) : PluginBase(PluginDescription()
|
||||
.mainType(PluginType.BGSOURCE)
|
||||
.fragmentClass(BGSourceFragment::class.java.name)
|
||||
.pluginIcon((R.drawable.ic_blooddrop_48))
|
||||
.pluginName(R.string.aidex)
|
||||
.shortName(R.string.randombg_short)
|
||||
.description(R.string.description_source_aidex),
|
||||
aapsLogger, rh, injector
|
||||
), BgSource {
|
||||
|
||||
private var advancedFiltering = false
|
||||
|
||||
/**
|
||||
* Aidex App doesn't have upload to NS
|
||||
*/
|
||||
override fun shouldUploadToNs(glucoseValue: GlucoseValue): Boolean = true
|
||||
|
||||
override fun advancedFilteringSupported(): Boolean {
|
||||
return advancedFiltering
|
||||
}
|
||||
|
||||
// cannot be inner class because of needed injection
|
||||
class AidexWorker(
|
||||
context: Context,
|
||||
params: WorkerParameters
|
||||
) : Worker(context, params) {
|
||||
|
||||
@Inject lateinit var aapsLogger: AAPSLogger
|
||||
@Inject lateinit var aidexPlugin: AidexPlugin
|
||||
@Inject lateinit var repository: AppRepository
|
||||
@Inject lateinit var dataWorker: DataWorker
|
||||
|
||||
init {
|
||||
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
|
||||
}
|
||||
|
||||
override fun doWork(): Result {
|
||||
var ret = Result.success()
|
||||
|
||||
if (!aidexPlugin.isEnabled()) return Result.success(workDataOf("Result" to "Plugin not enabled"))
|
||||
val bundle = dataWorker.pickupBundle(inputData.getLong(DataWorker.STORE_KEY, -1))
|
||||
?: return Result.failure(workDataOf("Error" to "missing input data"))
|
||||
|
||||
aapsLogger.debug(LTag.BGSOURCE, "Received Aidex data: $bundle")
|
||||
|
||||
if (bundle.containsKey(Intents.AIDEX_TRANSMITTER_SN)) aapsLogger.debug(LTag.BGSOURCE, "transmitterSerialNumber: " + bundle.getString(Intents.AIDEX_TRANSMITTER_SN))
|
||||
if (bundle.containsKey(Intents.AIDEX_SENSOR_ID)) aapsLogger.debug(LTag.BGSOURCE, "sensorId: " + bundle.getString(Intents.AIDEX_SENSOR_ID))
|
||||
|
||||
val glucoseValues = mutableListOf<CgmSourceTransaction.TransactionGlucoseValue>()
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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) }
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -1222,4 +1222,10 @@
|
|||
<string name="hide_loop">Hide loop</string>
|
||||
<string name="show_loop">Show loop</string>
|
||||
<string name="count_selected">%1$d selected</string>
|
||||
<!-- Aidex Cgms -->
|
||||
<string name="aidex">GlucoRx Aidex</string>
|
||||
<string name="aidex_short">Aidex</string>
|
||||
<string name="description_source_aidex">Receive BG values from GlucoRx Aidex CGMS.</string>
|
||||
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -111,6 +111,7 @@ data class GlucoseValue(
|
|||
GLUNOVO_NATIVE("Glunovo"),
|
||||
MM_600_SERIES("MM600Series"),
|
||||
EVERSENSE("Eversense"),
|
||||
AIDEX("GlucoRx Aidex"),
|
||||
RANDOM("Random"),
|
||||
UNKNOWN("Unknown"),
|
||||
|
||||
|
|
Loading…
Reference in a new issue