Skip to content

Commit 9899e3f

Browse files
v0.4.23.0 (final version for Phase 1 release)
- SetTbr, GetTbr and CancelTbr implemented and basically tested - maxBolus and maxBasal setting - started playing with Compose dialogs integration, removed history Dialog for now - extended HomeScreenMirrorDto - TempBasalPair: better toString
1 parent b53e777 commit 9899e3f

16 files changed

Lines changed: 299 additions & 235 deletions

File tree

pump/pump-common/src/main/kotlin/app/aaps/pump/common/defs/TempBasalPair.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ open class TempBasalPair constructor(
3636
}
3737

3838
override fun toString(): String {
39-
return ("TempBasalPair [" + "Rate=" + insulinRate + ", DurationMinutes=" + durationMinutes + ", IsPercent="
40-
+ isPercent + "]")
39+
val unit = if (isPercent) " %" else " U"
40+
return ("TempBasalPair [rate=${insulinRate}${unit},duration=" + durationMinutes + ",id=$id]")
4141
}
4242
}

pump/pump-common/src/main/res/layout/pump_history_activity.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
android:paddingBottom="@dimen/activity_vertical_margin"
88
android:paddingTop="@dimen/activity_vertical_margin"
99
android:background="?attr/activity_title_backgroundColor"
10-
tools:context="info.nightscout.aaps.pump.common.ui.PumpHistoryActivity">
10+
tools:context="app.aaps.pump.common.ui.PumpHistoryActivity">
1111

1212

1313
<LinearLayout

pump/tandem/Tandem_Notes.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
# Tandem
2+
At the moment it seems that t:slim X2 won't have capabilities to support closed loop, so that part
3+
of the project is put on hold now. I refactored code, so that Mobi code Slim code are separate where
4+
needed and common where it isn't. Project is now targeting t:mobi device and if at some point
5+
Slim will support all required remote commands, that part of project can be resurected and made
6+
work with current code.
7+
8+
# Tandem Mobi
9+
10+
Work on Mobi is in progress. Planned are 5 phases of development:
11+
12+
Phase 1: Base framework, configuration commands, set/get profile and set/get TBR (oref0), will need controlX2
13+
for management actions, QualifyingEvents (just display keywords)
14+
Phase 2: Bolus, adding all needed UI elements (needs to be done in Compose) and functionality for
15+
management (all actions done by controlX2: start/stop pump, change reservoir, fill cannula),
16+
start work on History -Reading, maybe also storing into Db, look into Notification, QE to add into Db,
17+
pump reconect whem disconnected (31.6.)
18+
Phase 3: History UI, readHistory after commands (and sync with real Ids), PumpInfo UI, QuickBolus settings
19+
After this phase is done, open to other users to start testing
20+
(31.8)
21+
Phase 4: More on history and Bugfixing, adding security fixes (31.9)
22+
23+
Phase 5: Prepare to add to /dev, clean code, final documentation
24+
25+
26+
27+
28+
129
# Tandem Slim X2
230

331
At the time of creation of project there were only versions of pump available that don't support

pump/tandem/src/main/kotlin/app/aaps/pump/tandem/common/comm/TandemCommunicationManager.kt

Lines changed: 27 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import app.aaps.core.interfaces.rx.bus.RxBus
1010
import app.aaps.core.interfaces.sharedPreferences.SP
1111
import app.aaps.core.ui.extensions.runOnUiThread
1212
import app.aaps.pump.common.data.PumpTimeDifferenceDto
13-
import app.aaps.pump.common.defs.PumpDriverMode
1413
import app.aaps.pump.common.defs.PumpDriverState
1514
import app.aaps.pump.common.defs.PumpErrorType
1615
import app.aaps.pump.common.defs.PumpUpdateFragmentType
@@ -24,23 +23,18 @@ import app.aaps.pump.tandem.common.events.EventHandleQualifyingEvent
2423
import app.aaps.pump.tandem.common.util.PumpX2L
2524
import app.aaps.pump.tandem.common.util.TandemPumpConst
2625
import app.aaps.pump.tandem.common.util.TandemPumpUtil
27-
import com.jwoglom.pumpx2.pump.PumpState
2826
import com.jwoglom.pumpx2.pump.TandemError
2927
import com.jwoglom.pumpx2.pump.bluetooth.TandemBluetoothHandler
3028
import com.jwoglom.pumpx2.pump.bluetooth.TandemConfig
3129
import com.jwoglom.pumpx2.pump.bluetooth.TandemPump
3230
import com.jwoglom.pumpx2.pump.messages.Message
33-
import com.jwoglom.pumpx2.pump.messages.request.currentStatus.ApiVersionRequest
34-
import com.jwoglom.pumpx2.pump.messages.request.currentStatus.TimeSinceResetRequest
3531
import com.jwoglom.pumpx2.pump.messages.response.authentication.AbstractCentralChallengeResponse
3632
import com.jwoglom.pumpx2.pump.messages.response.currentStatus.ApiVersionResponse
3733
import com.jwoglom.pumpx2.pump.messages.response.currentStatus.TimeSinceResetResponse
3834
import com.jwoglom.pumpx2.pump.messages.response.qualifyingEvent.QualifyingEvent
3935
import com.welie.blessed.BluetoothPeripheral
4036
import org.joda.time.DateTime
41-
import timber.log.Timber
42-
import java.time.ZoneId
43-
import java.time.ZonedDateTime
37+
4438
import javax.inject.Inject
4539

4640
/**
@@ -60,7 +54,6 @@ class TandemCommunicationManager @Inject constructor(
6054

6155
lateinit var peripheral: BluetoothPeripheral
6256
var connected = false
63-
//var inConnectMode = false
6457
var errorConnecting = false
6558
var commandRequestModeRunning = false
6659

@@ -82,52 +75,26 @@ class TandemCommunicationManager @Inject constructor(
8275

8376
var operationMode: OperationMode = OperationMode.None
8477

85-
var currentAddress : String? = null
86-
87-
// fun setNewAddress(btAddress: String) {
88-
// if (currentAddress==null) {
89-
// this.currentAddress = btAddress
90-
// } else {
91-
// if (!this.currentAddress.equals(btAddress)) {
92-
// this.currentAddress = btAddress
93-
// this.bluetoothHandler = null
94-
// }
95-
//
96-
// }
97-
//
98-
// }
99-
10078

10179
fun connect(): Boolean {
10280

103-
aapsLogger.info(TAG, "TANDEMDBG: connect() called")
104-
105-
if (pumpStatus.pumpDriverMode== PumpDriverMode.Demo) {
106-
aapsLogger.info(TAG, "TANDEMDBG: connect() - Faked")
107-
return true
108-
}
109-
110-
111-
aapsLogger.info(TAG, "TANDEMDBG: connect() ")
81+
aapsLogger.info(TAG, "connect() ")
11282

11383
if (bluetoothHandler==null) {
11484
createBluetoothHandler()
11585
}
11686

11787
connected = false
118-
// inConnectMode = true
11988
operationMode = OperationMode.ConnectionMode
12089
bluetoothHandler!!.startScan()
12190

12291
while (operationMode == OperationMode.ConnectionMode) {
123-
aapsLogger.info(TAG, "TANDEMDBG: inConnectMode")
124-
Thread.sleep(2000)
92+
93+
Thread.sleep(500)
12594

12695
if (connected || errorConnecting) {
127-
aapsLogger.info(TAG, "TANDEMDBG: connected: ${connected} error: ${errorConnecting}")
128-
// inConnectMode = false
96+
aapsLogger.info(TAG, "connected: ${connected} error: ${errorConnecting}")
12997
operationMode = OperationMode.StandardOperation
130-
//return connected;
13198
}
13299
}
133100

@@ -137,15 +104,7 @@ class TandemCommunicationManager @Inject constructor(
137104

138105
fun disconnect(): Boolean {
139106

140-
// aapsLogger.info(TAG, "TANDEMDBG: disconnect() called")
141-
142-
// if (pumpStatus.pumpDriverMode== PumpDriverMode.Demo) {
143-
// aapsLogger.info(TAG, "TANDEMDBG: disconnect() - Faked")
144-
// return false
145-
// }
146-
147-
148-
aapsLogger.info(TAG, "TANDEMDBG: disconnect ")
107+
aapsLogger.info(TAG, "disconnect()")
149108

150109
if (bluetoothHandler!=null) {
151110
bluetoothHandler!!.stop()
@@ -163,7 +122,6 @@ class TandemCommunicationManager @Inject constructor(
163122
return bluetoothHandler
164123
}
165124
aapsLogger.info(TAG, "createBluetoothHandler for Communication")
166-
//LConfigurator.enableTimber()
167125

168126
runOnUiThread {
169127
bluetoothHandler = TandemBluetoothHandler.getInstance(context, this, timberTree);
@@ -174,46 +132,27 @@ class TandemCommunicationManager @Inject constructor(
174132
pumpUtil.sleep(500)
175133
}
176134

177-
178-
// aapsLogger.info(TAG, "TANDEMDBG: createBluetoothHandler ")
179-
// bluetoothHandler = TandemBluetoothHandler.getInstance(context, this)
180-
// aapsLogger.info(TAG, "TANDEMDBG: createBluetoothHandler ${bluetoothHandler}")
181-
182135
return bluetoothHandler
183136
}
184137

185138

186-
187-
188139
override fun onInitialPumpConnection(peripheral: BluetoothPeripheral) {
189-
aapsLogger.info(TAG, "TANDEMDBG: onInitialPumpConnection: $peripheral")
140+
aapsLogger.info(TAG, "onInitialPumpConnection: $peripheral")
190141

191142
this.peripheral = peripheral
192143
pumpUtil.driverStatus = PumpDriverState.Handshaking
193144
super.onInitialPumpConnection(peripheral)
194145
}
195146

147+
196148
override fun onPumpConnected(peripheral: BluetoothPeripheral?) {
197-
aapsLogger.info(TAG, "TANDEMDBG: onPumpConnected: $peripheral")
149+
aapsLogger.info(TAG, "onPumpConnected: $peripheral")
198150

199151
super.onPumpConnected(peripheral)
200152
}
201153

202154

203155

204-
// override fun onPumpConnected(peripheral: BluetoothPeripheral?) {
205-
// Timber.i("TandemPump: onPumpConnected")
206-
//
207-
// // hack: ensure cached in PumpState.
208-
// Timber.i("JpakeDerivedSecret=%s", PumpState.getJpakeDerivedSecret(context))
209-
// Timber.i("JpakeServerNonce=%s", PumpState.getJpakeServerNonce(context))
210-
//
211-
// sendCommand(peripheral, ApiVersionRequest())
212-
// sendCommand(peripheral, TimeSinceResetRequest())
213-
// }
214-
215-
216-
217156
/**
218157
* Sends command to the pump, if driver is in preventConnect mode any messages will be ignored,
219158
* unless we specify forceSend. Force send should be used only for ChangeFillManager
@@ -228,20 +167,20 @@ class TandemCommunicationManager @Inject constructor(
228167
}
229168

230169
while (!::peripheral.isInitialized && times < 10) {
231-
aapsLogger.warn(LTag.PUMPCOMM, "TANDEMDBG: Waiting for peripheral for sendCommand with ${request.opCode()} - ${request.javaClass.name}")
170+
aapsLogger.warn(LTag.PUMPCOMM, "Waiting for peripheral for sendCommand with ${request.opCode()} - ${request.javaClass.name}")
232171
pumpUtil.sleep(1000)
233172
times++
234173
}
235174

236175
if (!::peripheral.isInitialized) {
237-
aapsLogger.warn(LTag.PUMPCOMM, "TANDEMDBG: Failed sendCommand, no peripheral with ${request.opCode()} - ${request.javaClass.name}")
176+
aapsLogger.warn(LTag.PUMPCOMM, "Failed sendCommand, no peripheral with ${request.opCode()} - ${request.javaClass.name}")
238177
return null;
239178
}
240179
this.commandRequestModeRunning = true
241180
this.commandRequest = request
242181
this.commandResponse = null
243182

244-
aapsLogger.info(LTag.PUMPCOMM, "TANDEMDBG: Sending Request: [code=${request.opCode()},class=${request::class.simpleName}]")
183+
aapsLogger.info(LTag.PUMPCOMM, "Sending Request: [code=${request.opCode()},class=${request::class.simpleName}]")
245184

246185
sendCommand(peripheral, request)
247186

@@ -264,9 +203,7 @@ class TandemCommunicationManager @Inject constructor(
264203

265204
operationMode = OperationMode.ExternalListenerOperation
266205

267-
aapsLogger.warn(LTag.PUMPCOMM, "STM: sendCommandWithListener sendCommand with ${request.opCode()} - ${request.javaClass.simpleName}")
268-
269-
aapsLogger.warn(LTag.PUMPCOMM, "STM: sendCommandWithListener connected [$connected]")
206+
aapsLogger.warn(LTag.PUMPCOMM, "STM: sendCommandWithListener sendCommand with [request_code=${request.opCode()},request_class=${request.javaClass.simpleName},connected=$connected]")
270207

271208
while (!::peripheral.isInitialized && times < 10) {
272209
aapsLogger.warn(LTag.PUMPCOMM, "STM: Waiting for peripheral for sendCommand with ${request.opCode()} - ${request.javaClass.name}")
@@ -278,34 +215,20 @@ class TandemCommunicationManager @Inject constructor(
278215
aapsLogger.warn(LTag.PUMPCOMM, "STM: Failed sendCommand, no peripheral with ${request.opCode()} - ${request.javaClass.name}")
279216
return null;
280217
}
281-
// this.commandRequestModeRunning = true
282-
// this.commandRequest = request
283-
// this.commandResponse = null
284218

285219
aapsLogger.info(LTag.PUMPCOMM, "STM: Sending Request: [code=${request.opCode()},class=${request::class.simpleName}]")
286220

287221
sendCommand(peripheral, request)
288222

289-
// while(commandRequestModeRunning) {
290-
//
291-
// if (commandResponse!=null) {
292-
// this.commandRequestModeRunning = false
293-
// return commandResponse
294-
// }
295-
//
296-
// pumpUtil.sleep(1000)
297-
// }
298-
299223
return null
300224
}
301225

302226

303-
304227
var apiVersionResponseReceived = false
305228

306229

307230
override fun onReceiveMessage(peripheral: BluetoothPeripheral, message: Message) {
308-
aapsLogger.info(LTag.PUMPBTCOMM, "TANDEMDBG: Received Response: ${message.opCode()} - ${message.javaClass.simpleName} - Mode: $operationMode")
231+
aapsLogger.info(LTag.PUMPBTCOMM, "Received Response: ${message.opCode()} - ${message.javaClass.simpleName} - Mode: $operationMode")
309232

310233
when(operationMode) {
311234
OperationMode.ConnectionMode -> receiveMessageInConnectMode(message)
@@ -339,40 +262,39 @@ class TandemCommunicationManager @Inject constructor(
339262

340263
aapsLogger.info(LTag.PUMPCOMM, "TimeSinceResetResponse: ${message}")
341264

342-
val dtPumpInstant = timeSince.currentTimeInstant
265+
//val dtPumpInstant = timeSince.currentTimeInstant
343266

344-
val zonedDateTime: ZonedDateTime = dtPumpInstant.atZone(ZoneId.of("Europe/Dublin"))
345-
//println("ZonedDateTime: $zonedDateTime")
267+
//val zonedDateTime: ZonedDateTime = dtPumpInstant.atZone(ZoneId.systemDefault())
346268

347-
aapsLogger.info(LTag.PUMPCOMM, "Pump Time: Zoned Time ${zonedDateTime}")
269+
///aapsLogger.info(LTag.PUMPCOMM, "Pump Time: Zoned Time ${zonedDateTime}")
348270

349-
val dtPump = DateTime(dtPumpInstant.toEpochMilli())
271+
val dtPump = DateTime(timeSince.currentTimeInstant.toEpochMilli())
350272

351273
val pumpTimeDifference = PumpTimeDifferenceDto(DateTime.now(), dtPump)
352274
pumpStatus.pumpTime = pumpTimeDifference
353275

354-
var timeDiffJson = pumpUtil.gson.toJson(pumpTimeDifference)
276+
//var timeDiffJson = pumpUtil.gson.toJson(pumpTimeDifference)
355277

356-
aapsLogger.info(LTag.PUMPCOMM, "Pump Time: ${timeDiffJson}")
278+
//aapsLogger.info(LTag.PUMPCOMM, "Pump Time: ${timeDiffJson}")
357279

358-
pumpStatus.pumpTime!!.displayTime(gson = pumpUtil.gson, aapsLogger = aapsLogger)
280+
//pumpStatus.pumpTime!!.displayTime(gson = pumpUtil.gson, aapsLogger = aapsLogger)
359281

360282
pumpUtil.driverStatus = PumpDriverState.Connected
361283

362284
this.connected = true
363-
this.operationMode = OperationMode.StandardOperation // TODO this is probably not needed
285+
this.operationMode = OperationMode.StandardOperation
364286

365287
}
366288
}
367289

368290
fun receiveMessageInStandardMode(message: Message) {
369291
if (this.commandRequest==null) {
370-
aapsLogger.error(LTag.PUMPCOMM, "TANDEMDBG: No Command Requested, but received message [code=${message.opCode()}]")
292+
aapsLogger.error(LTag.PUMPCOMM, "No Command Requested, but received message [code=${message.opCode()}]")
371293
} else {
372-
aapsLogger.info(LTag.PUMPCOMM, "TANDEMDBG: receivedMessage [code=${message.opCode()},expected=${commandRequest!!.getResponseOpCode()},class=${message::class.simpleName}]")
294+
aapsLogger.info(LTag.PUMPCOMM, "ReceivedMessage [code=${message.opCode()},expected=${commandRequest!!.getResponseOpCode()},class=${message::class.simpleName}]")
373295

374296
if (message.opCode() == commandRequest!!.getResponseOpCode()) {
375-
aapsLogger.info(LTag.PUMPCOMM, "TANDEMDBG: Response received ${message.opCode()}")
297+
aapsLogger.info(LTag.PUMPCOMM, "Response received [code=${message.opCode()},class=${message::class.simpleName}]")
376298
this.commandResponse = message
377299
} else {
378300
if (message is ApiVersionResponse) {
@@ -385,7 +307,7 @@ class TandemCommunicationManager @Inject constructor(
385307
rxBus.send(EventPumpFragmentValuesChanged(PumpUpdateFragmentType.None))
386308
}
387309
} else {
388-
aapsLogger.info(LTag.PUMPCOMM, "TANDEMDBG: discarding Message [code=${message.opCode()}")
310+
aapsLogger.info(TAG, "Discarding Message [code=${message.opCode()},class=${message.javaClass.simpleName}]")
389311
}
390312

391313
}
@@ -395,7 +317,7 @@ class TandemCommunicationManager @Inject constructor(
395317

396318

397319
override fun onReceiveQualifyingEvent(peripheral: BluetoothPeripheral, events: Set<QualifyingEvent>) {
398-
aapsLogger.info(TAG, "TANDEMDBG: onReceiveQualifyingEvent: %s (creating AAPS event)", events)
320+
aapsLogger.info(TAG, "QE: onReceiveQualifyingEvent: %s (creating AAPS event)", events)
399321
rxBus.send(EventHandleQualifyingEvent(events))
400322
}
401323

@@ -416,12 +338,6 @@ class TandemCommunicationManager @Inject constructor(
416338
}
417339

418340

419-
// TODO 1.4.4
420-
// override fun onInvalidPairingCode(peripheral: BluetoothPeripheral?, resp: PumpChallengeResponse?) {
421-
// aapsLogger.error(TAG, "TANDEMDBG: onInvalidPairingCode() - PairingCode seems to be no longer valid.")
422-
// sendInvalidPairingCodeError()
423-
// }
424-
425341
override fun onPumpCriticalError(peripheral: BluetoothPeripheral?, reason: TandemError?) {
426342
aapsLogger.error(TAG, "Pump Critical Error: ${reason}")
427343

@@ -448,8 +364,6 @@ class TandemCommunicationManager @Inject constructor(
448364
}
449365

450366

451-
// TODO class
452-
453367
enum class OperationMode {
454368
None,
455369
ConnectionMode,

0 commit comments

Comments
 (0)