- RileyStatusGeneral fixed in case fimrware is not set (no connection to RL yet, when page is opened) - Crashalytics

- Possible fix for SMB problem
- Possible fix for Treatments saving
- If last History entry has no date set, system doesn't crash (it crashed because it tryied to parse date and setting wrong values
This commit is contained in:
Andy Rozman 2019-05-02 20:22:44 +01:00
parent dbb9c132f4
commit 7f61f45b78
4 changed files with 89 additions and 49 deletions

View file

@ -1,9 +1,5 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog; package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog;
import java.util.Locale;
import org.joda.time.LocalDateTime;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -11,10 +7,15 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.joda.time.LocalDateTime;
import java.util.Locale;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface; import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil; import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
@ -101,10 +102,12 @@ public class RileyLinkStatusGeneral extends Fragment implements RefreshableInter
"-" "-"
: MainApp.gs(rileyLinkServiceData.errorCode.getResourceId(targetDevice))); : MainApp.gs(rileyLinkServiceData.errorCode.getResourceId(targetDevice)));
RileyLinkFirmwareVersion firmwareVersion = rileyLinkServiceData.versionCC110;
this.firmwareVersion.setText("BLE113: " + // this.firmwareVersion.setText("BLE113: " + //
rileyLinkServiceData.versionBLE113 == null ? "-" : rileyLinkServiceData.versionBLE113 + // rileyLinkServiceData.versionBLE113 == null ? "-" : rileyLinkServiceData.versionBLE113 + //
"\nCC110: " + rileyLinkServiceData.versionCC110 == null ? "-" : rileyLinkServiceData.versionCC110 "\nCC110: " + firmwareVersion == null ? "-" : firmwareVersion.toString());
.toString());
} }
// TODO add handling for Omnipod pump status // TODO add handling for Omnipod pump status

View file

@ -4,12 +4,14 @@ package info.nightscout.androidaps.plugins.pump.common.utils;
* Created by andy on 10/25/18. * Created by andy on 10/25/18.
*/ */
import android.util.Log;
import org.joda.time.LocalDateTime;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import org.joda.time.LocalDateTime;
/** /**
* This is simple version of ATechDate, limited only to one format (yyyymmddHHMIss) * This is simple version of ATechDate, limited only to one format (yyyymmddHHMIss)
*/ */
@ -39,7 +41,13 @@ public class DateTimeUtil {
int second = (int)atechDateTime; int second = (int)atechDateTime;
try {
return new LocalDateTime(year, month, dayOfMonth, hourOfDay, minute, second); return new LocalDateTime(year, month, dayOfMonth, hourOfDay, minute, second);
} catch (Exception ex) {
Log.e("DateTimeUtil", String.format("Error creating LocalDateTime from values [atechDateTime=%d, year=%d, month=%d, day=%d, hour=%d, minute=%d, second=%d]", atechDateTime, year, month, dayOfMonth, hourOfDay, minute, second));
//return null;
throw ex;
}
} }

View file

