RS connectivity & bolus improvement
This commit is contained in:
parent
7dd678c917
commit
3cdca93b30
22 changed files with 161 additions and 117 deletions
|
@ -265,7 +265,9 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
@Override
|
||||
public boolean loadHistory(byte type) {
|
||||
connectIfNotConnected("loadHistory");
|
||||
return danaRSService.loadHistory(type);
|
||||
danaRSService.loadHistory(type);
|
||||
disconnect("LoadHistory");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Constraints interface
|
||||
|
@ -393,10 +395,12 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
if (!danaRSService.updateBasalsInPump(profile)) {
|
||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
disconnect("SetNewBasalProfile");
|
||||
return FAILED;
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
disconnect("SetNewBasalProfile");
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -431,6 +435,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
log.debug("Refreshing data from pump");
|
||||
if (!isConnected() && !isConnecting()) {
|
||||
connect(reason);
|
||||
disconnect("RefreshDataFromPump");
|
||||
} else
|
||||
log.debug("Already connecting ...");
|
||||
}
|
||||
|
@ -445,7 +450,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder();
|
||||
detailedBolusInfo.insulin = configBuilderPlugin.applyBolusConstraints(detailedBolusInfo.insulin);
|
||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||
DetailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history
|
||||
int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||
int speed = 12;
|
||||
switch (preferencesSpeed) {
|
||||
|
@ -460,8 +464,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
break;
|
||||
}
|
||||
// v2 stores end time for bolus, we need to adjust time
|
||||
// default delivery speed is 12 U/min
|
||||
detailedBolusInfo.date += detailedBolusInfo.insulin / speed * 60d * 1000;
|
||||
// default delivery speed is 12 sec/U
|
||||
detailedBolusInfo.date += detailedBolusInfo.insulin * speed * 1000;
|
||||
// clean carbs to prevent counting them as twice because they will picked up as another record
|
||||
// I don't think it's necessary to copy DetailedBolusInfo right now for carbs records
|
||||
double carbs = detailedBolusInfo.carbs;
|
||||
|
@ -469,6 +473,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
int carbTime = detailedBolusInfo.carbTime;
|
||||
detailedBolusInfo.carbTime = 0;
|
||||
|
||||
DetailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history
|
||||
|
||||
Treatment t = new Treatment();
|
||||
boolean connectionOK = false;
|
||||
connectIfNotConnected("bolus");
|
||||
|
@ -481,7 +487,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
if (Config.logPumpActions)
|
||||
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
||||
// remove carbs because it's get from history seprately
|
||||
disconnect("DeliverTreatment");
|
||||
return result;
|
||||
} else {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
|
@ -624,6 +630,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
result.isPercent = true;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setTempBasalPercent: OK");
|
||||
disconnect("setTempBasalPercent");
|
||||
return result;
|
||||
}
|
||||
result.enacted = false;
|
||||
|
@ -647,6 +654,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
result.isPercent = true;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setHighTempBasalPercent: OK");
|
||||
disconnect("setHighTempBasalPercent");
|
||||
return result;
|
||||
}
|
||||
result.enacted = false;
|
||||
|
@ -690,6 +698,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
result.isPercent = false;
|
||||
if (Config.logPumpActions)
|
||||
log.debug("setExtendedBolus: OK");
|
||||
disconnect("setExtendedBolus");
|
||||
return result;
|
||||
}
|
||||
result.enacted = false;
|
||||
|
@ -708,6 +717,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
danaRSService.tempBasalStop();
|
||||
result.enacted = true;
|
||||
result.isTempCancel = true;
|
||||
disconnect("cancelTempBasal");
|
||||
}
|
||||
if (!pump.isTempBasalInProgress) {
|
||||
result.success = true;
|
||||
|
@ -734,6 +744,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
danaRSService.extendedBolusStop();
|
||||
result.enacted = true;
|
||||
result.isTempCancel = true;
|
||||
disconnect("extendedBolusStop");
|
||||
}
|
||||
if (!pump.isExtendedInProgress) {
|
||||
result.success = true;
|
||||
|
|
|
@ -4,13 +4,13 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
|
||||
import com.cozmo.danar.util.BleCommandUtil;
|
||||
|
||||
public class DanaRS_Packet_Basal_Set_Basal_Rate extends DanaRS_Packet {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Basal_Rate.class);
|
||||
|
||||
private double[] profileBasalRate;
|
||||
public int error;
|
||||
|
||||
public DanaRS_Packet_Basal_Set_Basal_Rate() {
|
||||
super();
|
||||
|
@ -38,11 +38,12 @@ public class DanaRS_Packet_Basal_Set_Basal_Rate extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@ import com.cozmo.danar.util.BleCommandUtil;
|
|||
public class DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal extends DanaRS_Packet {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal.class);
|
||||
|
||||
public int error;
|
||||
|
||||
public DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal() {
|
||||
super();
|
||||
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__CANCEL_TEMPORARY_BASAL;
|
||||
|
@ -22,9 +20,12 @@ public class DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal extends DanaRS_Packe
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
error = byteArrayToInt(getBytes(data, DATA_START, 1));
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result " + error);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ public class DanaRS_Packet_Basal_Set_Profile_Basal_Rate extends DanaRS_Packet {
|
|||
|
||||
private int profileNumber; // 0 - 4
|
||||
private double[] profileBasalRate;
|
||||
public int error;
|
||||
|
||||
public DanaRS_Packet_Basal_Set_Profile_Basal_Rate() {
|
||||
super();
|
||||
|
@ -41,11 +40,12 @@ public class DanaRS_Packet_Basal_Set_Profile_Basal_Rate extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import com.cozmo.danar.util.BleCommandUtil;
|
|||
public class DanaRS_Packet_Basal_Set_Profile_Number extends DanaRS_Packet {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Profile_Number.class);
|
||||
private int profileNumber;
|
||||
public int error;
|
||||
|
||||
public DanaRS_Packet_Basal_Set_Profile_Number() {
|
||||
super();
|
||||
|
@ -33,11 +32,12 @@ public class DanaRS_Packet_Basal_Set_Profile_Number extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.cozmo.danar.util.BleCommandUtil;
|
|||
|
||||
public class DanaRS_Packet_Basal_Set_Suspend_Off extends DanaRS_Packet {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Suspend_Off.class);
|
||||
public int error;
|
||||
|
||||
public DanaRS_Packet_Basal_Set_Suspend_Off() {
|
||||
super();
|
||||
|
@ -20,11 +19,12 @@ public class DanaRS_Packet_Basal_Set_Suspend_Off extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.cozmo.danar.util.BleCommandUtil;
|
|||
|
||||
public class DanaRS_Packet_Basal_Set_Suspend_On extends DanaRS_Packet {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Set_Suspend_On.class);
|
||||
public int error;
|
||||
|
||||
public DanaRS_Packet_Basal_Set_Suspend_On() {
|
||||
super();
|
||||
|
@ -20,11 +19,12 @@ public class DanaRS_Packet_Basal_Set_Suspend_On extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ public class DanaRS_Packet_Basal_Set_Temporary_Basal extends DanaRS_Packet {
|
|||
|
||||
private int temporaryBasalRatio;
|
||||
private int temporaryBasalDuration;
|
||||
public int error;
|
||||
|
||||
public DanaRS_Packet_Basal_Set_Temporary_Basal() {
|
||||
super();
|
||||
|
@ -37,11 +36,12 @@ public class DanaRS_Packet_Basal_Set_Temporary_Basal extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,12 +111,12 @@ public class DanaRS_Packet_Bolus_Set_Bolus_Option extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -83,12 +83,12 @@ public class DanaRS_Packet_Bolus_Set_CIR_CF_Array extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,12 +44,12 @@ public class DanaRS_Packet_Bolus_Set_Dual_Bolus extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,12 +40,12 @@ public class DanaRS_Packet_Bolus_Set_Extended_Bolus extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,12 @@ public class DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel extends DanaRS_Packet
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,12 +44,12 @@ public class DanaRS_Packet_Bolus_Set_Initial_Bolus extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,14 +48,12 @@ public class DanaRS_Packet_Bolus_Set_Step_Bolus_Start extends DanaRS_Packet {
|
|||
}
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
failed = status != 0x00;
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,13 +35,14 @@ public class DanaRS_Packet_Bolus_Set_Step_Bolus_Stop extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
stopped = true;
|
||||
if (!forced) {
|
||||
|
|
|
@ -31,12 +31,12 @@ public class DanaRS_Packet_General_Set_History_Upload_Mode extends DanaRS_Packet
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,12 +17,12 @@ public class DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear extends DanaR
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
int status = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
int result = intFromBuff(data, 0, 1);
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + status);
|
||||
if (result == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,10 @@ public class DanaRS_Packet_Option_Set_Pump_Time extends DanaRS_Packet {
|
|||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (error == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,10 @@ public class DanaRS_Packet_Option_Set_User_Option extends DanaRS_Packet {
|
|||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Result: " + error);
|
||||
if (error == 0)
|
||||
log.debug("Result OK");
|
||||
else
|
||||
log.error("Result Error: " + error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -165,19 +165,6 @@ public class BLEComm {
|
|||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING));
|
||||
isConnecting = true;
|
||||
|
||||
// Following should be removed later because we close Gatt on disconnect and this should never happen
|
||||
if ((mBluetoothDeviceAddress != null) && (address.equals(mBluetoothDeviceAddress)) && (mBluetoothGatt != null)) {
|
||||
log.debug("Trying to use an existing mBluetoothGatt for connection.");
|
||||
sHandler.post(updateProgress);
|
||||
if (mBluetoothGatt.connect()) {
|
||||
setCharacteristicNotification(getUARTReadBTGattChar(), true);
|
||||
return true;
|
||||
}
|
||||
sHandler.removeCallbacks(updateProgress);
|
||||
return false;
|
||||
}
|
||||
// end
|
||||
|
||||
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
|
||||
if (device == null) {
|
||||
log.debug("Device not found. Unable to connect.");
|
||||
|
@ -201,12 +188,19 @@ public class BLEComm {
|
|||
|
||||
public void disconnect(String from) {
|
||||
log.debug("disconnect from: " + from);
|
||||
|
||||
// cancel previous scheduled disconnection to prevent closing upcomming connection
|
||||
if (scheduledDisconnection != null)
|
||||
scheduledDisconnection.cancel(false);
|
||||
scheduledDisconnection = null;
|
||||
|
||||
if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) {
|
||||
return;
|
||||
}
|
||||
setCharacteristicNotification(getUARTReadBTGattChar(), false);
|
||||
mBluetoothGatt.disconnect();
|
||||
isConnected = false;
|
||||
SystemClock.sleep(2000);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
@ -214,6 +208,7 @@ public class BLEComm {
|
|||
if (mBluetoothGatt == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mBluetoothGatt.close();
|
||||
mBluetoothGatt = null;
|
||||
}
|
||||
|
@ -687,18 +682,19 @@ public class BLEComm {
|
|||
}
|
||||
|
||||
public void scheduleDisconnection() {
|
||||
|
||||
class DisconnectRunnable implements Runnable {
|
||||
public void run() {
|
||||
disconnect("scheduleDisconnection");
|
||||
scheduledDisconnection = null;
|
||||
}
|
||||
}
|
||||
// prepare task for execution in 5 sec
|
||||
// prepare task for execution in 30 sec
|
||||
// cancel waiting task to prevent sending multiple disconnections
|
||||
if (scheduledDisconnection != null)
|
||||
scheduledDisconnection.cancel(false);
|
||||
Runnable task = new DisconnectRunnable();
|
||||
final int sec = 5;
|
||||
final int sec = 30;
|
||||
scheduledDisconnection = worker.schedule(task, sec, TimeUnit.SECONDS);
|
||||
log.debug("Disconnection scheduled");
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import info.nightscout.androidaps.events.EventInitializationChanged;
|
|||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
||||
|
@ -188,16 +189,16 @@ public class DanaRSService extends Service {
|
|||
while (!msg.done && bleComm.isConnected()) {
|
||||
SystemClock.sleep(100);
|
||||
}
|
||||
SystemClock.sleep(200);
|
||||
lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean bolus(double insulin, int carbs, long carbtime, Treatment t) {
|
||||
public boolean bolus(final double insulin, int carbs, long carbtime, Treatment t) {
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.startingbolus)));
|
||||
bolusingTreatment = t;
|
||||
int speed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||
DanaRS_Packet_Bolus_Set_Step_Bolus_Start start = new DanaRS_Packet_Bolus_Set_Step_Bolus_Start(insulin, speed);
|
||||
final int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||
DanaRS_Packet_Bolus_Set_Step_Bolus_Start start = new DanaRS_Packet_Bolus_Set_Step_Bolus_Start(insulin, preferencesSpeed);
|
||||
DanaRS_Packet_Bolus_Set_Step_Bolus_Stop stop = new DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(insulin, t); // initialize static variables
|
||||
DanaRS_Packet_Notify_Delivery_Complete complete = new DanaRS_Packet_Notify_Delivery_Complete(insulin, t); // initialize static variables
|
||||
|
||||
|
@ -210,28 +211,57 @@ public class DanaRSService extends Service {
|
|||
bleComm.sendMessage(msgSetHistoryEntry_v2);
|
||||
lastHistoryFetched = carbtime - 60000;
|
||||
}
|
||||
if (insulin > 0) {
|
||||
DanaRS_Packet_Notify_Delivery_Rate_Display progress = new DanaRS_Packet_Notify_Delivery_Rate_Display(insulin, t); // initialize static variables
|
||||
|
||||
final long bolusStart = System.currentTimeMillis();
|
||||
if (insulin > 0) {
|
||||
if (!stop.stopped) {
|
||||
bleComm.sendMessage(start);
|
||||
} else {
|
||||
t.insulin = 0d;
|
||||
return false;
|
||||
}
|
||||
DanaRS_Packet_Notify_Delivery_Rate_Display progress = new DanaRS_Packet_Notify_Delivery_Rate_Display(insulin, t); // initialize static variables
|
||||
|
||||
while (!stop.stopped && !start.failed && !complete.done) {
|
||||
SystemClock.sleep(100);
|
||||
if ((System.currentTimeMillis() - progress.lastReceive) > 5 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm
|
||||
if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 1000L) { // if i didn't receive status for more than 20 sec expecting broken comm
|
||||
stop.stopped = true;
|
||||
stop.forced = true;
|
||||
log.debug("Communication stopped");
|
||||
}
|
||||
}
|
||||
}
|
||||
SystemClock.sleep(3000);
|
||||
|
||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||
bolusingEvent.t = t;
|
||||
bolusingEvent.percent = 99;
|
||||
|
||||
bolusingTreatment = null;
|
||||
DanaRSPlugin.connectIfNotConnected("ReadHistoryAfterBolus");
|
||||
int speed = 12;
|
||||
switch (preferencesSpeed) {
|
||||
case 0:
|
||||
speed = 12;
|
||||
break;
|
||||
case 1:
|
||||
speed = 30;
|
||||
break;
|
||||
case 2:
|
||||
speed = 60;
|
||||
break;
|
||||
}
|
||||
long bolusDurationInMSec = (long) (insulin * speed * 1000);
|
||||
long expectedEnd = bolusStart + bolusDurationInMSec + 2000;
|
||||
while (System.currentTimeMillis() < expectedEnd) {
|
||||
long waitTime = expectedEnd - System.currentTimeMillis();
|
||||
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.waitingforestimatedbolusend), waitTime / 1000);
|
||||
MainApp.bus().post(bolusingEvent);
|
||||
SystemClock.sleep(1000);
|
||||
}
|
||||
if (!(isConnected()))
|
||||
DanaRSPlugin.getPlugin().connect("loadEvents");
|
||||
loadEvents();
|
||||
bolusingEvent.percent = 100;
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue