dash ble: renames and fixes after testing
This commit is contained in:
parent
8154e16c94
commit
2aed2005ef
|
@ -53,9 +53,9 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
} // TODO are these reasonable values?
|
||||
|
||||
|
||||
private val observeScanAndActivateNewPod: Observable<PodEvent>
|
||||
private val observePairNewPod: Observable<PodEvent>
|
||||
get() = Observable.defer {
|
||||
bleManager.activateNewPod()
|
||||
bleManager.pairNewPod()
|
||||
} // TODO are these reasonable values?
|
||||
|
||||
private fun observeSendProgramBolusCommand(
|
||||
|
@ -177,7 +177,7 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
override fun activatePodPart1(lowReservoirAlertTrigger: AlertTrigger.ReservoirVolumeTrigger?): Observable<PodEvent> {
|
||||
return Observable.concat(
|
||||
observePodReadyForActivationPart1,
|
||||
observeScanAndActivateNewPod,
|
||||
observePairNewPod,
|
||||
observeActivationPart1Commands(lowReservoirAlertTrigger)
|
||||
).doOnComplete(ActivationProgressUpdater(ActivationProgress.PHASE_1_COMPLETED))
|
||||
// TODO these would be common for any observable returned in a public function in this class
|
||||
|
@ -415,6 +415,7 @@ class OmnipodDashManagerImpl @Inject constructor(
|
|||
}
|
||||
|
||||
is PodEvent.BluetoothConnected -> {
|
||||
podStateManager.bluetoothAddress = event.bluetoothAddress
|
||||
}
|
||||
|
||||
is PodEvent.Connected -> {
|
||||
|
|
|
@ -13,7 +13,7 @@ interface OmnipodDashBleManager {
|
|||
|
||||
fun connect(): Observable<PodEvent>
|
||||
|
||||
fun activateNewPod(): Observable<PodEvent>
|
||||
fun pairNewPod(): Observable<PodEvent>
|
||||
|
||||
fun disconnect()
|
||||
}
|
||||
|
|
|
@ -47,6 +47,10 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
private var msgIO: MessageIO? = null
|
||||
private var gatt: BluetoothGatt? = null
|
||||
private var status: ConnectionStatus = ConnectionStatus.IDLE
|
||||
private val myId = Id.fromInt(CONTROLLER_ID)
|
||||
private val uniqueId = podState.uniqueId
|
||||
private val podId = uniqueId?.let { Id.fromLong(uniqueId) }
|
||||
?: myId.increment() // pod not activated
|
||||
|
||||
@Throws(
|
||||
FailedToConnectException::class,
|
||||
|
@ -106,8 +110,8 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
val session = Session(
|
||||
aapsLogger = aapsLogger,
|
||||
msgIO = mIO,
|
||||
myId = Id.fromInt(CONTROLLER_ID),
|
||||
podId = Id.fromInt(CONTROLLER_ID).increment(),
|
||||
myId = myId,
|
||||
podId = podId,
|
||||
sessionKeys = keys,
|
||||
enDecrypt = enDecrypt
|
||||
)
|
||||
|
@ -144,7 +148,9 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
override fun connect(): Observable<PodEvent> = Observable.create { emitter ->
|
||||
try {
|
||||
|
||||
val podAddress = podState.bluetoothAddress ?: throw FailedToConnectException("Missing bluetoothAddress, activate the pod first")
|
||||
val podAddress =
|
||||
podState.bluetoothAddress
|
||||
?: throw FailedToConnectException("Missing bluetoothAddress, activate the pod first")
|
||||
// check if already connected
|
||||
val podDevice = bluetoothAdapter.getRemoteDevice(podAddress)
|
||||
val connectionState = bluetoothManager.getConnectionState(podDevice, BluetoothProfile.GATT)
|
||||
|
@ -154,6 +160,7 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
emitter.onComplete()
|
||||
return@create
|
||||
}
|
||||
|
||||
emitter.onNext(PodEvent.BluetoothConnecting)
|
||||
if (msgIO != null) {
|
||||
disconnect()
|
||||
|
@ -161,12 +168,10 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
val bleIO = connect(podDevice)
|
||||
val mIO = MessageIO(aapsLogger, bleIO)
|
||||
msgIO = mIO
|
||||
emitter.onNext(PodEvent.BluetoothConnected)
|
||||
emitter.onNext(PodEvent.BluetoothConnected(podAddress))
|
||||
|
||||
emitter.onNext(PodEvent.EstablishingSession)
|
||||
|
||||
establishSession(1.toByte())
|
||||
|
||||
emitter.onNext(PodEvent.Connected)
|
||||
|
||||
emitter.onComplete()
|
||||
|
@ -179,7 +184,6 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
private fun establishSession(msgSeq: Byte) {
|
||||
val mIO = msgIO ?: throw FailedToConnectException("connection lost")
|
||||
val ltk: ByteArray = podState.ltk ?: throw FailedToConnectException("Missing LTK, activate the pod first")
|
||||
val myId = Id.fromInt(CONTROLLER_ID)
|
||||
val uniqueId = podState.uniqueId
|
||||
val podId = uniqueId?.let { Id.fromLong(uniqueId) }
|
||||
?: myId.increment() // pod not activated
|
||||
|
@ -197,46 +201,43 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
sessionKeys = keys
|
||||
}
|
||||
|
||||
override fun activateNewPod(): Observable<PodEvent> = Observable.create { emitter ->
|
||||
override fun pairNewPod(): Observable<PodEvent> = Observable.create { emitter ->
|
||||
try {
|
||||
|
||||
if (podState.ltk != null) {
|
||||
throw PodAlreadyActivatedException()
|
||||
emitter.onNext(PodEvent.AlreadyPaired)
|
||||
emitter.onComplete()
|
||||
return@create
|
||||
}
|
||||
aapsLogger.info(LTag.PUMPBTCOMM, "starting new pod activation")
|
||||
|
||||
val podScanner = PodScanner(aapsLogger, bluetoothAdapter)
|
||||
emitter.onNext(PodEvent.Scanning)
|
||||
|
||||
val podScanner = PodScanner(aapsLogger, bluetoothAdapter)
|
||||
val podAddress = podScanner.scanForPod(
|
||||
PodScanner.SCAN_FOR_SERVICE_UUID,
|
||||
PodScanner.POD_ID_NOT_ACTIVATED
|
||||
).scanResult.device.address
|
||||
// For tests: this.podAddress = "B8:27:EB:1D:7E:BB";
|
||||
podState.bluetoothAddress = podAddress
|
||||
|
||||
emitter.onNext(PodEvent.BluetoothConnecting)
|
||||
val podDevice = bluetoothAdapter.getRemoteDevice(podAddress)
|
||||
val bleIO = connect(podDevice)
|
||||
emitter.onNext(PodEvent.BluetoothConnected)
|
||||
|
||||
val mIO = MessageIO(aapsLogger, bleIO)
|
||||
val myId = Id.fromInt(CONTROLLER_ID)
|
||||
val podId = myId.increment()
|
||||
emitter.onNext(PodEvent.Pairing)
|
||||
msgIO = mIO
|
||||
emitter.onNext(PodEvent.BluetoothConnected(podAddress))
|
||||
|
||||
emitter.onNext(PodEvent.Pairing)
|
||||
val ltkExchanger = LTKExchanger(aapsLogger, mIO, myId, podId, Id.fromLong(PodScanner.POD_ID_NOT_ACTIVATED))
|
||||
val pairResult = ltkExchanger.negotiateLTK()
|
||||
podState.ltk = pairResult.ltk
|
||||
podState.eapAkaSequenceNumber = 1
|
||||
emitter.onNext(PodEvent.Paired(podId))
|
||||
podState.uniqueId = podId.toLong()
|
||||
val msgSeq = pairResult.msgSeq
|
||||
podState.updateFromPairing(podId, pairResult)
|
||||
if (BuildConfig.DEBUG) {
|
||||
aapsLogger.info(LTag.PUMPCOMM, "Got LTK: ${pairResult.ltk.toHex()}")
|
||||
}
|
||||
emitter.onNext(PodEvent.EstablishingSession)
|
||||
establishSession(msgSeq)
|
||||
emitter.onNext(PodEvent.Paired(podId))
|
||||
|
||||
emitter.onNext(PodEvent.EstablishingSession)
|
||||
establishSession(pairResult.msgSeq)
|
||||
emitter.onNext(PodEvent.Connected)
|
||||
emitter.onComplete()
|
||||
} catch (ex: Exception) {
|
||||
disconnect()
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
||||
|
||||
class PodAlreadyActivatedException: Exception("The pod is already activated") {
|
||||
}
|
|
@ -8,9 +8,10 @@ sealed class PodEvent {
|
|||
|
||||
/* BT connection events */
|
||||
class AlreadyConnected(val bluetoothAddress: String) : PodEvent()
|
||||
object AlreadyPaired : PodEvent()
|
||||
object Scanning : PodEvent()
|
||||
object BluetoothConnecting : PodEvent()
|
||||
object BluetoothConnected : PodEvent()
|
||||
class BluetoothConnected(val bluetoothAddress: String) : PodEvent()
|
||||
object Pairing : PodEvent()
|
||||
class Paired(val uniqueId: Id) : PodEvent()
|
||||
object EstablishingSession : PodEvent()
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state
|
||||
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.Id
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.pair.PairResult
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.*
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.AlarmStatusResponse
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.DefaultStatusResponse
|
||||
|
@ -54,6 +56,7 @@ interface OmnipodDashPodStateManager {
|
|||
fun updateFromVersionResponse(response: VersionResponse)
|
||||
fun updateFromSetUniqueIdResponse(response: SetUniqueIdResponse)
|
||||
fun updateFromAlarmStatusResponse(response: AlarmStatusResponse)
|
||||
fun updateFromPairing(uniqueId: Id, pairResult: PairResult)
|
||||
fun reset()
|
||||
|
||||
data class TempBasal(val startTime: Long, val rate: Double, val durationInMinutes: Short) : Serializable
|
||||
|
|
|
@ -6,6 +6,8 @@ import info.nightscout.androidaps.logging.LTag
|
|||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
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
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.pair.PairResult
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.*
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.AlarmStatusResponse
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.DefaultStatusResponse
|
||||
|
@ -248,6 +250,13 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
rxBus.send(EventOmnipodDashPumpValuesChanged())
|
||||
}
|
||||
|
||||
override fun updateFromPairing(uniqueId: Id, pairResult: PairResult){
|
||||
podState.eapAkaSequenceNumber = 1
|
||||
podState.ltk = pairResult.ltk
|
||||
podState.uniqueId = uniqueId.toLong()
|
||||
}
|
||||
|
||||
|
||||
override fun reset() {
|
||||
podState = PodState()
|
||||
store()
|
||||
|
|
|
@ -20,7 +20,7 @@ class EnDecryptTest {
|
|||
Hex.decode("dda23c090a0a0a0a"),
|
||||
0
|
||||
),
|
||||
Hex.decode("ba1283744b6de9fab6d9b77d95a71d6e"),
|
||||
Hex.decode("ba1283744b6de9fab6d9b77d95a71d6e")
|
||||
)
|
||||
val encryptedMessage = Hex.decode(
|
||||
"54571101070003400242000002420001" +
|
||||
|
@ -43,7 +43,7 @@ class EnDecryptTest {
|
|||
Hex.decode("dda23c090a0a0a0a"),
|
||||
0
|
||||
),
|
||||
Hex.decode("ba1283744b6de9fab6d9b77d95a71d6e"),
|
||||
Hex.decode("ba1283744b6de9fab6d9b77d95a71d6e")
|
||||
)
|
||||
val encryptedMessage = Hex.decode(
|
||||
"54571101070003400242000002420001" +
|
||||
|
|
Loading…
Reference in a new issue