Medtrum: Lints
This commit is contained in:
parent
5074195315
commit
ae5c4ddeeb
4 changed files with 271 additions and 263 deletions
|
@ -255,7 +255,11 @@ import kotlin.math.abs
|
|||
|
||||
override fun isConnected(): Boolean {
|
||||
// This is a workaround to prevent AAPS to trigger connects when we have no patch activated
|
||||
return if (!isInitialized()) true else medtrumService?.isConnected ?: false
|
||||
return if (!isInitialized()) {
|
||||
true
|
||||
} else {
|
||||
medtrumService?.isConnected ?: false
|
||||
}
|
||||
}
|
||||
|
||||
override fun isConnecting(): Boolean = medtrumService?.isConnecting ?: false
|
||||
|
@ -544,31 +548,19 @@ import kotlin.math.abs
|
|||
|
||||
// Medtrum interface
|
||||
override fun loadEvents(): PumpEnactResult {
|
||||
if (!isInitialized()) {
|
||||
val result = PumpEnactResult(injector).success(false)
|
||||
result.comment = "pump not initialized"
|
||||
return result
|
||||
}
|
||||
if (!isInitialized()) return PumpEnactResult(injector).success(false).enacted(false)
|
||||
val connectionOK = medtrumService?.loadEvents() ?: false
|
||||
return PumpEnactResult(injector).success(connectionOK)
|
||||
}
|
||||
|
||||
override fun setUserOptions(): PumpEnactResult {
|
||||
if (!isInitialized()) {
|
||||
val result = PumpEnactResult(injector).success(false)
|
||||
result.comment = "pump not initialized"
|
||||
return result
|
||||
}
|
||||
if (!isInitialized()) return PumpEnactResult(injector).success(false).enacted(false)
|
||||
val connectionOK = medtrumService?.setUserSettings() ?: false
|
||||
return PumpEnactResult(injector).success(connectionOK)
|
||||
}
|
||||
|
||||
override fun clearAlarms(): PumpEnactResult {
|
||||
if (!isInitialized()) {
|
||||
val result = PumpEnactResult(injector).success(false)
|
||||
result.comment = "pump not initialized"
|
||||
return result
|
||||
}
|
||||
if (!isInitialized()) return PumpEnactResult(injector).success(false).enacted(false)
|
||||
val connectionOK = medtrumService?.clearAlarms() ?: false
|
||||
return PumpEnactResult(injector).success(connectionOK)
|
||||
}
|
||||
|
@ -579,11 +571,7 @@ import kotlin.math.abs
|
|||
}
|
||||
|
||||
override fun updateTime(): PumpEnactResult {
|
||||
if (!isInitialized()) {
|
||||
val result = PumpEnactResult(injector).success(false)
|
||||
result.comment = "pump not initialized"
|
||||
return result
|
||||
}
|
||||
if (!isInitialized()) return PumpEnactResult(injector).success(false).enacted(false)
|
||||
val connectionOK = medtrumService?.updateTimeIfNeeded() ?: false
|
||||
return PumpEnactResult(injector).success(connectionOK)
|
||||
}
|
||||
|
|
|
@ -421,7 +421,7 @@ class MedtrumPump @Inject constructor(
|
|||
)
|
||||
aapsLogger.debug(
|
||||
LTag.PUMPCOMM,
|
||||
"handleBasalStatusUpdate: ${if (newRecord) "**NEW** " else ""}EVENT TEMP_START ($basalType) ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) " + "Rate: $basalRate Duration: ${duration} temporaryBasalInfo: $temporaryBasalInfo, expectedTemporaryBasal: $expectedTemporaryBasal"
|
||||
"handleBasalStatusUpdate: ${newRecordInfo(newRecord)}EVENT TEMP_START ($basalType) ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) " + "Rate: $basalRate Duration: ${duration} temporaryBasalInfo: $temporaryBasalInfo, expectedTemporaryBasal: $expectedTemporaryBasal"
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -438,7 +438,7 @@ class MedtrumPump @Inject constructor(
|
|||
)
|
||||
aapsLogger.debug(
|
||||
LTag.PUMPCOMM,
|
||||
"handleBasalStatusUpdate: ${if (newRecord) "**NEW** " else ""}EVENT TEMP_START ($basalType) ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) expectedTemporaryBasal: $expectedTemporaryBasal"
|
||||
"handleBasalStatusUpdate: ${newRecordInfo(newRecord)}EVENT TEMP_START ($basalType) ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) expectedTemporaryBasal: $expectedTemporaryBasal"
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -507,7 +507,7 @@ class MedtrumPump @Inject constructor(
|
|||
)
|
||||
aapsLogger.debug(
|
||||
LTag.PUMPCOMM,
|
||||
"handleBasalStatusUpdate: ${if (newRecord) "**NEW** " else ""}EVENT TEMP_START (FAKE)"
|
||||
"handleBasalStatusUpdate: ${newRecordInfo(newRecord)}EVENT TEMP_START (FAKE)"
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -597,4 +597,8 @@ class MedtrumPump @Inject constructor(
|
|||
.let { EnumSet.copyOf(it) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun newRecordInfo(newRecord: Boolean): String {
|
||||
return "${if (newRecord) "**NEW** " else ""}"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,57 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
|||
if (recordHeader == VALID_HEADER) {
|
||||
when (recordType) {
|
||||
BOLUS_RECORD, BOLUS_RECORD_ALT -> {
|
||||
handleBolusRecord(data)
|
||||
}
|
||||
|
||||
BASAL_RECORD, BASAL_RECORD_ALT -> {
|
||||
handleBasalRecord(data)
|
||||
}
|
||||
|
||||
ALARM_RECORD -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: ALARM_RECORD")
|
||||
}
|
||||
|
||||
AUTO_RECORD -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: AUTO_RECORD")
|
||||
}
|
||||
|
||||
TIME_SYNC_RECORD -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: TIME_SYNC_RECORD")
|
||||
}
|
||||
|
||||
AUTO1_RECORD -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: AUTO1_RECORD")
|
||||
}
|
||||
|
||||
AUTO2_RECORD -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: AUTO2_RECORD")
|
||||
}
|
||||
|
||||
AUTO3_RECORD -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: AUTO3_RECORD")
|
||||
}
|
||||
|
||||
TDD_RECORD -> {
|
||||
handleTddRecord(data)
|
||||
}
|
||||
|
||||
else -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: Unknown record type: $recordType")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
aapsLogger.error(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: Invalid record header")
|
||||
}
|
||||
|
||||
// Update sequence number
|
||||
medtrumPump.syncedSequenceNumber = recordSequence // Assume sync upwards
|
||||
}
|
||||
|
||||
return success
|
||||
}
|
||||
|
||||
private fun handleBolusRecord(data: ByteArray) {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: BOLUS_RECORD")
|
||||
val typeAndWizard = data.copyOfRange(RESP_RECORD_DATA_START, RESP_RECORD_DATA_START + 1).toInt()
|
||||
val bolusCause = data.copyOfRange(RESP_RECORD_DATA_START + 1, RESP_RECORD_DATA_START + 2).toInt()
|
||||
|
@ -143,7 +194,7 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
|||
|
||||
aapsLogger.debug(
|
||||
LTag.PUMPCOMM,
|
||||
"from record: ${if (newRecord) "**NEW** " else ""}EVENT BOLUS ${dateUtil.dateAndTimeString(bolusStartTime)} ($bolusStartTime) Bolus: ${bolusNormalDelivered}U "
|
||||
"from record: ${newRecordInfo(newRecord)}EVENT BOLUS ${dateUtil.dateAndTimeString(bolusStartTime)} ($bolusStartTime) Bolus: ${bolusNormalDelivered}U "
|
||||
)
|
||||
if (bolusStartTime > medtrumPump.lastBolusTime) {
|
||||
medtrumPump.lastBolusTime = bolusStartTime
|
||||
|
@ -163,7 +214,7 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
|||
)
|
||||
aapsLogger.debug(
|
||||
LTag.PUMPCOMM,
|
||||
"from record: ${if (newRecord) "**NEW** " else ""}EVENT EXTENDED BOLUS ${dateUtil.dateAndTimeString(bolusStartTime)} ($bolusStartTime) Bolus: ${bolusNormalDelivered}U "
|
||||
"from record: ${newRecordInfo(newRecord)}EVENT EXTENDED BOLUS ${dateUtil.dateAndTimeString(bolusStartTime)} ($bolusStartTime) Bolus: ${bolusNormalDelivered}U "
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -189,7 +240,7 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
|||
)
|
||||
aapsLogger.error(
|
||||
LTag.PUMPCOMM,
|
||||
"from record: ${if (newRecord) "**NEW** " else ""}EVENT COMBI BOLUS ${dateUtil.dateAndTimeString(bolusStartTime)} ($bolusStartTime) Bolus: ${bolusNormalDelivered}U Extended: ${bolusExtendedDelivered} THIS SHOULD NOT HAPPEN!!!"
|
||||
"from record: ${newRecordInfo(newRecord)}EVENT COMBI BOLUS ${dateUtil.dateAndTimeString(bolusStartTime)} ($bolusStartTime) Bolus: ${bolusNormalDelivered}U Extended: ${bolusExtendedDelivered} THIS SHOULD NOT HAPPEN!!!"
|
||||
)
|
||||
if (!newRecord && detailedBolusInfo != null) {
|
||||
// detailedInfo can be from another similar record. Reinsert
|
||||
|
@ -205,11 +256,14 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
|||
aapsLogger.error(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: BOLUS_RECORD: Unknown bolus type: $bolusType")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BASAL_RECORD, BASAL_RECORD_ALT -> {
|
||||
private fun handleBasalRecord(data: ByteArray) {
|
||||
val medtrumTimeUtil = MedtrumTimeUtil()
|
||||
|
||||
val recordPatchId = data.copyOfRange(RESP_RECORD_PATCH_ID_START, RESP_RECORD_PATCH_ID_END).toLong()
|
||||
val recordSequence = data.copyOfRange(RESP_RECORD_SEQUENCE_START, RESP_RECORD_SEQUENCE_END).toInt()
|
||||
|
||||
val basalStartTime = medtrumTimeUtil.convertPumpTimeToSystemTimeMillis(data.copyOfRange(RESP_RECORD_DATA_START, RESP_RECORD_DATA_START + 4).toLong())
|
||||
val basalEndTime = medtrumTimeUtil.convertPumpTimeToSystemTimeMillis(data.copyOfRange(RESP_RECORD_DATA_START + 4, RESP_RECORD_DATA_START + 8).toLong())
|
||||
val basalType = enumValues<BasalType>()[data.copyOfRange(RESP_RECORD_DATA_START + 8, RESP_RECORD_DATA_START + 9).toInt()]
|
||||
|
@ -248,7 +302,7 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
|||
)
|
||||
aapsLogger.debug(
|
||||
LTag.PUMPCOMM,
|
||||
"handleBasalStatusUpdate from record: ${if (newRecord) "**NEW** " else ""}EVENT TEMP_SYNC: ($basalType) ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) " +
|
||||
"handleBasalStatusUpdate from record: ${newRecordInfo(newRecord)}EVENT TEMP_SYNC: ($basalType) ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) " +
|
||||
"Rate: $basalRate Duration: ${duration}"
|
||||
)
|
||||
}
|
||||
|
@ -269,7 +323,7 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
|||
)
|
||||
aapsLogger.debug(
|
||||
LTag.PUMPCOMM,
|
||||
"handleBasalStatusUpdate from record: ${if (newRecord) "**NEW** " else ""}EVENT SUSPEND: ($basalType) ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) " +
|
||||
"handleBasalStatusUpdate from record: ${newRecordInfo(newRecord)}EVENT SUSPEND: ($basalType) ${dateUtil.dateAndTimeString(basalStartTime)} ($basalStartTime) " +
|
||||
"Rate: $basalRate Duration: ${duration}"
|
||||
)
|
||||
}
|
||||
|
@ -287,31 +341,7 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
|||
}
|
||||
}
|
||||
|
||||
ALARM_RECORD -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: ALARM_RECORD")
|
||||
}
|
||||
|
||||
AUTO_RECORD -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: AUTO_RECORD")
|
||||
}
|
||||
|
||||
TIME_SYNC_RECORD -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: TIME_SYNC_RECORD")
|
||||
}
|
||||
|
||||
AUTO1_RECORD -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: AUTO1_RECORD")
|
||||
}
|
||||
|
||||
AUTO2_RECORD -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: AUTO2_RECORD")
|
||||
}
|
||||
|
||||
AUTO3_RECORD -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: AUTO3_RECORD")
|
||||
}
|
||||
|
||||
TDD_RECORD -> {
|
||||
private fun handleTddRecord(data: ByteArray) {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: TDD_RECORD")
|
||||
val timestamp = MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(data.copyOfRange(RESP_RECORD_DATA_START, RESP_RECORD_DATA_START + 4).toLong())
|
||||
val timeZoneOffset = data.copyOfRange(RESP_RECORD_DATA_START + 4, RESP_RECORD_DATA_START + 6).toInt()
|
||||
|
@ -349,25 +379,12 @@ class GetRecordPacket(injector: HasAndroidInjector, private val recordIndex: Int
|
|||
|
||||
aapsLogger.debug(
|
||||
LTag.PUMPCOMM,
|
||||
"handleBasalStatusUpdate from record: ${if (newRecord) "**NEW** " else ""}EVENT TDD: ${dateUtil.dateAndTimeString(timestamp)} ($timestamp) " +
|
||||
"handleBasalStatusUpdate from record: ${newRecordInfo(newRecord)}EVENT TDD: ${dateUtil.dateAndTimeString(timestamp)} ($timestamp) " +
|
||||
"TDD: $tdd, BasalTDD: $basalTdd, BolusTDD: ${tdd - basalTdd}"
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
else -> {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: Unknown record type: $recordType")
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
aapsLogger.error(LTag.PUMPCOMM, "GetRecordPacket HandleResponse: Invalid record header")
|
||||
}
|
||||
|
||||
// Update sequence number
|
||||
medtrumPump.syncedSequenceNumber = recordSequence // Assume sync upwards
|
||||
}
|
||||
|
||||
return success
|
||||
private fun newRecordInfo(newRecord: Boolean): String {
|
||||
return "${if (newRecord) "**NEW** " else ""}"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,7 +109,6 @@ class NotificationPacket(val injector: HasAndroidInjector) {
|
|||
|
||||
if (fieldMask and MASK_EXTENDED_BOLUS != 0) {
|
||||
aapsLogger.error(LTag.PUMPCOMM, "Extended bolus notification received, extended bolus not supported!")
|
||||
// TODO Handle error and stop pump if this happens?
|
||||
offset += 3
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue