some v2 driver tweaking

This commit is contained in:
Milos Kozak 2017-06-01 20:52:38 +02:00
parent 622097aabc
commit a19a5a442b
4 changed files with 56 additions and 33 deletions

View file

@ -59,7 +59,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private static final int DATABASE_VERSION = 7; private static final int DATABASE_VERSION = 7;
private static Long latestTreatmentChange = null; private static Long earliestDataChange = null;
private static final ScheduledExecutorService bgWorker = Executors.newSingleThreadScheduledExecutor(); private static final ScheduledExecutorService bgWorker = Executors.newSingleThreadScheduledExecutor();
private static ScheduledFuture<?> scheduledBgPost = null; private static ScheduledFuture<?> scheduledBgPost = null;
@ -184,7 +184,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class); TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class);
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class); TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class); TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class);
updateLatestTreatmentChange(0); updateEarliestDataChange(0);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -209,7 +209,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
try { try {
TableUtils.dropTable(connectionSource, Treatment.class, true); TableUtils.dropTable(connectionSource, Treatment.class, true);
TableUtils.createTableIfNotExists(connectionSource, Treatment.class); TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
updateLatestTreatmentChange(0); updateEarliestDataChange(0);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -230,7 +230,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
try { try {
TableUtils.dropTable(connectionSource, TemporaryBasal.class, true); TableUtils.dropTable(connectionSource, TemporaryBasal.class, true);
TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class); TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class);
updateLatestTreatmentChange(0); updateEarliestDataChange(0);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -241,7 +241,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
try { try {
TableUtils.dropTable(connectionSource, ExtendedBolus.class, true); TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class); TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
updateLatestTreatmentChange(0); updateEarliestDataChange(0);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -465,7 +465,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
boolean historyChange = changeAffectingIobCob(treatment); boolean historyChange = changeAffectingIobCob(treatment);
status = getDaoTreatments().createOrUpdate(treatment); status = getDaoTreatments().createOrUpdate(treatment);
if (historyChange) if (historyChange)
updateLatestTreatmentChange(treatment.date); updateEarliestDataChange(treatment.date);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -476,7 +476,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void delete(Treatment treatment) { public void delete(Treatment treatment) {
try { try {
getDaoTreatments().delete(treatment); getDaoTreatments().delete(treatment);
updateLatestTreatmentChange(treatment.date); updateEarliestDataChange(treatment.date);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -540,13 +540,13 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return null; return null;
} }
void updateLatestTreatmentChange(long newDate) { void updateEarliestDataChange(long newDate) {
if (latestTreatmentChange == null) { if (earliestDataChange == null) {
latestTreatmentChange = newDate; earliestDataChange = newDate;
return; return;
} }
if (newDate < latestTreatmentChange) { if (newDate < earliestDataChange) {
latestTreatmentChange = newDate; earliestDataChange = newDate;
} }
} }
@ -556,9 +556,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
log.debug("Firing EventTreatmentChange"); log.debug("Firing EventTreatmentChange");
MainApp.bus().post(new EventReloadTreatmentData()); MainApp.bus().post(new EventReloadTreatmentData());
MainApp.bus().post(new EventTreatmentChange()); MainApp.bus().post(new EventTreatmentChange());
if (latestTreatmentChange != null) if (earliestDataChange != null)
MainApp.bus().post(new EventNewHistoryData(latestTreatmentChange)); MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
latestTreatmentChange = null; earliestDataChange = null;
scheduledTratmentPost = null; scheduledTratmentPost = null;
} }
} }
@ -830,7 +830,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
tempBasal.date = tempBasal.date - tempBasal.date % 1000; tempBasal.date = tempBasal.date - tempBasal.date % 1000;
try { try {
getDaoTemporaryBasal().createOrUpdate(tempBasal); getDaoTemporaryBasal().createOrUpdate(tempBasal);
updateLatestTreatmentChange(tempBasal.date); updateEarliestDataChange(tempBasal.date);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -840,7 +840,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void delete(TemporaryBasal tempBasal) { public void delete(TemporaryBasal tempBasal) {
try { try {
getDaoTemporaryBasal().delete(tempBasal); getDaoTemporaryBasal().delete(tempBasal);
updateLatestTreatmentChange(tempBasal.date); updateEarliestDataChange(tempBasal.date);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -893,6 +893,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
log.debug("Firing EventTempBasalChange"); log.debug("Firing EventTempBasalChange");
MainApp.bus().post(new EventReloadTempBasalData()); MainApp.bus().post(new EventReloadTempBasalData());
MainApp.bus().post(new EventTempBasalChange()); MainApp.bus().post(new EventTempBasalChange());
if (earliestDataChange != null)
MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
earliestDataChange = null;
scheduledTemBasalsPost = null; scheduledTemBasalsPost = null;
} }
} }
@ -1051,7 +1054,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
extendedBolus.date = extendedBolus.date - extendedBolus.date % 1000; extendedBolus.date = extendedBolus.date - extendedBolus.date % 1000;
try { try {
getDaoExtendedBolus().createOrUpdate(extendedBolus); getDaoExtendedBolus().createOrUpdate(extendedBolus);
updateLatestTreatmentChange(extendedBolus.date); updateEarliestDataChange(extendedBolus.date);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -1061,7 +1064,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void delete(ExtendedBolus extendedBolus) { public void delete(ExtendedBolus extendedBolus) {
try { try {
getDaoExtendedBolus().delete(extendedBolus); getDaoExtendedBolus().delete(extendedBolus);
updateLatestTreatmentChange(extendedBolus.date); updateEarliestDataChange(extendedBolus.date);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -1189,6 +1192,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
log.debug("Firing EventExtendedBolusChange"); log.debug("Firing EventExtendedBolusChange");
MainApp.bus().post(new EventReloadTreatmentData()); MainApp.bus().post(new EventReloadTreatmentData());
MainApp.bus().post(new EventExtendedBolusChange()); MainApp.bus().post(new EventExtendedBolusChange());
if (earliestDataChange != null)
MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
earliestDataChange = null;
scheduledExtendedBolusPost = null; scheduledExtendedBolusPost = null;
} }
} }

View file

@ -287,7 +287,8 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
Treatment t = new Treatment(detailedBolusInfo.insulinInterface); Treatment t = new Treatment(detailedBolusInfo.insulinInterface);
boolean connectionOK = false; boolean connectionOK = false;
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, new Date().getTime() + detailedBolusInfo.carbTime * 60 * 1000, t); if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, new Date().getTime() + detailedBolusInfo.carbTime * 60 * 1000, t);
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK; result.success = connectionOK;
result.bolusDelivered = t.insulin; result.bolusDelivered = t.insulin;
@ -370,22 +371,19 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Correct temp basal already set (doLowTemp || doHighTemp)"); log.debug("setTempBasalAbsolute: Correct temp basal already set (doLowTemp || doHighTemp)");
return result; return result;
} else { } }
if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Stopping temp basal (doLowTemp || doHighTemp)");
result = cancelTempBasal();
// Check for proper result
if (!result.success) {
log.error("setTempBasalAbsolute: Failed to stop previous temp basal (doLowTemp || doHighTemp)");
return result;
}
}
}
// Convert duration from minutes to hours // Convert duration from minutes to hours
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)"); log.debug("setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)");
// use special APS temp basal call ... 100+/15min .... 100-/30min // use special APS temp basal call ... 100+/15min .... 100-/30min
setHighTempBasalPercent(percentRate); result = setHighTempBasalPercent(percentRate);
if (!result.success) {
log.error("setTempBasalAbsolute: Failed to set hightemp basal");
return result;
}
if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: hightemp basal set ok");
return result;
} }
// We should never end here // We should never end here
log.error("setTempBasalAbsolute: Internal error"); log.error("setTempBasalAbsolute: Internal error");
@ -437,7 +435,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
} }
result.enacted = false; result.enacted = false;
result.success = false; result.success = false;
result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly); result.comment = MainApp.instance().getString(R.string.tempbasaldeliveryerror);
log.error("setTempBasalPercent: Failed to set temp basal"); log.error("setTempBasalPercent: Failed to set temp basal");
return result; return result;
} }