@ -174,7 +174,16 @@ public class MedtronicHistoryData {
this.setLastHistoryRecordTime(pheLast.atechDateTime); this.setLastHistoryRecordTime(pheLast.atechDateTime);
LocalDateTime dt = DateTimeUtil.toLocalDateTime(pheLast.atechDateTime); LocalDateTime dt = null;
try {
dt = DateTimeUtil.toLocalDateTime(pheLast.atechDateTime);
} catch (Exception ex) {
LOG.error("Problem decoding date from last record: {}" + pheLast);
}
if (dt != null) {
dt = dt.minusDays(1); // we keep 24 hours dt = dt.minusDays(1); // we keep 24 hours
long dtRemove = DateTimeUtil.toATechDate(dt); long dtRemove = DateTimeUtil.toATechDate(dt);
@ -194,6 +203,9 @@ public class MedtronicHistoryData {
LOG.debug("All History records [afterFilterCount={}, removedItemsCount={}, newItemsCount={}]", LOG.debug("All History records [afterFilterCount={}, removedItemsCount={}, newItemsCount={}]",
allHistory.size(), removeList.size(), newHistory.size()); allHistory.size(), removeList.size(), newHistory.size());
} else {
LOG.error("Since we couldn't determine date, we don't clean full history. This is just workaround.");
}
this.newHistory.clear(); this.newHistory.clear();

View file

@ -255,6 +255,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
try { try {
Treatment old; Treatment old;
treatment.date = DatabaseHelper.roundDateToSec(treatment.date); treatment.date = DatabaseHelper.roundDateToSec(treatment.date);
boolean changed = false;
if (treatment.source == Source.PUMP) { if (treatment.source == Source.PUMP) {
// check for changed from pump change in NS // check for changed from pump change in NS
@ -262,16 +263,15 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
if (existingTreatment != null) { if (existingTreatment != null) {
boolean equalRePumpHistory = existingTreatment.equalsRePumpHistory(treatment); boolean equalRePumpHistory = existingTreatment.equalsRePumpHistory(treatment);
boolean sameSource = existingTreatment.source == treatment.source; boolean sameSource = existingTreatment.source == treatment.source;
if (!equalRePumpHistory) { if (!equalRePumpHistory) {
// another treatment exists. Update it with the treatment coming from the pump // another treatment exists. Update it with the treatment coming from the pump
if (L.isEnabled(L.DATATREATMENTS)) if (L.isEnabled(L.DATATREATMENTS))
log.debug("Pump record already found in database: " + existingTreatment.toString() + " wanting to add " + treatment.toString()); log.debug("Pump record already found in database: " + existingTreatment.toString() + " wanting to add " + treatment.toString());
long oldDate = existingTreatment.date; long oldDate = existingTreatment.date;
//preserve carbs // preserve carbs & SMB
if (existingTreatment.isValid && existingTreatment.carbs > 0 && treatment.carbs == 0) { changed = preserveCarbsAndSMB(treatment, existingTreatment);
treatment.carbs = existingTreatment.carbs;
}
getDao().delete(existingTreatment); // need to delete/create because date may change too getDao().delete(existingTreatment); // need to delete/create because date may change too
existingTreatment.copyBasics(treatment); existingTreatment.copyBasics(treatment);
@ -279,8 +279,9 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
DatabaseHelper.updateEarliestDataChange(oldDate); DatabaseHelper.updateEarliestDataChange(oldDate);
DatabaseHelper.updateEarliestDataChange(existingTreatment.date); DatabaseHelper.updateEarliestDataChange(existingTreatment.date);
scheduleTreatmentChange(treatment); scheduleTreatmentChange(treatment);
return new UpdateReturn(sameSource, false); //updating a pump treatment with another one from the pump is not counted as clash return new UpdateReturn(sameSource || changed, false); //updating a pump treatment with another one from the pump is not counted as clash
} }
return new UpdateReturn(equalRePumpHistory, false); return new UpdateReturn(equalRePumpHistory, false);
} }
existingTreatment = getDao().queryForId(treatment.date); existingTreatment = getDao().queryForId(treatment.date);
@ -292,10 +293,8 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
if (L.isEnabled(L.DATATREATMENTS)) if (L.isEnabled(L.DATATREATMENTS))
log.debug("Pump record already found in database: " + existingTreatment.toString() + " wanting to add " + treatment.toString()); log.debug("Pump record already found in database: " + existingTreatment.toString() + " wanting to add " + treatment.toString());
//preserve carbs // preserve carbs & SMB
if (existingTreatment.isValid && existingTreatment.carbs > 0 && treatment.carbs == 0) { changed = preserveCarbsAndSMB(treatment, existingTreatment);
treatment.carbs = existingTreatment.carbs;
}
getDao().delete(existingTreatment); // need to delete/create because date may change too getDao().delete(existingTreatment); // need to delete/create because date may change too
existingTreatment.copyFrom(treatment); existingTreatment.copyFrom(treatment);
@ -303,7 +302,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
DatabaseHelper.updateEarliestDataChange(oldDate); DatabaseHelper.updateEarliestDataChange(oldDate);
DatabaseHelper.updateEarliestDataChange(existingTreatment.date); DatabaseHelper.updateEarliestDataChange(existingTreatment.date);
scheduleTreatmentChange(treatment); scheduleTreatmentChange(treatment);
return new UpdateReturn(equalRePumpHistory || sameSource, false); return new UpdateReturn(equalRePumpHistory || sameSource || changed, false);
} }
getDao().create(treatment); getDao().create(treatment);
if (L.isEnabled(L.DATATREATMENTS)) if (L.isEnabled(L.DATATREATMENTS))
@ -379,12 +378,28 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
return new UpdateReturn(false, false); return new UpdateReturn(false, false);
} }
private boolean preserveCarbsAndSMB(Treatment treatment, Treatment existingTreatment) {
if (existingTreatment.isValid) {
if (existingTreatment.carbs > 0 && treatment.carbs == 0) {
treatment.carbs = existingTreatment.carbs;
}
treatment.isSMB = (existingTreatment.isSMB || treatment.isSMB);
return true;
}
return false;
}
private void treatmentCopy(Treatment oldTreatment, Treatment newTreatment, boolean fromNightScout) { private void treatmentCopy(Treatment oldTreatment, Treatment newTreatment, boolean fromNightScout) {
log.debug("treatmentCopy [old={}, new={}]", oldTreatment.toString(), newTreatment.toString()); log.debug("treatmentCopy [old={}, new={}]", oldTreatment.toString(), newTreatment.toString());
if (fromNightScout) { if (fromNightScout) {
long pumpId_old = oldTreatment.pumpId; long pumpId_old = oldTreatment.pumpId;
boolean isSMB = (oldTreatment.isSMB || newTreatment.isSMB);
oldTreatment.copyFrom(newTreatment); oldTreatment.copyFrom(newTreatment);
if (pumpId_old != 0) { if (pumpId_old != 0) {
@ -395,6 +410,8 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
oldTreatment.source = Source.PUMP; oldTreatment.source = Source.PUMP;
} }
oldTreatment.isSMB = isSMB;
} else { } else {
oldTreatment.copyFrom(newTreatment); oldTreatment.copyFrom(newTreatment);
} }