RS,Rv2: thread safe history

This commit is contained in:
Milos Kozak 2018-08-17 13:58:06 +02:00
parent 9c1e52bd17
commit 15e69a478e
8 changed files with 90 additions and 86 deletions

View file

@ -142,8 +142,8 @@ public class MessageBase {
return date;
}
public static Date dateTimeSecFromBuff(byte[] buff, int offset) {
Date date =
public static synchronized long dateTimeSecFromBuff(byte[] buff, int offset) {
return
new Date(
100 + intFromBuff(buff, offset, 1),
intFromBuff(buff, offset + 1, 1) - 1,
@ -151,8 +151,7 @@ public class MessageBase {
intFromBuff(buff, offset + 3, 1),
intFromBuff(buff, offset + 4, 1),
intFromBuff(buff, offset + 5, 1)
);
return date;
).getTime();
}
public static Date dateFromBuff(byte[] buff, int offset) {

View file

@ -25,7 +25,7 @@ public class MsgHistoryAll extends MessageBase {
byte recordCode = (byte) intFromBuff(bytes, 0, 1);
Date date = dateFromBuff(bytes, 1); // 3 bytes
Date datetime = dateTimeFromBuff(bytes, 1); // 5 bytes
Date datetimewihtsec = dateTimeSecFromBuff(bytes, 1); // 6 bytes
long datetimewihtsec = dateTimeSecFromBuff(bytes, 1); // 6 bytes
double dailyBasal = intFromBuff(bytes, 4, 2) * 0.01d;
double dailyBolus = intFromBuff(bytes, 6, 2) * 0.01d;
@ -79,42 +79,42 @@ public class MsgHistoryAll extends MessageBase {
break;
case RecordTypes.RECORD_TYPE_PRIME:
messageType += "prime";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordDate = datetimewihtsec;
danaRHistoryRecord.recordValue = value * 0.01;
break;
case RecordTypes.RECORD_TYPE_ERROR:
messageType += "error";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordDate = datetimewihtsec;
danaRHistoryRecord.recordValue = value * 0.01;
break;
case RecordTypes.RECORD_TYPE_REFILL:
messageType += "refill";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordDate = datetimewihtsec;
danaRHistoryRecord.recordValue = value * 0.01;
break;
case RecordTypes.RECORD_TYPE_BASALHOUR:
messageType += "basal hour";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordDate = datetimewihtsec;
danaRHistoryRecord.recordValue = value * 0.01;
break;
case RecordTypes.RECORD_TYPE_TB:
messageType += "tb";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordDate = datetimewihtsec;
danaRHistoryRecord.recordValue = value * 0.01;
break;
case RecordTypes.RECORD_TYPE_GLUCOSE:
messageType += "glucose";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordDate = datetimewihtsec;
danaRHistoryRecord.recordValue = value;
break;
case RecordTypes.RECORD_TYPE_CARBO:
messageType += "carbo";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordDate = datetimewihtsec;
danaRHistoryRecord.recordValue = value;
break;
case RecordTypes.RECORD_TYPE_ALARM:
messageType += "alarm";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordDate = datetimewihtsec;
String strAlarm = "None";
switch ((int) paramByte8) {
case 67:
@ -135,7 +135,7 @@ public class MsgHistoryAll extends MessageBase {
break;
case RecordTypes.RECORD_TYPE_SUSPEND:
messageType += "suspend";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordDate = datetimewihtsec;
String strRecordValue = "Off";
if ((int) paramByte8 == 79)
strRecordValue = "On";

View file

@ -16,6 +16,7 @@ import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.utils.DateUtil;
public class MsgInitConnStatusTime extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
@ -52,11 +53,11 @@ public class MsgInitConnStatusTime extends MessageBase {
return;
}
Date time = dateTimeSecFromBuff(bytes, 0);
long time = dateTimeSecFromBuff(bytes, 0);
int versionCode = intFromBuff(bytes, 6, 1);
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Pump time: " + time);
log.debug("Pump time: " + DateUtil.dateAndTimeFullString(time));
log.debug("Version code: " + versionCode);
}
}

View file

@ -17,6 +17,7 @@ import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.utils.DateUtil;
public class MsgInitConnStatusTime_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
@ -54,14 +55,14 @@ public class MsgInitConnStatusTime_k extends MessageBase {
return;
}
Date time = dateTimeSecFromBuff(bytes, 0);
long time = dateTimeSecFromBuff(bytes, 0);
int versionCode1 = intFromBuff(bytes, 6, 1);
int versionCode2 = intFromBuff(bytes, 7, 1);
int versionCode3 = intFromBuff(bytes, 8, 1);
int versionCode4 = intFromBuff(bytes, 9, 1);
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Pump time: " + time);
log.debug("Pump time: " + DateUtil.dateAndTimeFullString(time));
log.debug("Version code1: " + versionCode1);
log.debug("Version code2: " + versionCode2);
log.debug("Version code3: " + versionCode3);

View file

@ -100,8 +100,8 @@ public class DanaRS_Packet {
return ret;
}
public static Date dateTimeSecFromBuff(byte[] buff, int offset) {
Date date =
public static synchronized long dateTimeSecFromBuff(byte[] buff, int offset) {
return
new Date(
100 + intFromBuff(buff, offset, 1),
intFromBuff(buff, offset + 1, 1) - 1,
@ -109,8 +109,7 @@ public class DanaRS_Packet {
intFromBuff(buff, offset + 3, 1),
intFromBuff(buff, offset + 4, 1),
intFromBuff(buff, offset + 5, 1)
);
return date;
).getTime();
}
protected static int intFromBuff(byte[] b, int srcStart, int srcLength) {

View file

@ -83,23 +83,23 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
return;
}
Date datetime = dateTimeSecFromBuff(data, 1); // 6 bytes
long datetime = dateTimeSecFromBuff(data, 1); // 6 bytes
int param1 = ((intFromBuff(data, 7, 1) << 8) & 0xFF00) + (intFromBuff(data, 8, 1) & 0xFF);
int param2 = ((intFromBuff(data, 9, 1) << 8) & 0xFF00) + (intFromBuff(data, 10, 1) & 0xFF);
TemporaryBasal temporaryBasal = new TemporaryBasal().date(datetime.getTime()).source(Source.PUMP).pumpId(datetime.getTime());
TemporaryBasal temporaryBasal = new TemporaryBasal().date(datetime).source(Source.PUMP).pumpId(datetime);
ExtendedBolus extendedBolus = new ExtendedBolus();
extendedBolus.date = datetime.getTime();
extendedBolus.date = datetime;
extendedBolus.source = Source.PUMP;
extendedBolus.pumpId = datetime.getTime();
extendedBolus.pumpId = datetime;
String status;
switch (recordCode) {
case DanaRPump.TEMPSTART:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT TEMPSTART (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Ratio: " + param1 + "% Duration: " + param2 + "min");
log.debug("EVENT TEMPSTART (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Ratio: " + param1 + "% Duration: " + param2 + "min");
temporaryBasal.percentRate = param1;
temporaryBasal.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
@ -107,13 +107,13 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
break;
case DanaRPump.TEMPSTOP:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT TEMPSTOP (" + recordCode + ") " + datetime.toLocaleString());
log.debug("EVENT TEMPSTOP (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime));
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
status = "TEMPSTOP " + DateUtil.timeString(datetime);
break;
case DanaRPump.EXTENDEDSTART:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT EXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
log.debug("EVENT EXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
extendedBolus.insulin = param1 / 100d;
extendedBolus.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
@ -121,43 +121,43 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
break;
case DanaRPump.EXTENDEDSTOP:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT EXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
log.debug("EVENT EXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
status = "EXTENDEDSTOP " + DateUtil.timeString(datetime);
break;
case DanaRPump.BOLUS:
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime.getTime());
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime);
if (detailedBolusInfo == null) {
detailedBolusInfo = new DetailedBolusInfo();
}
detailedBolusInfo.date = datetime.getTime();
detailedBolusInfo.date = datetime;
detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = datetime.getTime();
detailedBolusInfo.pumpId = datetime;
detailedBolusInfo.insulin = param1 / 100d;
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
if (L.isEnabled(L.PUMPCOMM))
log.debug((newRecord ? "**NEW** " : "") + "EVENT BOLUS (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
log.debug((newRecord ? "**NEW** " : "") + "EVENT BOLUS (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
status = "BOLUS " + DateUtil.timeString(datetime);
break;
case DanaRPump.DUALBOLUS:
detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime.getTime());
detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime);
if (detailedBolusInfo == null) {
detailedBolusInfo = new DetailedBolusInfo();
}
detailedBolusInfo.date = datetime.getTime();
detailedBolusInfo.date = datetime;
detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = datetime.getTime();
detailedBolusInfo.pumpId = datetime;
detailedBolusInfo.insulin = param1 / 100d;
newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
if (L.isEnabled(L.PUMPCOMM))
log.debug((newRecord ? "**NEW** " : "") + "EVENT DUALBOLUS (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
log.debug((newRecord ? "**NEW** " : "") + "EVENT DUALBOLUS (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
status = "DUALBOLUS " + DateUtil.timeString(datetime);
break;
case DanaRPump.DUALEXTENDEDSTART:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT DUALEXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
log.debug("EVENT DUALEXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
extendedBolus.insulin = param1 / 100d;
extendedBolus.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
@ -165,60 +165,60 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
break;
case DanaRPump.DUALEXTENDEDSTOP:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
log.debug("EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
status = "DUALEXTENDEDSTOP " + DateUtil.timeString(datetime);
break;
case DanaRPump.SUSPENDON:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT SUSPENDON (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")");
log.debug("EVENT SUSPENDON (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")");
status = "SUSPENDON " + DateUtil.timeString(datetime);
break;
case DanaRPump.SUSPENDOFF:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT SUSPENDOFF (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")");
log.debug("EVENT SUSPENDOFF (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")");
status = "SUSPENDOFF " + DateUtil.timeString(datetime);
break;
case DanaRPump.REFILL:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT REFILL (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Amount: " + param1 / 100d + "U");
log.debug("EVENT REFILL (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100d + "U");
status = "REFILL " + DateUtil.timeString(datetime);
break;
case DanaRPump.PRIME:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT PRIME (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Amount: " + param1 / 100d + "U");
log.debug("EVENT PRIME (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100d + "U");
status = "PRIME " + DateUtil.timeString(datetime);
break;
case DanaRPump.PROFILECHANGE:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT PROFILECHANGE (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " No: " + param1 + " CurrentRate: " + (param2 / 100d) + "U/h");
log.debug("EVENT PROFILECHANGE (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " No: " + param1 + " CurrentRate: " + (param2 / 100d) + "U/h");
status = "PROFILECHANGE " + DateUtil.timeString(datetime);
break;
case DanaRPump.CARBS:
DetailedBolusInfo emptyCarbsInfo = new DetailedBolusInfo();
emptyCarbsInfo.carbs = param1;
emptyCarbsInfo.date = datetime.getTime();
emptyCarbsInfo.date = datetime;
emptyCarbsInfo.source = Source.PUMP;
emptyCarbsInfo.pumpId = datetime.getTime();
emptyCarbsInfo.pumpId = datetime;
newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(emptyCarbsInfo, false);
if (L.isEnabled(L.PUMPCOMM))
log.debug((newRecord ? "**NEW** " : "") + "EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Carbs: " + param1 + "g");
log.debug((newRecord ? "**NEW** " : "") + "EVENT CARBS (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g");
status = "CARBS " + DateUtil.timeString(datetime);
break;
case DanaRPump.PRIMECANNULA:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT PRIMECANNULA(" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Amount: " + param1 / 100d + "U");
log.debug("EVENT PRIMECANNULA(" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100d + "U");
status = "PRIMECANNULA " + DateUtil.timeString(datetime);
break;
default:
if (L.isEnabled(L.PUMPCOMM))
log.debug("Event: " + recordCode + " " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Param1: " + param1 + " Param2: " + param2);
log.debug("Event: " + recordCode + " " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2);
status = "UNKNOWN " + DateUtil.timeString(datetime);
break;
}
if (datetime.getTime() > lastEventTimeLoaded)
lastEventTimeLoaded = datetime.getTime();
if (datetime > lastEventTimeLoaded)
lastEventTimeLoaded = datetime;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.processinghistory) + ": " + status));
}

View file

@ -58,26 +58,26 @@ public class MsgHistoryEvents_v2 extends MessageBase {
return;
}
Date datetime = dateTimeSecFromBuff(bytes, 1); // 6 bytes
long datetime = dateTimeSecFromBuff(bytes, 1); // 6 bytes
int param1 = intFromBuff(bytes, 7, 2);
int param2 = intFromBuff(bytes, 9, 2);
TemporaryBasal temporaryBasal = new TemporaryBasal()
.date(datetime.getTime())
.date(datetime)
.source(Source.PUMP)
.pumpId(datetime.getTime());
.pumpId(datetime);
ExtendedBolus extendedBolus = new ExtendedBolus();
extendedBolus.date = datetime.getTime();
extendedBolus.date = datetime;
extendedBolus.source = Source.PUMP;
extendedBolus.pumpId = datetime.getTime();
extendedBolus.pumpId = datetime;
String status = "";
switch (recordCode) {
case DanaRPump.TEMPSTART:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT TEMPSTART (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Ratio: " + param1 + "% Duration: " + param2 + "min");
log.debug("EVENT TEMPSTART (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Ratio: " + param1 + "% Duration: " + param2 + "min");
temporaryBasal.percentRate = param1;
temporaryBasal.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
@ -85,13 +85,13 @@ public class MsgHistoryEvents_v2 extends MessageBase {
break;
case DanaRPump.TEMPSTOP:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT TEMPSTOP (" + recordCode + ") " + datetime.toLocaleString());
log.debug("EVENT TEMPSTOP (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime));
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
status = "TEMPSTOP " + DateUtil.timeString(datetime);
break;
case DanaRPump.EXTENDEDSTART:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT EXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
log.debug("EVENT EXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
extendedBolus.insulin = param1 / 100d;
extendedBolus.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
@ -99,43 +99,43 @@ public class MsgHistoryEvents_v2 extends MessageBase {
break;
case DanaRPump.EXTENDEDSTOP:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT EXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
log.debug("EVENT EXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
status = "EXTENDEDSTOP " + DateUtil.timeString(datetime);
break;
case DanaRPump.BOLUS:
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime.getTime());
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime);
if (detailedBolusInfo == null) {
detailedBolusInfo = new DetailedBolusInfo();
}
detailedBolusInfo.date = datetime.getTime();
detailedBolusInfo.date = datetime;
detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = datetime.getTime();
detailedBolusInfo.pumpId = datetime;
detailedBolusInfo.insulin = param1 / 100d;
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
if (L.isEnabled(L.PUMPCOMM))
log.debug((newRecord ? "**NEW** " : "") + "EVENT BOLUS (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
log.debug((newRecord ? "**NEW** " : "") + "EVENT BOLUS (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
status = "BOLUS " + DateUtil.timeString(datetime);
break;
case DanaRPump.DUALBOLUS:
detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime.getTime());
detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime);
if (detailedBolusInfo == null) {
detailedBolusInfo = new DetailedBolusInfo();
}
detailedBolusInfo.date = datetime.getTime();
detailedBolusInfo.date = datetime;
detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = datetime.getTime();
detailedBolusInfo.pumpId = datetime;
detailedBolusInfo.insulin = param1 / 100d;
newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
if (L.isEnabled(L.PUMPCOMM))
log.debug((newRecord ? "**NEW** " : "") + "EVENT DUALBOLUS (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
log.debug((newRecord ? "**NEW** " : "") + "EVENT DUALBOLUS (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
status = "DUALBOLUS " + DateUtil.timeString(datetime);
break;
case DanaRPump.DUALEXTENDEDSTART:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT DUALEXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
log.debug("EVENT DUALEXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
extendedBolus.insulin = param1 / 100d;
extendedBolus.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
@ -143,55 +143,55 @@ public class MsgHistoryEvents_v2 extends MessageBase {
break;
case DanaRPump.DUALEXTENDEDSTOP:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
log.debug("EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
status = "DUALEXTENDEDSTOP " + DateUtil.timeString(datetime);
break;
case DanaRPump.SUSPENDON:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT SUSPENDON (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")");
log.debug("EVENT SUSPENDON (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")");
status = "SUSPENDON " + DateUtil.timeString(datetime);
break;
case DanaRPump.SUSPENDOFF:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT SUSPENDOFF (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")");
log.debug("EVENT SUSPENDOFF (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")");
status = "SUSPENDOFF " + DateUtil.timeString(datetime);
break;
case DanaRPump.REFILL:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT REFILL (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Amount: " + param1 / 100d + "U");
log.debug("EVENT REFILL (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100d + "U");
status = "REFILL " + DateUtil.timeString(datetime);
break;
case DanaRPump.PRIME:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT PRIME (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Amount: " + param1 / 100d + "U");
log.debug("EVENT PRIME (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100d + "U");
status = "PRIME " + DateUtil.timeString(datetime);
break;
case DanaRPump.PROFILECHANGE:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT PROFILECHANGE (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " No: " + param1 + " CurrentRate: " + (param2 / 100d) + "U/h");
log.debug("EVENT PROFILECHANGE (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " No: " + param1 + " CurrentRate: " + (param2 / 100d) + "U/h");
status = "PROFILECHANGE " + DateUtil.timeString(datetime);
break;
case DanaRPump.CARBS:
DetailedBolusInfo emptyCarbsInfo = new DetailedBolusInfo();
emptyCarbsInfo.carbs = param1;
emptyCarbsInfo.date = datetime.getTime();
emptyCarbsInfo.date = datetime;
emptyCarbsInfo.source = Source.PUMP;
emptyCarbsInfo.pumpId = datetime.getTime();
emptyCarbsInfo.pumpId = datetime;
newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(emptyCarbsInfo, false);
if (L.isEnabled(L.PUMPCOMM))
log.debug((newRecord ? "**NEW** " : "") + "EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Carbs: " + param1 + "g");
log.debug((newRecord ? "**NEW** " : "") + "EVENT CARBS (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g");
status = "CARBS " + DateUtil.timeString(datetime);
break;
default:
if (L.isEnabled(L.PUMPCOMM))
log.debug("Event: " + recordCode + " " + datetime.toLocaleString() + " (" + datetime.getTime() + ")" + " Param1: " + param1 + " Param2: " + param2);
log.debug("Event: " + recordCode + " " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2);
status = "UNKNOWN " + DateUtil.timeString(datetime);
break;
}
if (datetime.getTime() > lastEventTimeLoaded)
lastEventTimeLoaded = datetime.getTime();
if (datetime > lastEventTimeLoaded)
lastEventTimeLoaded = datetime;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.processinghistory) + ": " + status));
}

View file

@ -97,27 +97,27 @@ public class DateUtil {
}
public static String dateString(Date date) {
//return DateUtils.formatDateTime(MainApp.instance(), date.getTime(), DateUtils.FORMAT_SHOW_DATE); this provide month name not number
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
return df.format(date);
}
public static String dateString(long mills) {
//return DateUtils.formatDateTime(MainApp.instance(), mills, DateUtils.FORMAT_SHOW_DATE); this provide month name not number
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
return df.format(mills);
}
public static String timeString(Date date) {
//return DateUtils.formatDateTime(MainApp.instance(), date.getTime(), DateUtils.FORMAT_SHOW_TIME);
return new DateTime(date).toString(DateTimeFormat.shortTime());
}
public static String timeString(long mills) {
//return DateUtils.formatDateTime(MainApp.instance(), mills, DateUtils.FORMAT_SHOW_TIME);
return new DateTime(mills).toString(DateTimeFormat.shortTime());
}
public static String timeFullString(long mills) {
return new DateTime(mills).toString(DateTimeFormat.fullTime());
}
public static String dateAndTimeString(Date date) {
return dateString(date) + " " + timeString(date);
}
@ -130,6 +130,10 @@ public class DateUtil {
return dateString(mills) + " " + timeString(mills);
}
public static String dateAndTimeFullString(long mills) {
return dateString(mills) + " " + timeFullString(mills);
}
public static String minAgo(long time) {
int mins = (int) ((now() - time) / 1000 / 60);
return MainApp.gs(R.string.minago, mins);