Merge branch 'dev' of github.com:MilosKozak/AndroidAPS into carbs-required

This commit is contained in:
Tim Gunn 2020-05-20 00:09:57 +12:00
commit 3ae1bb669d
No known key found for this signature in database
GPG key ID: C9BC1E9D0D0AED8C
11 changed files with 113 additions and 55 deletions

View file

@ -64,7 +64,7 @@ abstract class PluginsModule {
abstract fun bindIobCobCalculatorPlugin(plugin: IobCobCalculatorPlugin): PluginBase abstract fun bindIobCobCalculatorPlugin(plugin: IobCobCalculatorPlugin): PluginBase
@Binds @Binds
@NotNSClient @AllConfigs
@IntoMap @IntoMap
@IntKey(20) @IntKey(20)
abstract fun bindActionsPlugin(plugin: ActionsPlugin): PluginBase abstract fun bindActionsPlugin(plugin: ActionsPlugin): PluginBase

View file

@ -49,7 +49,8 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
@Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var defaultValueHelper: DefaultValueHelper @Inject lateinit var defaultValueHelper: DefaultValueHelper
@Inject lateinit var iobCobStaticCalculatorPlugin: IobCobStaticCalculatorPlugin @Inject lateinit var iobCobCalculatorPluginHistory: IobCobCalculatorPluginHistory
@Inject lateinit var treatmentsPluginHistory: TreatmentsPluginHistory
@Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var buildHelper: BuildHelper @Inject lateinit var buildHelper: BuildHelper
@Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var fabricPrivacy: FabricPrivacy
@ -148,7 +149,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
public override fun onPause() { public override fun onPause() {
super.onPause() super.onPause()
disposable.clear() disposable.clear()
iobCobStaticCalculatorPlugin.stopCalculation("onPause") iobCobCalculatorPluginHistory.stopCalculation("onPause")
} }
public override fun onResume() { public override fun onResume() {
@ -157,7 +158,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
.toObservable(EventAutosensCalculationFinished::class.java) .toObservable(EventAutosensCalculationFinished::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ event: EventAutosensCalculationFinished -> .subscribe({ event: EventAutosensCalculationFinished ->
// catch only events from iobCobStaticCalculatorPlugin // catch only events from iobCobCalculatorPluginHistory
if (event.cause === eventCustomCalculationFinished) { if (event.cause === eventCustomCalculationFinished) {
aapsLogger.debug(LTag.AUTOSENS, "EventAutosensCalculationFinished") aapsLogger.debug(LTag.AUTOSENS, "EventAutosensCalculationFinished")
updateGUI("EventAutosensCalculationFinished") updateGUI("EventAutosensCalculationFinished")
@ -220,10 +221,11 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
} }
private fun runCalculation(from: String) { private fun runCalculation(from: String) {
treatmentsPluginHistory.initializeData(start - T.hours(8).msecs())
val end = start + T.hours(rangeToDisplay.toLong()).msecs() val end = start + T.hours(rangeToDisplay.toLong()).msecs()
iobCobStaticCalculatorPlugin.stopCalculation(from) iobCobCalculatorPluginHistory.stopCalculation(from)
iobCobStaticCalculatorPlugin.clearCache() iobCobCalculatorPluginHistory.clearCache()
iobCobStaticCalculatorPlugin.runCalculation(from, end, true, false, eventCustomCalculationFinished) iobCobCalculatorPluginHistory.runCalculation(from, end, true, false, eventCustomCalculationFinished)
} }
@Synchronized @Synchronized
@ -242,7 +244,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
GlobalScope.launch(Dispatchers.Main) { GlobalScope.launch(Dispatchers.Main) {
historybrowse_bggraph ?: return@launch historybrowse_bggraph ?: return@launch
val graphData = GraphData(injector, historybrowse_bggraph, iobCobStaticCalculatorPlugin) val graphData = GraphData(injector, historybrowse_bggraph, iobCobCalculatorPluginHistory, treatmentsPluginHistory)
val secondaryGraphsData: ArrayList<GraphData> = ArrayList() val secondaryGraphsData: ArrayList<GraphData> = ArrayList()
// do preparation in different thread // do preparation in different thread
@ -279,7 +281,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
// ------------------ 2nd graph // ------------------ 2nd graph
for (g in 0 until secondaryGraphs.size) { for (g in 0 until secondaryGraphs.size) {
val secondGraphData = GraphData(injector, secondaryGraphs[g], iobCobStaticCalculatorPlugin) val secondGraphData = GraphData(injector, secondaryGraphs[g], iobCobCalculatorPluginHistory, treatmentsPluginHistory)
var useIobForScale = false var useIobForScale = false
var useCobForScale = false var useCobForScale = false
var useDevForScale = false var useDevForScale = false

View file

@ -9,7 +9,6 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorP
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
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.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -18,7 +17,7 @@ import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@Singleton @Singleton
class IobCobStaticCalculatorPlugin @Inject constructor( class IobCobCalculatorPluginHistory @Inject constructor(
injector: HasAndroidInjector, injector: HasAndroidInjector,
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
rxBus: RxBusWrapper, rxBus: RxBusWrapper,
@ -26,14 +25,14 @@ class IobCobStaticCalculatorPlugin @Inject constructor(
resourceHelper: ResourceHelper, resourceHelper: ResourceHelper,
profileFunction: ProfileFunction, profileFunction: ProfileFunction,
activePlugin: ActivePluginProvider, activePlugin: ActivePluginProvider,
treatmentsPlugin: TreatmentsPlugin, treatmentsPluginHistory: TreatmentsPluginHistory,
sensitivityOref1Plugin: SensitivityOref1Plugin, sensitivityOref1Plugin: SensitivityOref1Plugin,
sensitivityAAPSPlugin: SensitivityAAPSPlugin, sensitivityAAPSPlugin: SensitivityAAPSPlugin,
sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin, sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin,
fabricPrivacy: FabricPrivacy, fabricPrivacy: FabricPrivacy,
dateUtil: DateUtil dateUtil: DateUtil
) : IobCobCalculatorPlugin(injector, aapsLogger, rxBus, sp, resourceHelper, profileFunction, ) : IobCobCalculatorPlugin(injector, aapsLogger, rxBus, sp, resourceHelper, profileFunction,
activePlugin, treatmentsPlugin, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin, fabricPrivacy, dateUtil) { activePlugin, treatmentsPluginHistory, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin, fabricPrivacy, dateUtil) {
override fun onStart() { // do not attach to rxbus override fun onStart() { // do not attach to rxbus
} }

View file

@ -0,0 +1,41 @@
package info.nightscout.androidaps.historyBrowser
import android.content.Context
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
import info.nightscout.androidaps.plugins.treatments.TreatmentService
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class TreatmentsPluginHistory @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
rxBus: RxBusWrapper,
resourceHelper: ResourceHelper,
context: Context,
sp: SP,
profileFunction: ProfileFunction,
activePlugin: ActivePluginProvider,
nsUpload: NSUpload,
fabricPrivacy: FabricPrivacy, dateUtil: DateUtil
) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, context, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil) {
init {
onStart()
}
override fun onStart() {
service = TreatmentService(injector)
initializeData(range())
}
}

View file

@ -18,9 +18,9 @@ import info.nightscout.androidaps.events.*
import info.nightscout.androidaps.historyBrowser.HistoryBrowseActivity import info.nightscout.androidaps.historyBrowser.HistoryBrowseActivity
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction
import info.nightscout.androidaps.plugins.general.overview.StatusLightHandler import info.nightscout.androidaps.plugins.general.overview.StatusLightHandler
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
@ -192,17 +192,15 @@ class ActionsFragment : DaggerFragment() {
@Synchronized @Synchronized
fun updateGui() { fun updateGui() {
actions_profileswitch?.visibility = (activePlugin.activeProfileInterface.profile != null).toVisibility()
val profile = profileFunction.getProfile() val profile = profileFunction.getProfile()
val pump = activePlugin.activePump val pump = activePlugin.activePump
actions_temptarget?.visibility = (profile != null).toVisibility() actions_profileswitch?.visibility = (
actions_historybrowser.visibility = (profile != null).toVisibility() activePlugin.activeProfileInterface.profile != null &&
pump.pumpDescription.isSetBasalProfileCapable &&
val basalProfileEnabled = buildHelper.isEngineeringModeOrRelease() && pump.pumpDescription.isSetBasalProfileCapable pump.isInitialized &&
!pump.isSuspended).toVisibility()
actions_profileswitch?.visibility = if (!basalProfileEnabled || !pump.isInitialized || pump.isSuspended) View.GONE else View.VISIBLE
if (!pump.pumpDescription.isExtendedBolusCapable || !pump.isInitialized || pump.isSuspended || pump.isFakingTempsByExtendedBoluses) { if (!pump.pumpDescription.isExtendedBolusCapable || !pump.isInitialized || pump.isSuspended || pump.isFakingTempsByExtendedBoluses) {
actions_extendedbolus?.visibility = View.GONE actions_extendedbolus?.visibility = View.GONE
@ -236,12 +234,11 @@ class ActionsFragment : DaggerFragment() {
} }
} }
actions_fill?.visibility = actions_historybrowser.visibility = (profile != null).toVisibility()
if (!pump.pumpDescription.isRefillingCapable || !pump.isInitialized || pump.isSuspended) View.GONE actions_fill?.visibility = (pump.pumpDescription.isRefillingCapable && pump.isInitialized && !pump.isSuspended).toVisibility()
else View.VISIBLE actions_temptarget?.visibility = (profile != null && config.APS).toVisibility()
actions_temptarget?.visibility = config.APS.toVisibility()
actions_tddstats?.visibility = pump.pumpDescription.supportsTDDs.toVisibility() actions_tddstats?.visibility = pump.pumpDescription.supportsTDDs.toVisibility()
statusLightHandler.updateStatusLights(careportal_canulaage, careportal_insulinage, null, careportal_sensorage, careportal_pbage, null) statusLightHandler.updateStatusLights(careportal_canulaage, careportal_insulinage, null, careportal_sensorage, careportal_pbage, null)
checkPumpCustomActions() checkPumpCustomActions()
} }

View file

@ -485,11 +485,11 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
overview_iobgraph.removeAllViews() overview_iobgraph.removeAllViews()
for (i in 1 until numOfGraphs) { for (i in 1 until numOfGraphs) {
val label = TextView(context) val label = TextView(context)
label.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT).also { it.setMargins(100, 0, 0, -90) } label.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT).also { it.setMargins(100, 0, 0, -120) }
overview_iobgraph.addView(label) overview_iobgraph.addView(label)
secondaryGraphsLabel.add(label) secondaryGraphsLabel.add(label)
val graph = GraphView(context) val graph = GraphView(context)
graph.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, resourceHelper.dpToPx(100)).also { it.setMargins(0, resourceHelper.dpToPx(5), 0, resourceHelper.dpToPx(10)) } graph.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, resourceHelper.dpToPx(100)).also { it.setMargins(0, resourceHelper.dpToPx(35), 0, resourceHelper.dpToPx(15)) }
graph.gridLabelRenderer?.gridColor = resourceHelper.gc(R.color.graphgrid) graph.gridLabelRenderer?.gridColor = resourceHelper.gc(R.color.graphgrid)
graph.gridLabelRenderer?.reloadStyles() graph.gridLabelRenderer?.reloadStyles()
graph.gridLabelRenderer?.isHorizontalLabelsVisible = false graph.gridLabelRenderer?.isHorizontalLabelsVisible = false
@ -790,7 +790,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
// ****** GRAPH ******* // ****** GRAPH *******
GlobalScope.launch(Dispatchers.Main) { GlobalScope.launch(Dispatchers.Main) {
overview_bggraph ?: return@launch overview_bggraph ?: return@launch
val graphData = GraphData(injector, overview_bggraph, iobCobCalculatorPlugin) val graphData = GraphData(injector, overview_bggraph, iobCobCalculatorPlugin, treatmentsPlugin)
val secondaryGraphsData: ArrayList<GraphData> = ArrayList() val secondaryGraphsData: ArrayList<GraphData> = ArrayList()
// do preparation in different thread // do preparation in different thread
@ -853,7 +853,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
// ------------------ 2nd graph // ------------------ 2nd graph
for (g in 0 until secondaryGraphs.size) { for (g in 0 until secondaryGraphs.size) {
val secondGraphData = GraphData(injector, secondaryGraphs[g], iobCobCalculatorPlugin) val secondGraphData = GraphData(injector, secondaryGraphs[g], iobCobCalculatorPlugin, treatmentsPlugin)
var useIobForScale = false var useIobForScale = false
var useCobForScale = false var useCobForScale = false
var useDevForScale = false var useDevForScale = false

View file

@ -34,7 +34,13 @@ import kotlin.math.abs
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
class GraphData(injector: HasAndroidInjector, private val graph: GraphView, private val iobCobCalculatorPlugin: IobCobCalculatorPlugin) { class GraphData(
injector: HasAndroidInjector,
private val graph: GraphView,
private val iobCobCalculatorPlugin: IobCobCalculatorPlugin,
private val treatmentsPlugin: TreatmentsInterface
) {
// IobCobCalculatorPlugin Cannot be injected: HistoryBrowser // IobCobCalculatorPlugin Cannot be injected: HistoryBrowser
@Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var aapsLogger: AAPSLogger
@ -42,8 +48,6 @@ class GraphData(injector: HasAndroidInjector, private val graph: GraphView, priv
@Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var activePlugin: ActivePluginProvider
private val treatmentsPlugin: TreatmentsInterface
var maxY = Double.MIN_VALUE var maxY = Double.MIN_VALUE
private var minY = Double.MAX_VALUE private var minY = Double.MAX_VALUE
private var bgReadingsArray: List<BgReading>? = null private var bgReadingsArray: List<BgReading>? = null
@ -53,7 +57,6 @@ class GraphData(injector: HasAndroidInjector, private val graph: GraphView, priv
init { init {
injector.androidInjector().inject(this) injector.androidInjector().inject(this)
units = profileFunction.getUnits() units = profileFunction.getUnits()
treatmentsPlugin = activePlugin.activeTreatments
} }
@Suppress("UNUSED_PARAMETER") @Suppress("UNUSED_PARAMETER")

View file

@ -57,7 +57,7 @@ class NotificationWithAction constructor(
id = NSURGENTALARM id = NSURGENTALARM
level = URGENT level = URGENT
text = nsAlarm.title() text = nsAlarm.title()
if (nsAlarm.low() && sp.getBoolean(R.string.key_nsalarm_low, false) || nsAlarm.high() && sp.getBoolean(R.string.key_nsalarm_high, false) || nsAlarm.timeago() && sp.getBoolean(R.string.key_nsalarm_staledata, false)) soundId = R.raw.urgentalarm if (nsAlarm.low() && sp.getBoolean(R.string.key_nsalarm_urgent_low, false) || nsAlarm.high() && sp.getBoolean(R.string.key_nsalarm_urgent_high, false) || nsAlarm.timeago() && sp.getBoolean(R.string.key_nsalarm_staledata, false)) soundId = R.raw.urgentalarm
} }
} }
buttonText = R.string.snooze buttonText = R.string.snooze

View file

@ -86,7 +86,7 @@ class ActionStringHandler @Inject constructor(
var rMessage = "" var rMessage = ""
var rAction = "" var rAction = ""
// do the parsing and check constraints // do the parsing and check constraints
val act = actionString.split("\\s+").toTypedArray() val act = actionString.split("\\s+".toRegex()).toTypedArray()
if ("fillpreset" == act[0]) { ///////////////////////////////////// PRIME/FILL if ("fillpreset" == act[0]) { ///////////////////////////////////// PRIME/FILL
val amount: Double = if ("1" == act[1]) { val amount: Double = if ("1" == act[1]) {
sp.getDouble("fill_button1", 0.3) sp.getDouble("fill_button1", 0.3)
@ -470,7 +470,7 @@ class ActionStringHandler @Inject constructor(
if (System.currentTimeMillis() - lastSentTimestamp > TIMEOUT) return if (System.currentTimeMillis() - lastSentTimestamp > TIMEOUT) return
lastConfirmActionString = null lastConfirmActionString = null
// do the parsing, check constraints and enact! // do the parsing, check constraints and enact!
val act = actionString.split("\\s+").toTypedArray() val act = actionString.split("\\s+".toRegex()).toTypedArray()
if ("fill" == act[0]) { if ("fill" == act[0]) {
val amount = SafeParse.stringToDouble(act[1]) val amount = SafeParse.stringToDouble(act[1])
val insulinAfterConstraints = constraintChecker.applyBolusConstraints(Constraint(amount)).value() val insulinAfterConstraints = constraintChecker.applyBolusConstraints(Constraint(amount)).value()

View file

@ -178,7 +178,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
return this.service; return this.service;
} }
private long range() { protected long range() {
double dia = Constants.defaultDIA; double dia = Constants.defaultDIA;
if (profileFunction.getProfile() != null) if (profileFunction.getProfile() != null)
dia = profileFunction.getProfile().getDia(); dia = profileFunction.getProfile().getDia();

View file

@ -1,12 +1,12 @@
package info.nightscout.androidaps.danars.comm package info.nightscout.androidaps.danars.comm
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.dana.comm.RecordTypes
import info.nightscout.androidaps.db.DanaRHistoryRecord import info.nightscout.androidaps.db.DanaRHistoryRecord
import info.nightscout.androidaps.events.EventDanaRSyncStatus
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.dana.comm.RecordTypes
import info.nightscout.androidaps.events.EventDanaRSyncStatus
import org.joda.time.DateTime import org.joda.time.DateTime
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
@ -83,20 +83,17 @@ abstract class DanaRS_Packet_History_(
val historySecond = byteArrayToInt(getBytes(data, DATA_START + 6, 1)) val historySecond = byteArrayToInt(getBytes(data, DATA_START + 6, 1))
val paramByte7 = historySecond.toByte() val paramByte7 = historySecond.toByte()
val dailyBolus: Double = ((data[DATA_START + 6].toInt() and 0xFF shl 8) + (data[DATA_START + 7].toInt() and 0xFF)) * 0.01 val dailyBolus: Double = ((data[DATA_START + 6].toInt() and 0xFF shl 8) + (data[DATA_START + 7].toInt() and 0xFF)) * 0.01
val date = DateTime(2000 + historyYear, historyMonth, historyDay, 0, 0)
val datetime = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute)
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
val historyCode = byteArrayToInt(getBytes(data, DATA_START + 7, 1)) val historyCode = byteArrayToInt(getBytes(data, DATA_START + 7, 1))
val paramByte8 = historyCode.toByte() val paramByte8 = historyCode.toByte()
val value: Int = (data[DATA_START + 8].toInt() and 0xFF shl 8) + (data[DATA_START + 9].toInt() and 0xFF) val value: Int = (data[DATA_START + 8].toInt() and 0xFF shl 8) + (data[DATA_START + 9].toInt() and 0xFF)
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
danaRHistoryRecord.setBytes(data) danaRHistoryRecord.setBytes(data)
// danaRHistoryRecord.recordCode is different from DanaR codes // danaRHistoryRecord.recordCode is different from DanaR codes
// set in switch for every type // set in switch for every type
var messageType = "" var messageType = ""
when (recordCode) { when (recordCode) {
0x02 -> { 0x02 -> {
danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_BOLUS danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_BOLUS
val datetime = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute)
danaRHistoryRecord.recordDate = datetime.millis danaRHistoryRecord.recordDate = datetime.millis
when (0xF0 and paramByte8.toInt()) { when (0xF0 and paramByte8.toInt()) {
0xA0 -> { 0xA0 -> {
@ -123,61 +120,77 @@ abstract class DanaRS_Packet_History_(
} }
danaRHistoryRecord.recordDuration = (paramByte8.toInt() and 0x0F) * 60 + paramByte7.toInt() danaRHistoryRecord.recordDuration = (paramByte8.toInt() and 0x0F) * 60 + paramByte7.toInt()
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetime.millis) + " Code: " + historyCode + " Value: " + value)
} }
0x03 -> { 0x03 -> {
danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_DAILY danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_DAILY
messageType += "dailyinsulin" messageType += "dailyinsulin"
val date = DateTime(2000 + historyYear, historyMonth, historyDay, 0, 0)
danaRHistoryRecord.recordDate = date.millis danaRHistoryRecord.recordDate = date.millis
danaRHistoryRecord.recordDailyBasal = dailyBasal danaRHistoryRecord.recordDailyBasal = dailyBasal
danaRHistoryRecord.recordDailyBolus = dailyBolus danaRHistoryRecord.recordDailyBolus = dailyBolus
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(date.millis) + " Code: " + historyCode + " Value: " + value)
} }
0x04 -> { 0x04 -> {
danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_PRIME danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_PRIME
messageType += "prime" messageType += "prime"
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordDate = datetimewihtsec.millis
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
} }
0x05 -> { 0x05 -> {
danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_REFILL danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_REFILL
messageType += "refill" messageType += "refill"
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordDate = datetimewihtsec.millis
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
} }
0x0b -> { 0x0b -> {
danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_BASALHOUR danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_BASALHOUR
messageType += "basal hour" messageType += "basal hour"
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordDate = datetimewihtsec.millis
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
} }
0x99 -> { 0x99 -> {
danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_TEMP_BASAL danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_TEMP_BASAL
messageType += "tb" messageType += "tb"
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordDate = datetimewihtsec.millis
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
} }
0x06 -> { 0x06 -> {
danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_GLUCOSE danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_GLUCOSE
messageType += "glucose" messageType += "glucose"
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordDate = datetimewihtsec.millis
danaRHistoryRecord.recordValue = value.toDouble() danaRHistoryRecord.recordValue = value.toDouble()
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
} }
0x07 -> { 0x07 -> {
danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_CARBO danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_CARBO
messageType += "carbo" messageType += "carbo"
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordDate = datetimewihtsec.millis
danaRHistoryRecord.recordValue = value.toDouble() danaRHistoryRecord.recordValue = value.toDouble()
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
} }
0x0a -> { 0x0a -> {
danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_ALARM danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_ALARM
messageType += "alarm" messageType += "alarm"
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordDate = datetimewihtsec.millis
var strAlarm = "None" var strAlarm = "None"
when (paramByte8.toInt()) { when (paramByte8.toInt()) {
@ -188,15 +201,18 @@ abstract class DanaRS_Packet_History_(
} }
danaRHistoryRecord.recordAlarm = strAlarm danaRHistoryRecord.recordAlarm = strAlarm
danaRHistoryRecord.recordValue = value * 0.01 danaRHistoryRecord.recordValue = value * 0.01
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
} }
0x09 -> { 0x09 -> {
danaRHistoryRecord.recordCode = info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_SUSPEND danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_SUSPEND
messageType += "suspend" messageType += "suspend"
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
danaRHistoryRecord.recordDate = datetimewihtsec.millis danaRHistoryRecord.recordDate = datetimewihtsec.millis
var strRecordValue = "Off" var strRecordValue = "Off"
if (paramByte8.toInt() == 79) strRecordValue = "On" if (paramByte8.toInt() == 79) strRecordValue = "On"
danaRHistoryRecord.stringRecordValue = strRecordValue danaRHistoryRecord.stringRecordValue = strRecordValue
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
} }
} }
databaseHelper.createOrUpdate(danaRHistoryRecord) databaseHelper.createOrUpdate(danaRHistoryRecord)