DanaRv2 queue & pump autodection
This commit is contained in:
parent
8818afe033
commit
a13661400f
26 changed files with 196 additions and 132 deletions
|
@ -7,5 +7,6 @@ import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface DanaRInterface {
|
public interface DanaRInterface {
|
||||||
PumpEnactResult loadHistory(byte type);
|
PumpEnactResult loadHistory(byte type); // for history browser
|
||||||
|
PumpEnactResult loadEvents(); // events history to build treatments from
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ public class Notification {
|
||||||
public static final int TOAST_ALARM = 22;
|
public static final int TOAST_ALARM = 22;
|
||||||
public static final int WRONGBASALSTEP = 23;
|
public static final int WRONGBASALSTEP = 23;
|
||||||
public static final int BOLUS_DELIVERY_ERROR = 24;
|
public static final int BOLUS_DELIVERY_ERROR = 24;
|
||||||
|
public static final int WRONG_DRIVER = 24;
|
||||||
|
|
||||||
public int id;
|
public int id;
|
||||||
public Date date;
|
public Date date;
|
||||||
|
|
|
@ -756,6 +756,11 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
return sExecutionService.loadHistory(type);
|
return sExecutionService.loadHistory(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PumpEnactResult loadEvents() {
|
||||||
|
return null; // no history, not needed
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constraint interface
|
* Constraint interface
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -31,8 +31,7 @@ public class MsgCheckValue extends MessageBase {
|
||||||
pump.protocol = intFromBuff(bytes, 1, 1);
|
pump.protocol = intFromBuff(bytes, 1, 1);
|
||||||
pump.productCode = intFromBuff(bytes, 2, 1);
|
pump.productCode = intFromBuff(bytes, 2, 1);
|
||||||
if (pump.model != DanaRPump.EXPORT_MODEL) {
|
if (pump.model != DanaRPump.EXPORT_MODEL) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
|
MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model");
|
||||||
((DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class)).disconnect("Wrong Model");
|
|
||||||
log.debug("Wrong model selected");
|
log.debug("Wrong model selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,12 @@ import java.util.Date;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
|
@ -25,8 +29,9 @@ public class MsgInitConnStatusTime extends MessageBase {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(byte[] bytes) {
|
public void handleMessage(byte[] bytes) {
|
||||||
if (bytes.length - 10 > 7) {
|
if (bytes.length - 10 > 7) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
|
Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL);
|
||||||
((DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class)).disconnect("Wrong Model");
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
|
MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model");
|
||||||
log.debug("Wrong model selected. Switching to Korean DanaR");
|
log.debug("Wrong model selected. Switching to Korean DanaR");
|
||||||
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, true);
|
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, true);
|
||||||
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, true);
|
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, true);
|
||||||
|
@ -41,7 +46,8 @@ public class MsgInitConnStatusTime extends MessageBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.getConfigBuilder().storeSettings();
|
MainApp.getConfigBuilder().storeSettings();
|
||||||
MainApp.bus().post(new EventRefreshOverview("MsgInitConnStatusTime"));
|
MainApp.bus().post(new EventRefreshGui());
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -758,6 +758,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
return sExecutionService.loadHistory(type);
|
return sExecutionService.loadHistory(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PumpEnactResult loadEvents() {
|
||||||
|
return null; // no history, not needed
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constraint interface
|
* Constraint interface
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -32,7 +32,6 @@ public class MsgCheckValue_k extends MessageBase {
|
||||||
pump.protocol = intFromBuff(bytes, 1, 1);
|
pump.protocol = intFromBuff(bytes, 1, 1);
|
||||||
pump.productCode = intFromBuff(bytes, 2, 1);
|
pump.productCode = intFromBuff(bytes, 2, 1);
|
||||||
if (pump.model != DanaRPump.DOMESTIC_MODEL) {
|
if (pump.model != DanaRPump.DOMESTIC_MODEL) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
|
|
||||||
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
|
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
|
||||||
log.debug("Wrong model selected");
|
log.debug("Wrong model selected");
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,11 @@ import java.util.Date;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||||
|
@ -27,7 +30,8 @@ public class MsgInitConnStatusTime_k extends MessageBase {
|
||||||
public void handleMessage(byte[] bytes) {
|
public void handleMessage(byte[] bytes) {
|
||||||
|
|
||||||
if (bytes.length - 10 < 10) {
|
if (bytes.length - 10 < 10) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
|
Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL);
|
||||||
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
|
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
|
||||||
log.debug("Wrong model selected. Switching to export DanaR");
|
log.debug("Wrong model selected. Switching to export DanaR");
|
||||||
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, false);
|
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, false);
|
||||||
|
@ -37,13 +41,14 @@ public class MsgInitConnStatusTime_k extends MessageBase {
|
||||||
DanaRPump.getInstance().lastConnection = new Date(0); // mark not initialized
|
DanaRPump.getInstance().lastConnection = new Date(0); // mark not initialized
|
||||||
|
|
||||||
//If profile coming from pump, switch it as well
|
//If profile coming from pump, switch it as well
|
||||||
if(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PROFILE)){
|
if (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PROFILE)) {
|
||||||
(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, false);
|
(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, false);
|
||||||
(MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, true);
|
(MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.getConfigBuilder().storeSettings();
|
MainApp.getConfigBuilder().storeSettings();
|
||||||
MainApp.bus().post(new EventRefreshOverview("MsgInitConnStatusTime_k"));
|
MainApp.bus().post(new EventRefreshGui());
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -262,6 +262,11 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
return danaRSService.loadHistory(type);
|
return danaRSService.loadHistory(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PumpEnactResult loadEvents() {
|
||||||
|
return danaRSService.loadEvents();
|
||||||
|
}
|
||||||
|
|
||||||
// Constraints interface
|
// Constraints interface
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,6 +25,7 @@ import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
||||||
|
@ -70,6 +71,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_D
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_Delivery_Rate_Display;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_Delivery_Rate_Display;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Get_Pump_Time;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Get_Pump_Time;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Set_Pump_Time;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Set_Pump_Time;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
@ -171,7 +173,7 @@ public class DanaRSService extends Service {
|
||||||
log.debug("Pump status loaded");
|
log.debug("Pump status loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadEvents() {
|
public PumpEnactResult loadEvents() {
|
||||||
DanaRS_Packet_APS_History_Events msg;
|
DanaRS_Packet_APS_History_Events msg;
|
||||||
if (lastHistoryFetched == 0) {
|
if (lastHistoryFetched == 0) {
|
||||||
msg = new DanaRS_Packet_APS_History_Events(0);
|
msg = new DanaRS_Packet_APS_History_Events(0);
|
||||||
|
@ -186,6 +188,7 @@ public class DanaRSService extends Service {
|
||||||
}
|
}
|
||||||
lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded;
|
lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded;
|
||||||
log.debug("Events loaded");
|
log.debug("Events loaded");
|
||||||
|
return new PumpEnactResult().success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -227,7 +230,7 @@ public class DanaRSService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||||
bolusingEvent.t = t;
|
bolusingEvent.t = t;
|
||||||
bolusingEvent.percent = 99;
|
bolusingEvent.percent = 99;
|
||||||
|
|
||||||
|
@ -252,14 +255,16 @@ public class DanaRSService extends Service {
|
||||||
MainApp.bus().post(bolusingEvent);
|
MainApp.bus().post(bolusingEvent);
|
||||||
SystemClock.sleep(1000);
|
SystemClock.sleep(1000);
|
||||||
}
|
}
|
||||||
if (!(isConnected()))
|
ConfigBuilderPlugin.getCommandQueue().loadEvents(new Callback() {
|
||||||
DanaRSPlugin.getPlugin().connect("loadEvents");
|
@Override
|
||||||
loadEvents();
|
public void run() {
|
||||||
// reread bolus status
|
// reread bolus status
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
||||||
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // last bolus
|
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // last bolus
|
||||||
bolusingEvent.percent = 100;
|
bolusingEvent.percent = 100;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
|
||||||
|
}
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -361,9 +361,10 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
||||||
// Recheck pump status if older than 30 min
|
// Recheck pump status if older than 30 min
|
||||||
if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
//This should not be needed while using queue because connection should be done before calling this
|
||||||
connect("setTempBasalAbsolute old data");
|
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
||||||
}
|
// connect("setTempBasalAbsolute old data");
|
||||||
|
//}
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
||||||
|
@ -625,12 +626,12 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopConnecting() {
|
public void stopConnecting() {
|
||||||
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
if (sExecutionService != null) sExecutionService.stopConnecting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getPumpStatus() {
|
public void getPumpStatus() {
|
||||||
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
if (sExecutionService != null) sExecutionService.getPumpStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -700,6 +701,11 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
return sExecutionService.loadHistory(type);
|
return sExecutionService.loadHistory(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PumpEnactResult loadEvents() {
|
||||||
|
return sExecutionService.loadEvents();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constraint interface
|
* Constraint interface
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,11 +3,17 @@ package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||||
|
@ -36,13 +42,31 @@ public class MsgCheckValue_v2 extends MessageBase {
|
||||||
pump.protocol = intFromBuff(bytes, 1, 1);
|
pump.protocol = intFromBuff(bytes, 1, 1);
|
||||||
pump.productCode = intFromBuff(bytes, 2, 1);
|
pump.productCode = intFromBuff(bytes, 2, 1);
|
||||||
if (pump.model != DanaRPump.EXPORT_MODEL) {
|
if (pump.model != DanaRPump.EXPORT_MODEL) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
|
Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL);
|
||||||
DanaRv2Plugin.getPlugin().disconnect("Wrong Model");
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
log.debug("Wrong model selected");
|
MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model");
|
||||||
|
log.debug("Wrong model selected. Switching to Korean DanaR");
|
||||||
|
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, true);
|
||||||
|
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, true);
|
||||||
|
MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentEnabled(PluginBase.PUMP, false);
|
||||||
|
MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginBase.PUMP, false);
|
||||||
|
DanaRPump.getInstance().lastConnection = new Date(0); // mark not initialized
|
||||||
|
|
||||||
|
//If profile coming from pump, switch it as well
|
||||||
|
if(MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginBase.PROFILE)){
|
||||||
|
(MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, false);
|
||||||
|
(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
MainApp.getConfigBuilder().storeSettings();
|
||||||
|
MainApp.bus().post(new EventRefreshGui());
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pump.protocol != 2) {
|
if (pump.protocol != 2) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
|
Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL);
|
||||||
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
|
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
|
||||||
log.debug("Wrong model selected. Switching to non APS DanaR");
|
log.debug("Wrong model selected. Switching to non APS DanaR");
|
||||||
(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setFragmentEnabled(PluginBase.PUMP, false);
|
(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setFragmentEnabled(PluginBase.PUMP, false);
|
||||||
|
@ -57,7 +81,8 @@ public class MsgCheckValue_v2 extends MessageBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.getConfigBuilder().storeSettings();
|
MainApp.getConfigBuilder().storeSettings();
|
||||||
MainApp.bus().post(new EventRefreshOverview("MsgCheckValue_v2"));
|
MainApp.bus().post(new EventRefreshGui());
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Config.logDanaMessageDetail) {
|
if (Config.logDanaMessageDetail) {
|
||||||
|
|
|
@ -35,6 +35,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
||||||
|
@ -49,6 +50,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetHistoryEntry_v2
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgCheckValue_v2;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgCheckValue_v2;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusBolusExtended_v2;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusBolusExtended_v2;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusTempBasal_v2;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusTempBasal_v2;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.ToastUtils;
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
@ -62,14 +64,12 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
private BluetoothSocket mRfcommSocket;
|
private BluetoothSocket mRfcommSocket;
|
||||||
private BluetoothDevice mBTDevice;
|
private BluetoothDevice mBTDevice;
|
||||||
|
|
||||||
private PowerManager.WakeLock mWakeLock;
|
|
||||||
private IBinder mBinder = new LocalBinder();
|
private IBinder mBinder = new LocalBinder();
|
||||||
|
|
||||||
private DanaRPump danaRPump;
|
private DanaRPump danaRPump;
|
||||||
private Treatment bolusingTreatment = null;
|
private Treatment bolusingTreatment = null;
|
||||||
|
|
||||||
private static Boolean connectionInProgress = false;
|
private static Boolean connectionInProgress = false;
|
||||||
private static final Object connectionLock = new Object();
|
|
||||||
|
|
||||||
private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
|
private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
|
||||||
|
|
||||||
|
@ -96,9 +96,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
registerBus();
|
registerBus();
|
||||||
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
||||||
danaRPump = DanaRPump.getInstance();
|
danaRPump = DanaRPump.getInstance();
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
|
||||||
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaRv2ExecutionService");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LocalBinder extends Binder {
|
public class LocalBinder extends Binder {
|
||||||
|
@ -160,35 +157,28 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error);
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (isConnected() || isConnecting()) {
|
|
||||||
if (Config.logDanaBTComm)
|
if (connectionInProgress)
|
||||||
log.debug("already connected/connecting from: " + from);
|
return;
|
||||||
waitMsec(3000);
|
|
||||||
}
|
new Thread(new Runnable() {
|
||||||
final long maxConnectionTime = 5 * 60 * 1000L; // 5 min
|
@Override
|
||||||
synchronized (connectionLock) {
|
public void run() {
|
||||||
//log.debug("entering connection while loop");
|
connectionInProgress = true;
|
||||||
connectionInProgress = true;
|
getBTSocketForSelectedPump();
|
||||||
mWakeLock.acquire();
|
if (mRfcommSocket == null || mBTDevice == null) {
|
||||||
getBTSocketForSelectedPump();
|
connectionInProgress = false;
|
||||||
if (mRfcommSocket == null || mBTDevice == null)
|
return; // Device not found
|
||||||
return; // Device not found
|
}
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
while (!isConnected() && startTime + maxConnectionTime >= System.currentTimeMillis()) {
|
|
||||||
long secondsElapsed = (System.currentTimeMillis() - startTime) / 1000L;
|
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
|
|
||||||
if (Config.logDanaBTComm)
|
|
||||||
log.debug("connect waiting " + secondsElapsed + "sec from: " + from);
|
|
||||||
try {
|
try {
|
||||||
mRfcommSocket.connect();
|
mRfcommSocket.connect();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
//log.error("Unhandled exception", e);
|
//log.error("Unhandled exception", e);
|
||||||
if (e.getMessage().contains("socket closed")) {
|
if (e.getMessage().contains("socket closed")) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
waitMsec(1000);
|
|
||||||
|
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
if (mSerialIOThread != null) {
|
if (mSerialIOThread != null) {
|
||||||
|
@ -196,23 +186,16 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
|
||||||
if (!getPumpStatus()) {
|
|
||||||
mSerialIOThread.disconnect("getPumpStatus failed");
|
|
||||||
waitMsec(3000);
|
|
||||||
if (!MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginBase.PUMP))
|
|
||||||
return;
|
|
||||||
getBTSocketForSelectedPump();
|
|
||||||
startTime = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connectionInProgress = false;
|
||||||
}
|
}
|
||||||
if (!isConnected()) {
|
}).start();
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
|
}
|
||||||
log.error("Pump connection timed out");
|
|
||||||
}
|
public void stopConnecting() {
|
||||||
connectionInProgress = false;
|
if (mSerialIOThread != null)
|
||||||
mWakeLock.release();
|
mSerialIOThread.disconnect("stopConnecting");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getBTSocketForSelectedPump() {
|
private void getBTSocketForSelectedPump() {
|
||||||
|
@ -247,7 +230,7 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
mSerialIOThread.disconnect("EventPreferenceChange");
|
mSerialIOThread.disconnect("EventPreferenceChange");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getPumpStatus() {
|
public void getPumpStatus() {
|
||||||
try {
|
try {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
|
||||||
MsgStatus statusMsg = new MsgStatus();
|
MsgStatus statusMsg = new MsgStatus();
|
||||||
|
@ -259,7 +242,7 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
if (danaRPump.isNewPump) {
|
if (danaRPump.isNewPump) {
|
||||||
mSerialIOThread.sendMessage(checkValue);
|
mSerialIOThread.sendMessage(checkValue);
|
||||||
if (!checkValue.received) {
|
if (!checkValue.received) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,28 +254,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingextendedbolusstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingextendedbolusstatus)));
|
||||||
mSerialIOThread.sendMessage(exStatusMsg);
|
mSerialIOThread.sendMessage(exStatusMsg);
|
||||||
|
|
||||||
if (!statusMsg.received) {
|
|
||||||
mSerialIOThread.sendMessage(statusMsg);
|
|
||||||
}
|
|
||||||
if (!statusBasicMsg.received) {
|
|
||||||
mSerialIOThread.sendMessage(statusBasicMsg);
|
|
||||||
}
|
|
||||||
if (!tempStatusMsg.received) {
|
|
||||||
// Load of status of current basal rate failed, give one more try
|
|
||||||
mSerialIOThread.sendMessage(tempStatusMsg);
|
|
||||||
}
|
|
||||||
if (!exStatusMsg.received) {
|
|
||||||
// Load of status of current extended bolus failed, give one more try
|
|
||||||
mSerialIOThread.sendMessage(exStatusMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check we have really current status of pump
|
|
||||||
if (!statusMsg.received || !statusBasicMsg.received || !tempStatusMsg.received || !exStatusMsg.received) {
|
|
||||||
waitMsec(10 * 1000);
|
|
||||||
log.debug("getPumpStatus failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !MainApp.getSpecificPlugin(DanaRv2Plugin.class).isInitialized()) {
|
if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !MainApp.getSpecificPlugin(DanaRv2Plugin.class).isInitialized()) {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpsettings)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpsettings)));
|
||||||
|
@ -334,11 +295,10 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tempBasal(int percent, int durationInHours) {
|
public boolean tempBasal(int percent, int durationInHours) {
|
||||||
connect("tempBasal");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
if (danaRPump.isTempBasalInProgress) {
|
if (danaRPump.isTempBasalInProgress) {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
||||||
|
@ -354,7 +314,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean highTempBasal(int percent) {
|
public boolean highTempBasal(int percent) {
|
||||||
connect("highTempBasal");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
if (danaRPump.isTempBasalInProgress) {
|
if (danaRPump.isTempBasalInProgress) {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
||||||
|
@ -370,7 +329,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tempBasalStop() {
|
public boolean tempBasalStop() {
|
||||||
connect("tempBasalStop");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
||||||
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
|
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
|
||||||
|
@ -381,7 +339,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean extendedBolus(double insulin, int durationInHalfHours) {
|
public boolean extendedBolus(double insulin, int durationInHalfHours) {
|
||||||
connect("extendedBolus");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus)));
|
||||||
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
|
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
|
||||||
|
@ -392,7 +349,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean extendedBolusStop() {
|
public boolean extendedBolusStop() {
|
||||||
connect("extendedBolusStop");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus)));
|
||||||
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
|
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
|
||||||
|
@ -402,7 +358,7 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean bolus(final double amount, int carbs, long carbtime, Treatment t) {
|
public boolean bolus(final double amount, int carbs, long carbtime, final Treatment t) {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.startingbolus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.startingbolus)));
|
||||||
bolusingTreatment = t;
|
bolusingTreatment = t;
|
||||||
final int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
final int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||||
|
@ -413,7 +369,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
start = new MsgBolusStartWithSpeed(amount, preferencesSpeed);
|
start = new MsgBolusStartWithSpeed(amount, preferencesSpeed);
|
||||||
MsgBolusStop stop = new MsgBolusStop(amount, t);
|
MsgBolusStop stop = new MsgBolusStop(amount, t);
|
||||||
|
|
||||||
connect("bolus");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
|
|
||||||
if (carbs > 0) {
|
if (carbs > 0) {
|
||||||
|
@ -436,7 +391,7 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
while (!stop.stopped && !start.failed) {
|
while (!stop.stopped && !start.failed) {
|
||||||
waitMsec(100);
|
waitMsec(100);
|
||||||
if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 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 15 sec expecting broken comm
|
||||||
stop.stopped = true;
|
stop.stopped = true;
|
||||||
stop.forced = true;
|
stop.forced = true;
|
||||||
log.debug("Communication stopped");
|
log.debug("Communication stopped");
|
||||||
|
@ -444,7 +399,7 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||||
bolusingEvent.t = t;
|
bolusingEvent.t = t;
|
||||||
bolusingEvent.percent = 99;
|
bolusingEvent.percent = 99;
|
||||||
|
|
||||||
|
@ -469,16 +424,18 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
MainApp.bus().post(bolusingEvent);
|
MainApp.bus().post(bolusingEvent);
|
||||||
SystemClock.sleep(1000);
|
SystemClock.sleep(1000);
|
||||||
}
|
}
|
||||||
if (!(isConnected()))
|
ConfigBuilderPlugin.getCommandQueue().loadEvents(new Callback() {
|
||||||
connect("loadEvents");
|
@Override
|
||||||
loadEvents();
|
public void run() {
|
||||||
// load last bolus status
|
// load last bolus status
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
||||||
mSerialIOThread.sendMessage(new MsgStatus());
|
mSerialIOThread.sendMessage(new MsgStatus());
|
||||||
bolusingEvent.percent = 100;
|
bolusingEvent.percent = 100;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
|
||||||
|
}
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bolusStop() {
|
public void bolusStop() {
|
||||||
if (Config.logDanaBTComm)
|
if (Config.logDanaBTComm)
|
||||||
|
@ -497,7 +454,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean carbsEntry(int amount, long time) {
|
public boolean carbsEntry(int amount, long time) {
|
||||||
connect("carbsEntry");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(time, amount);
|
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(time, amount);
|
||||||
mSerialIOThread.sendMessage(msg);
|
mSerialIOThread.sendMessage(msg);
|
||||||
|
@ -509,7 +465,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
|
|
||||||
public PumpEnactResult loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
connect("loadHistory");
|
|
||||||
if (!isConnected()) return result;
|
if (!isConnected()) return result;
|
||||||
MessageBase msg = null;
|
MessageBase msg = null;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -555,8 +510,9 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadEvents() {
|
public PumpEnactResult loadEvents() {
|
||||||
if (!isConnected()) return false;
|
if (!isConnected())
|
||||||
|
return new PumpEnactResult().success(false);
|
||||||
waitMsec(300);
|
waitMsec(300);
|
||||||
MsgHistoryEvents_v2 msg;
|
MsgHistoryEvents_v2 msg;
|
||||||
if (lastHistoryFetched == 0) {
|
if (lastHistoryFetched == 0) {
|
||||||
|
@ -572,11 +528,10 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
waitMsec(200);
|
waitMsec(200);
|
||||||
lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded;
|
lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded;
|
||||||
return true;
|
return new PumpEnactResult().success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateBasalsInPump(final Profile profile) {
|
public boolean updateBasalsInPump(final Profile profile) {
|
||||||
connect("updateBasalsInPump");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
|
||||||
double[] basal = DanaRPump.buildDanaRProfileRecord(profile);
|
double[] basal = DanaRPump.buildDanaRProfileRecord(profile);
|
||||||
|
|
|
@ -28,6 +28,7 @@ import info.nightscout.androidaps.queue.commands.CommandBolus;
|
||||||
import info.nightscout.androidaps.queue.commands.CommandCancelExtendedBolus;
|
import info.nightscout.androidaps.queue.commands.CommandCancelExtendedBolus;
|
||||||
import info.nightscout.androidaps.queue.commands.CommandCancelTempBasal;
|
import info.nightscout.androidaps.queue.commands.CommandCancelTempBasal;
|
||||||
import info.nightscout.androidaps.queue.commands.CommandExtendedBolus;
|
import info.nightscout.androidaps.queue.commands.CommandExtendedBolus;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandLoadEvents;
|
||||||
import info.nightscout.androidaps.queue.commands.CommandLoadHistory;
|
import info.nightscout.androidaps.queue.commands.CommandLoadHistory;
|
||||||
import info.nightscout.androidaps.queue.commands.CommandReadStatus;
|
import info.nightscout.androidaps.queue.commands.CommandReadStatus;
|
||||||
import info.nightscout.androidaps.queue.commands.CommandSetProfile;
|
import info.nightscout.androidaps.queue.commands.CommandSetProfile;
|
||||||
|
@ -358,6 +359,25 @@ public class CommandQueue {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns true if command is queued
|
||||||
|
public boolean loadEvents(Callback callback) {
|
||||||
|
if (isRunning(Command.CommandType.LOADEVENTS)) {
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove all unfinished
|
||||||
|
removeAll(Command.CommandType.LOADEVENTS);
|
||||||
|
|
||||||
|
// add new command to queue
|
||||||
|
add(new CommandLoadEvents(callback));
|
||||||
|
|
||||||
|
notifyAboutNewCommand();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public Spanned spannedStatus() {
|
public Spanned spannedStatus() {
|
||||||
String s = "";
|
String s = "";
|
||||||
int line = 0;
|
int line = 0;
|
||||||
|
|
|
@ -43,10 +43,10 @@ public class QueueThread extends Thread {
|
||||||
mWakeLock.acquire();
|
mWakeLock.acquire();
|
||||||
MainApp.bus().post(new EventQueueChanged());
|
MainApp.bus().post(new EventQueueChanged());
|
||||||
connectionStartTime = System.currentTimeMillis();
|
connectionStartTime = System.currentTimeMillis();
|
||||||
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
log.debug("Looping ...");
|
log.debug("Looping ...");
|
||||||
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
|
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
|
||||||
if (pump.isConnecting()) {
|
if (pump.isConnecting()) {
|
||||||
|
|
|
@ -15,7 +15,8 @@ public abstract class Command {
|
||||||
EXTENDEDBOLUS,
|
EXTENDEDBOLUS,
|
||||||
BASALPROFILE,
|
BASALPROFILE,
|
||||||
READSTATUS,
|
READSTATUS,
|
||||||
LOADHISTORY // so far only Dana specific
|
LOADHISTORY, // so far only Dana specific
|
||||||
|
LOADEVENTS // so far only Dana specific
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandType commandType;
|
public CommandType commandType;
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package info.nightscout.androidaps.queue.commands;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 10.11.2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class CommandLoadEvents extends Command {
|
||||||
|
public CommandLoadEvents(Callback callback) {
|
||||||
|
commandType = CommandType.LOADEVENTS;
|
||||||
|
this.callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
|
if (pump instanceof DanaRInterface) {
|
||||||
|
DanaRInterface danaPump = (DanaRInterface) pump;
|
||||||
|
PumpEnactResult r = danaPump.loadEvents();
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(r).run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String status() {
|
||||||
|
return "LOADEVENTS";
|
||||||
|
}
|
||||||
|
}
|
|
@ -371,7 +371,6 @@
|
||||||
<string name="pumpshutdown">Помпата е изключена</string>
|
<string name="pumpshutdown">Помпата е изключена</string>
|
||||||
<string name="batterydischarged">Батерията на помпата е изтощена</string>
|
<string name="batterydischarged">Батерията на помпата е изтощена</string>
|
||||||
<string name="danarkoreanpump">DanaR Korean</string>
|
<string name="danarkoreanpump">DanaR Korean</string>
|
||||||
<string name="wrongpumpdriverselected">Избран е грешен тип помпа</string>
|
|
||||||
<string name="basal_rate">Базал:</string>
|
<string name="basal_rate">Базал:</string>
|
||||||
<string name="profile_set_failed">Неуспешно задаване на базален профил</string>
|
<string name="profile_set_failed">Неуспешно задаване на базален профил</string>
|
||||||
<string name="profile_set_ok">Профила на помпата е обновен</string>
|
<string name="profile_set_ok">Профила на помпата е обновен</string>
|
||||||
|
|
|
@ -352,7 +352,6 @@
|
||||||
<string name="profile_set_failed">Nastavení bazálního profilu selhalo</string>
|
<string name="profile_set_failed">Nastavení bazálního profilu selhalo</string>
|
||||||
<string name="profile_set_ok">Bazální profil aktualizován</string>
|
<string name="profile_set_ok">Bazální profil aktualizován</string>
|
||||||
<string name="pumpNotInitializedProfileNotSet">Pumpa není inicializována, profil nenastaven!</string>
|
<string name="pumpNotInitializedProfileNotSet">Pumpa není inicializována, profil nenastaven!</string>
|
||||||
<string name="wrongpumpdriverselected">Vybrán špatný ovladač pumpy</string>
|
|
||||||
<string name="basalvaluebelowminimum">Hodnota bazálu pod povoleným minimem. Nenastaveno!</string>
|
<string name="basalvaluebelowminimum">Hodnota bazálu pod povoleným minimem. Nenastaveno!</string>
|
||||||
<string name="mdi">Pera</string>
|
<string name="mdi">Pera</string>
|
||||||
<string name="sms_actualbg">Glykémie:</string>
|
<string name="sms_actualbg">Glykémie:</string>
|
||||||
|
|
|
@ -290,7 +290,6 @@
|
||||||
<string name="pumperror">Pumpenfehler</string>
|
<string name="pumperror">Pumpenfehler</string>
|
||||||
<string name="target_range">Zielbereich:</string>
|
<string name="target_range">Zielbereich:</string>
|
||||||
<string name="units">Einheiten:</string>
|
<string name="units">Einheiten:</string>
|
||||||
<string name="wrongpumpdriverselected">Falscher Pumpentreiber ausgewählt</string>
|
|
||||||
<string name="danar_refill">Befüllen</string>
|
<string name="danar_refill">Befüllen</string>
|
||||||
<string name="danar_disableeasymode">EasyUI Modus in der Pumpe deaktivieren</string>
|
<string name="danar_disableeasymode">EasyUI Modus in der Pumpe deaktivieren</string>
|
||||||
<string name="danar_basalhour">Basal-Stunde</string>
|
<string name="danar_basalhour">Basal-Stunde</string>
|
||||||
|
|
|
@ -421,7 +421,6 @@
|
||||||
<string name="waitingforpumpclicktorefresh">Attesa Micro. Clicca per rinnovare</string>
|
<string name="waitingforpumpclicktorefresh">Attesa Micro. Clicca per rinnovare</string>
|
||||||
<string name="wear_showbgi_title">Visualizza BGI</string>
|
<string name="wear_showbgi_title">Visualizza BGI</string>
|
||||||
<string name="wrongpassword">Password Errata</string>
|
<string name="wrongpassword">Password Errata</string>
|
||||||
<string name="wrongpumpdriverselected">Driver Micro Errato</string>
|
|
||||||
<string name="wrongpumppassword">Password Micro Errata</string>
|
<string name="wrongpumppassword">Password Micro Errata</string>
|
||||||
<string name="xdrip">Xdrip</string>
|
<string name="xdrip">Xdrip</string>
|
||||||
<string name="xdripnotinstalled">xDrip non installato</string>
|
<string name="xdripnotinstalled">xDrip non installato</string>
|
||||||
|
|
|
@ -373,7 +373,6 @@
|
||||||
<string name="pumpshutdown">펌프 중지</string>
|
<string name="pumpshutdown">펌프 중지</string>
|
||||||
<string name="batterydischarged">펌프배터리 방전</string>
|
<string name="batterydischarged">펌프배터리 방전</string>
|
||||||
<string name="danarkoreanpump">다나R 한글</string>
|
<string name="danarkoreanpump">다나R 한글</string>
|
||||||
<string name="wrongpumpdriverselected">펌프 드라이버가 잘못 선택되었습니다</string>
|
|
||||||
<string name="basal_rate">기초주입량:</string>
|
<string name="basal_rate">기초주입량:</string>
|
||||||
<string name="profile_set_failed">기초주입 프로파일 설정이 실패하였습니다</string>
|
<string name="profile_set_failed">기초주입 프로파일 설정이 실패하였습니다</string>
|
||||||
<string name="profile_set_ok">기초주입 프로파일이 펌프에 업데이트 되었습니다</string>
|
<string name="profile_set_ok">기초주입 프로파일이 펌프에 업데이트 되었습니다</string>
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
<string name="xdripnotinstalled">xDrip+ niet geïnstalleerd</string>
|
<string name="xdripnotinstalled">xDrip+ niet geïnstalleerd</string>
|
||||||
<string name="xdrip">xDrip</string>
|
<string name="xdrip">xDrip</string>
|
||||||
<string name="wrongpumppassword">Verkeerd pomp wachtwoord!</string>
|
<string name="wrongpumppassword">Verkeerd pomp wachtwoord!</string>
|
||||||
<string name="wrongpumpdriverselected">Verkeerde pomp driver geselecteerd</string>
|
|
||||||
<string name="wrongpassword">Verkeerd wachtwoord</string>
|
<string name="wrongpassword">Verkeerd wachtwoord</string>
|
||||||
<string name="wear_showbgi_title">Toon BGI</string>
|
<string name="wear_showbgi_title">Toon BGI</string>
|
||||||
<string name="wear_showbgi_summary">Voeg BGI toe aan status lijn</string>
|
<string name="wear_showbgi_summary">Voeg BGI toe aan status lijn</string>
|
||||||
|
|
|
@ -553,7 +553,6 @@
|
||||||
<string name="wear_showbgi_summary">добавить BGI в строку состояния</string>
|
<string name="wear_showbgi_summary">добавить BGI в строку состояния</string>
|
||||||
<string name="wear_showbgi_title">показать BGI</string>
|
<string name="wear_showbgi_title">показать BGI</string>
|
||||||
<string name="wrongpassword">неверный пароль</string>
|
<string name="wrongpassword">неверный пароль</string>
|
||||||
<string name="wrongpumpdriverselected">неправильно выбран драйвер помпы</string>
|
|
||||||
<string name="wrongpumppassword">неверный пароль помпы</string>
|
<string name="wrongpumppassword">неверный пароль помпы</string>
|
||||||
<string name="xdrip">xdrip</string>
|
<string name="xdrip">xdrip</string>
|
||||||
<string name="xdripnotinstalled">xdrip+ не установлен</string>
|
<string name="xdripnotinstalled">xdrip+ не установлен</string>
|
||||||
|
|
|
@ -293,7 +293,6 @@
|
||||||
<string name="xdripnotinstalled">xDrip+ inte installerat</string>
|
<string name="xdripnotinstalled">xDrip+ inte installerat</string>
|
||||||
<string name="xdrip">xDrip</string>
|
<string name="xdrip">xDrip</string>
|
||||||
<string name="wrongpumppassword">Fel lösenord för pump</string>
|
<string name="wrongpumppassword">Fel lösenord för pump</string>
|
||||||
<string name="wrongpumpdriverselected">Fel pump program vald</string>
|
|
||||||
<string name="wrongpassword">Fel lösenord</string>
|
<string name="wrongpassword">Fel lösenord</string>
|
||||||
<string name="wear_showbgi_title">Visa BGI</string>
|
<string name="wear_showbgi_title">Visa BGI</string>
|
||||||
<string name="wear_showbgi_summary">Visa BGI i statusfält</string>
|
<string name="wear_showbgi_summary">Visa BGI i statusfält</string>
|
||||||
|
|
|
@ -384,7 +384,6 @@
|
||||||
<string name="pumpshutdown">Pump Shutdown</string>
|
<string name="pumpshutdown">Pump Shutdown</string>
|
||||||
<string name="batterydischarged">Pump Battery Discharged</string>
|
<string name="batterydischarged">Pump Battery Discharged</string>
|
||||||
<string name="danarkoreanpump">DanaR Korean</string>
|
<string name="danarkoreanpump">DanaR Korean</string>
|
||||||
<string name="wrongpumpdriverselected">Wrong pump driver selected</string>
|
|
||||||
<string name="basal_rate">Basal rate:</string>
|
<string name="basal_rate">Basal rate:</string>
|
||||||
<string name="profile_set_failed">Setting of basal profile failed</string>
|
<string name="profile_set_failed">Setting of basal profile failed</string>
|
||||||
<string name="profile_set_ok">Basal profile in pump updated</string>
|
<string name="profile_set_ok">Basal profile in pump updated</string>
|
||||||
|
@ -758,5 +757,6 @@
|
||||||
<string name="processinghistory">Processing event</string>
|
<string name="processinghistory">Processing event</string>
|
||||||
<string name="startingbolus">Starting bolus delivery</string>
|
<string name="startingbolus">Starting bolus delivery</string>
|
||||||
<string name="executingrightnow">Command is executed right now</string>
|
<string name="executingrightnow">Command is executed right now</string>
|
||||||
|
<string name="pumpdrivercorrected">Pump driver corrected</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue