basic sync for v2
This commit is contained in:
parent
b3d18b2537
commit
15f44e6085
|
@ -34,6 +34,7 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
||||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||||
import info.nightscout.androidaps.events.EventNewBG;
|
import info.nightscout.androidaps.events.EventNewBG;
|
||||||
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
import info.nightscout.androidaps.events.EventReloadTempBasalData;
|
import info.nightscout.androidaps.events.EventReloadTempBasalData;
|
||||||
import info.nightscout.androidaps.events.EventReloadTreatmentData;
|
import info.nightscout.androidaps.events.EventReloadTreatmentData;
|
||||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||||
|
@ -193,6 +194,15 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
scheduleExtendedBolusChange();
|
scheduleExtendedBolusChange();
|
||||||
scheduleTemporaryTargetChange();
|
scheduleTemporaryTargetChange();
|
||||||
scheduleCareportalEventChange();
|
scheduleCareportalEventChange();
|
||||||
|
new java.util.Timer().schedule(
|
||||||
|
new java.util.TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
MainApp.bus().post(new EventRefreshGui(false));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
3000
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetTreatments() {
|
public void resetTreatments() {
|
||||||
|
@ -440,7 +450,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
// -------------------- TREATMENT HANDLING -------------------
|
// -------------------- TREATMENT HANDLING -------------------
|
||||||
|
|
||||||
public boolean changeAffectingIobCob(Treatment t) {
|
public boolean changeAffectingIobCob(Treatment t) {
|
||||||
Treatment existing = findTreatmentByTimeIndex(t.date);
|
Treatment existing = findTreatmentByTime(t.date);
|
||||||
if (existing == null)
|
if (existing == null)
|
||||||
return true;
|
return true;
|
||||||
if (existing.insulin == t.insulin && existing.carbs == t.carbs)
|
if (existing.insulin == t.insulin && existing.carbs == t.carbs)
|
||||||
|
@ -507,7 +517,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Treatment findTreatmentByTimeIndex(Long timeIndex) {
|
public Treatment findTreatmentByTime(Long timeIndex) {
|
||||||
try {
|
try {
|
||||||
QueryBuilder<Treatment, String> qb = null;
|
QueryBuilder<Treatment, String> qb = null;
|
||||||
Dao<Treatment, Long> daoTreatments = getDaoTreatments();
|
Dao<Treatment, Long> daoTreatments = getDaoTreatments();
|
||||||
|
@ -518,10 +528,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
PreparedQuery<Treatment> preparedQuery = queryBuilder.prepare();
|
PreparedQuery<Treatment> preparedQuery = queryBuilder.prepare();
|
||||||
List<Treatment> trList = daoTreatments.query(preparedQuery);
|
List<Treatment> trList = daoTreatments.query(preparedQuery);
|
||||||
if (trList.size() != 1) {
|
if (trList.size() != 1) {
|
||||||
log.debug("Treatment findTreatmentByTimeIndex query size: " + trList.size());
|
//log.debug("Treatment findTreatmentByTime query size: " + trList.size());
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
log.debug("Treatment findTreatmentByTimeIndex found: " + trList.get(0).log());
|
//log.debug("Treatment findTreatmentByTime found: " + trList.get(0).log());
|
||||||
return trList.get(0);
|
return trList.get(0);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@ -853,6 +863,30 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
return new ArrayList<TemporaryBasal>();
|
return new ArrayList<TemporaryBasal>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public TemporaryBasal findTempBasalByTime(Long timeIndex) {
|
||||||
|
try {
|
||||||
|
QueryBuilder<TemporaryBasal, String> qb = null;
|
||||||
|
Dao<TemporaryBasal, Long> daoTemporaryBasal = getDaoTemporaryBasal();
|
||||||
|
QueryBuilder<TemporaryBasal, Long> queryBuilder = daoTemporaryBasal.queryBuilder();
|
||||||
|
Where where = queryBuilder.where();
|
||||||
|
where.eq("date", timeIndex);
|
||||||
|
queryBuilder.limit(10L);
|
||||||
|
PreparedQuery<TemporaryBasal> preparedQuery = queryBuilder.prepare();
|
||||||
|
List<TemporaryBasal> trList = daoTemporaryBasal.query(preparedQuery);
|
||||||
|
if (trList.size() != 1) {
|
||||||
|
//log.debug("TemporaryBasal findTempBasalByTime query size: " + trList.size());
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
//log.debug("TemporaryBasal findTempBasalByTime found: " + trList.get(0).log());
|
||||||
|
return trList.get(0);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
static public void scheduleTemporaryBasalChange() {
|
static public void scheduleTemporaryBasalChange() {
|
||||||
class PostRunnable implements Runnable {
|
class PostRunnable implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -1050,6 +1084,30 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
return new ArrayList<ExtendedBolus>();
|
return new ArrayList<ExtendedBolus>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public ExtendedBolus findExtendedBolusByTime(Long timeIndex) {
|
||||||
|
try {
|
||||||
|
QueryBuilder<ExtendedBolus, String> qb = null;
|
||||||
|
Dao<ExtendedBolus, Long> daoExtendedBolus = getDaoExtendedBolus();
|
||||||
|
QueryBuilder<ExtendedBolus, Long> queryBuilder = daoExtendedBolus.queryBuilder();
|
||||||
|
Where where = queryBuilder.where();
|
||||||
|
where.eq("date", timeIndex);
|
||||||
|
queryBuilder.limit(10L);
|
||||||
|
PreparedQuery<ExtendedBolus> preparedQuery = queryBuilder.prepare();
|
||||||
|
List<ExtendedBolus> trList = daoExtendedBolus.query(preparedQuery);
|
||||||
|
if (trList.size() != 1) {
|
||||||
|
//log.debug("ExtendedBolus findExtendedBolusByTime query size: " + trList.size());
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
//log.debug("ExtendedBolus findExtendedBolusByTime found: " + trList.get(0).log());
|
||||||
|
return trList.get(0);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteExtendedBolusById(String _id) {
|
public void deleteExtendedBolusById(String _id) {
|
||||||
try {
|
try {
|
||||||
QueryBuilder<ExtendedBolus, Long> queryBuilder = null;
|
QueryBuilder<ExtendedBolus, Long> queryBuilder = null;
|
||||||
|
|
|
@ -133,12 +133,12 @@ public class ActionsFragment extends Fragment implements View.OnClickListener {
|
||||||
profileSwitch.setVisibility(View.GONE);
|
profileSwitch.setVisibility(View.GONE);
|
||||||
else
|
else
|
||||||
profileSwitch.setVisibility(View.VISIBLE);
|
profileSwitch.setVisibility(View.VISIBLE);
|
||||||
if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress())
|
if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() || MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses())
|
||||||
extendedBolus.setVisibility(View.GONE);
|
extendedBolus.setVisibility(View.GONE);
|
||||||
else {
|
else {
|
||||||
extendedBolus.setVisibility(View.VISIBLE);
|
extendedBolus.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress())
|
if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() || MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses())
|
||||||
extendedBolusCancel.setVisibility(View.GONE);
|
extendedBolusCancel.setVisibility(View.GONE);
|
||||||
else {
|
else {
|
||||||
extendedBolusCancel.setVisibility(View.VISIBLE);
|
extendedBolusCancel.setVisibility(View.VISIBLE);
|
||||||
|
@ -205,26 +205,28 @@ public class ActionsFragment extends Fragment implements View.OnClickListener {
|
||||||
fillDialog.show(manager, "FillDialog");
|
fillDialog.show(manager, "FillDialog");
|
||||||
break;
|
break;
|
||||||
case R.id.actions_50_30:
|
case R.id.actions_50_30:
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
|
||||||
sHandler.post(new Runnable() {
|
sHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
DanaRv2Plugin danaRv2Plugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class);
|
DanaRv2Plugin danaRv2Plugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class);
|
||||||
|
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
||||||
|
danaRv2Plugin.cancelTempBasal();
|
||||||
|
}
|
||||||
danaRv2Plugin.setHighTempBasalPercent(50);
|
danaRv2Plugin.setHighTempBasalPercent(50);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case R.id.actions_400_15:
|
case R.id.actions_400_15:
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
|
||||||
sHandler.post(new Runnable() {
|
sHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
DanaRv2Plugin danaRv2Plugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class);
|
DanaRv2Plugin danaRv2Plugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class);
|
||||||
|
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
||||||
|
danaRv2Plugin.cancelTempBasal();
|
||||||
|
}
|
||||||
danaRv2Plugin.setHighTempBasalPercent(400);
|
danaRv2Plugin.setHighTempBasalPercent(400);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,22 @@ public class DanaRPump {
|
||||||
|
|
||||||
public static final String PROFILE_PREFIX = "DanaR-";
|
public static final String PROFILE_PREFIX = "DanaR-";
|
||||||
|
|
||||||
|
// v2 history entries
|
||||||
|
public static final int TEMPSTART = 1;
|
||||||
|
public static final int TEMPSTOP = 2;
|
||||||
|
public static final int EXTENDEDSTART = 3;
|
||||||
|
public static final int EXTENDEDSTOP = 4;
|
||||||
|
public static final int BOLUS = 5;
|
||||||
|
public static final int DUALBOLUS = 6;
|
||||||
|
public static final int DUALEXTENDEDSTART = 7;
|
||||||
|
public static final int DUALEXTENDEDSTOP = 8;
|
||||||
|
public static final int SUSPENDON = 9;
|
||||||
|
public static final int SUSPENDOFF = 10;
|
||||||
|
public static final int REFILL = 11;
|
||||||
|
public static final int PRIME = 12;
|
||||||
|
public static final int PROFILECHANGE = 13;
|
||||||
|
public static final int CARBS = 14;
|
||||||
|
|
||||||
public Date lastConnection = new Date(0);
|
public Date lastConnection = new Date(0);
|
||||||
public Date lastSettingsRead = new Date(0);
|
public Date lastSettingsRead = new Date(0);
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class MessageBase {
|
||||||
AddParamByte((byte) (date.get(Calendar.YEAR) - 1900 - 100));
|
AddParamByte((byte) (date.get(Calendar.YEAR) - 1900 - 100));
|
||||||
AddParamByte((byte) (date.get(Calendar.MONTH) + 1));
|
AddParamByte((byte) (date.get(Calendar.MONTH) + 1));
|
||||||
AddParamByte((byte) (date.get(Calendar.DAY_OF_MONTH)));
|
AddParamByte((byte) (date.get(Calendar.DAY_OF_MONTH)));
|
||||||
AddParamByte((byte) (date.get(Calendar.HOUR)));
|
AddParamByte((byte) (date.get(Calendar.HOUR_OF_DAY)));
|
||||||
AddParamByte((byte) (date.get(Calendar.MINUTE)));
|
AddParamByte((byte) (date.get(Calendar.MINUTE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class MessageBase {
|
||||||
AddParamByte((byte) (date.get(Calendar.YEAR) - 1900 - 100));
|
AddParamByte((byte) (date.get(Calendar.YEAR) - 1900 - 100));
|
||||||
AddParamByte((byte) (date.get(Calendar.MONTH) + 1));
|
AddParamByte((byte) (date.get(Calendar.MONTH) + 1));
|
||||||
AddParamByte((byte) (date.get(Calendar.DAY_OF_MONTH)));
|
AddParamByte((byte) (date.get(Calendar.DAY_OF_MONTH)));
|
||||||
AddParamByte((byte) (date.get(Calendar.HOUR)));
|
AddParamByte((byte) (date.get(Calendar.HOUR_OF_DAY)));
|
||||||
AddParamByte((byte) (date.get(Calendar.MINUTE)));
|
AddParamByte((byte) (date.get(Calendar.MINUTE)));
|
||||||
AddParamByte((byte) (date.get(Calendar.SECOND)));
|
AddParamByte((byte) (date.get(Calendar.SECOND)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,20 +14,21 @@ public class MsgSetCarbsEntry extends MessageBase {
|
||||||
SetCommand(0x0402);
|
SetCommand(0x0402);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MsgSetCarbsEntry(Calendar time, int amount) {
|
public MsgSetCarbsEntry(long time, int amount) {
|
||||||
this();
|
this();
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTimeInMillis(time);
|
||||||
AddParamByte((byte) RecordTypes.RECORD_TYPE_CARBO);
|
AddParamByte((byte) RecordTypes.RECORD_TYPE_CARBO);
|
||||||
AddParamByte((byte) (time.get(Calendar.YEAR) % 100));
|
AddParamByte((byte) (calendar.get(Calendar.YEAR) % 100));
|
||||||
AddParamByte((byte) (time.get(Calendar.MONTH) + 1));
|
AddParamByte((byte) (calendar.get(Calendar.MONTH) + 1));
|
||||||
AddParamByte((byte) (time.get(Calendar.DAY_OF_MONTH)));
|
AddParamByte((byte) (calendar.get(Calendar.DAY_OF_MONTH)));
|
||||||
AddParamByte((byte) (time.get(Calendar.HOUR_OF_DAY)));
|
AddParamByte((byte) (calendar.get(Calendar.HOUR_OF_DAY)));
|
||||||
AddParamByte((byte) (time.get(Calendar.MINUTE)));
|
AddParamByte((byte) (calendar.get(Calendar.MINUTE)));
|
||||||
AddParamByte((byte) (time.get(Calendar.SECOND)));
|
AddParamByte((byte) (calendar.get(Calendar.SECOND)));
|
||||||
AddParamByte((byte) 0x43); //??
|
AddParamByte((byte) 0x43); //??
|
||||||
AddParamInt(amount);
|
AddParamInt(amount);
|
||||||
if (Config.logDanaMessageDetail)
|
if (Config.logDanaMessageDetail)
|
||||||
log.debug("Set carb entry: " + amount + " date " + time.getTime().toString());
|
log.debug("Set carb entry: " + amount + " date " + calendar.getTime().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -400,8 +400,7 @@ public class DanaRExecutionService extends Service {
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
|
|
||||||
if (carbs > 0) {
|
if (carbs > 0) {
|
||||||
Calendar time = Calendar.getInstance();
|
mSerialIOThread.sendMessage(new MsgSetCarbsEntry(new Date().getTime(), carbs));
|
||||||
mSerialIOThread.sendMessage(new MsgSetCarbsEntry(time, carbs));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables
|
MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables
|
||||||
|
@ -463,8 +462,7 @@ public class DanaRExecutionService extends Service {
|
||||||
public boolean carbsEntry(int amount) {
|
public boolean carbsEntry(int amount) {
|
||||||
connect("carbsEntry");
|
connect("carbsEntry");
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
Calendar time = Calendar.getInstance();
|
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(new Date().getTime(), amount);
|
||||||
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(time, amount);
|
|
||||||
mSerialIOThread.sendMessage(msg);
|
mSerialIOThread.sendMessage(msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,8 +394,7 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
|
|
||||||
if (carbs > 0) {
|
if (carbs > 0) {
|
||||||
Calendar time = Calendar.getInstance();
|
mSerialIOThread.sendMessage(new MsgSetCarbsEntry(new Date().getTime(), carbs));
|
||||||
mSerialIOThread.sendMessage(new MsgSetCarbsEntry(time, carbs));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables
|
MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables
|
||||||
|
@ -440,8 +439,7 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
public boolean carbsEntry(int amount) {
|
public boolean carbsEntry(int amount) {
|
||||||
connect("carbsEntry");
|
connect("carbsEntry");
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
Calendar time = Calendar.getInstance();
|
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(new Date().getTime(), amount);
|
||||||
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(time, amount);
|
|
||||||
mSerialIOThread.sendMessage(msg);
|
mSerialIOThread.sendMessage(msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,7 +287,7 @@ 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, 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;
|
||||||
|
@ -295,9 +295,6 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
|
||||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||||
if (Config.logPumpActions)
|
if (Config.logPumpActions)
|
||||||
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
||||||
detailedBolusInfo.insulin = t.insulin;
|
|
||||||
detailedBolusInfo.date = new Date().getTime();
|
|
||||||
MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo);
|
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
@ -357,8 +354,8 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
|
||||||
Integer percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
|
Integer percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
|
||||||
if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue();
|
if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue();
|
||||||
else percentRate = Round.floorTo((double) percentRate, 10d).intValue();
|
else percentRate = Round.floorTo((double) percentRate, 10d).intValue();
|
||||||
if (percentRate > getPumpDescription().maxTempPercent)
|
if (percentRate > 500) // Special high temp 500/15min
|
||||||
percentRate = getPumpDescription().maxTempPercent;
|
percentRate = 500;
|
||||||
// Check if some temp is already in progress
|
// Check if some temp is already in progress
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
||||||
// Correct basal already set ?
|
// Correct basal already set ?
|
||||||
|
@ -387,7 +384,8 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
|
||||||
// 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)");
|
||||||
return setTempBasalPercent(percentRate, durationInMinutes);
|
// use special APS temp basal call ... 100+/15min .... 100-/30min
|
||||||
|
setHighTempBasalPercent(percentRate);
|
||||||
}
|
}
|
||||||
// We should never end here
|
// We should never end here
|
||||||
log.error("setTempBasalAbsolute: Internal error");
|
log.error("setTempBasalAbsolute: Internal error");
|
||||||
|
|
|
@ -24,8 +24,10 @@ public class MessageHashTable_v2 {
|
||||||
put(new MsgBolusStart()); // 0x0102 CMD_MEALINS_START_DATA
|
put(new MsgBolusStart()); // 0x0102 CMD_MEALINS_START_DATA
|
||||||
put(new MsgBolusProgress()); // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
|
put(new MsgBolusProgress()); // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
|
||||||
put(new MsgStatusProfile()); // 0x0204 CMD_PUMP_CALCULATION_SETTING
|
put(new MsgStatusProfile()); // 0x0204 CMD_PUMP_CALCULATION_SETTING
|
||||||
put(new MsgStatusTempBasal()); // 0x0205 CMD_PUMP_EXERCISE_MODE
|
|
||||||
put(new MsgStatusBolusExtended()); // 0x0207 CMD_PUMP_EXPANS_INS_I
|
put(new MsgStatusTempBasal_v2()); // 0x0205 CMD_PUMP_EXERCISE_MODE
|
||||||
|
put(new MsgStatusBolusExtended_v2()); // 0x0207 CMD_PUMP_EXPANS_INS_I
|
||||||
|
|
||||||
put(new MsgStatusBasic()); // 0x020A CMD_PUMP_INITVIEW_I
|
put(new MsgStatusBasic()); // 0x020A CMD_PUMP_INITVIEW_I
|
||||||
put(new MsgStatus()); // 0x020B CMD_PUMP_STATUS
|
put(new MsgStatus()); // 0x020B CMD_PUMP_STATUS
|
||||||
put(new MsgInitConnStatusTime()); // 0x0301 CMD_PUMPINIT_TIME_INFO
|
put(new MsgInitConnStatusTime()); // 0x0301 CMD_PUMPINIT_TIME_INFO
|
||||||
|
|
|
@ -6,17 +6,24 @@ import org.slf4j.LoggerFactory;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||||
import info.nightscout.utils.DateUtil;
|
|
||||||
|
|
||||||
public class MsgHistoryEvents_v2 extends MessageBase {
|
public class MsgHistoryEvents_v2 extends MessageBase {
|
||||||
private static Logger log = LoggerFactory.getLogger(MsgHistoryEvents_v2.class);
|
private static Logger log = LoggerFactory.getLogger(MsgHistoryEvents_v2.class);
|
||||||
public boolean done;
|
public boolean done;
|
||||||
|
|
||||||
public MsgHistoryEvents_v2(Date from) {
|
public static long lastEventTimeLoaded = 0;
|
||||||
|
|
||||||
|
public MsgHistoryEvents_v2(long from) {
|
||||||
SetCommand(0xE003);
|
SetCommand(0xE003);
|
||||||
GregorianCalendar gfrom = new GregorianCalendar();
|
GregorianCalendar gfrom = new GregorianCalendar();
|
||||||
gfrom.setTimeInMillis(from.getTime());
|
gfrom.setTimeInMillis(from);
|
||||||
AddParamDate(gfrom);
|
AddParamDate(gfrom);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
@ -45,54 +52,108 @@ public class MsgHistoryEvents_v2 extends MessageBase {
|
||||||
int param1 = intFromBuff(bytes, 7, 2);
|
int param1 = intFromBuff(bytes, 7, 2);
|
||||||
int param2 = intFromBuff(bytes, 9, 2);
|
int param2 = intFromBuff(bytes, 9, 2);
|
||||||
|
|
||||||
|
TemporaryBasal temporaryBasal = MainApp.getDbHelper().findTempBasalByTime(datetime.getTime());
|
||||||
|
if (temporaryBasal != null) {
|
||||||
|
log.debug("Existing temporaryBasal found. Skipping ...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
temporaryBasal = new TemporaryBasal();
|
||||||
|
|
||||||
|
ExtendedBolus extendedBolus = MainApp.getDbHelper().findExtendedBolusByTime(datetime.getTime());
|
||||||
|
if (extendedBolus != null) {
|
||||||
|
log.debug("Existing extendedBolus found. Skipping ...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
extendedBolus = new ExtendedBolus();
|
||||||
|
|
||||||
|
Treatment treatment = MainApp.getDbHelper().findTreatmentByTime(datetime.getTime());
|
||||||
|
if (treatment != null) {
|
||||||
|
log.debug("Existing treatment found. Skipping ...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
|
|
||||||
switch (recordCode) {
|
switch (recordCode) {
|
||||||
case 1:
|
case DanaRPump.TEMPSTART:
|
||||||
log.debug("EVENT TEMPSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Ratio: " + param1 + "% Duration: " + param2 + "min");
|
log.debug("EVENT TEMPSTART (" + recordCode + ") " + datetime.toLocaleString() + " Ratio: " + param1 + "% Duration: " + param2 + "min");
|
||||||
|
temporaryBasal.date = datetime.getTime();
|
||||||
|
temporaryBasal.percentRate = param1;
|
||||||
|
temporaryBasal.durationInMinutes = param2;
|
||||||
|
MainApp.getConfigBuilder().addToHistoryTempBasalStart(temporaryBasal);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case DanaRPump.TEMPSTOP:
|
||||||
log.debug("EVENT TEMPSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime));
|
log.debug("EVENT TEMPSTOP (" + recordCode + ") " + datetime.toLocaleString());
|
||||||
|
temporaryBasal.date = datetime.getTime();
|
||||||
|
temporaryBasal.durationInMinutes = 0;
|
||||||
|
MainApp.getConfigBuilder().addToHistoryTempBasalStart(temporaryBasal);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case DanaRPump.EXTENDEDSTART:
|
||||||
log.debug("EVENT EXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
log.debug("EVENT EXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
||||||
|
extendedBolus.date = datetime.getTime();
|
||||||
|
extendedBolus.insulin = param1 / 100d;
|
||||||
|
extendedBolus.durationInMinutes = param2;
|
||||||
|
MainApp.getConfigBuilder().addToHistoryExtendedBolusStart(extendedBolus);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case DanaRPump.EXTENDEDSTOP:
|
||||||
log.debug("EVENT EXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
|
log.debug("EVENT EXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
|
||||||
|
extendedBolus.date = datetime.getTime();
|
||||||
|
extendedBolus.durationInMinutes = 0;
|
||||||
|
MainApp.getConfigBuilder().addToHistoryExtendedBolusStart(extendedBolus);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case DanaRPump.BOLUS:
|
||||||
log.debug("EVENT BOLUS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
log.debug("EVENT BOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
||||||
|
detailedBolusInfo.date = datetime.getTime();
|
||||||
|
detailedBolusInfo.insulin = param1 / 100d;
|
||||||
|
MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case DanaRPump.DUALBOLUS:
|
||||||
log.debug("EVENT DUALBOLUS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
log.debug("EVENT DUALBOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
||||||
|
detailedBolusInfo.date = datetime.getTime();
|
||||||
|
detailedBolusInfo.insulin = param1 / 100d;
|
||||||
|
MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo);
|
||||||
break;
|
break;
|
||||||
case 7:
|
case DanaRPump.DUALEXTENDEDSTART:
|
||||||
log.debug("EVENT DUALEXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
log.debug("EVENT DUALEXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
|
||||||
|
extendedBolus.date = datetime.getTime();
|
||||||
|
extendedBolus.insulin = param1 / 100d;
|
||||||
|
extendedBolus.durationInMinutes = param2;
|
||||||
|
MainApp.getConfigBuilder().addToHistoryExtendedBolusStart(extendedBolus);
|
||||||
break;
|
break;
|
||||||
case 8:
|
case DanaRPump.DUALEXTENDEDSTOP:
|
||||||
log.debug("EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
|
log.debug("EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
|
||||||
|
extendedBolus.date = datetime.getTime();
|
||||||
|
extendedBolus.durationInMinutes = 0;
|
||||||
|
MainApp.getConfigBuilder().addToHistoryExtendedBolusStart(extendedBolus);
|
||||||
break;
|
break;
|
||||||
case 9:
|
case DanaRPump.SUSPENDON:
|
||||||
log.debug("EVENT SUSPENDON (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime));
|
log.debug("EVENT SUSPENDON (" + recordCode + ") " + datetime.toLocaleString());
|
||||||
break;
|
break;
|
||||||
case 10:
|
case DanaRPump.SUSPENDOFF:
|
||||||
log.debug("EVENT SUSPENDOFF (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime));
|
log.debug("EVENT SUSPENDOFF (" + recordCode + ") " + datetime.toLocaleString());
|
||||||
break;
|
break;
|
||||||
case 11:
|
case DanaRPump.REFILL:
|
||||||
log.debug("EVENT REFILL (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Amount: " + param1 + "U");
|
log.debug("EVENT REFILL (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + param1 / 100d + "U");
|
||||||
break;
|
break;
|
||||||
case 12:
|
case DanaRPump.PRIME:
|
||||||
log.debug("EVENT PRIME (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Amount: " + param1 + "U");
|
log.debug("EVENT PRIME (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + param1 / 100d + "U");
|
||||||
break;
|
break;
|
||||||
case 13:
|
case DanaRPump.PROFILECHANGE:
|
||||||
log.debug("EVENT PROFILECHANGE (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " No: " + param1 + "U CurrentRate: " + param2 + "U/h");
|
log.debug("EVENT PROFILECHANGE (" + recordCode + ") " + datetime.toLocaleString() + " No: " + param1 + "U CurrentRate: " + param2 + "U/h");
|
||||||
break;
|
break;
|
||||||
case 14:
|
case DanaRPump.CARBS:
|
||||||
log.debug("EVENT CARBS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " Carbs: " + param1 + "g");
|
log.debug("EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " Carbs: " + param1 + "g");
|
||||||
|
detailedBolusInfo.date = datetime.getTime();
|
||||||
|
detailedBolusInfo.carbs = param1;
|
||||||
|
MainApp.getConfigBuilder().addTreatmentToHistory(detailedBolusInfo);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log.debug("Event: " + recordCode + " " + DateUtil.dateAndTimeString(datetime) + " Param1: " + param1 + " Param2: " + param2);
|
log.debug("Event: " + recordCode + " " + datetime.toLocaleString() + " Param1: " + param1 + " Param2: " + param2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (datetime.getTime() > lastEventTimeLoaded)
|
||||||
|
lastEventTimeLoaded = datetime.getTime();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,17 +16,17 @@ public class MsgSetHistoryEntry_v2 extends MessageBase {
|
||||||
SetCommand(0xE004);
|
SetCommand(0xE004);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MsgSetHistoryEntry_v2(int type, Date time, int param1, int param2) {
|
public MsgSetHistoryEntry_v2(int type, long time, int param1, int param2) {
|
||||||
this();
|
this();
|
||||||
|
|
||||||
AddParamByte((byte) type);
|
AddParamByte((byte) type);
|
||||||
GregorianCalendar gtime = new GregorianCalendar();
|
GregorianCalendar gtime = new GregorianCalendar();
|
||||||
gtime.setTimeInMillis(time.getTime());
|
gtime.setTimeInMillis(time);
|
||||||
AddParamDateTime(gtime);
|
AddParamDateTime(gtime);
|
||||||
AddParamInt(param1);
|
AddParamInt(param1);
|
||||||
AddParamInt(param2);
|
AddParamInt(param2);
|
||||||
if (Config.logDanaMessageDetail)
|
if (Config.logDanaMessageDetail)
|
||||||
log.debug("Set history entry: type: " + type + " date: " + time.toString() + " param1: " + param1 + " param2: " + param2);
|
log.debug("Set history entry: type: " + type + " date: " + new Date(time).toString() + " param1: " + param1 + " param2: " + param2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.Config;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||||
|
|
||||||
|
public class MsgStatusBolusExtended_v2 extends MessageBase {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(MsgStatusBolusExtended_v2.class);
|
||||||
|
|
||||||
|
public MsgStatusBolusExtended_v2() {
|
||||||
|
SetCommand(0x0207);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleMessage(byte[] bytes) {
|
||||||
|
boolean isExtendedInProgress = intFromBuff(bytes, 0, 1) == 1;
|
||||||
|
int extendedBolusHalfHours = intFromBuff(bytes, 1, 1);
|
||||||
|
int extendedBolusMinutes = extendedBolusHalfHours * 30;
|
||||||
|
|
||||||
|
double extendedBolusAmount = intFromBuff(bytes, 2, 2) / 100d;
|
||||||
|
int extendedBolusSoFarInSecs = intFromBuff(bytes, 4, 3);
|
||||||
|
// This is available only on korean, but not needed now
|
||||||
|
// int extendedBolusDeliveryPulse = intFromBuff(bytes, 7, 2);
|
||||||
|
// int isEasyUIUserSleep = intFromBuff(bytes, 9, 1);
|
||||||
|
|
||||||
|
int extendedBolusSoFarInMinutes = extendedBolusSoFarInSecs / 60;
|
||||||
|
double extendedBolusAbsoluteRate = isExtendedInProgress ? extendedBolusAmount / extendedBolusMinutes * 60 : 0d;
|
||||||
|
Date extendedBolusStart = isExtendedInProgress ? getDateFromSecAgo(extendedBolusSoFarInSecs) : new Date(0);
|
||||||
|
int extendedBolusRemainingMinutes = extendedBolusMinutes - extendedBolusSoFarInMinutes;
|
||||||
|
|
||||||
|
DanaRPump pump = DanaRPump.getInstance();
|
||||||
|
pump.isExtendedInProgress = isExtendedInProgress;
|
||||||
|
pump.extendedBolusMinutes = extendedBolusMinutes;
|
||||||
|
pump.extendedBolusAmount = extendedBolusAmount;
|
||||||
|
pump.extendedBolusSoFarInMinutes = extendedBolusSoFarInMinutes;
|
||||||
|
pump.extendedBolusAbsoluteRate = extendedBolusAbsoluteRate;
|
||||||
|
pump.extendedBolusStart = extendedBolusStart;
|
||||||
|
pump.extendedBolusRemainingMinutes = extendedBolusRemainingMinutes;
|
||||||
|
|
||||||
|
if (Config.logDanaMessageDetail) {
|
||||||
|
log.debug("Is extended bolus running: " + isExtendedInProgress);
|
||||||
|
log.debug("Extended bolus min: " + extendedBolusMinutes);
|
||||||
|
log.debug("Extended bolus amount: " + extendedBolusAmount);
|
||||||
|
log.debug("Extended bolus so far in minutes: " + extendedBolusSoFarInMinutes);
|
||||||
|
log.debug("Extended bolus absolute rate: " + extendedBolusAbsoluteRate);
|
||||||
|
log.debug("Extended bolus start: " + extendedBolusStart);
|
||||||
|
log.debug("Extended bolus remaining minutes: " + extendedBolusRemainingMinutes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private Date getDateFromSecAgo(int tempBasalAgoSecs) {
|
||||||
|
return new Date((long) (Math.ceil(new Date().getTime() / 1000d) - tempBasalAgoSecs) * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.Config;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||||
|
|
||||||
|
public class MsgStatusTempBasal_v2 extends MessageBase {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(MsgStatusTempBasal_v2.class);
|
||||||
|
|
||||||
|
public MsgStatusTempBasal_v2() {
|
||||||
|
SetCommand(0x0205);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleMessage(byte[] bytes) {
|
||||||
|
boolean isTempBasalInProgress = (intFromBuff(bytes, 0, 1) & 0x01) == 0x01;
|
||||||
|
boolean isAPSTempBasalInProgress = (intFromBuff(bytes, 0, 1) & 0x02) == 0x02;
|
||||||
|
int tempBasalPercent = intFromBuff(bytes, 1, 1);
|
||||||
|
if (tempBasalPercent > 200) tempBasalPercent = (tempBasalPercent - 200) * 10;
|
||||||
|
int tempBasalTotalSec;
|
||||||
|
if (intFromBuff(bytes, 2, 1) == 150) tempBasalTotalSec = 15 * 60;
|
||||||
|
else if (intFromBuff(bytes, 2, 1) == 160) tempBasalTotalSec = 30 * 60;
|
||||||
|
else tempBasalTotalSec = intFromBuff(bytes, 2, 1) * 60 * 60;
|
||||||
|
int tempBasalRunningSeconds = intFromBuff(bytes, 3, 3);
|
||||||
|
int tempBasalRemainingMin = (tempBasalTotalSec - tempBasalRunningSeconds) / 60;
|
||||||
|
Date tempBasalStart = isTempBasalInProgress ? getDateFromTempBasalSecAgo(tempBasalRunningSeconds) : new Date(0);
|
||||||
|
|
||||||
|
DanaRPump pump = DanaRPump.getInstance();
|
||||||
|
pump.isTempBasalInProgress = isTempBasalInProgress;
|
||||||
|
pump.tempBasalPercent = tempBasalPercent;
|
||||||
|
pump.tempBasalRemainingMin = tempBasalRemainingMin;
|
||||||
|
pump.tempBasalTotalSec = tempBasalTotalSec;
|
||||||
|
pump.tempBasalStart = tempBasalStart;
|
||||||
|
|
||||||
|
if (Config.logDanaMessageDetail) {
|
||||||
|
log.debug("Is temp basal running: " + isTempBasalInProgress);
|
||||||
|
log.debug("Is APS temp basal running: " + isAPSTempBasalInProgress);
|
||||||
|
log.debug("Current temp basal percent: " + tempBasalPercent);
|
||||||
|
log.debug("Current temp basal remaining min: " + tempBasalRemainingMin);
|
||||||
|
log.debug("Current temp basal total sec: " + tempBasalTotalSec);
|
||||||
|
log.debug("Current temp basal start: " + tempBasalStart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private Date getDateFromTempBasalSecAgo(int tempBasalAgoSecs) {
|
||||||
|
return new Date((long) (Math.ceil(new Date().getTime() / 1000d) - tempBasalAgoSecs) * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -44,8 +44,11 @@ import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.SerialIOThread;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.SerialIOThread;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgHistoryEvents_v2;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgHistoryEvents_v2;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetAPSTempBasalStart_v2;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetAPSTempBasalStart_v2;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetHistoryEntry_v2;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusAPS_v2;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusAPS_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.MsgStatusTempBasal_v2;
|
||||||
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;
|
||||||
|
@ -70,6 +73,8 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
|
|
||||||
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");
|
||||||
|
|
||||||
|
private long lastHistoryFetched = 0;
|
||||||
|
|
||||||
private BroadcastReceiver receiver = new BroadcastReceiver() {
|
private BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
@ -247,8 +252,8 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
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();
|
||||||
MsgStatusBasic statusBasicMsg = new MsgStatusBasic();
|
MsgStatusBasic statusBasicMsg = new MsgStatusBasic();
|
||||||
MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal();
|
MsgStatusTempBasal_v2 tempStatusMsg = new MsgStatusTempBasal_v2();
|
||||||
MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended();
|
MsgStatusBolusExtended_v2 exStatusMsg = new MsgStatusBolusExtended_v2();
|
||||||
MsgCheckValue_v2 checkValue = new MsgCheckValue_v2();
|
MsgCheckValue_v2 checkValue = new MsgCheckValue_v2();
|
||||||
|
|
||||||
if (danaRPump.isNewPump) {
|
if (danaRPump.isNewPump) {
|
||||||
|
@ -325,7 +330,8 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
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());
|
mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2());
|
||||||
|
loadEvents();
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -335,8 +341,8 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
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 MsgStatusAPS_v2());
|
mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2());
|
||||||
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
|
loadEvents();
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -346,7 +352,8 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
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());
|
||||||
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
|
mSerialIOThread.sendMessage(new MsgStatusTempBasal_v2());
|
||||||
|
loadEvents();
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -356,7 +363,8 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
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)));
|
||||||
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
|
mSerialIOThread.sendMessage(new MsgStatusBolusExtended_v2());
|
||||||
|
loadEvents();
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -366,12 +374,13 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
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());
|
||||||
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
|
mSerialIOThread.sendMessage(new MsgStatusBolusExtended_v2());
|
||||||
|
loadEvents();
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean bolus(double amount, int carbs, Treatment t) {
|
public boolean bolus(double amount, int carbs, long carbtime, Treatment t) {
|
||||||
bolusingTreatment = t;
|
bolusingTreatment = t;
|
||||||
MsgBolusStart start = new MsgBolusStart(amount);
|
MsgBolusStart start = new MsgBolusStart(amount);
|
||||||
MsgBolusStop stop = new MsgBolusStop(amount, t);
|
MsgBolusStop stop = new MsgBolusStop(amount, t);
|
||||||
|
@ -380,8 +389,11 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
|
|
||||||
if (carbs > 0) {
|
if (carbs > 0) {
|
||||||
Calendar time = Calendar.getInstance();
|
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(carbtime, carbs);
|
||||||
mSerialIOThread.sendMessage(new MsgSetCarbsEntry(time, carbs));
|
mSerialIOThread.sendMessage(msg);
|
||||||
|
MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(DanaRPump.CARBS, carbtime, carbs, 0);
|
||||||
|
mSerialIOThread.sendMessage(msgSetHistoryEntry_v2);
|
||||||
|
lastHistoryFetched = carbtime - 1000;
|
||||||
}
|
}
|
||||||
MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables
|
MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables
|
||||||
MainApp.bus().post(new EventDanaRBolusStart());
|
MainApp.bus().post(new EventDanaRBolusStart());
|
||||||
|
@ -402,7 +414,7 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
waitMsec(300);
|
waitMsec(300);
|
||||||
bolusingTreatment = null;
|
bolusingTreatment = null;
|
||||||
getPumpStatus();
|
loadEvents();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,12 +434,14 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean carbsEntry(int amount) {
|
public boolean carbsEntry(int amount, long time) {
|
||||||
connect("carbsEntry");
|
connect("carbsEntry");
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
Calendar time = Calendar.getInstance();
|
|
||||||
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(time, amount);
|
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(time, amount);
|
||||||
mSerialIOThread.sendMessage(msg);
|
mSerialIOThread.sendMessage(msg);
|
||||||
|
MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(DanaRPump.CARBS, time, amount, 0);
|
||||||
|
mSerialIOThread.sendMessage(msgSetHistoryEntry_v2);
|
||||||
|
lastHistoryFetched = time - 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,12 +492,20 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
|
|
||||||
public boolean loadEvents() {
|
public boolean loadEvents() {
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MsgHistoryEvents_v2 msg = new MsgHistoryEvents_v2();
|
MsgHistoryEvents_v2 msg;
|
||||||
|
if (lastHistoryFetched == 0) {
|
||||||
|
msg = new MsgHistoryEvents_v2();
|
||||||
|
log.debug("Loading complete event history");
|
||||||
|
} else {
|
||||||
|
msg = new MsgHistoryEvents_v2(lastHistoryFetched);
|
||||||
|
log.debug("Loading event history from: " + new Date(lastHistoryFetched).toLocaleString());
|
||||||
|
}
|
||||||
mSerialIOThread.sendMessage(msg);
|
mSerialIOThread.sendMessage(msg);
|
||||||
while (!msg.done && mRfcommSocket.isConnected()) {
|
while (!msg.done && mRfcommSocket.isConnected()) {
|
||||||
waitMsec(100);
|
waitMsec(100);
|
||||||
}
|
}
|
||||||
waitMsec(200);
|
waitMsec(200);
|
||||||
|
lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -341,7 +341,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addToHistoryExtendedBolusStart(ExtendedBolus extendedBolus) {
|
public void addToHistoryExtendedBolusStart(ExtendedBolus extendedBolus) {
|
||||||
log.debug("Adding new ExtentedBolus record" + extendedBolus);
|
log.debug("Adding new ExtentedBolus record" + extendedBolus.log());
|
||||||
MainApp.getDbHelper().createOrUpdate(extendedBolus);
|
MainApp.getDbHelper().createOrUpdate(extendedBolus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,7 +350,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
ExtendedBolus extendedBolus = new ExtendedBolus();
|
ExtendedBolus extendedBolus = new ExtendedBolus();
|
||||||
extendedBolus.date = time;
|
extendedBolus.date = time;
|
||||||
extendedBolus.durationInMinutes = 0;
|
extendedBolus.durationInMinutes = 0;
|
||||||
log.debug("Adding new ExtentedBolus stop record" + extendedBolus);
|
log.debug("Adding new ExtentedBolus stop record" + extendedBolus.log());
|
||||||
MainApp.getDbHelper().createOrUpdate(extendedBolus);
|
MainApp.getDbHelper().createOrUpdate(extendedBolus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addToHistoryTempBasalStart(TemporaryBasal tempBasal) {
|
public void addToHistoryTempBasalStart(TemporaryBasal tempBasal) {
|
||||||
log.debug("Adding new TemporaryBasal record" + tempBasal);
|
log.debug("Adding new TemporaryBasal record" + tempBasal.log());
|
||||||
MainApp.getDbHelper().createOrUpdate(tempBasal);
|
MainApp.getDbHelper().createOrUpdate(tempBasal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,7 +399,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
TemporaryBasal temporaryBasal = new TemporaryBasal();
|
TemporaryBasal temporaryBasal = new TemporaryBasal();
|
||||||
temporaryBasal.date = time;
|
temporaryBasal.date = time;
|
||||||
temporaryBasal.durationInMinutes = 0;
|
temporaryBasal.durationInMinutes = 0;
|
||||||
log.debug("Adding new TemporaryBasal stop record" + temporaryBasal);
|
log.debug("Adding new TemporaryBasal stop record" + temporaryBasal.log());
|
||||||
MainApp.getDbHelper().createOrUpdate(temporaryBasal);
|
MainApp.getDbHelper().createOrUpdate(temporaryBasal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,7 +413,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
treatment.source = detailedBolusInfo.source;
|
treatment.source = detailedBolusInfo.source;
|
||||||
treatment.mealBolus = treatment.carbs > 0;
|
treatment.mealBolus = treatment.carbs > 0;
|
||||||
MainApp.getDbHelper().createOrUpdate(treatment);
|
MainApp.getDbHelper().createOrUpdate(treatment);
|
||||||
log.debug("Adding new Treatment record" + treatment);
|
log.debug("Adding new Treatment record" + treatment.log());
|
||||||
if (detailedBolusInfo.carbTime != 0) {
|
if (detailedBolusInfo.carbTime != 0) {
|
||||||
Treatment carbsTreatment = new Treatment(detailedBolusInfo.insulinInterface);
|
Treatment carbsTreatment = new Treatment(detailedBolusInfo.insulinInterface);
|
||||||
carbsTreatment.date = detailedBolusInfo.date + detailedBolusInfo.carbTime * 60 * 1000L;
|
carbsTreatment.date = detailedBolusInfo.date + detailedBolusInfo.carbTime * 60 * 1000L;
|
||||||
|
|
Loading…
Reference in a new issue