Verify RSv1 password

This commit is contained in:
Milos Kozak 2020-05-02 00:17:39 +02:00
parent 25cc09ec26
commit bce3d3b6b9
8 changed files with 76 additions and 59 deletions

View file

@ -67,7 +67,8 @@ import javax.inject.Singleton
PreferencesModule::class,
OverviewModule::class,
DataClassesModule::class,
SMSModule::class
SMSModule::class,
DanaRSCommModule::class
]
)
interface AppComponent : AndroidInjector<MainApp> {

View file

@ -74,7 +74,7 @@ import info.nightscout.androidaps.utils.wizard.BolusWizard
import info.nightscout.androidaps.utils.wizard.QuickWizardEntry
import javax.inject.Singleton
@Module(includes = [AppModule.AppBindings::class, PluginsModule::class, DanaRSCommModule::class])
@Module(includes = [AppModule.AppBindings::class, PluginsModule::class])
open class AppModule {
@Provides

View file

@ -119,6 +119,7 @@ class DanaRPump @Inject constructor(
// DanaRS specific
var rsPassword = ""
var v3RSPump = false;
// User settings
var timeDisplayType = 0
@ -219,7 +220,10 @@ class DanaRPump @Inject constructor(
}
val isPasswordOK: Boolean
get() = !(password != -1 && password != sp.getInt(R.string.key_danar_password, -1))
get() = password == sp.getInt(R.string.key_danar_password, -2)
val isRSPasswordOK: Boolean
get() = rsPassword.equals(sp.getString(R.string.key_danars_password, ""), ignoreCase = true)
fun reset() {
aapsLogger.debug(LTag.PUMP, "DanaRPump reset")

View file

@ -81,7 +81,15 @@ class DanaRSPlugin @Inject constructor(
override fun updatePreferenceSummary(pref: Preference) {
super.updatePreferenceSummary(pref)
if (pref.key == resourceHelper.gs(R.string.key_danars_name)) pref.summary = sp.getString(R.string.key_danars_name, "")
if (pref.key == resourceHelper.gs(R.string.key_danars_name)) {
val value = sp.getStringOrNull(R.string.key_danars_name, null)
pref.summary = value
?: resourceHelper.gs(R.string.rileylink_error_address_not_set_short)
}
if (pref.key == resourceHelper.gs(R.string.key_danars_password)) {
if (danaRPump.v3RSPump) pref
}
}
override fun onStart() {
@ -204,7 +212,7 @@ class DanaRSPlugin @Inject constructor(
// Pump interface
override fun isInitialized(): Boolean {
return danaRPump.lastConnection > 0 && danaRPump.maxBasal > 0
return danaRPump.lastConnection > 0 && danaRPump.maxBasal > 0 && danaRPump.isRSPasswordOK
}
override fun isSuspended(): Boolean {
@ -402,7 +410,6 @@ class DanaRSPlugin @Inject constructor(
@Synchronized
override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean): PumpEnactResult {
val pump = danaRPump
val result = PumpEnactResult(injector)
var percentAfterConstraint = constraintChecker.applyBasalPercentConstraints(Constraint(percent), profile).value()
if (percentAfterConstraint < 0) {
@ -421,8 +428,8 @@ class DanaRSPlugin @Inject constructor(
result.success = true
result.isTempCancel = false
result.comment = resourceHelper.gs(R.string.virtualpump_resultok)
result.duration = pump.tempBasalRemainingMin
result.percent = pump.tempBasalPercent
result.duration = danaRPump.tempBasalRemainingMin
result.percent = danaRPump.tempBasalPercent
result.isPercent = true
aapsLogger.debug(LTag.PUMP, "setTempBasalPercent: Correct value already set")
return result
@ -435,13 +442,13 @@ class DanaRSPlugin @Inject constructor(
val durationInHours = max(durationInMinutes / 60, 1)
danaRSService?.tempBasal(percentAfterConstraint, durationInHours) ?: false
}
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percentAfterConstraint) {
if (connectionOK && danaRPump.isTempBasalInProgress && danaRPump.tempBasalPercent == percentAfterConstraint) {
result.enacted = true
result.success = true
result.comment = resourceHelper.gs(R.string.virtualpump_resultok)
result.isTempCancel = false
result.duration = pump.tempBasalRemainingMin
result.percent = pump.tempBasalPercent
result.duration = danaRPump.tempBasalRemainingMin
result.percent = danaRPump.tempBasalPercent
result.isPercent = true
aapsLogger.debug(LTag.PUMP, "setTempBasalPercent: OK")
return result
@ -454,16 +461,15 @@ class DanaRSPlugin @Inject constructor(
}
@Synchronized private fun setHighTempBasalPercent(percent: Int): PumpEnactResult {
val pump = danaRPump
val result = PumpEnactResult(injector)
val connectionOK = danaRSService?.highTempBasal(percent) ?: false
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
if (connectionOK && danaRPump.isTempBasalInProgress && danaRPump.tempBasalPercent == percent) {
result.enacted = true
result.success = true
result.comment = resourceHelper.gs(R.string.virtualpump_resultok)
result.isTempCancel = false
result.duration = pump.tempBasalRemainingMin
result.percent = pump.tempBasalPercent
result.duration = danaRPump.tempBasalRemainingMin
result.percent = danaRPump.tempBasalPercent
result.isPercent = true
aapsLogger.debug(LTag.PUMP, "setHighTempBasalPercent: OK")
return result
@ -477,7 +483,6 @@ class DanaRSPlugin @Inject constructor(
@Synchronized
override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult {
val pump = danaRPump
var insulinAfterConstraint = constraintChecker.applyExtendedBolusConstraints(Constraint(insulin)).value()
// needs to be rounded
val durationInHalfHours = max(durationInMinutes / 30, 1)
@ -488,23 +493,23 @@ class DanaRSPlugin @Inject constructor(
result.enacted = false
result.success = true
result.comment = resourceHelper.gs(R.string.virtualpump_resultok)
result.duration = pump.extendedBolusRemainingMinutes
result.absolute = pump.extendedBolusAbsoluteRate
result.duration = danaRPump.extendedBolusRemainingMinutes
result.absolute = danaRPump.extendedBolusAbsoluteRate
result.isPercent = false
result.isTempCancel = false
aapsLogger.debug(LTag.PUMP, "setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulinAfterConstraint)
aapsLogger.debug(LTag.PUMP, "setExtendedBolus: Correct extended bolus already set. Current: " + danaRPump.extendedBolusAmount + " Asked: " + insulinAfterConstraint)
return result
}
val connectionOK = danaRSService?.extendedBolus(insulinAfterConstraint, durationInHalfHours)
?: false
if (connectionOK && pump.isExtendedInProgress && abs(pump.extendedBolusAbsoluteRate - insulinAfterConstraint) < pumpDescription.extendedBolusStep) {
if (connectionOK && danaRPump.isExtendedInProgress && abs(danaRPump.extendedBolusAbsoluteRate - insulinAfterConstraint) < pumpDescription.extendedBolusStep) {
result.enacted = true
result.success = true
result.comment = resourceHelper.gs(R.string.virtualpump_resultok)
result.isTempCancel = false
result.duration = pump.extendedBolusRemainingMinutes
result.absolute = pump.extendedBolusAbsoluteRate
result.bolusDelivered = pump.extendedBolusAmount
result.duration = danaRPump.extendedBolusRemainingMinutes
result.absolute = danaRPump.extendedBolusAbsoluteRate
result.bolusDelivered = danaRPump.extendedBolusAmount
result.isPercent = false
aapsLogger.debug(LTag.PUMP, "setExtendedBolus: OK")
return result
@ -562,9 +567,8 @@ class DanaRSPlugin @Inject constructor(
}
override fun getJSONStatus(profile: Profile, profileName: String): JSONObject {
val pump = danaRPump
val now = System.currentTimeMillis()
if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) {
if (danaRPump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) {
return JSONObject()
}
val pumpJson = JSONObject()
@ -572,13 +576,13 @@ class DanaRSPlugin @Inject constructor(
val status = JSONObject()
val extended = JSONObject()
try {
battery.put("percent", pump.batteryRemaining)
status.put("status", if (pump.pumpSuspended) "suspended" else "normal")
status.put("timestamp", DateUtil.toISOString(pump.lastConnection))
battery.put("percent", danaRPump.batteryRemaining)
status.put("status", if (danaRPump.pumpSuspended) "suspended" else "normal")
status.put("timestamp", DateUtil.toISOString(danaRPump.lastConnection))
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION)
if (pump.lastBolusTime != 0L) {
extended.put("LastBolus", DateUtil.dateAndTimeString(pump.lastBolusTime))
extended.put("LastBolusAmount", pump.lastBolusAmount)
if (danaRPump.lastBolusTime != 0L) {
extended.put("LastBolus", DateUtil.dateAndTimeString(danaRPump.lastBolusTime))
extended.put("LastBolusAmount", danaRPump.lastBolusAmount)
}
val tb = treatmentsPlugin.getTempBasalFromHistory(now)
if (tb != null) {
@ -601,7 +605,7 @@ class DanaRSPlugin @Inject constructor(
pumpJson.put("battery", battery)
pumpJson.put("status", status)
pumpJson.put("extended", extended)
pumpJson.put("reservoir", pump.reservoirRemainingUnits.toInt())
pumpJson.put("reservoir", danaRPump.reservoirRemainingUnits.toInt())
pumpJson.put("clock", DateUtil.toISOString(now))
} catch (e: JSONException) {
aapsLogger.error("Unhandled exception", e)
@ -626,15 +630,14 @@ class DanaRSPlugin @Inject constructor(
}
override fun shortStatus(veryShort: Boolean): String {
val pump = danaRPump
var ret = ""
if (pump.lastConnection != 0L) {
val agoMillis = System.currentTimeMillis() - pump.lastConnection
if (danaRPump.lastConnection != 0L) {
val agoMillis = System.currentTimeMillis() - danaRPump.lastConnection
val agoMin = (agoMillis / 60.0 / 1000.0).toInt()
ret += "LastConn: $agoMin minago\n"
}
if (pump.lastBolusTime != 0L)
ret += "LastBolus: ${DecimalFormatter.to2Decimal(pump.lastBolusAmount)}U @${DateFormat.format("HH:mm", pump.lastBolusTime)}"
if (danaRPump.lastBolusTime != 0L)
ret += "LastBolus: ${DecimalFormatter.to2Decimal(danaRPump.lastBolusAmount)}U @${DateFormat.format("HH:mm", danaRPump.lastBolusTime)}"
val activeTemp = treatmentsPlugin.getRealTempBasalFromHistory(System.currentTimeMillis())
if (activeTemp != null)
@ -645,10 +648,10 @@ class DanaRSPlugin @Inject constructor(
ret += "Extended: $activeExtendedBolus\n"
if (!veryShort) {
ret += "TDD: ${DecimalFormatter.to0Decimal(pump.dailyTotalUnits)} / ${pump.maxDailyTotalUnits} U"
ret += "TDD: ${DecimalFormatter.to0Decimal(danaRPump.dailyTotalUnits)} / ${danaRPump.maxDailyTotalUnits} U"
}
ret += "Reserv: ${DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits)} U"
ret += "Batt: ${pump.batteryRemaining}"
ret += "Reserv: ${DecimalFormatter.to0Decimal(danaRPump.reservoirRemainingUnits)} U"
ret += "Batt: ${danaRPump.batteryRemaining}"
return ret
}

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
@ -22,6 +23,7 @@ import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTabl
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet
import info.nightscout.androidaps.plugins.pump.danaRS.encryption.BleEncryption
import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.extensions.notify
import info.nightscout.androidaps.utils.extensions.waitMillis
@ -67,6 +69,7 @@ class BLEComm @Inject internal constructor(
set(newValue) {
bleEncryption.setEnhancedEncryption(newValue)
field = newValue
danaRPump.v3RSPump = newValue
}
private var isEasyMode: Boolean = false
private var isUnitUD: Boolean = false
@ -550,11 +553,19 @@ class BLEComm @Inject internal constructor(
var pass: Int = (decryptedBuffer[size - 1].toInt() and 0x000000FF shl 8) + (decryptedBuffer[size - 2].toInt() and 0x000000FF)
pass = pass xor 3463
danaRPump.rsPassword = Integer.toHexString(pass)
aapsLogger.debug(LTag.PUMPBTCOMM, "Pump user password: " + Integer.toHexString(pass))
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED))
isConnected = true
isConnecting = false
aapsLogger.debug(LTag.PUMPBTCOMM, "RS connected and status read")
aapsLogger.debug(LTag.PUMPBTCOMM, "Pump user password: " + danaRPump.rsPassword)
if (!danaRPump.isRSPasswordOK) {
aapsLogger.error(LTag.PUMPBTCOMM, "Wrong pump password")
rxBus.send(EventNewNotification(Notification(Notification.WRONG_PUMP_PASSWORD, resourceHelper.gs(R.string.wrongpumppassword), Notification.URGENT)))
disconnect("WrongPassword")
SystemClock.sleep(T.mins(1).msecs())
} else {
rxBus.send(EventDismissNotification(Notification.WRONG_PUMP_PASSWORD))
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED))
isConnected = true
isConnecting = false
aapsLogger.debug(LTag.PUMPBTCOMM, "RS connected and status read")
}
}
}

View file

@ -379,6 +379,7 @@
<string name="danar_history_refill">Refill</string>
<string name="danar_history_syspend">Suspend</string>
<string name="danar_history_connectingfor">Connecting for %1$d s</string>
<string name="danars_password_title">Pump password (v1 only)</string>
<string name="danar_password_title">Pump password</string>
<string name="wrongpumppassword">Wrong pump password!</string>
<string name="pumpbusy">Pump is busy</string>
@ -805,7 +806,6 @@
<string name="danarspump">DanaRS</string>
<string name="danarspump_shortname">Dana</string>
<string name="selectedpump">Selected pump</string>
<string name="pairpump">Pair new pump</string>
<string name="bolusspeed">Bolus speed</string>
<string name="key_danars_bolusspeed" translatable="false">danars_bolusspeed</string>
<string name="danar_setbasalstep001">Set basal step to 0.01 U/h</string>
@ -1844,4 +1844,5 @@
<string name="key_statuslights_copy_ns" translatable="false">statuslights_copy_ns</string>
<string name="copyexistingvalues">Copy NS settings (if exists)?</string>
<string name="key_statuslights_overview_advanced" translatable="false">statuslights_overview_advanced</string>
<string name="key_danars_password">danars_password</string>
</resources>

View file

@ -18,11 +18,13 @@
<string name="error_mustbe6digitnumber">Must be 6 digit number</string>
<string name="error_mustbe12hexadidits">Must be 12 characters of ABCDEF0123456789</string>
<string name="error_mustbe8hexadidits">Must be 8 characters of ABCDEF0123456789</string>
<string name="error_mustbe4hexadidits">Must be 4 characters of ABCDEF0123456789</string>
<string name="error_not_a_minimum_length">Not a minimum length</string>
<string name="error_pin_not_valid">Pin should be 3 to 6 digits, not same or in series</string>
<string name="fourdigitnumber" translatable="false">^\\d{4}</string>
<string name="twelvehexanumber" translatable="false">^[A-F0-9]{12}$</string>
<string name="eighthexanumber" translatable="false">^[A-F0-9]{8}$</string>
<string name="fourhexanumber" translatable="false">^[A-F0-9]{4}$</string>
</resources>

View file

@ -8,24 +8,19 @@
app:initialExpandedChildrenCount="0">
<Preference
android:key="blescannner"
android:title="@string/pairpump">
android:key="@string/key_danars_name"
android:summary=""
android:title="@string/selectedpump">
<intent android:action="info.nightscout.androidaps.plugins.PumpDanaRS.activities.BLEScanActivity" />
</Preference>
<EditTextPreference
android:key="@string/key_danars_name"
android:persistent="false"
android:selectable="false"
android:summary=""
android:title="@string/selectedpump" />
<info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference
android:inputType="numberPassword"
android:key="@string/key_danar_password"
android:title="@string/danar_password_title"
validate:customRegexp="@string/fourdigitnumber"
validate:testErrorString="@string/error_mustbe4digitnumber"
android:digits="0123456789ABCDEF"
android:key="@string/key_danars_password"
android:title="@string/danars_password_title"
validate:customRegexp="@string/fourhexanumber"
validate:testErrorString="@string/error_mustbe4hexadidits"
validate:testType="regexp" />
<ListPreference