diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/sync/NsClient.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/sync/NsClient.kt index 9b53c5f59b..6ef90a7c02 100644 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/sync/NsClient.kt +++ b/core/interfaces/src/main/java/info/nightscout/interfaces/sync/NsClient.kt @@ -11,7 +11,6 @@ interface NsClient : Sync { val version: Version val address: String - val nsClientService: NSClientService? fun pause(newState: Boolean) fun resend(reason: String) @@ -24,9 +23,6 @@ interface NsClient : Sync { fun resetToFullSync() - interface NSClientService { - - fun dbAdd(collection: String, data: JSONObject, originalObject: Any, progress: String) - fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any, progress: String) - } + fun dbAdd(collection: String, data: JSONObject, originalObject: Any, progress: String) + fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any, progress: String) } \ No newline at end of file diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/NSAndroidClientImpl.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/NSAndroidClientImpl.kt index 4a5b3ffa10..183c8e09ca 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/NSAndroidClientImpl.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/NSAndroidClientImpl.kt @@ -3,12 +3,16 @@ package info.nightscout.sdk import android.content.Context import info.nightscout.sdk.exceptions.DateHeaderOutOfToleranceException import info.nightscout.sdk.exceptions.InvalidAccessTokenException +import info.nightscout.sdk.exceptions.InvalidFormatNightscoutException import info.nightscout.sdk.exceptions.TodoNightscoutException +import info.nightscout.sdk.exceptions.UnknownResponseNightscoutException import info.nightscout.sdk.interfaces.NSAndroidClient import info.nightscout.sdk.localmodel.Status import info.nightscout.sdk.localmodel.entry.NSSgvV3 +import info.nightscout.sdk.localmodel.treatment.CreateUpdateResponse import info.nightscout.sdk.localmodel.treatment.NSTreatment import info.nightscout.sdk.mapper.toLocal +import info.nightscout.sdk.mapper.toRemoteTreatment import info.nightscout.sdk.mapper.toSgv import info.nightscout.sdk.mapper.toTreatment import info.nightscout.sdk.networking.NetworkStackBuilder @@ -58,6 +62,8 @@ class NSAndroidClientImpl( accessToken = accessToken, logging = logging ) + override var lastStatus: Status? = null + private set /* * TODO: how should our result look like? @@ -81,7 +87,7 @@ class NSAndroidClientImpl( } override suspend fun getStatus(): Status = callWrapper(dispatcher) { - api.statusSimple().result!!.toLocal() + api.statusSimple().result!!.toLocal().also { lastStatus = it } } // TODO: return something better than a String @@ -152,6 +158,22 @@ class NSAndroidClientImpl( } } + override suspend fun createTreatment(nsTreatment: NSTreatment): CreateUpdateResponse = callWrapper(dispatcher) { + + val remoteTreatment = nsTreatment.toRemoteTreatment() ?: throw InvalidFormatNightscoutException() + val response = api.createTreatment(remoteTreatment) + if (response.isSuccessful) { + return@callWrapper CreateUpdateResponse( + identifier = response.body()?.result?.identifier ?: throw UnknownResponseNightscoutException(), + isDeduplication = response.body()?.result?.isDeduplication ?: false, + deduplicatedIdentifier = response.body()?.result?.deduplicatedIdentifier, + lastModified = response.body()?.result?.lastModified + ) + } else { + throw TodoNightscoutException() // TODO: react to response errors (offline, ...) + } + } + private suspend fun callWrapper(dispatcher: CoroutineDispatcher, block: suspend () -> T): T = withContext(dispatcher) { retry( diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/exceptions/InvalidFormatNightscoutException.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/exceptions/InvalidFormatNightscoutException.kt new file mode 100644 index 0000000000..80ab0f019e --- /dev/null +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/exceptions/InvalidFormatNightscoutException.kt @@ -0,0 +1,3 @@ +package info.nightscout.sdk.exceptions + +class InvalidFormatNightscoutException : NightscoutException() diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/exceptions/UnknownResponseNightscoutException.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/exceptions/UnknownResponseNightscoutException.kt new file mode 100644 index 0000000000..f706d499b9 --- /dev/null +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/exceptions/UnknownResponseNightscoutException.kt @@ -0,0 +1,3 @@ +package info.nightscout.sdk.exceptions + +class UnknownResponseNightscoutException : NightscoutException() diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/interfaces/NSAndroidClient.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/interfaces/NSAndroidClient.kt index 918f4e8538..bfb07f1490 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/interfaces/NSAndroidClient.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/interfaces/NSAndroidClient.kt @@ -2,12 +2,14 @@ package info.nightscout.sdk.interfaces import info.nightscout.sdk.localmodel.Status import info.nightscout.sdk.localmodel.entry.NSSgvV3 +import info.nightscout.sdk.localmodel.treatment.CreateUpdateResponse import info.nightscout.sdk.localmodel.treatment.NSTreatment import info.nightscout.sdk.remotemodel.LastModified import info.nightscout.sdk.remotemodel.RemoteDeviceStatus interface NSAndroidClient { + val lastStatus: Status? suspend fun getVersion(): String suspend fun getStatus(): Status suspend fun getEntries(): String @@ -18,4 +20,5 @@ interface NSAndroidClient { suspend fun getSgvsNewerThan(from: Long, limit: Long): List suspend fun getTreatmentsModifiedSince(from: Long, limit: Long): List suspend fun getDeviceStatusModifiedSince(from: Long): List + suspend fun createTreatment(NsTreatment: NSTreatment): CreateUpdateResponse } \ No newline at end of file diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/ApiPermissions.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/ApiPermissions.kt index d78861667a..5eaa012fde 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/ApiPermissions.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/ApiPermissions.kt @@ -7,4 +7,7 @@ data class ApiPermissions( val profile: ApiPermission, val settings: ApiPermission, val treatments: ApiPermission -) +) { + fun isFull() = deviceStatus.full && entries.full && food.full && profile.full && settings.full && treatments.full + fun isRead() = deviceStatus.read && entries.read && food.read && profile.read && settings.read && treatments.read +} diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/CreateUpdateResponse.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/CreateUpdateResponse.kt new file mode 100644 index 0000000000..ad7a3835a2 --- /dev/null +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/CreateUpdateResponse.kt @@ -0,0 +1,8 @@ +package info.nightscout.sdk.localmodel.treatment + +class CreateUpdateResponse( + val identifier: String?, + val isDeduplication: Boolean? = false, + val deduplicatedIdentifier: String? = null, + val lastModified: Long? = null +) \ No newline at end of file diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSBolus.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSBolus.kt index 76d482f222..dbc9f63408 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSBolus.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSBolus.kt @@ -7,8 +7,8 @@ data class NSBolus( override val device: String?, override val identifier: String, override val units: NsUnits?, - override val srvModified: Long, - override val srvCreated: Long, + override val srvModified: Long?, + override val srvCreated: Long?, override val utcOffset: Long, override val subject: String?, override var isReadOnly: Boolean, diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSBolusWizard.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSBolusWizard.kt index 11a1ab3a48..d192577c70 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSBolusWizard.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSBolusWizard.kt @@ -8,8 +8,8 @@ data class NSBolusWizard( override val device: String?, override val identifier: String, override val units: NsUnits?, - override val srvModified: Long, - override val srvCreated: Long, + override val srvModified: Long?, + override val srvCreated: Long?, override val utcOffset: Long, override val subject: String?, override var isReadOnly: Boolean, diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSCarbs.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSCarbs.kt index 9f3dd66be2..b3069a4a1d 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSCarbs.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSCarbs.kt @@ -7,8 +7,8 @@ data class NSCarbs( override val device: String?, override val identifier: String, override val units: NsUnits?, - override val srvModified: Long, - override val srvCreated: Long, + override val srvModified: Long?, + override val srvCreated: Long?, override val utcOffset: Long, override val subject: String?, override var isReadOnly: Boolean, diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSEffectiveProfileSwitch.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSEffectiveProfileSwitch.kt index 4fa8b1e322..731048b678 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSEffectiveProfileSwitch.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSEffectiveProfileSwitch.kt @@ -8,8 +8,8 @@ data class NSEffectiveProfileSwitch( override val device: String?, override val identifier: String, override val units: NsUnits?, - override val srvModified: Long, - override val srvCreated: Long, + override val srvModified: Long?, + override val srvCreated: Long?, override val utcOffset: Long, override val subject: String?, override var isReadOnly: Boolean, diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSExtendedBolus.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSExtendedBolus.kt index 0fc041d9e5..cb179b70d2 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSExtendedBolus.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSExtendedBolus.kt @@ -7,8 +7,8 @@ data class NSExtendedBolus( override val device: String?, override val identifier: String, override val units: NsUnits?, - override val srvModified: Long, - override val srvCreated: Long, + override val srvModified: Long?, + override val srvCreated: Long?, override val utcOffset: Long, override val subject: String?, override var isReadOnly: Boolean, @@ -21,5 +21,5 @@ data class NSExtendedBolus( override val pumpSerial: String?, val duration: Long, val enteredinsulin: Double, - val isEmulatingTempbasal: Boolean + val isEmulatingTempBasal: Boolean? ) : NSTreatment diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSOfflineEvent.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSOfflineEvent.kt index 1abffef44c..1d64e0c6cd 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSOfflineEvent.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSOfflineEvent.kt @@ -7,8 +7,8 @@ data class NSOfflineEvent( override val device: String?, override val identifier: String, override val units: NsUnits?, - override val srvModified: Long, - override val srvCreated: Long, + override val srvModified: Long?, + override val srvCreated: Long?, override val utcOffset: Long, override val subject: String?, override var isReadOnly: Boolean, diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSProfileSwitch.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSProfileSwitch.kt index c97e5de38c..d36056eebd 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSProfileSwitch.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSProfileSwitch.kt @@ -8,8 +8,8 @@ data class NSProfileSwitch( override val device: String?, override val identifier: String, override val units: NsUnits?, - override val srvModified: Long, - override val srvCreated: Long, + override val srvModified: Long?, + override val srvCreated: Long?, override val utcOffset: Long, override val subject: String?, override var isReadOnly: Boolean, diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTemporaryBasal.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTemporaryBasal.kt index 8a025e7097..b3dabf908a 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTemporaryBasal.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTemporaryBasal.kt @@ -8,8 +8,8 @@ data class NSTemporaryBasal( override val device: String?, override val identifier: String, override val units: NsUnits?, - override val srvModified: Long, - override val srvCreated: Long, + override val srvModified: Long?, + override val srvCreated: Long?, override val utcOffset: Long, override val subject: String?, override var isReadOnly: Boolean, @@ -21,9 +21,11 @@ data class NSTemporaryBasal( override val pumpType: String?, override val pumpSerial: String?, val duration: Long, - val rate: Double, + val rate: Double, // when sending to NS always convertedToAbsolute(timestamp, profile) val isAbsolute: Boolean, - val type: Type + val type: Type, + val percent: Double? = null, // when sending to NS (rate - 100) + val absolute: Double? = null // when sending to NS (rate) ) : NSTreatment { enum class Type { diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTemporaryTarget.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTemporaryTarget.kt index c4a03bca18..77276096db 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTemporaryTarget.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTemporaryTarget.kt @@ -7,8 +7,8 @@ data class NSTemporaryTarget( override val device: String?, override val identifier: String, override val units: NsUnits?, - override val srvModified: Long, - override val srvCreated: Long, + override val srvModified: Long?, + override val srvCreated: Long?, override val utcOffset: Long, override val subject: String?, override var isReadOnly: Boolean, diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTherapyEvent.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTherapyEvent.kt index 503c9ee65f..1fe671107c 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTherapyEvent.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTherapyEvent.kt @@ -8,8 +8,8 @@ data class NSTherapyEvent( override val device: String?, override val identifier: String, override val units: NsUnits?, - override val srvModified: Long, - override val srvCreated: Long, + override val srvModified: Long?, + override val srvCreated: Long?, override val utcOffset: Long, override val subject: String?, override var isReadOnly: Boolean, diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTreatment.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTreatment.kt index f522b0673c..04a10c17eb 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTreatment.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSTreatment.kt @@ -8,8 +8,8 @@ interface NSTreatment { val identifier: String val units: NsUnits? val eventType: EventType - val srvModified: Long - val srvCreated: Long + val srvModified: Long? + val srvCreated: Long? val utcOffset: Long val subject: String? var isReadOnly: Boolean diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/mapper/TreatmentMapper.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/mapper/TreatmentMapper.kt index 7af6badcbb..47cb5e7b2a 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/mapper/TreatmentMapper.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/mapper/TreatmentMapper.kt @@ -117,7 +117,7 @@ internal fun RemoteTreatment.toTreatment(): NSTreatment? { pumpSerial = extendedEmulated.pumpSerial, enteredinsulin = extendedEmulated.enteredinsulin ?: 0.0, duration = extendedEmulated.durationInMilliseconds ?: TimeUnit.MINUTES.toMillis(extendedEmulated.duration ?: 0L), - isEmulatingTempbasal = extendedEmulated.isEmulatingTempBasal + isEmulatingTempBasal = extendedEmulated.isEmulatingTempBasal ) } @@ -329,10 +329,270 @@ internal fun RemoteTreatment.toTreatment(): NSTreatment? { pumpSerial = this.pumpSerial, enteredinsulin = this.enteredinsulin, duration = this.durationInMilliseconds ?: TimeUnit.MINUTES.toMillis(this.duration ?: 0L), - isEmulatingTempbasal = this.isEmulatingTempBasal + isEmulatingTempBasal = this.isEmulatingTempBasal ) } } return null } + +internal fun NSTreatment.toRemoteTreatment(): RemoteTreatment? = + when (this) { + is NSBolus -> RemoteTreatment( + date = date, + device = device, + identifier = identifier, + units = units?.value, + utcOffset = utcOffset, + subject = subject, + isReadOnly = isReadOnly, + isValid = isValid, + eventType = eventType, + notes = notes, + pumpId = pumpId, + endId = endId, + pumpType = pumpType, + pumpSerial = pumpSerial, + insulin = insulin, + type = type.name + ) + + is NSCarbs -> RemoteTreatment( + date = date, + device = device, + identifier = identifier, + units = units?.value, + utcOffset = utcOffset, + subject = subject, + isReadOnly = isReadOnly, + isValid = isValid, + eventType = eventType, + notes = notes, + pumpId = pumpId, + endId = endId, + pumpType = pumpType, + pumpSerial = pumpSerial, + carbs = carbs, + duration = duration + ) + + is NSTemporaryTarget -> RemoteTreatment( + date = date, + device = device, + identifier = identifier, + units = units?.value, + srvModified = srvModified, + srvCreated = srvCreated, + utcOffset = utcOffset, + subject = subject, + isReadOnly = isReadOnly, + isValid = isValid, + eventType = eventType, + notes = notes, + pumpId = pumpId, + endId = endId, + pumpType = pumpType, + pumpSerial = pumpSerial, + duration = TimeUnit.MILLISECONDS.toMinutes(duration), + durationInMilliseconds = duration, + targetBottom = targetBottom, + targetTop = targetTop, + reason = reason.text + ) + /* + // Convert back emulated TBR -> EB + eventType == EventType.TEMPORARY_BASAL && extendedEmulated != null -> + + return RemoteTreatment( + date = treatmentTimestamp, + device = device, + identifier = identifier, + units = NsUnits.fromString(extendedEmulated.units), + srvModified = srvModified, + srvCreated = srvCreated, + utcOffset = utcOffset ?: 0, + subject = subject, + isReadOnly = extendedEmulated.isReadOnly ?: false, + isValid = extendedEmulated.isValid ?: true, + eventType = extendedEmulated.eventType, + notes = extendedEmulated.notes, + pumpId = extendedEmulated.pumpId, + endId = extendedEmulated.endId, + pumpType = extendedEmulated.pumpType, + pumpSerial = extendedEmulated.pumpSerial, + enteredinsulin = extendedEmulated.enteredinsulin ?: 0.0, + duration = extendedEmulated.durationInMilliseconds ?: TimeUnit.MINUTES.toMillis(extendedEmulated.duration ?: 0L), + isEmulatingTempbasal = extendedEmulated.isEmulatingTempBasal + ) + } + */ + is NSTemporaryBasal -> RemoteTreatment( + date = date, + device = device, + identifier = identifier, + units = units?.value, + srvModified = srvModified, + srvCreated = srvCreated, + utcOffset = utcOffset, + subject = subject, + isReadOnly = isReadOnly, + isValid = isValid, + eventType = eventType, + notes = notes, + pumpId = pumpId, + endId = endId, + pumpType = pumpType, + pumpSerial = pumpSerial, + duration = TimeUnit.MILLISECONDS.toMinutes(duration), + durationInMilliseconds = duration, + absolute = absolute, + percent = percent, + rate = absolute, + type = type.name + ) + + is NSEffectiveProfileSwitch -> RemoteTreatment( + date = date, + device = device, + identifier = identifier, + units = units?.value, + srvModified = srvModified, + srvCreated = srvCreated, + utcOffset = utcOffset, + subject = subject, + isReadOnly = isReadOnly, + isValid = isValid, + eventType = eventType, + notes = notes, + pumpId = pumpId, + endId = endId, + pumpType = pumpType, + pumpSerial = pumpSerial, + profileJson = profileJson.toString(), + originalProfileName = originalProfileName, + originalCustomizedName = originalCustomizedName, + originalTimeshift = originalTimeshift, + originalPercentage = originalPercentage, + originalDuration = originalDuration, + originalEnd = originalEnd + ) + + is NSProfileSwitch -> RemoteTreatment( + date = date, + device = device, + identifier = identifier, + units = units?.value, + srvModified = srvModified, + srvCreated = srvCreated, + utcOffset = utcOffset, + subject = subject, + isReadOnly = isReadOnly, + isValid = isValid, + eventType = eventType, + notes = notes, + pumpId = pumpId, + endId = endId, + pumpType = pumpType, + pumpSerial = pumpSerial, + profileJson = profileJson.toString(), // must be de-customized + profile = profileName, + originalProfileName = originalProfileName, + originalDuration = originalDuration, + duration = duration, + timeshift = timeShift, + percentage = percentage, + ) + + is NSBolusWizard -> RemoteTreatment( + date = date, + device = device, + identifier = identifier, + units = units?.value, + srvModified = srvModified, + srvCreated = srvCreated, + utcOffset = utcOffset, + subject = subject, + isReadOnly = isReadOnly, + isValid = isValid, + eventType = eventType, + notes = notes, + pumpId = pumpId, + endId = endId, + pumpType = pumpType, + pumpSerial = pumpSerial, + bolusCalculatorResult = bolusCalculatorResult, + glucose = glucose + ) + + is NSTherapyEvent -> RemoteTreatment( + date = date, + device = device, + identifier = identifier, + units = units?.value, + srvModified = srvModified, + srvCreated = srvCreated, + utcOffset = utcOffset, + subject = subject, + isReadOnly = isReadOnly, + isValid = isValid, + eventType = eventType, + notes = notes, + pumpId = pumpId, + endId = endId, + pumpType = pumpType, + pumpSerial = pumpSerial, + duration = TimeUnit.MILLISECONDS.toMinutes(duration), + durationInMilliseconds = duration, + glucose = glucose, + enteredBy = enteredBy, + glucoseType = glucoseType?.text + ) + + is NSOfflineEvent -> RemoteTreatment( + date = date, + device = device, + identifier = identifier, + units = units?.value, + srvModified = srvModified, + srvCreated = srvCreated, + utcOffset = utcOffset, + subject = subject, + isReadOnly = isReadOnly, + isValid = isValid, + eventType = eventType, + notes = notes, + pumpId = pumpId, + endId = endId, + pumpType = pumpType, + pumpSerial = pumpSerial, + duration = TimeUnit.MILLISECONDS.toMinutes(duration), + durationInMilliseconds = duration, + reason = reason.name + ) + + is NSExtendedBolus -> RemoteTreatment( + date = date, + device = device, + identifier = identifier, + units = units?.value, + srvModified = srvModified, + srvCreated = srvCreated, + utcOffset = utcOffset, + subject = subject, + isReadOnly = isReadOnly, + isValid = isValid, + eventType = eventType, + notes = notes, + pumpId = pumpId, + endId = endId, + pumpType = pumpType, + pumpSerial = pumpSerial, + enteredinsulin = enteredinsulin, + duration = TimeUnit.MILLISECONDS.toMinutes(duration), + durationInMilliseconds = duration, + isEmulatingTempBasal = isEmulatingTempBasal + ) + + else -> null + } diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/networking/NightscoutRemoteService.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/networking/NightscoutRemoteService.kt index 4619aef0c0..3ae740d2db 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/networking/NightscoutRemoteService.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/networking/NightscoutRemoteService.kt @@ -4,11 +4,17 @@ import com.google.gson.JsonElement import info.nightscout.sdk.remotemodel.LastModified import info.nightscout.sdk.remotemodel.RemoteDeviceStatus import info.nightscout.sdk.remotemodel.NSResponse +import info.nightscout.sdk.remotemodel.RemoteCreateUpdateResponse import info.nightscout.sdk.remotemodel.RemoteEntry import info.nightscout.sdk.remotemodel.RemoteStatusResponse import info.nightscout.sdk.remotemodel.RemoteTreatment +import okhttp3.RequestBody +import retrofit2.Call import retrofit2.Response +import retrofit2.http.Body import retrofit2.http.GET +import retrofit2.http.Header +import retrofit2.http.POST import retrofit2.http.Path import retrofit2.http.Query @@ -48,4 +54,8 @@ internal interface NightscoutRemoteService { @GET("v3/devicestatus/history/{from}") suspend fun getDeviceStatusModifiedSince(@Path("from") from: Long): Response>> + + @POST("v3/treatments") + fun createTreatment(@Body remoteTreatment: RemoteTreatment): Response> + } diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/remotemodel/RemoteStatusResponse.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/remotemodel/RemoteStatusResponse.kt index 15055f9051..be313118ba 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/remotemodel/RemoteStatusResponse.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/remotemodel/RemoteStatusResponse.kt @@ -17,6 +17,13 @@ internal data class RemoteStorage( @SerializedName("version") val version: String ) +internal data class RemoteCreateUpdateResponse( + @SerializedName("identifier") val identifier: String?, + @SerializedName("isDeduplication") val isDeduplication: Boolean?, + @SerializedName("deduplicatedIdentifier") val deduplicatedIdentifier: String?, + @SerializedName("lastModified") val lastModified: Long? +) + internal data class RemoteApiPermissions( @SerializedName("devicestatus") val deviceStatus: RemoteApiPermission, @SerializedName("entries") val entries: RemoteApiPermission, diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/remotemodel/RemoteTreatment.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/remotemodel/RemoteTreatment.kt index 80929a2133..d73f0098fc 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/remotemodel/RemoteTreatment.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/remotemodel/RemoteTreatment.kt @@ -18,72 +18,71 @@ import org.json.JSONObject * */ internal data class RemoteTreatment( @SerializedName("identifier") val identifier: String, // string Main addressing, required field that identifies document in the collection. The client should not create the identifier, the server automatically assigns it when the document is inserted. - @SerializedName("date") val date: Long?, // integer($int64) or string required timestamp when the record or event occurred, you can choose from three input formats Unix epoch in milliseconds (1525383610088), Unix epoch in seconds (1525383610), ISO 8601 with optional timezone ('2018-05-03T21:40:10.088Z' or '2018-05-03T23:40:10.088+02:00') - @SerializedName("mills") val mills: Long?, // integer($int64) or string required timestamp when the record or event occurred, you can choose from three input formats Unix - @SerializedName("timestamp") val timestamp: Long?, // integer($int64) or string required timestamp when the record or event occurred, you can choose from three input formats Unix epoch in milliseconds (1525383610088), Unix epoch in seconds (1525383610), ISO 8601 with optional timezone ('2018-05-03T21:40:10.088Z' or '2018-05-03T23:40:10.088+02:00') - @SerializedName("created_at") val created_at: String, // integer($int64) or string timestamp on previous version of api, in my examples, a lot of treatments don't have date, only created_at, some of them with string others with long... - @SerializedName("utcOffset") val utcOffset: Long?, // integer Local UTC offset (timezone) of the event in minutes. This field can be set either directly by the client (in the incoming - // document) or it is automatically parsed from the date field. + @SerializedName("date") val date: Long? = null, // integer($int64) or string required timestamp when the record or event occurred, you can choose from three input formats Unix epoch in milliseconds (1525383610088), Unix epoch in seconds (1525383610), ISO 8601 with optional timezone ('2018-05-03T21:40:10.088Z' or '2018-05-03T23:40:10.088+02:00') + @SerializedName("mills") val mills: Long? = null, // integer($int64) or string required timestamp when the record or event occurred, you can choose from three input formats Unix + @SerializedName("timestamp") val timestamp: Long? = null, // integer($int64) or string required timestamp when the record or event occurred, you can choose from three input formats Unix epoch in milliseconds (1525383610088), Unix epoch in seconds (1525383610), ISO 8601 with optional timezone ('2018-05-03T21:40:10.088Z' or '2018-05-03T23:40:10.088+02:00') + @SerializedName("created_at") val created_at: String? = null, // integer($int64) or string timestamp on previous version of api, in my examples, a lot of treatments don't have date, only created_at, some of them with string others with long... + @SerializedName("utcOffset") val utcOffset: Long? = null, // integer Local UTC offset (timezone) of the event in minutes. This field can be set either directly by the client (in the incoming document) or it is automatically parsed from the date field. // @SerializedName("app") val app : String, // TODO required ? Application or system in which the record was entered by human or device for the first time. - @SerializedName("device") val device: String?, // string The device from which the data originated (including serial number of the device, if it is relevant and safe). - @SerializedName("srvCreated") val srvCreated: Long, // integer($int64) example: 1525383610088 The server's timestamp of document insertion into the database (Unix epoch in ms). This field appears only for documents which were inserted by API v3. - @SerializedName("subject") val subject: String?, // string Name of the security subject (within Nightscout scope) which has created the document. This field is automatically set by the server from the passed token or JWT. - @SerializedName("srvModified") val srvModified: Long, // integer($int64) example: 1525383610088 The server's timestamp of the last document modification in the database (Unix epoch in ms). This field appears only for documents which were somehow modified by API v3 (inserted, updated or deleted). - @SerializedName("modifiedBy") val modifiedBy: String?, // string Name of the security subject (within Nightscout scope) which has patched or deleted the document for the last time. This field is automatically set by the server. - @SerializedName("isValid") val isValid: Boolean?, // boolean A flag set by the server only for deleted documents. This field appears only within history operation and for documents which were deleted by API v3 (and they always have a false value) - @SerializedName("isReadOnly") val isReadOnly: Boolean?, // boolean A flag set by client that locks the document from any changes. Every document marked with isReadOnly=true is forever immutable and cannot even be deleted. + @SerializedName("device") val device: String? = null, // string The device from which the data originated (including serial number of the device, if it is relevant and safe). + @SerializedName("srvCreated") val srvCreated: Long? = null, // integer($int64) example: 1525383610088 The server's timestamp of document insertion into the database (Unix epoch in ms). This field appears only for documents which were inserted by API v3. + @SerializedName("subject") val subject: String? = null, // string Name of the security subject (within Nightscout scope) which has created the document. This field is automatically set by the server from the passed token or JWT. + @SerializedName("srvModified") val srvModified: Long? = null, // integer($int64) example: 1525383610088 The server's timestamp of the last document modification in the database (Unix epoch in ms). This field appears only for documents which were somehow modified by API v3 (inserted, updated or deleted). + @SerializedName("modifiedBy") val modifiedBy: String? = null, // string Name of the security subject (within Nightscout scope) which has patched or deleted the document for the last time. This field is automatically set by the server. + @SerializedName("isValid") val isValid: Boolean? = null, // boolean A flag set by the server only for deleted documents. This field appears only within history operation and for documents which were deleted by API v3 (and they always have a false value) + @SerializedName("isReadOnly") val isReadOnly: Boolean? = null, // boolean A flag set by client that locks the document from any changes. Every document marked with isReadOnly=true is forever immutable and cannot even be deleted. @SerializedName("eventType") val eventType: EventType, // string "BG Check", "Snack Bolus", "Meal Bolus", "Correction Bolus", "Carb Correction", "Combo Bolus", "Announcement", "Note", "Question", "Exercise", "Site Change", "Sensor Start", "Sensor Change", "Pump Battery Change", "Insulin Change", "Temp Basal", "Profile Switch", "D.A.D. Alert", "Temporary Target", "OpenAPS Offline", "Bolus Wizard" - @SerializedName("glucose") val glucose: Double?, // double Current glucose - @SerializedName("glucoseType") val glucoseType: String?, // string example: "Sensor", "Finger", "Manual" - @SerializedName("units") val units: String?, // string The units for the glucose value, mg/dl or mmol/l. It is strongly recommended to fill in this field. - @SerializedName("carbs") val carbs: Double?, // number... Amount of carbs given. - @SerializedName("protein") val protein: Int?, // number... Amount of protein given. - @SerializedName("fat") val fat: Int?, // number... Amount of fat given. - @SerializedName("insulin") val insulin: Double?, // number... Amount of insulin, if any. - @SerializedName("duration") val duration: Long?, // number... Duration in minutes. - @SerializedName("durationInMilliseconds") val durationInMilliseconds: Long?, // number... Duration in milliseconds. - @SerializedName("preBolus") val preBolus: Int?, // number... How many minutes the bolus was given before the meal started. - @SerializedName("splitNow") val splitNow: Int?, // number... Immediate part of combo bolus (in percent). - @SerializedName("splitExt") val splitExt: Int?, // number... Extended part of combo bolus (in percent). - @SerializedName("percent") val percent: Double?, // number... Eventual basal change in percent. - @SerializedName("absolute") val absolute: Double?, // number... Eventual basal change in absolute value (insulin units per hour). - @SerializedName("targetTop") val targetTop: Double?, // number... Top limit of temporary target. - @SerializedName("targetBottom") val targetBottom: Double?, // number... Bottom limit of temporary target. - @SerializedName("profile") val profile: String?, // string Name of the profile to which the pump has been switched. - @SerializedName("reason") val reason: String?, // string For example the reason why the profile has been switched or why the temporary target has been set. - @SerializedName("notes") val notes: String?, // string Description/notes of treatment. - @SerializedName("enteredBy") val enteredBy: String?, // string Who entered the treatment. + @SerializedName("glucose") val glucose: Double? = null, // double Current glucose + @SerializedName("glucoseType") val glucoseType: String? = null, // string example: "Sensor", "Finger", "Manual" + @SerializedName("units") val units: String? = null, // string The units for the glucose value, mg/dl or mmol/l. It is strongly recommended to fill in this field. + @SerializedName("carbs") val carbs: Double? = null, // number... Amount of carbs given. + @SerializedName("protein") val protein: Int? = null, // number... Amount of protein given. + @SerializedName("fat") val fat: Int? = null, // number... Amount of fat given. + @SerializedName("insulin") val insulin: Double? = null, // number... Amount of insulin, if any. + @SerializedName("duration") val duration: Long? = null, // number... Duration in minutes. + @SerializedName("durationInMilliseconds") val durationInMilliseconds: Long? = null, // number... Duration in milliseconds. + @SerializedName("preBolus") val preBolus: Int? = null, // number... How many minutes the bolus was given before the meal started. + @SerializedName("splitNow") val splitNow: Int? = null, // number... Immediate part of combo bolus (in percent). + @SerializedName("splitExt") val splitExt: Int? = null, // number... Extended part of combo bolus (in percent). + @SerializedName("percent") val percent: Double? = null, // number... Eventual basal change in percent. + @SerializedName("absolute") val absolute: Double? = null, // number... Eventual basal change in absolute value (insulin units per hour). + @SerializedName("targetTop") val targetTop: Double? = null, // number... Top limit of temporary target. + @SerializedName("targetBottom") val targetBottom: Double? = null, // number... Bottom limit of temporary target. + @SerializedName("profile") val profile: String? = null, // string Name of the profile to which the pump has been switched. + @SerializedName("reason") val reason: String? = null, // string For example the reason why the profile has been switched or why the temporary target has been set. + @SerializedName("notes") val notes: String? = null, // string Description/notes of treatment. + @SerializedName("enteredBy") val enteredBy: String? = null, // string Who entered the treatment. - @SerializedName("endId") val endId: Long?, // long id of record which ended this - @SerializedName("pumpId") val pumpId: Long?, // long or "Meal Bolus", "Correction Bolus", "Combo Bolus" ex 4102 not sure if long or int - @SerializedName("pumpType") val pumpType: String?, // string "Meal Bolus", "Correction Bolus", "Combo Bolus" ex "ACCU_CHEK_INSIGHT_BLUETOOTH", - @SerializedName("pumpSerial") val pumpSerial: String?, // string "Meal Bolus", "Correction Bolus", "Combo Bolus" "33013206", + @SerializedName("endId") val endId: Long? = null, // long id of record which ended this + @SerializedName("pumpId") val pumpId: Long? = null, // long or "Meal Bolus", "Correction Bolus", "Combo Bolus" ex 4102 not sure if long or int + @SerializedName("pumpType") val pumpType: String? = null, // string "Meal Bolus", "Correction Bolus", "Combo Bolus" ex "ACCU_CHEK_INSIGHT_BLUETOOTH", + @SerializedName("pumpSerial") val pumpSerial: String? = null, // string "Meal Bolus", "Correction Bolus", "Combo Bolus" "33013206", // other fields found in examples but not in documentation - @SerializedName("profileJson") val profileJson: String?, // string "Profile Switch" ex json toString "{\"units\":\"mg\\/dl\",\"dia\":5,\"timezone\":\"Africa\\/Cairo\", + @SerializedName("profileJson") val profileJson: String? = null, // string "Profile Switch" ex json toString "{\"units\":\"mg\\/dl\",\"dia\":5,\"timezone\":\"Africa\\/Cairo\", // \"sens\":[{\"time\":\"00:00\",\"timeAsSeconds\":0,\"value\":60},{\"time\":\"07:00\",\"timeAsSeconds\":25200,\"value\":60},{\"time\":\"08:00\",\"timeAsSeconds\":28800,\"value\":61.33333333333333},{\"time\":\"09:00\",\"timeAsSeconds\":32400,\"value\":65.33333333333333},{\"time\":\"10:00\",\"timeAsSeconds\":36000,\"value\":69.33333333333333},{\"time\":\"11:00\",\"timeAsSeconds\":39600,\"value\":73.33333333333333},{\"time\":\"13:00\",\"timeAsSeconds\":46800,\"value\":72},{\"time\":\"14:00\",\"timeAsSeconds\":50400,\"value\":68},{\"time\":\"15:00\",\"timeAsSeconds\":54000,\"value\":65.33333333333333},{\"time\":\"16:00\",\"timeAsSeconds\":57600,\"value\":65.33333333333333}],\"carbratio\":[{\"time\":\"00:00\",\"timeAsSeconds\":0,\"value\":5.7333333333333325},{\"time\":\"11:00\",\"timeAsSeconds\":39600,\"value\":7.333333333333333},{\"time\":\"16:00\",\"timeAsSeconds\":57600,\"value\":6.666666666666666}],\"basal\":[{\"time\":\"00:00\",\"timeAsSeconds\":0,\"value\":0.5249999999999999},{\"time\":\"01:00\",\"timeAsSeconds\":3600,\"value\":0.585},{\"time\":\"02:00\",\"timeAsSeconds\":7200,\"value\":0.6375},{\"time\":\"03:00\",\"timeAsSeconds\":10800,\"value\":0.5625},{\"time\":\"04:00\",\"timeAsSeconds\":14400,\"value\":0.4575},{\"time\":\"05:00\",\"timeAsSeconds\":18000,\"value\":0.5175},{\"time\":\"06:00\",\"timeAsSeconds\":21600,\"value\":0.48},{\"time\":\"07:00\",\"timeAsSeconds\":25200,\"value\":0.51},{\"time\":\"08:00\",\"timeAsSeconds\":28800,\"value\":0.48750000000000004},{\"time\":\"09:00\",\"timeAsSeconds\":32400,\"value\":0.48},{\"time\":\"10:00\",\"timeAsSeconds\":36000,\"value\":0.48750000000000004},{\"time\":\"11:00\",\"timeAsSeconds\":39600,\"value\":0.5025000000000001},{\"time\":\"12:00\",\"timeAsSeconds\":43200,\"value\":0.5549999999999999},{\"time\":\"13:00\",\"timeAsSeconds\":46800,\"value\":0.5700000000000001},{\"time\":\"14:00\",\"timeAsSeconds\":50400,\"value\":0.5700000000000001},{\"time\":\"15:00\",\"timeAsSeconds\":54000,\"value\":0.5775},{\"time\":\"16:00\",\"timeAsSeconds\":57600,\"value\":0.51},{\"time\":\"17:00\",\"timeAsSeconds\":61200,\"value\":0.54},{\"time\":\"18:00\",\"timeAsSeconds\":64800,\"value\":0.48750000000000004},{\"time\":\"19:00\",\"timeAsSeconds\":68400,\"value\":0.5249999999999999},{\"time\":\"20:00\",\"timeAsSeconds\":72000,\"value\":0.46499999999999997},{\"time\":\"21:00\",\"timeAsSeconds\":75600,\"value\":0.46499999999999997},{\"time\":\"22:00\",\"timeAsSeconds\":79200,\"value\":0.43499999999999994},{\"time\":\"23:00\",\"timeAsSeconds\":82800,\"value\":0.41250000000000003}],\"target_low\":[{\"time\":\"00:00\",\"timeAsSeconds\":0,\"value\":100},{\"time\":\"06:00\",\"timeAsSeconds\":21600,\"value\":90},{\"time\":\"09:00\",\"timeAsSeconds\":32400,\"value\":100},{\"time\":\"11:00\",\"timeAsSeconds\":39600,\"value\":90},{\"time\":\"14:00\",\"timeAsSeconds\":50400,\"value\":100},{\"time\":\"18:00\",\"timeAsSeconds\":64800,\"value\":90},{\"time\":\"21:00\",\"timeAsSeconds\":75600,\"value\":100}],\"target_high\":[{\"time\":\"00:00\",\"timeAsSeconds\":0,\"value\":100},{\"time\":\"06:00\",\"timeAsSeconds\":21600,\"value\":90},{\"time\":\"09:00\",\"timeAsSeconds\":32400,\"value\":100},{\"time\":\"11:00\",\"timeAsSeconds\":39600,\"value\":90},{\"time\":\"14:00\",\"timeAsSeconds\":50400,\"value\":100},{\"time\":\"18:00\",\"timeAsSeconds\":64800,\"value\":90},{\"time\":\"21:00\",\"timeAsSeconds\":75600,\"value\":100}]}", - @SerializedName("originalProfileName") val originalProfileName: String?, // string "Effective Profile Switch" - @SerializedName("originalCustomizedName") val originalCustomizedName: String?, // string "Effective Profile Switch" - @SerializedName("originalTimeshift") val originalTimeshift: Long?, // long "Effective Profile Switch" - @SerializedName("originalPercentage") val originalPercentage: Int?, // int "Effective Profile Switch" - @SerializedName("originalDuration") val originalDuration: Long?, // long "Effective Profile Switch" - @SerializedName("originalEnd") val originalEnd: Long?, // long "Effective Profile Switch" + @SerializedName("originalProfileName") val originalProfileName: String? = null, // string "Effective Profile Switch" + @SerializedName("originalCustomizedName") val originalCustomizedName: String? = null, // string "Effective Profile Switch" + @SerializedName("originalTimeshift") val originalTimeshift: Long? = null, // long "Effective Profile Switch" + @SerializedName("originalPercentage") val originalPercentage: Int? = null, // int "Effective Profile Switch" + @SerializedName("originalDuration") val originalDuration: Long? = null, // long "Effective Profile Switch" + @SerializedName("originalEnd") val originalEnd: Long? = null, // long "Effective Profile Switch" - @SerializedName("bolusCalculatorResult") val bolusCalculatorResult: String?, // string "Bolus Wizard" json toString ex "bolusCalculatorResult": "{\"basalIOB\":-0.247,\"bolusIOB\":-1.837,\"carbs\":45.0,\"carbsInsulin\":9.0,\"cob\":0.0,\"cobInsulin\":0.0,\"dateCreated\":1626202788810,\"glucoseDifference\":44.0,\"glucoseInsulin\":0.8979591836734694,\"glucoseTrend\":5.5,\"glucoseValue\":134.0,\"ic\":5.0,\"id\":331,\"interfaceIDs_backing\":{\"nightscoutId\":\"60ede2a4c574da0004a3869d\"},\"isValid\":true,\"isf\":49.0,\"note\":\"\",\"otherCorrection\":0.0,\"percentageCorrection\":90,\"profileName\":\"Tuned 13/01 90%Lyum\",\"superbolusInsulin\":0.0,\"targetBGHigh\":90.0,\"targetBGLow\":90.0,\"timestamp\":1626202783325,\"totalInsulin\":7.34,\"trendInsulin\":0.336734693877551,\"utcOffset\":7200000,\"version\":1,\"wasBasalIOBUsed\":true,\"wasBolusIOBUsed\":true,\"wasCOBUsed\":true,\"wasGlucoseUsed\":true,\"wasSuperbolusUsed\":false,\"wasTempTargetUsed\":false,\"wasTrendUsed\":true,\"wereCarbsUsed\":false}", - @SerializedName("type") val type: String?, // string "Meal Bolus", "Correction Bolus", "Combo Bolus", "Temp Basal" type of bolus "NORMAL", "SMB", "FAKE_EXTENDED" - @SerializedName("isSMB") val isSMB: Boolean, // boolean "Meal Bolus", "Correction Bolus", "Combo Bolus" - @SerializedName("enteredinsulin") val enteredinsulin: Double?, // number... "Combo Bolus" insulin is missing only enteredinsulin field found - @SerializedName("relative") val relative: Double?, // number... "Combo Bolus", "extendedEmulated" (not in doc see below) - @SerializedName("isEmulatingTempBasal") val isEmulatingTempBasal: Boolean, // boolean "Combo Bolus", "extendedEmulated" (not in doc see below) - @SerializedName("isAnnouncement") val isAnnouncement: Boolean, // boolean "Announcement" - @SerializedName("rate") val rate: Double?, // Double "Temp Basal" absolute rate (could be calculated with percent and profile information...) - @SerializedName("extendedEmulated") val extendedEmulated: RemoteTreatment?, // Gson of emulated EB - @SerializedName("timeshift") val timeshift: Long, // integer "Profile Switch" - @SerializedName("percentage") val percentage: Int?, // integer "Profile Switch" + @SerializedName("bolusCalculatorResult") val bolusCalculatorResult: String? = null, // string "Bolus Wizard" json toString ex "bolusCalculatorResult": "{\"basalIOB\":-0.247,\"bolusIOB\":-1.837,\"carbs\":45.0,\"carbsInsulin\":9.0,\"cob\":0.0,\"cobInsulin\":0.0,\"dateCreated\":1626202788810,\"glucoseDifference\":44.0,\"glucoseInsulin\":0.8979591836734694,\"glucoseTrend\":5.5,\"glucoseValue\":134.0,\"ic\":5.0,\"id\":331,\"interfaceIDs_backing\":{\"nightscoutId\":\"60ede2a4c574da0004a3869d\"},\"isValid\":true,\"isf\":49.0,\"note\":\"\",\"otherCorrection\":0.0,\"percentageCorrection\":90,\"profileName\":\"Tuned 13/01 90%Lyum\",\"superbolusInsulin\":0.0,\"targetBGHigh\":90.0,\"targetBGLow\":90.0,\"timestamp\":1626202783325,\"totalInsulin\":7.34,\"trendInsulin\":0.336734693877551,\"utcOffset\":7200000,\"version\":1,\"wasBasalIOBUsed\":true,\"wasBolusIOBUsed\":true,\"wasCOBUsed\":true,\"wasGlucoseUsed\":true,\"wasSuperbolusUsed\":false,\"wasTempTargetUsed\":false,\"wasTrendUsed\":true,\"wereCarbsUsed\":false}", + @SerializedName("type") val type: String? = null, // string "Meal Bolus", "Correction Bolus", "Combo Bolus", "Temp Basal" type of bolus "NORMAL", "SMB", "FAKE_EXTENDED" + @SerializedName("isSMB") val isSMB: Boolean? = null, // boolean "Meal Bolus", "Correction Bolus", "Combo Bolus" + @SerializedName("enteredinsulin") val enteredinsulin: Double? = null, // number... "Combo Bolus" insulin is missing only enteredinsulin field found + @SerializedName("relative") val relative: Double? = null, // number... "Combo Bolus", "extendedEmulated" (not in doc see below) + @SerializedName("isEmulatingTempBasal") val isEmulatingTempBasal: Boolean? = null, // boolean "Combo Bolus", "extendedEmulated" (not in doc see below) + @SerializedName("isAnnouncement") val isAnnouncement: Boolean? = null, // boolean "Announcement" + @SerializedName("rate") val rate: Double? = null, // Double "Temp Basal" absolute rate (could be calculated with percent and profile information...) + @SerializedName("extendedEmulated") val extendedEmulated: RemoteTreatment? = null, // Gson of emulated EB + @SerializedName("timeshift") val timeshift: Long? = null, // integer "Profile Switch" + @SerializedName("percentage") val percentage: Int? = null // integer "Profile Switch" ) { fun timestamp(): Long { - return date ?: mills ?: timestamp ?: fromISODateString(created_at) + return date ?: mills ?: timestamp ?: created_at?. let { fromISODateString(created_at) } ?: 0L } private fun fromISODateString(isoDateString: String): Long = diff --git a/core/ui/src/main/java/info/nightscout/core/ui/extensions/RadioGroupExtension.kt b/core/ui/src/main/java/info/nightscout/core/ui/extensions/RadioGroupExtension.kt index 0bf51f656f..54b61b97db 100644 --- a/core/ui/src/main/java/info/nightscout/core/ui/extensions/RadioGroupExtension.kt +++ b/core/ui/src/main/java/info/nightscout/core/ui/extensions/RadioGroupExtension.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.utils.extensions +package info.nightscout.core.ui.extensions import android.widget.RadioGroup import androidx.appcompat.widget.AppCompatRadioButton diff --git a/core/ui/src/main/res/values-fr-rFR/strings.xml b/core/ui/src/main/res/values-fr-rFR/strings.xml index 4e0d6017eb..f36b0cea34 100644 --- a/core/ui/src/main/res/values-fr-rFR/strings.xml +++ b/core/ui/src/main/res/values-fr-rFR/strings.xml @@ -14,6 +14,7 @@ %1$.2f U/h Pompe non initialisée, profil non défini ! La mise à jour du profil basal a échouée + Bolus de %1$.2f U délivré avec succès Aucun débit basal valide lu depuis la pompe Limiter l’IA %1$.1f U en raison de la %2$s BOUCLE DÉSACTIVÉE PAR RESTRICTIONS @@ -161,6 +162,8 @@ DAI G/I SI + Echec de l\'annulation du basal temporaire + Échec de l\'annulation du Bolus étendu Remontée des informations vers NS Boucle désactivée/suspendue Insuline Active (IA) @@ -246,6 +249,7 @@ %1$dg de glucides requis dans %2$d min. + DTQ cumulée DTQ avec Pondération Exponentielle Basal Bolus diff --git a/core/ui/src/main/res/values-pt-rBR/strings.xml b/core/ui/src/main/res/values-pt-rBR/strings.xml index add6078c4b..70eb1193f6 100644 --- a/core/ui/src/main/res/values-pt-rBR/strings.xml +++ b/core/ui/src/main/res/values-pt-rBR/strings.xml @@ -419,7 +419,7 @@ Aviso : Selecione o perfil para ajustar O perfil selecionado tem %1$d valores de IC. Autotune vai usar %2$.2f g/U - O perfil selecionado tem %1$d valores de ISF. Autotune vai usar %2$.1f g/U + O perfil selecionado tem %1$d valores de ISF. Autotune usará %2$.1f %3$s/U Erro nos dados de entrada, tente executar novamente autotune ou reduza o número de dias Cálculos do Autotune iniciados, por favor aguarde Verifique os resultados cuidadosamente antes de usá-los! diff --git a/core/ui/src/main/res/values-ru-rRU/strings.xml b/core/ui/src/main/res/values-ru-rRU/strings.xml index 90bb6dbab1..3ee938b1fc 100644 --- a/core/ui/src/main/res/values-ru-rRU/strings.xml +++ b/core/ui/src/main/res/values-ru-rRU/strings.xml @@ -162,6 +162,8 @@ Время действия инсулина DIA IC углкоэф ГУ/инс ISF (чувствительность к инсулину) + Отмена врем базала не состоялась + Сбой отмены пролонгированного болюса статус передачи данных в NS Отключенный/приостановленный цикл Активный инсулин (IOB) @@ -426,7 +428,6 @@ Парам % Отсутствует - Профиль авто тюн Выполнить Autotune Проверьте профиль ввода Сравнить профили diff --git a/core/ui/src/main/res/values-zh-rCN/strings.xml b/core/ui/src/main/res/values-zh-rCN/strings.xml index 1c13a48a4c..afe0f6964f 100644 --- a/core/ui/src/main/res/values-zh-rCN/strings.xml +++ b/core/ui/src/main/res/values-zh-rCN/strings.xml @@ -483,7 +483,7 @@ 最大基础率被限定为 %1$.2f U/h 由于 %2$s 泵限制 - 由于 %2$s, 将最大百分比限制为 %1$d% + 由于 %2$s, 将最大百分比限制为 %1$d%% 它必须是正数 由于 %2$s, 将大剂量限制为 %1$.1f U diff --git a/core/utils/src/main/java/info/nightscout/core/utils/extensions/JSONObjectExt.kt b/core/utils/src/main/java/info/nightscout/core/utils/extensions/JSONObjectExt.kt index bfcf039497..8f38aab753 100644 --- a/core/utils/src/main/java/info/nightscout/core/utils/extensions/JSONObjectExt.kt +++ b/core/utils/src/main/java/info/nightscout/core/utils/extensions/JSONObjectExt.kt @@ -1,4 +1,4 @@ -package info.nightscout.core.extensions +package info.nightscout.core.utils.extensions import androidx.annotation.StringRes import info.nightscout.shared.interfaces.ResourceHelper diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneCore.kt b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneCore.kt index 3c0de91b51..a173b54a22 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneCore.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneCore.kt @@ -165,7 +165,7 @@ class AutotuneCore @Inject constructor( for (i in 0..23) { newHourlyBasalProfile[i] = hourlyBasalProfile[i] } - val basalUnTuned = previousAutotune.basalUntuned + val basalUnTuned = previousAutotune.basalUnTuned //autotune-core (lib/autotune/index.js) #210-#266 // look at net deviations for each hour @@ -484,7 +484,7 @@ class AutotuneCore @Inject constructor( previousAutotune.basal = basalProfile previousAutotune.isf = isf previousAutotune.ic = Round.roundTo(carbRatio, 0.001) - previousAutotune.basalUntuned = basalUnTuned + previousAutotune.basalUnTuned = basalUnTuned previousAutotune.dia = newDia previousAutotune.peak = newPeak val localInsulin = LocalInsulin("Ins_$newPeak-$newDia", newPeak, newDia) diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFS.kt b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFS.kt index fb32c8bb6f..69d655462d 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFS.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFS.kt @@ -89,14 +89,14 @@ class AutotuneFS @Inject constructor( } fun exportPumpProfile(profile: ATProfile) { - createAutotunefile(PUMPPROFILE, profile.profiletoOrefJSON(), true) - createAutotunefile(PUMPPROFILE, profile.profiletoOrefJSON()) + createAutotunefile(PUMPPROFILE, profile.profileToOrefJSON(), true) + createAutotunefile(PUMPPROFILE, profile.profileToOrefJSON()) } fun exportTunedProfile(tunedProfile: ATProfile) { - createAutotunefile(TUNEDPROFILE + formatDate(tunedProfile.from) + ".json", tunedProfile.profiletoOrefJSON()) + createAutotunefile(TUNEDPROFILE + formatDate(tunedProfile.from) + ".json", tunedProfile.profileToOrefJSON()) try { - createAutotunefile(rh.gs(info.nightscout.core.ui.R.string.autotune_tunedprofile_name) + ".json", tunedProfile.profiletoOrefJSON(), true) + createAutotunefile(rh.gs(info.nightscout.core.ui.R.string.autotune_tunedprofile_name) + ".json", tunedProfile.profileToOrefJSON(), true) } catch (e: JSONException) { } } diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFragment.kt b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFragment.kt index 2bfd3b5e14..be1c6f5f76 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFragment.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFragment.kt @@ -28,9 +28,9 @@ import info.nightscout.interfaces.Constants import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.plugin.ActivePlugin +import info.nightscout.interfaces.profile.Instantiator import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileFunction -import info.nightscout.interfaces.profile.Instantiator import info.nightscout.interfaces.profile.ProfileStore import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.utils.MidnightTime @@ -149,12 +149,12 @@ class AutotuneFragment : DaggerFragment() { } binding.autotuneUpdateProfile.setOnClickListener { - val localName = autotunePlugin.pumpProfile.profilename + val localName = autotunePlugin.pumpProfile.profileName OKDialog.showConfirmation(requireContext(), rh.gs(info.nightscout.core.ui.R.string.autotune_update_input_profile_button), rh.gs(info.nightscout.core.ui.R.string.autotune_update_local_profile_message, localName), Runnable { - autotunePlugin.tunedProfile?.profilename = localName + autotunePlugin.tunedProfile?.profileName = localName autotunePlugin.updateProfile(autotunePlugin.tunedProfile) autotunePlugin.updateButtonVisibility = View.GONE autotunePlugin.saveLastRun() @@ -169,12 +169,12 @@ class AutotuneFragment : DaggerFragment() { } binding.autotuneRevertProfile.setOnClickListener { - val localName = autotunePlugin.pumpProfile.profilename + val localName = autotunePlugin.pumpProfile.profileName OKDialog.showConfirmation(requireContext(), rh.gs(info.nightscout.core.ui.R.string.autotune_revert_input_profile_button), rh.gs(info.nightscout.core.ui.R.string.autotune_revert_local_profile_message, localName), Runnable { - autotunePlugin.tunedProfile?.profilename = "" + autotunePlugin.tunedProfile?.profileName = "" autotunePlugin.updateProfile(autotunePlugin.pumpProfile) autotunePlugin.updateButtonVisibility = View.VISIBLE autotunePlugin.saveLastRun() @@ -192,11 +192,11 @@ class AutotuneFragment : DaggerFragment() { val pumpProfile = profileFunction.getProfile()?.let { currentProfile -> profileStore.getSpecificProfile(profileName)?.let { specificProfile -> ATProfile(ProfileSealed.Pure(specificProfile), LocalInsulin(""), injector).also { - it.profilename = profileName + it.profileName = profileName } } ?: ATProfile(currentProfile, LocalInsulin(""), injector).also { - it.profilename = profileFunction.getProfileName() + it.profileName = profileFunction.getProfileName() } } pumpProfile?.let { @@ -205,7 +205,7 @@ class AutotuneFragment : DaggerFragment() { time = dateUtil.now(), mode = UiInteraction.Mode.CUSTOM_PROFILE, customProfile = pumpProfile.profile.toPureNsJson(dateUtil).toString(), - customProfileName = pumpProfile.profilename + customProfileName = pumpProfile.profileName ) } } @@ -219,7 +219,7 @@ class AutotuneFragment : DaggerFragment() { time = dateUtil.now(), mode = UiInteraction.Mode.PROFILE_COMPARE, customProfile = pumpProfile.profile.toPureNsJson(dateUtil).toString(), - customProfileName = pumpProfile.profilename + "\n" + rh.gs(info.nightscout.core.ui.R.string.autotune_tunedprofile_name), + customProfileName = pumpProfile.profileName + "\n" + rh.gs(info.nightscout.core.ui.R.string.autotune_tunedprofile_name), customProfile2 = tunedProfile?.toPureNsJson(dateUtil).toString() ) } @@ -231,17 +231,17 @@ class AutotuneFragment : DaggerFragment() { tunedProfile?.let { tunedP -> tunedP.profileStore(circadian)?.let { OKDialog.showConfirmation(requireContext(), - rh.gs(info.nightscout.core.ui.R.string.activate_profile) + ": " + tunedP.profilename + " ?", + rh.gs(info.nightscout.core.ui.R.string.activate_profile) + ": " + tunedP.profileName + " ?", { uel.log( UserEntry.Action.STORE_PROFILE, UserEntry.Sources.Autotune, - ValueWithUnit.SimpleString(tunedP.profilename) + ValueWithUnit.SimpleString(tunedP.profileName) ) val now = dateUtil.now() if (profileFunction.createProfileSwitch( it, - profileName = tunedP.profilename, + profileName = tunedP.profileName, durationInMinutes = 0, percentage = 100, timeShiftInHours = 0, @@ -252,7 +252,7 @@ class AutotuneFragment : DaggerFragment() { UserEntry.Action.PROFILE_SWITCH, UserEntry.Sources.Autotune, "Autotune AutoSwitch", - ValueWithUnit.SimpleString(autotunePlugin.tunedProfile!!.profilename) + ValueWithUnit.SimpleString(autotunePlugin.tunedProfile!!.profileName) ) } rxBus.send(EventLocalProfileChanged()) @@ -472,7 +472,7 @@ class AutotuneFragment : DaggerFragment() { val time = df.format(h.toLong()) + ":00" totalPump += autotunePlugin.pumpProfile.basal[h] totalTuned += tuned.basal[h] - layout.addView(toTableRowValue(context, time, autotunePlugin.pumpProfile.basal[h], tuned.basal[h], "%.3f", tuned.basalUntuned[h].toString())) + layout.addView(toTableRowValue(context, time, autotunePlugin.pumpProfile.basal[h], tuned.basal[h], "%.3f", tuned.basalUnTuned[h].toString())) } layout.addView(toTableRowValue(context, "∑", totalPump, totalTuned, "%.3f", " ")) } diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotunePlugin.kt b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotunePlugin.kt index 50c4ab61c2..461797ea48 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotunePlugin.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/AutotunePlugin.kt @@ -14,9 +14,9 @@ import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType +import info.nightscout.interfaces.profile.Instantiator import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileFunction -import info.nightscout.interfaces.profile.Instantiator import info.nightscout.interfaces.utils.JsonHelper import info.nightscout.interfaces.utils.MidnightTime import info.nightscout.plugins.aps.R @@ -131,10 +131,10 @@ class AutotunePlugin @Inject constructor( val starttime = endTime - daysBack * 24 * 60 * 60 * 1000L autotuneFS.exportSettings(settings(lastRun, daysBack, starttime, endTime)) tunedProfile = ATProfile(profile, localInsulin, injector).also { - it.profilename = rh.gs(info.nightscout.core.ui.R.string.autotune_tunedprofile_name) + it.profileName = rh.gs(info.nightscout.core.ui.R.string.autotune_tunedprofile_name) } pumpProfile = ATProfile(profile, localInsulin, injector).also { - it.profilename = selectedProfile + it.profileName = selectedProfile } autotuneFS.exportPumpProfile(pumpProfile) @@ -195,31 +195,31 @@ class AutotunePlugin @Inject constructor( if (autoSwitch) { val circadian = sp.getBoolean(info.nightscout.core.utils.R.string.key_autotune_circadian_ic_isf, false) tunedProfile?.let { tunedP -> - tunedP.profilename = pumpProfile.profilename + tunedP.profileName = pumpProfile.profileName updateProfile(tunedP) uel.log( UserEntry.Action.STORE_PROFILE, UserEntry.Sources.Automation, rh.gs(info.nightscout.core.ui.R.string.autotune), - ValueWithUnit.SimpleString(tunedP.profilename) + ValueWithUnit.SimpleString(tunedP.profileName) ) updateButtonVisibility = View.GONE tunedP.profileStore(circadian)?.let { profilestore -> if (profileFunction.createProfileSwitch( profilestore, - profileName = tunedP.profilename, + profileName = tunedP.profileName, durationInMinutes = 0, percentage = 100, timeShiftInHours = 0, timestamp = dateUtil.now() ) ) { - log("Profile Switch succeed ${tunedP.profilename}") + log("Profile Switch succeed ${tunedP.profileName}") uel.log( UserEntry.Action.PROFILE_SWITCH, UserEntry.Sources.Automation, rh.gs(info.nightscout.core.ui.R.string.autotune), - ValueWithUnit.SimpleString(tunedP.profilename) + ValueWithUnit.SimpleString(tunedP.profileName) ) } rxBus.send(EventLocalProfileChanged()) @@ -262,7 +262,7 @@ class AutotunePlugin @Inject constructor( totalBasal += pumpProfile.basal[i] totalTuned += tunedProfile.basal[i] val percentageChangeValue = tunedProfile.basal[i] / pumpProfile.basal[i] * 100 - 100 - strResult += rh.gs(info.nightscout.core.ui.R.string.autotune_log_basal, i.toDouble(), pumpProfile.basal[i], tunedProfile.basal[i], tunedProfile.basalUntuned[i], percentageChangeValue) + strResult += rh.gs(info.nightscout.core.ui.R.string.autotune_log_basal, i.toDouble(), pumpProfile.basal[i], tunedProfile.basal[i], tunedProfile.basalUnTuned[i], percentageChangeValue) } strResult += line strResult += rh.gs(info.nightscout.core.ui.R.string.autotune_log_sum_basal, totalBasal, totalTuned) @@ -329,10 +329,10 @@ class AutotunePlugin @Inject constructor( val profileList: ArrayList = profileStore.getProfileList() var indexLocalProfile = -1 for (p in profileList.indices) - if (profileList[p] == newProfile.profilename) + if (profileList[p] == newProfile.profileName) indexLocalProfile = p if (indexLocalProfile == -1) { - profilePlugin.addProfile(profilePlugin.copyFrom(newProfile.getProfile(circadian), newProfile.profilename)) + profilePlugin.addProfile(profilePlugin.copyFrom(newProfile.getProfile(circadian), newProfile.profileName)) return } profilePlugin.currentProfileIndex = indexLocalProfile @@ -348,17 +348,17 @@ class AutotunePlugin @Inject constructor( json.put("lastNbDays", lastNbDays) json.put("lastRun", lastRun) json.put("pumpProfile", pumpProfile.profile.toPureNsJson(dateUtil)) - json.put("pumpProfileName", pumpProfile.profilename) + json.put("pumpProfileName", pumpProfile.profileName) json.put("pumpPeak", pumpProfile.peak) json.put("pumpDia", pumpProfile.dia) tunedProfile?.let { atProfile -> json.put("tunedProfile", atProfile.profile.toPureNsJson(dateUtil)) json.put("tunedCircadianProfile", atProfile.circadianProfile.toPureNsJson(dateUtil)) - json.put("tunedProfileName", atProfile.profilename) + json.put("tunedProfileName", atProfile.profileName) json.put("tunedPeak", atProfile.peak) json.put("tunedDia", atProfile.dia) for (i in 0..23) { - json.put("missingDays_$i", atProfile.basalUntuned[i]) + json.put("missingDays_$i", atProfile.basalUnTuned[i]) } } json.put("result", result) @@ -379,7 +379,7 @@ class AutotunePlugin @Inject constructor( selectedProfile = JsonHelper.safeGetString(json, "pumpProfileName", "") val profile = JsonHelper.safeGetJSONObject(json, "pumpProfile", null)?.let { pureProfileFromJson(it, dateUtil) } ?: return - pumpProfile = ATProfile(ProfileSealed.Pure(profile), localInsulin, injector).also { it.profilename = selectedProfile } + pumpProfile = ATProfile(ProfileSealed.Pure(profile), localInsulin, injector).also { it.profileName = selectedProfile } val tunedPeak = JsonHelper.safeGetInt(json, "tunedPeak") val tunedDia = JsonHelper.safeGetDouble(json, "tunedDia") localInsulin = LocalInsulin("PumpInsulin", tunedPeak, tunedDia) @@ -389,10 +389,10 @@ class AutotunePlugin @Inject constructor( val circadianTuned = JsonHelper.safeGetJSONObject(json, "tunedCircadianProfile", null)?.let { pureProfileFromJson(it, dateUtil) } ?: return tunedProfile = ATProfile(ProfileSealed.Pure(tuned), localInsulin, injector).also { atProfile -> - atProfile.profilename = tunedProfileName + atProfile.profileName = tunedProfileName atProfile.circadianProfile = ProfileSealed.Pure(circadianTuned) for (i in 0..23) { - atProfile.basalUntuned[i] = JsonHelper.safeGetInt(json, "missingDays_$i") + atProfile.basalUnTuned[i] = JsonHelper.safeGetInt(json, "missingDays_$i") } } result = JsonHelper.safeGetString(json, "result", "") diff --git a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/data/ATProfile.kt b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/data/ATProfile.kt index f8b139736a..e8861d37ef 100644 --- a/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/data/ATProfile.kt +++ b/plugins/aps/src/main/java/info/nightscout/plugins/general/autotune/data/ATProfile.kt @@ -10,13 +10,15 @@ import info.nightscout.interfaces.Config import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.insulin.Insulin import info.nightscout.interfaces.plugin.ActivePlugin +import info.nightscout.interfaces.profile.Instantiator import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileFunction -import info.nightscout.interfaces.profile.Instantiator import info.nightscout.interfaces.profile.ProfileStore import info.nightscout.interfaces.profile.PureProfile import info.nightscout.interfaces.utils.Round import info.nightscout.rx.bus.RxBus +import info.nightscout.rx.logging.AAPSLogger +import info.nightscout.rx.logging.LTag import info.nightscout.shared.SafeParse import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP @@ -28,6 +30,7 @@ import org.json.JSONObject import java.text.DecimalFormat import java.util.TimeZone import javax.inject.Inject +import kotlin.math.min class ATProfile(profile: Profile, var localInsulin: LocalInsulin, val injector: HasAndroidInjector) { @@ -39,30 +42,31 @@ class ATProfile(profile: Profile, var localInsulin: LocalInsulin, val injector: @Inject lateinit var rxBus: RxBus @Inject lateinit var rh: ResourceHelper @Inject lateinit var instantiator: Instantiator + @Inject lateinit var aapsLogger: AAPSLogger var profile: ProfileSealed var circadianProfile: ProfileSealed - lateinit var pumpProfile: ProfileSealed - var profilename: String = "" + private lateinit var pumpProfile: ProfileSealed + var profileName: String = "" var basal = DoubleArray(24) - var basalUntuned = IntArray(24) + var basalUnTuned = IntArray(24) var ic = 0.0 var isf = 0.0 var dia = 0.0 var peak = 0 var isValid: Boolean = false var from: Long = 0 - var pumpProfileAvgISF = 0.0 - var pumpProfileAvgIC = 0.0 + private var pumpProfileAvgISF = 0.0 + private var pumpProfileAvgIC = 0.0 val icSize: Int get() = profile.getIcsValues().size val isfSize: Int get() = profile.getIsfsMgdlValues().size - val avgISF: Double - get() = if (profile.getIsfsMgdlValues().size == 1) profile.getIsfsMgdlValues().get(0).value else Round.roundTo(averageProfileValue(profile.getIsfsMgdlValues()), 0.01) - val avgIC: Double - get() = if (profile.getIcsValues().size == 1) profile.getIcsValues().get(0).value else Round.roundTo(averageProfileValue(profile.getIcsValues()), 0.01) + private val avgISF: Double + get() = if (profile.getIsfsMgdlValues().size == 1) profile.getIsfsMgdlValues()[0].value else Round.roundTo(averageProfileValue(profile.getIsfsMgdlValues()), 0.01) + private val avgIC: Double + get() = if (profile.getIcsValues().size == 1) profile.getIcsValues()[0].value else Round.roundTo(averageProfileValue(profile.getIcsValues()), 0.01) fun getBasal(timestamp: Long): Double = basal[MidnightUtils.secondsFromMidnight(timestamp) / 3600] @@ -94,12 +98,12 @@ class ATProfile(profile: Profile, var localInsulin: LocalInsulin, val injector: //Export json string with oref0 format used for autotune // Include min_5m_carbimpact, insulin type, single value for carb_ratio and isf - fun profiletoOrefJSON(): String { + fun profileToOrefJSON(): String { var jsonString = "" val json = JSONObject() val insulinInterface: Insulin = activePlugin.activeInsulin try { - json.put("name", profilename) + json.put("name", profileName) json.put("min_5m_carbimpact", sp.getDouble("openapsama_min_5m_carbimpact", 3.0)) json.put("dia", dia) if (insulinInterface.id === Insulin.InsulinType.OREF_ULTRA_RAPID_ACTING) json.put( @@ -110,32 +114,31 @@ class ATProfile(profile: Profile, var localInsulin: LocalInsulin, val injector: json.put("useCustomPeakTime", true) json.put("insulinPeakTime", 45) } else if (insulinInterface.id === Insulin.InsulinType.OREF_FREE_PEAK) { - val peaktime: Int = sp.getInt(rh.gs(info.nightscout.core.utils.R.string.key_insulin_oref_peak), 75) - json.put("curve", if (peaktime > 50) "rapid-acting" else "ultra-rapid") + val peakTime: Int = sp.getInt(rh.gs(info.nightscout.core.utils.R.string.key_insulin_oref_peak), 75) + json.put("curve", if (peakTime > 50) "rapid-acting" else "ultra-rapid") json.put("useCustomPeakTime", true) - json.put("insulinPeakTime", peaktime) + json.put("insulinPeakTime", peakTime) } val basals = JSONArray() for (h in 0..23) { - val secondfrommidnight = h * 60 * 60 - var time: String - time = DecimalFormat("00").format(h) + ":00:00" + val secondFromMidnight = h * 60 * 60 + val time: String = DecimalFormat("00").format(h) + ":00:00" basals.put( JSONObject() .put("start", time) .put("minutes", h * 60) .put( - "rate", profile.getBasalTimeFromMidnight(secondfrommidnight) + "rate", profile.getBasalTimeFromMidnight(secondFromMidnight) ) ) } json.put("basalprofile", basals) - val isfvalue = Round.roundTo(avgISF, 0.001) + val isfValue = Round.roundTo(avgISF, 0.001) json.put( "isfProfile", JSONObject().put( "sensitivities", - JSONArray().put(JSONObject().put("i", 0).put("start", "00:00:00").put("sensitivity", isfvalue).put("offset", 0).put("x", 0).put("endoffset", 1440)) + JSONArray().put(JSONObject().put("i", 0).put("start", "00:00:00").put("sensitivity", isfValue).put("offset", 0).put("x", 0).put("endoffset", 1440)) ) ) json.put("carb_ratio", avgIC) @@ -145,6 +148,7 @@ class ATProfile(profile: Profile, var localInsulin: LocalInsulin, val injector: json.put("timezone", TimeZone.getDefault().id) jsonString = json.toString(2).replace("\\/", "/") } catch (e: JSONException) { + aapsLogger.error(LTag.CORE, e.stackTraceToString()) } return jsonString @@ -163,6 +167,7 @@ class ATProfile(profile: Profile, var localInsulin: LocalInsulin, val injector: } json.put("basal", jsonArray(basal)) } catch (e: JSONException) { + aapsLogger.error(LTag.CORE, e.stackTraceToString()) } return pureProfileFromJson(json, dateUtil, profile.units.asText) } @@ -172,36 +177,37 @@ class ATProfile(profile: Profile, var localInsulin: LocalInsulin, val injector: val json = JSONObject() val store = JSONObject() val tunedProfile = if (circadian) circadianProfile else profile - if (profilename.isEmpty()) - profilename = rh.gs(info.nightscout.core.ui.R.string.autotune_tunedprofile_name) + if (profileName.isEmpty()) + profileName = rh.gs(info.nightscout.core.ui.R.string.autotune_tunedprofile_name) try { - store.put(profilename, tunedProfile.toPureNsJson(dateUtil)) - json.put("defaultProfile", profilename) + store.put(profileName, tunedProfile.toPureNsJson(dateUtil)) + json.put("defaultProfile", profileName) json.put("store", store) json.put("startDate", dateUtil.toISOAsUTC(dateUtil.now())) profileStore = instantiator.provideProfileStore(json) } catch (e: JSONException) { + aapsLogger.error(LTag.CORE, e.stackTraceToString()) } return profileStore } - fun jsonArray(values: DoubleArray): JSONArray { + private fun jsonArray(values: DoubleArray): JSONArray { val json = JSONArray() for (h in 0..23) { - val secondfrommidnight = h * 60 * 60 + val secondFromMidnight = h * 60 * 60 val df = DecimalFormat("00") val time = df.format(h.toLong()) + ":00" json.put( JSONObject() .put("time", time) - .put("timeAsSeconds", secondfrommidnight) + .put("timeAsSeconds", secondFromMidnight) .put("value", values[h]) ) } return json } - fun jsonArray(value: Double) = + private fun jsonArray(value: Double): JSONArray = JSONArray().put( JSONObject() .put("time", "00:00") @@ -209,7 +215,7 @@ class ATProfile(profile: Profile, var localInsulin: LocalInsulin, val injector: .put("value", value) ) - fun jsonArray(values: List, multiplier: Double = 1.0): JSONArray { + private fun jsonArray(values: List, multiplier: Double = 1.0): JSONArray { val json = JSONArray() var elapsedHours = 0L values.forEach { @@ -249,7 +255,7 @@ class ATProfile(profile: Profile, var localInsulin: LocalInsulin, val injector: var minBasal = 1.0 for (h in 0..23) { basal[h] = Round.roundTo(profile.basalBlocks.blockValueBySeconds(T.hours(h.toLong()).secs().toInt(), 1.0, 0), 0.001) - minBasal = Math.min(minBasal, basal[h]) + minBasal = min(minBasal, basal[h]) } ic = avgIC isf = avgISF diff --git a/plugins/automation/src/main/res/values-fr-rFR/strings.xml b/plugins/automation/src/main/res/values-fr-rFR/strings.xml index f93499276f..c0efca8739 100644 --- a/plugins/automation/src/main/res/values-fr-rFR/strings.xml +++ b/plugins/automation/src/main/res/values-fr-rFR/strings.xml @@ -127,5 +127,6 @@ S D + Il est temps de manger !\nExécutez l\'assistant Bolus et refaites le calcul. Il est temps de faire le bolus !\nExécutez l\'Assistant et faites de nouveau le calcul. diff --git a/plugins/automation/src/main/res/values-ru-rRU/strings.xml b/plugins/automation/src/main/res/values-ru-rRU/strings.xml index 94eb511d5d..08f70cf702 100644 --- a/plugins/automation/src/main/res/values-ru-rRU/strings.xml +++ b/plugins/automation/src/main/res/values-ru-rRU/strings.xml @@ -127,5 +127,6 @@ Сб Вс + Пора есть!\n Запустите помощник болюса снова для подсчета. Пора дать болюс!\nЗапустите помощник болюса и повторите расчет. diff --git a/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/safety/SafetyPlugin.kt b/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/safety/SafetyPlugin.kt index 47782f0581..2e543ef4c5 100644 --- a/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/safety/SafetyPlugin.kt +++ b/plugins/constraints/src/main/java/info/nightscout/plugins/constraints/safety/SafetyPlugin.kt @@ -1,12 +1,12 @@ package info.nightscout.plugins.constraints.safety import dagger.android.HasAndroidInjector -import info.nightscout.core.extensions.putDouble -import info.nightscout.core.extensions.putInt -import info.nightscout.core.extensions.putString -import info.nightscout.core.extensions.storeDouble -import info.nightscout.core.extensions.storeInt -import info.nightscout.core.extensions.storeString +import info.nightscout.core.utils.extensions.putDouble +import info.nightscout.core.utils.extensions.putInt +import info.nightscout.core.utils.extensions.putString +import info.nightscout.core.utils.extensions.storeDouble +import info.nightscout.core.utils.extensions.storeInt +import info.nightscout.core.utils.extensions.storeString import info.nightscout.interfaces.Config import info.nightscout.interfaces.ApsMode import info.nightscout.interfaces.constraints.Constraint diff --git a/plugins/constraints/src/main/res/values-es-rES/exam.xml b/plugins/constraints/src/main/res/values-es-rES/exam.xml index 090ccceaa9..22ddaba8ce 100644 --- a/plugins/constraints/src/main/res/values-es-rES/exam.xml +++ b/plugins/constraints/src/main/res/values-es-rES/exam.xml @@ -1,145 +1,68 @@ - ¿Qué es cierto acerca de DIA? - Duración de la acción de insulina (DIA) - Debes establecer el valor de DIA en tu perfil. - El valor mínimo permitido es 5 horas. - https://androidaps.readthedocs.io/en/latest/EN/Configuration/Config-Builder.html?#insulin - Si estás satisfecho con el valor de DIA que utilizaste en tu bomba antes de utilizar AAPS y te funcionó bien, no hay necesidad de cambarlo cuando empieces a cerrar el lazo. - Deberías determinar por ti mismo el valor apropiado para DIA. - Objetivo temporal ante Hipoglucemia - ¿Cuál es la razón principal para establecer un objetivo temporal por hipoglucemia? - Para corregir hipoglucemias causadas por ajustes incorrectos de la tasa basal. - Para evitar que AAPS corrija de forma excesiva ante un aumento rápido de la glucosa por tomar carbohidratos rápidos para recuperarse de una hipoglucemia. - Para corregir una hipoglucemia que sucedió como resultando del ejercicio. - Para evitar que la glucosa sanguínea continue bajando si ya hay una tasa basal temporal igual a 0% en funcionamiento. - https://androidaps.readthedocs.io/en/latest/EN/Usage/temptarget.html - ¿Qué perfil puede ser usado y configurado estando desconectado? - Tema: Perfil desconectado - El perfil que proviene de Nightscout (NS) puede ser utilizado, pero no configurado. - https://androidaps.readthedocs.io/en/latest/EN/Configuration/Config-Builder.html#profile - Razones para aplicar \"Desconectar bomba\" en AAPS - ¿Qué se debe hacer al desconectar la bomba? - Esto es innecesario, ya que no se entregará insulina si la bomba está físicamente desconectada. - Evita que AAPS tenga en cuenta la insulina que no se administró cuando la bomba estaba físicamente desconectada - Si la bomba permanece conectada, no se detendrá el suministro de insulina. - Pasará AAPS a modo de lazo abierto + ¿Qué es cierto acerca de DAI? + Duración de la acción de insulina (DAI) + Debes establecer el valor de DAI en tu perfil. + El valor mínimo permitido es de 5 horas. + Si estás satisfecho con el valor de DAI que utilizas en tu bomba antes de utilizar AAPS y te funcionó bien, no hay necesidad de cambiarlo cuando empieces a usar el bucle cerrado. + Deberás determinar por ti mismo el valor apropiado para DAI. + Evita que AAPS considere la insulina que no se suministró cuando la bomba estaba físicamente desconectada + Se activará el modo de bucle abierto en AAPS. https://androidaps.readthedocs.io/en/latest/EN/Getting-Started/FAQ.html#other-settings - Ajustes de AAPS - Ajustes de AAPS - ¿Cuáles son las mejores prácticas para hacer copias de seguridad de sus configuraciones? - No necesita exportar sus configuraciones siempre que haga una nota de ellos. - Exporta tu configuración después de completar un objetivo. - Exportar la configuración después de cambiar cualquiera de sus ajustes. - Exportar la configuración una vez finalizada la configuración inicial y haber establecido sus preferencias. - Exportar la configuración localmente usando el menú de mantenimiento. - El archivo de configuración se encuentra en la carpeta Almacenamiento/AAPS/preferencias en el teléfono. - Copie el archivo de preferencias a una ubicación segura fuera de su teléfono (p.e. mediante el uso del alamacenamiento en la nube, conectándose con un cable a una computadora, correo electrónico, etc.) - Si su teléfono está dañado o perdido, hay formas fáciles de recuperar remotamente su configuración sin hacer una copia de seguridad. - https://androidaps.readthedocs.io/en/latest/EN/Usage/ExportImportSettings.html - https://androidaps.readthedocs.io/en/latest/EN/Getting-Started/FAQ.html#what-emergency-equipment-is-recommended-to-take-with-me - Lecturas CGM ruidosas - ¿Qué se debe hacer si los datos de CGM tienen ruido? - No hacer nada: AAPS se ocupará de ello. - Deshabilita el lazo cerrado para evitar posibles sobredosis o subdosis. - Sustituya los sensores con valores ruidosos o inexactos. - Comprueba que tu aplicación del CGM proporciona datos suavizados. - https://androidaps.readthedocs.io/en/latest/EN/Usage/Smoothing-Blood-Glucose-Data-in-xDrip.html#smoothing-blood-glucose-data - Ejercicio y perfiles - ¿Cómo puede usar perfiles para ayudar mejor al sistema a hacer frente al ejercicio aeróbico? - Haga un cambio de perfil a menos de 100%. - Haga un cambio de perfil a más de 100%. - Dejar el perfil configurado al 100%. - Suspender el lazo - https://androidaps.readthedocs.io/en/latest/EN/Usage/temptarget.html#activity-temp-target - Ejercicios y objetivos temporales - ¿Cómo se puede usar objetivos temporales para ayudar mejor al sistema a hacer frente al ejercicio aeróbico? - Establece un objetivo de glucosa en la sangre actividad que comienza un tiempo adecuado antes de comenzar el ejercicio. - Establece un objetivo de glucosa en la sangre actividad después de finalizar el ejercicio. - Deja tu objetivo de glucosa sanguíneo sin cambios. - Espere hasta que la glucosa en sangre caiga por debajo de su objetivo de hipo temp y luego coma 15 g de hidratos de carbono de actividad rápida. - https://androidaps.readthedocs.io/en/latest/EN/Usage/temptarget.html#activity-temp-target - ¿Recibo insulina cuando el lazo está desactivado/suspendido? - Sí, la insulina basal sigue siendo entregada. - No, la administración de la insulina está detenida. - Pruebas basales, ISF, e I:C - ¿Cuándo se deben validar estos valores? - Antes de empezar el lazo - Cuando se tienen valores de glucosa altos o bajos frecuentemente. - Al menos una vez a la semana. - Una vez fijados y validados, estos valores no debrían cambiar a lo largo del tiempo. - https://androidaps.readthedocs.io/en/latest/EN/Getting-Started/FAQ.html#androidaps-settings - Requisitos previos - ¿Qué es esencial para configurar y utilizar AAPS? - Información de perfil validada (Basal, IC, ISF, DIA). - Un ordenador con Android Studio instalado y configurado. - Un teléfono compatible. - Una bomba de insulina compatible, si planeas usar el sistema en modo \"lazo cerrado\". - Nightscout, para tener un registro de los datos y revisar los parámetros de configuración. - Una cuenta de Tidepool. - Una cuenta de Google. - Una cuenta de Github. - Experiencia programando o editando código. - Una bomba MiniMed 670G. - https://androidaps.readthedocs.io/en/latest/EN/Module/module.html - Un Smartwatch. - Un MCG soportado. - Requisitos previos - ¿Qué es esencial para configurar y utilizar AAPS? - Parámetros validados para poder configurar un perfil (ISF, I:C ratio, perfil basal, DIA etc.). - Un dispositivo Android compatible (e.j. un móvil, un smartwatch Android compatible o una tablet). - AAPS requiere una conexión a Internet para funcionar en modo lazo cerrado. - Un medidor continuo de glucosa (MCG) y una aplicación capaz de recibir los valores proporcionados por el medidor en el móvil o tablet. - https://androidaps.readthedocs.io/en/latest/EN/Module/module.html - Actualizando AAPS - Compruebe todas las respuestas correctas. - Es necesario tener Git instalado y configurado en el ordenador. - Cuando esté disponible una versión más reciente de AAPS, las funciones de las versiones anteriores pueden ser limitadas de forma remota después de una fecha determinada. - Se debe guardar en un lugar seguro la \"keystore\" que se ha empleado y usar la misma\"key\" para futuras actulizaciones. - Nunca actualice si el sistema está funcionando bien. - Si tienes problemas construyendo la aplicación (. apk), puedes instalar el mismo archivo. apk compilado por un amigo. - https://androidaps.readthedocs.io/en/latest/EN/Installing-AndroidAPS/Update-to-new-version.html#update-to-a-new-version-or-branch - Solución de problemas - ¿Dónde puedes buscar ayuda con AAPS? - Puede solicitar asesoramiento en el grupo de usuarios de AAPS en Facebook. - Deberías leer (y volver a leer) la documentación de AAPS. - Puedes solicitar asesoramiento y registrar problemas técnicos o indidencias en el grupo de Discord de AAPS. - Debes preguntar a tu endocrino o educador diabetológico. - https://androidaps.readthedocs.io/en/latest/EN/Installing-AndroidAPS/Update-to-new-version.html#troubleshooting - https://www.facebook.com/groups/AndroidAPSUsers/ - https://discord.gg/4fQUWHZ4Mw - Plugins de insulina - ¿Qué insulina debes usar con el plugin Ultra-Rapid Oref? - Fiasp® - NovoRapid®/Novolog® - Humalog® - Actrapid®/Humalin R®/\"insulina humana estándar\". - https://androidaps.readthedocs.io/en/latest/EN/Configuration/Config-Builder.html#insulin - Plugins de sensibilidad - Compruebe todas las respuestas correctas. - Los plugins de sensibilidad permiten a AAPS ajustarse para cambios temporales o de corta duración en la sensibilidad a la insulina (por ejemplo, cambios hormonales o problemas con la absorción en el sitio de infusión). - Los plugins de sensibilidad sugieren al usuario cambios en la cantidad de insulina basal a suministrar, en el factor de sensibiliad a la insulina (ISF) y en el ratio I:C y pueden ser incorporados al perfil definido. - Registrar el cámbio de cánula reseteará Autosens, dejándolo de nuevo al 100%. - Algunas de las opciones del plugin tienen rangos de tiempo configurables que pueden ser definidos por el usuario. - https://androidaps.readthedocs.io/en/latest/EN/Configuration/Sensitivity-detection-and-COB.html - https://androidaps.readthedocs.io/es/latest/Usage/Open-APS-features.html?highlight=Autosens#autosens - Error de entrada de Carbohidratos - ¿Qué deberías hacer si has hecho una entrada incorrecta de carbohidratos? - Elimina la entrada incorrecta en los tratamientos e introduce el valor correcto de carbohidratos. - Bolo con insulina usando el menú de llenado de la infusión. - No hacer nada - AAPS realizará los ajustes apropiados. - Bolo con insulina usando el botón de Insulina (bolus) en página general. - Errores de entrega/entrada de insulina - ¿Qué debes hacer si recibiste menos insulina de la que sugiere la historia de la bomba p.ej. debido a una oclusión, una cánula fallida o olvidarse de reponer la bomba después de una ducha? - Elimina los datos de insulina del portal de Nightscout Careportal para eliminarlos del historial de la bomba. - Comparar valores en AAPS con el historial de la bomba (si la bomba lo soporta). - Bolo una proporción de la insulina calculada “perdida” por jeringa/pluma o usando menú de llenado. - No hacer nada y permite que AAPS corrija cualquier resultado de nivel alto de glucosa en sangre. - Carbohidratos activos (COB) - ¿Cómo afecta el cambio del valor ISF al cálculo de COB? - Incrementar el ISF hará que los carbohidratos se absorban más lentamente - Incrementar el ISF hará que los carbohidratos se absorban más rápidamente - Incrementar el ISF no afectará la absorción calculada de carbohidratos + No necesita exportar sus configuraciones siempre que haga las tenga anotadas. + Exportar tu configuración después de completar un objetivo. + Exportar las configuraciones después de cambiar cualquiera de sus ajustes. + Exportar las configuraciones una vez finalizada la configuración inicial y haber establecido sus preferencias. + Copie el archivo de preferencias a una ubicación segura fuera de su teléfono (p.e. mediante el uso del almacenamiento en la nube, conectando su teléfono con un cable a una computadora, correo electrónico, etc.) + Si su teléfono es dañado o perdido, hay formas fáciles de recuperar remotamente su configuración sin hacer una copia de seguridad. + Lecturas CGM con mucha variabilidad + ¿Qué se debe hacer si los datos de CGM tienen mucha variabilidad? + Deshabilitar el bucle cerrado para evitar posibles sobredosis o subdosis. + Sustituya el sensor con valores muy variables o inexactos. + ¿Cómo puede usar los perfiles para mejorar el sistema durante el ejercicio aeróbico? + Cambie el perfil por un valor menor a 100%. + Cambie el perfil por un valor mayor a 100%. + Suspender el bucle. + ¿Cómo se puede usar el objetivo temporal de glucosa para ayudar al sistema durante los ejercicios aeróbicos? + Establezca el objetivo de tipo actividad antes de comenzar el ejercicio, considerando un tiempo razonable antes de la actividad. + Establezca un objetivo de tipo actividad después de finalizar el ejercicio. + Deja tu objetivo de glucosa sin cambios. + Espere hasta que los valores de glucosa se encuentren por debajo del valor definido en el objetivo de tipo hipoglicemia. Luego consuma 15 g de carbohidratos de rápida absorción. + ¿Puedo recibir insulina cuando el bucle está desactivado/suspendido? + Sí, la insulina basal sigue siendo suministrada. + No, la administración de la insulina se detiene. + Pruebas para basales, I:C y FSI + Antes de empezar cualquier bucle. + Cuando los valores de glucosa son muy altos o bajos de manera frecuente. + Una vez establecidos y validados, estos valores no deberían cambiar a lo largo del tiempo. + Información de perfil previamente validada (Basal, IC, FSI, DAI). + Una computadora con Android Studio instalado y configurado. + Una bomba de insulina compatible, si planeas usar el sistema en modo bucle cerrado. + AAPS requiere una conexión a Internet para funcionar con el modo bucle cerrado. + Seleccione todas las respuestas correctas. + Es necesario tener Git instalado y configurado en la computadora. + Cuando esté disponible una versión más reciente de AAPS, las funciones de las versiones anteriores pueden ser limitadas de forma remota después de una fecha especifica. + Se debe guardar en un lugar seguro de su computadora la \"keystore\" (archivo.jks) que se ha empleado previamente y usar la misma \"keystore\" para futuras actualizaciones. + Nunca se debe actualizar AAPS si el sistema está funcionando bien. + Puedes solicitar asesoramiento y registrar problemas técnicos o incidencias en el grupo de Discord de AAPS. + Debes preguntar a tu endocrinólogo o educador en diabetes. + Seleccione todas las respuestas correctas. + Los plugins de sensibilidad sugieren al usuario cambios en la cantidad de insulina basal a suministrar, en el factor de sensibilidad a la insulina (ISF) y en el ratio I:C y pueden ser incorporados al perfil definido. + Registrar el cámbio de cánula reinicia Autosens, volviendo de nuevo al 100%. + Error de ingreso de Carbohidratos + ¿Qué deberías hacer si has cometido un error al ingresar carbohidratos? + Elimina la entrada incorrecta en pestaña de tratamientos e introduce el valor correcto. + Darse un bolo desde el menú de llenado de la infusión. + No hacer nada - AAPS realizará los ajustes necesarios. + Darse un bolo usando el botón de Insulina (bolus) en página general. + Elimina los valores de insulina del portal de Nightscout o Careportal para eliminarlos del historial de la bomba. + Comparar valores en AAPS con el historial de la bomba (si la bomba los registra). + Bolo una proporción de la insulina calculada “perdida” por jeringa/pluma o usando menú de Insulina. + No hacer nada y permite que AAPS corrija cualquier resultado de nivel alto de glucosa. + ¿Cómo afecta el cambio del valor FSI al cálculo de COB? + Incrementar el FSI hará que los carbohidratos se absorban más lentamente + Incrementar el FSI hará que los carbohidratos se absorban más rápidamente + Incrementar el FSI no afectará la absorción calculada de carbohidratos ¿Cómo afecta cambiar los valores de IC a los cálculos de COB? Incrementar el IC hará que los carbohidratos se absorban más lentamente Incrementar el IC hará que los carbohidratos se absorban más rápidamente diff --git a/plugins/constraints/src/main/res/values-fr-rFR/strings.xml b/plugins/constraints/src/main/res/values-fr-rFR/strings.xml index 4e6f7bd219..668de616e0 100644 --- a/plugins/constraints/src/main/res/values-fr-rFR/strings.xml +++ b/plugins/constraints/src/main/res/values-fr-rFR/strings.xml @@ -2,12 +2,27 @@ + Changement d\'heure dans moins de 24 heures + Changement d\'heure dans moins de 3 heures - Boucle fermée désactivée + Boucle désactivée ! Libérez au moins %1$d Mo du stockage interne ! + ancienne version + très ancienne version + Application expirée + Nouvelle version disponible depuis %1$d jours ! Retour à Arrêt Glycémie Basse (AGB) dans %2$d jours, la boucle sera désactivée dans %3$d jours + Nous avons détecté que vous utilisez une version invalide. Boucle désactivée ! + Version %1$s disponible + La version %1$s expire le %2$s + Données recalculées utilisées + Gly trop proche :\n%1$s\n%2$s + recalculé + entrées doubles Données plates. Considérées comme incorrectes + Bolus étendu limité à %1$.1f U à cause de %2$s Limiter les glucides %1$d g à cause de %2$s Pompe n’est pas capable de basals temporaires Mode de Boucle Fermée désactivé dans les préférences @@ -17,7 +32,7 @@ SMB non autorisé en mode boucle ouverte valeur Max dans les préférences limite fixée - Traitements de sécurité + Sécurité des traitements Terminé, félicitations ! Pas encore terminé diff --git a/plugins/constraints/src/main/res/values-ru-rRU/exam.xml b/plugins/constraints/src/main/res/values-ru-rRU/exam.xml index 92a6e8f53b..9d2bed09e7 100644 --- a/plugins/constraints/src/main/res/values-ru-rRU/exam.xml +++ b/plugins/constraints/src/main/res/values-ru-rRU/exam.xml @@ -108,6 +108,7 @@ https://androidaps.readthedocs.io/en/latest/EN/Installing-AndroidAPS/Update-to-new-version.html#troubleshooting https://www.facebook.com/groups/AndroidAPSUsers/ https://discord.gg/4fQUWHZ4Mw + Модули для инсулинов Какой инсулин следует использовать с модулем Сверхбыстрый Oref? Fiasp® Novoapid ® /Novolog ® diff --git a/plugins/constraints/src/main/res/values-ru-rRU/strings.xml b/plugins/constraints/src/main/res/values-ru-rRU/strings.xml index 332dd41100..844423e9f1 100644 --- a/plugins/constraints/src/main/res/values-ru-rRU/strings.xml +++ b/plugins/constraints/src/main/res/values-ru-rRU/strings.xml @@ -2,11 +2,27 @@ + Переход на летнее/зимнее время через 24 часа или менее + Изменение сезонного времени произошло меньше 3 часов назад-Закрытый цикл выключен + Освободите по крайней мере %1$d MB из внутренней памяти! Цикл остановлен! + старая версия + очень старая версия + Истек срок действия приложения + Новая версия доступна уже %1$d дней! По истечении %2$d дн алгоритм переходит в режим работы только с остановкой при низкой гликемии LGS, замкнутый цикл будет отключен через %3$d дн + Мы обнаружили, что вы используете недопустимую версию. Цикл отключен! + Доступна версия %1$s + Версия: %1$s истекает %2$s + Используются пересчитанные данные + ГК слишком близко:\n%1$s\n%2$s + пересчитано + двойные записи + Неменяющиеся данные. Принимаю за неверные + Ограничиваю пролонгированный болюс до %1$.1f ед. из-за %2$s Ограничение углеводов до %1$d г. из-за %2$s Помпа не рассчитана на подачу временного базала Режим замкнутого цикла отключен в настройках @@ -18,6 +34,7 @@ жесткий предел Безопасность терапии + Завершено, отлично! Не завершено Прошло времени Максимум активного инсулина IOB установлен правильно diff --git a/plugins/insulin/src/main/java/info/nightscout/insulin/InsulinOrefFreePeakPlugin.kt b/plugins/insulin/src/main/java/info/nightscout/insulin/InsulinOrefFreePeakPlugin.kt index 30ed94d058..60582ac68f 100644 --- a/plugins/insulin/src/main/java/info/nightscout/insulin/InsulinOrefFreePeakPlugin.kt +++ b/plugins/insulin/src/main/java/info/nightscout/insulin/InsulinOrefFreePeakPlugin.kt @@ -1,8 +1,8 @@ package info.nightscout.insulin import dagger.android.HasAndroidInjector -import info.nightscout.core.extensions.putInt -import info.nightscout.core.extensions.storeInt +import info.nightscout.core.utils.extensions.putInt +import info.nightscout.core.utils.extensions.storeInt import info.nightscout.interfaces.Config import info.nightscout.interfaces.insulin.Insulin import info.nightscout.interfaces.profile.ProfileFunction diff --git a/plugins/insulin/src/main/res/values-fr-rFR/strings.xml b/plugins/insulin/src/main/res/values-fr-rFR/strings.xml index 9c694e762c..3554c0dc9d 100644 --- a/plugins/insulin/src/main/res/values-fr-rFR/strings.xml +++ b/plugins/insulin/src/main/res/values-fr-rFR/strings.xml @@ -1,8 +1,18 @@ + Lyumjev + Réglages pour les insulines Humalog et NovoRapid / NovoLog + Réglages pour l\'insuline Fiasp + Réglages pour l\'insuline Lyumjev + Permet de définir le pic de l’activité de l’insuline et ne doit être utilisé que par les utilisateurs avancés + INS + Délai du pic de la courbe IA + Délai du pic [min] Profil d\'insuline ajustable Oref Insuline à Action Rapide Oref Insuline Ultra Rapide Oref Durée d’Action pour %1$f trop courte - utiliser %2$f à la place ! + Novorapid, Novolog, Humalog + Fiasp diff --git a/plugins/main/src/main/AndroidManifest.xml b/plugins/main/src/main/AndroidManifest.xml index aff7ae7188..1bcf09f595 100644 --- a/plugins/main/src/main/AndroidManifest.xml +++ b/plugins/main/src/main/AndroidManifest.xml @@ -1,11 +1,14 @@ + + - diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/overview/OverviewPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/overview/OverviewPlugin.kt index be8198fd6c..09facd21a8 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/overview/OverviewPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/overview/OverviewPlugin.kt @@ -7,14 +7,14 @@ import androidx.preference.SwitchPreference import dagger.android.HasAndroidInjector import info.nightscout.core.events.EventIobCalculationProgress import info.nightscout.core.events.EventNewNotification -import info.nightscout.core.extensions.putDouble -import info.nightscout.core.extensions.putInt -import info.nightscout.core.extensions.putString -import info.nightscout.core.extensions.storeDouble -import info.nightscout.core.extensions.storeInt -import info.nightscout.core.extensions.storeString import info.nightscout.core.graph.OverviewData import info.nightscout.core.ui.dialogs.OKDialog +import info.nightscout.core.utils.extensions.putDouble +import info.nightscout.core.utils.extensions.putInt +import info.nightscout.core.utils.extensions.putString +import info.nightscout.core.utils.extensions.storeDouble +import info.nightscout.core.utils.extensions.storeInt +import info.nightscout.core.utils.extensions.storeString import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.interfaces.Config import info.nightscout.interfaces.Overview diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/overview/dialogs/EditQuickWizardDialog.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/overview/dialogs/EditQuickWizardDialog.kt index 78e3fac0f1..217b5adc92 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/overview/dialogs/EditQuickWizardDialog.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/overview/dialogs/EditQuickWizardDialog.kt @@ -10,9 +10,9 @@ import android.view.WindowManager import com.google.android.material.timepicker.MaterialTimePicker import com.google.android.material.timepicker.TimeFormat import dagger.android.support.DaggerDialogFragment -import info.nightscout.androidaps.utils.extensions.selectedItemPosition -import info.nightscout.androidaps.utils.extensions.setEnableForChildren -import info.nightscout.androidaps.utils.extensions.setSelection +import info.nightscout.core.ui.extensions.selectedItemPosition +import info.nightscout.core.ui.extensions.setEnableForChildren +import info.nightscout.core.ui.extensions.setSelection import info.nightscout.core.wizard.QuickWizard import info.nightscout.core.wizard.QuickWizardEntry import info.nightscout.plugins.R diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/WearFragment.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/WearFragment.kt index 12d516917d..57cd89ec9d 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/WearFragment.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/WearFragment.kt @@ -5,9 +5,9 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import dagger.android.support.DaggerFragment -import info.nightscout.androidaps.plugins.general.wear.events.EventWearUpdateGui import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.plugins.databinding.WearFragmentBinding +import info.nightscout.plugins.general.wear.events.EventWearUpdateGui import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventMobileToWear diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/events/EventWearUpdateGui.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/events/EventWearUpdateGui.kt index e7cb807f01..b8c4761358 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/events/EventWearUpdateGui.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/events/EventWearUpdateGui.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.wear.events +package info.nightscout.plugins.general.wear.events import info.nightscout.rx.events.Event diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataLayerListenerServiceMobile.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataLayerListenerServiceMobile.kt index 8e9696e0f4..13a8ff47f9 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataLayerListenerServiceMobile.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataLayerListenerServiceMobile.kt @@ -15,7 +15,6 @@ import com.google.android.gms.wearable.PutDataMapRequest import com.google.android.gms.wearable.Wearable import com.google.android.gms.wearable.WearableListenerService import dagger.android.AndroidInjection -import info.nightscout.androidaps.plugins.general.wear.events.EventWearUpdateGui import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.Config @@ -27,6 +26,7 @@ import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.receivers.ReceiverStatusStore import info.nightscout.plugins.R import info.nightscout.plugins.general.wear.WearPlugin +import info.nightscout.plugins.general.wear.events.EventWearUpdateGui import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventMobileToWear diff --git a/plugins/source/src/main/java/info/nightscout/source/BGSourceFragment.kt b/plugins/source/src/main/java/info/nightscout/source/BGSourceFragment.kt index 29808634f9..a308813c4e 100644 --- a/plugins/source/src/main/java/info/nightscout/source/BGSourceFragment.kt +++ b/plugins/source/src/main/java/info/nightscout/source/BGSourceFragment.kt @@ -140,7 +140,7 @@ class BGSourceFragment : DaggerFragment(), MenuProvider { val newDay = position == 0 || !dateUtil.isSameDay(glucoseValue.timestamp, glucoseValues[position - 1].timestamp) holder.binding.date.visibility = newDay.toVisibility() holder.binding.date.text = if (newDay) dateUtil.dateStringRelative(glucoseValue.timestamp, rh) else "" - holder.binding.time.text = dateUtil.timeString(glucoseValue.timestamp) + holder.binding.time.text = dateUtil.timeStringWithSeconds(glucoseValue.timestamp) holder.binding.value.text = glucoseValue.valueToUnitsString(profileFunction.getUnits()) holder.binding.direction.setImageResource(glucoseValue.trendArrow.directionToIcon()) if (position > 0) { diff --git a/plugins/source/src/main/res/values-es-rES/strings.xml b/plugins/source/src/main/res/values-es-rES/strings.xml index d1e10c327d..1af8d15dc1 100644 --- a/plugins/source/src/main/res/values-es-rES/strings.xml +++ b/plugins/source/src/main/res/values-es-rES/strings.xml @@ -1,22 +1,7 @@ - NSClient BG - NS BG - Recibir los datos de glucosa de Nightscout - xDrip+ - Recibir los valores de glucosa de xDrip+ - Dexcom (BYODA) - BYODA - Recibir los valores de glucosa de la aplicación Dexcom \'Build Your Own Device\' - Eversense App (parcheada) - Recibir los valores de glucosa de la aplicación Eversense parcheada. - Glimp - Recibir valores de glucosa de Glimp. - MM640g - Recibir los valores de glucosa del 600SeriesAndroidUploader. - Poctech - Recibir los valores de glucosa de Poctech + Eversense App (parchada) Glunovo Recibir los valores de glucosa de la aplicación Glunovo Intelligo @@ -35,4 +20,5 @@ Ajuste de subida de datos de glucosa Registro de cambio de sensor en Nightscout Crear evento \"Cambio de sensor\" en Nightscout automáticamente al iniciar el sensor + dirección diff --git a/plugins/source/src/main/res/values-fr-rFR/strings.xml b/plugins/source/src/main/res/values-fr-rFR/strings.xml index bfdf27b888..a9e7d5075c 100644 --- a/plugins/source/src/main/res/values-fr-rFR/strings.xml +++ b/plugins/source/src/main/res/values-fr-rFR/strings.xml @@ -35,4 +35,5 @@ Paramètres de téléchargement des glycémies Enreg. du changement de capteur sur NS Créer automatiquement un événement \"Changement de capteur\" dans NS au démarrage du capteur + direction diff --git a/plugins/source/src/main/res/values-ru-rRU/strings.xml b/plugins/source/src/main/res/values-ru-rRU/strings.xml index 75ade468d5..13210be58e 100644 --- a/plugins/source/src/main/res/values-ru-rRU/strings.xml +++ b/plugins/source/src/main/res/values-ru-rRU/strings.xml @@ -1,6 +1,8 @@ + ГК с клиента Nightscout + ГК с NS Получать данные гликемии с сайта Nightscout xDrip + Получать данные гликемии от xDrip+. @@ -9,7 +11,9 @@ Получать данные ГК от \'Самостоятельно собранного приложения Dexcom\'. Приложение Eversense (пропатченное) Получать данные гликемии от пропатченного приложения Eversense. + Glimp Получать данные гликемии от Glimp. + MM640g Получать данные гликемии от 600SeriesAndroidUploader. Poctech Получать данные гликемии от приложения Poctech @@ -20,6 +24,7 @@ Томато (MiaoMiao) Томато Получать значения ГК от приложения Tomato (устройство MiaoMiao) + Aidex GlucoRx Aidex Получить значения ГК от GlucoRx Aidex Случайные значения ГК @@ -30,4 +35,5 @@ Параметры загрузки СК Вносить запись о замене сенсора в NS Автоматически создать событие \"Замена сенсора\" в NS при запуске сенсора + направление diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/DataSyncSelectorImplementation.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/DataSyncSelectorImplementation.kt index cce42329b2..7536a783d9 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/DataSyncSelectorImplementation.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/DataSyncSelectorImplementation.kt @@ -159,7 +159,7 @@ class DataSyncSelectorImplementation @Inject constructor( } // without nsId = create new bolus.first.interfaceIDs.nightscoutId == null -> - activePlugin.activeNsClient?.nsClientService?.dbAdd( + activePlugin.activeNsClient?.dbAdd( "treatments", bolus.first.toJson(true, dateUtil), DataSyncSelector.PairBolus(bolus.first, bolus.second.id), @@ -167,7 +167,7 @@ class DataSyncSelectorImplementation @Inject constructor( ) // with nsId = update if it's modified record bolus.first.interfaceIDs.nightscoutId != null && bolus.first.id != bolus.second.id -> - activePlugin.activeNsClient?.nsClientService?.dbUpdate( + activePlugin.activeNsClient?.dbUpdate( "treatments", bolus.first.interfaceIDs.nightscoutId, bolus.first.toJson(false, dateUtil), @@ -222,10 +222,10 @@ class DataSyncSelectorImplementation @Inject constructor( } // without nsId = create new carb.first.interfaceIDs.nightscoutId == null -> - activePlugin.activeNsClient?.nsClientService?.dbAdd("treatments", carb.first.toJson(true, dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second.id), "$startId/$lastDbId") + activePlugin.activeNsClient?.dbAdd("treatments", carb.first.toJson(true, dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second.id), "$startId/$lastDbId") // with nsId = update if it's modified record carb.first.interfaceIDs.nightscoutId != null && carb.first.id != carb.second.id -> - activePlugin.activeNsClient?.nsClientService?.dbUpdate( + activePlugin.activeNsClient?.dbUpdate( "treatments", carb.first.interfaceIDs.nightscoutId, carb.first.toJson(false, dateUtil), @@ -280,7 +280,7 @@ class DataSyncSelectorImplementation @Inject constructor( } // without nsId = create new bolusCalculatorResult.first.interfaceIDs.nightscoutId == null -> - activePlugin.activeNsClient?.nsClientService?.dbAdd( + activePlugin.activeNsClient?.dbAdd( "treatments", bolusCalculatorResult.first.toJson(true, dateUtil, profileFunction), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second.id), @@ -288,7 +288,7 @@ class DataSyncSelectorImplementation @Inject constructor( ) // with nsId = update if it's modified record bolusCalculatorResult.first.interfaceIDs.nightscoutId != null && bolusCalculatorResult.first.id != bolusCalculatorResult.second.id -> - activePlugin.activeNsClient?.nsClientService?.dbUpdate( + activePlugin.activeNsClient?.dbUpdate( "treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, bolusCalculatorResult.first.toJson(false, dateUtil, profileFunction), DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second.id), "$startId/$lastDbId" ) @@ -340,7 +340,7 @@ class DataSyncSelectorImplementation @Inject constructor( } // without nsId = create new tt.first.interfaceIDs.nightscoutId == null -> - activePlugin.activeNsClient?.nsClientService?.dbAdd( + activePlugin.activeNsClient?.dbAdd( "treatments", tt.first.toJson(true, profileFunction.getUnits(), dateUtil), DataSyncSelector.PairTemporaryTarget(tt.first, tt.second.id), @@ -348,7 +348,7 @@ class DataSyncSelectorImplementation @Inject constructor( ) // existing with nsId = update tt.first.interfaceIDs.nightscoutId != null -> - activePlugin.activeNsClient?.nsClientService?.dbUpdate( + activePlugin.activeNsClient?.dbUpdate( "treatments", tt.first.interfaceIDs.nightscoutId, tt.first.toJson(false, profileFunction.getUnits(), dateUtil), @@ -403,10 +403,10 @@ class DataSyncSelectorImplementation @Inject constructor( } // without nsId = create new food.first.interfaceIDs.nightscoutId == null -> - activePlugin.activeNsClient?.nsClientService?.dbAdd("food", food.first.toJson(true), DataSyncSelector.PairFood(food.first, food.second.id), "$startId/$lastDbId") + activePlugin.activeNsClient?.dbAdd("food", food.first.toJson(true), DataSyncSelector.PairFood(food.first, food.second.id), "$startId/$lastDbId") // with nsId = update food.first.interfaceIDs.nightscoutId != null -> - activePlugin.activeNsClient?.nsClientService?.dbUpdate( + activePlugin.activeNsClient?.dbUpdate( "food", food.first.interfaceIDs.nightscoutId, food.first.toJson(false), @@ -462,10 +462,10 @@ class DataSyncSelectorImplementation @Inject constructor( } // without nsId = create new gv.first.interfaceIDs.nightscoutId == null -> - activePlugin.activeNsClient?.nsClientService?.dbAdd("entries", gv.first.toJson(true, dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second.id), "$startId/$lastDbId") + activePlugin.activeNsClient?.dbAdd("entries", gv.first.toJson(true, dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second.id), "$startId/$lastDbId") // with nsId = update else -> // gv.first.interfaceIDs.nightscoutId != null - activePlugin.activeNsClient?.nsClientService?.dbUpdate( + activePlugin.activeNsClient?.dbUpdate( "entries", gv.first.interfaceIDs.nightscoutId, gv.first.toJson(false, dateUtil), @@ -524,10 +524,10 @@ class DataSyncSelectorImplementation @Inject constructor( } // without nsId = create new te.first.interfaceIDs.nightscoutId == null -> - activePlugin.activeNsClient?.nsClientService?.dbAdd("treatments", te.first.toJson(true, dateUtil), DataSyncSelector.PairTherapyEvent(te.first, te.second.id), "$startId/$lastDbId") + activePlugin.activeNsClient?.dbAdd("treatments", te.first.toJson(true, dateUtil), DataSyncSelector.PairTherapyEvent(te.first, te.second.id), "$startId/$lastDbId") // nsId = update te.first.interfaceIDs.nightscoutId != null -> - activePlugin.activeNsClient?.nsClientService?.dbUpdate( + activePlugin.activeNsClient?.dbUpdate( "treatments", te.first.interfaceIDs.nightscoutId, te.first.toJson(false, dateUtil), @@ -567,7 +567,7 @@ class DataSyncSelectorImplementation @Inject constructor( when { // without nsId = create new deviceStatus.interfaceIDs.nightscoutId == null -> - activePlugin.activeNsClient?.nsClientService?.dbAdd("devicestatus", deviceStatus.toJson(dateUtil), deviceStatus, "$startId/$lastDbId") + activePlugin.activeNsClient?.dbAdd("devicestatus", deviceStatus.toJson(dateUtil), deviceStatus, "$startId/$lastDbId") // with nsId = ignore deviceStatus.interfaceIDs.nightscoutId != null -> Any() } @@ -620,7 +620,7 @@ class DataSyncSelectorImplementation @Inject constructor( } // without nsId = create new tb.first.interfaceIDs.nightscoutId == null -> - activePlugin.activeNsClient?.nsClientService?.dbAdd( + activePlugin.activeNsClient?.dbAdd( "treatments", tb.first.toJson(true, profile, dateUtil), DataSyncSelector.PairTemporaryBasal(tb.first, tb.second.id), @@ -628,7 +628,7 @@ class DataSyncSelectorImplementation @Inject constructor( ) // with nsId = update tb.first.interfaceIDs.nightscoutId != null -> - activePlugin.activeNsClient?.nsClientService?.dbUpdate( + activePlugin.activeNsClient?.dbUpdate( "treatments", tb.first.interfaceIDs.nightscoutId, tb.first.toJson(false, profile, dateUtil), @@ -691,7 +691,7 @@ class DataSyncSelectorImplementation @Inject constructor( } // without nsId = create new eb.first.interfaceIDs.nightscoutId == null -> - activePlugin.activeNsClient?.nsClientService?.dbAdd( + activePlugin.activeNsClient?.dbAdd( "treatments", eb.first.toJson(true, profile, dateUtil), DataSyncSelector.PairExtendedBolus(eb.first, eb.second.id), @@ -699,7 +699,7 @@ class DataSyncSelectorImplementation @Inject constructor( ) // with nsId = update eb.first.interfaceIDs.nightscoutId != null -> - activePlugin.activeNsClient?.nsClientService?.dbUpdate( + activePlugin.activeNsClient?.dbUpdate( "treatments", eb.first.interfaceIDs.nightscoutId, eb.first.toJson(false, profile, dateUtil), @@ -759,10 +759,10 @@ class DataSyncSelectorImplementation @Inject constructor( } // without nsId = create new ps.first.interfaceIDs.nightscoutId == null -> - activePlugin.activeNsClient?.nsClientService?.dbAdd("treatments", ps.first.toJson(true, dateUtil), DataSyncSelector.PairProfileSwitch(ps.first, ps.second.id), "$startId/$lastDbId") + activePlugin.activeNsClient?.dbAdd("treatments", ps.first.toJson(true, dateUtil), DataSyncSelector.PairProfileSwitch(ps.first, ps.second.id), "$startId/$lastDbId") // with nsId = update ps.first.interfaceIDs.nightscoutId != null -> - activePlugin.activeNsClient?.nsClientService?.dbUpdate( + activePlugin.activeNsClient?.dbUpdate( "treatments", ps.first.interfaceIDs.nightscoutId, ps.first.toJson(false, dateUtil), @@ -816,7 +816,7 @@ class DataSyncSelectorImplementation @Inject constructor( } // without nsId = create new ps.first.interfaceIDs.nightscoutId == null -> - activePlugin.activeNsClient?.nsClientService?.dbAdd( + activePlugin.activeNsClient?.dbAdd( "treatments", ps.first.toJson(true, dateUtil), DataSyncSelector.PairEffectiveProfileSwitch(ps.first, ps.second.id), @@ -824,7 +824,7 @@ class DataSyncSelectorImplementation @Inject constructor( ) // with nsId = update ps.first.interfaceIDs.nightscoutId != null -> - activePlugin.activeNsClient?.nsClientService?.dbUpdate( + activePlugin.activeNsClient?.dbUpdate( "treatments", ps.first.interfaceIDs.nightscoutId, ps.first.toJson(false, dateUtil), @@ -879,10 +879,10 @@ class DataSyncSelectorImplementation @Inject constructor( } // without nsId = create new oe.first.interfaceIDs.nightscoutId == null -> - activePlugin.activeNsClient?.nsClientService?.dbAdd("treatments", oe.first.toJson(true, dateUtil), DataSyncSelector.PairOfflineEvent(oe.first, oe.second.id), "$startId/$lastDbId") + activePlugin.activeNsClient?.dbAdd("treatments", oe.first.toJson(true, dateUtil), DataSyncSelector.PairOfflineEvent(oe.first, oe.second.id), "$startId/$lastDbId") // existing with nsId = update oe.first.interfaceIDs.nightscoutId != null -> - activePlugin.activeNsClient?.nsClientService?.dbUpdate( + activePlugin.activeNsClient?.dbUpdate( "treatments", oe.first.interfaceIDs.nightscoutId, oe.first.toJson(false, dateUtil), @@ -905,7 +905,7 @@ class DataSyncSelectorImplementation @Inject constructor( if (lastChange > lastSync) { if (activePlugin.activeProfileSource.profile?.allProfilesValid != true) return val profileJson = activePlugin.activeProfileSource.profile?.data ?: return - activePlugin.activeNsClient?.nsClientService?.dbAdd("profile", profileJson, DataSyncSelector.PairProfileStore(profileJson, dateUtil.now()), "") + activePlugin.activeNsClient?.dbAdd("profile", profileJson, DataSyncSelector.PairProfileStore(profileJson, dateUtil.now()), "") } } } diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/NSClientPlugin.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/NSClientPlugin.kt index be820c7839..a6dad603c0 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/NSClientPlugin.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/NSClientPlugin.kt @@ -47,6 +47,7 @@ import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign +import org.json.JSONObject import javax.inject.Inject import javax.inject.Singleton @@ -81,7 +82,7 @@ class NSClientPlugin @Inject constructor( private val handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper) private val listLog: MutableList = ArrayList() override var status = "" - override var nsClientService: NSClientService? = null + var nsClientService: NSClientService? = null val isAllowed: Boolean get() = nsClientReceiverDelegate.allowed val blockingReason: String @@ -235,4 +236,12 @@ class NSClientPlugin @Inject constructor( override fun resetToFullSync() { dataSyncSelector.resetToNextFullSync() } + + override fun dbAdd(collection: String, data: JSONObject, originalObject: Any, progress: String) { + nsClientService?.dbAdd(collection, data, originalObject, progress) + } + + override fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any, progress: String) { + nsClientService?.dbUpdate(collection, _id, data, originalObject, progress) + } } \ No newline at end of file diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/extensions/ProfileSwitchExtension.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/extensions/ProfileSwitchExtension.kt index 09bc1e7f48..6975c1febb 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/extensions/ProfileSwitchExtension.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/extensions/ProfileSwitchExtension.kt @@ -5,6 +5,7 @@ import info.nightscout.core.extensions.getCustomizedName import info.nightscout.core.extensions.pureProfileFromJson import info.nightscout.core.profile.ProfileSealed import info.nightscout.database.entities.ProfileSwitch +import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.entities.embedments.InterfaceIDs import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.utils.JsonHelper @@ -23,7 +24,7 @@ fun ProfileSwitch.toJson(isAdd: Boolean, dateUtil: DateUtil): JSONObject = .put("created_at", dateUtil.toISOString(timestamp)) .put("enteredBy", "openaps://" + "AndroidAPS") .put("isValid", isValid) - .put("eventType", info.nightscout.database.entities.TherapyEvent.Type.PROFILE_SWITCH.text) + .put("eventType", TherapyEvent.Type.PROFILE_SWITCH.text) .also { // remove customization to store original profileJson in toPureNsJson call timeshift = 0 percentage = 100 diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/services/NSClientService.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/services/NSClientService.kt index 69f3fdd187..6933b8bfee 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/services/NSClientService.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/services/NSClientService.kt @@ -25,7 +25,6 @@ import info.nightscout.interfaces.notifications.Notification import info.nightscout.interfaces.nsclient.NSAlarm import info.nightscout.interfaces.nsclient.NSSettingsStatus import info.nightscout.interfaces.sync.DataSyncSelector -import info.nightscout.interfaces.sync.NsClient import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.utils.JsonHelper.safeGetString import info.nightscout.interfaces.utils.JsonHelper.safeGetStringAllowNull @@ -72,7 +71,7 @@ import java.net.URISyntaxException import java.util.Locale import javax.inject.Inject -class NSClientService : DaggerService(), NsClient.NSClientService { +class NSClientService : DaggerService() { @Inject lateinit var injector: HasAndroidInjector @Inject lateinit var aapsLogger: AAPSLogger @@ -251,7 +250,7 @@ class NSClientService : DaggerService(), NsClient.NSClientService { } else if (!nsEnabled) { rxBus.send(EventNSClientNewLog("NSCLIENT", "disabled")) rxBus.send(EventNSClientStatus("Disabled")) - } else if (nsURL != "" && (config.isEngineeringMode() || nsURL.lowercase(Locale.getDefault()).startsWith("https://"))) { + } else if (nsURL != "" && (nsURL.lowercase(Locale.getDefault()).startsWith("https://"))) { try { rxBus.send(EventNSClientStatus("Connecting ...")) val opt = IO.Options() @@ -598,7 +597,7 @@ class NSClientService : DaggerService(), NsClient.NSClientService { } } - override fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any, progress: String) { + fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any, progress: String) { try { if (_id == null) return if (!isConnected || !hasWriteAuth) return @@ -618,7 +617,7 @@ class NSClientService : DaggerService(), NsClient.NSClientService { } } - override fun dbAdd(collection: String, data: JSONObject, originalObject: Any, progress: String) { + fun dbAdd(collection: String, data: JSONObject, originalObject: Any, progress: String) { try { if (!isConnected || !hasWriteAuth) return val message = JSONObject() diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt index b7486c1bda..9cc8242897 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3Plugin.kt @@ -26,7 +26,6 @@ import info.nightscout.interfaces.utils.HtmlHelper import info.nightscout.plugins.sync.R import info.nightscout.plugins.sync.nsShared.NSClientFragment import info.nightscout.plugins.sync.nsShared.events.EventNSClientResend -import info.nightscout.plugins.sync.nsShared.events.EventNSClientStatus import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGUI import info.nightscout.plugins.sync.nsclient.NsClientReceiverDelegate import info.nightscout.plugins.sync.nsclient.data.AlarmAck @@ -54,6 +53,7 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json +import org.json.JSONObject import javax.inject.Inject import javax.inject.Singleton import kotlin.math.max @@ -87,21 +87,30 @@ class NSClientV3Plugin @Inject constructor( companion object { val JOB_NAME: String = this::class.java.simpleName + val REFRESH_INTERVAL = T.mins(5).msecs() } private val disposable = CompositeDisposable() + private lateinit var runLoop: Runnable private val handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper) private val listLog: MutableList = ArrayList() - override var status = "" - override val nsClientService: NSClientService? = null // service not needed + override val status + get() = + when { + sp.getBoolean(R.string.key_ns_client_paused, false) -> rh.gs(info.nightscout.core.ui.R.string.paused) + isAllowed.not() -> blockingReason + nsAndroidClient.lastStatus == null -> rh.gs(R.string.not_connected) + workIsRunning(arrayOf(JOB_NAME)) -> rh.gs(R.string.working) + nsAndroidClient.lastStatus?.apiPermissions?.isFull() == true -> rh.gs(info.nightscout.shared.R.string.connected) + nsAndroidClient.lastStatus?.apiPermissions?.isRead() == true -> rh.gs(R.string.read_only) + else -> rh.gs(info.nightscout.core.ui.R.string.unknown) + } internal lateinit var nsAndroidClient: NSAndroidClient // private lateinit var nsAndroidRxClient: NSAndroidRxClient - val isAllowed: Boolean - get() = nsClientReceiverDelegate.allowed - val blockingReason: String - get() = nsClientReceiverDelegate.blockingReason + val isAllowed get() = nsClientReceiverDelegate.allowed + val blockingReason get() = nsClientReceiverDelegate.blockingReason private val maxAge = T.days(77).msecs() internal var lastModified: LastModified? = null // timestamp of last modification for every collection @@ -133,31 +142,24 @@ class NSClientV3Plugin @Inject constructor( lastFetched.collections.profile = max(dateUtil.now() - maxAge, lastFetched.collections.profile) lastFetched.collections.devicestatus = max(dateUtil.now() - maxAge, lastFetched.collections.devicestatus) - nsAndroidClient = NSAndroidClientImpl( - baseUrl = sp.getString(info.nightscout.core.utils.R.string.key_nsclientinternal_url, "").lowercase().replace("https://", ""), - accessToken = sp.getString(R.string.key_ns_client_token, ""), - context = context, - logging = true - ) + setClient() nsClientReceiverDelegate.grabReceiversState() - disposable += rxBus - .toObservable(EventNSClientStatus::class.java) - .observeOn(aapsSchedulers.io) - .subscribe({ event -> - status = event.getStatus(context) - rxBus.send(EventNSClientUpdateGUI()) - // Pass to setup wizard - rxBus.send(EventSWSyncStatus(event.getStatus(context))) - }, fabricPrivacy::logException) disposable += rxBus .toObservable(EventNetworkChange::class.java) .observeOn(aapsSchedulers.io) - .subscribe({ ev -> nsClientReceiverDelegate.onStatusEvent(ev) }, fabricPrivacy::logException) + .subscribe({ ev -> + nsClientReceiverDelegate.onStatusEvent(ev) + setClient() + }, fabricPrivacy::logException) disposable += rxBus .toObservable(EventPreferenceChange::class.java) .observeOn(aapsSchedulers.io) - .subscribe({ ev -> nsClientReceiverDelegate.onStatusEvent(ev) }, fabricPrivacy::logException) + .subscribe({ ev -> + nsClientReceiverDelegate.onStatusEvent(ev) + if (ev.isChanged(rh.gs(R.string.key_ns_client_token)) || ev.isChanged(rh.gs(info.nightscout.core.utils.R.string.key_nsclientinternal_url))) + setClient() + }, fabricPrivacy::logException) // disposable += rxBus // .toObservable(EventAppExit::class.java) // .observeOn(aapsSchedulers.io) @@ -177,10 +179,18 @@ class NSClientV3Plugin @Inject constructor( .toObservable(EventNSClientResend::class.java) .observeOn(aapsSchedulers.io) .subscribe({ event -> resend(event.reason) }, fabricPrivacy::logException) + + runLoop = Runnable { + executeLoop() + handler.postDelayed(runLoop, REFRESH_INTERVAL) + } + handler.postDelayed(runLoop, REFRESH_INTERVAL) + executeLoop() } override fun onStop() { // context.applicationContext.unbindService(mConnection) + handler.removeCallbacksAndMessages(null) disposable.clear() super.onStop() } @@ -196,8 +206,8 @@ class NSClientV3Plugin @Inject constructor( preferenceFragment.findPreference(rh.gs(R.string.key_ns_receive_tbr_eb))?.isVisible = config.isEngineeringMode() } - override val hasWritePermission: Boolean get() = nsClientService?.hasWriteAuth ?: false - override val connected: Boolean get() = nsClientService?.isConnected ?: false + override val hasWritePermission: Boolean get() = nsAndroidClient.lastStatus?.apiPermissions?.isFull() ?: false + override val connected: Boolean get() = nsAndroidClient.lastStatus != null override fun clearLog() { handler.post { @@ -206,6 +216,16 @@ class NSClientV3Plugin @Inject constructor( } } + private fun setClient() { + nsAndroidClient = NSAndroidClientImpl( + baseUrl = sp.getString(info.nightscout.core.utils.R.string.key_nsclientinternal_url, "").lowercase().replace("https://", ""), + accessToken = sp.getString(R.string.key_ns_client_token, ""), + context = context, + logging = true + ) + rxBus.send(EventSWSyncStatus(status)) + } + private fun addToLog(ev: EventNSClientNewLog) { synchronized(listLog) { listLog.add(ev) @@ -231,7 +251,7 @@ class NSClientV3Plugin @Inject constructor( } override fun resend(reason: String) { - nsClientService?.resend(reason) +// nsClientService?.resend(reason) } override fun pause(newState: Boolean) { @@ -239,8 +259,7 @@ class NSClientV3Plugin @Inject constructor( rxBus.send(EventPreferenceChange(rh.gs(R.string.key_ns_client_paused))) } - override val version: NsClient.Version - get() = NsClient.Version.V3 + override val version: NsClient.Version get() = NsClient.Version.V3 override val address: String get() = sp.getString(info.nightscout.core.utils.R.string.key_nsclientinternal_url, "") @@ -250,12 +269,12 @@ class NSClientV3Plugin @Inject constructor( aapsLogger.debug(LTag.NSCLIENT, "Upload disabled. Message dropped") return } - nsClientService?.sendAlarmAck( - AlarmAck().also { ack -> - ack.level = originalAlarm.level() - ack.group = originalAlarm.group() - ack.silenceTime = silenceTimeInMilliseconds - }) + // nsClientService?.sendAlarmAck( + // AlarmAck().also { ack -> + // ack.level = originalAlarm.level() + // ack.group = originalAlarm.group() + // ack.silenceTime = silenceTimeInMilliseconds + // }) } override fun updateLatestBgReceivedIfNewer(latestReceived: Long) { @@ -282,11 +301,39 @@ class NSClientV3Plugin @Inject constructor( storeLastFetched() } + override fun dbAdd(collection: String, data: JSONObject, originalObject: Any, progress: String) { + TODO("Not yet implemented") + } + + override fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any, progress: String) { + TODO("Not yet implemented") + } + private fun storeLastFetched() { sp.putString(R.string.key_ns_client_v3_last_modified, Json.encodeToString(LastModified.serializer(), lastFetched)) } fun test() { + executeLoop() + } + + fun scheduleNewExecution() { + val toTime = lastFetched.collections.entries + T.mins(6).plus(T.secs(0)).msecs() + if (toTime > dateUtil.now()) { + handler.postDelayed({ executeLoop() }, toTime - dateUtil.now()) + rxBus.send(EventNSClientNewLog("NEXT", dateUtil.dateAndTimeAndSecondsString(toTime))) + } + } + + private fun executeLoop() { + if (sp.getBoolean(R.string.key_ns_client_paused, false)) { + rxBus.send(EventNSClientNewLog("NSCLIENT", "paused")) + return + } + if (!isAllowed) { + rxBus.send(EventNSClientNewLog("NSCLIENT", blockingReason)) + return + } if (workIsRunning(arrayOf(JOB_NAME))) rxBus.send(EventNSClientNewLog("RUN", "Already running")) else { diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/extensions/ExtendedBolusExtension.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/extensions/ExtendedBolusExtension.kt index c2dfeaa81b..090b71f7b2 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/extensions/ExtendedBolusExtension.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/extensions/ExtendedBolusExtension.kt @@ -11,6 +11,6 @@ fun NSExtendedBolus.toExtendedBolus(): ExtendedBolus = utcOffset = utcOffset, amount = enteredinsulin, duration = duration, - isEmulatingTempBasal = isEmulatingTempbasal, + isEmulatingTempBasal = isEmulatingTempBasal ?: false, interfaceIDs_backing = InterfaceIDs(nightscoutId = identifier, pumpId = pumpId, pumpType = InterfaceIDs.PumpType.fromString(pumpType), pumpSerial = pumpSerial, endId = endId) ) diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorker.kt index 8bccefe53f..99b9cbed8c 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorker.kt @@ -76,6 +76,7 @@ class LoadBgWorker( } else { rxBus.send(EventNSClientNewLog("END", "No new SGVs from ${dateUtil.dateAndTimeAndSecondsString(nsClientV3Plugin.lastFetched.collections.entries)}")) + nsClientV3Plugin.scheduleNewExecution() // Idea is to run after 5 min after last BG WorkManager.getInstance(context) .beginUniqueWork( NSClientV3Plugin.JOB_NAME, diff --git a/plugins/sync/src/main/res/values-cs-rCZ/strings.xml b/plugins/sync/src/main/res/values-cs-rCZ/strings.xml index b1beabbc57..61cc0c4179 100644 --- a/plugins/sync/src/main/res/values-cs-rCZ/strings.xml +++ b/plugins/sync/src/main/res/values-cs-rCZ/strings.xml @@ -97,4 +97,7 @@ Odstranit vše Resetovat start Nahrát nyní + Nepřipojeno + Jen pro čtení + Pracuji diff --git a/plugins/sync/src/main/res/values-es-rES/strings.xml b/plugins/sync/src/main/res/values-es-rES/strings.xml index f1d46065f4..131b6173fc 100644 --- a/plugins/sync/src/main/res/values-es-rES/strings.xml +++ b/plugins/sync/src/main/res/values-es-rES/strings.xml @@ -97,4 +97,7 @@ Eliminar todos Restablecer inicio Subir ahora + No conectado + Sólo lectura + Funcionando diff --git a/plugins/sync/src/main/res/values-fr-rFR/strings.xml b/plugins/sync/src/main/res/values-fr-rFR/strings.xml index 5069f0dc37..de85e5002c 100644 --- a/plugins/sync/src/main/res/values-fr-rFR/strings.xml +++ b/plugins/sync/src/main/res/values-fr-rFR/strings.xml @@ -97,4 +97,7 @@ Supprimer tout Réinitialiser le démarrage Télécharger maintenant + Non connecté + Lecture seule + Opération en cours diff --git a/plugins/sync/src/main/res/values-ru-rRU/strings.xml b/plugins/sync/src/main/res/values-ru-rRU/strings.xml index b67a2c12aa..9fa4e3545d 100644 --- a/plugins/sync/src/main/res/values-ru-rRU/strings.xml +++ b/plugins/sync/src/main/res/values-ru-rRU/strings.xml @@ -97,4 +97,7 @@ Удалить всё Перезапустить старт Выгрузить (передать данные) сейчас + Нет подключения + Только чтение + Обработка diff --git a/plugins/sync/src/main/res/values/strings.xml b/plugins/sync/src/main/res/values/strings.xml index 666d569463..9d6bdef502 100644 --- a/plugins/sync/src/main/res/values/strings.xml +++ b/plugins/sync/src/main/res/values/strings.xml @@ -143,4 +143,8 @@ Reset start Upload now + Not connected + Read only + Working + \ No newline at end of file diff --git a/pump/combo/src/main/java/info/nightscout/pump/combo/di/ComboActivitiesModule.kt b/pump/combo/src/main/java/info/nightscout/pump/combo/di/ComboActivitiesModule.kt index ea71e7d0b1..832893dd2c 100644 --- a/pump/combo/src/main/java/info/nightscout/pump/combo/di/ComboActivitiesModule.kt +++ b/pump/combo/src/main/java/info/nightscout/pump/combo/di/ComboActivitiesModule.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.danars.di +package info.nightscout.pump.combo.di import dagger.Module import dagger.android.ContributesAndroidInjector diff --git a/pump/combo/src/main/java/info/nightscout/pump/combo/di/ComboModule.kt b/pump/combo/src/main/java/info/nightscout/pump/combo/di/ComboModule.kt index d31494715d..405589340f 100644 --- a/pump/combo/src/main/java/info/nightscout/pump/combo/di/ComboModule.kt +++ b/pump/combo/src/main/java/info/nightscout/pump/combo/di/ComboModule.kt @@ -1,7 +1,6 @@ package info.nightscout.pump.combo.di import dagger.Module -import info.nightscout.androidaps.danars.di.ComboActivitiesModule @Module(includes = [ ComboActivitiesModule::class diff --git a/pump/combov2/README.md b/pump/combov2/README.md new file mode 100644 index 0000000000..17727f3561 --- /dev/null +++ b/pump/combov2/README.md @@ -0,0 +1,153 @@ +# Overview over combov2's and ComboCtl's architecture + +ComboCtl is the core driver. It uses Kotlin Multiplatform and is written in a platform agnostic +way. The code is located in `comboctl/`, and is also available in [its own separate repository] +(https://github.com/dv1/ComboCtl). That separate repository is kept in sync with the ComboCtl +copy in AndroidAPS as much as possible, with some notable changes (see below). "combov2" is the +name of the AndroidAPS driver. In short: combov2 = ComboCtl + extra AndroidAPS integration code. + +## Directory structure + +The directory structure of the local ComboCtl itself is: + +* `comboctl/src/commonMain/` : The platform agnostic portion of ComboCtl. The vast majority of + ComboCtl's logic is contained there. +* `comboctl/src/androidMain/` : The Android specific code. This in particular contains + implementations of the Bluetooth interfaces that are defined in `commonMain/`. +* `comboctl/src/jvmTest/` : Unit tests. This subdirectory is called `jvmTest` because in the + ComboCtl repository, there is also a `jvmMain/` subdirectory, and the unit tests are run + with the JVM. + +The AndroidAPS specific portion of the driver is located in `src/`. This connects ComboCtl with +AndroidAPS. In particular, this is where the `ComboV2Plugin` class is located. That's the main +entrypoint for the combov2 driver plugin. + +## Basic description of how ComboCtl communicates with the pump + +ComboCtl uses Kotlin coroutines. It uses [the Default dispatcher](https://kotlinlang. +org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-default.html), +with [a limitedParallelism](https://kotlinlang.org/api/kotlinx. +coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/limited-parallelism.html) +constraint to prevent actual parallelism, that is, to not let coroutine jobs run on multiple +threads concurrently. Coroutines are used in ComboCtl to greatly simplify the communication steps, +which normally require a number of state machines to be implemented manually. Stackless coroutines +like Kotlin's essentially are automatically generated state machines under the hood, and this is +what they are used for here. Enabling parallelism is not part of such a state machine. Furthermore, +communication with the Combo does not benefit from parallelism. + +The communication code in ComboCtl is split in higher level operations (in its `Pump` class) and +lower level ones (in its `PumpIO` class). `Pump` instantiates `PumpIO` internally, and focuses on +implementing functionality like reading basal profiles, setting TBRs etc. `PumpIO` implements the +building blocks for these higher level operations. In particular, `PumpIO` has an internal +coroutine scope that is used for sending data to the Combo and for running a "heartbeat" loop. +That "heartbeat" is a message that needs to be regularly sent to the Combo (unless other data is +sent to the Combo in time, like a command to press a button). If nothing is sent to a Combo for +some time, it will eventually disconnect. For this reason, that heartbeat loop is necessary. + +PumpIO also contains the code for performing the pump pairing. + +Going further down a level, `TransportLayer` implements the IO code to generate packets for the +Combo and parse packets coming from the Combo. This includes code for authenticating outgoing +packets and for checking incoming ones. `TransportLayer` also contains the `IO` subclass, which +actually transfers packets to and receives data from the Combo. + +One important detail to keep in mind about the `IO` class is that it enforces a packet send +interval of 200 ms. That is: The time between packet transmission is never shorter than 200 ms +(it is OK to be longer). The interval is important, because the Combo has a ring buffer for the +packet it receives, and transmitting packets to the Combo too quickly causes an overflow and a +subsequent error in the Combo, which then terminates the connection. + +The Combo can run in three modes. The first one is the "service" mode, which is only briefly +used for setting up the connection. Immediately after the connection is established, the pump +continues in the "command" or "remote terminal" (abbr. "RT") mode. The "command" mode is what the +remote control of the Combo uses for its direct commands (that is, delivering bolus and retrieving +the latest changes / activities from the history). The "remote terminal" mode replicates the LCD +on the pump itself along with the 4 Combo buttons. + +Only a few operations are possible in the command mode. In particular, the driver uses the bolus +delivery command from the command mode, the command to retrieve a history delta, and the command +for getting the pump's current date and time. But everything else (getting basal profile, setting +TBR, getting pump status...) is done in the remote terminal mode, by emulating a user pressing +buttons. This unfortunately means that these operations are performed slowly, but there is no +other choice. + +## Details about long-pressing RT buttons + +As part of operations like reading the pump's profile, an emulated long RT button press is sometimes +used. Such long presses cause more rapid changes compared to multiple short button presses. A +button press is "long" when the emulated user "holds down" the button, while a short button press +equals pressing and immediately releasing the emulated button. + +The greater speed of long button presses comes with a drawback though: "Overshoots" can happen. For +example, if long button pressing is used for adjusting a quantity on screen, then the quantity may +still get incremented/decremented after the emulated user "released" the button. It is therefore +necessary to check the quantity on screen, and finetune it with short button presses afterwards +if necessary. + +## Idempotent and non-idempotent high level commands + +A command is _idempotent_ if it can be repeated if the connection to the pump was lost. Most +commands are idempotent. For example, reading the basal profile can be repeated if during the +initial basal profile retrieval the connection was lost (for example because the user walked away +from the pump). After a few attempts to repeat the command, an error is produced (to avoid an +infinite loop). + +Currently, there is only one non-idempotent command: Delivering a bolus. This one _cannot_ be +repeated, otherwise there is a high risk of infusing too much insulin. Instead, in case of a +connection failure, the delivering bolus command fails immediately and is not automatically +attempted again. + +## Automatic datetime adjustments and timezone offset handling + +ComboCtl automatically adjusts the date and time of the Combo. This is done through the RT mode, +since there is no command-mode command to _set_ the current datetime (but there is one for +_getting_ the current datetime). But since the Combo cannot store a timezone offset (it only stores +localtime), the timezone offset that has been used so far is stored in a dedicated field in the +pump state store that ComboCtl uses. DST changes and timezone changes can be tracked properly with +this logic. + +The pump's current datetime is always retrieved (through the command mode) every time a connection +is established to it, and compared to the system's current datetime. If these two differ too much, +the pump's datetime is automatically adjusted. This keeps the pump's datetime in sync. + +## Notes about how TBRs are set + +TBRs are set through the remote terminal mode. The driver assumes that the Combo is configured +to use 15-minute TBR duration steps sizes and a TBR percentage maximum of 500%. There is code +in the driver to detect if the maximum is not set to 500%. If AndroidAPS tries to set a percentage +that is higher than the actually configured maximum, then eventually, an error is reported. + +:warning: The duration step size cannot be detected by the driver. The user _must_ make sure that +the step size is configured to 15 minutes. + +## Pairing with a Combo and the issue with pump queue connection timeouts + +When pairing, the pump queue's internal timeout is likely to be reached. Essentially, the queue +tries to connect to the pump right after the driver was selected in the configuration. But +a connection cannot be established because the pump is not yet paired. + +When the queue attempts to connect to the pump, it "thinks" that if the connect procedure does not +complete after 120 seconds, then the driver must be stuck somehow. The queue then hits a timeout. +The assumption about 120s is correct if the Combo is already paired (a connection should be set up +in far less time than 120s). But if it is currently being paired, the steps involved can take +about 2-3 minutes. + +For this reason, the driver automatically requests a pump update - which connects to the pump - +once pairing is done. + +## Changes to ComboCtl in the local copy + +The code in `comboctl/` is ComboCtl minus the `jvmMain/` code, which contains code for the Linux +platform. This includes C++ glue code to the BlueZ stack. Since none of this is useful to +AndroidAPS, it is better left out, especially since it consists of almost 9000 lines of code. + +Also, the original `comboctl/build.gradle.kts` files is replaced by `comboctl/build.gradle`, which +is much simpler, and builds ComboCtl as a kotlin-android project, not a Kotlin Multiplatform one. +This simplifies integration into AndroidAPS, and avoids multiplatform problems (after all, +Kotlin Multiplatform is still marked as an alpha version feature). + +When updating ComboCtl, it is important to keep these differences in mind. + +Differences between the copy in `comboctl/` and the original ComboCtl code must be kept as little +as possible, and preferably be transferred to the main ComboCtl project. This helps with keeping the +`comboctl/` copy and the main project in sync since transferring changes then is straightforward. diff --git a/pump/combov2/comboctl-changes.txt b/pump/combov2/comboctl-changes.txt deleted file mode 100644 index 728e9ec14c..0000000000 --- a/pump/combov2/comboctl-changes.txt +++ /dev/null @@ -1,14 +0,0 @@ -The code in comboctl/ is ComboCtl minus the jvmMain/ code, which contains code for the Linux platform. -This includes C++ glue code to the BlueZ stack. Since none of this is useful to AndroidAPS, it is better -left out, especially since it consists of almost 9000 lines of code. - -Also, the original comboctl/build.gradle.kts files is replaced by comboctl/build.gradle, which is -much simpler, and builds ComboCtl as a kotlin-android project, not a kotlin-multiplatform one. -This simplifies integration into AndroidAPS, and avoids multiplatform problems (after all, -Kotlin Multiplatform is still marked as an alpha version feature). - -When updating ComboCtl, it is important to keep these differences in mind. - -Differences between the copy in comboctl/ and the original ComboCtl code must be kept as little as -possible, and preferably be transferred to the main ComboCtl project. This helps keep the comboctl/ -copy and the main project in sync. diff --git a/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothDevice.kt b/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothDevice.kt index 8f954ec0cb..ae154d22e0 100644 --- a/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothDevice.kt +++ b/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothDevice.kt @@ -67,8 +67,9 @@ class AndroidBluetoothDevice( // just yet (for example because the UI is still shown on the LCD), while // the retryBlocking loop here is in place because the _Android device_ // may not be ready to connect right away. - // TODO: Test and define what happens when all attempts failed. - // The user needs to be informed and given the choice to try again. + // When all attempts fail, retryBlocking() lets the exception pass through. + // That exception is wrapped in BluetoothException, which then needs to be + // handled by the caller. val totalNumAttempts = 5 retryBlocking(numberOfRetries = totalNumAttempts, delayBetweenRetries = 100) { attemptNumber, previousException -> if (abortConnectAttempt) diff --git a/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothInterface.kt b/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothInterface.kt index 3f2ee01dd0..e1dfee66dc 100644 --- a/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothInterface.kt +++ b/pump/combov2/comboctl/src/androidMain/kotlin/info/nightscout/comboctl/android/AndroidBluetoothInterface.kt @@ -381,13 +381,6 @@ class AndroidBluetoothInterface(private val androidContext: Context) : Bluetooth // instance was already processed. This check here instead // verifies if we have seen the same Bluetooth address on // *different* Android Bluetooth device instances. - // TODO: Test how AndroidBluetoothInterface behaves if the - // device is unpaired while discovery is ongoing (manually by - // the user for example). In theory, this should be handled - // properly by the onBondStateChanged function below. - // TODO: This check may not be necessary on all Android - // devices. On some, it seems to also work if we use the - // first offered BluetoothDevice. if (comboctlBtAddress !in previouslyDiscoveredDevices) { previouslyDiscoveredDevices[comboctlBtAddress] = androidBtDevice logger(LogLevel.DEBUG) { diff --git a/pump/combov2/comboctl/src/commonMain/kotlin/info/nightscout/comboctl/main/Pump.kt b/pump/combov2/comboctl/src/commonMain/kotlin/info/nightscout/comboctl/main/Pump.kt index 745e23276c..68c7de77eb 100644 --- a/pump/combov2/comboctl/src/commonMain/kotlin/info/nightscout/comboctl/main/Pump.kt +++ b/pump/combov2/comboctl/src/commonMain/kotlin/info/nightscout/comboctl/main/Pump.kt @@ -2743,8 +2743,6 @@ class Pump( ) } - numObservedScreens++ - val factorIndexOnScreen = parsedScreen.beginTime.hour // numUnits null means the basal profile factor @@ -2752,6 +2750,11 @@ class Pump( if (parsedScreen.numUnits == null) return@longPressRTButtonUntil LongPressRTButtonsCommand.ContinuePressingButton + // Increase this _after_ checking for a blinking screen + // to not accidentally count the blinking and non-blinking + // screens as two separate ones. + numObservedScreens++ + // If the factor in the profile is >= 0, // it means it was already read earlier. if (basalProfileFactors[factorIndexOnScreen] >= 0) @@ -2759,14 +2762,16 @@ class Pump( val factor = parsedScreen.numUnits basalProfileFactors[factorIndexOnScreen] = factor - logger(LogLevel.DEBUG) { "Got basal profile factor #$factorIndexOnScreen : $factor" } + + numRetrievedFactors++ + logger(LogLevel.DEBUG) { + "Got basal profile factor #$factorIndexOnScreen : $factor; $numRetrievedFactors factor(s) read and $numObservedScreens screen(s) observed thus far" + } getBasalProfileReporter.setCurrentProgressStage( RTCommandProgressStage.GettingBasalProfile(numRetrievedFactors) ) - numRetrievedFactors++ - return@longPressRTButtonUntil if (numObservedScreens >= NUM_COMBO_BASAL_PROFILE_FACTORS) LongPressRTButtonsCommand.ReleaseButton else @@ -2819,21 +2824,19 @@ class Pump( } } + numRetrievedFactors++ getBasalProfileReporter.setCurrentProgressStage( RTCommandProgressStage.GettingBasalProfile(numRetrievedFactors) ) - numRetrievedFactors++ } } - // All factors retrieved. Press CHECK once to get back to the total - // basal rate screen, and then CHECK again to return to the main menu. - - rtNavigationContext.shortPressButton(RTNavigationButton.CHECK) - waitUntilScreenAppears(rtNavigationContext, ParsedScreen.BasalRateTotalScreen::class) - - rtNavigationContext.shortPressButton(RTNavigationButton.CHECK) - waitUntilScreenAppears(rtNavigationContext, ParsedScreen.MainScreen::class) + // All factors retrieved. Press BACK repeatedly until we are back at the main menu. + cycleToRTScreen( + rtNavigationContext, + RTNavigationButton.BACK, + ParsedScreen.MainScreen::class + ) getBasalProfileReporter.setCurrentProgressStage(BasicProgressStage.Finished) diff --git a/pump/combov2/src/main/res/values-fr-rFR/strings.xml b/pump/combov2/src/main/res/values-fr-rFR/strings.xml index d95eac085e..05f6c80633 100644 --- a/pump/combov2/src/main/res/values-fr-rFR/strings.xml +++ b/pump/combov2/src/main/res/values-fr-rFR/strings.xml @@ -85,6 +85,9 @@ Niveau réservoir pompe bas Paramétrage du DBT réussi Échec du réglage du DBT + Définir l\'émulation 100% TBR + Laisser se terminer l\'émulation 100% TBR en cours + Requête 100% DBT redondante ignorée Limite inattendue lors de l’ajustement du DBT: le pourcentage cible de %1$d%%, a dépassé la limite de %1$d%% Impossible de définir le DBT absolu si le débit de basal est zéro Appairer AndroidAPS et Android avec une pompe Accu-Chek Combo non appariée diff --git a/pump/combov2/src/main/res/values-ru-rRU/strings.xml b/pump/combov2/src/main/res/values-ru-rRU/strings.xml index 43227b663f..c75a5f9604 100644 --- a/pump/combov2/src/main/res/values-ru-rRU/strings.xml +++ b/pump/combov2/src/main/res/values-ru-rRU/strings.xml @@ -95,6 +95,9 @@ Низкий уровень инсулина в картридже помпы Настройки TBR выполнены Не удалось установить TBR + Установить эмуляцию. временного базала TBR 100% + Позволить завершиться текущей эмуляции временного базала 100% TBR + Игнорирование избыточного запроса на 100% TBR Непредвиденный предел, встретившийся при настройке TBR: целевой процент составил %1$d%%, а достиг предела %1$d%% Невозможно установить абсолютный TBR, если базовая скорость равна нулю Выполнить сопряжение AndroidAPS и Android с помпой Accu-Chek Combo diff --git a/pump/dana/src/main/java/info/nightscout/pump/dana/DanaPump.kt b/pump/dana/src/main/java/info/nightscout/pump/dana/DanaPump.kt index f266dae18e..35764163a6 100644 --- a/pump/dana/src/main/java/info/nightscout/pump/dana/DanaPump.kt +++ b/pump/dana/src/main/java/info/nightscout/pump/dana/DanaPump.kt @@ -55,7 +55,7 @@ class DanaPump @Inject constructor( var lastConnection: Long = 0 var lastSettingsRead: Long = 0 - @JvmField var lastHistoryFetched: Long = 0 + @JvmField var readHistoryFrom: Long = 0 // start next history read from this timestamp @JvmField var historyDoneReceived: Boolean = false // true when last history message is received // Info @@ -410,7 +410,7 @@ class DanaPump @Inject constructor( aapsLogger.debug(LTag.PUMP, "DanaRPump reset") lastConnection = 0 lastSettingsRead = 0 - lastHistoryFetched = 0 + readHistoryFrom = 0 } fun modelFriendlyName(): String = diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java index 57760a5663..3ab6863eb7 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/DanaRv2Plugin.java @@ -57,8 +57,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { private final TemporaryBasalStorage temporaryBasalStorage; private final FabricPrivacy fabricPrivacy; - public long lastEventTimeLoaded = 0; - @Inject public DanaRv2Plugin( HasAndroidInjector injector, @@ -345,7 +343,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { PumpEnactResult result = new PumpEnactResult(getInjector()); if (danaPump.isTempBasalInProgress()) { sExecutionService.tempBasalStop(); - result.enacted(true).isTempCancel(true); + result.success(true).enacted(true).isTempCancel(true); } else { result.success(true).isTempCancel(true).comment(info.nightscout.core.ui.R.string.ok); aapsLogger.debug(LTag.PUMP, "cancelRealTempBasal: OK"); diff --git a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/services/DanaRv2ExecutionService.java b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/services/DanaRv2ExecutionService.java index 18eabcdf03..f723ac765d 100644 --- a/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/services/DanaRv2ExecutionService.java +++ b/pump/danar/src/main/java/info/nightscout/androidaps/danaRv2/services/DanaRv2ExecutionService.java @@ -346,7 +346,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(injector, DanaPump.HistoryEntry.CARBS.getValue(), carbtime, carbs, 0); mSerialIOThread.sendMessage(msgSetHistoryEntry_v2); - danaPump.lastHistoryFetched = Math.min(danaPump.lastHistoryFetched, carbtime - T.Companion.mins(1).msecs()); + danaPump.readHistoryFrom = Math.min(danaPump.readHistoryFrom, carbtime - T.Companion.mins(1).msecs()); if (!msgSetHistoryEntry_v2.isReceived() || msgSetHistoryEntry_v2.getFailed()) uiInteraction.runAlarm(rh.gs(info.nightscout.pump.dana.R.string.carbs_store_error), rh.gs(info.nightscout.core.ui.R.string.error), info.nightscout.core.ui.R.raw.boluserror); } @@ -418,7 +418,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(injector, DanaPump.HistoryEntry.CARBS.getValue(), time, amount, 0); mSerialIOThread.sendMessage(msgSetHistoryEntry_v2); - danaPump.lastHistoryFetched = Math.min(danaPump.lastHistoryFetched, time - T.Companion.mins(1).msecs()); + danaPump.readHistoryFrom = Math.min(danaPump.readHistoryFrom, time - T.Companion.mins(1).msecs()); return true; } @@ -433,18 +433,17 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { if (!isConnected()) return new PumpEnactResult(injector).success(false); SystemClock.sleep(300); - MsgHistoryEventsV2 msg = new MsgHistoryEventsV2(injector, danaPump.lastHistoryFetched); - aapsLogger.debug(LTag.PUMP, "Loading event history from: " + dateUtil.dateAndTimeString(danaPump.lastHistoryFetched)); + MsgHistoryEventsV2 msg = new MsgHistoryEventsV2(injector, danaPump.readHistoryFrom); + aapsLogger.debug(LTag.PUMP, "Loading event history from: " + dateUtil.dateAndTimeString(danaPump.readHistoryFrom)); mSerialIOThread.sendMessage(msg); while (!danaPump.historyDoneReceived && mRfcommSocket.isConnected()) { SystemClock.sleep(100); } SystemClock.sleep(200); - if (danaRv2Plugin.lastEventTimeLoaded != 0) - danaPump.lastHistoryFetched = danaRv2Plugin.lastEventTimeLoaded - T.Companion.mins(1).msecs(); + if (danaPump.getLastEventTimeLoaded() != 0) danaPump.readHistoryFrom = danaPump.getLastEventTimeLoaded() - T.Companion.mins(1).msecs(); else - danaPump.lastHistoryFetched = 0; + danaPump.readHistoryFrom = 0; danaPump.setLastConnection(System.currentTimeMillis()); return new PumpEnactResult(injector).success(true); } diff --git a/pump/danars/src/main/java/info/nightscout/pump/danars/dialogs/PairingProgressDialog.kt b/pump/danars/src/main/java/info/nightscout/pump/danars/dialogs/PairingProgressDialog.kt index 8fd988a3df..51d00909eb 100644 --- a/pump/danars/src/main/java/info/nightscout/pump/danars/dialogs/PairingProgressDialog.kt +++ b/pump/danars/src/main/java/info/nightscout/pump/danars/dialogs/PairingProgressDialog.kt @@ -53,7 +53,6 @@ class PairingProgressDialog : DaggerDialogFragment() { dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) isCancelable = false dialog?.setCanceledOnTouchOutside(false) - setViews() return binding.root } @@ -84,6 +83,7 @@ class PairingProgressDialog : DaggerDialogFragment() { _binding?.ok?.visibility = View.VISIBLE } } + setViews() } override fun dismiss() { diff --git a/pump/danars/src/main/java/info/nightscout/pump/danars/services/DanaRSService.kt b/pump/danars/src/main/java/info/nightscout/pump/danars/services/DanaRSService.kt index 0b43f17b02..88a5ea63df 100644 --- a/pump/danars/src/main/java/info/nightscout/pump/danars/services/DanaRSService.kt +++ b/pump/danars/src/main/java/info/nightscout/pump/danars/services/DanaRSService.kt @@ -262,19 +262,13 @@ class DanaRSService : DaggerService() { return result } SystemClock.sleep(1000) - val msg: DanaRSPacketAPSHistoryEvents - if (danaPump.lastHistoryFetched == 0L) { - msg = DanaRSPacketAPSHistoryEvents(injector, 0) - aapsLogger.debug(LTag.PUMPCOMM, "Loading complete event history") - } else { - msg = DanaRSPacketAPSHistoryEvents(injector, danaPump.lastHistoryFetched) - aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + dateUtil.dateAndTimeString(danaPump.lastHistoryFetched)) - } + val msg = DanaRSPacketAPSHistoryEvents(injector, danaPump.readHistoryFrom) + aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + dateUtil.dateAndTimeString(danaPump.readHistoryFrom)) sendMessage(msg) while (!danaPump.historyDoneReceived && bleComm.isConnected) { SystemClock.sleep(100) } - danaPump.lastHistoryFetched = if (danaPump.lastEventTimeLoaded != 0L) danaPump.lastEventTimeLoaded - T.mins(1).msecs() else 0 + danaPump.readHistoryFrom = if (danaPump.lastEventTimeLoaded != 0L) danaPump.lastEventTimeLoaded - T.mins(1).msecs() else 0 aapsLogger.debug(LTag.PUMPCOMM, "Events loaded") rxBus.send(EventPumpStatusChanged(rh.gs(info.nightscout.pump.dana.R.string.gettingpumpstatus))) sendMessage(DanaRSPacketGeneralInitialScreenInformation(injector)) @@ -305,7 +299,7 @@ class DanaRSService : DaggerService() { // sendMessage(msg); val msgSetHistoryEntryV2 = DanaRSPacketAPSSetEventHistory(injector, DanaPump.HistoryEntry.CARBS.value, carbTime, carbs, 0) sendMessage(msgSetHistoryEntryV2) - danaPump.lastHistoryFetched = min(danaPump.lastHistoryFetched, carbTime - T.mins(1).msecs()) + danaPump.readHistoryFrom = min(danaPump.readHistoryFrom, carbTime - T.mins(1).msecs()) if (!msgSetHistoryEntryV2.isReceived || msgSetHistoryEntryV2.failed) uiInteraction.runAlarm(rh.gs(info.nightscout.pump.dana.R.string.carbs_store_error), rh.gs(info.nightscout.core.ui.R.string.error), info.nightscout.core.ui.R.raw.boluserror) } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BasalLimitInquireResponsePacket.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BasalLimitInquireResponsePacket.kt index 0d2f428178..0089294c28 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BasalLimitInquireResponsePacket.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BasalLimitInquireResponsePacket.kt @@ -3,7 +3,7 @@ package info.nightscout.pump.diaconn.packet import dagger.android.HasAndroidInjector import info.nightscout.pump.diaconn.DiaconnG8Pump import info.nightscout.pump.diaconn.R -import info.nightscout.pump.diaconn.pumplog.PumplogUtil +import info.nightscout.pump.diaconn.pumplog.PumpLogUtil import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP @@ -39,7 +39,7 @@ class BasalLimitInquireResponsePacket(injector: HasAndroidInjector) : DiaconnG8P } diaconnG8Pump.maxBasalPerHours = getShortToInt(bufferData).toDouble() / 100.0 // not include tempbasal limit val pumpFirmwareVersion = sp.getString(rh.gs(R.string.pumpversion), "") - if(pumpFirmwareVersion.isNotEmpty() && PumplogUtil.isPumpVersionGe(pumpFirmwareVersion, 3, 0)) { + if(pumpFirmwareVersion.isNotEmpty() && PumpLogUtil.isPumpVersionGe(pumpFirmwareVersion, 3, 0)) { diaconnG8Pump.maxBasal = diaconnG8Pump.maxBasalPerHours * 2.5 // include tempbasal } else { diaconnG8Pump.maxBasal = diaconnG8Pump.maxBasalPerHours * 2.0 // include tempbasal diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigAPSMainInfoInquireResponsePacket.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigAPSMainInfoInquireResponsePacket.kt index 0408aa03a1..975e8edade 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigAPSMainInfoInquireResponsePacket.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigAPSMainInfoInquireResponsePacket.kt @@ -3,7 +3,7 @@ package info.nightscout.pump.diaconn.packet import dagger.android.HasAndroidInjector import info.nightscout.pump.diaconn.DiaconnG8Pump import info.nightscout.pump.diaconn.R -import info.nightscout.pump.diaconn.pumplog.PumplogUtil +import info.nightscout.pump.diaconn.pumplog.PumpLogUtil import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP @@ -214,7 +214,7 @@ class BigAPSMainInfoInquireResponsePacket( diaconnG8Pump.pumpProfiles!![diaconnG8Pump.activeProfile][23] = diaconnG8Pump.baseAmount24 //incarnation no 처리 - diaconnG8Pump.isPumpVersionGe2_63 = PumplogUtil.isPumpVersionGe(sp.getString(rh.gs(R.string.pumpversion), ""), 2, 63) + diaconnG8Pump.isPumpVersionGe2_63 = PumpLogUtil.isPumpVersionGe(sp.getString(rh.gs(R.string.pumpversion), ""), 2, 63) aapsLogger.debug(LTag.PUMPCOMM, "result > " + diaconnG8Pump.result) aapsLogger.debug(LTag.PUMPCOMM, "systemRemainInsulin > " + diaconnG8Pump.systemRemainInsulin) diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigLogInquireResponsePacket.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigLogInquireResponsePacket.kt index cc99c8b9f8..23c00cf689 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigLogInquireResponsePacket.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigLogInquireResponsePacket.kt @@ -19,32 +19,32 @@ import info.nightscout.pump.diaconn.api.PumpLogDto import info.nightscout.pump.diaconn.common.RecordTypes import info.nightscout.pump.diaconn.database.DiaconnHistoryRecord import info.nightscout.pump.diaconn.database.DiaconnHistoryRecordDao -import info.nightscout.pump.diaconn.pumplog.LOG_ALARM_BATTERY -import info.nightscout.pump.diaconn.pumplog.LOG_ALARM_BLOCK -import info.nightscout.pump.diaconn.pumplog.LOG_ALARM_SHORTAGE -import info.nightscout.pump.diaconn.pumplog.LOG_CHANGE_INJECTOR_SUCCESS -import info.nightscout.pump.diaconn.pumplog.LOG_CHANGE_NEEDLE_SUCCESS -import info.nightscout.pump.diaconn.pumplog.LOG_CHANGE_TUBE_SUCCESS -import info.nightscout.pump.diaconn.pumplog.LOG_INJECTION_1DAY -import info.nightscout.pump.diaconn.pumplog.LOG_INJECTION_1DAY_BASAL -import info.nightscout.pump.diaconn.pumplog.LOG_INJECTION_1HOUR_BASAL -import info.nightscout.pump.diaconn.pumplog.LOG_INJECTION_DUAL_NORMAL -import info.nightscout.pump.diaconn.pumplog.LOG_INJECT_DUAL_FAIL -import info.nightscout.pump.diaconn.pumplog.LOG_INJECT_DUAL_SUCCESS -import info.nightscout.pump.diaconn.pumplog.LOG_INJECT_MEAL_FAIL -import info.nightscout.pump.diaconn.pumplog.LOG_INJECT_MEAL_SUCCESS -import info.nightscout.pump.diaconn.pumplog.LOG_INJECT_NORMAL_FAIL -import info.nightscout.pump.diaconn.pumplog.LOG_INJECT_NORMAL_SUCCESS -import info.nightscout.pump.diaconn.pumplog.LOG_INJECT_SQUARE_FAIL -import info.nightscout.pump.diaconn.pumplog.LOG_INJECT_SQUARE_SUCCESS -import info.nightscout.pump.diaconn.pumplog.LOG_RESET_SYS_V3 -import info.nightscout.pump.diaconn.pumplog.LOG_SET_DUAL_INJECTION -import info.nightscout.pump.diaconn.pumplog.LOG_SET_SQUARE_INJECTION -import info.nightscout.pump.diaconn.pumplog.LOG_SUSPEND_RELEASE_V2 -import info.nightscout.pump.diaconn.pumplog.LOG_SUSPEND_V2 -import info.nightscout.pump.diaconn.pumplog.LOG_TB_START_V3 -import info.nightscout.pump.diaconn.pumplog.LOG_TB_STOP_V3 -import info.nightscout.pump.diaconn.pumplog.PumplogUtil +import info.nightscout.pump.diaconn.pumplog.LogAlarmBattery +import info.nightscout.pump.diaconn.pumplog.LogAlarmBlock +import info.nightscout.pump.diaconn.pumplog.LogAlarmShortAge +import info.nightscout.pump.diaconn.pumplog.LogChangeInjectorSuccess +import info.nightscout.pump.diaconn.pumplog.LogChangeNeedleSuccess +import info.nightscout.pump.diaconn.pumplog.LogChangeTubeSuccess +import info.nightscout.pump.diaconn.pumplog.LogInjectDualFail +import info.nightscout.pump.diaconn.pumplog.LogInjectDualSuccess +import info.nightscout.pump.diaconn.pumplog.LogInjectMealFail +import info.nightscout.pump.diaconn.pumplog.LogInjectMealSuccess +import info.nightscout.pump.diaconn.pumplog.LogInjectNormalFail +import info.nightscout.pump.diaconn.pumplog.LogInjectNormalSuccess +import info.nightscout.pump.diaconn.pumplog.LogInjectSquareFail +import info.nightscout.pump.diaconn.pumplog.LogInjectSquareSuccess +import info.nightscout.pump.diaconn.pumplog.LogInjection1Day +import info.nightscout.pump.diaconn.pumplog.LogInjection1DayBasal +import info.nightscout.pump.diaconn.pumplog.LogInjection1HourBasal +import info.nightscout.pump.diaconn.pumplog.LogInjectionDualNormal +import info.nightscout.pump.diaconn.pumplog.LogResetSysV3 +import info.nightscout.pump.diaconn.pumplog.LogSetDualInjection +import info.nightscout.pump.diaconn.pumplog.LogSetSquareInjection +import info.nightscout.pump.diaconn.pumplog.LogSuspendReleaseV2 +import info.nightscout.pump.diaconn.pumplog.LogSuspendV2 +import info.nightscout.pump.diaconn.pumplog.LogTbStartV3 +import info.nightscout.pump.diaconn.pumplog.LogTbStopV3 +import info.nightscout.pump.diaconn.pumplog.PumpLogUtil import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventPumpStatusChanged import info.nightscout.rx.logging.LTag @@ -113,22 +113,22 @@ class BigLogInquireResponsePacket( val logNum = getShortToInt(bufferData) // 2byte // log Data Parsing val logData = byteArrayOf( - PumplogUtil.getByte(bufferData), - PumplogUtil.getByte(bufferData), - PumplogUtil.getByte(bufferData), - PumplogUtil.getByte(bufferData), - PumplogUtil.getByte(bufferData), - PumplogUtil.getByte(bufferData), - PumplogUtil.getByte(bufferData), - PumplogUtil.getByte(bufferData), - PumplogUtil.getByte(bufferData), - PumplogUtil.getByte(bufferData), - PumplogUtil.getByte(bufferData), - PumplogUtil.getByte(bufferData) + PumpLogUtil.getByte(bufferData), + PumpLogUtil.getByte(bufferData), + PumpLogUtil.getByte(bufferData), + PumpLogUtil.getByte(bufferData), + PumpLogUtil.getByte(bufferData), + PumpLogUtil.getByte(bufferData), + PumpLogUtil.getByte(bufferData), + PumpLogUtil.getByte(bufferData), + PumpLogUtil.getByte(bufferData), + PumpLogUtil.getByte(bufferData), + PumpLogUtil.getByte(bufferData), + PumpLogUtil.getByte(bufferData) ) // process Log to DB val logDataToHexString = toNarrowHex(logData) - val pumpLogKind: Byte = PumplogUtil.getKind(logDataToHexString) + val pumpLogKind: Byte = PumpLogUtil.getKind(logDataToHexString) var status: String val diaconnG8HistoryRecord = DiaconnHistoryRecord(0) @@ -151,8 +151,8 @@ class BigLogInquireResponsePacket( when (pumpLogKind) { - LOG_INJECT_MEAL_SUCCESS.LOG_KIND -> { - val logItem = LOG_INJECT_MEAL_SUCCESS.parse(logDataToHexString) + LogInjectMealSuccess.LOG_KIND -> { + val logItem = LogInjectMealSuccess.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -186,8 +186,8 @@ class BigLogInquireResponsePacket( status = "MEAL_BOLUS_SUCCESS" + dateUtil.timeString(logDateTime) } - LOG_INJECT_MEAL_FAIL.LOG_KIND -> { - val logItem = LOG_INJECT_MEAL_FAIL.parse(logDataToHexString) + LogInjectMealFail.LOG_KIND -> { + val logItem = LogInjectMealFail.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -221,8 +221,8 @@ class BigLogInquireResponsePacket( status = "MEAL_BOLUS_FAIL " + dateUtil.timeString(logDateTime) } - LOG_INJECT_NORMAL_SUCCESS.LOG_KIND -> { - val logItem = LOG_INJECT_NORMAL_SUCCESS.parse(logDataToHexString) + LogInjectNormalSuccess.LOG_KIND -> { + val logItem = LogInjectNormalSuccess.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") @@ -257,8 +257,8 @@ class BigLogInquireResponsePacket( status = "BOLUS_SUCCESS" + dateUtil.timeString(logDateTime) } - LOG_INJECT_NORMAL_FAIL.LOG_KIND -> { - val logItem = LOG_INJECT_NORMAL_FAIL.parse(logDataToHexString) + LogInjectNormalFail.LOG_KIND -> { + val logItem = LogInjectNormalFail.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -295,8 +295,8 @@ class BigLogInquireResponsePacket( status = "BOLUS_FAIL " + dateUtil.timeString(logDateTime) } - LOG_SET_SQUARE_INJECTION.LOG_KIND -> { - val logItem = LOG_SET_SQUARE_INJECTION.parse(logDataToHexString) + LogSetSquareInjection.LOG_KIND -> { + val logItem = LogSetSquareInjection.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -326,8 +326,8 @@ class BigLogInquireResponsePacket( status = "EXTENDED_BOLUS_START " + dateUtil.timeString(logDateTime) } - LOG_INJECT_SQUARE_SUCCESS.LOG_KIND -> { - val logItem = LOG_INJECT_SQUARE_SUCCESS.parse(logDataToHexString) + LogInjectSquareSuccess.LOG_KIND -> { + val logItem = LogInjectSquareSuccess.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -343,8 +343,8 @@ class BigLogInquireResponsePacket( status = "EXTENDED_BOLUS_END " + dateUtil.timeString(logDateTime) } - LOG_INJECT_SQUARE_FAIL.LOG_KIND -> { - val logItem = LOG_INJECT_SQUARE_FAIL.parse(logDataToHexString) + LogInjectSquareFail.LOG_KIND -> { + val logItem = LogInjectSquareFail.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -371,8 +371,8 @@ class BigLogInquireResponsePacket( status = "EXTENDED_BOLUS_FAIL " + dateUtil.timeString(logDateTime) } - LOG_SET_DUAL_INJECTION.LOG_KIND -> { - val logItem = LOG_SET_DUAL_INJECTION.parse(logDataToHexString) + LogSetDualInjection.LOG_KIND -> { + val logItem = LogSetDualInjection.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -405,8 +405,8 @@ class BigLogInquireResponsePacket( status = "DUAL_EXTENDED_START " + dateUtil.timeString(logDateTime) } - LOG_INJECTION_DUAL_NORMAL.LOG_KIND -> { - val logItem = LOG_INJECTION_DUAL_NORMAL.parse(logDataToHexString) + LogInjectionDualNormal.LOG_KIND -> { + val logItem = LogInjectionDualNormal.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -445,8 +445,8 @@ class BigLogInquireResponsePacket( status = "DUAL_BOLUS" + dateUtil.timeString(logDateTime) } - LOG_INJECT_DUAL_SUCCESS.LOG_KIND -> { - val logItem = LOG_INJECT_DUAL_SUCCESS.parse(logDataToHexString) + LogInjectDualSuccess.LOG_KIND -> { + val logItem = LogInjectDualSuccess.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -464,8 +464,8 @@ class BigLogInquireResponsePacket( status = "DUAL_BOLUS_SQUARE_SUCCESS " + dateUtil.timeString(logDateTime) } - LOG_INJECT_DUAL_FAIL.LOG_KIND -> { - val logItem = LOG_INJECT_DUAL_FAIL.parse(logDataToHexString) + LogInjectDualFail.LOG_KIND -> { + val logItem = LogInjectDualFail.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -493,8 +493,8 @@ class BigLogInquireResponsePacket( status = "DUAL_BOLUS FAIL " + dateUtil.timeString(logDateTime) } - LOG_INJECTION_1HOUR_BASAL.LOG_KIND -> { - val logItem = LOG_INJECTION_1HOUR_BASAL.parse(logDataToHexString) + LogInjection1HourBasal.LOG_KIND -> { + val logItem = LogInjection1HourBasal.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -509,8 +509,8 @@ class BigLogInquireResponsePacket( status = "1HOUR BASAL " + dateUtil.dateAndTimeString(logDateTime) } - LOG_SUSPEND_V2.LOG_KIND -> { - val logItem = LOG_SUSPEND_V2.parse(logDataToHexString) + LogSuspendV2.LOG_KIND -> { + val logItem = LogSuspendV2.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -524,8 +524,8 @@ class BigLogInquireResponsePacket( status = "SUSPEND " + dateUtil.timeString(logDateTime) } - LOG_SUSPEND_RELEASE_V2.LOG_KIND -> { - val logItem = LOG_SUSPEND_RELEASE_V2.parse(logDataToHexString) + LogSuspendReleaseV2.LOG_KIND -> { + val logItem = LogSuspendReleaseV2.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -539,8 +539,8 @@ class BigLogInquireResponsePacket( status = "SUSPEND_RELEASE " + dateUtil.timeString(logDateTime) } - LOG_CHANGE_INJECTOR_SUCCESS.LOG_KIND -> { - val logItem = LOG_CHANGE_INJECTOR_SUCCESS.parse(logDataToHexString) + LogChangeInjectorSuccess.LOG_KIND -> { + val logItem = LogChangeInjectorSuccess.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -568,8 +568,8 @@ class BigLogInquireResponsePacket( status = "INSULIN_CHANGE " + dateUtil.timeString(logDateTime) } - LOG_CHANGE_TUBE_SUCCESS.LOG_KIND -> { - val logItem = LOG_CHANGE_TUBE_SUCCESS.parse(logDataToHexString) + LogChangeTubeSuccess.LOG_KIND -> { + val logItem = LogChangeTubeSuccess.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -600,8 +600,8 @@ class BigLogInquireResponsePacket( status = "TUBE_CHANGE " + dateUtil.timeString(logDateTime) } - LOG_INJECTION_1DAY.LOG_KIND -> { // Daily Bolus Log - val logItem = LOG_INJECTION_1DAY.parse(logDataToHexString) + LogInjection1Day.LOG_KIND -> { // Daily Bolus Log + val logItem = LogInjection1Day.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -649,8 +649,8 @@ class BigLogInquireResponsePacket( status = "DAILY_BOLUS " + dateUtil.timeString(logDateTime) } - LOG_INJECTION_1DAY_BASAL.LOG_KIND -> { // Daily Basal Log - val logItem = LOG_INJECTION_1DAY_BASAL.parse(logDataToHexString) + LogInjection1DayBasal.LOG_KIND -> { // Daily Basal Log + val logItem = LogInjection1DayBasal.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -698,8 +698,8 @@ class BigLogInquireResponsePacket( status = "DAILY_BASAL " + dateUtil.timeString(logDateTime) } - LOG_CHANGE_NEEDLE_SUCCESS.LOG_KIND -> { - val logItem = LOG_CHANGE_NEEDLE_SUCCESS.parse(logDataToHexString) + LogChangeNeedleSuccess.LOG_KIND -> { + val logItem = LogChangeNeedleSuccess.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -728,8 +728,8 @@ class BigLogInquireResponsePacket( status = "NEEDLE_CHANGE " + dateUtil.timeString(logDateTime) } - LOG_TB_START_V3.LOG_KIND -> { - val logItem = LOG_TB_START_V3.parse(logDataToHexString) + LogTbStartV3.LOG_KIND -> { + val logItem = LogTbStartV3.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") @@ -772,8 +772,8 @@ class BigLogInquireResponsePacket( status = "TEMP_START " + dateUtil.timeString(logDateTime) } - LOG_TB_STOP_V3.LOG_KIND -> { - val logItem = LOG_TB_STOP_V3.parse(logDataToHexString) + LogTbStopV3.LOG_KIND -> { + val logItem = LogTbStopV3.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -806,8 +806,8 @@ class BigLogInquireResponsePacket( status = "TEMP_STOP " + dateUtil.timeString(logDateTime) } - LOG_ALARM_BATTERY.LOG_KIND -> { // BATTERY SHORTAGE ALARM - val logItem = LOG_ALARM_BATTERY.parse(logDataToHexString) + LogAlarmBattery.LOG_KIND -> { // BATTERY SHORTAGE ALARM + val logItem = LogAlarmBattery.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") val logDateTime = logStartDate.time @@ -822,8 +822,8 @@ class BigLogInquireResponsePacket( status = "BATTERY_ALARM " + dateUtil.timeString(logDateTime) } - LOG_ALARM_BLOCK.LOG_KIND -> { // INJECTION BLOCKED ALARM - val logItem = LOG_ALARM_BLOCK.parse(logDataToHexString) + LogAlarmBlock.LOG_KIND -> { // INJECTION BLOCKED ALARM + val logItem = LogAlarmBlock.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") @@ -840,8 +840,8 @@ class BigLogInquireResponsePacket( status = "BLOCK_ALARM " + dateUtil.timeString(logDateTime) } - LOG_ALARM_SHORTAGE.LOG_KIND -> { // INSULIN SHORTAGE ALARM - val logItem = LOG_ALARM_SHORTAGE.parse(logDataToHexString) + LogAlarmShortAge.LOG_KIND -> { // INSULIN SHORTAGE ALARM + val logItem = LogAlarmShortAge.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") @@ -858,8 +858,8 @@ class BigLogInquireResponsePacket( status = "SHORT_AGE_ALARM " + dateUtil.timeString(logDateTime) } - LOG_RESET_SYS_V3.LOG_KIND -> { - val logItem = LOG_RESET_SYS_V3.parse(logDataToHexString) + LogResetSysV3.LOG_KIND -> { + val logItem = LogResetSysV3.parse(logDataToHexString) aapsLogger.debug(LTag.PUMPCOMM, "$logItem ") val logStartDate = DateUtils.parseDate(logItem.dttm, "yyyy-MM-dd HH:mm:ss") diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigMainInfoInquireResponsePacket.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigMainInfoInquireResponsePacket.kt index 7ee93e9a1f..ce67dc789d 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigMainInfoInquireResponsePacket.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigMainInfoInquireResponsePacket.kt @@ -5,7 +5,7 @@ import info.nightscout.interfaces.pump.defs.PumpDescription import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.pump.diaconn.DiaconnG8Pump import info.nightscout.pump.diaconn.R -import info.nightscout.pump.diaconn.pumplog.PumplogUtil +import info.nightscout.pump.diaconn.pumplog.PumpLogUtil import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP @@ -213,7 +213,7 @@ class BigMainInfoInquireResponsePacket( diaconnG8Pump.pumpProfiles!![diaconnG8Pump.activeProfile][23] = diaconnG8Pump.baseAmount24 //incarnation no 처리 - diaconnG8Pump.isPumpVersionGe2_63 = PumplogUtil.isPumpVersionGe(sp.getString(rh.gs(R.string.pumpversion), ""), 2, 63) + diaconnG8Pump.isPumpVersionGe2_63 = PumpLogUtil.isPumpVersionGe(sp.getString(rh.gs(R.string.pumpversion), ""), 2, 63) aapsLogger.debug(LTag.PUMPCOMM, "result > " + diaconnG8Pump.result) aapsLogger.debug(LTag.PUMPCOMM, "systemRemainInsulin > " + diaconnG8Pump.systemRemainInsulin) diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_ALARM_BATTERY.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogAlarmBattery.kt similarity index 68% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_ALARM_BATTERY.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogAlarmBattery.kt index faf98ff078..75ad61dce4 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_ALARM_BATTERY.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogAlarmBattery.kt @@ -6,7 +6,7 @@ import java.nio.ByteOrder /* * Battery Shortage Alarm Log */ -class LOG_ALARM_BATTERY private constructor( +class LogAlarmBattery private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 1=INFO, 2=WARNING, 3=MAJOR, 4=CRITICAL @@ -15,8 +15,8 @@ class LOG_ALARM_BATTERY private constructor( val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) override fun toString(): String { val sb = StringBuilder("LOG_ALARM_BATTERY{") @@ -35,17 +35,17 @@ class LOG_ALARM_BATTERY private constructor( companion object { const val LOG_KIND: Byte = 0x28 - fun parse(data: String): LOG_ALARM_BATTERY { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogAlarmBattery { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_ALARM_BATTERY( + return LogAlarmBattery( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_ALARM_BLOCK.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogAlarmBlock.kt similarity index 66% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_ALARM_BLOCK.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogAlarmBlock.kt index 5b794a8843..dcfc0b8397 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_ALARM_BLOCK.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogAlarmBlock.kt @@ -6,19 +6,19 @@ import java.nio.ByteOrder /* * Injection Blocked Alarm Log */ -class LOG_ALARM_BLOCK private constructor( +class LogAlarmBlock private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 1=INFO, 2=WARNING, 3=MAJOR, 4=CRITICAL - val alarmLevel: Byte, // 1=OCCUR - val ack: Byte, + private val alarmLevel: Byte, // 1=OCCUR + private val ack: Byte, val amount: Short, // 1=BASE, 2=Meal, 3=snack , 4=square, 5=dual, 6=tube change, 7=needle change, 8=insulin change val reason: Byte, val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) override fun toString(): String { val sb = StringBuilder("LOG_ALARM_BLOCK{") @@ -39,19 +39,19 @@ class LOG_ALARM_BLOCK private constructor( companion object { const val LOG_KIND: Byte = 0x29 - fun parse(data: String): LOG_ALARM_BLOCK { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogAlarmBlock { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_ALARM_BLOCK( + return LogAlarmBlock( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_ALARM_SHORTAGE.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogAlarmShortAge.kt similarity index 63% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_ALARM_SHORTAGE.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogAlarmShortAge.kt index 827d2a6622..89c6329332 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_ALARM_SHORTAGE.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogAlarmShortAge.kt @@ -6,18 +6,18 @@ import java.nio.ByteOrder /* * Insulin shortage alarm */ -class LOG_ALARM_SHORTAGE private constructor( +class LogAlarmShortAge private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 1=INFO, 2=WARNING, 3=MAJOR, 4=CRITICAL - val alarmLevel: Byte, // 1=OCCUR, 2=STOP - val ack: Byte, // (1~100U) + private val alarmLevel: Byte, // 1=OCCUR, 2=STOP + private val ack: Byte, // (1~100U) val remain: Byte, val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) override fun toString(): String { val sb = StringBuilder("LOG_ALARM_SHORTAGE{") @@ -37,18 +37,18 @@ class LOG_ALARM_SHORTAGE private constructor( companion object { const val LOG_KIND: Byte = 0x2A - fun parse(data: String): LOG_ALARM_SHORTAGE { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogAlarmShortAge { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_ALARM_SHORTAGE( + return LogAlarmShortAge( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_CHANGE_INJECTOR_SUCCESS.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogChangeInjectorSuccess.kt similarity index 67% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_CHANGE_INJECTOR_SUCCESS.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogChangeInjectorSuccess.kt index e0ae6a26c4..26ba1b3150 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_CHANGE_INJECTOR_SUCCESS.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogChangeInjectorSuccess.kt @@ -6,7 +6,7 @@ import java.nio.ByteOrder /* * 주사기 교체 성공 */ -class LOG_CHANGE_INJECTOR_SUCCESS private constructor( +class LogChangeInjectorSuccess private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 47.5=4750 @@ -15,8 +15,8 @@ class LOG_CHANGE_INJECTOR_SUCCESS private constructor( val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) override fun toString(): String { val sb = StringBuilder("LOG_CHANGE_INJECTOR_SUCCESS{") @@ -35,17 +35,17 @@ class LOG_CHANGE_INJECTOR_SUCCESS private constructor( companion object { const val LOG_KIND: Byte = 0x1A - fun parse(data: String): LOG_CHANGE_INJECTOR_SUCCESS { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogChangeInjectorSuccess { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_CHANGE_INJECTOR_SUCCESS( + return LogChangeInjectorSuccess( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_CHANGE_NEEDLE_SUCCESS.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogChangeNeedleSuccess.kt similarity index 66% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_CHANGE_NEEDLE_SUCCESS.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogChangeNeedleSuccess.kt index 045a28e302..f69320fcc9 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_CHANGE_NEEDLE_SUCCESS.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogChangeNeedleSuccess.kt @@ -6,7 +6,8 @@ import java.nio.ByteOrder /* * 바늘 공기빼기 성공 */ -class LOG_CHANGE_NEEDLE_SUCCESS private constructor( +@Suppress("SpellCheckingInspection") +class LogChangeNeedleSuccess private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 47.5=4750 @@ -15,8 +16,8 @@ class LOG_CHANGE_NEEDLE_SUCCESS private constructor( val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) override fun toString(): String { val sb = StringBuilder("LOG_CHANGE_NEEDLE_SUCCESS{") @@ -35,17 +36,17 @@ class LOG_CHANGE_NEEDLE_SUCCESS private constructor( companion object { const val LOG_KIND: Byte = 0x1C - fun parse(data: String): LOG_CHANGE_NEEDLE_SUCCESS { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogChangeNeedleSuccess { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_CHANGE_NEEDLE_SUCCESS( + return LogChangeNeedleSuccess( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_CHANGE_TUBE_SUCCESS.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogChangeTubeSuccess.kt similarity index 66% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_CHANGE_TUBE_SUCCESS.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogChangeTubeSuccess.kt index 84b57d3e87..d3a6025de9 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_CHANGE_TUBE_SUCCESS.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogChangeTubeSuccess.kt @@ -6,7 +6,8 @@ import java.nio.ByteOrder /* * 튜브 공기빼기 성공 */ -class LOG_CHANGE_TUBE_SUCCESS private constructor( +@Suppress("SpellCheckingInspection") +class LogChangeTubeSuccess private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 47.5=4750 @@ -15,8 +16,8 @@ class LOG_CHANGE_TUBE_SUCCESS private constructor( val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) override fun toString(): String { val sb = StringBuilder("LOG_CHANGE_TUBE_SUCCESS{") @@ -35,17 +36,17 @@ class LOG_CHANGE_TUBE_SUCCESS private constructor( companion object { const val LOG_KIND: Byte = 0x18 - fun parse(data: String): LOG_CHANGE_TUBE_SUCCESS { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogChangeTubeSuccess { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_CHANGE_TUBE_SUCCESS( + return LogChangeTubeSuccess( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_DUAL_FAIL.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectDualFail.kt similarity index 71% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_DUAL_FAIL.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectDualFail.kt index 8aa28434d7..c9197f2854 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_DUAL_FAIL.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectDualFail.kt @@ -7,7 +7,8 @@ import java.nio.ByteOrder /* * Dual Injection Fail Log */ -class LOG_INJECT_DUAL_FAIL private constructor( +@Suppress("SpellCheckingInspection") +class LogInjectDualFail private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 47.5=4750 @@ -18,8 +19,8 @@ class LOG_INJECT_DUAL_FAIL private constructor( val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) fun getInjectTime(): Int { return injectTime and 0xff @@ -44,19 +45,19 @@ class LOG_INJECT_DUAL_FAIL private constructor( companion object { const val LOG_KIND: Byte = 0x11 - fun parse(data: String): LOG_INJECT_DUAL_FAIL { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogInjectDualFail { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_INJECT_DUAL_FAIL( + return LogInjectDualFail( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_DUAL_SUCCESS.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectDualSuccess.kt similarity index 67% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_DUAL_SUCCESS.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectDualSuccess.kt index f5dd9d1638..3e0acd0b80 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_DUAL_SUCCESS.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectDualSuccess.kt @@ -7,18 +7,19 @@ import java.nio.ByteOrder /* * 듀얼주입 성공 */ -class LOG_INJECT_DUAL_SUCCESS private constructor( +@Suppress("SpellCheckingInspection") +class LogInjectDualSuccess private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 47.5=4750 - val injectNormAmount: Short, // 47.5=4750 + private val injectNormAmount: Short, // 47.5=4750 val injectSquareAmount: Short, // 1분단위 주입시간(124=124분=2시간4분) private val injectTime: Byte, val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) fun getInjectTime(): Int { return injectTime and 0xff } @@ -41,18 +42,18 @@ class LOG_INJECT_DUAL_SUCCESS private constructor( companion object { const val LOG_KIND: Byte = 0x10 - fun parse(data: String): LOG_INJECT_DUAL_SUCCESS { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogInjectDualSuccess { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_INJECT_DUAL_SUCCESS( + return LogInjectDualSuccess( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_MEAL_FAIL.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectMealFail.kt similarity index 71% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_MEAL_FAIL.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectMealFail.kt index ab046f0e9f..a01640f6d1 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_MEAL_FAIL.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectMealFail.kt @@ -7,7 +7,8 @@ import java.nio.ByteOrder /* * 식사주입 실패 */ -class LOG_INJECT_MEAL_FAIL private constructor( +@Suppress("SpellCheckingInspection") +class LogInjectMealFail private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 47.5=4750 @@ -18,8 +19,8 @@ class LOG_INJECT_MEAL_FAIL private constructor( val reason: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) fun getInjectTime(): Int { return injectTime and 0xff @@ -44,19 +45,19 @@ class LOG_INJECT_MEAL_FAIL private constructor( companion object { const val LOG_KIND: Byte = 0x09 - fun parse(data: String): LOG_INJECT_MEAL_FAIL { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogInjectMealFail { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_INJECT_MEAL_FAIL( + return LogInjectMealFail( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_MEAL_SUCCESS.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectMealSuccess.kt similarity index 67% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_MEAL_SUCCESS.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectMealSuccess.kt index e1292aae47..23cda27c74 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_MEAL_SUCCESS.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectMealSuccess.kt @@ -7,7 +7,8 @@ import java.nio.ByteOrder /* * 식사주입 성공 */ -class LOG_INJECT_MEAL_SUCCESS private constructor( +@Suppress("SpellCheckingInspection") +class LogInjectMealSuccess private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 47.5=4750 @@ -15,12 +16,11 @@ class LOG_INJECT_MEAL_SUCCESS private constructor( val injectAmount: Short, // 1분단위 주입시간(124=124분=2시간4분) private val injectTime: Byte, // 아침=1, 점심=2, 저녁=3 val time: Byte, - batteryRemain: Byte + val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) - val batteryRemain: Byte = batteryRemain + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) fun getInjectTime(): Int { return injectTime and 0xff } @@ -44,19 +44,19 @@ class LOG_INJECT_MEAL_SUCCESS private constructor( companion object { const val LOG_KIND: Byte = 0x08 - fun parse(data: String): LOG_INJECT_MEAL_SUCCESS { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogInjectMealSuccess { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_INJECT_MEAL_SUCCESS( + return LogInjectMealSuccess( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_NORMAL_FAIL.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectNormalFail.kt similarity index 68% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_NORMAL_FAIL.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectNormalFail.kt index 71b0beb1d4..ca4e156085 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_NORMAL_FAIL.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectNormalFail.kt @@ -7,19 +7,20 @@ import java.nio.ByteOrder /* * 일반주입 실패 */ -class LOG_INJECT_NORMAL_FAIL private constructor( +@Suppress("SpellCheckingInspection") +class LogInjectNormalFail private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 47.5=4750 - val setAmount: Short, // 47.5=4750 + private val setAmount: Short, // 47.5=4750 val injectAmount: Short, // 1분단위 주입시간(124=124분=2시간4분) val injectTime: Byte, // 1=주입막힘, 2=배터리잔량부족, 3=약물부족, 4=사용자중지, 5=시스템리셋, 6=기타, 7=긴급정지 val reason: Byte, val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) fun getInjectTime(): Int { return injectTime and 0xff @@ -44,19 +45,19 @@ class LOG_INJECT_NORMAL_FAIL private constructor( companion object { const val LOG_KIND: Byte = 0x0B - fun parse(data: String): LOG_INJECT_NORMAL_FAIL { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogInjectNormalFail { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_INJECT_NORMAL_FAIL( + return LogInjectNormalFail( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_NORMAL_SUCCESS.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectNormalSuccess.kt similarity index 66% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_NORMAL_SUCCESS.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectNormalSuccess.kt index 4692b7b8a0..6725145414 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_NORMAL_SUCCESS.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectNormalSuccess.kt @@ -7,18 +7,19 @@ import java.nio.ByteOrder /* * 일반주입 성공 */ -class LOG_INJECT_NORMAL_SUCCESS private constructor( +@Suppress("SpellCheckingInspection") +class LogInjectNormalSuccess private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 47.5=4750 - val setAmount: Short, // 47.5=4750 + private val setAmount: Short, // 47.5=4750 val injectAmount: Short, // 1분단위 주입시간(124=124분=2시간4분) val injectTime: Byte, val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) fun getInjectTime(): Int { return injectTime and 0xff } @@ -41,18 +42,18 @@ class LOG_INJECT_NORMAL_SUCCESS private constructor( companion object { const val LOG_KIND: Byte = 0x0A - fun parse(data: String): LOG_INJECT_NORMAL_SUCCESS { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogInjectNormalSuccess { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_INJECT_NORMAL_SUCCESS( + return LogInjectNormalSuccess( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_SQUARE_FAIL.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectSquareFail.kt similarity index 70% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_SQUARE_FAIL.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectSquareFail.kt index c815dfec45..31c910307d 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_SQUARE_FAIL.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectSquareFail.kt @@ -7,7 +7,8 @@ import java.nio.ByteOrder /* * 스퀘어주입 실패 */ -class LOG_INJECT_SQUARE_FAIL private constructor( +@Suppress("SpellCheckingInspection") +class LogInjectSquareFail private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 47.5=4750 @@ -17,8 +18,8 @@ class LOG_INJECT_SQUARE_FAIL private constructor( val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) fun getInjectTime(): Int { return injectTime and 0xff @@ -42,18 +43,18 @@ class LOG_INJECT_SQUARE_FAIL private constructor( companion object { const val LOG_KIND: Byte = 0x0E - fun parse(data: String): LOG_INJECT_SQUARE_FAIL { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogInjectSquareFail { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_INJECT_SQUARE_FAIL( + return LogInjectSquareFail( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_SQUARE_SUCCESS.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectSquareSuccess.kt similarity index 64% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_SQUARE_SUCCESS.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectSquareSuccess.kt index e76fe57c06..0d1a2181e2 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECT_SQUARE_SUCCESS.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectSquareSuccess.kt @@ -7,17 +7,18 @@ import java.nio.ByteOrder /* * 스퀘어주입 성공 */ -class LOG_INJECT_SQUARE_SUCCESS private constructor( +@Suppress("SpellCheckingInspection") +class LogInjectSquareSuccess private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 47.5=4750 - val injectAmount: Short, // 1분단위 주입시간(124=124분=2시간4분) + private val injectAmount: Short, // 1분단위 주입시간(124=124분=2시간4분) private val injectTime: Byte, val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) fun getInjectTime(): Int { return injectTime and 0xff } @@ -39,17 +40,17 @@ class LOG_INJECT_SQUARE_SUCCESS private constructor( companion object { const val LOG_KIND: Byte = 0x0D - fun parse(data: String): LOG_INJECT_SQUARE_SUCCESS { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogInjectSquareSuccess { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_INJECT_SQUARE_SUCCESS( + return LogInjectSquareSuccess( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECTION_1DAY.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjection1Day.kt similarity index 68% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECTION_1DAY.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjection1Day.kt index 4d536a6194..2dc31d9e47 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECTION_1DAY.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjection1Day.kt @@ -6,7 +6,8 @@ import java.nio.ByteOrder /* * 당일 주입 총량 (식사, 추가) */ -class LOG_INJECTION_1DAY private constructor( +@Suppress("SpellCheckingInspection") +class LogInjection1Day private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 당일 식사주입 총량 47.5=4750 @@ -15,8 +16,8 @@ class LOG_INJECTION_1DAY private constructor( val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) override fun toString(): String { val sb = StringBuilder("LOG_INJECTION_1DAY{") @@ -35,17 +36,17 @@ class LOG_INJECTION_1DAY private constructor( companion object { const val LOG_KIND: Byte = 0x2F - fun parse(data: String): LOG_INJECTION_1DAY { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogInjection1Day { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_INJECTION_1DAY( + return LogInjection1Day( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECTION_1DAY_BASAL.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjection1DayBasal.kt similarity index 66% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECTION_1DAY_BASAL.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjection1DayBasal.kt index 9c8a47fc37..2c90363850 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECTION_1DAY_BASAL.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjection1DayBasal.kt @@ -6,7 +6,8 @@ import java.nio.ByteOrder /* * 당일 주입 총량 (기저) */ -class LOG_INJECTION_1DAY_BASAL private constructor( +@Suppress("SpellCheckingInspection") +class LogInjection1DayBasal private constructor( val data: String, val dttm: String, typeAndKind: Byte, @@ -15,8 +16,8 @@ class LOG_INJECTION_1DAY_BASAL private constructor( val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) override fun toString(): String { val sb = StringBuilder("LOG_INJECTION_1DAY_BASAL{") @@ -33,16 +34,16 @@ class LOG_INJECTION_1DAY_BASAL private constructor( companion object { const val LOG_KIND: Byte = 0x2E - fun parse(data: String): LOG_INJECTION_1DAY_BASAL { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogInjection1DayBasal { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_INJECTION_1DAY_BASAL( + return LogInjection1DayBasal( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECTION_1HOUR_BASAL.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjection1HourBasal.kt similarity index 74% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECTION_1HOUR_BASAL.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjection1HourBasal.kt index ea0663d07b..c09820b992 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECTION_1HOUR_BASAL.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjection1HourBasal.kt @@ -6,7 +6,8 @@ import java.nio.ByteOrder /* * 1시간 단위 기저 주입량 */ -class LOG_INJECTION_1HOUR_BASAL private constructor( +@Suppress("SpellCheckingInspection") +class LogInjection1HourBasal private constructor( val data: String, val dttm: String, typeAndKind: Byte, @@ -17,8 +18,8 @@ class LOG_INJECTION_1HOUR_BASAL private constructor( private val remainTotalAmount: Short ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) val beforeAmount // 해당시간의 임시기저 계산 전 기저주입량: 기저주입막힘 발생 시 기저주입 막힘량 제외, 기저정지로 인해 주입되지 않은 량 제외, 리셋으로 인해 주입되지 않은 량 제외(47.5=4750) : Short = tbBeforeAmount val afterAmount // 해당시간의 임시기저 계산 후 기저주입량: 기저주입막힘 발생 시 기저주입 막힘량 제외, 기저정지로 인해 주입되지 않은 량 제외, 리셋으로 인해 주입되지 않은 량 제외(47.5=4750) @@ -42,18 +43,18 @@ class LOG_INJECTION_1HOUR_BASAL private constructor( companion object { const val LOG_KIND: Byte = 0x2C - fun parse(data: String): LOG_INJECTION_1HOUR_BASAL { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogInjection1HourBasal { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_INJECTION_1HOUR_BASAL( + return LogInjection1HourBasal( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECTION_DUAL_NORMAL.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectionDualNormal.kt similarity index 67% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECTION_DUAL_NORMAL.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectionDualNormal.kt index ce46ea8bfd..95f9fb19b5 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_INJECTION_DUAL_NORMAL.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogInjectionDualNormal.kt @@ -7,18 +7,19 @@ import java.nio.ByteOrder /* * 듀얼(일반) 주입량: 듀얼(일반) 주입 완료 시 기록하는 방식 */ -class LOG_INJECTION_DUAL_NORMAL private constructor( +@Suppress("SpellCheckingInspection") +class LogInjectionDualNormal private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 설정량 47.5=4750 - val setAmount: Short, // 주입량 47.5=4750 + private val setAmount: Short, // 주입량 47.5=4750 val injectAmount: Short, // 1분 단위 주입 시간 Ex) 124 = 124분 = 2시간 4분 private val injectTime: Byte, val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) fun getInjectTime(): Int { return injectTime and 0xff } @@ -41,18 +42,18 @@ class LOG_INJECTION_DUAL_NORMAL private constructor( companion object { const val LOG_KIND: Byte = 0x35 - fun parse(data: String): LOG_INJECTION_DUAL_NORMAL { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogInjectionDualNormal { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_INJECTION_DUAL_NORMAL( + return LogInjectionDualNormal( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_RESET_SYS_V3.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogResetSysV3.kt similarity index 62% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_RESET_SYS_V3.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogResetSysV3.kt index 491fdf04bb..a47ba43e0d 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_RESET_SYS_V3.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogResetSysV3.kt @@ -6,18 +6,19 @@ import java.nio.ByteOrder /* * System Reset Log */ -class LOG_RESET_SYS_V3 private constructor( +@Suppress("SpellCheckingInspection") +class LogResetSysV3 private constructor( val data: String, val dttm: String, typeAndKind: Byte, val batteryRemain: Byte, val reason: Byte, // 사유(1:공장초기화 후 리셋, 2:긴급정지 해제 후 리셋, 3:사용자 배터리 교체 후 리셋, 4:캘리브레이션 후 리셋, 9:예상치 못한 시스템 리셋) - val rcon1: Short, // PIC 데이터 시트 내 정의된 2바이트 값 - val rcon2: Short // PIC 데이터 시트 내 정의된 2바이트 값 + private val rcon1: Short, // PIC 데이터 시트 내 정의된 2바이트 값 + private val rcon2: Short // PIC 데이터 시트 내 정의된 2바이트 값 ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) override fun toString(): String { val sb = StringBuilder("LOG_RESET_SYS_V3{") @@ -37,18 +38,18 @@ class LOG_RESET_SYS_V3 private constructor( companion object { const val LOG_KIND: Byte = 0x01 - fun parse(data: String): LOG_RESET_SYS_V3 { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogResetSysV3 { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_RESET_SYS_V3( + return LogResetSysV3( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getShort(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getShort(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_SET_DUAL_INJECTION.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogSetDualInjection.kt similarity index 66% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_SET_DUAL_INJECTION.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogSetDualInjection.kt index c90acc008b..daedf5c04c 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_SET_DUAL_INJECTION.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogSetDualInjection.kt @@ -7,18 +7,19 @@ import java.nio.ByteOrder /* * 듀얼주입 설정(시작) */ -class LOG_SET_DUAL_INJECTION private constructor( +@Suppress("SpellCheckingInspection") +class LogSetDualInjection private constructor( val data: String, val dttm: String, typeAndKind: Byte, - val setNormAmount: Short, // 47.5=4750 + private val setNormAmount: Short, // 47.5=4750 val setSquareAmount: Short, // 47.5=4750 private val injectTime: Byte, // 1~30( 1: 10min ) val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) fun getInjectTime(): Int { return injectTime and 0xff } @@ -41,18 +42,18 @@ class LOG_SET_DUAL_INJECTION private constructor( companion object { const val LOG_KIND: Byte = 0x0F - fun parse(data: String): LOG_SET_DUAL_INJECTION { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogSetDualInjection { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_SET_DUAL_INJECTION( + return LogSetDualInjection( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_SET_SQUARE_INJECTION.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogSetSquareInjection.kt similarity index 68% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_SET_SQUARE_INJECTION.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogSetSquareInjection.kt index 4c315da683..6ad23e0439 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_SET_SQUARE_INJECTION.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogSetSquareInjection.kt @@ -7,7 +7,8 @@ import java.nio.ByteOrder /* * 스퀘어주입 설정(시작) */ -class LOG_SET_SQUARE_INJECTION private constructor( +@Suppress("SpellCheckingInspection") +class LogSetSquareInjection private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 47.5=4750 @@ -16,8 +17,8 @@ class LOG_SET_SQUARE_INJECTION private constructor( val batteryRemain: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) fun getInjectTime(): Int { return injectTime and 0xff } @@ -39,17 +40,17 @@ class LOG_SET_SQUARE_INJECTION private constructor( companion object { const val LOG_KIND: Byte = 0x0C - fun parse(data: String): LOG_SET_SQUARE_INJECTION { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogSetSquareInjection { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_SET_SQUARE_INJECTION( + return LogSetSquareInjection( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_SUSPEND_RELEASE_V2.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogSuspendReleaseV2.kt similarity index 73% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_SUSPEND_RELEASE_V2.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogSuspendReleaseV2.kt index b10961e883..e53445912c 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_SUSPEND_RELEASE_V2.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogSuspendReleaseV2.kt @@ -6,7 +6,8 @@ import java.nio.ByteOrder /* * 일시정지 중지 (기저정지 해제) */ -class LOG_SUSPEND_RELEASE_V2 private constructor( +@Suppress("SpellCheckingInspection") +class LogSuspendReleaseV2 private constructor( val data: String, val dttm: String, typeAndKind: Byte, @@ -17,7 +18,7 @@ class LOG_SUSPEND_RELEASE_V2 private constructor( val type: Byte val kind: Byte val batteryRemain: Byte - val patternType // 1=기본, 2=생활1, 3=생활2, 4=생활3, 5=닥터1, 6=닥터2 + private val patternType // 1=기본, 2=생활1, 3=생활2, 4=생활3, 5=닥터1, 6=닥터2 : Byte override fun toString(): String { @@ -48,23 +49,23 @@ class LOG_SUSPEND_RELEASE_V2 private constructor( companion object { const val LOG_KIND: Byte = 0x04 - fun parse(data: String): LOG_SUSPEND_RELEASE_V2 { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogSuspendReleaseV2 { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_SUSPEND_RELEASE_V2( + return LogSuspendReleaseV2( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } init { - type = PumplogUtil.getType(typeAndKind) - kind = PumplogUtil.getKind(typeAndKind) + type = PumpLogUtil.getType(typeAndKind) + kind = PumpLogUtil.getKind(typeAndKind) this.batteryRemain = batteryRemain this.patternType = patternType } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_SUSPEND_V2.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogSuspendV2.kt similarity index 73% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_SUSPEND_V2.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogSuspendV2.kt index 7a1dc061c8..0daf0acaea 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_SUSPEND_V2.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogSuspendV2.kt @@ -6,16 +6,17 @@ import java.nio.ByteOrder /* * 일시정지 시작 (기저정지) */ -class LOG_SUSPEND_V2 private constructor( +@Suppress("SpellCheckingInspection") +class LogSuspendV2 private constructor( val data: String, val dttm: String, typeAndKind: Byte, val batteryRemain: Byte, // 1=기본, 2=생활1, 3=생활2, 4=생활3, 5=닥터1, 6=닥터2 - val patternType: Byte + private val patternType: Byte ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) override fun toString(): String { val sb = StringBuilder("LOG_SUSPEND_V2{") @@ -46,16 +47,16 @@ class LOG_SUSPEND_V2 private constructor( companion object { const val LOG_KIND: Byte = 0x03 - fun parse(data: String): LOG_SUSPEND_V2 { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogSuspendV2 { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_SUSPEND_V2( + return LogSuspendV2( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_TB_START_V3.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogTbStartV3.kt similarity index 72% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_TB_START_V3.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogTbStartV3.kt index 8f54222df8..09d3e7897f 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_TB_START_V3.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogTbStartV3.kt @@ -8,7 +8,8 @@ import java.nio.ByteOrder /* * 임시기저 설정(시작) */ -class LOG_TB_START_V3 private constructor( +@Suppress("SpellCheckingInspection") +class LogTbStartV3 private constructor( val data: String, val dttm: String, typeAndKind: Byte, // 임시기저 시간(30분 ~ 24시간, 2 ~ 96, 1당 15분 단위 증감) @@ -17,8 +18,8 @@ class LOG_TB_START_V3 private constructor( private val tbDttm: String // 앱에서 생성 전달한 임시기저 시작(요청) 시간 ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) fun getTbInjectRateRatio(): Int { return tbInjectRateRatio and 0xffff @@ -33,7 +34,7 @@ class LOG_TB_START_V3 private constructor( sb.append(", kind=").append(kind.toInt()) sb.append(", tbTime=").append(tbTime.toInt()) sb.append(", tbInjectRateRatio=").append(tbInjectRateRatio and 0xffff) - if (!StringUtils.equals(tbDttm, PumplogUtil.getDttm("ffffffff"))) { + if (!StringUtils.equals(tbDttm, PumpLogUtil.getDttm("ffffffff"))) { sb.append(", tbDttm=").append(tbDttm) } sb.append('}') @@ -43,17 +44,17 @@ class LOG_TB_START_V3 private constructor( companion object { const val LOG_KIND: Byte = 0x12 - fun parse(data: String): LOG_TB_START_V3 { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogTbStartV3 { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_TB_START_V3( + return LogTbStartV3( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getDttm(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getDttm(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_TB_STOP_V3.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogTbStopV3.kt similarity index 72% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_TB_STOP_V3.kt rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogTbStopV3.kt index 51080f95bb..1b4bff1be5 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LOG_TB_STOP_V3.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/LogTbStopV3.kt @@ -8,7 +8,8 @@ import java.nio.ByteOrder /* * 임시기저 중지(완료) */ -class LOG_TB_STOP_V3 private constructor( +@Suppress("SpellCheckingInspection") +class LogTbStopV3 private constructor( val data: String, val dttm: String, typeAndKind: Byte, @@ -20,8 +21,8 @@ class LOG_TB_STOP_V3 private constructor( private val tbDttm: String ) { - val type: Byte = PumplogUtil.getType(typeAndKind) - val kind: Byte = PumplogUtil.getKind(typeAndKind) + val type: Byte = PumpLogUtil.getType(typeAndKind) + val kind: Byte = PumpLogUtil.getKind(typeAndKind) fun getTbInjectRateRatio(): Int { return tbInjectRateRatio and 0xffff @@ -36,7 +37,7 @@ class LOG_TB_STOP_V3 private constructor( sb.append(", kind=").append(kind.toInt()) sb.append(", tbInjectRateRatio=").append(tbInjectRateRatio and 0xffff) sb.append(", reason=").append(reason.toInt()) - if (!StringUtils.equals(tbDttm, PumplogUtil.getDttm("ffffffff"))) { + if (!StringUtils.equals(tbDttm, PumpLogUtil.getDttm("ffffffff"))) { sb.append(", tbDttm=").append(tbDttm) } sb.append('}') @@ -46,17 +47,17 @@ class LOG_TB_STOP_V3 private constructor( companion object { const val LOG_KIND: Byte = 0x13 - fun parse(data: String): LOG_TB_STOP_V3 { - val bytes = PumplogUtil.hexStringToByteArray(data) + fun parse(data: String): LogTbStopV3 { + val bytes = PumpLogUtil.hexStringToByteArray(data) val buffer = ByteBuffer.wrap(bytes) buffer.order(ByteOrder.LITTLE_ENDIAN) - return LOG_TB_STOP_V3( + return LogTbStopV3( data, - PumplogUtil.getDttm(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getShort(buffer), - PumplogUtil.getByte(buffer), - PumplogUtil.getDttm(buffer) + PumpLogUtil.getDttm(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getShort(buffer), + PumpLogUtil.getByte(buffer), + PumpLogUtil.getDttm(buffer) ) } } diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/PumplogUtil.java b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/PumpLogUtil.java similarity index 96% rename from pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/PumplogUtil.java rename to pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/PumpLogUtil.java index c458aba743..27ea305112 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/PumplogUtil.java +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/pumplog/PumpLogUtil.java @@ -13,7 +13,8 @@ import java.util.TimeZone; /* * 디아콘 G8 펌프 로그 유틸리티 클래스 */ -public class PumplogUtil { +@SuppressWarnings({"CommentedOutCode", "SpellCheckingInspection"}) +public class PumpLogUtil { /* * 바이트버퍼에서 4바이트 날짜를 구한다. * @param buffer 바이트버퍼 @@ -39,7 +40,7 @@ public class PumplogUtil { */ @SuppressLint("SimpleDateFormat") public static String getDttm(String data) { - byte[] bytes = PumplogUtil.hexStringToByteArray(data); + byte[] bytes = PumpLogUtil.hexStringToByteArray(data); byte b0 = bytes[0]; byte b1 = bytes[1]; byte b2 = bytes[2]; @@ -74,9 +75,11 @@ public class PumplogUtil { * @param buffer 바이트버퍼 * @return int */ + /* public static int getInt(ByteBuffer buffer) { return buffer.getInt(); } + */ /* * 로그데이터에서 로그 타입 바이트를 구한다. @@ -136,12 +139,14 @@ public class PumplogUtil { * @param data 1970.1.1이후 경과한 초 * @return 날짜(GMT기준) */ + /* public static Date pumpTimeToGMTDate(Integer data) { long epochTime = new Date(0).getTime(); // 1970-01-01 long pumpTime = data.longValue() * 1000; // 초를 밀리초 단위로 변환 int timeZoneOffset = TimeZone.getDefault().getRawOffset(); // GMT와 로컬 타임존 사이의 차이 return new Date(epochTime + pumpTime - timeZoneOffset); } + */ /* * 펌프 버전이 해당 버전보다 크거나 같은지 여부 확인(새로운 기능이 추가된 버전을 체크하기 위함) diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt index ca627bb3fd..d412ab138f 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/service/DiaconnG8Service.kt @@ -57,7 +57,7 @@ import info.nightscout.pump.diaconn.packet.TempBasalInquirePacket import info.nightscout.pump.diaconn.packet.TempBasalSettingPacket import info.nightscout.pump.diaconn.packet.TimeInquirePacket import info.nightscout.pump.diaconn.packet.TimeSettingPacket -import info.nightscout.pump.diaconn.pumplog.PumplogUtil +import info.nightscout.pump.diaconn.pumplog.PumpLogUtil import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventAppExit @@ -168,7 +168,7 @@ class DiaconnG8Service : DaggerService() { val pumpFirmwareVersion = sp.getString(rh.gs(R.string.pumpversion), "") - if (pumpFirmwareVersion.isNotEmpty() && PumplogUtil.isPumpVersionGe(pumpFirmwareVersion, 3, 0)) { + if (pumpFirmwareVersion.isNotEmpty() && PumpLogUtil.isPumpVersionGe(pumpFirmwareVersion, 3, 0)) { sendMessage(BigAPSMainInfoInquirePacket(injector)) // APS Pump Main Info } else { sendMessage(BasalLimitInquirePacket(injector)) // basal Limit diff --git a/pump/eopatch/src/main/res/values-ko/strings.xml b/pump/eopatch/src/main/res/values-ko/strings.xml index b6a4b40c9d..a22c51e5b8 100644 --- a/pump/eopatch/src/main/res/values-ko/strings.xml +++ b/pump/eopatch/src/main/res/values-ko/strings.xml @@ -9,7 +9,6 @@ 패치 버저 알림 h:mm a - 볼루스 %1$.2f U의 주입이 완료되었습니다. BLE 상태 일련 번호 로트 번호 diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.kt index 5aa76055f7..defdbf9c45 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.kt @@ -216,10 +216,6 @@ class MedtronicPumpPlugin @Inject constructor( } } - override fun hasService(): Boolean { - return true - } - override fun onStartScheduledPumpActions() { // check status every minute (if any status needs refresh we send readStatus command) diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryResult.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryResult.kt index d19e53b43d..b53cb342e4 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryResult.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryResult.kt @@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump import info.nightscout.core.utils.DateTimeUtil import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag -import java.util.Collections /** * History page contains data, sorted from newest to oldest (0=newest..n=oldest) @@ -18,19 +17,19 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis private val searchEntry: PumpHistoryEntry? = null private var searchDate: Long? = null private var searchType = SearchType.None - var unprocessedEntries: List = ArrayList() + var unprocessedEntries: MutableList = ArrayList() var validEntries: MutableList = ArrayList() - fun addHistoryEntries(entries: List /*, page: Int*/) { + fun addHistoryEntries(entries: MutableList /*, page: Int*/) { unprocessedEntries = entries //aapsLogger.debug(LTag.PUMPCOMM,"PumpHistoryResult. Unprocessed entries: {}", MedtronicUtil.getGsonInstance().toJson(entries)); processEntries() } // TODO Bug #145 need to check if we had timeChange that went -1, that situation needs to be evaluated separately - fun processEntries() { + private fun processEntries() { var olderEntries = 0 - Collections.reverse(unprocessedEntries) + unprocessedEntries.reverse() when (searchType) { SearchType.None -> //aapsLogger.debug(LTag.PUMPCOMM,"PE. None search"); validEntries.addAll(unprocessedEntries) @@ -42,7 +41,7 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis aapsLogger.debug(LTag.PUMPCOMM, "PE. PumpHistoryResult. Search entry date: " + searchEntry!!.atechDateTime) //val date = searchEntry.atechDateTime for (unprocessedEntry in unprocessedEntries) { - if (unprocessedEntry.equals(searchEntry)) { + if (unprocessedEntry == searchEntry) { //aapsLogger.debug(LTag.PUMPCOMM,"PE. Item found {}.", unprocessedEntry); isSearchFinished = true break @@ -56,7 +55,7 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis } SearchType.Date -> { - aapsLogger.debug(LTag.PUMPCOMM, "PE. Date search: Search date: " + searchDate) + aapsLogger.debug(LTag.PUMPCOMM, "PE. Date search: Search date: $searchDate") for (unprocessedEntry in unprocessedEntries) { if (unprocessedEntry.atechDateTime == 0L) { aapsLogger.debug(LTag.PUMPCOMM, "PE. PumpHistoryResult. Search entry date: Entry with no date: $unprocessedEntry") diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.kt index 34fe0eafa5..2e53e74990 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.pump.medtronic.util +import com.google.gson.Gson import com.google.gson.GsonBuilder import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil @@ -18,13 +19,13 @@ import info.nightscout.rx.events.EventDismissNotification import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper -import org.joda.time.LocalTime import java.nio.ByteBuffer import java.nio.ByteOrder import java.util.Locale import javax.inject.Inject import javax.inject.Singleton import kotlin.experimental.or +import kotlin.math.abs /** * Created by andy on 5/9/18. @@ -38,39 +39,41 @@ class MedtronicUtil @Inject constructor( private val uiInteraction: UiInteraction ) { + @Suppress("PrivatePropertyName") private val ENVELOPE_SIZE = 4 // 0xA7 S1 S2 S3 CMD PARAM_COUNT [PARAMS] //private MedtronicDeviceType medtronicPumpModel; private var currentCommand: MedtronicCommandType? = null var settings: Map? = null + @Suppress("PrivatePropertyName") private val BIG_FRAME_LENGTH = 65 - private val doneBit = 1 shl 7 + //private val doneBit = 1 shl 7 var pumpTime: ClockDTO? = null - var gsonInstance = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create() + var gsonInstance: Gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create() - fun getTimeFrom30MinInterval(interval: Int): LocalTime { - return if (interval % 2 == 0) { - LocalTime(interval / 2, 0) - } else { - LocalTime((interval - 1) / 2, 30) - } - } + // fun getTimeFrom30MinInterval(interval: Int): LocalTime { + // return if (interval % 2 == 0) { + // LocalTime(interval / 2, 0) + // } else { + // LocalTime((interval - 1) / 2, 30) + // } + // } - fun decodeBasalInsulin(i: Int, j: Int): Double { - return decodeBasalInsulin(makeUnsignedShort(i, j)) - } + // fun decodeBasalInsulin(i: Int, j: Int): Double { + // return decodeBasalInsulin(makeUnsignedShort(i, j)) + // } - fun decodeBasalInsulin(i: Int): Double { - return i.toDouble() / 40.0 - } + // fun decodeBasalInsulin(i: Int): Double { + // return i.toDouble() / 40.0 + // } - fun getBasalStrokes(amount: Double): ByteArray { - return getBasalStrokes(amount, false) - } + // fun getBasalStrokes(amount: Double): ByteArray { + // return getBasalStrokes(amount, false) + // } - fun getBasalStrokesInt(amount: Double): Int { - return getStrokesInt(amount, 40) - } + // fun getBasalStrokesInt(amount: Double): Int { + // return getStrokesInt(amount, 40) + // } fun getBolusStrokes(amount: Double): ByteArray { val strokesPerUnit = medtronicPumpStatus.medtronicDeviceType.bolusStrokes @@ -89,17 +92,17 @@ class MedtronicUtil @Inject constructor( return ByteUtil.fromHexString(String.format("%02x%0" + 2 * length + "x", length, strokes)) } - fun createCommandBody(input: ByteArray): ByteArray { - return ByteUtil.concat(input.size.toByte(), input) - } + // fun createCommandBody(input: ByteArray): ByteArray { + // return ByteUtil.concat(input.size.toByte(), input) + // } - fun sendNotification(notificationType: MedtronicNotificationType, rh: ResourceHelper) { - uiInteraction.addNotification( - notificationType.notificationType, - rh.gs(notificationType.resourceId), - notificationType.notificationUrgency - ) - } + // fun sendNotification(notificationType: MedtronicNotificationType, rh: ResourceHelper) { + // uiInteraction.addNotification( + // notificationType.notificationType, + // rh.gs(notificationType.resourceId), + // notificationType.notificationUrgency + // ) + // } fun sendNotification(notificationType: MedtronicNotificationType, rh: ResourceHelper, vararg parameters: Any?) { uiInteraction.addNotification( @@ -117,7 +120,7 @@ class MedtronicUtil @Inject constructor( return buildCommandPayload(rileyLinkServiceData, commandType.commandCode, parameters) } - fun buildCommandPayload(rileyLinkServiceData: RileyLinkServiceData, commandType: Byte, parameters: ByteArray?): ByteArray { + private fun buildCommandPayload(rileyLinkServiceData: RileyLinkServiceData, commandType: Byte, parameters: ByteArray?): ByteArray { // A7 31 65 51 C0 00 52 val commandLength = (if (parameters == null) 2 else 2 + parameters.size).toByte() val sendPayloadBuffer = ByteBuffer.allocate(ENVELOPE_SIZE + commandLength) // + CRC_SIZE @@ -283,12 +286,13 @@ class MedtronicUtil @Inject constructor( return getStrokes(amount, 40, returnFixedSize) } - fun getStrokes(amount: Double, strokesPerUnit: Int, returnFixedSize: Boolean): ByteArray { + @Suppress("SameParameterValue") + private fun getStrokes(amount: Double, strokesPerUnit: Int, returnFixedSize: Boolean): ByteArray { val strokes = getStrokesInt(amount, strokesPerUnit) return getByteArrayFromUnsignedShort(strokes, returnFixedSize) } - fun getStrokesInt(amount: Double, strokesPerUnit: Int): Int { + private fun getStrokesInt(amount: Double, strokesPerUnit: Int): Int { //var length = 1 var scrollRate = 1 if (strokesPerUnit >= 40) { @@ -304,7 +308,7 @@ class MedtronicUtil @Inject constructor( fun isSame(d1: Double, d2: Double): Boolean { val diff = d1 - d2 - return Math.abs(diff) <= 0.000001 + return abs(diff) <= 0.000001 } } diff --git a/pump/medtronic/src/main/res/values-af-rZA/strings.xml b/pump/medtronic/src/main/res/values-af-rZA/strings.xml index 88bff175b8..01d2cbc61d 100644 --- a/pump/medtronic/src/main/res/values-af-rZA/strings.xml +++ b/pump/medtronic/src/main/res/values-af-rZA/strings.xml @@ -35,7 +35,7 @@ Basale profiel is verkeerd op pomp (moet STD wees). Verkeerde TBR op pomp (Moet Absoluut wees). Verkeerde Maks Bolus gestel op Pomp(moet %1$.2f wees). - Verkeerde Maks Basale op Pomp (moet %1$.2f %1$.2f wees),. + Verkeerde Maks Basale op Pomp (moet %1$.2f wees). Operasie nie moontlik.\n\n Jy moet jou Medtronic pomp opstel voordat jy die operasie kan gebruik. Oor 24h Tyd was versoek. diff --git a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Milenage.kt b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Milenage.kt index c06c5a3410..15e6477d15 100644 --- a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Milenage.kt +++ b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Milenage.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session +import android.annotation.SuppressLint import info.nightscout.core.utils.toHex import info.nightscout.interfaces.Config import info.nightscout.rx.logging.AAPSLogger @@ -10,8 +11,8 @@ import javax.crypto.Cipher import javax.crypto.spec.SecretKeySpec class Milenage( - private val aapsLogger: AAPSLogger, - private val config: Config, + aapsLogger: AAPSLogger, + config: Config, private val k: ByteArray, val sqn: ByteArray, randParam: ByteArray? = null, @@ -30,6 +31,7 @@ class Milenage( } private val secretKeySpec = SecretKeySpec(k, "AES") + @SuppressLint("GetInstance") private val cipher: Cipher = Cipher.getInstance("AES/ECB/NoPadding") init { @@ -123,9 +125,10 @@ class Milenage( } } + @Suppress("SpellCheckingInspection") companion object { - val RESYNC_AMF = Hex.decode("0000") + val RESYNC_AMF: ByteArray = Hex.decode("0000") private val MILENAGE_OP = Hex.decode("cdc202d5123e20f62b6d676ac72cb318") private val MILENAGE_AMF = Hex.decode("b9b9") const val KEY_SIZE = 16 diff --git a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt index b28bbc8036..9eef681ae6 100644 --- a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt +++ b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt @@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state import android.os.SystemClock import com.google.gson.Gson -import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.androidaps.plugins.pump.omnipod.dash.EventOmnipodDashPumpValuesChanged import info.nightscout.androidaps.plugins.pump.omnipod.dash.R import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.Id @@ -20,6 +19,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response. import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.DefaultStatusResponse import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.SetUniqueIdResponse import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.VersionResponse +import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.interfaces.utils.Round import info.nightscout.rx.bus.RxBus import info.nightscout.rx.logging.AAPSLogger @@ -437,7 +437,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( } @Synchronized - override fun updateActiveCommand() = Maybe.create { source -> + override fun updateActiveCommand(): Maybe = Maybe.create { source -> val activeCommand = podState.activeCommand if (activeCommand == null) { logger.error(LTag.PUMPCOMM, "No active command to update") @@ -515,6 +515,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( "lastResponse=$lastStatusResponseReceived " + "$sequenceNumberOfLastProgrammingCommand $historyId" ) + @Suppress("KotlinConstantConditions") when { createdRealtime <= podState.lastStatusResponseReceived && sequence == podState.sequenceNumberOfLastProgrammingCommand -> diff --git a/pump/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/extensions/PumpStateExtension.kt b/pump/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/extensions/PumpStateExtension.kt index a12532c9de..001440a4f4 100644 --- a/pump/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/extensions/PumpStateExtension.kt +++ b/pump/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/extensions/PumpStateExtension.kt @@ -1,4 +1,4 @@ -package info.nightscout.core.pump +package info.nightscout.androidaps.plugins.pump.omnipod.eros.extensions import info.nightscout.interfaces.pump.PumpSync import kotlin.math.ceil diff --git a/pump/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/manager/AapsOmnipodErosManager.java b/pump/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/manager/AapsOmnipodErosManager.java index 8c1584c2c9..8af0a35161 100644 --- a/pump/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/manager/AapsOmnipodErosManager.java +++ b/pump/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/manager/AapsOmnipodErosManager.java @@ -56,12 +56,12 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.manager.ErosP import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.manager.OmnipodManager; import info.nightscout.androidaps.plugins.pump.omnipod.eros.event.EventOmnipodErosPumpValuesChanged; import info.nightscout.androidaps.plugins.pump.omnipod.eros.extensions.DetailedBolusInfoExtensionKt; +import info.nightscout.androidaps.plugins.pump.omnipod.eros.extensions.PumpStateExtensionKt; import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.ErosHistory; import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryRecordEntity; import info.nightscout.androidaps.plugins.pump.omnipod.eros.rileylink.manager.OmnipodRileyLinkCommunicationManager; import info.nightscout.androidaps.plugins.pump.omnipod.eros.util.AapsOmnipodUtil; import info.nightscout.androidaps.plugins.pump.omnipod.eros.util.OmnipodAlertUtil; -import info.nightscout.core.pump.PumpStateExtensionKt; import info.nightscout.interfaces.notifications.Notification; import info.nightscout.interfaces.profile.Profile; import info.nightscout.interfaces.pump.DetailedBolusInfo; diff --git a/pump/pump-common/src/main/java/info/nightscout/pump/common/PumpPluginAbstract.kt b/pump/pump-common/src/main/java/info/nightscout/pump/common/PumpPluginAbstract.kt index 22a21e56df..25b3957678 100644 --- a/pump/pump-common/src/main/java/info/nightscout/pump/common/PumpPluginAbstract.kt +++ b/pump/pump-common/src/main/java/info/nightscout/pump/common/PumpPluginAbstract.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.content.ServiceConnection import android.text.format.DateFormat +import com.google.gson.Gson import com.google.gson.GsonBuilder import dagger.android.HasAndroidInjector import info.nightscout.core.utils.fabric.FabricPrivacy @@ -26,6 +27,7 @@ import info.nightscout.interfaces.utils.DecimalFormatter.to2Decimal import info.nightscout.pump.common.data.PumpStatus import info.nightscout.pump.common.defs.PumpDriverState import info.nightscout.pump.common.sync.PumpDbEntryCarbs +import info.nightscout.pump.common.sync.PumpSyncEntriesCreator import info.nightscout.pump.common.sync.PumpSyncStorage import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus @@ -61,7 +63,7 @@ abstract class PumpPluginAbstract protected constructor( var aapsSchedulers: AapsSchedulers, var pumpSync: PumpSync, var pumpSyncStorage: PumpSyncStorage -) : PumpPluginBase(pluginDescription, injector, aapsLogger, rh, commandQueue), Pump, Constraints, info.nightscout.pump.common.sync.PumpSyncEntriesCreator { +) : PumpPluginBase(pluginDescription, injector, aapsLogger, rh, commandQueue), Pump, Constraints, PumpSyncEntriesCreator { protected val disposable = CompositeDisposable() @@ -80,24 +82,21 @@ abstract class PumpPluginAbstract protected constructor( pumpDescription.fillFor(value) } - protected var gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create() + protected var gson: Gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create() abstract fun initPumpStatusData() - open fun hasService(): Boolean { - return true - } - override fun onStart() { super.onStart() initPumpStatusData() - if (hasService()) { + serviceConnection?.let { serviceConnection -> val intent = Intent(context, serviceClass) - context.bindService(intent, serviceConnection!!, Context.BIND_AUTO_CREATE) - disposable.add(rxBus - .toObservable(EventAppExit::class.java) - .observeOn(aapsSchedulers.io) - .subscribe({ _ -> context.unbindService(serviceConnection!!) }) { throwable: Throwable? -> fabricPrivacy.logException(throwable!!) } + context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE) + disposable.add( + rxBus + .toObservable(EventAppExit::class.java) + .observeOn(aapsSchedulers.io) + .subscribe({ context.unbindService(serviceConnection) }, fabricPrivacy::logException) ) } serviceRunning = true @@ -106,8 +105,8 @@ abstract class PumpPluginAbstract protected constructor( override fun onStop() { aapsLogger.debug(LTag.PUMP, model().model + " onStop()") - if (hasService()) { - context.unbindService(serviceConnection!!) + serviceConnection?.let { serviceConnection -> + context.unbindService(serviceConnection) } serviceRunning = false disposable.clear() @@ -334,7 +333,7 @@ abstract class PumpPluginAbstract protected constructor( rxBus.send(EventCustomActionsChanged()) } - override fun manufacturer(): ManufacturerType = pumpType.manufacturer!! + override fun manufacturer(): ManufacturerType = pumpType.manufacturer ?: ManufacturerType.AAPS override fun model(): PumpType = pumpType override fun canHandleDST(): Boolean = false diff --git a/pump/pump-common/src/main/java/info/nightscout/pump/common/sync/PumpSyncStorage.kt b/pump/pump-common/src/main/java/info/nightscout/pump/common/sync/PumpSyncStorage.kt index 1de834263e..548fad8665 100644 --- a/pump/pump-common/src/main/java/info/nightscout/pump/common/sync/PumpSyncStorage.kt +++ b/pump/pump-common/src/main/java/info/nightscout/pump/common/sync/PumpSyncStorage.kt @@ -66,8 +66,11 @@ class PumpSyncStorage @Inject constructor( if (jsonData.isNotBlank()) { @Suppress("UNCHECKED_CAST") - pumpSyncStorageTBR = xstream.fromXML(jsonData, MutableList::class.java) as - MutableList + pumpSyncStorageTBR = try { + xstream.fromXML(jsonData, MutableList::class.java) as MutableList + } catch (e: Exception) { + mutableListOf() + } aapsLogger.debug(LTag.PUMP, "Loading Pump Sync Storage: tbrs=${pumpSyncStorageTBR.size}.") aapsLogger.debug(LTag.PUMP, "DD: PumpSyncStorageTBR=$pumpSyncStorageTBR") diff --git a/pump/pump-common/src/main/res/values-fr-rFR/strings.xml b/pump/pump-common/src/main/res/values-fr-rFR/strings.xml index fbb5a624e1..2083618893 100644 --- a/pump/pump-common/src/main/res/values-fr-rFR/strings.xml +++ b/pump/pump-common/src/main/res/values-fr-rFR/strings.xml @@ -5,6 +5,7 @@ Opération PAS ENCORE supportée par la pompe. OK Numéro de série de la pompe + %1$.2f U / %2$.2f U délivrés Non initialisé Initialisé diff --git a/pump/pump-core/src/main/res/values-fr-rFR/strings.xml b/pump/pump-core/src/main/res/values-fr-rFR/strings.xml index cef1881d71..452f916a90 100644 --- a/pump/pump-core/src/main/res/values-fr-rFR/strings.xml +++ b/pump/pump-core/src/main/res/values-fr-rFR/strings.xml @@ -1,6 +1,7 @@ + Jamais contacté En veille Réveil en cours Actif diff --git a/pump/virtual/src/main/res/values-es-rES/strings.xml b/pump/virtual/src/main/res/values-es-rES/strings.xml index e4a2c05fd9..0d7016149a 100644 --- a/pump/virtual/src/main/res/values-es-rES/strings.xml +++ b/pump/virtual/src/main/res/values-es-rES/strings.xml @@ -1,6 +1,7 @@ + Bomba virtual Definición de la bomba Bolo: Paso =%1$s\nBolo Extendido: [paso =%2$s, Duración =%3$smin -%4$sh] \nBasal: Paso =%5$s\nTBR: %6$s ( %7$s), Duración =%8$sMin -%9$sh\n%10$s BOMBAV diff --git a/pump/virtual/src/main/res/values-fr-rFR/strings.xml b/pump/virtual/src/main/res/values-fr-rFR/strings.xml index a4d939ede6..0d1d572148 100644 --- a/pump/virtual/src/main/res/values-fr-rFR/strings.xml +++ b/pump/virtual/src/main/res/values-fr-rFR/strings.xml @@ -1,6 +1,7 @@ + Type de pompe virtuelle Définition de pompe Bolus : Étape =%1$s\nExtended Bolus : [Étape =%2$s, Durée =%3$smin -%4$sh]\nBasal : Étape =%5$s\nTBR : %6$s (par %7$s), Durée =%8$smin -%9$sh\n%10$s POMPEV diff --git a/pump/virtual/src/main/res/values-ru-rRU/strings.xml b/pump/virtual/src/main/res/values-ru-rRU/strings.xml index 2a771d664b..988e7c4de3 100644 --- a/pump/virtual/src/main/res/values-ru-rRU/strings.xml +++ b/pump/virtual/src/main/res/values-ru-rRU/strings.xml @@ -1,6 +1,11 @@ + Тип виртуальной помпы + Определение помпы + Болюс: Шаг =%1$s\n Пролонгированный Болюс: [Шаг =%2$s, Продолжительность =%3$sмин -%4$sh] \nБазал: Шаг =%5$s\n ВБС: %6$s (на %7$s), Продолжительность =%8$sмин -%9$sh\n%10$s + ВиртПомпа Интеграция с помпами, еще не имеющими драйвера (незамкнутый цикл) + ВИРТУАЛЬНАЯ ПОМПА настройки вирт помпы diff --git a/workflow/src/main/java/info/nightscout/workflow/iob/CarbsInPastExtension.kt b/workflow/src/main/java/info/nightscout/workflow/iob/CarbsInPastExtension.kt index 23e7a93780..d675ffa3a0 100644 --- a/workflow/src/main/java/info/nightscout/workflow/iob/CarbsInPastExtension.kt +++ b/workflow/src/main/java/info/nightscout/workflow/iob/CarbsInPastExtension.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.iob.iobCobCalculator +package info.nightscout.workflow.iob import info.nightscout.database.entities.Carbs import info.nightscout.interfaces.Constants diff --git a/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOref1Worker.kt b/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOref1Worker.kt index 95657f8da3..9ce169cf21 100644 --- a/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOref1Worker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOref1Worker.kt @@ -23,7 +23,6 @@ import info.nightscout.interfaces.profile.Instantiator import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.profiling.Profiler import info.nightscout.interfaces.utils.DecimalFormatter -import info.nightscout.plugins.iob.iobCobCalculator.fromCarbs import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.Event import info.nightscout.rx.events.EventAutosensCalculationFinished diff --git a/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOrefWorker.kt b/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOrefWorker.kt index 39b02048fe..538c179fe0 100644 --- a/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOrefWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOrefWorker.kt @@ -21,7 +21,6 @@ import info.nightscout.interfaces.profile.Instantiator import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.profiling.Profiler import info.nightscout.interfaces.utils.DecimalFormatter -import info.nightscout.plugins.iob.iobCobCalculator.fromCarbs import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.Event import info.nightscout.rx.events.EventAutosensCalculationFinished