dash/ble: stop reading a message on send

We were receiving a message in that case just because we used the `eqos`
parameter incorrectly.
This commit is contained in:
Andrei Vereha 2021-03-11 21:36:43 +01:00
parent 2aed2005ef
commit 1a678a9507
7 changed files with 10 additions and 22 deletions

View file

@ -31,7 +31,7 @@ data class Id(val address: ByteArray) {
companion object {
private val PERIPHERAL_NODE_INDEX = 1 // TODO: understand the meaning of this value. It comes from preferences
private const val PERIPHERAL_NODE_INDEX = 1 // TODO: understand the meaning of this value. It comes from preferences
fun fromInt(v: Int): Id {
return Id(ByteBuffer.allocate(4).putInt(v).array())

View file

@ -36,5 +36,4 @@ open class BleCommand(val data: ByteArray) {
override fun hashCode(): Int {
return data.contentHashCode()
}
}

View file

@ -8,7 +8,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptio
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io.BleIO
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io.CharacteristicType
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io.PayloadJoiner
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.CommandType
import info.nightscout.androidaps.utils.extensions.toHex
class MessageIO(private val aapsLogger: AAPSLogger, private val bleIO: BleIO) {
@ -22,19 +21,12 @@ class MessageIO(private val aapsLogger: AAPSLogger, private val bleIO: BleIO) {
return
}
throw UnexpectedCommandException(actual)
}
fun sendMessage(msg: MessagePacket):MessagePacket? {
fun sendMessage(msg: MessagePacket) {
bleIO.flushIncomingQueues()
bleIO.sendAndConfirmPacket(CharacteristicType.CMD, BleCommandRTS().data)
val expectCTS = bleIO.receivePacket(CharacteristicType.CMD)
if (expectCTS.isEmpty()) {
throw UnexpectedCommandException(BleCommand(expectCTS))
}
//if (expectCTS[0] == BleCommandType.RTS.value) {
//the pod is trying to send something, after we sent RTS, let's read it
//}
expectCommandType(BleCommand(expectCTS), BleCommandCTS())
val payload = msg.asByteArray()
aapsLogger.debug(LTag.PUMPBTCOMM, "Sending message: ${payload.toHex()}")
@ -48,11 +40,10 @@ class MessageIO(private val aapsLogger: AAPSLogger, private val bleIO: BleIO) {
val expectSuccess = bleIO.receivePacket(CharacteristicType.CMD)
expectCommandType(BleCommand(expectSuccess), BleCommandSuccess())
// TODO: handle NACKS/FAILS/etc
return null
}
// TODO: use higher timeout when receiving the first packet in a message
fun receiveMessage( firstCmd: ByteArray? = null): MessagePacket {
fun receiveMessage(firstCmd: ByteArray? = null): MessagePacket {
var expectRTS = firstCmd
if (expectRTS == null) {
expectRTS = bleIO.receivePacket(CharacteristicType.CMD)

View file

@ -11,7 +11,7 @@ class StringLengthPrefixEncoding {
companion object {
private val LENGTH_BYTES = 2
private const val LENGTH_BYTES = 2
fun parseKeys(keys: Array<String>, payload: ByteArray): Array<ByteArray> {
val ret = Array<ByteArray>(keys.size, { ByteArray(0) })

View file

@ -236,8 +236,9 @@ internal class LTKExchanger(private val aapsLogger: AAPSLogger, private val msgI
private val PDM_CONF_MAGIC_PREFIX = "KC_2_U".toByteArray()
private val POD_CONF_MAGIC_PREFIX = "KC_2_V".toByteArray()
private const val GET_POD_STATUS_HEX_COMMAND =
"ffc32dbd08030e0100008a" // TODO for now we are assuming this command is build out of constant parameters, use a proper command builder for that.
private const val GET_POD_STATUS_HEX_COMMAND = "ffc32dbd08030e0100008a"
// TODO for now we are assuming this command is build out of constant parameters,
// use a proper command builder for that.
private const val SP1 = "SP1="
private const val SP2 = ",SP2="

View file

@ -35,10 +35,8 @@ class Session(
val msg = getCmdMessage(cmd)
aapsLogger.debug(LTag.PUMPBTCOMM, "Sending command(wrapped): ${msg.payload.toHex()}")
val reply = msgIO.sendMessage(msg)
if (reply != null) { // TODO : this means the last ACK was not received, send it again?
aapsLogger.debug(LTag.PUMPBTCOMM, "Received a message with payload instead of CTS: ${reply.payload.toHex()} in packet $reply")
}
msgIO.sendMessage(msg)
val responseMsg = msgIO.receiveMessage()
val decrypted = enDecrypt.decrypt(responseMsg)
aapsLogger.debug(LTag.PUMPBTCOMM, "Received response: $decrypted")

View file

@ -250,13 +250,12 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
rxBus.send(EventOmnipodDashPumpValuesChanged())
}
override fun updateFromPairing(uniqueId: Id, pairResult: PairResult){
override fun updateFromPairing(uniqueId: Id, pairResult: PairResult) {
podState.eapAkaSequenceNumber = 1
podState.ltk = pairResult.ltk
podState.uniqueId = uniqueId.toLong()
}
override fun reset() {
podState = PodState()
store()