Dana-i: store pairing key
This commit is contained in:
parent
3dc2f073fe
commit
7ad425ae1d
5 changed files with 47 additions and 28 deletions
|
@ -80,8 +80,10 @@ class DanaFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View {
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = DanarFragmentBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
@ -112,7 +114,9 @@ class DanaFragment : DaggerFragment() {
|
|||
danaPump.reset()
|
||||
commandQueue.readStatus("Clicked connect to pump", null)
|
||||
}
|
||||
if (activePlugin.activePump.pumpDescription.pumpType == PumpType.DANA_RS)
|
||||
if (activePlugin.activePump.pumpDescription.pumpType == PumpType.DANA_RS ||
|
||||
activePlugin.activePump.pumpDescription.pumpType == PumpType.DANA_I
|
||||
)
|
||||
binding.btconnection.setOnLongClickListener {
|
||||
activity?.let {
|
||||
OKDialog.showConfirmation(it, rh.gs(R.string.resetpairing)) {
|
||||
|
@ -152,22 +156,22 @@ class DanaFragment : DaggerFragment() {
|
|||
.toObservable(EventPumpStatusChanged::class.java)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe({
|
||||
pumpStatusIcon = when (it.status) {
|
||||
EventPumpStatusChanged.Status.CONNECTING ->
|
||||
"{fa-bluetooth-b spin} ${it.secondsElapsed}s"
|
||||
EventPumpStatusChanged.Status.CONNECTED ->
|
||||
"{fa-bluetooth}"
|
||||
EventPumpStatusChanged.Status.DISCONNECTED ->
|
||||
"{fa-bluetooth-b}"
|
||||
pumpStatusIcon = when (it.status) {
|
||||
EventPumpStatusChanged.Status.CONNECTING ->
|
||||
"{fa-bluetooth-b spin} ${it.secondsElapsed}s"
|
||||
EventPumpStatusChanged.Status.CONNECTED ->
|
||||
"{fa-bluetooth}"
|
||||
EventPumpStatusChanged.Status.DISCONNECTED ->
|
||||
"{fa-bluetooth-b}"
|
||||
|
||||
else ->
|
||||
"{fa-bluetooth-b}"
|
||||
}
|
||||
binding.btconnection.text = pumpStatusIcon
|
||||
pumpStatus = it.getStatus(rh)
|
||||
binding.pumpStatus.text = pumpStatus
|
||||
binding.pumpStatusLayout.visibility = (pumpStatus != "").toVisibility()
|
||||
}, fabricPrivacy::logException)
|
||||
else ->
|
||||
"{fa-bluetooth-b}"
|
||||
}
|
||||
binding.btconnection.text = pumpStatusIcon
|
||||
pumpStatus = it.getStatus(rh)
|
||||
binding.pumpStatus.text = pumpStatus
|
||||
binding.pumpStatusLayout.visibility = (pumpStatus != "").toVisibility()
|
||||
}, fabricPrivacy::logException)
|
||||
|
||||
pumpStatus = ""
|
||||
pumpStatusIcon = "{fa-bluetooth-b}"
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<string name="key_danars_v3_randompairingkey" translatable="false">danars_v3_randompairing_key_</string>
|
||||
<string name="key_danars_v3_pairingkey" translatable="false">danars_v3_pairing_key_</string>
|
||||
<string name="key_danars_v3_randomsynckey" translatable="false">danars_v3_randomsync_key_</string>
|
||||
<string name="key_dana_ble5_pairingkey" translatable="false">dana_ble5_pairingkey</string>
|
||||
<string name="key_rs_logcanulachange" translatable="false">rs_logcanulachange</string>
|
||||
<string name="key_rs_loginsulinchange" translatable="false">rs_loginsulinchange</string>
|
||||
<string name="key_rs_last_clear_key_request" translatable="false">rs_last_clear_key_request</string>
|
||||
|
|
|
@ -625,5 +625,6 @@ class DanaRSPlugin @Inject constructor(
|
|||
sp.remove(rh.gs(R.string.key_danars_v3_randompairingkey) + mDeviceName)
|
||||
sp.remove(rh.gs(R.string.key_danars_v3_pairingkey) + mDeviceName)
|
||||
sp.remove(rh.gs(R.string.key_danars_v3_randomsynckey) + mDeviceName)
|
||||
sp.remove(rh.gs(R.string.key_dana_ble5_pairingkey) + mDeviceName)
|
||||
}
|
||||
}
|
|
@ -149,15 +149,7 @@ class BLEComm @Inject internal constructor(
|
|||
if (lastClearRequest != 0L && dateUtil.isOlderThan(lastClearRequest, 5)) {
|
||||
ToastUtils.showToastInUiThread(context, R.string.invalidpairing)
|
||||
danaRSPlugin.changePump()
|
||||
sp.getStringOrNull(R.string.key_danars_address, null)?.let { address ->
|
||||
bluetoothAdapter?.getRemoteDevice(address)?.let { device ->
|
||||
try {
|
||||
device::class.java.getMethod("removeBond").invoke(device)
|
||||
} catch (e: Exception) {
|
||||
aapsLogger.error("Removing bond has been failed. ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
removeBond()
|
||||
} else if (lastClearRequest == 0L) {
|
||||
aapsLogger.error("Clearing pairing keys postponed")
|
||||
sp.putLong(R.string.key_rs_last_clear_key_request, dateUtil.now())
|
||||
|
@ -196,6 +188,18 @@ class BLEComm @Inject internal constructor(
|
|||
SystemClock.sleep(2000)
|
||||
}
|
||||
|
||||
private fun removeBond() {
|
||||
sp.getStringOrNull(R.string.key_danars_address, null)?.let { address ->
|
||||
bluetoothAdapter?.getRemoteDevice(address)?.let { device ->
|
||||
try {
|
||||
device::class.java.getMethod("removeBond").invoke(device)
|
||||
} catch (e: Exception) {
|
||||
aapsLogger.error("Removing bond has been failed. ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized fun close() {
|
||||
/*
|
||||
if (!encryptedDataRead && !encryptedCommandSent) {
|
||||
|
@ -558,9 +562,17 @@ class BLEComm @Inject internal constructor(
|
|||
danaPump.hwModel = decryptedBuffer[5].toInt()
|
||||
danaPump.protocol = decryptedBuffer[7].toInt()
|
||||
val pairingKey = DanaRSPacket.asciiStringFromBuff(decryptedBuffer, 8, 6) // used while bonding
|
||||
if (decryptedBuffer[8] != 0.toByte())
|
||||
sp.putString(rh.gs(R.string.key_dana_ble5_pairingkey) + danaRSPlugin.mDeviceName, pairingKey)
|
||||
|
||||
val storedPairingKey = sp.getString(rh.gs(R.string.key_dana_ble5_pairingkey) + danaRSPlugin.mDeviceName, "")
|
||||
if (storedPairingKey.isNullOrBlank()) {
|
||||
removeBond()
|
||||
disconnect("Non existing pairing key")
|
||||
}
|
||||
|
||||
if (danaPump.hwModel == 0x09) {
|
||||
bleEncryption.setBle5Key(pairingKey.encodeToByteArray())
|
||||
bleEncryption.setBle5Key(storedPairingKey.encodeToByteArray())
|
||||
aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + "ENCRYPTION__PUMP_CHECK BLE5 (OK)" + " " + DanaRSPacket.toHexString(decryptedBuffer))
|
||||
// Dana-i BLE5 Pump
|
||||
sendBLE5PairingInformation()
|
||||
|
|
|
@ -118,6 +118,7 @@ class DanaRSService : DaggerService() {
|
|||
val pump = activePlugin.activePump
|
||||
rxBus.send(EventPumpStatusChanged(rh.gs(R.string.gettingpumpsettings)))
|
||||
sendMessage(DanaRSPacketEtcKeepConnection(injector)) // test encryption for v3 & BLE
|
||||
if (!bleComm.isConnected) return
|
||||
sendMessage(DanaRSPacketGeneralGetShippingInformation(injector)) // serial no
|
||||
sendMessage(DanaRSPacketGeneralGetPumpCheck(injector)) // firmware
|
||||
sendMessage(DanaRSPacketBasalGetProfileNumber(injector))
|
||||
|
|
Loading…
Reference in a new issue