ktlint format
This commit is contained in:
parent
3ebcc1c71e
commit
77c816e813
146 changed files with 557 additions and 467 deletions
|
@ -30,7 +30,9 @@ class DashHistoryTest {
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||||
database = Room.inMemoryDatabaseBuilder(
|
database = Room.inMemoryDatabaseBuilder(
|
||||||
context, DashHistoryDatabase::class.java).build()
|
context,
|
||||||
|
DashHistoryDatabase::class.java
|
||||||
|
).build()
|
||||||
dao = database.historyRecordDao()
|
dao = database.historyRecordDao()
|
||||||
dashHistory = DashHistory(dao, HistoryMapper())
|
dashHistory = DashHistory(dao, HistoryMapper())
|
||||||
}
|
}
|
||||||
|
@ -69,4 +71,4 @@ class DashHistoryTest {
|
||||||
fun tearDown() {
|
fun tearDown() {
|
||||||
database.close()
|
database.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ class RxSchedulerRule(val scheduler: Scheduler) : TestRule {
|
||||||
RxJavaPlugins.reset()
|
RxJavaPlugins.reset()
|
||||||
RxAndroidPlugins.reset()
|
RxAndroidPlugins.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.Event
|
import info.nightscout.androidaps.events.Event
|
||||||
|
|
||||||
class EventOmnipodDashPumpValuesChanged : Event()
|
class EventOmnipodDashPumpValuesChanged : Event()
|
||||||
|
|
|
@ -207,4 +207,4 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {
|
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,5 +29,4 @@ class OmnipodDashHistoryModule {
|
||||||
@Singleton
|
@Singleton
|
||||||
internal fun provideDashHistory(dao: HistoryRecordDao, historyMapper: HistoryMapper) =
|
internal fun provideDashHistory(dao: HistoryRecordDao, historyMapper: HistoryMapper) =
|
||||||
DashHistory(dao, historyMapper)
|
DashHistory(dao, historyMapper)
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -47,4 +47,4 @@ abstract class OmnipodDashModule {
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
abstract fun bindsOmnipodDashManagerImpl(omnipodManager: OmnipodDashManagerImpl): OmnipodDashManager
|
abstract fun bindsOmnipodDashManagerImpl(omnipodManager: OmnipodDashManagerImpl): OmnipodDashManager
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,4 +86,4 @@ abstract class OmnipodDashWizardViewModelsModule {
|
||||||
@OmnipodPluginQualifier
|
@OmnipodPluginQualifier
|
||||||
@ViewModelKey(PodDiscardedViewModel::class)
|
@ViewModelKey(PodDiscardedViewModel::class)
|
||||||
internal abstract fun podDiscardedViewModel(viewModel: DashPodDiscardedViewModel): ViewModel
|
internal abstract fun podDiscardedViewModel(viewModel: DashPodDiscardedViewModel): ViewModel
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,4 +37,4 @@ interface OmnipodDashManager {
|
||||||
fun silenceAlerts(alerts: EnumSet<AlertType>): Observable<PodEvent>
|
fun silenceAlerts(alerts: EnumSet<AlertType>): Observable<PodEvent>
|
||||||
|
|
||||||
fun deactivatePod(): Observable<PodEvent>
|
fun deactivatePod(): Observable<PodEvent>
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,14 +50,15 @@ class OmnipodDashManagerImpl @Inject constructor(
|
||||||
|
|
||||||
private fun observeSendProgramBolusCommand(units: Double, rateInEighthPulsesPerSeconds: Byte, confirmationBeeps: Boolean, completionBeeps: Boolean): Observable<PodEvent> {
|
private fun observeSendProgramBolusCommand(units: Double, rateInEighthPulsesPerSeconds: Byte, confirmationBeeps: Boolean, completionBeeps: Boolean): Observable<PodEvent> {
|
||||||
return Observable.defer {
|
return Observable.defer {
|
||||||
bleManager.sendCommand(ProgramBolusCommand.Builder()
|
bleManager.sendCommand(
|
||||||
.setUniqueId(podStateManager.uniqueId!!.toInt())
|
ProgramBolusCommand.Builder()
|
||||||
.setSequenceNumber(podStateManager.messageSequenceNumber)
|
.setUniqueId(podStateManager.uniqueId!!.toInt())
|
||||||
.setNonce(1229869870) // TODO
|
.setSequenceNumber(podStateManager.messageSequenceNumber)
|
||||||
.setNumberOfUnits(units)
|
.setNonce(1229869870) // TODO
|
||||||
.setDelayBetweenPulsesInEighthSeconds(rateInEighthPulsesPerSeconds)
|
.setNumberOfUnits(units)
|
||||||
.setProgramReminder(ProgramReminder(confirmationBeeps, completionBeeps, 0))
|
.setDelayBetweenPulsesInEighthSeconds(rateInEighthPulsesPerSeconds)
|
||||||
.build()
|
.setProgramReminder(ProgramReminder(confirmationBeeps, completionBeeps, 0))
|
||||||
|
.build()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,13 +79,15 @@ class OmnipodDashManagerImpl @Inject constructor(
|
||||||
get() = Observable.defer {
|
get() = Observable.defer {
|
||||||
observeSendGetPodStatusCommand()
|
observeSendGetPodStatusCommand()
|
||||||
.ignoreElements() //
|
.ignoreElements() //
|
||||||
.andThen(Observable.defer {
|
.andThen(
|
||||||
if (podStateManager.podStatus == PodStatus.RUNNING_ABOVE_MIN_VOLUME) {
|
Observable.defer {
|
||||||
Observable.empty()
|
if (podStateManager.podStatus == PodStatus.RUNNING_ABOVE_MIN_VOLUME) {
|
||||||
} else {
|
Observable.empty()
|
||||||
Observable.error(IllegalStateException("Unexpected Pod status"))
|
} else {
|
||||||
|
Observable.error(IllegalStateException("Unexpected Pod status"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun observeSendProgramAlertsCommand(alertConfigurations: List<AlertConfiguration>, multiCommandFlag: Boolean = false): Observable<PodEvent> {
|
private fun observeSendProgramAlertsCommand(alertConfigurations: List<AlertConfiguration>, multiCommandFlag: Boolean = false): Observable<PodEvent> {
|
||||||
|
@ -119,32 +122,38 @@ class OmnipodDashManagerImpl @Inject constructor(
|
||||||
get() = Observable.defer {
|
get() = Observable.defer {
|
||||||
observeSendGetPodStatusCommand()
|
observeSendGetPodStatusCommand()
|
||||||
.ignoreElements() //
|
.ignoreElements() //
|
||||||
.andThen(Observable.defer {
|
.andThen(
|
||||||
if (podStateManager.podStatus == PodStatus.CLUTCH_DRIVE_ENGAGED) {
|
Observable.defer {
|
||||||
Observable.empty()
|
if (podStateManager.podStatus == PodStatus.CLUTCH_DRIVE_ENGAGED) {
|
||||||
} else {
|
Observable.empty()
|
||||||
Observable.error(IllegalStateException("Unexpected Pod status"))
|
} else {
|
||||||
|
Observable.error(IllegalStateException("Unexpected Pod status"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val observeSendSetUniqueIdCommand: Observable<PodEvent>
|
private val observeSendSetUniqueIdCommand: Observable<PodEvent>
|
||||||
get() = Observable.defer {
|
get() = Observable.defer {
|
||||||
bleManager.sendCommand(SetUniqueIdCommand.Builder() //
|
bleManager.sendCommand(
|
||||||
.setSequenceNumber(podStateManager.messageSequenceNumber) //
|
SetUniqueIdCommand.Builder() //
|
||||||
.setUniqueId(podStateManager.uniqueId!!.toInt()) //
|
.setSequenceNumber(podStateManager.messageSequenceNumber) //
|
||||||
.setLotNumber(podStateManager.lotNumber!!.toInt()) //
|
.setUniqueId(podStateManager.uniqueId!!.toInt()) //
|
||||||
.setPodSequenceNumber(podStateManager.podSequenceNumber!!.toInt())
|
.setLotNumber(podStateManager.lotNumber!!.toInt()) //
|
||||||
.setInitializationTime(Date())
|
.setPodSequenceNumber(podStateManager.podSequenceNumber!!.toInt())
|
||||||
.build()) //
|
.setInitializationTime(Date())
|
||||||
|
.build()
|
||||||
|
) //
|
||||||
}
|
}
|
||||||
|
|
||||||
private val observeSendGetVersionCommand: Observable<PodEvent>
|
private val observeSendGetVersionCommand: Observable<PodEvent>
|
||||||
get() = Observable.defer {
|
get() = Observable.defer {
|
||||||
bleManager.sendCommand(GetVersionCommand.Builder() //
|
bleManager.sendCommand(
|
||||||
.setSequenceNumber(podStateManager.messageSequenceNumber) //
|
GetVersionCommand.Builder() //
|
||||||
.setUniqueId(DEFAULT_UNIQUE_ID) //
|
.setSequenceNumber(podStateManager.messageSequenceNumber) //
|
||||||
.build()) //
|
.setUniqueId(DEFAULT_UNIQUE_ID) //
|
||||||
|
.build()
|
||||||
|
) //
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun activatePodPart1(lowReservoirAlertTrigger: AlertTrigger.ReservoirVolumeTrigger?): Observable<PodEvent> {
|
override fun activatePodPart1(lowReservoirAlertTrigger: AlertTrigger.ReservoirVolumeTrigger?): Observable<PodEvent> {
|
||||||
|
@ -277,30 +286,32 @@ class OmnipodDashManagerImpl @Inject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (podStateManager.activationProgress.isBefore(ActivationProgress.UPDATED_EXPIRATION_ALERTS)) {
|
if (podStateManager.activationProgress.isBefore(ActivationProgress.UPDATED_EXPIRATION_ALERTS)) {
|
||||||
observables.add(observeSendProgramAlertsCommand(
|
observables.add(
|
||||||
listOf(
|
observeSendProgramAlertsCommand(
|
||||||
// FIXME use user configured expiration alert
|
listOf(
|
||||||
AlertConfiguration(
|
// FIXME use user configured expiration alert
|
||||||
AlertType.EXPIRATION,
|
AlertConfiguration(
|
||||||
enabled = true,
|
AlertType.EXPIRATION,
|
||||||
durationInMinutes = TimeUnit.HOURS.toMinutes(7).toShort(),
|
enabled = true,
|
||||||
autoOff = false,
|
durationInMinutes = TimeUnit.HOURS.toMinutes(7).toShort(),
|
||||||
AlertTrigger.TimerTrigger(TimeUnit.HOURS.toMinutes(73).toShort()), // FIXME use activation time
|
autoOff = false,
|
||||||
BeepType.FOUR_TIMES_BIP_BEEP,
|
AlertTrigger.TimerTrigger(TimeUnit.HOURS.toMinutes(73).toShort()), // FIXME use activation time
|
||||||
BeepRepetitionType.XXX3
|
BeepType.FOUR_TIMES_BIP_BEEP,
|
||||||
|
BeepRepetitionType.XXX3
|
||||||
|
),
|
||||||
|
AlertConfiguration(
|
||||||
|
AlertType.EXPIRATION_IMMINENT,
|
||||||
|
enabled = true,
|
||||||
|
durationInMinutes = TimeUnit.HOURS.toMinutes(1).toShort(),
|
||||||
|
autoOff = false,
|
||||||
|
AlertTrigger.TimerTrigger(TimeUnit.HOURS.toMinutes(79).toShort()), // FIXME use activation time
|
||||||
|
BeepType.FOUR_TIMES_BIP_BEEP,
|
||||||
|
BeepRepetitionType.XXX4
|
||||||
|
)
|
||||||
),
|
),
|
||||||
AlertConfiguration(
|
multiCommandFlag = true
|
||||||
AlertType.EXPIRATION_IMMINENT,
|
).doOnComplete(ActivationProgressUpdater(ActivationProgress.UPDATED_EXPIRATION_ALERTS))
|
||||||
enabled = true,
|
)
|
||||||
durationInMinutes = TimeUnit.HOURS.toMinutes(1).toShort(),
|
|
||||||
autoOff = false,
|
|
||||||
AlertTrigger.TimerTrigger(TimeUnit.HOURS.toMinutes(79).toShort()), // FIXME use activation time
|
|
||||||
BeepType.FOUR_TIMES_BIP_BEEP,
|
|
||||||
BeepRepetitionType.XXX4
|
|
||||||
)
|
|
||||||
),
|
|
||||||
multiCommandFlag = true
|
|
||||||
).doOnComplete(ActivationProgressUpdater(ActivationProgress.UPDATED_EXPIRATION_ALERTS)))
|
|
||||||
}
|
}
|
||||||
if (podStateManager.activationProgress.isBefore(ActivationProgress.PROGRAMMED_BASAL)) {
|
if (podStateManager.activationProgress.isBefore(ActivationProgress.PROGRAMMED_BASAL)) {
|
||||||
observables.add(
|
observables.add(
|
||||||
|
@ -399,7 +410,7 @@ class OmnipodDashManagerImpl @Inject constructor(
|
||||||
handleResponse(event.response)
|
handleResponse(event.response)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,7 +435,6 @@ class OmnipodDashManagerImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class ErrorInterceptor : Consumer<Throwable> {
|
inner class ErrorInterceptor : Consumer<Throwable> {
|
||||||
|
@ -432,7 +442,6 @@ class OmnipodDashManagerImpl @Inject constructor(
|
||||||
override fun accept(throwable: Throwable) {
|
override fun accept(throwable: Throwable) {
|
||||||
logger.debug(LTag.PUMP, "Intercepted error in OmnipodDashManagerImpl: ${throwable.javaClass.simpleName}")
|
logger.debug(LTag.PUMP, "Intercepted error in OmnipodDashManagerImpl: ${throwable.javaClass.simpleName}")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class ActivationProgressUpdater(private val value: ActivationProgress) : Action {
|
inner class ActivationProgressUpdater(private val value: ActivationProgress) : Action {
|
||||||
|
@ -440,6 +449,5 @@ class OmnipodDashManagerImpl @Inject constructor(
|
||||||
override fun run() {
|
override fun run() {
|
||||||
podStateManager.activationProgress = value
|
podStateManager.activationProgress = value
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ data class Id(val address: ByteArray) {
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
val asInt = ByteBuffer.wrap(address).int
|
val asInt = ByteBuffer.wrap(address).int
|
||||||
return "${asInt}/${address.toHex()}"
|
return "$asInt/${address.toHex()}"
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -33,5 +33,4 @@ data class Id(val address: ByteArray) {
|
||||||
return Id(ByteBuffer.allocate(4).putInt(v).array())
|
return Id(ByteBuffer.allocate(4).putInt(v).array())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,4 +14,4 @@ interface OmnipodDashBleManager {
|
||||||
fun connect(): Observable<PodEvent>
|
fun connect(): Observable<PodEvent>
|
||||||
|
|
||||||
fun disconnect()
|
fun disconnect()
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,10 @@ class OmnipodDashBleManagerImpl @Inject constructor(private val context: Context
|
||||||
// TODO: locking?
|
// TODO: locking?
|
||||||
val podDevice = bluetoothAdapter.getRemoteDevice(podAddress)
|
val podDevice = bluetoothAdapter.getRemoteDevice(podAddress)
|
||||||
val incomingPackets: Map<CharacteristicType, BlockingQueue<ByteArray>> =
|
val incomingPackets: Map<CharacteristicType, BlockingQueue<ByteArray>> =
|
||||||
mapOf(CharacteristicType.CMD to LinkedBlockingDeque(),
|
mapOf(
|
||||||
CharacteristicType.DATA to LinkedBlockingDeque())
|
CharacteristicType.CMD to LinkedBlockingDeque(),
|
||||||
|
CharacteristicType.DATA to LinkedBlockingDeque()
|
||||||
|
)
|
||||||
val bleCommCallbacks = BleCommCallbacks(aapsLogger, incomingPackets)
|
val bleCommCallbacks = BleCommCallbacks(aapsLogger, incomingPackets)
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Connecting to $podAddress")
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Connecting to $podAddress")
|
||||||
var autoConnect = true
|
var autoConnect = true
|
||||||
|
@ -118,5 +120,4 @@ class OmnipodDashBleManagerImpl @Inject constructor(private val context: Context
|
||||||
private const val CONNECT_TIMEOUT_MS = 7000
|
private const val CONNECT_TIMEOUT_MS = 7000
|
||||||
const val CONTROLLER_ID = 4242 // TODO read from preferences or somewhere else.
|
const val CONTROLLER_ID = 4242 // TODO read from preferences or somewhere else.
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import android.bluetooth.BluetoothGatt
|
||||||
import android.bluetooth.BluetoothGattCharacteristic
|
import android.bluetooth.BluetoothGattCharacteristic
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.callbacks.BleCommCallbacks
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.callbacks.BleCommCallbacks
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.CharacteristicNotFoundException
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.CharacteristicNotFoundException
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.ServiceNotFoundException
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.ServiceNotFoundException
|
||||||
|
@ -29,8 +28,10 @@ class ServiceDiscoverer(private val logger: AAPSLogger, private val gatt: Blueto
|
||||||
?: throw CharacteristicNotFoundException(CharacteristicType.CMD.value)
|
?: throw CharacteristicNotFoundException(CharacteristicType.CMD.value)
|
||||||
val dataChar = service.getCharacteristic(CharacteristicType.DATA.uuid) // TODO: this is never used
|
val dataChar = service.getCharacteristic(CharacteristicType.DATA.uuid) // TODO: this is never used
|
||||||
?: throw CharacteristicNotFoundException(CharacteristicType.DATA.value)
|
?: throw CharacteristicNotFoundException(CharacteristicType.DATA.value)
|
||||||
var chars = mapOf(CharacteristicType.CMD to cmdChar,
|
var chars = mapOf(
|
||||||
CharacteristicType.DATA to dataChar)
|
CharacteristicType.CMD to cmdChar,
|
||||||
|
CharacteristicType.DATA to dataChar
|
||||||
|
)
|
||||||
return chars
|
return chars
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,11 @@ class BleCommCallbacks(private val aapsLogger: AAPSLogger, private val incomingP
|
||||||
} else {
|
} else {
|
||||||
CharacteristicWriteConfirmationError(status)
|
CharacteristicWriteConfirmationError(status)
|
||||||
}
|
}
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "OnCharacteristicWrite with status/char/value " +
|
aapsLogger.debug(
|
||||||
status + "/" + byValue(characteristic.uuid.toString()) + "/" + characteristic.value.toHex())
|
LTag.PUMPBTCOMM,
|
||||||
|
"OnCharacteristicWrite with status/char/value " +
|
||||||
|
status + "/" + byValue(characteristic.uuid.toString()) + "/" + characteristic.value.toHex()
|
||||||
|
)
|
||||||
try {
|
try {
|
||||||
if (writeQueue.size > 0) {
|
if (writeQueue.size > 0) {
|
||||||
aapsLogger.warn(LTag.PUMPBTCOMM, "Write confirm queue should be empty. found: " + writeQueue.size)
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Write confirm queue should be empty. found: " + writeQueue.size)
|
||||||
|
@ -97,9 +100,12 @@ class BleCommCallbacks(private val aapsLogger: AAPSLogger, private val incomingP
|
||||||
super.onCharacteristicChanged(gatt, characteristic)
|
super.onCharacteristicChanged(gatt, characteristic)
|
||||||
val payload = characteristic.value
|
val payload = characteristic.value
|
||||||
val characteristicType = byValue(characteristic.uuid.toString())
|
val characteristicType = byValue(characteristic.uuid.toString())
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "OnCharacteristicChanged with char/value " +
|
aapsLogger.debug(
|
||||||
characteristicType + "/" +
|
LTag.PUMPBTCOMM,
|
||||||
payload.toHex())
|
"OnCharacteristicChanged with char/value " +
|
||||||
|
characteristicType + "/" +
|
||||||
|
payload.toHex()
|
||||||
|
)
|
||||||
incomingPackets[characteristicType]!!.add(payload)
|
incomingPackets[characteristicType]!!.add(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,12 +115,13 @@ class BleCommCallbacks(private val aapsLogger: AAPSLogger, private val incomingP
|
||||||
?: throw TimeoutException()
|
?: throw TimeoutException()
|
||||||
when (confirmed) {
|
when (confirmed) {
|
||||||
is DescriptorWriteConfirmationError -> throw CouldNotConfirmWriteException(confirmed.status)
|
is DescriptorWriteConfirmationError -> throw CouldNotConfirmWriteException(confirmed.status)
|
||||||
is DescriptorWriteConfirmationUUID -> if (confirmed.uuid != descriptorUUID) {
|
is DescriptorWriteConfirmationUUID ->
|
||||||
aapsLogger.warn(LTag.PUMPBTCOMM, "Could not confirm descriptor write. Got ${confirmed.uuid}. Expected: $descriptorUUID")
|
if (confirmed.uuid != descriptorUUID) {
|
||||||
throw CouldNotConfirmDescriptorWriteException(descriptorUUID, confirmed.uuid)
|
aapsLogger.warn(LTag.PUMPBTCOMM, "Could not confirm descriptor write. Got ${confirmed.uuid}. Expected: $descriptorUUID")
|
||||||
} else {
|
throw CouldNotConfirmDescriptorWriteException(descriptorUUID, confirmed.uuid)
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Confirmed descriptor write : " + confirmed.uuid)
|
} else {
|
||||||
}
|
aapsLogger.debug(LTag.PUMPBTCOMM, "Confirmed descriptor write : " + confirmed.uuid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,4 +151,4 @@ class BleCommCallbacks(private val aapsLogger: AAPSLogger, private val incomingP
|
||||||
|
|
||||||
private const val WRITE_CONFIRM_TIMEOUT_MS = 10 // the confirmation queue should be empty anyway
|
private const val WRITE_CONFIRM_TIMEOUT_MS = 10 // the confirmation queue should be empty anyway
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,4 +4,4 @@ sealed class CharacteristicWriteConfirmation
|
||||||
|
|
||||||
data class CharacteristicWriteConfirmationPayload(val payload: ByteArray) : CharacteristicWriteConfirmation()
|
data class CharacteristicWriteConfirmationPayload(val payload: ByteArray) : CharacteristicWriteConfirmation()
|
||||||
|
|
||||||
data class CharacteristicWriteConfirmationError(val status: Int) : CharacteristicWriteConfirmation()
|
data class CharacteristicWriteConfirmationError(val status: Int) : CharacteristicWriteConfirmation()
|
||||||
|
|
|
@ -4,4 +4,4 @@ sealed class DescriptorWriteConfirmation
|
||||||
|
|
||||||
data class DescriptorWriteConfirmationUUID(val uuid: String) : DescriptorWriteConfirmation()
|
data class DescriptorWriteConfirmationUUID(val uuid: String) : DescriptorWriteConfirmation()
|
||||||
|
|
||||||
data class DescriptorWriteConfirmationError(val status: Int) : DescriptorWriteConfirmation()
|
data class DescriptorWriteConfirmationError(val status: Int) : DescriptorWriteConfirmation()
|
||||||
|
|
|
@ -2,9 +2,10 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.command
|
||||||
|
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
|
|
||||||
class BleCommandHello(controllerId: Int) : BleCommand(BleCommandType.HELLO,
|
class BleCommandHello(controllerId: Int) : BleCommand(
|
||||||
|
BleCommandType.HELLO,
|
||||||
ByteBuffer.allocate(6)
|
ByteBuffer.allocate(6)
|
||||||
.put(1.toByte()) // TODO find the meaning of this constant
|
.put(1.toByte()) // TODO find the meaning of this constant
|
||||||
.put(4.toByte()) // TODO find the meaning of this constant
|
.put(4.toByte()) // TODO find the meaning of this constant
|
||||||
.putInt(controllerId).array()
|
.putInt(controllerId).array()
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,4 +10,4 @@ enum class BleCommandType(val value: Byte) {
|
||||||
values().firstOrNull { it.value == value }
|
values().firstOrNull { it.value == value }
|
||||||
?: throw IllegalArgumentException("Unknown BleCommandType: $value")
|
?: throw IllegalArgumentException("Unknown BleCommandType: $value")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
||||||
|
|
||||||
class BleIOBusyException : Exception()
|
class BleIOBusyException : Exception()
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
||||||
|
|
||||||
class CharacteristicNotFoundException(cmdCharacteristicUuid: String) : FailedToConnectException("characteristic not found: $cmdCharacteristicUuid")
|
class CharacteristicNotFoundException(cmdCharacteristicUuid: String) : FailedToConnectException("characteristic not found: $cmdCharacteristicUuid")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
||||||
|
|
||||||
class CouldNotConfirmDescriptorWriteException(override val message: String?) : Exception(message) {
|
class CouldNotConfirmDescriptorWriteException(override val message: String?) : Exception(message) {
|
||||||
constructor(sent: String, confirmed: String) : this("Could not confirm write. Sent: {$sent} .Received: ${confirmed}")
|
constructor(sent: String, confirmed: String) : this("Could not confirm write. Sent: {$sent} .Received: $confirmed")
|
||||||
constructor(status: Int) : this("Could not confirm write. Write status: ${status}")
|
constructor(status: Int) : this("Could not confirm write. Write status: $status")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
||||||
|
|
||||||
class CouldNotConfirmWriteException(override val message: String?) : Exception(message) {
|
class CouldNotConfirmWriteException(override val message: String?) : Exception(message) {
|
||||||
constructor(sent: ByteArray, confirmed: ByteArray) : this("Could not confirm write. Sent: {$sent} .Received: ${confirmed}")
|
constructor(sent: ByteArray, confirmed: ByteArray) : this("Could not confirm write. Sent: {$sent} .Received: $confirmed")
|
||||||
constructor(status: Int) : this("Could not confirm write. Write status: ${status}")
|
constructor(status: Int) : this("Could not confirm write. Write status: $status")
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.excepti
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io.CharacteristicType
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io.CharacteristicType
|
||||||
|
|
||||||
class CouldNotEnableNotifications(cmd: CharacteristicType) : Exception(cmd.value)
|
class CouldNotEnableNotifications(cmd: CharacteristicType) : Exception(cmd.value)
|
||||||
|
|
|
@ -2,4 +2,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.excepti
|
||||||
|
|
||||||
import info.nightscout.androidaps.utils.extensions.toHex
|
import info.nightscout.androidaps.utils.extensions.toHex
|
||||||
|
|
||||||
class CouldNotParseMessageException(val payload: ByteArray) : Exception("Could not parse message payload: ${payload.toHex()}")
|
class CouldNotParseMessageException(val payload: ByteArray) : Exception("Could not parse message payload: ${payload.toHex()}")
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
||||||
|
|
||||||
class CouldNotSendBleException(msg: String?) : Exception(msg)
|
class CouldNotSendBleException(msg: String?) : Exception(msg)
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
||||||
|
|
||||||
class DescriptorNotFoundException : Exception()
|
class DescriptorNotFoundException : Exception()
|
||||||
|
|
|
@ -5,4 +5,4 @@ import android.os.ParcelUuid
|
||||||
class DiscoveredInvalidPodException : Exception {
|
class DiscoveredInvalidPodException : Exception {
|
||||||
constructor(message: String) : super(message)
|
constructor(message: String) : super(message)
|
||||||
constructor(message: String, serviceUUIds: List<ParcelUuid?>) : super("$message service UUIDs: $serviceUUIds")
|
constructor(message: String, serviceUUIds: List<ParcelUuid?>) : super("$message service UUIDs: $serviceUUIds")
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.excepti
|
||||||
open class FailedToConnectException : Exception {
|
open class FailedToConnectException : Exception {
|
||||||
constructor() : super()
|
constructor() : super()
|
||||||
constructor(message: String?) : super(message)
|
constructor(message: String?) : super(message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.excepti
|
||||||
class MessageIOException : Exception {
|
class MessageIOException : Exception {
|
||||||
constructor(msg: String) : super(msg)
|
constructor(msg: String) : super(msg)
|
||||||
constructor(cause: Throwable) : super("Caught Exception during Message I/O", cause)
|
constructor(cause: Throwable) : super("Caught Exception during Message I/O", cause)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.excepti
|
||||||
open class ScanFailException : Exception {
|
open class ScanFailException : Exception {
|
||||||
constructor(message: String) : super(message)
|
constructor(message: String) : super(message)
|
||||||
constructor(errorCode: Int) : super("errorCode$errorCode")
|
constructor(errorCode: Int) : super("errorCode$errorCode")
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,4 +8,4 @@ class ScanFailFoundTooManyException(devices: List<BleDiscoveredDevice>) : ScanFa
|
||||||
private val devices: List<BleDiscoveredDevice> = ArrayList(devices)
|
private val devices: List<BleDiscoveredDevice> = ArrayList(devices)
|
||||||
val discoveredDevices: List<BleDiscoveredDevice>
|
val discoveredDevices: List<BleDiscoveredDevice>
|
||||||
get() = Collections.unmodifiableList(devices)
|
get() = Collections.unmodifiableList(devices)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
||||||
|
|
||||||
class ScanFailNotFoundException : ScanFailException("No Pod found")
|
class ScanFailNotFoundException : ScanFailException("No Pod found")
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions
|
||||||
|
|
||||||
class ServiceNotFoundException(serviceUuid: String) : FailedToConnectException("service not found: $serviceUuid")
|
class ServiceNotFoundException(serviceUuid: String) : FailedToConnectException("service not found: $serviceUuid")
|
||||||
|
|
|
@ -2,4 +2,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.excepti
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.command.BleCommand
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.command.BleCommand
|
||||||
|
|
||||||
class UnexpectedCommandException(val cmd: BleCommand) : Exception("Unexpected command: ${cmd}")
|
class UnexpectedCommandException(val cmd: BleCommand) : Exception("Unexpected command: $cmd")
|
||||||
|
|
|
@ -97,4 +97,4 @@ class BleIO(private val aapsLogger: AAPSLogger, private val chars: Map<Character
|
||||||
|
|
||||||
private const val DEFAULT_IO_TIMEOUT_MS = 1000
|
private const val DEFAULT_IO_TIMEOUT_MS = 1000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,4 +19,4 @@ enum class CharacteristicType(val value: String) {
|
||||||
values().firstOrNull { it.value == value }
|
values().firstOrNull { it.value == value }
|
||||||
?: throw IllegalArgumentException("Unknown Characteristic Type: $value")
|
?: throw IllegalArgumentException("Unknown Characteristic Type: $value")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.io
|
||||||
|
|
||||||
enum class IOState {
|
enum class IOState {
|
||||||
IDLE, WRITING, READING
|
IDLE, WRITING, READING
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message
|
||||||
import info.nightscout.androidaps.utils.extensions.toHex
|
import info.nightscout.androidaps.utils.extensions.toHex
|
||||||
|
|
||||||
class CrcMismatchException(val expected: Long, val actual: Long, val payload: ByteArray) :
|
class CrcMismatchException(val expected: Long, val actual: Long, val payload: ByteArray) :
|
||||||
Exception("CRC mismatch. Actual: ${actual}. Expected: ${expected}. Payload: ${payload.toHex()}")
|
Exception("CRC mismatch. Actual: $actual. Expected: $expected. Payload: ${payload.toHex()}")
|
||||||
|
|
|
@ -2,4 +2,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message
|
||||||
|
|
||||||
import info.nightscout.androidaps.utils.extensions.toHex
|
import info.nightscout.androidaps.utils.extensions.toHex
|
||||||
|
|
||||||
class IncorrectPacketException(val expectedIndex: Byte, val payload: ByteArray) : Exception("Invalid payload: ${payload.toHex()}. Expected index: ${expectedIndex}")
|
class IncorrectPacketException(val expectedIndex: Byte, val payload: ByteArray) : Exception("Invalid payload: ${payload.toHex()}. Expected index: $expectedIndex")
|
||||||
|
|
|
@ -63,4 +63,4 @@ class MessageIO(private val aapsLogger: AAPSLogger, private val bleIO: BleIO) {
|
||||||
throw MessageIOException(cause = e)
|
throw MessageIOException(cause = e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,8 @@ data class MessagePacket(
|
||||||
val gateway: Boolean = false,
|
val gateway: Boolean = false,
|
||||||
val sas: Boolean = false, // TODO: understand
|
val sas: Boolean = false, // TODO: understand
|
||||||
val tfs: Boolean = false, // TODO: understand
|
val tfs: Boolean = false, // TODO: understand
|
||||||
val version: Short = 0.toShort()) {
|
val version: Short = 0.toShort()
|
||||||
|
) {
|
||||||
|
|
||||||
fun asByteArray(): ByteArray {
|
fun asByteArray(): ByteArray {
|
||||||
val bb = ByteBuffer.allocate(16 + payload.size)
|
val bb = ByteBuffer.allocate(16 + payload.size)
|
||||||
|
@ -139,8 +140,7 @@ private class Flag(var value: Int = 0) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun Byte.toUnsignedInt() = this.toInt() and 0xff
|
internal fun Byte.toUnsignedInt() = this.toInt() and 0xff
|
||||||
|
|
|
@ -12,4 +12,4 @@ enum class MessageType(val value: Byte) {
|
||||||
MessageType.values().firstOrNull { it.value == value }
|
MessageType.values().firstOrNull { it.value == value }
|
||||||
?: throw IllegalArgumentException("Unknown MessageType: $value")
|
?: throw IllegalArgumentException("Unknown MessageType: $value")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
|
||||||
firstPacket.size < FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS ->
|
firstPacket.size < FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS ->
|
||||||
throw IncorrectPacketException(0, firstPacket)
|
throw IncorrectPacketException(0, firstPacket)
|
||||||
|
|
||||||
fullFragments == 0 -> {
|
fullFragments == 0 -> {
|
||||||
crc = ByteBuffer.wrap(firstPacket.copyOfRange(2, 6)).int.toUnsignedLong()
|
crc = ByteBuffer.wrap(firstPacket.copyOfRange(2, 6)).int.toUnsignedLong()
|
||||||
val rest = firstPacket[6]
|
val rest = firstPacket[6]
|
||||||
val end = min(rest + FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS, BlePacket.MAX_SIZE)
|
val end = min(rest + FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS, BlePacket.MAX_SIZE)
|
||||||
|
@ -41,10 +41,10 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// With middle packets
|
// With middle packets
|
||||||
firstPacket.size < BlePacket.MAX_SIZE ->
|
firstPacket.size < BlePacket.MAX_SIZE ->
|
||||||
throw IncorrectPacketException(0, firstPacket)
|
throw IncorrectPacketException(0, firstPacket)
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
fragments.add(firstPacket.copyOfRange(FirstBlePacket.HEADER_SIZE_WITH_MIDDLE_PACKETS, BlePacket.MAX_SIZE))
|
fragments.add(firstPacket.copyOfRange(FirstBlePacket.HEADER_SIZE_WITH_MIDDLE_PACKETS, BlePacket.MAX_SIZE))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
|
||||||
}
|
}
|
||||||
expectedIndex++
|
expectedIndex++
|
||||||
when {
|
when {
|
||||||
idx < fullFragments -> { // this is a middle fragment
|
idx < fullFragments -> { // this is a middle fragment
|
||||||
if (packet.size < BlePacket.MAX_SIZE) {
|
if (packet.size < BlePacket.MAX_SIZE) {
|
||||||
throw IncorrectPacketException(idx.toByte(), packet)
|
throw IncorrectPacketException(idx.toByte(), packet)
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
|
||||||
fragments.add(packet.copyOfRange(LastBlePacket.HEADER_SIZE, packet.size))
|
fragments.add(packet.copyOfRange(LastBlePacket.HEADER_SIZE, packet.size))
|
||||||
}
|
}
|
||||||
|
|
||||||
idx > fullFragments -> { // this is the extra fragment
|
idx > fullFragments -> { // this is the extra fragment
|
||||||
val size = packet[1].toInt()
|
val size = packet[1].toInt()
|
||||||
if (packet.size < LastOptionalPlusOneBlePacket.HEADER_SIZE + size) {
|
if (packet.size < LastOptionalPlusOneBlePacket.HEADER_SIZE + size) {
|
||||||
throw IncorrectPacketException(idx.toByte(), packet)
|
throw IncorrectPacketException(idx.toByte(), packet)
|
||||||
|
@ -103,7 +103,6 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
|
||||||
}
|
}
|
||||||
return bytes.copyOfRange(0, bytes.size)
|
return bytes.copyOfRange(0, bytes.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun Int.toUnsignedLong() = this.toLong() and 0xffffffffL
|
internal fun Int.toUnsignedLong() = this.toLong() and 0xffffffffL
|
||||||
|
|
|
@ -15,51 +15,63 @@ internal class PayloadSplitter(private val payload: ByteArray) {
|
||||||
val crc32 = payload.crc32()
|
val crc32 = payload.crc32()
|
||||||
if (payload.size <= FirstBlePacket.CAPACITY_WITH_THE_OPTIONAL_PLUS_ONE_PACKET) {
|
if (payload.size <= FirstBlePacket.CAPACITY_WITH_THE_OPTIONAL_PLUS_ONE_PACKET) {
|
||||||
val end = min(FirstBlePacket.CAPACITY_WITHOUT_MIDDLE_PACKETS, payload.size)
|
val end = min(FirstBlePacket.CAPACITY_WITHOUT_MIDDLE_PACKETS, payload.size)
|
||||||
ret.add(FirstBlePacket(
|
ret.add(
|
||||||
totalFragments = 0,
|
FirstBlePacket(
|
||||||
payload = payload.copyOfRange(0, end),
|
totalFragments = 0,
|
||||||
size = payload.size.toByte(),
|
payload = payload.copyOfRange(0, end),
|
||||||
crc32 = crc32,
|
size = payload.size.toByte(),
|
||||||
))
|
crc32 = crc32,
|
||||||
|
)
|
||||||
|
)
|
||||||
if (payload.size > FirstBlePacket.CAPACITY_WITHOUT_MIDDLE_PACKETS) {
|
if (payload.size > FirstBlePacket.CAPACITY_WITHOUT_MIDDLE_PACKETS) {
|
||||||
ret.add(LastOptionalPlusOneBlePacket(
|
ret.add(
|
||||||
index = 1,
|
LastOptionalPlusOneBlePacket(
|
||||||
payload = payload.copyOfRange(end, payload.size),
|
index = 1,
|
||||||
size = (payload.size - end).toByte(),
|
payload = payload.copyOfRange(end, payload.size),
|
||||||
))
|
size = (payload.size - end).toByte(),
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
val middleFragments = (payload.size - FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS) / MiddleBlePacket.CAPACITY
|
val middleFragments = (payload.size - FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS) / MiddleBlePacket.CAPACITY
|
||||||
val rest = ((payload.size - middleFragments * MiddleBlePacket.CAPACITY) - FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS).toByte()
|
val rest = ((payload.size - middleFragments * MiddleBlePacket.CAPACITY) - FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS).toByte()
|
||||||
ret.add(FirstBlePacket(
|
ret.add(
|
||||||
totalFragments = (middleFragments + 1).toByte(),
|
FirstBlePacket(
|
||||||
payload = payload.copyOfRange(0, FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS),
|
totalFragments = (middleFragments + 1).toByte(),
|
||||||
))
|
payload = payload.copyOfRange(0, FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS),
|
||||||
|
)
|
||||||
|
)
|
||||||
for (i in 1..middleFragments) {
|
for (i in 1..middleFragments) {
|
||||||
val p = if (i == 1) {
|
val p = if (i == 1) {
|
||||||
payload.copyOfRange(FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS, FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS + MiddleBlePacket.CAPACITY)
|
payload.copyOfRange(FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS, FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS + MiddleBlePacket.CAPACITY)
|
||||||
} else {
|
} else {
|
||||||
payload.copyOfRange(FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS + (i - 1) * MiddleBlePacket.CAPACITY, FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS + i * MiddleBlePacket.CAPACITY)
|
payload.copyOfRange(FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS + (i - 1) * MiddleBlePacket.CAPACITY, FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS + i * MiddleBlePacket.CAPACITY)
|
||||||
}
|
}
|
||||||
ret.add(MiddleBlePacket(
|
ret.add(
|
||||||
index = i.toByte(),
|
MiddleBlePacket(
|
||||||
payload = p,
|
index = i.toByte(),
|
||||||
))
|
payload = p,
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
val end = min(LastBlePacket.CAPACITY, rest.toInt())
|
val end = min(LastBlePacket.CAPACITY, rest.toInt())
|
||||||
ret.add(LastBlePacket(
|
ret.add(
|
||||||
index = (middleFragments + 1).toByte(),
|
LastBlePacket(
|
||||||
size = rest,
|
index = (middleFragments + 1).toByte(),
|
||||||
payload = payload.copyOfRange(middleFragments * MiddleBlePacket.CAPACITY + FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS, middleFragments * MiddleBlePacket.CAPACITY + FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS + end),
|
size = rest,
|
||||||
crc32 = crc32,
|
payload = payload.copyOfRange(middleFragments * MiddleBlePacket.CAPACITY + FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS, middleFragments * MiddleBlePacket.CAPACITY + FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS + end),
|
||||||
))
|
crc32 = crc32,
|
||||||
|
)
|
||||||
|
)
|
||||||
if (rest > LastBlePacket.CAPACITY) {
|
if (rest > LastBlePacket.CAPACITY) {
|
||||||
ret.add(LastOptionalPlusOneBlePacket(
|
ret.add(
|
||||||
index = (middleFragments + 2).toByte(),
|
LastOptionalPlusOneBlePacket(
|
||||||
size = (rest - LastBlePacket.CAPACITY).toByte(),
|
index = (middleFragments + 2).toByte(),
|
||||||
payload = payload.copyOfRange(middleFragments * MiddleBlePacket.CAPACITY + FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS + LastBlePacket.CAPACITY, payload.size),
|
size = (rest - LastBlePacket.CAPACITY).toByte(),
|
||||||
))
|
payload = payload.copyOfRange(middleFragments * MiddleBlePacket.CAPACITY + FirstBlePacket.CAPACITY_WITH_MIDDLE_PACKETS + LastBlePacket.CAPACITY, payload.size),
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,21 +18,21 @@ class StringLengthPrefixEncoding {
|
||||||
var remaining = payload
|
var remaining = payload
|
||||||
for ((index, key) in keys.withIndex()) {
|
for ((index, key) in keys.withIndex()) {
|
||||||
when {
|
when {
|
||||||
remaining.size < key.length ->
|
remaining.size < key.length ->
|
||||||
throw MessageIOException("Payload too short: ${payload.toHex()} for key: ${key}")
|
throw MessageIOException("Payload too short: ${payload.toHex()} for key: $key")
|
||||||
!(remaining.copyOfRange(0, key.length).decodeToString() == key) ->
|
!(remaining.copyOfRange(0, key.length).decodeToString() == key) ->
|
||||||
throw MessageIOException("Key not found: ${key} in ${payload.toHex()}")
|
throw MessageIOException("Key not found: $key in ${payload.toHex()}")
|
||||||
// last key can be empty, no length
|
// last key can be empty, no length
|
||||||
index == keys.size - 1 && remaining.size == key.length ->
|
index == keys.size - 1 && remaining.size == key.length ->
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
remaining.size < key.length + LENGTH_BYTES ->
|
remaining.size < key.length + LENGTH_BYTES ->
|
||||||
throw MessageIOException("Length not found: for ${key} in ${payload.toHex()}")
|
throw MessageIOException("Length not found: for $key in ${payload.toHex()}")
|
||||||
}
|
}
|
||||||
remaining = remaining.copyOfRange(key.length, remaining.size)
|
remaining = remaining.copyOfRange(key.length, remaining.size)
|
||||||
val length = (remaining[0].toUnsignedInt() shl 1) or remaining[1].toUnsignedInt()
|
val length = (remaining[0].toUnsignedInt() shl 1) or remaining[1].toUnsignedInt()
|
||||||
if (length > remaining.size) {
|
if (length > remaining.size) {
|
||||||
throw MessageIOException("Payload too short, looking for length ${length} for ${key} in ${payload.toHex()}")
|
throw MessageIOException("Payload too short, looking for length $length for $key in ${payload.toHex()}")
|
||||||
}
|
}
|
||||||
ret[index] = remaining.copyOfRange(LENGTH_BYTES, LENGTH_BYTES + length)
|
ret[index] = remaining.copyOfRange(LENGTH_BYTES, LENGTH_BYTES + length)
|
||||||
remaining = remaining.copyOfRange(LENGTH_BYTES + length, remaining.size)
|
remaining = remaining.copyOfRange(LENGTH_BYTES + length, remaining.size)
|
||||||
|
@ -60,4 +60,4 @@ class StringLengthPrefixEncoding {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,4 +92,3 @@ data class LastOptionalPlusOneBlePacket(val index: Byte, val payload: ByteArray,
|
||||||
internal const val HEADER_SIZE = 2
|
internal const val HEADER_SIZE = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -253,4 +253,4 @@ private fun aesCmac(key: ByteArray, data: ByteArray, result: ByteArray) {
|
||||||
mac.init(KeyParameter(key))
|
mac.init(KeyParameter(key))
|
||||||
mac.update(data, 0, data.size)
|
mac.update(data, 0, data.size)
|
||||||
mac.doFinal(result, 0)
|
mac.doFinal(result, 0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,4 +17,4 @@ data class PairMessage(
|
||||||
sequenceNumber = sequenceNumber,
|
sequenceNumber = sequenceNumber,
|
||||||
sas = true // TODO: understand why this is true for PairMessages
|
sas = true // TODO: understand why this is true for PairMessages
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,7 +15,6 @@ class BleDiscoveredDevice(val scanResult: ScanResult, private val scanRecord: Sc
|
||||||
val serviceUuids = scanRecord.serviceUuids
|
val serviceUuids = scanRecord.serviceUuids
|
||||||
if (serviceUuids.size != 9) {
|
if (serviceUuids.size != 9) {
|
||||||
throw DiscoveredInvalidPodException("Expected 9 service UUIDs, got" + serviceUuids.size, serviceUuids)
|
throw DiscoveredInvalidPodException("Expected 9 service UUIDs, got" + serviceUuids.size, serviceUuids)
|
||||||
|
|
||||||
}
|
}
|
||||||
if (extractUUID16(serviceUuids[0]) != MAIN_SERVICE_UUID) {
|
if (extractUUID16(serviceUuids[0]) != MAIN_SERVICE_UUID) {
|
||||||
// this is the service that we filtered for
|
// this is the service that we filtered for
|
||||||
|
@ -79,4 +78,4 @@ class BleDiscoveredDevice(val scanResult: ScanResult, private val scanRecord: Sc
|
||||||
lotNo = parseLotNo()
|
lotNo = parseLotNo()
|
||||||
sequenceNo = parseSeqNo()
|
sequenceNo = parseSeqNo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,4 +45,4 @@ class PodScanner(private val logger: AAPSLogger, private val bluetoothAdapter: B
|
||||||
const val POD_ID_NOT_ACTIVATED = 0xFFFFFFFFL
|
const val POD_ID_NOT_ACTIVATED = 0xFFFFFFFFL
|
||||||
private const val SCAN_DURATION_MS = 5000
|
private const val SCAN_DURATION_MS = 5000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,5 +45,4 @@ class ScanCollector(private val logger: AAPSLogger, private val podID: Long) : S
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(ret)
|
return Collections.unmodifiableList(ret)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -3,4 +3,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.status
|
||||||
enum class ConnectionStatus {
|
enum class ConnectionStatus {
|
||||||
CONNECTED,
|
CONNECTED,
|
||||||
NOT_CONNECTED;
|
NOT_CONNECTED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,4 +20,3 @@ sealed class PodEvent {
|
||||||
class CommandSent(val command: Command) : PodEvent()
|
class CommandSent(val command: Command) : PodEvent()
|
||||||
class ResponseReceived(val response: Response) : PodEvent()
|
class ResponseReceived(val response: Response) : PodEvent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,14 @@ class DeactivateCommand private constructor(
|
||||||
) : NonceEnabledCommand(CommandType.DEACTIVATE, uniqueId, sequenceNumber, multiCommandFlag, nonce) {
|
) : NonceEnabledCommand(CommandType.DEACTIVATE, uniqueId, sequenceNumber, multiCommandFlag, nonce) {
|
||||||
|
|
||||||
override val encoded: ByteArray
|
override val encoded: ByteArray
|
||||||
get() = appendCrc(ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
get() = appendCrc(
|
||||||
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
|
ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
||||||
.put(commandType.value) //
|
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
|
||||||
.put(BODY_LENGTH) //
|
.put(commandType.value) //
|
||||||
.putInt(nonce) //
|
.put(BODY_LENGTH) //
|
||||||
.array())
|
.putInt(nonce) //
|
||||||
|
.array()
|
||||||
|
)
|
||||||
|
|
||||||
override fun toString(): String = "DeactivateCommand{" +
|
override fun toString(): String = "DeactivateCommand{" +
|
||||||
"nonce=" + nonce +
|
"nonce=" + nonce +
|
||||||
|
@ -39,4 +41,4 @@ class DeactivateCommand private constructor(
|
||||||
private const val LENGTH: Short = 6
|
private const val LENGTH: Short = 6
|
||||||
private const val BODY_LENGTH: Byte = 4
|
private const val BODY_LENGTH: Byte = 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,14 @@ class GetStatusCommand private constructor(
|
||||||
) : HeaderEnabledCommand(CommandType.GET_STATUS, uniqueId, sequenceNumber, multiCommandFlag) {
|
) : HeaderEnabledCommand(CommandType.GET_STATUS, uniqueId, sequenceNumber, multiCommandFlag) {
|
||||||
|
|
||||||
override val encoded: ByteArray
|
override val encoded: ByteArray
|
||||||
get() = appendCrc(ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
get() = appendCrc(
|
||||||
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
|
ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
||||||
.put(commandType.value) //
|
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
|
||||||
.put(BODY_LENGTH) //
|
.put(commandType.value) //
|
||||||
.put(statusResponseType.value) //
|
.put(BODY_LENGTH) //
|
||||||
.array())
|
.put(statusResponseType.value) //
|
||||||
|
.array()
|
||||||
|
)
|
||||||
|
|
||||||
class Builder : HeaderEnabledCommandBuilder<Builder, GetStatusCommand>() {
|
class Builder : HeaderEnabledCommandBuilder<Builder, GetStatusCommand>() {
|
||||||
|
|
||||||
|
@ -35,7 +37,6 @@ class GetStatusCommand private constructor(
|
||||||
|
|
||||||
return GetStatusCommand(uniqueId!!, sequenceNumber!!, multiCommandFlag, statusResponseType!!)
|
return GetStatusCommand(uniqueId!!, sequenceNumber!!, multiCommandFlag, statusResponseType!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -43,4 +44,4 @@ class GetStatusCommand private constructor(
|
||||||
private const val LENGTH: Short = 3
|
private const val LENGTH: Short = 3
|
||||||
private const val BODY_LENGTH: Byte = 1
|
private const val BODY_LENGTH: Byte = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,14 @@ class GetVersionCommand private constructor(
|
||||||
) : HeaderEnabledCommand(CommandType.GET_VERSION, uniqueId, sequenceNumber, multiCommandFlag) {
|
) : HeaderEnabledCommand(CommandType.GET_VERSION, uniqueId, sequenceNumber, multiCommandFlag) {
|
||||||
|
|
||||||
override val encoded: ByteArray
|
override val encoded: ByteArray
|
||||||
get() = appendCrc(ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
get() = appendCrc(
|
||||||
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
|
ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
||||||
.put(commandType.value) //
|
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
|
||||||
.put(BODY_LENGTH) //
|
.put(commandType.value) //
|
||||||
.putInt(uniqueId) //
|
.put(BODY_LENGTH) //
|
||||||
.array())
|
.putInt(uniqueId) //
|
||||||
|
.array()
|
||||||
|
)
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "GetVersionCommand{" +
|
return "GetVersionCommand{" +
|
||||||
|
@ -41,4 +43,4 @@ class GetVersionCommand private constructor(
|
||||||
private const val LENGTH: Short = 6
|
private const val LENGTH: Short = 6
|
||||||
private const val BODY_LENGTH: Byte = 4
|
private const val BODY_LENGTH: Byte = 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,4 +67,4 @@ class ProgramAlertsCommand private constructor(
|
||||||
init {
|
init {
|
||||||
this.alertConfigurations = ArrayList(alertConfigurations)
|
this.alertConfigurations = ArrayList(alertConfigurations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,11 +49,13 @@ class ProgramBasalCommand private constructor(
|
||||||
val basalCommand = buffer.array()
|
val basalCommand = buffer.array()
|
||||||
val interlockCommand = interlockCommand.encoded
|
val interlockCommand = interlockCommand.encoded
|
||||||
val header: ByteArray = encodeHeader(uniqueId, sequenceNumber, (basalCommand.size + interlockCommand.size).toShort(), multiCommandFlag)
|
val header: ByteArray = encodeHeader(uniqueId, sequenceNumber, (basalCommand.size + interlockCommand.size).toShort(), multiCommandFlag)
|
||||||
return appendCrc(ByteBuffer.allocate(basalCommand.size + interlockCommand.size + header.size) //
|
return appendCrc(
|
||||||
.put(header) //
|
ByteBuffer.allocate(basalCommand.size + interlockCommand.size + header.size) //
|
||||||
.put(interlockCommand) //
|
.put(header) //
|
||||||
.put(basalCommand) //
|
.put(interlockCommand) //
|
||||||
.array())
|
.put(basalCommand) //
|
||||||
|
.array()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
@ -102,12 +104,16 @@ class ProgramBasalCommand private constructor(
|
||||||
val longInsulinProgramElements: List<BasalInsulinProgramElement> = mapTenthPulsesPerSlotToLongInsulinProgramElements(ProgramBasalUtil.mapBasalProgramToTenthPulsesPerSlot(basalProgram!!))
|
val longInsulinProgramElements: List<BasalInsulinProgramElement> = mapTenthPulsesPerSlotToLongInsulinProgramElements(ProgramBasalUtil.mapBasalProgramToTenthPulsesPerSlot(basalProgram!!))
|
||||||
val shortInsulinProgramElements = ProgramBasalUtil.mapPulsesPerSlotToShortInsulinProgramElements(pulsesPerSlot)
|
val shortInsulinProgramElements = ProgramBasalUtil.mapPulsesPerSlotToShortInsulinProgramElements(pulsesPerSlot)
|
||||||
val currentBasalInsulinProgramElement = ProgramBasalUtil.calculateCurrentLongInsulinProgramElement(longInsulinProgramElements, currentTime)
|
val currentBasalInsulinProgramElement = ProgramBasalUtil.calculateCurrentLongInsulinProgramElement(longInsulinProgramElements, currentTime)
|
||||||
val interlockCommand = ProgramInsulinCommand(uniqueId!!, sequenceNumber!!, multiCommandFlag, nonce!!,
|
val interlockCommand = ProgramInsulinCommand(
|
||||||
|
uniqueId!!, sequenceNumber!!, multiCommandFlag, nonce!!,
|
||||||
shortInsulinProgramElements, checksum, currentSlot.index, currentSlot.eighthSecondsRemaining,
|
shortInsulinProgramElements, checksum, currentSlot.index, currentSlot.eighthSecondsRemaining,
|
||||||
currentSlot.pulsesRemaining, ProgramInsulinCommand.DeliveryType.BASAL)
|
currentSlot.pulsesRemaining, ProgramInsulinCommand.DeliveryType.BASAL
|
||||||
return ProgramBasalCommand(interlockCommand, uniqueId!!, sequenceNumber!!, multiCommandFlag,
|
)
|
||||||
|
return ProgramBasalCommand(
|
||||||
|
interlockCommand, uniqueId!!, sequenceNumber!!, multiCommandFlag,
|
||||||
longInsulinProgramElements, programReminder!!, currentBasalInsulinProgramElement.index,
|
longInsulinProgramElements, programReminder!!, currentBasalInsulinProgramElement.index,
|
||||||
currentBasalInsulinProgramElement.remainingTenthPulses, currentBasalInsulinProgramElement.delayUntilNextTenthPulseInUsec)
|
currentBasalInsulinProgramElement.remainingTenthPulses, currentBasalInsulinProgramElement.delayUntilNextTenthPulseInUsec
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,4 +124,4 @@ class ProgramBasalCommand private constructor(
|
||||||
this.remainingTenthPulsesInCurrentInsulinProgramElement = remainingTenthPulsesInCurrentInsulinProgramElement
|
this.remainingTenthPulsesInCurrentInsulinProgramElement = remainingTenthPulsesInCurrentInsulinProgramElement
|
||||||
this.delayUntilNextTenthPulseInUsec = delayUntilNextTenthPulseInUsec
|
this.delayUntilNextTenthPulseInUsec = delayUntilNextTenthPulseInUsec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,15 +18,17 @@ class ProgramBeepsCommand private constructor(
|
||||||
) : HeaderEnabledCommand(CommandType.PROGRAM_BEEPS, uniqueId, sequenceNumber, multiCommandFlag) {
|
) : HeaderEnabledCommand(CommandType.PROGRAM_BEEPS, uniqueId, sequenceNumber, multiCommandFlag) {
|
||||||
|
|
||||||
override val encoded: ByteArray
|
override val encoded: ByteArray
|
||||||
get() = appendCrc(ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
get() = appendCrc(
|
||||||
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
|
ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
||||||
.put(commandType.value) //
|
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
|
||||||
.put(BODY_LENGTH) //
|
.put(commandType.value) //
|
||||||
.put(immediateBeepType.value) //
|
.put(BODY_LENGTH) //
|
||||||
.put(basalReminder.encoded) //
|
.put(immediateBeepType.value) //
|
||||||
.put(tempBasalReminder.encoded) //
|
.put(basalReminder.encoded) //
|
||||||
.put(bolusReminder.encoded) //
|
.put(tempBasalReminder.encoded) //
|
||||||
.array())
|
.put(bolusReminder.encoded) //
|
||||||
|
.array()
|
||||||
|
)
|
||||||
|
|
||||||
class Builder : HeaderEnabledCommandBuilder<Builder, ProgramBeepsCommand>() {
|
class Builder : HeaderEnabledCommandBuilder<Builder, ProgramBeepsCommand>() {
|
||||||
|
|
||||||
|
@ -70,4 +72,4 @@ class ProgramBeepsCommand private constructor(
|
||||||
private const val LENGTH: Short = 6
|
private const val LENGTH: Short = 6
|
||||||
private const val BODY_LENGTH: Byte = 4
|
private const val BODY_LENGTH: Byte = 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,11 +32,13 @@ class ProgramBolusCommand private constructor(
|
||||||
.array()
|
.array()
|
||||||
val interlockCommand = interlockCommand.encoded
|
val interlockCommand = interlockCommand.encoded
|
||||||
val header: ByteArray = encodeHeader(uniqueId, sequenceNumber, (bolusCommand.size + interlockCommand.size).toShort(), multiCommandFlag)
|
val header: ByteArray = encodeHeader(uniqueId, sequenceNumber, (bolusCommand.size + interlockCommand.size).toShort(), multiCommandFlag)
|
||||||
return appendCrc(ByteBuffer.allocate(header.size + interlockCommand.size + bolusCommand.size) //
|
return appendCrc(
|
||||||
.put(header) //
|
ByteBuffer.allocate(header.size + interlockCommand.size + bolusCommand.size) //
|
||||||
.put(interlockCommand) //
|
.put(header) //
|
||||||
.put(bolusCommand) //
|
.put(interlockCommand) //
|
||||||
.array())
|
.put(bolusCommand) //
|
||||||
|
.array()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
@ -82,8 +84,10 @@ class ProgramBolusCommand private constructor(
|
||||||
|
|
||||||
val numberOfPulses = Math.round(numberOfUnits!! * 20).toShort()
|
val numberOfPulses = Math.round(numberOfUnits!! * 20).toShort()
|
||||||
val byte10And11 = (numberOfPulses * delayBetweenPulsesInEighthSeconds!!).toShort()
|
val byte10And11 = (numberOfPulses * delayBetweenPulsesInEighthSeconds!!).toShort()
|
||||||
val interlockCommand = ProgramInsulinCommand(uniqueId!!, sequenceNumber!!, multiCommandFlag, nonce!!, listOf(BolusShortInsulinProgramElement(numberOfPulses)), calculateChecksum(0x01.toByte(), byte10And11, numberOfPulses),
|
val interlockCommand = ProgramInsulinCommand(
|
||||||
0x01.toByte(), byte10And11, numberOfPulses, ProgramInsulinCommand.DeliveryType.BOLUS)
|
uniqueId!!, sequenceNumber!!, multiCommandFlag, nonce!!, listOf(BolusShortInsulinProgramElement(numberOfPulses)), calculateChecksum(0x01.toByte(), byte10And11, numberOfPulses),
|
||||||
|
0x01.toByte(), byte10And11, numberOfPulses, ProgramInsulinCommand.DeliveryType.BOLUS
|
||||||
|
)
|
||||||
val delayUntilFirstTenthPulseInUsec = delayBetweenPulsesInEighthSeconds!! / 8 * 100000
|
val delayUntilFirstTenthPulseInUsec = delayBetweenPulsesInEighthSeconds!! / 8 * 100000
|
||||||
return ProgramBolusCommand(interlockCommand, uniqueId!!, sequenceNumber!!, multiCommandFlag, programReminder!!, (numberOfPulses * 10).toShort(), delayUntilFirstTenthPulseInUsec)
|
return ProgramBolusCommand(interlockCommand, uniqueId!!, sequenceNumber!!, multiCommandFlag, programReminder!!, (numberOfPulses * 10).toShort(), delayUntilFirstTenthPulseInUsec)
|
||||||
}
|
}
|
||||||
|
@ -94,12 +98,14 @@ class ProgramBolusCommand private constructor(
|
||||||
private const val LENGTH: Short = 15
|
private const val LENGTH: Short = 15
|
||||||
private const val BODY_LENGTH: Byte = 13
|
private const val BODY_LENGTH: Byte = 13
|
||||||
private fun calculateChecksum(numberOfSlots: Byte, byte10And11: Short, numberOfPulses: Short): Short {
|
private fun calculateChecksum(numberOfSlots: Byte, byte10And11: Short, numberOfPulses: Short): Short {
|
||||||
return MessageUtil.calculateChecksum(ByteBuffer.allocate(7) //
|
return MessageUtil.calculateChecksum(
|
||||||
.put(numberOfSlots) //
|
ByteBuffer.allocate(7) //
|
||||||
.putShort(byte10And11) //
|
.put(numberOfSlots) //
|
||||||
.putShort(numberOfPulses) //
|
.putShort(byte10And11) //
|
||||||
.putShort(numberOfPulses) //
|
.putShort(numberOfPulses) //
|
||||||
.array())
|
.putShort(numberOfPulses) //
|
||||||
|
.array()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,9 @@ class ProgramInsulinCommand internal constructor(
|
||||||
uniqueId: Int,
|
uniqueId: Int,
|
||||||
sequenceNumber: Short,
|
sequenceNumber: Short,
|
||||||
multiCommandFlag: Boolean,
|
multiCommandFlag: Boolean,
|
||||||
nonce: Int, insulinProgramElements:
|
nonce: Int,
|
||||||
List<ShortInsulinProgramElement>,
|
insulinProgramElements:
|
||||||
|
List<ShortInsulinProgramElement>,
|
||||||
private val checksum: Short,
|
private val checksum: Short,
|
||||||
private val byte9: Byte,
|
private val byte9: Byte,
|
||||||
private val byte10And11: Short,
|
private val byte10And11: Short,
|
||||||
|
@ -66,4 +67,4 @@ class ProgramInsulinCommand internal constructor(
|
||||||
", multiCommandFlag=" + multiCommandFlag +
|
", multiCommandFlag=" + multiCommandFlag +
|
||||||
'}'
|
'}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,9 +59,11 @@ class ProgramTempBasalCommand private constructor(
|
||||||
val tenthPulsesPerSlot = ProgramTempBasalUtil.mapTempBasalToTenthPulsesPerSlot(durationInSlots.toInt(), rateInUnitsPerHour!!)
|
val tenthPulsesPerSlot = ProgramTempBasalUtil.mapTempBasalToTenthPulsesPerSlot(durationInSlots.toInt(), rateInUnitsPerHour!!)
|
||||||
val shortInsulinProgramElements = ProgramTempBasalUtil.mapPulsesPerSlotToShortInsulinProgramElements(pulsesPerSlot)
|
val shortInsulinProgramElements = ProgramTempBasalUtil.mapPulsesPerSlotToShortInsulinProgramElements(pulsesPerSlot)
|
||||||
val insulinProgramElements = ProgramTempBasalUtil.mapTenthPulsesPerSlotToLongInsulinProgramElements(tenthPulsesPerSlot)
|
val insulinProgramElements = ProgramTempBasalUtil.mapTenthPulsesPerSlotToLongInsulinProgramElements(tenthPulsesPerSlot)
|
||||||
val interlockCommand = ProgramInsulinCommand(uniqueId!!, sequenceNumber!!, multiCommandFlag, nonce!!, shortInsulinProgramElements,
|
val interlockCommand = ProgramInsulinCommand(
|
||||||
|
uniqueId!!, sequenceNumber!!, multiCommandFlag, nonce!!, shortInsulinProgramElements,
|
||||||
ProgramTempBasalUtil.calculateChecksum(durationInSlots, pulsesPerSlot[0], pulsesPerSlot), durationInSlots,
|
ProgramTempBasalUtil.calculateChecksum(durationInSlots, pulsesPerSlot[0], pulsesPerSlot), durationInSlots,
|
||||||
0x3840.toShort(), pulsesPerSlot[0], ProgramInsulinCommand.DeliveryType.TEMP_BASAL)
|
0x3840.toShort(), pulsesPerSlot[0], ProgramInsulinCommand.DeliveryType.TEMP_BASAL
|
||||||
|
)
|
||||||
return ProgramTempBasalCommand(interlockCommand, uniqueId!!, sequenceNumber!!, multiCommandFlag, programReminder!!, insulinProgramElements)
|
return ProgramTempBasalCommand(interlockCommand, uniqueId!!, sequenceNumber!!, multiCommandFlag, programReminder!!, insulinProgramElements)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,10 +93,12 @@ class ProgramTempBasalCommand private constructor(
|
||||||
val tempBasalCommand = buffer.array()
|
val tempBasalCommand = buffer.array()
|
||||||
val interlockCommand = interlockCommand.encoded
|
val interlockCommand = interlockCommand.encoded
|
||||||
val header: ByteArray = encodeHeader(uniqueId, sequenceNumber, (tempBasalCommand.size + interlockCommand.size).toShort(), multiCommandFlag)
|
val header: ByteArray = encodeHeader(uniqueId, sequenceNumber, (tempBasalCommand.size + interlockCommand.size).toShort(), multiCommandFlag)
|
||||||
return appendCrc(ByteBuffer.allocate(header.size + interlockCommand.size + tempBasalCommand.size) //
|
return appendCrc(
|
||||||
.put(header) //
|
ByteBuffer.allocate(header.size + interlockCommand.size + tempBasalCommand.size) //
|
||||||
.put(interlockCommand) //
|
.put(header) //
|
||||||
.put(tempBasalCommand) //
|
.put(interlockCommand) //
|
||||||
.array())
|
.put(tempBasalCommand) //
|
||||||
|
.array()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,17 +16,19 @@ class SetUniqueIdCommand private constructor(
|
||||||
) : HeaderEnabledCommand(CommandType.SET_UNIQUE_ID, uniqueId, sequenceNumber, multiCommandFlag) {
|
) : HeaderEnabledCommand(CommandType.SET_UNIQUE_ID, uniqueId, sequenceNumber, multiCommandFlag) {
|
||||||
|
|
||||||
override val encoded: ByteArray
|
override val encoded: ByteArray
|
||||||
get() = appendCrc(ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
get() = appendCrc(
|
||||||
.put(encodeHeader(DEFAULT_UNIQUE_ID, sequenceNumber, LENGTH, multiCommandFlag)) //
|
ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
||||||
.put(commandType.value) //
|
.put(encodeHeader(DEFAULT_UNIQUE_ID, sequenceNumber, LENGTH, multiCommandFlag)) //
|
||||||
.put(BODY_LENGTH) //
|
.put(commandType.value) //
|
||||||
.putInt(uniqueId) //
|
.put(BODY_LENGTH) //
|
||||||
.put(0x14.toByte()) // FIXME ??
|
.putInt(uniqueId) //
|
||||||
.put(0x04.toByte()) // FIXME ??
|
.put(0x14.toByte()) // FIXME ??
|
||||||
.put(encodeInitializationTime(initializationTime)) //
|
.put(0x04.toByte()) // FIXME ??
|
||||||
.putInt(lotNumber) //
|
.put(encodeInitializationTime(initializationTime)) //
|
||||||
.putInt(podSequenceNumber) //
|
.putInt(lotNumber) //
|
||||||
.array())
|
.putInt(podSequenceNumber) //
|
||||||
|
.array()
|
||||||
|
)
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "SetUniqueIdCommand{" +
|
return "SetUniqueIdCommand{" +
|
||||||
|
@ -78,12 +80,12 @@ class SetUniqueIdCommand private constructor(
|
||||||
val instance = Calendar.getInstance()
|
val instance = Calendar.getInstance()
|
||||||
instance.time = date
|
instance.time = date
|
||||||
return byteArrayOf( //
|
return byteArrayOf( //
|
||||||
(instance[Calendar.MONTH] + 1).toByte(), //
|
(instance[Calendar.MONTH] + 1).toByte(), //
|
||||||
instance[Calendar.DATE].toByte(), //
|
instance[Calendar.DATE].toByte(), //
|
||||||
(instance[Calendar.YEAR] % 100).toByte(), //
|
(instance[Calendar.YEAR] % 100).toByte(), //
|
||||||
instance[Calendar.HOUR_OF_DAY].toByte(), //
|
instance[Calendar.HOUR_OF_DAY].toByte(), //
|
||||||
instance[Calendar.MINUTE].toByte() //
|
instance[Calendar.MINUTE].toByte() //
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,15 @@ class SilenceAlertsCommand private constructor(
|
||||||
|
|
||||||
override val encoded: ByteArray
|
override val encoded: ByteArray
|
||||||
get() =
|
get() =
|
||||||
appendCrc(ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
appendCrc(
|
||||||
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
|
ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
||||||
.put(commandType.value) //
|
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
|
||||||
.put(BODY_LENGTH) //
|
.put(commandType.value) //
|
||||||
.putInt(nonce) //
|
.put(BODY_LENGTH) //
|
||||||
.put(AlertUtil.encodeAlertSet(alertTypes)) //
|
.putInt(nonce) //
|
||||||
.array())
|
.put(AlertUtil.encodeAlertSet(alertTypes)) //
|
||||||
|
.array()
|
||||||
|
)
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "SilenceAlertsCommand{" +
|
return "SilenceAlertsCommand{" +
|
||||||
|
@ -57,4 +59,4 @@ class SilenceAlertsCommand private constructor(
|
||||||
private const val LENGTH = 7.toShort()
|
private const val LENGTH = 7.toShort()
|
||||||
private const val BODY_LENGTH = 5.toByte()
|
private const val BODY_LENGTH = 5.toByte()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,13 +19,15 @@ class StopDeliveryCommand private constructor(
|
||||||
|
|
||||||
override val encoded: ByteArray
|
override val encoded: ByteArray
|
||||||
get() {
|
get() {
|
||||||
return appendCrc(ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
return appendCrc(
|
||||||
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
|
ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
|
||||||
.put(commandType.value) //
|
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
|
||||||
.put(BODY_LENGTH) //
|
.put(commandType.value) //
|
||||||
.putInt(nonce) //
|
.put(BODY_LENGTH) //
|
||||||
.put((beepType.value.toInt() shl 4 or deliveryType.encoded[0].toInt()).toByte()) //
|
.putInt(nonce) //
|
||||||
.array())
|
.put((beepType.value.toInt() shl 4 or deliveryType.encoded[0].toInt()).toByte()) //
|
||||||
|
.array()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
@ -81,4 +83,4 @@ class StopDeliveryCommand private constructor(
|
||||||
private const val LENGTH: Short = 7
|
private const val LENGTH: Short = 7
|
||||||
private const val BODY_LENGTH: Byte = 5
|
private const val BODY_LENGTH: Byte = 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,4 +6,4 @@ import java.io.Serializable
|
||||||
interface Command : Encodable, Serializable {
|
interface Command : Encodable, Serializable {
|
||||||
|
|
||||||
val commandType: CommandType
|
val commandType: CommandType
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,12 @@ enum class CommandType(val value: Byte) {
|
||||||
GET_VERSION(0x07.toByte()),
|
GET_VERSION(0x07.toByte()),
|
||||||
GET_STATUS(0x0e.toByte()),
|
GET_STATUS(0x0e.toByte()),
|
||||||
SILENCE_ALERTS(0x11.toByte()),
|
SILENCE_ALERTS(0x11.toByte()),
|
||||||
PROGRAM_BASAL(0x13.toByte()), // Always preceded by 0x1a
|
PROGRAM_BASAL(0x13.toByte()), // Always preceded by 0x1a
|
||||||
PROGRAM_TEMP_BASAL(0x16.toByte()), // Always preceded by 0x1a
|
PROGRAM_TEMP_BASAL(0x16.toByte()), // Always preceded by 0x1a
|
||||||
PROGRAM_BOLUS(0x17.toByte()), // Always preceded by 0x1a
|
PROGRAM_BOLUS(0x17.toByte()), // Always preceded by 0x1a
|
||||||
PROGRAM_ALERTS(0x19.toByte()),
|
PROGRAM_ALERTS(0x19.toByte()),
|
||||||
PROGRAM_INSULIN(0x1a.toByte()), // Always followed by one of: 0x13, 0x16, 0x17
|
PROGRAM_INSULIN(0x1a.toByte()), // Always followed by one of: 0x13, 0x16, 0x17
|
||||||
DEACTIVATE(0x1c.toByte()),
|
DEACTIVATE(0x1c.toByte()),
|
||||||
PROGRAM_BEEPS(0x1e.toByte()),
|
PROGRAM_BEEPS(0x1e.toByte()),
|
||||||
STOP_DELIVERY(0x1f.toByte());
|
STOP_DELIVERY(0x1f.toByte());
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,4 +6,4 @@ abstract class NonceEnabledCommand protected constructor(
|
||||||
sequenceNumber: Short,
|
sequenceNumber: Short,
|
||||||
multiCommandFlag: Boolean,
|
multiCommandFlag: Boolean,
|
||||||
protected val nonce: Int
|
protected val nonce: Int
|
||||||
) : HeaderEnabledCommand(commandType, uniqueId, sequenceNumber, multiCommandFlag)
|
) : HeaderEnabledCommand(commandType, uniqueId, sequenceNumber, multiCommandFlag)
|
||||||
|
|
|
@ -5,4 +5,4 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.b
|
||||||
interface CommandBuilder<R : Command> {
|
interface CommandBuilder<R : Command> {
|
||||||
|
|
||||||
fun build(): R
|
fun build(): R
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,4 +31,4 @@ abstract class HeaderEnabledCommandBuilder<T : HeaderEnabledCommandBuilder<T, R>
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun buildCommand(): R
|
protected abstract fun buildCommand(): R
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,4 +15,4 @@ abstract class NonceEnabledCommandBuilder<T : NonceEnabledCommandBuilder<T, R>,
|
||||||
this.nonce = nonce
|
this.nonce = nonce
|
||||||
return this as T
|
return this as T
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,4 +31,4 @@ open class BasalInsulinProgramElement(
|
||||||
", delayBetweenTenthPulsesInUsec=" + delayBetweenTenthPulsesInUsec +
|
", delayBetweenTenthPulsesInUsec=" + delayBetweenTenthPulsesInUsec +
|
||||||
'}'
|
'}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,17 @@ import kotlin.experimental.and
|
||||||
|
|
||||||
class BasalShortInsulinProgramElement(
|
class BasalShortInsulinProgramElement(
|
||||||
private val numberOfSlots: Byte, // 4 bits
|
private val numberOfSlots: Byte, // 4 bits
|
||||||
private val pulsesPerSlot: Short, //10 bits
|
private val pulsesPerSlot: Short, // 10 bits
|
||||||
private val extraAlternatePulse: Boolean
|
private val extraAlternatePulse: Boolean
|
||||||
) : ShortInsulinProgramElement {
|
) : ShortInsulinProgramElement {
|
||||||
|
|
||||||
override val encoded: ByteArray
|
override val encoded: ByteArray
|
||||||
get() {
|
get() {
|
||||||
val firstByte = (numberOfSlots - 1 and 0x0f shl 4 //
|
val firstByte = (
|
||||||
or ((if (extraAlternatePulse) 1 else 0) shl 3) //
|
numberOfSlots - 1 and 0x0f shl 4 //
|
||||||
or (pulsesPerSlot.toInt() ushr 8 and 0x03)).toByte()
|
or ((if (extraAlternatePulse) 1 else 0) shl 3) //
|
||||||
|
or (pulsesPerSlot.toInt() ushr 8 and 0x03)
|
||||||
|
).toByte()
|
||||||
return ByteBuffer.allocate(2) //
|
return ByteBuffer.allocate(2) //
|
||||||
.put(firstByte) //
|
.put(firstByte) //
|
||||||
.put((pulsesPerSlot and 0xff).toByte()) //
|
.put((pulsesPerSlot and 0xff).toByte()) //
|
||||||
|
@ -27,4 +29,4 @@ class BasalShortInsulinProgramElement(
|
||||||
", extraAlternatePulse=" + extraAlternatePulse +
|
", extraAlternatePulse=" + extraAlternatePulse +
|
||||||
'}'
|
'}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,4 +8,4 @@ class BolusShortInsulinProgramElement(
|
||||||
|
|
||||||
override val encoded: ByteArray
|
override val encoded: ByteArray
|
||||||
get() = ByteBuffer.allocate(2).putShort(numberOfPulses).array()
|
get() = ByteBuffer.allocate(2).putShort(numberOfPulses).array()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,4 @@ class CurrentBasalInsulinProgramElement(
|
||||||
", delayUntilNextTenthPulseInUsec=" + delayUntilNextTenthPulseInUsec +
|
", delayUntilNextTenthPulseInUsec=" + delayUntilNextTenthPulseInUsec +
|
||||||
", remainingTenthPulses=" + remainingTenthPulses +
|
", remainingTenthPulses=" + remainingTenthPulses +
|
||||||
'}'
|
'}'
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,4 @@ class CurrentSlot(
|
||||||
", eighthSecondsRemaining=" + eighthSecondsRemaining +
|
", eighthSecondsRemaining=" + eighthSecondsRemaining +
|
||||||
", pulsesRemaining=" + pulsesRemaining +
|
", pulsesRemaining=" + pulsesRemaining +
|
||||||
'}'
|
'}'
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.Encodable
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.Encodable
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
interface ShortInsulinProgramElement : Encodable, Serializable
|
interface ShortInsulinProgramElement : Encodable, Serializable
|
||||||
|
|
|
@ -21,4 +21,4 @@ class TempBasalInsulinProgramElement(
|
||||||
}
|
}
|
||||||
return buffer.array()
|
return buffer.array()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,4 +205,4 @@ object ProgramBasalUtil {
|
||||||
}
|
}
|
||||||
return MessageUtil.calculateChecksum(buffer.array())
|
return MessageUtil.calculateChecksum(buffer.array())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,4 +59,4 @@ object ProgramTempBasalUtil {
|
||||||
|
|
||||||
fun mapPulsesPerSlotToShortInsulinProgramElements(pulsesPerSlot: ShortArray?): List<ShortInsulinProgramElement> =
|
fun mapPulsesPerSlotToShortInsulinProgramElements(pulsesPerSlot: ShortArray?): List<ShortInsulinProgramElement> =
|
||||||
ProgramBasalUtil.mapPulsesPerSlotToShortInsulinProgramElements(pulsesPerSlot)
|
ProgramBasalUtil.mapPulsesPerSlotToShortInsulinProgramElements(pulsesPerSlot)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,4 +18,4 @@ enum class ActivationProgress {
|
||||||
fun isBefore(other: ActivationProgress): Boolean = ordinal < other.ordinal
|
fun isBefore(other: ActivationProgress): Boolean = ordinal < other.ordinal
|
||||||
|
|
||||||
fun isAtLeast(other: ActivationProgress): Boolean = ordinal >= other.ordinal
|
fun isAtLeast(other: ActivationProgress): Boolean = ordinal >= other.ordinal
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,5 +159,4 @@ enum class AlarmType(override val value: Byte) : HasValue {
|
||||||
ALARM_BLE_QN_EXCEED_MAX_RETRY(0xc1.toByte()),
|
ALARM_BLE_QN_EXCEED_MAX_RETRY(0xc1.toByte()),
|
||||||
ALARM_BLE_QN_CRIT_VAR_FAIL(0xc2.toByte()),
|
ALARM_BLE_QN_CRIT_VAR_FAIL(0xc2.toByte()),
|
||||||
UNKNOWN(0xff.toByte());
|
UNKNOWN(0xff.toByte());
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -29,15 +29,17 @@ class AlertConfiguration(
|
||||||
return ByteBuffer.allocate(6) //
|
return ByteBuffer.allocate(6) //
|
||||||
.put(firstByte)
|
.put(firstByte)
|
||||||
.put(durationInMinutes.toByte()) //
|
.put(durationInMinutes.toByte()) //
|
||||||
.putShort(when (trigger) {
|
.putShort(
|
||||||
is AlertTrigger.ReservoirVolumeTrigger -> {
|
when (trigger) {
|
||||||
trigger.thresholdInMicroLiters
|
is AlertTrigger.ReservoirVolumeTrigger -> {
|
||||||
}
|
trigger.thresholdInMicroLiters
|
||||||
|
}
|
||||||
|
|
||||||
is AlertTrigger.TimerTrigger -> {
|
is AlertTrigger.TimerTrigger -> {
|
||||||
trigger.offsetInMinutes
|
trigger.offsetInMinutes
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}) //
|
) //
|
||||||
.put(beepRepetition.value) //
|
.put(beepRepetition.value) //
|
||||||
.put(beepType.value) //
|
.put(beepType.value) //
|
||||||
.array()
|
.array()
|
||||||
|
@ -54,4 +56,4 @@ class AlertConfiguration(
|
||||||
", beepRepetition=" + beepRepetition +
|
", beepRepetition=" + beepRepetition +
|
||||||
'}'
|
'}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definiti
|
||||||
sealed class AlertTrigger {
|
sealed class AlertTrigger {
|
||||||
class TimerTrigger(val offsetInMinutes: Short) : AlertTrigger()
|
class TimerTrigger(val offsetInMinutes: Short) : AlertTrigger()
|
||||||
class ReservoirVolumeTrigger(val thresholdInMicroLiters: Short) : AlertTrigger()
|
class ReservoirVolumeTrigger(val thresholdInMicroLiters: Short) : AlertTrigger()
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,4 +20,4 @@ enum class AlertType(val index: Byte) : HasValue {
|
||||||
} else {
|
} else {
|
||||||
(1 shl index.toInt()).toByte()
|
(1 shl index.toInt()).toByte()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,4 +87,4 @@ class BasalProgram(
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
return segments.hashCode()
|
return segments.hashCode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,5 +10,4 @@ enum class BeepRepetitionType(
|
||||||
XXX3(0x05.toByte()), // Used in user pod expiration alert
|
XXX3(0x05.toByte()), // Used in user pod expiration alert
|
||||||
XXX4(0x06.toByte()), // Used in pod expiration alert
|
XXX4(0x06.toByte()), // Used in pod expiration alert
|
||||||
XXX5(0x08.toByte()); // Used in imminent pod expiration alert
|
XXX5(0x08.toByte()); // Used in imminent pod expiration alert
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -5,4 +5,4 @@ enum class BeepType(val value: Byte) {
|
||||||
SILENT(0x00.toByte()),
|
SILENT(0x00.toByte()),
|
||||||
FOUR_TIMES_BIP_BEEP(0x02.toByte()), // Used in low reservoir alert, user expiration alert, expiration alert, imminent expiration alert, lump of coal alert
|
FOUR_TIMES_BIP_BEEP(0x02.toByte()), // Used in low reservoir alert, user expiration alert, expiration alert, imminent expiration alert, lump of coal alert
|
||||||
LONG_SINGLE_BEEP(0x06.toByte()); // Used in stop delivery command
|
LONG_SINGLE_BEEP(0x06.toByte()); // Used in stop delivery command
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,4 +11,4 @@ enum class DeliveryStatus(override val value: Byte) : HasValue {
|
||||||
BOLUS_AND_BASAL_ACTIVE(0x05.toByte()),
|
BOLUS_AND_BASAL_ACTIVE(0x05.toByte()),
|
||||||
BOLUS_AND_TEMP_BASAL_ACTIVE(0x06.toByte()),
|
BOLUS_AND_TEMP_BASAL_ACTIVE(0x06.toByte()),
|
||||||
UNKNOWN(0xff.toByte());
|
UNKNOWN(0xff.toByte());
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definiti
|
||||||
interface Encodable {
|
interface Encodable {
|
||||||
|
|
||||||
val encoded: ByteArray
|
val encoded: ByteArray
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,4 +34,4 @@ enum class NakErrorType(override val value: Byte) : HasValue {
|
||||||
IGNORE_COMMAND(0x1c.toByte()),
|
IGNORE_COMMAND(0x1c.toByte()),
|
||||||
INVALID_CRC(0x1d.toByte()),
|
INVALID_CRC(0x1d.toByte()),
|
||||||
UNKNOWN(0xff.toByte());
|
UNKNOWN(0xff.toByte());
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,4 +23,4 @@ enum class PodStatus(override val value: Byte) : HasValue {
|
||||||
UNKNOWN(0xff.toByte());
|
UNKNOWN(0xff.toByte());
|
||||||
|
|
||||||
fun isRunning(): Boolean = this == RUNNING_ABOVE_MIN_VOLUME || this == RUNNING_BELOW_MIN_VOLUME
|
fun isRunning(): Boolean = this == RUNNING_ABOVE_MIN_VOLUME || this == RUNNING_BELOW_MIN_VOLUME
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,11 @@ class ProgramReminder(
|
||||||
) : Encodable, Serializable {
|
) : Encodable, Serializable {
|
||||||
|
|
||||||
override val encoded: ByteArray
|
override val encoded: ByteArray
|
||||||
get() = byteArrayOf(((if (atStart) 1 else 0) shl 7
|
get() = byteArrayOf(
|
||||||
or ((if (atEnd) 1 else 0) shl 6)
|
(
|
||||||
or ((atInterval and 0x3f).toInt())).toByte())
|
(if (atStart) 1 else 0) shl 7
|
||||||
}
|
or ((if (atEnd) 1 else 0) shl 6)
|
||||||
|
or ((atInterval and 0x3f).toInt())
|
||||||
|
).toByte()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -5,4 +5,4 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
|
||||||
abstract class ActivationResponseBase(
|
abstract class ActivationResponseBase(
|
||||||
val activationResponseType: ActivationResponseType,
|
val activationResponseType: ActivationResponseType,
|
||||||
encoded: ByteArray
|
encoded: ByteArray
|
||||||
) : ResponseBase(ResponseType.ACTIVATION_RESPONSE, encoded)
|
) : ResponseBase(ResponseType.ACTIVATION_RESPONSE, encoded)
|
||||||
|
|
|
@ -5,4 +5,4 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
|
||||||
open class AdditionalStatusResponseBase internal constructor(
|
open class AdditionalStatusResponseBase internal constructor(
|
||||||
val statusResponseType: StatusResponseType,
|
val statusResponseType: StatusResponseType,
|
||||||
encoded: ByteArray
|
encoded: ByteArray
|
||||||
) : ResponseBase(ResponseType.ADDITIONAL_STATUS_RESPONSE, encoded)
|
) : ResponseBase(ResponseType.ADDITIONAL_STATUS_RESPONSE, encoded)
|
||||||
|
|
|
@ -84,5 +84,4 @@ class AlarmStatusResponse(
|
||||||
}
|
}
|
||||||
|
|
||||||
infix fun Byte.shr(i: Int): Int = toInt() shr i
|
infix fun Byte.shr(i: Int): Int = toInt() shr i
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ class DefaultStatusResponse(
|
||||||
", minutesSinceActivation=$minutesSinceActivation" +
|
", minutesSinceActivation=$minutesSinceActivation" +
|
||||||
", reservoirPulsesRemaining=$reservoirPulsesRemaining)"
|
", reservoirPulsesRemaining=$reservoirPulsesRemaining)"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
infix fun Byte.ushr(i: Int) = toInt() ushr i
|
infix fun Byte.ushr(i: Int) = toInt() ushr i
|
||||||
|
|
|
@ -46,4 +46,4 @@ class NakResponse(
|
||||||
", encoded=" + encoded.contentToString() +
|
", encoded=" + encoded.contentToString() +
|
||||||
'}'
|
'}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,4 +6,4 @@ interface Response : Serializable {
|
||||||
|
|
||||||
val responseType: ResponseType
|
val responseType: ResponseType
|
||||||
val encoded: ByteArray
|
val encoded: ByteArray
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,5 +6,4 @@ abstract class ResponseBase(
|
||||||
) : Response {
|
) : Response {
|
||||||
|
|
||||||
override val encoded: ByteArray = encoded.copyOf(encoded.size)
|
override val encoded: ByteArray = encoded.copyOf(encoded.size)
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue