Skip to content

Commit

Permalink
Merge pull request diyaps#15 from ottai-developer/master
Browse files Browse the repository at this point in the history
feat:Receive BG values from Ottai App.
  • Loading branch information
diyaps authored Jun 20, 2024
2 parents e6efdb0 + a5ce126 commit 70b3ac6
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
<action android:name="com.fanqies.tomatofn.BgEstimate" />
<!-- Receiver from GlucoRx Aidex -->
<action android:name="com.microtechmd.cgms.aidex.action.BgEstimate" />
<!-- Receiver from patched Ottai app -->
<action android:name="cn.diyaps.sharing.OT_APP" />
<!-- Receiver from patched SI app -->
<action android:name="cn.diyaps.sharing.SI_APP" />
<!-- Receiver from patched Sino app -->
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/kotlin/app/aaps/di/PluginsListModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import app.aaps.plugins.source.GlunovoPlugin
import app.aaps.plugins.source.IntelligoPlugin
import app.aaps.plugins.source.MM640gPlugin
import app.aaps.plugins.source.NSClientSourcePlugin
import app.aaps.plugins.source.PathedOTAppPlugin
import app.aaps.plugins.source.PathedSIAppPlugin
import app.aaps.plugins.source.PathedSinoAppPlugin
import app.aaps.plugins.source.PoctechPlugin
Expand Down Expand Up @@ -432,6 +433,12 @@ abstract class PluginsListModule {
@IntKey(470)
abstract fun bindGlunovoPlugin(plugin: GlunovoPlugin): PluginBase

@Binds
@AllConfigs
@IntoMap
@IntKey(666)
abstract fun bindPatchedOTAppPlugin(plugin: PathedOTAppPlugin): PluginBase

@Binds
@AllConfigs
@IntoMap
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/kotlin/app/aaps/receivers/DataReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import app.aaps.plugins.source.DexcomPlugin
import app.aaps.plugins.source.EversensePlugin
import app.aaps.plugins.source.GlimpPlugin
import app.aaps.plugins.source.MM640gPlugin
import app.aaps.plugins.source.PathedOTAppPlugin
import app.aaps.plugins.source.PathedSIAppPlugin
import app.aaps.plugins.source.PathedSinoAppPlugin
import app.aaps.plugins.source.PoctechPlugin
Expand Down Expand Up @@ -69,6 +70,12 @@ open class DataReceiver : DaggerBroadcastReceiver() {
it.copyString("collection", bundle)
it.copyString("data", bundle)
}.build()).build()
Intents.OTAPP_BG ->
OneTimeWorkRequest.Builder(PathedOTAppPlugin.PathedOTAppWorker::class.java)
.setInputData(Data.Builder().also {
it.copyString("collection", bundle)
it.copyString("data", bundle)
}.build()).build()
Intents.SIAPP_BG ->
OneTimeWorkRequest.Builder(PathedSIAppPlugin.PathedSIAppWorker::class.java)
.setInputData(Data.Builder().also {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ interface Intents {
var AIDEX_TRANSMITTER_SN = "com.microtechmd.cgms.aidex.TransmitterSerialNumber"
var AIDEX_SENSOR_ID = "com.microtechmd.cgms.aidex.SensorId"

// Patched Ottai App -> AAPS
const val OTAPP_BG = "cn.diyaps.sharing.OT_APP"

// Patched SI App -> AAPS
const val SIAPP_BG = "cn.diyaps.sharing.SI_APP"

Expand Down
Binary file added core/ui/src/main/res/mipmap-xhdpi/ottai_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ data class GlucoseValue(
MM_600_SERIES("MM600Series"),
EVERSENSE("Eversense"),
AIDEX("GlucoRx Aidex"),
OTApp("Ottai App"),
SIApp("SI App"),
SinoApp("SI App"),
RANDOM("Random"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package app.aaps.plugins.source

import android.content.Context
import androidx.work.WorkerParameters
import androidx.work.workDataOf
import app.aaps.core.interfaces.logging.AAPSLogger
import app.aaps.core.interfaces.logging.LTag
import app.aaps.core.interfaces.plugin.PluginBase
import app.aaps.core.interfaces.plugin.PluginDescription
import app.aaps.core.interfaces.plugin.PluginType
import app.aaps.core.interfaces.resources.ResourceHelper
import app.aaps.core.interfaces.source.BgSource
import app.aaps.core.interfaces.utils.DateUtil
import app.aaps.core.main.utils.worker.LoggingWorker
import app.aaps.database.entities.GlucoseValue
import app.aaps.database.impl.AppRepository
import app.aaps.database.impl.transactions.CgmSourceTransaction
import app.aaps.database.transactions.TransactionGlucoseValue
import dagger.android.HasAndroidInjector
import kotlinx.coroutines.Dispatchers
import org.json.JSONArray
import org.json.JSONException
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class PathedOTAppPlugin @Inject constructor(injector: HasAndroidInjector, rh: ResourceHelper, aapsLogger: AAPSLogger, )
: PluginBase(PluginDescription()
.mainType(PluginType.BGSOURCE)
.fragmentClass(BGSourceFragment::class.java.name)
.preferencesId(R.xml.pref_bgsource)
.pluginIcon(app.aaps.core.ui.R.mipmap.ottai_icon)
.pluginName(R.string.patched_ottai_app)
.description(R.string.description_source_patched_ottai_app),
aapsLogger, rh, injector), BgSource {

// cannot be inner class because of needed injection
class PathedOTAppWorker(context: Context, params: WorkerParameters) : LoggingWorker(context, params, Dispatchers.IO) {

@Inject lateinit var mOTAppPlugin: PathedOTAppPlugin
@Inject lateinit var injector: HasAndroidInjector
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var repository: AppRepository

init {
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
}

override suspend fun doWorkAndLog(): Result {
var ret = Result.success()
if (!mOTAppPlugin.isEnabled()) return Result.success()
val collection = inputData.getString("collection") ?: return Result.failure(workDataOf("Error" to "missing collection"))
if (collection == "entries") {
val data = inputData.getString("data")
aapsLogger.debug(LTag.BGSOURCE, "Received SI App Data: $data")
if (!data.isNullOrEmpty()) {
try {
val glucoseValues = mutableListOf<TransactionGlucoseValue>()
val jsonArray = JSONArray(data)
for (i in 0 until jsonArray.length()) {
val jsonObject = jsonArray.getJSONObject(i)
when (val type = jsonObject.getString("type")) {
"sgv" ->{
glucoseValues += TransactionGlucoseValue(
timestamp = jsonObject.getLong("date"),
value = jsonObject.getDouble("sgv"),
raw = jsonObject.getDouble("sgv"),
noise = null,
trendArrow = GlucoseValue.TrendArrow.fromString(jsonObject.getString("direction")),
sourceSensor = GlucoseValue.SourceSensor.OTApp)
}
else -> aapsLogger.debug(LTag.BGSOURCE, "Unknown entries type: $type")
}
}
repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null))
.doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving values from Ottai App", it)
ret = Result.failure(workDataOf("Error" to it.toString()))
}
.blockingGet()
.also { savedValues ->
savedValues.all().forEach {
aapsLogger.debug(LTag.DATABASE, "Inserted bg $it")
}
}
} catch (e: JSONException) {
aapsLogger.error("Exception: ", e)
ret = Result.failure(workDataOf("Error" to e.toString()))
}
}
}
return ret
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import app.aaps.plugins.source.EversensePlugin
import app.aaps.plugins.source.GlimpPlugin
import app.aaps.plugins.source.MM640gPlugin
import app.aaps.plugins.source.NSClientSourcePlugin
import app.aaps.plugins.source.PathedOTAppPlugin
import app.aaps.plugins.source.PathedSIAppPlugin
import app.aaps.plugins.source.PathedSinoAppPlugin
import app.aaps.plugins.source.PoctechPlugin
Expand All @@ -34,6 +35,7 @@ abstract class SourceModule {
@ContributesAndroidInjector abstract fun contributesXdripWorker(): XdripSourcePlugin.XdripSourceWorker
@ContributesAndroidInjector abstract fun contributesDexcomWorker(): DexcomPlugin.DexcomWorker
@ContributesAndroidInjector abstract fun contributesMM640gWorker(): MM640gPlugin.MM640gWorker
@ContributesAndroidInjector abstract fun contributesOTAppWorker(): PathedOTAppPlugin.PathedOTAppWorker
@ContributesAndroidInjector abstract fun contributesSIAppWorker(): PathedSIAppPlugin.PathedSIAppWorker
@ContributesAndroidInjector abstract fun contributesSinoAppWorker(): PathedSinoAppPlugin.PathedSinoAppWorker
@ContributesAndroidInjector abstract fun contributesGlimpWorker(): GlimpPlugin.GlimpWorker
Expand Down
3 changes: 3 additions & 0 deletions plugins/source/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<string name="aidex_short">Aidex动泰</string>
<string name="description_source_aidex">从GlucoRx Aidex动泰持续葡萄糖监测系统接收血糖值。</string>
<string name="bgsource_upload">血糖上传设置</string>
<!-- Patched OT App -->
<string name="patched_ottai_app">欧态-小欧生态</string>
<string name="description_source_patched_ottai_app">从欧态易测APP接收血糖值。</string>
<!-- Patched SI App -->
<string name="patched_si_app">X基补丁版</string>
<string name="description_source_patched_si_app">从X基补丁版App接收血糖值。</string>
Expand Down
3 changes: 3 additions & 0 deletions plugins/source/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<string name="dexcom_log_ns_sensor_change_summary">Create event \"Sensor Change\" in NS automatically on sensor start</string>
<string name="direction">direction</string>

<!-- Patched OT App -->
<string name="patched_ottai_app">欧态-小欧生态</string>
<string name="description_source_patched_ottai_app">从欧态易测APP接收血糖值。</string>
<!-- Patched SI and Sino App -->
<string name="patched_si_app">Patched SI App</string>
<string name="patched_sino_app">Patched Sino App</string>
Expand Down

0 comments on commit 70b3ac6

Please sign in to comment.