View file

@ -54,21 +54,30 @@ public class MsgHistoryEvents_v2 extends MessageBase {
TemporaryBasal temporaryBasal = MainApp.getDbHelper().findTempBasalByTime(datetime.getTime()); TemporaryBasal temporaryBasal = MainApp.getDbHelper().findTempBasalByTime(datetime.getTime());
if (temporaryBasal != null) { if (temporaryBasal != null) {
log.debug("EVENT (" + recordCode + ") " + datetime.toLocaleString() + " Param1: " + param1 + " Param2: " + param2);
log.debug("Existing temporaryBasal found. Skipping ..."); log.debug("Existing temporaryBasal found. Skipping ...");
if (datetime.getTime() > lastEventTimeLoaded)
lastEventTimeLoaded = datetime.getTime();
return; return;
} }
temporaryBasal = new TemporaryBasal(); temporaryBasal = new TemporaryBasal();
ExtendedBolus extendedBolus = MainApp.getDbHelper().findExtendedBolusByTime(datetime.getTime()); ExtendedBolus extendedBolus = MainApp.getDbHelper().findExtendedBolusByTime(datetime.getTime());
if (extendedBolus != null) { if (extendedBolus != null) {
log.debug("EVENT (" + recordCode + ") " + datetime.toLocaleString() + " Param1: " + param1 + " Param2: " + param2);
log.debug("Existing extendedBolus found. Skipping ..."); log.debug("Existing extendedBolus found. Skipping ...");
if (datetime.getTime() > lastEventTimeLoaded)
lastEventTimeLoaded = datetime.getTime();
return; return;
} }
extendedBolus = new ExtendedBolus(); extendedBolus = new ExtendedBolus();
Treatment treatment = MainApp.getDbHelper().findTreatmentByTime(datetime.getTime()); Treatment treatment = MainApp.getDbHelper().findTreatmentByTime(datetime.getTime());
if (treatment != null) { if (treatment != null) {
log.debug("EVENT (" + recordCode + ") " + datetime.toLocaleString() + " Param1: " + param1 + " Param2: " + param2);
log.debug("Existing treatment found. Skipping ..."); log.debug("Existing treatment found. Skipping ...");
if (datetime.getTime() > lastEventTimeLoaded)
lastEventTimeLoaded = datetime.getTime();
return; return;
} }
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();

View file

@ -328,6 +328,11 @@ public class DanaRv2ExecutionService extends Service {
public boolean tempBasal(int percent, int durationInHours) { public boolean tempBasal(int percent, int durationInHours) {
connect("tempBasal"); connect("tempBasal");
if (!isConnected()) return false; if (!isConnected()) return false;
if (danaRPump.isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
waitMsec(500);
}
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours)); mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours));
mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2()); mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2());
@ -339,6 +344,11 @@ public class DanaRv2ExecutionService extends Service {
public boolean highTempBasal(int percent) { public boolean highTempBasal(int percent) {
connect("highTempBasal"); connect("highTempBasal");
if (!isConnected()) return false; if (!isConnected()) return false;
if (danaRPump.isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
waitMsec(500);
}
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetAPSTempBasalStart_v2(percent)); mSerialIOThread.sendMessage(new MsgSetAPSTempBasalStart_v2(percent));
mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2()); mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2());