DanaR queue driver
This commit is contained in:
parent
f134163a76
commit
252c0b3db9
8 changed files with 69 additions and 158 deletions
|
@ -350,9 +350,10 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
@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();
|
||||||
|
|
||||||
|
@ -680,12 +681,12 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopConnecting() {
|
public void stopConnecting() {
|
||||||
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAA
|
if (sExecutionService != null) sExecutionService.stopConnecting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getPumpStatus() {
|
public void getPumpStatus() {
|
||||||
// TODO AAAAAAAAAAAAAAAAAAAAAAAAAAA
|
if (sExecutionService != null) sExecutionService.getPumpStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.data.ProfileStore;
|
||||||
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.interfaces.ProfileInterface;
|
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
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;
|
||||||
|
@ -44,14 +45,7 @@ public class ProfileViewDialog extends DialogFragment {
|
||||||
|
|
||||||
private Button refreshButton;
|
private Button refreshButton;
|
||||||
|
|
||||||
Handler mHandler;
|
|
||||||
static HandlerThread mHandlerThread;
|
|
||||||
|
|
||||||
public ProfileViewDialog() {
|
public ProfileViewDialog() {
|
||||||
mHandlerThread = new HandlerThread(ProfileViewDialog.class.getSimpleName());
|
|
||||||
mHandlerThread.start();
|
|
||||||
|
|
||||||
mHandler = new Handler(mHandlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -72,18 +66,7 @@ public class ProfileViewDialog extends DialogFragment {
|
||||||
refreshButton.setOnClickListener(new View.OnClickListener() {
|
refreshButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
mHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().readStatus("ProfileViewDialog", null);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
DanaRPump.getInstance().lastSettingsRead = new Date(0);
|
|
||||||
if (MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginBase.PUMP))
|
|
||||||
DanaRPlugin.getPlugin().connect("ProfileViewDialog");
|
|
||||||
if (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PUMP))
|
|
||||||
DanaRKoreanPlugin.getPlugin().connect("ProfileViewDialog");
|
|
||||||
if (MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginBase.PUMP))
|
|
||||||
DanaRv2Plugin.getPlugin().connect("ProfileViewDialog");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -38,11 +38,13 @@ import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
|
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
|
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.ToastUtils;
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
@ -150,15 +152,7 @@ public class DanaRHistoryActivity extends Activity {
|
||||||
reloadButton.setOnClickListener(new View.OnClickListener() {
|
reloadButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
final TypeList selected = (TypeList) historyTypeSpinner.getSelectedItem();
|
||||||
if (pump.isBusy()) {
|
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), getString(R.string.pumpbusy));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
TypeList selected = (TypeList) historyTypeSpinner.getSelectedItem();
|
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -168,7 +162,9 @@ public class DanaRHistoryActivity extends Activity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
clearCardView();
|
clearCardView();
|
||||||
((DanaRInterface)pump).loadHistory(selected.type);
|
ConfigBuilderPlugin.getCommandQueue().loadHistory(selected.type, new Callback() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
loadDataFromDB(selected.type);
|
loadDataFromDB(selected.type);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -40,24 +40,17 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
|
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
import info.nightscout.utils.ToastUtils;
|
|
||||||
|
|
||||||
public class DanaRStatsActivity extends Activity {
|
public class DanaRStatsActivity extends Activity {
|
||||||
private static Logger log = LoggerFactory.getLogger(DanaRStatsActivity.class);
|
private static Logger log = LoggerFactory.getLogger(DanaRStatsActivity.class);
|
||||||
|
|
||||||
private boolean mBounded;
|
|
||||||
|
|
||||||
private Handler mHandler;
|
|
||||||
private static HandlerThread mHandlerThread;
|
|
||||||
|
|
||||||
TextView statusView, statsMessage, totalBaseBasal2;
|
TextView statusView, statsMessage, totalBaseBasal2;
|
||||||
EditText totalBaseBasal;
|
EditText totalBaseBasal;
|
||||||
Button reloadButton;
|
Button reloadButton;
|
||||||
|
@ -72,9 +65,6 @@ public class DanaRStatsActivity extends Activity {
|
||||||
|
|
||||||
public DanaRStatsActivity() {
|
public DanaRStatsActivity() {
|
||||||
super();
|
super();
|
||||||
mHandlerThread = new HandlerThread(DanaRStatsActivity.class.getSimpleName());
|
|
||||||
mHandlerThread.start();
|
|
||||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -233,14 +223,6 @@ public class DanaRStatsActivity extends Activity {
|
||||||
reloadButton.setOnClickListener(new View.OnClickListener() {
|
reloadButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
|
||||||
if (pump.isBusy()) {
|
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), getString(R.string.pumpbusy));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -250,7 +232,9 @@ public class DanaRStatsActivity extends Activity {
|
||||||
statsMessage.setText(getString(R.string.danar_stats_warning_Message));
|
statsMessage.setText(getString(R.string.danar_stats_warning_Message));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
((DanaRInterface) pump).loadHistory(RecordTypes.RECORD_TYPE_DAILY);
|
ConfigBuilderPlugin.getCommandQueue().loadHistory(RecordTypes.RECORD_TYPE_DAILY, new Callback() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
|
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -95,14 +95,12 @@ public class DanaRExecutionService 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 = DanaRPump.getInstance();
|
private DanaRPump danaRPump = DanaRPump.getInstance();
|
||||||
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");
|
||||||
|
|
||||||
|
@ -126,9 +124,6 @@ public class DanaRExecutionService extends Service {
|
||||||
public DanaRExecutionService() {
|
public DanaRExecutionService() {
|
||||||
registerBus();
|
registerBus();
|
||||||
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
|
||||||
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaRExecutionService");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LocalBinder extends Binder {
|
public class LocalBinder extends Binder {
|
||||||
|
@ -190,35 +185,28 @@ public class DanaRExecutionService 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;
|
||||||
mWakeLock.acquire();
|
|
||||||
getBTSocketForSelectedPump();
|
getBTSocketForSelectedPump();
|
||||||
if (mRfcommSocket == null || mBTDevice == null)
|
if (mRfcommSocket == null || mBTDevice == null) {
|
||||||
|
connectionInProgress = false;
|
||||||
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) {
|
||||||
|
@ -226,23 +214,16 @@ public class DanaRExecutionService 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(DanaRPlugin.class).isEnabled(PluginBase.PUMP))
|
|
||||||
return;
|
|
||||||
getBTSocketForSelectedPump();
|
|
||||||
startTime = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!isConnected()) {
|
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
|
|
||||||
log.error("Pump connection timed out");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connectionInProgress = false;
|
connectionInProgress = false;
|
||||||
mWakeLock.release();
|
|
||||||
}
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopConnecting() {
|
||||||
|
if (mSerialIOThread != null)
|
||||||
|
mSerialIOThread.disconnect("stopConnecting");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getBTSocketForSelectedPump() {
|
private void getBTSocketForSelectedPump() {
|
||||||
|
@ -277,7 +258,7 @@ public class DanaRExecutionService 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();
|
||||||
|
@ -289,7 +270,7 @@ public class DanaRExecutionService extends Service {
|
||||||
if (danaRPump.isNewPump) {
|
if (danaRPump.isNewPump) {
|
||||||
mSerialIOThread.sendMessage(checkValue);
|
mSerialIOThread.sendMessage(checkValue);
|
||||||
if (!checkValue.received) {
|
if (!checkValue.received) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,28 +282,6 @@ public class DanaRExecutionService extends Service {
|
||||||
mSerialIOThread.sendMessage(exStatusMsg);
|
mSerialIOThread.sendMessage(exStatusMsg);
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
||||||
|
|
||||||
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(DanaRPlugin.class).isInitialized()) {
|
if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !MainApp.getSpecificPlugin(DanaRPlugin.class).isInitialized()) {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpsettings)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpsettings)));
|
||||||
|
@ -362,11 +321,9 @@ public class DanaRExecutionService extends Service {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)));
|
||||||
|
@ -381,7 +338,6 @@ public class DanaRExecutionService 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());
|
||||||
|
@ -391,7 +347,6 @@ public class DanaRExecutionService 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)));
|
||||||
|
@ -401,7 +356,6 @@ public class DanaRExecutionService 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());
|
||||||
|
@ -420,7 +374,6 @@ public class DanaRExecutionService 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) {
|
||||||
|
@ -476,6 +429,7 @@ public class DanaRExecutionService extends Service {
|
||||||
MainApp.bus().post(bolusingEvent);
|
MainApp.bus().post(bolusingEvent);
|
||||||
SystemClock.sleep(1000);
|
SystemClock.sleep(1000);
|
||||||
}
|
}
|
||||||
|
if (!isConnected())
|
||||||
connect("bolusingInterrupted");
|
connect("bolusingInterrupted");
|
||||||
getPumpStatus();
|
getPumpStatus();
|
||||||
if (danaRPump.lastBolusTime.getTime() > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old
|
if (danaRPump.lastBolusTime.getTime() > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old
|
||||||
|
@ -507,7 +461,6 @@ public class DanaRExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean carbsEntry(int amount) {
|
public boolean carbsEntry(int amount) {
|
||||||
connect("carbsEntry");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(System.currentTimeMillis(), amount);
|
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(System.currentTimeMillis(), amount);
|
||||||
mSerialIOThread.sendMessage(msg);
|
mSerialIOThread.sendMessage(msg);
|
||||||
|
@ -516,7 +469,6 @@ public class DanaRExecutionService 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) {
|
||||||
|
@ -563,7 +515,6 @@ public class DanaRExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
@ -20,6 +20,8 @@ import java.util.Objects;
|
||||||
import info.nightscout.androidaps.BuildConfig;
|
import info.nightscout.androidaps.BuildConfig;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
|
@ -27,7 +29,7 @@ import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
@ -42,10 +44,6 @@ import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
|
|
@ -78,7 +78,6 @@ public class DanaRSService extends Service {
|
||||||
|
|
||||||
private BLEComm bleComm = BLEComm.getInstance(this);
|
private BLEComm bleComm = BLEComm.getInstance(this);
|
||||||
|
|
||||||
private PowerManager.WakeLock mWakeLock;
|
|
||||||
private IBinder mBinder = new LocalBinder();
|
private IBinder mBinder = new LocalBinder();
|
||||||
|
|
||||||
private DanaRPump danaRPump = DanaRPump.getInstance();
|
private DanaRPump danaRPump = DanaRPump.getInstance();
|
||||||
|
@ -93,10 +92,6 @@ public class DanaRSService extends Service {
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
|
||||||
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, DanaRSService.class.getSimpleName());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
|
|
|
@ -360,13 +360,16 @@ public class CommandQueue {
|
||||||
|
|
||||||
public Spanned spannedStatus() {
|
public Spanned spannedStatus() {
|
||||||
String s = "";
|
String s = "";
|
||||||
|
int line = 0;
|
||||||
if (performing != null) {
|
if (performing != null) {
|
||||||
s += "<b>" + performing.status() + "</b>";
|
s += "<b>" + performing.status() + "</b>";
|
||||||
|
line++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < queue.size(); i++) {
|
for (int i = 0; i < queue.size(); i++) {
|
||||||
if (i != 0)
|
if (line != 0)
|
||||||
s += "<br>";
|
s += "<br>";
|
||||||
s += queue.get(i).status();
|
s += queue.get(i).status();
|
||||||
|
line++;
|
||||||
}
|
}
|
||||||
return Html.fromHtml(s);
|
return Html.fromHtml(s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue