Implement most methods in OmnipodDashManagerImpl + cleanup

This commit is contained in:
Bart Sopers 2021-03-31 01:10:21 +02:00
parent 19a132c596
commit 811f136830
46 changed files with 609 additions and 317 deletions

View file

@ -23,7 +23,10 @@ abstract class OmnipodWizardModule {
@Provides
@OmnipodPluginQualifier
fun providesViewModelFactory(@OmnipodPluginQualifier viewModels: MutableMap<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>): ViewModelProvider.Factory {
fun providesViewModelFactory(
@OmnipodPluginQualifier
viewModels: MutableMap<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>
): ViewModelProvider.Factory {
return ViewModelFactory(viewModels)
}
}

View file

@ -41,7 +41,11 @@ class AttachPodFragment : InfoFragmentBase() {
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(getString(getTitleId()))
.setMessage(getString(R.string.omnipod_common_pod_activation_wizard_attach_pod_confirm_insert_cannula_text))
.setPositiveButton(getString(R.string.omnipod_common_ok)) { _, _ -> findNavController().navigate(getNextPageActionId()) }
.setPositiveButton(getString(R.string.omnipod_common_ok)) { _, _ ->
findNavController().navigate(
getNextPageActionId()
)
}
.setNegativeButton(getString(R.string.omnipod_common_cancel), null)
.show()
}

View file

@ -24,7 +24,8 @@ abstract class ActionFragmentBase : WizardFragmentBase() {
binding.navButtonsLayout.buttonNext.isEnabled = false
view.findViewById<TextView>(R.id.omnipod_wizard_action_page_text).setText(getTextId())
view.findViewById<Button>(R.id.omnipod_wizard_button_retry).setOnClickListener { actionViewModel.executeAction() }
view.findViewById<Button>(R.id.omnipod_wizard_button_retry)
.setOnClickListener { actionViewModel.executeAction() }
actionViewModel.isActionExecutingLiveData.observe(viewLifecycleOwner, { isExecuting ->
if (isExecuting) {
@ -33,7 +34,8 @@ abstract class ActionFragmentBase : WizardFragmentBase() {
view.findViewById<Button>(R.id.omnipod_wizard_button_discard_pod).visibility = View.GONE
view.findViewById<Button>(R.id.omnipod_wizard_button_retry).visibility = View.GONE
}
view.findViewById<ProgressBar>(R.id.omnipod_wizard_action_progress_indication).visibility = isExecuting.toVisibility()
view.findViewById<ProgressBar>(R.id.omnipod_wizard_action_progress_indication).visibility =
isExecuting.toVisibility()
view.findViewById<Button>(R.id.button_cancel).isEnabled = !isExecuting
})
@ -42,9 +44,12 @@ abstract class ActionFragmentBase : WizardFragmentBase() {
val isExecuting = isActionExecuting()
view.findViewById<Button>(R.id.button_next).isEnabled = result.success
view.findViewById<ImageView>(R.id.omnipod_wizard_action_success).visibility = result.success.toVisibility()
view.findViewById<TextView>(R.id.omnipod_wizard_action_error).visibility = (!isExecuting && !result.success).toVisibility()
view.findViewById<Button>(R.id.omnipod_wizard_button_retry).visibility = (!isExecuting && !result.success).toVisibility()
view.findViewById<ImageView>(R.id.omnipod_wizard_action_success).visibility =
result.success.toVisibility()
view.findViewById<TextView>(R.id.omnipod_wizard_action_error).visibility =
(!isExecuting && !result.success).toVisibility()
view.findViewById<Button>(R.id.omnipod_wizard_button_retry).visibility =
(!isExecuting && !result.success).toVisibility()
if (!result.success) {
view.findViewById<TextView>(R.id.omnipod_wizard_action_error).text = result.comment

View file

@ -47,7 +47,8 @@ abstract class WizardFragmentBase : DaggerFragment() {
if (nextPage == null) {
binding.navButtonsLayout.buttonNext.text = getString(R.string.omnipod_common_wizard_button_finish)
binding.navButtonsLayout.buttonNext.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.omnipod_wizard_finish_button, context?.theme))
binding.navButtonsLayout.buttonNext.backgroundTintList =
ColorStateList.valueOf(resources.getColor(R.color.omnipod_wizard_finish_button, context?.theme))
}
updateProgressIndication()

View file

@ -33,13 +33,13 @@ class OmnipodDashPumpPlugin @Inject constructor(
companion object {
private val pluginDescription = PluginDescription() //
.mainType(PluginType.PUMP) //
.fragmentClass(OmnipodDashOverviewFragment::class.java.name) //
private val pluginDescription = PluginDescription()
.mainType(PluginType.PUMP)
.fragmentClass(OmnipodDashOverviewFragment::class.java.name)
.pluginIcon(R.drawable.ic_pod_128)
.pluginName(R.string.omnipod_dash_name) //
.shortName(R.string.omnipod_dash_name_short) //
.preferencesId(R.xml.omnipod_dash_preferences) //
.pluginName(R.string.omnipod_dash_name)
.shortName(R.string.omnipod_dash_name_short)
.preferencesId(R.xml.omnipod_dash_preferences)
.description(R.string.omnipod_dash_pump_description)
private val pumpDescription = PumpDescription(PumpType.Omnipod_Dash)

View file

@ -5,6 +5,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definitio
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertTrigger
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertType
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BasalProgram
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BeepType
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.ResponseType
import io.reactivex.Observable
import java.util.*
@ -14,9 +16,9 @@ interface OmnipodDashManager {
fun activatePodPart2(basalProgram: BasalProgram): Observable<PodEvent>
fun getStatus(): Observable<PodEvent>
fun getStatus(type: ResponseType.StatusResponseType): Observable<PodEvent>
fun setBasalProgram(program: BasalProgram): Observable<PodEvent>
fun setBasalProgram(basalProgram: BasalProgram): Observable<PodEvent>
fun suspendDelivery(): Observable<PodEvent>
@ -26,15 +28,15 @@ interface OmnipodDashManager {
fun cancelTempBasal(): Observable<PodEvent>
fun bolus(amount: Double): Observable<PodEvent>
fun bolus(units: Double, confirmationBeeps: Boolean, completionBeeps: Boolean): Observable<PodEvent>
fun cancelBolus(): Observable<PodEvent>
fun programBeeps(): Observable<PodEvent>
fun playBeep(beepType: BeepType): Observable<PodEvent>
fun programAlerts(alertConfigurations: List<AlertConfiguration>): Observable<PodEvent>
fun silenceAlerts(alerts: EnumSet<AlertType>): Observable<PodEvent>
fun silenceAlerts(alertTypes: EnumSet<AlertType>): Observable<PodEvent>
fun deactivatePod(): Observable<PodEvent>
}

View file

@ -26,11 +26,17 @@ class OmnipodDashManagerImpl @Inject constructor(
private val aapsSchedulers: AapsSchedulers
) : OmnipodDashManager {
companion object {
const val NONCE = 1229869870 // The Omnipod Dash seems to use a fixed nonce
}
private val observePodReadyForActivationPart1: Observable<PodEvent>
get() = Observable.defer {
if (podStateManager.activationProgress.isBefore(ActivationProgress.PHASE_1_COMPLETED)) {
Observable.empty()
} else {
// TODO introduce specialized Exception
Observable.error(IllegalStateException("Pod is in an incorrect state"))
}
}
@ -42,6 +48,27 @@ class OmnipodDashManagerImpl @Inject constructor(
)) {
Observable.empty()
} else {
// TODO introduce specialized Exception
Observable.error(IllegalStateException("Pod is in an incorrect state"))
}
}
private val observeUniqueIdSet: Observable<PodEvent>
get() = Observable.defer {
if (podStateManager.activationProgress.isAtLeast(ActivationProgress.SET_UNIQUE_ID)) {
Observable.empty()
} else {
// TODO introduce specialized Exception
Observable.error(IllegalStateException("Pod is in an incorrect state"))
}
}
private val observePodRunning: Observable<PodEvent>
get() = Observable.defer {
if (podStateManager.activationProgress == ActivationProgress.COMPLETED && podStateManager.podStatus!!.isRunning()) {
Observable.empty()
} else {
// TODO introduce specialized Exception
Observable.error(IllegalStateException("Pod is in an incorrect state"))
}
}
@ -67,7 +94,7 @@ class OmnipodDashManagerImpl @Inject constructor(
ProgramBolusCommand.Builder()
.setUniqueId(podStateManager.uniqueId!!.toInt())
.setSequenceNumber(podStateManager.messageSequenceNumber)
.setNonce(1229869870) // TODO
.setNonce(NONCE)
.setNumberOfUnits(units)
.setDelayBetweenPulsesInEighthSeconds(rateInEighthPulsesPerSeconds)
.setProgramReminder(ProgramReminder(confirmationBeeps, completionBeeps, 0))
@ -119,15 +146,16 @@ class OmnipodDashManagerImpl @Inject constructor(
ProgramAlertsCommand.Builder()
.setUniqueId(podStateManager.uniqueId!!.toInt())
.setSequenceNumber(podStateManager.messageSequenceNumber)
.setNonce(1229869870) // TODO
.setNonce(NONCE)
.setAlertConfigurations(alertConfigurations)
.setMultiCommandFlag(multiCommandFlag)
.build(),
DefaultStatusResponse::class
)
}
}
private fun observeProgramBasalCommand(basalProgram: BasalProgram): Observable<PodEvent> {
private fun observeSendProgramBasalCommand(basalProgram: BasalProgram): Observable<PodEvent> {
return Observable.defer {
val currentTime = Date()
logger.debug(LTag.PUMPCOMM, "Programming basal. currentTime={}, basalProgram={}", currentTime, basalProgram)
@ -135,7 +163,7 @@ class OmnipodDashManagerImpl @Inject constructor(
ProgramBasalCommand.Builder()
.setUniqueId(podStateManager.uniqueId!!.toInt())
.setSequenceNumber(podStateManager.messageSequenceNumber)
.setNonce(1229869870) // TODO
.setNonce(NONCE)
.setProgramReminder(ProgramReminder(atStart = false, atEnd = false, atInterval = 0))
.setBasalProgram(basalProgram)
.setCurrentTime(currentTime)
@ -160,26 +188,26 @@ class OmnipodDashManagerImpl @Inject constructor(
private val observeSendSetUniqueIdCommand: Observable<PodEvent>
get() = Observable.defer {
bleManager.sendCommand(
SetUniqueIdCommand.Builder() //
.setSequenceNumber(podStateManager.messageSequenceNumber) //
.setUniqueId(podStateManager.uniqueId!!.toInt()) //
.setLotNumber(podStateManager.lotNumber!!.toInt()) //
SetUniqueIdCommand.Builder()
.setSequenceNumber(podStateManager.messageSequenceNumber)
.setUniqueId(podStateManager.uniqueId!!.toInt())
.setLotNumber(podStateManager.lotNumber!!.toInt())
.setPodSequenceNumber(podStateManager.podSequenceNumber!!.toInt())
.setInitializationTime(Date())
.build(),
SetUniqueIdResponse::class
) //
)
}
private val observeSendGetVersionCommand: Observable<PodEvent>
get() = Observable.defer {
bleManager.sendCommand(
GetVersionCommand.Builder() //
.setSequenceNumber(podStateManager.messageSequenceNumber) //
.setUniqueId(DEFAULT_UNIQUE_ID) //
GetVersionCommand.Builder()
.setSequenceNumber(podStateManager.messageSequenceNumber)
.setUniqueId(DEFAULT_UNIQUE_ID)
.build(),
VersionResponse::class
) //
)
}
override fun activatePodPart1(lowReservoirAlertTrigger: AlertTrigger.ReservoirVolumeTrigger?): Observable<PodEvent> {
@ -190,7 +218,7 @@ class OmnipodDashManagerImpl @Inject constructor(
observeActivationPart1Commands(lowReservoirAlertTrigger)
).doOnComplete(ActivationProgressUpdater(ActivationProgress.PHASE_1_COMPLETED))
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor()) //
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
}
@ -225,10 +253,10 @@ class OmnipodDashManagerImpl @Inject constructor(
ProgramBolusCommand.Builder()
.setUniqueId(podStateManager.uniqueId!!.toInt())
.setSequenceNumber(podStateManager.messageSequenceNumber)
.setNonce(1229869870) // TODO
.setNonce(NONCE)
.setNumberOfUnits(podStateManager.firstPrimeBolusVolume!! * 0.05)
.setDelayBetweenPulsesInEighthSeconds(podStateManager.primePulseRate!!.toByte())
.setProgramReminder(ProgramReminder(false, false, 0))
.setProgramReminder(ProgramReminder(atStart = false, atEnd = false, atInterval = 0))
.build(),
DefaultStatusResponse::class
)
@ -290,7 +318,7 @@ class OmnipodDashManagerImpl @Inject constructor(
observeActivationPart2Commands(basalProgram)
).doOnComplete(ActivationProgressUpdater(ActivationProgress.COMPLETED))
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor()) //
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
}
@ -363,7 +391,7 @@ class OmnipodDashManagerImpl @Inject constructor(
}
if (podStateManager.activationProgress.isBefore(ActivationProgress.PROGRAMMED_BASAL)) {
observables.add(
observeProgramBasalCommand(basalProgram)
observeSendProgramBasalCommand(basalProgram)
.doOnComplete(ActivationProgressUpdater(ActivationProgress.PROGRAMMED_BASAL))
)
}
@ -371,70 +399,233 @@ class OmnipodDashManagerImpl @Inject constructor(
return observables.reversed()
}
override fun getStatus(): Observable<PodEvent> {
// TODO
return Observable.empty()
override fun getStatus(type: ResponseType.StatusResponseType): Observable<PodEvent> {
return Observable.concat(
observeUniqueIdSet,
observeConnectToPod,
observeSendGetPodStatusCommand(type)
)
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
}
override fun setBasalProgram(program: BasalProgram): Observable<PodEvent> {
// TODO
return Observable.empty()
override fun setBasalProgram(basalProgram: BasalProgram): Observable<PodEvent> {
return Observable.concat(
observePodRunning,
observeConnectToPod,
observeSendProgramBasalCommand(basalProgram)
)
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
}
private fun observeSendStopDeliveryCommand(deliveryType: StopDeliveryCommand.DeliveryType): Observable<PodEvent> {
return Observable.defer {
bleManager.sendCommand(
StopDeliveryCommand.Builder()
.setSequenceNumber(podStateManager.messageSequenceNumber)
.setUniqueId(podStateManager.uniqueId!!.toInt())
.setNonce(NONCE)
.setDeliveryType(deliveryType)
.build(),
DefaultStatusResponse::class
)
}
}
override fun suspendDelivery(): Observable<PodEvent> {
// TODO
return Observable.empty()
return Observable.concat(
observePodRunning,
observeConnectToPod,
observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.ALL)
)
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
}
override fun setTime(): Observable<PodEvent> {
// TODO
logger.error(LTag.PUMPCOMM, "NOT IMPLEMENTED: setTime()")
return Observable.empty()
}
private fun observeSendProgramTempBasalCommand(rate: Double, durationInMinutes: Short): Observable<PodEvent> {
return Observable.defer {
// TODO cancel current temp basal (if active)
bleManager.sendCommand(
ProgramTempBasalCommand.Builder()
.setSequenceNumber(podStateManager.messageSequenceNumber)
.setUniqueId(podStateManager.uniqueId!!.toInt())
.setNonce(NONCE)
.setRateInUnitsPerHour(rate)
.setDurationInMinutes(durationInMinutes)
.build(),
DefaultStatusResponse::class
)
}
}
override fun setTempBasal(rate: Double, durationInMinutes: Short): Observable<PodEvent> {
// TODO
return Observable.empty()
return Observable.concat(
observePodRunning,
observeConnectToPod,
observeSendProgramTempBasalCommand(rate, durationInMinutes)
)
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
}
override fun cancelTempBasal(): Observable<PodEvent> {
// TODO
return Observable.empty()
return Observable.concat(
observePodRunning,
observeConnectToPod,
observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.TEMP_BASAL)
)
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
}
override fun bolus(amount: Double): Observable<PodEvent> {
// TODO
return Observable.empty()
override fun bolus(units: Double, confirmationBeeps: Boolean, completionBeeps: Boolean): Observable<PodEvent> {
return Observable.concat(
observePodRunning,
observeConnectToPod,
observeSendProgramBolusCommand(
units,
podStateManager.pulseRate!!.toByte(),
confirmationBeeps,
completionBeeps
)
)
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
}
override fun cancelBolus(): Observable<PodEvent> {
// TODO
return Observable.empty()
return Observable.concat(
observePodRunning,
observeConnectToPod,
observeSendStopDeliveryCommand(StopDeliveryCommand.DeliveryType.BOLUS)
)
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
}
override fun programBeeps(): Observable<PodEvent> {
// TODO
return Observable.empty()
private fun observeSendConfigureBeepsCommand(
basalReminder: ProgramReminder = ProgramReminder(atStart = false, atEnd = false, atInterval = 0),
tempBasalReminder: ProgramReminder = ProgramReminder(atStart = false, atEnd = false, atInterval = 0),
bolusReminder: ProgramReminder = ProgramReminder(atStart = false, atEnd = false, atInterval = 0),
immediateBeepType: BeepType = BeepType.SILENT
): Observable<PodEvent> {
return Observable.defer {
bleManager.sendCommand(
ProgramBeepsCommand.Builder()
.setSequenceNumber(podStateManager.messageSequenceNumber)
.setUniqueId(podStateManager.uniqueId!!.toInt())
.setBasalReminder(basalReminder)
.setTempBasalReminder(tempBasalReminder)
.setBolusReminder(bolusReminder)
.setImmediateBeepType(immediateBeepType)
.build(),
DefaultStatusResponse::class
)
}
}
override fun playBeep(beepType: BeepType): Observable<PodEvent> {
return Observable.concat(
observePodRunning,
observeConnectToPod,
observeSendConfigureBeepsCommand(immediateBeepType = beepType)
)
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
}
override fun programAlerts(alertConfigurations: List<AlertConfiguration>): Observable<PodEvent> {
// TODO
return Observable.empty()
return Observable.concat(
observePodRunning,
observeConnectToPod,
observeSendProgramAlertsCommand(alertConfigurations)
)
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
}
override fun silenceAlerts(alerts: EnumSet<AlertType>): Observable<PodEvent> {
// TODO
return Observable.empty()
private fun observeSendSilenceAlertsCommand(alertTypes: EnumSet<AlertType>): Observable<PodEvent> {
return Observable.defer {
bleManager.sendCommand(
SilenceAlertsCommand.Builder()
.setSequenceNumber(podStateManager.messageSequenceNumber)
.setUniqueId(podStateManager.uniqueId!!.toInt())
.setNonce(NONCE)
.setAlertTypes(alertTypes)
.build(),
DefaultStatusResponse::class
)
}
}
override fun silenceAlerts(alertTypes: EnumSet<AlertType>): Observable<PodEvent> {
return Observable.concat(
observePodRunning,
observeConnectToPod,
observeSendSilenceAlertsCommand(alertTypes)
)
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
}
private val observeSendDeactivateCommand: Observable<PodEvent>
get() = Observable.defer {
bleManager.sendCommand(
DeactivateCommand.Builder()
.setSequenceNumber(podStateManager.messageSequenceNumber)
.setUniqueId(podStateManager.uniqueId!!.toInt())
.setNonce(NONCE)
.build(),
DefaultStatusResponse::class
)
}
override fun deactivatePod(): Observable<PodEvent> {
// TODO
return Observable.empty()
return Observable.concat(
observePodRunning,
observeConnectToPod,
observeSendDeactivateCommand
)
// TODO these would be common for any observable returned in a public function in this class
.doOnNext(PodEventInterceptor())
.doOnError(ErrorInterceptor())
.subscribeOn(aapsSchedulers.io)
//
.doOnComplete(podStateManager::reset)
}
inner class PodEventInterceptor : Consumer<PodEvent> {
override fun accept(event: PodEvent) {
logger.debug(LTag.PUMP, "Intercepted PodEvent in OmnipodDashManagerImpl: ${event.javaClass.simpleName}")
when (event) {
is PodEvent.AlreadyConnected -> {
podStateManager.bluetoothAddress = event.bluetoothAddress

View file

@ -119,7 +119,7 @@ class OmnipodDashBleManagerImpl @Inject constructor(
enDecrypt = enDecrypt
)
val response = session.sendCommand(cmd, responseType)
emitter.onNext(PodEvent.ResponseReceived(response))
emitter.onNext(PodEvent.ResponseReceived(cmd, response))
emitter.onComplete()
} catch (ex: Exception) {
emitter.tryOnError(ex)

View file

@ -50,10 +50,14 @@ sealed class PodEvent {
}
}
class ResponseReceived(val response: Response) : PodEvent() {
class ResponseReceived(
val command: Command,
val response: Response
) : PodEvent() {
override fun toString(): String {
return "ResponseReceived(response=$response)"
return "ResponseReceived(command=$command, response=$response)"
}
}
}

View file

@ -14,11 +14,11 @@ class DeactivateCommand private constructor(
override val encoded: ByteArray
get() = appendCrc(
ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
.put(commandType.value) //
.put(BODY_LENGTH) //
.putInt(nonce) //
ByteBuffer.allocate(LENGTH + HEADER_LENGTH)
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag))
.put(commandType.value)
.put(BODY_LENGTH)
.putInt(nonce)
.array()
)

View file

@ -15,11 +15,11 @@ class GetStatusCommand private constructor(
override val encoded: ByteArray
get() = appendCrc(
ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
.put(commandType.value) //
.put(BODY_LENGTH) //
.put(statusResponseType.value) //
ByteBuffer.allocate(LENGTH + HEADER_LENGTH)
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag))
.put(commandType.value)
.put(BODY_LENGTH)
.put(statusResponseType.value)
.array()
)

View file

@ -13,11 +13,11 @@ class GetVersionCommand private constructor(
override val encoded: ByteArray
get() = appendCrc(
ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
.put(commandType.value) //
.put(BODY_LENGTH) //
.putInt(uniqueId) //
ByteBuffer.allocate(LENGTH + HEADER_LENGTH)
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag))
.put(commandType.value)
.put(BODY_LENGTH)
.putInt(uniqueId)
.array()
)

View file

@ -27,10 +27,10 @@ class ProgramAlertsCommand private constructor(
override val encoded: ByteArray
get() {
val byteBuffer: ByteBuffer = ByteBuffer.allocate(getLength() + HEADER_LENGTH) //
.put(encodeHeader(uniqueId, sequenceNumber, getLength(), multiCommandFlag)) //
.put(commandType.value) //
.put(getBodyLength()) //
val byteBuffer: ByteBuffer = ByteBuffer.allocate(getLength() + HEADER_LENGTH)
.put(encodeHeader(uniqueId, sequenceNumber, getLength(), multiCommandFlag))
.put(commandType.value)
.put(getBodyLength())
.putInt(nonce)
for (configuration in alertConfigurations) {
byteBuffer.put(configuration.encoded)

View file

@ -36,12 +36,12 @@ class ProgramBasalCommand private constructor(
override val encoded: ByteArray
get() {
val buffer = ByteBuffer.allocate(length.toInt()) //
.put(commandType.value) //
.put(bodyLength) //
.put(programReminder.encoded) //
.put(currentInsulinProgramElementIndex) //
.putShort(remainingTenthPulsesInCurrentInsulinProgramElement) //
val buffer = ByteBuffer.allocate(length.toInt())
.put(commandType.value)
.put(bodyLength)
.put(programReminder.encoded)
.put(currentInsulinProgramElementIndex)
.putShort(remainingTenthPulsesInCurrentInsulinProgramElement)
.putInt(delayUntilNextTenthPulseInUsec)
for (insulinProgramElement in insulinProgramElements) {
buffer.put(insulinProgramElement.encoded)
@ -55,10 +55,10 @@ class ProgramBasalCommand private constructor(
multiCommandFlag
)
return appendCrc(
ByteBuffer.allocate(basalCommand.size + interlockCommand.size + header.size) //
.put(header) //
.put(interlockCommand) //
.put(basalCommand) //
ByteBuffer.allocate(basalCommand.size + interlockCommand.size + header.size)
.put(header)
.put(interlockCommand)
.put(basalCommand)
.array()
)
}

View file

@ -19,14 +19,14 @@ class ProgramBeepsCommand private constructor(
override val encoded: ByteArray
get() = appendCrc(
ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
.put(commandType.value) //
.put(BODY_LENGTH) //
.put(immediateBeepType.value) //
.put(basalReminder.encoded) //
.put(tempBasalReminder.encoded) //
.put(bolusReminder.encoded) //
ByteBuffer.allocate(LENGTH + HEADER_LENGTH)
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag))
.put(commandType.value)
.put(BODY_LENGTH)
.put(immediateBeepType.value)
.put(basalReminder.encoded)
.put(tempBasalReminder.encoded)
.put(bolusReminder.encoded)
.array()
)

View file

@ -21,12 +21,12 @@ class ProgramBolusCommand private constructor(
override val encoded: ByteArray
get() {
val bolusCommand = ByteBuffer.allocate(LENGTH.toInt()) //
.put(commandType.value) //
.put(BODY_LENGTH) //
.put(programReminder.encoded) //
.putShort(numberOfTenthPulses) //
.putInt(delayUntilFirstTenthPulseInUsec) //
val bolusCommand = ByteBuffer.allocate(LENGTH.toInt())
.put(commandType.value)
.put(BODY_LENGTH)
.put(programReminder.encoded)
.putShort(numberOfTenthPulses)
.putInt(delayUntilFirstTenthPulseInUsec)
.putShort(0.toShort()) // Extended bolus pulses
.putInt(0) // Delay between tenth extended pulses in usec
.array()
@ -38,10 +38,10 @@ class ProgramBolusCommand private constructor(
multiCommandFlag
)
return appendCrc(
ByteBuffer.allocate(header.size + interlockCommand.size + bolusCommand.size) //
.put(header) //
.put(interlockCommand) //
.put(bolusCommand) //
ByteBuffer.allocate(header.size + interlockCommand.size + bolusCommand.size)
.put(header)
.put(interlockCommand)
.put(bolusCommand)
.array()
)
}
@ -120,11 +120,11 @@ class ProgramBolusCommand private constructor(
private const val BODY_LENGTH: Byte = 13
private fun calculateChecksum(numberOfSlots: Byte, byte10And11: Short, numberOfPulses: Short): Short {
return MessageUtil.calculateChecksum(
ByteBuffer.allocate(7) //
.put(numberOfSlots) //
.putShort(byte10And11) //
.putShort(numberOfPulses) //
.putShort(numberOfPulses) //
ByteBuffer.allocate(7)
.put(numberOfSlots)
.putShort(byte10And11)
.putShort(numberOfPulses)
.putShort(numberOfPulses)
.array()
)
}

View file

@ -37,12 +37,12 @@ class ProgramInsulinCommand internal constructor(
override val encoded: ByteArray
get() {
val buffer = ByteBuffer.allocate(getLength().toInt()) //
.put(commandType.value) //
.put(getBodyLength()) //
.putInt(nonce) //
.put(deliveryType.getValue()) //
.putShort(checksum) //
val buffer = ByteBuffer.allocate(getLength().toInt())
.put(commandType.value)
.put(getBodyLength())
.putInt(nonce)
.put(deliveryType.getValue())
.putShort(checksum)
.put(byte9) // BASAL: currentSlot // BOLUS: number of ShortInsulinProgramElements
.putShort(byte10And11) // BASAL: remainingEighthSecondsInCurrentSlot // BOLUS: immediate pulses multiplied by delay between pulses in eighth seconds
.putShort(byte12And13) // BASAL: remainingPulsesInCurrentSlot // BOLUS: immediate pulses

View file

@ -103,12 +103,12 @@ class ProgramTempBasalCommand private constructor(
delayUntilNextTenthPulseInUsec =
(firstProgramElement.numberOfSlots.toLong() * 1800.0 / remainingTenthPulsesInFirstElement * 1000000).toInt()
}
val buffer = ByteBuffer.allocate(getLength().toInt()) //
.put(commandType.value) //
.put(getBodyLength()) //
.put(programReminder.encoded) //
val buffer = ByteBuffer.allocate(getLength().toInt())
.put(commandType.value)
.put(getBodyLength())
.put(programReminder.encoded)
.put(0x00.toByte()) // Current slot index
.putShort(remainingTenthPulsesInFirstElement) //
.putShort(remainingTenthPulsesInFirstElement)
.putInt(delayUntilNextTenthPulseInUsec)
for (element in insulinProgramElements) {
buffer.put(element.encoded)
@ -122,10 +122,10 @@ class ProgramTempBasalCommand private constructor(
multiCommandFlag
)
return appendCrc(
ByteBuffer.allocate(header.size + interlockCommand.size + tempBasalCommand.size) //
.put(header) //
.put(interlockCommand) //
.put(tempBasalCommand) //
ByteBuffer.allocate(header.size + interlockCommand.size + tempBasalCommand.size)
.put(header)
.put(interlockCommand)
.put(tempBasalCommand)
.array()
)
}

View file

@ -17,16 +17,16 @@ class SetUniqueIdCommand private constructor(
override val encoded: ByteArray
get() = appendCrc(
ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
.put(encodeHeader(DEFAULT_UNIQUE_ID, sequenceNumber, LENGTH, multiCommandFlag)) //
.put(commandType.value) //
.put(BODY_LENGTH) //
.putInt(uniqueId) //
ByteBuffer.allocate(LENGTH + HEADER_LENGTH)
.put(encodeHeader(DEFAULT_UNIQUE_ID, sequenceNumber, LENGTH, multiCommandFlag))
.put(commandType.value)
.put(BODY_LENGTH)
.putInt(uniqueId)
.put(0x14.toByte()) // FIXME ??
.put(0x04.toByte()) // FIXME ??
.put(encodeInitializationTime(initializationTime)) //
.putInt(lotNumber) //
.putInt(podSequenceNumber) //
.put(encodeInitializationTime(initializationTime))
.putInt(lotNumber)
.putInt(podSequenceNumber)
.array()
)
@ -86,12 +86,12 @@ class SetUniqueIdCommand private constructor(
private fun encodeInitializationTime(date: Date): ByteArray {
val instance = Calendar.getInstance()
instance.time = date
return byteArrayOf( //
(instance[Calendar.MONTH] + 1).toByte(), //
instance[Calendar.DATE].toByte(), //
(instance[Calendar.YEAR] % 100).toByte(), //
instance[Calendar.HOUR_OF_DAY].toByte(), //
instance[Calendar.MINUTE].toByte() //
return byteArrayOf(
(instance[Calendar.MONTH] + 1).toByte(),
instance[Calendar.DATE].toByte(),
(instance[Calendar.YEAR] % 100).toByte(),
instance[Calendar.HOUR_OF_DAY].toByte(),
instance[Calendar.MINUTE].toByte()
)
}
}

View file

@ -19,12 +19,12 @@ class SilenceAlertsCommand private constructor(
override val encoded: ByteArray
get() =
appendCrc(
ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
.put(commandType.value) //
.put(BODY_LENGTH) //
.putInt(nonce) //
.put(AlertUtil.encodeAlertSet(alertTypes)) //
ByteBuffer.allocate(LENGTH + HEADER_LENGTH)
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag))
.put(commandType.value)
.put(BODY_LENGTH)
.putInt(nonce)
.put(AlertUtil.encodeAlertSet(alertTypes))
.array()
)

View file

@ -20,12 +20,12 @@ class StopDeliveryCommand private constructor(
override val encoded: ByteArray
get() {
return appendCrc(
ByteBuffer.allocate(LENGTH + HEADER_LENGTH) //
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag)) //
.put(commandType.value) //
.put(BODY_LENGTH) //
.putInt(nonce) //
.put((beepType.value.toInt() shl 4 or deliveryType.encoded[0].toInt()).toByte()) //
ByteBuffer.allocate(LENGTH + HEADER_LENGTH)
.put(encodeHeader(uniqueId, sequenceNumber, LENGTH, multiCommandFlag))
.put(commandType.value)
.put(BODY_LENGTH)
.putInt(nonce)
.put((beepType.value.toInt() shl 4 or deliveryType.encoded[0].toInt()).toByte())
.array()
)
}

View file

@ -13,9 +13,9 @@ abstract class HeaderEnabledCommand protected constructor(
companion object {
internal fun appendCrc(command: ByteArray): ByteArray =
ByteBuffer.allocate(command.size + 2) //
.put(command) //
.putShort(MessageUtil.createCrc(command)) //
ByteBuffer.allocate(command.size + 2)
.put(command)
.putShort(MessageUtil.createCrc(command))
.array()
internal fun encodeHeader(
@ -24,9 +24,9 @@ abstract class HeaderEnabledCommand protected constructor(
length: Short,
multiCommandFlag: Boolean
): ByteArray =
ByteBuffer.allocate(6) //
.putInt(uniqueId) //
.putShort((sequenceNumber.toInt() and 0x0f shl 10 or length.toInt() or ((if (multiCommandFlag) 1 else 0) shl 15)).toShort()) //
ByteBuffer.allocate(6)
.putInt(uniqueId)
.putShort((sequenceNumber.toInt() and 0x0f shl 10 or length.toInt() or ((if (multiCommandFlag) 1 else 0) shl 15)).toShort())
.array()
internal const val HEADER_LENGTH: Short = 6

View file

@ -12,9 +12,9 @@ open class BasalInsulinProgramElement(
) : Encodable, Serializable {
override val encoded: ByteArray
get() = ByteBuffer.allocate(6) //
.putShort(totalTenthPulses) //
.putInt(if (totalTenthPulses.toInt() == 0) Int.MIN_VALUE or delayBetweenTenthPulsesInUsec else delayBetweenTenthPulsesInUsec) //
get() = ByteBuffer.allocate(6)
.putShort(totalTenthPulses)
.putInt(if (totalTenthPulses.toInt() == 0) Int.MIN_VALUE or delayBetweenTenthPulsesInUsec else delayBetweenTenthPulsesInUsec)
.array()
val durationInSeconds: Short
get() = (numberOfSlots * 1800).toShort()

View file

@ -12,13 +12,13 @@ class BasalShortInsulinProgramElement(
override val encoded: ByteArray
get() {
val firstByte = (
numberOfSlots - 1 and 0x0f shl 4 //
or ((if (extraAlternatePulse) 1 else 0) shl 3) //
numberOfSlots - 1 and 0x0f shl 4
or ((if (extraAlternatePulse) 1 else 0) shl 3)
or (pulsesPerSlot.toInt() ushr 8 and 0x03)
).toByte()
return ByteBuffer.allocate(2) //
.put(firstByte) //
.put((pulsesPerSlot and 0xff).toByte()) //
return ByteBuffer.allocate(2)
.put(firstByte)
.put((pulsesPerSlot and 0xff).toByte())
.array()
}

View file

@ -13,10 +13,10 @@ class TempBasalInsulinProgramElement(
val buffer = ByteBuffer.allocate(6)
if (totalTenthPulses.toInt() == 0) {
val i = (durationInSeconds.toDouble() * 1000000.0 / numberOfSlots.toDouble()).toInt() or Int.MIN_VALUE
buffer.putShort(numberOfSlots.toShort()) //
buffer.putShort(numberOfSlots.toShort())
.putInt(i)
} else {
buffer.putShort(totalTenthPulses) //
buffer.putShort(totalTenthPulses)
.putInt(delayBetweenTenthPulsesInUsec)
}
return buffer.array()

View file

@ -248,9 +248,9 @@ object ProgramBasalUtil {
}
fun calculateChecksum(pulsesPerSlot: ShortArray?, currentSlot: CurrentSlot): Short {
val buffer = ByteBuffer.allocate(1 + 2 + 2 + NUMBER_OF_BASAL_SLOTS * 2) //
.put(currentSlot.index) //
.putShort(currentSlot.pulsesRemaining) //
val buffer = ByteBuffer.allocate(1 + 2 + 2 + NUMBER_OF_BASAL_SLOTS * 2)
.put(currentSlot.index)
.putShort(currentSlot.pulsesRemaining)
.putShort(currentSlot.eighthSecondsRemaining)
for (pulses in pulsesPerSlot!!) {
buffer.putShort(pulses)

View file

@ -53,9 +53,9 @@ object ProgramTempBasalUtil {
}
fun calculateChecksum(totalNumberOfSlots: Byte, pulsesInFirstSlot: Short, pulsesPerSlot: ShortArray?): Short {
val buffer = ByteBuffer.allocate(1 + 2 + 2 + 2 * pulsesPerSlot!!.size) //
.put(totalNumberOfSlots) //
.putShort(0x3840.toShort()) //
val buffer = ByteBuffer.allocate(1 + 2 + 2 + 2 * pulsesPerSlot!!.size)
.put(totalNumberOfSlots)
.putShort(0x3840.toShort())
.putShort(pulsesInFirstSlot)
for (pulses in pulsesPerSlot) {
buffer.putShort(pulses)

View file

@ -26,9 +26,9 @@ class AlertConfiguration(
firstByte = firstByte or (1 shl 1)
}
firstByte = firstByte or ((durationInMinutes.toInt() shr 8 and 0x01).toByte())
return ByteBuffer.allocate(6) //
return ByteBuffer.allocate(6)
.put(firstByte)
.put(durationInMinutes.toByte()) //
.put(durationInMinutes.toByte())
.putShort(
when (trigger) {
is AlertTrigger.ReservoirVolumeTrigger -> {
@ -39,9 +39,9 @@ class AlertConfiguration(
trigger.offsetInMinutes
}
}
) //
.put(beepRepetition.value) //
.put(beepType.value) //
)
.put(beepRepetition.value)
.put(beepType.value)
.array()
}

View file

@ -4,24 +4,43 @@ import androidx.annotation.StringRes
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.omnipod.common.R
import info.nightscout.androidaps.plugins.pump.omnipod.common.ui.wizard.deactivation.viewmodel.action.DeactivatePodViewModel
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.OmnipodDashManager
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
import io.reactivex.Single
import io.reactivex.rxkotlin.subscribeBy
import javax.inject.Inject
class DashDeactivatePodViewModel @Inject constructor(
private val omnipodManager: OmnipodDashManager,
private val podStateManager: OmnipodDashPodStateManager,
injector: HasAndroidInjector,
logger: AAPSLogger
) : DeactivatePodViewModel(injector, logger) {
override fun doExecuteAction(): Single<PumpEnactResult> = Single.just(
PumpEnactResult(injector).success(true).comment("TODO")
) // TODO
override fun doExecuteAction(): Single<PumpEnactResult> = Single.create { source ->
omnipodManager.deactivatePod().subscribeBy(
onNext = { podEvent ->
logger.debug(
LTag.PUMP,
"Received PodEvent in Pod deactivation: $podEvent"
)
},
onError = { throwable ->
logger.error(LTag.PUMP, "Error in Pod deactivation", throwable)
source.onSuccess(PumpEnactResult(injector).success(false).comment(throwable.message))
},
onComplete = {
logger.debug("Pod deactivation completed")
source.onSuccess(PumpEnactResult(injector).success(true))
}
)
}
override fun discardPod() {
// TODO
podStateManager.reset()
}
@StringRes

View file

@ -4,7 +4,7 @@ import com.google.crypto.tink.subtle.Hex
import info.nightscout.androidaps.logging.AAPSLoggerTest
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.Id
import info.nightscout.androidaps.utils.extensions.toHex
import org.junit.Assert.*
import org.junit.Assert.assertEquals
import org.junit.Test
class MessagePacketTest {

View file

@ -7,6 +7,7 @@ import org.junit.Test
import java.util.*
class PayloadSplitJoinTest {
private val random = Random(42)
@Test fun testSplitAndJoinBack() {

View file

@ -7,6 +7,7 @@ import org.junit.Assert.assertTrue
import org.junit.Test
class PayloadSplitterTest {
@Test fun testSplitter() {
val f1 = "00,01,54,57,10,23,03,00,00,c0,ff,ff,ff,fe,08,20,2e,a8,50,30".replace(",", "")
val f2 = "01,04,bc,20,1f,f6,3d,00,01,a5,ff,ff,ff,fe,08,20,2e,a8,50,30".replace(",", "")

View file

@ -2,10 +2,11 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message
import com.google.crypto.tink.subtle.Hex
import info.nightscout.androidaps.utils.extensions.toHex
import org.junit.Assert.*
import org.junit.Assert.assertEquals
import org.junit.Test
class StringLengthPrefixEncodingTest {
private val p0Payload = Hex.decode("50,30,3d,00,01,a5".replace(",", "")) // from logs
private val p0Content = Hex.decode("a5")

View file

@ -2,11 +2,12 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.pair
import info.nightscout.androidaps.logging.AAPSLoggerTest
import info.nightscout.androidaps.utils.extensions.toHex
import org.junit.Assert.*
import org.junit.Assert.assertEquals
import org.junit.Test
import org.spongycastle.util.encoders.Hex
class KeyExchangeTest {
@Test fun testLTK() {
val aapsLogger = AAPSLoggerTest()
val ke = KeyExchange(

View file

@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session
import info.nightscout.androidaps.logging.AAPSLoggerTest
import info.nightscout.androidaps.utils.extensions.toHex
import org.junit.Assert
import org.junit.Assert.*
import org.junit.Test
import org.spongycastle.util.encoders.Hex
@ -11,7 +10,8 @@ class EapMessageTest {
@Test fun testParseAndBack() {
val aapsLogger = AAPSLoggerTest()
val payload = Hex.decode("01bd0038170100000205000000c55c78e8d3b9b9e935860a7259f6c001050000c2cd1248451103bd77a6c7ef88c441ba7e0200006cff5d18")
val payload =
Hex.decode("01bd0038170100000205000000c55c78e8d3b9b9e935860a7259f6c001050000c2cd1248451103bd77a6c7ef88c441ba7e0200006cff5d18")
val eapMsg = EapMessage.parse(aapsLogger, payload)
val back = eapMsg.toByteArray()
Assert.assertEquals(back.toHex(), payload.toHex())

View file

@ -8,11 +8,11 @@ import org.junit.Test
class DeactivateCommandTest {
@Test @Throws(DecoderException::class) fun testEncoding() {
val encoded = DeactivateCommand.Builder() //
.setUniqueId(37879809) //
.setSequenceNumber(5.toShort()) //
.setNonce(1229869870) //
.build() //
val encoded = DeactivateCommand.Builder()
.setUniqueId(37879809)
.setSequenceNumber(5.toShort())
.setNonce(1229869870)
.build()
.encoded
Assert.assertArrayEquals(Hex.decodeHex("0242000114061C04494E532E001C"), encoded)

View file

@ -9,11 +9,11 @@ import org.junit.Test
class GetStatusCommandTest {
@Test @Throws(DecoderException::class) fun testGetDefaultStatusResponse() {
val encoded = GetStatusCommand.Builder() //
.setUniqueId(37879810) //
.setSequenceNumber(15.toShort()) //
.setStatusResponseType(ResponseType.StatusResponseType.DEFAULT_STATUS_RESPONSE) //
.build() //
val encoded = GetStatusCommand.Builder()
.setUniqueId(37879810)
.setSequenceNumber(15.toShort())
.setStatusResponseType(ResponseType.StatusResponseType.DEFAULT_STATUS_RESPONSE)
.build()
.encoded
Assert.assertArrayEquals(Hex.decodeHex("024200023C030E0100024C"), encoded)

View file

@ -8,10 +8,10 @@ import org.junit.Test
class GetVersionCommandTest {
@Test @Throws(DecoderException::class) fun testEncoding() {
val encoded = GetVersionCommand.Builder() //
.setSequenceNumber(0.toShort()) //
.setUniqueId(GetVersionCommand.DEFAULT_UNIQUE_ID) //
.build() //
val encoded = GetVersionCommand.Builder()
.setSequenceNumber(0.toShort())
.setUniqueId(GetVersionCommand.DEFAULT_UNIQUE_ID)
.build()
.encoded
Assert.assertArrayEquals(Hex.decodeHex("FFFFFFFF00060704FFFFFFFF82B2"), encoded)

View file

@ -15,16 +15,36 @@ class ProgramAlertsCommandTest {
@Test @Throws(DecoderException::class) fun testExpirationAlerts() {
val configurations: MutableList<AlertConfiguration> = ArrayList()
configurations.add(AlertConfiguration(AlertType.EXPIRATION, true, 420.toShort(), false, AlertTrigger.TimerTrigger(4305.toShort()), BeepType.FOUR_TIMES_BIP_BEEP, BeepRepetitionType.XXX3))
configurations.add(AlertConfiguration(AlertType.EXPIRATION_IMMINENT, true, 0.toShort(), false, AlertTrigger.TimerTrigger(4725.toShort()), BeepType.FOUR_TIMES_BIP_BEEP, BeepRepetitionType.XXX4))
configurations.add(
AlertConfiguration(
AlertType.EXPIRATION,
true,
420.toShort(),
false,
AlertTrigger.TimerTrigger(4305.toShort()),
BeepType.FOUR_TIMES_BIP_BEEP,
BeepRepetitionType.XXX3
)
)
configurations.add(
AlertConfiguration(
AlertType.EXPIRATION_IMMINENT,
true,
0.toShort(),
false,
AlertTrigger.TimerTrigger(4725.toShort()),
BeepType.FOUR_TIMES_BIP_BEEP,
BeepRepetitionType.XXX4
)
)
val encoded = ProgramAlertsCommand.Builder() //
.setUniqueId(37879811) //
.setSequenceNumber(3.toShort()) //
.setMultiCommandFlag(true) //
.setNonce(1229869870) //
.setAlertConfigurations(configurations) //
.build() //
val encoded = ProgramAlertsCommand.Builder()
.setUniqueId(37879811)
.setSequenceNumber(3.toShort())
.setMultiCommandFlag(true)
.setNonce(1229869870)
.setAlertConfigurations(configurations)
.build()
.encoded
Assert.assertArrayEquals(Hex.decodeHex("024200038C121910494E532E79A410D1050228001275060280F5"), encoded)
@ -32,14 +52,24 @@ class ProgramAlertsCommandTest {
@Test @Throws(DecoderException::class) fun testLowReservoirAlert() {
val configurations: MutableList<AlertConfiguration> = ArrayList()
configurations.add(AlertConfiguration(AlertType.LOW_RESERVOIR, true, 0.toShort(), false, AlertTrigger.ReservoirVolumeTrigger(200.toShort()), BeepType.FOUR_TIMES_BIP_BEEP, BeepRepetitionType.XXX))
configurations.add(
AlertConfiguration(
AlertType.LOW_RESERVOIR,
true,
0.toShort(),
false,
AlertTrigger.ReservoirVolumeTrigger(200.toShort()),
BeepType.FOUR_TIMES_BIP_BEEP,
BeepRepetitionType.XXX
)
)
val encoded = ProgramAlertsCommand.Builder() //
.setUniqueId(37879811) //
.setSequenceNumber(8.toShort()) //
.setNonce(1229869870) //
.setAlertConfigurations(configurations) //
.build() //
val encoded = ProgramAlertsCommand.Builder()
.setUniqueId(37879811)
.setSequenceNumber(8.toShort())
.setNonce(1229869870)
.setAlertConfigurations(configurations)
.build()
.encoded
Assert.assertArrayEquals(Hex.decodeHex("02420003200C190A494E532E4C0000C801020149"), encoded)
@ -47,14 +77,24 @@ class ProgramAlertsCommandTest {
@Test @Throws(DecoderException::class) fun testUserExpirationAlert() {
val configurations: MutableList<AlertConfiguration> = ArrayList()
configurations.add(AlertConfiguration(AlertType.USER_SET_EXPIRATION, true, 0.toShort(), false, AlertTrigger.TimerTrigger(4079.toShort()), BeepType.FOUR_TIMES_BIP_BEEP, BeepRepetitionType.XXX2))
configurations.add(
AlertConfiguration(
AlertType.USER_SET_EXPIRATION,
true,
0.toShort(),
false,
AlertTrigger.TimerTrigger(4079.toShort()),
BeepType.FOUR_TIMES_BIP_BEEP,
BeepRepetitionType.XXX2
)
)
val encoded = ProgramAlertsCommand.Builder() //
.setUniqueId(37879811) //
.setSequenceNumber(15.toShort()) //
.setNonce(1229869870) //
.setAlertConfigurations(configurations) //
.build() //
val encoded = ProgramAlertsCommand.Builder()
.setUniqueId(37879811)
.setSequenceNumber(15.toShort())
.setNonce(1229869870)
.setAlertConfigurations(configurations)
.build()
.encoded
Assert.assertArrayEquals(Hex.decodeHex("024200033C0C190A494E532E38000FEF030203E2"), encoded)
@ -62,15 +102,25 @@ class ProgramAlertsCommandTest {
@Test @Throws(DecoderException::class) fun testLumpOfCoalAlert() {
val configurations: MutableList<AlertConfiguration> = ArrayList()
configurations.add(AlertConfiguration(AlertType.EXPIRATION, true, 55.toShort(), false, AlertTrigger.TimerTrigger(5.toShort()), BeepType.FOUR_TIMES_BIP_BEEP, BeepRepetitionType.XXX5))
configurations.add(
AlertConfiguration(
AlertType.EXPIRATION,
true,
55.toShort(),
false,
AlertTrigger.TimerTrigger(5.toShort()),
BeepType.FOUR_TIMES_BIP_BEEP,
BeepRepetitionType.XXX5
)
)
val encoded = ProgramAlertsCommand.Builder() //
.setUniqueId(37879811) //
.setSequenceNumber(10.toShort()) //
.setMultiCommandFlag(false) //
.setNonce(1229869870) //
.setAlertConfigurations(configurations) //
.build() //
val encoded = ProgramAlertsCommand.Builder()
.setUniqueId(37879811)
.setSequenceNumber(10.toShort())
.setMultiCommandFlag(false)
.setNonce(1229869870)
.setAlertConfigurations(configurations)
.build()
.encoded
Assert.assertArrayEquals(Hex.decodeHex("02420003280C190A494E532E7837000508020356"), encoded)

View file

@ -17,14 +17,14 @@ class ProgramBasalCommandTest {
val basalProgram = BasalProgram(segments)
val date = Date(121, 1, 17, 14, 47, 43)
val encoded = ProgramBasalCommand.Builder() //
.setUniqueId(37879809) //
.setNonce(1229869870) //
.setSequenceNumber(10.toShort()) //
.setBasalProgram(basalProgram) //
.setCurrentTime(date) //
.setProgramReminder(ProgramReminder(false, true, 0.toByte())) //
.build() //
val encoded = ProgramBasalCommand.Builder()
.setUniqueId(37879809)
.setNonce(1229869870)
.setSequenceNumber(10.toShort())
.setBasalProgram(basalProgram)
.setCurrentTime(date)
.setProgramReminder(ProgramReminder(false, true, 0.toByte()))
.build()
.encoded
Assert.assertArrayEquals(
@ -40,14 +40,14 @@ class ProgramBasalCommandTest {
val basalProgram = BasalProgram(segments)
val date = Date(121, 0, 30, 23, 21, 46)
val encoded = ProgramBasalCommand.Builder() //
.setUniqueId(4241) //
.setNonce(1229869870) //
.setSequenceNumber(12.toShort()) //
.setBasalProgram(basalProgram) //
.setCurrentTime(date) //
.setProgramReminder(ProgramReminder(atStart = false, atEnd = false, atInterval = 0.toByte())) //
.build() //
val encoded = ProgramBasalCommand.Builder()
.setUniqueId(4241)
.setNonce(1229869870)
.setSequenceNumber(12.toShort())
.setBasalProgram(basalProgram)
.setCurrentTime(date)
.setProgramReminder(ProgramReminder(atStart = false, atEnd = false, atInterval = 0.toByte()))
.build()
.encoded
Assert.assertArrayEquals(

View file

@ -10,14 +10,14 @@ import org.junit.Test
class ProgramBeepsCommandTest {
@Test @Throws(DecoderException::class) fun testPlayTestBeep() {
val encoded = ProgramBeepsCommand.Builder() //
.setUniqueId(37879810) //
.setSequenceNumber(11.toShort()) //
.setImmediateBeepType(BeepType.FOUR_TIMES_BIP_BEEP) //
.setBasalReminder(ProgramReminder(false, false, 0.toByte())) //
.setTempBasalReminder(ProgramReminder(false, false, 0.toByte())) //
.setBolusReminder(ProgramReminder(false, false, 0.toByte())) //
.build() //
val encoded = ProgramBeepsCommand.Builder()
.setUniqueId(37879810)
.setSequenceNumber(11.toShort())
.setImmediateBeepType(BeepType.FOUR_TIMES_BIP_BEEP)
.setBasalReminder(ProgramReminder(false, false, 0.toByte()))
.setTempBasalReminder(ProgramReminder(false, false, 0.toByte()))
.setBolusReminder(ProgramReminder(false, false, 0.toByte()))
.build()
.encoded
Assert.assertArrayEquals(Hex.decodeHex("024200022C061E0402000000800F"), encoded)

View file

@ -9,16 +9,19 @@ import org.junit.Test
class ProgramBolusCommandTest {
@Test @Throws(DecoderException::class) fun testProgramBolusCommand() {
val encoded = ProgramBolusCommand.Builder() //
.setNumberOfUnits(5.0) //
.setProgramReminder(ProgramReminder(false, true, 0.toByte())) //
.setDelayBetweenPulsesInEighthSeconds(16.toByte()) //
.setUniqueId(37879809) //
.setSequenceNumber(14.toShort()) //
.setNonce(1229869870) //
.build() //
val encoded = ProgramBolusCommand.Builder()
.setNumberOfUnits(5.0)
.setProgramReminder(ProgramReminder(false, true, 0.toByte()))
.setDelayBetweenPulsesInEighthSeconds(16.toByte())
.setUniqueId(37879809)
.setSequenceNumber(14.toShort())
.setNonce(1229869870)
.build()
.encoded
Assert.assertArrayEquals(Hex.decodeHex("02420001381F1A0E494E532E02010F01064000640064170D4003E800030D4000000000000080F6"), encoded)
Assert.assertArrayEquals(
Hex.decodeHex("02420001381F1A0E494E532E02010F01064000640064170D4003E800030D4000000000000080F6"),
encoded
)
}
}

View file

@ -9,28 +9,34 @@ import org.junit.Test
class ProgramTempBasalCommandTest {
@Test @Throws(DecoderException::class) fun testExtraAlternateSegmentPulseTempBasal() {
val command = ProgramTempBasalCommand.Builder() //
.setUniqueId(37879809) //
.setNonce(1229869870) //
.setSequenceNumber(15.toShort()) //
.setRateInUnitsPerHour(5.05) //
.setDurationInMinutes(60.toShort()) //
.setProgramReminder(ProgramReminder(false, true, 0.toByte())) //
val command = ProgramTempBasalCommand.Builder()
.setUniqueId(37879809)
.setNonce(1229869870)
.setSequenceNumber(15.toShort())
.setRateInUnitsPerHour(5.05)
.setDurationInMinutes(60.toShort())
.setProgramReminder(ProgramReminder(false, true, 0.toByte()))
.build()
Assert.assertArrayEquals(Hex.decodeHex("024200013C201A0E494E532E01011102384000321832160E400003F20036634403F20036634482A6"), command.encoded)
Assert.assertArrayEquals(
Hex.decodeHex("024200013C201A0E494E532E01011102384000321832160E400003F20036634403F20036634482A6"),
command.encoded
)
}
@Test @Throws(DecoderException::class) fun testZeroTempBasal() {
val command = ProgramTempBasalCommand.Builder() //
.setUniqueId(37879809) //
.setNonce(1229869870) //
.setSequenceNumber(7.toShort()) //
.setRateInUnitsPerHour(0.0) //
.setDurationInMinutes(300.toShort()) //
.setProgramReminder(ProgramReminder(true, true, 0.toByte())) //
val command = ProgramTempBasalCommand.Builder()
.setUniqueId(37879809)
.setNonce(1229869870)
.setSequenceNumber(7.toShort())
.setRateInUnitsPerHour(0.0)
.setDurationInMinutes(300.toShort())
.setProgramReminder(ProgramReminder(true, true, 0.toByte()))
.build()
Assert.assertArrayEquals(Hex.decodeHex("024200011C201A0E494E532E0100820A384000009000160EC000000A6B49D200000AEB49D20001DE"), command.encoded)
Assert.assertArrayEquals(
Hex.decodeHex("024200011C201A0E494E532E0100820A384000009000160EC000000A6B49D200000AEB49D20001DE"),
command.encoded
)
}
}

View file

@ -9,13 +9,13 @@ import java.util.*
class SetUniqueIdCommandTest {
@Test @Throws(DecoderException::class) fun testEncoding() {
val encoded = SetUniqueIdCommand.Builder() //
.setUniqueId(37879811) //
.setSequenceNumber(6.toShort()) //
.setLotNumber(135556289) //
.setPodSequenceNumber(681767) //
.setInitializationTime(Date(2021, 1, 10, 14, 41)) //
.build() //
val encoded = SetUniqueIdCommand.Builder()
.setUniqueId(37879811)
.setSequenceNumber(6.toShort())
.setLotNumber(135556289)
.setPodSequenceNumber(681767)
.setInitializationTime(Date(2021, 1, 10, 14, 41))
.build()
.encoded
Assert.assertArrayEquals(Hex.decodeHex("FFFFFFFF18150313024200031404020A150E2908146CC1000A67278344"), encoded)

View file

@ -10,12 +10,12 @@ import java.util.*
class SilenceAlertsCommandTest {
@Test @Throws(DecoderException::class) fun testSilenceLowReservoirAlert() {
val encoded = SilenceAlertsCommand.Builder() //
.setUniqueId(37879811) //
.setSequenceNumber(1.toShort()) //
.setNonce(1229869870) //
.setAlertTypes(EnumSet.of(AlertType.LOW_RESERVOIR)) //
.build() //
val encoded = SilenceAlertsCommand.Builder()
.setUniqueId(37879811)
.setSequenceNumber(1.toShort())
.setNonce(1229869870)
.setAlertTypes(EnumSet.of(AlertType.LOW_RESERVOIR))
.build()
.encoded
Assert.assertArrayEquals(Hex.decodeHex("0242000304071105494E532E1081CE"), encoded)

View file

@ -9,26 +9,26 @@ import org.junit.Test
class StopDeliveryCommandTest {
@Test @Throws(DecoderException::class) fun testStopTempBasal() {
val encoded = StopDeliveryCommand.Builder() //
.setUniqueId(37879811) //
.setSequenceNumber(0.toShort()) //
.setNonce(1229869870) //
.setDeliveryType(StopDeliveryCommand.DeliveryType.TEMP_BASAL) //
.setBeepType(BeepType.LONG_SINGLE_BEEP) //
.build() //
val encoded = StopDeliveryCommand.Builder()
.setUniqueId(37879811)
.setSequenceNumber(0.toShort())
.setNonce(1229869870)
.setDeliveryType(StopDeliveryCommand.DeliveryType.TEMP_BASAL)
.setBeepType(BeepType.LONG_SINGLE_BEEP)
.build()
.encoded
Assert.assertArrayEquals(Hex.decodeHex("0242000300071F05494E532E6201B1"), encoded)
}
@Test @Throws(DecoderException::class) fun testSuspendDelivery() {
val encoded = StopDeliveryCommand.Builder() //
.setUniqueId(37879811) //
.setSequenceNumber(2.toShort()) //
.setNonce(1229869870) //
.setDeliveryType(StopDeliveryCommand.DeliveryType.ALL) //
.setBeepType(BeepType.SILENT) //
.build() //
val encoded = StopDeliveryCommand.Builder()
.setUniqueId(37879811)
.setSequenceNumber(2.toShort())
.setNonce(1229869870)
.setDeliveryType(StopDeliveryCommand.DeliveryType.ALL)
.setBeepType(BeepType.SILENT)
.build()
.encoded
Assert.assertArrayEquals(Hex.decodeHex("0242000308071F05494E532E078287"), encoded)