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; return date;
} }
public static Date dateTimeSecFromBuff(byte[] buff, int offset) { public static synchronized long dateTimeSecFromBuff(byte[] buff, int offset) {
Date date = return
new Date( new Date(
100 + intFromBuff(buff, offset, 1), 100 + intFromBuff(buff, offset, 1),
intFromBuff(buff, offset + 1, 1) - 1, intFromBuff(buff, offset + 1, 1) - 1,
@ -151,8 +151,7 @@ public class MessageBase {
intFromBuff(buff, offset + 3, 1), intFromBuff(buff, offset + 3, 1),
intFromBuff(buff, offset + 4, 1), intFromBuff(buff, offset + 4, 1),
intFromBuff(buff, offset + 5, 1) intFromBuff(buff, offset + 5, 1)
); ).getTime();
return date;
} }
public static Date dateFromBuff(byte[] buff, int offset) { 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); byte recordCode = (byte) intFromBuff(bytes, 0, 1);
Date date = dateFromBuff(bytes, 1); // 3 bytes Date date = dateFromBuff(bytes, 1); // 3 bytes
Date datetime = dateTimeFromBuff(bytes, 1); // 5 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 dailyBasal = intFromBuff(bytes, 4, 2) * 0.01d;
double dailyBolus = intFromBuff(bytes, 6, 2) * 0.01d; double dailyBolus = intFromBuff(bytes, 6, 2) * 0.01d;
@ -79,42 +79,42 @@ public class MsgHistoryAll extends MessageBase {
break; break;
case RecordTypes.RECORD_TYPE_PRIME: case RecordTypes.RECORD_TYPE_PRIME:
messageType += "prime"; messageType += "prime";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime(); danaRHistoryRecord.recordDate = datetimewihtsec;
danaRHistoryRecord.recordValue = value * 0.01; danaRHistoryRecord.recordValue = value * 0.01;
break; break;
case RecordTypes.RECORD_TYPE_ERROR: case RecordTypes.RECORD_TYPE_ERROR:
messageType += "error"; messageType += "error";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime(); danaRHistoryRecord.recordDate = datetimewihtsec;
danaRHistoryRecord.recordValue = value * 0.01; danaRHistoryRecord.recordValue = value * 0.01;
break; break;
case RecordTypes.RECORD_TYPE_REFILL: case RecordTypes.RECORD_TYPE_REFILL:
messageType += "refill"; messageType += "refill";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime(); danaRHistoryRecord.recordDate = datetimewihtsec;
danaRHistoryRecord.recordValue = value * 0.01; danaRHistoryRecord.recordValue = value * 0.01;
break; break;
case RecordTypes.RECORD_TYPE_BASALHOUR: case RecordTypes.RECORD_TYPE_BASALHOUR:
messageType += "basal hour"; messageType += "basal hour";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime(); danaRHistoryRecord.recordDate = datetimewihtsec;
danaRHistoryRecord.recordValue = value * 0.01; danaRHistoryRecord.recordValue = value * 0.01;
break; break;
case RecordTypes.RECORD_TYPE_TB: case RecordTypes.RECORD_TYPE_TB:
messageType += "tb"; messageType += "tb";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime(); danaRHistoryRecord.recordDate = datetimewihtsec;
danaRHistoryRecord.recordValue = value * 0.01; danaRHistoryRecord.recordValue = value * 0.01;
break; break;
case RecordTypes.RECORD_TYPE_GLUCOSE: case RecordTypes.RECORD_TYPE_GLUCOSE:
messageType += "glucose"; messageType += "glucose";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime(); danaRHistoryRecord.recordDate = datetimewihtsec;
danaRHistoryRecord.recordValue = value; danaRHistoryRecord.recordValue = value;
break; break;
case RecordTypes.RECORD_TYPE_CARBO: case RecordTypes.RECORD_TYPE_CARBO:
messageType += "carbo"; messageType += "carbo";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime(); danaRHistoryRecord.recordDate = datetimewihtsec;
danaRHistoryRecord.recordValue = value; danaRHistoryRecord.recordValue = value;
break; break;
case RecordTypes.RECORD_TYPE_ALARM: case RecordTypes.RECORD_TYPE_ALARM:
messageType += "alarm"; messageType += "alarm";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime(); danaRHistoryRecord.recordDate = datetimewihtsec;
String strAlarm = "None"; String strAlarm = "None";
switch ((int) paramByte8) { switch ((int) paramByte8) {
case 67: case 67:
@ -135,7 +135,7 @@ public class MsgHistoryAll extends MessageBase {
break; break;
case RecordTypes.RECORD_TYPE_SUSPEND: case RecordTypes.RECORD_TYPE_SUSPEND:
messageType += "suspend"; messageType += "suspend";
danaRHistoryRecord.recordDate = datetimewihtsec.getTime(); danaRHistoryRecord.recordDate = datetimewihtsec;
String strRecordValue = "Off"; String strRecordValue = "Off";
if ((int) paramByte8 == 79) if ((int) paramByte8 == 79)
strRecordValue = "On"; 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.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.utils.DateUtil;
public class MsgInitConnStatusTime extends MessageBase { public class MsgInitConnStatusTime extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
@ -52,11 +53,11 @@ public class MsgInitConnStatusTime extends MessageBase {
return; return;
} }
Date time = dateTimeSecFromBuff(bytes, 0); long time = dateTimeSecFromBuff(bytes, 0);
int versionCode = intFromBuff(bytes, 6, 1); int versionCode = intFromBuff(bytes, 6, 1);
if (L.isEnabled(L.PUMPCOMM)) { if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Pump time: " + time); log.debug("Pump time: " + DateUtil.dateAndTimeFullString(time));
log.debug("Version code: " + versionCode); 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.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.utils.DateUtil;
public class MsgInitConnStatusTime_k extends MessageBase { public class MsgInitConnStatusTime_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM); private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
@ -54,14 +55,14 @@ public class MsgInitConnStatusTime_k extends MessageBase {
return; return;
} }
Date time = dateTimeSecFromBuff(bytes, 0); long time = dateTimeSecFromBuff(bytes, 0);
int versionCode1 = intFromBuff(bytes, 6, 1); int versionCode1 = intFromBuff(bytes, 6, 1);
int versionCode2 = intFromBuff(bytes, 7, 1); int versionCode2 = intFromBuff(bytes, 7, 1);
int versionCode3 = intFromBuff(bytes, 8, 1); int versionCode3 = intFromBuff(bytes, 8, 1);
int versionCode4 = intFromBuff(bytes, 9, 1); int versionCode4 = intFromBuff(bytes, 9, 1);
if (L.isEnabled(L.PUMPCOMM)) { 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 code1: " + versionCode1);
log.debug("Version code2: " + versionCode2); log.debug("Version code2: " + versionCode2);
log.debug("Version code3: " + versionCode3); log.debug("Version code3: " + versionCode3);

View file

@ -100,8 +100,8 @@ public class DanaRS_Packet {
return ret; return ret;
} }
public static Date dateTimeSecFromBuff(byte[] buff, int offset) { public static synchronized long dateTimeSecFromBuff(byte[] buff, int offset) {
Date date = return
new Date( new Date(
100 + intFromBuff(buff, offset, 1), 100 + intFromBuff(buff, offset, 1),
intFromBuff(buff, offset + 1, 1) - 1, intFromBuff(buff, offset + 1, 1) - 1,
@ -109,8 +109,7 @@ public class DanaRS_Packet {
intFromBuff(buff, offset + 3, 1), intFromBuff(buff, offset + 3, 1),
intFromBuff(buff, offset + 4, 1), intFromBuff(buff, offset + 4, 1),
intFromBuff(buff, offset + 5, 1) intFromBuff(buff, offset + 5, 1)
); ).getTime();
return date;
} }
protected static int intFromBuff(byte[] b, int srcStart, int srcLength) { 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; 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 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); 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 extendedBolus = new ExtendedBolus();
extendedBolus.date = datetime.getTime(); extendedBolus.date = datetime;
extendedBolus.source = Source.PUMP; extendedBolus.source = Source.PUMP;
extendedBolus.pumpId = datetime.getTime(); extendedBolus.pumpId = datetime;
String status; String status;
switch (recordCode) { switch (recordCode) {
case DanaRPump.TEMPSTART: case DanaRPump.TEMPSTART:
if (L.isEnabled(L.PUMPCOMM)) 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.percentRate = param1;
temporaryBasal.durationInMinutes = param2; temporaryBasal.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal); TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
@ -107,13 +107,13 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
break; break;
case DanaRPump.TEMPSTOP: case DanaRPump.TEMPSTOP:
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT TEMPSTOP (" + recordCode + ") " + datetime.toLocaleString()); log.debug("EVENT TEMPSTOP (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime));
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal); TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
status = "TEMPSTOP " + DateUtil.timeString(datetime); status = "TEMPSTOP " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.EXTENDEDSTART: case DanaRPump.EXTENDEDSTART:
if (L.isEnabled(L.PUMPCOMM)) 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.insulin = param1 / 100d;
extendedBolus.durationInMinutes = param2; extendedBolus.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
@ -121,43 +121,43 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
break; break;
case DanaRPump.EXTENDEDSTOP: case DanaRPump.EXTENDEDSTOP:
if (L.isEnabled(L.PUMPCOMM)) 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); TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
status = "EXTENDEDSTOP " + DateUtil.timeString(datetime); status = "EXTENDEDSTOP " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.BOLUS: case DanaRPump.BOLUS:
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime.getTime()); DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime);
if (detailedBolusInfo == null) { if (detailedBolusInfo == null) {
detailedBolusInfo = new DetailedBolusInfo(); detailedBolusInfo = new DetailedBolusInfo();
} }
detailedBolusInfo.date = datetime.getTime(); detailedBolusInfo.date = datetime;
detailedBolusInfo.source = Source.PUMP; detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = datetime.getTime(); detailedBolusInfo.pumpId = datetime;
detailedBolusInfo.insulin = param1 / 100d; detailedBolusInfo.insulin = param1 / 100d;
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
if (L.isEnabled(L.PUMPCOMM)) 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); status = "BOLUS " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.DUALBOLUS: case DanaRPump.DUALBOLUS:
detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime.getTime()); detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime);
if (detailedBolusInfo == null) { if (detailedBolusInfo == null) {
detailedBolusInfo = new DetailedBolusInfo(); detailedBolusInfo = new DetailedBolusInfo();
} }
detailedBolusInfo.date = datetime.getTime(); detailedBolusInfo.date = datetime;
detailedBolusInfo.source = Source.PUMP; detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = datetime.getTime(); detailedBolusInfo.pumpId = datetime;
detailedBolusInfo.insulin = param1 / 100d; detailedBolusInfo.insulin = param1 / 100d;
newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
if (L.isEnabled(L.PUMPCOMM)) 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); status = "DUALBOLUS " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.DUALEXTENDEDSTART: case DanaRPump.DUALEXTENDEDSTART:
if (L.isEnabled(L.PUMPCOMM)) 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.insulin = param1 / 100d;
extendedBolus.durationInMinutes = param2; extendedBolus.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
@ -165,60 +165,60 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
break; break;
case DanaRPump.DUALEXTENDEDSTOP: case DanaRPump.DUALEXTENDEDSTOP:
if (L.isEnabled(L.PUMPCOMM)) 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); TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
status = "DUALEXTENDEDSTOP " + DateUtil.timeString(datetime); status = "DUALEXTENDEDSTOP " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.SUSPENDON: case DanaRPump.SUSPENDON:
if (L.isEnabled(L.PUMPCOMM)) 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); status = "SUSPENDON " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.SUSPENDOFF: case DanaRPump.SUSPENDOFF:
if (L.isEnabled(L.PUMPCOMM)) 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); status = "SUSPENDOFF " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.REFILL: case DanaRPump.REFILL:
if (L.isEnabled(L.PUMPCOMM)) 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); status = "REFILL " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.PRIME: case DanaRPump.PRIME:
if (L.isEnabled(L.PUMPCOMM)) 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); status = "PRIME " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.PROFILECHANGE: case DanaRPump.PROFILECHANGE:
if (L.isEnabled(L.PUMPCOMM)) 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); status = "PROFILECHANGE " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.CARBS: case DanaRPump.CARBS:
DetailedBolusInfo emptyCarbsInfo = new DetailedBolusInfo(); DetailedBolusInfo emptyCarbsInfo = new DetailedBolusInfo();
emptyCarbsInfo.carbs = param1; emptyCarbsInfo.carbs = param1;
emptyCarbsInfo.date = datetime.getTime(); emptyCarbsInfo.date = datetime;
emptyCarbsInfo.source = Source.PUMP; emptyCarbsInfo.source = Source.PUMP;
emptyCarbsInfo.pumpId = datetime.getTime(); emptyCarbsInfo.pumpId = datetime;
newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(emptyCarbsInfo, false); newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(emptyCarbsInfo, false);
if (L.isEnabled(L.PUMPCOMM)) 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); status = "CARBS " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.PRIMECANNULA: case DanaRPump.PRIMECANNULA:
if (L.isEnabled(L.PUMPCOMM)) 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); status = "PRIMECANNULA " + DateUtil.timeString(datetime);
break; break;
default: default:
if (L.isEnabled(L.PUMPCOMM)) 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); status = "UNKNOWN " + DateUtil.timeString(datetime);
break; break;
} }
if (datetime.getTime() > lastEventTimeLoaded) if (datetime > lastEventTimeLoaded)
lastEventTimeLoaded = datetime.getTime(); lastEventTimeLoaded = datetime;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.processinghistory) + ": " + status)); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.processinghistory) + ": " + status));
} }

View file

@ -58,26 +58,26 @@ public class MsgHistoryEvents_v2 extends MessageBase {
return; return;
} }
Date datetime = dateTimeSecFromBuff(bytes, 1); // 6 bytes long datetime = dateTimeSecFromBuff(bytes, 1); // 6 bytes
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 = new TemporaryBasal() TemporaryBasal temporaryBasal = new TemporaryBasal()
.date(datetime.getTime()) .date(datetime)
.source(Source.PUMP) .source(Source.PUMP)
.pumpId(datetime.getTime()); .pumpId(datetime);
ExtendedBolus extendedBolus = new ExtendedBolus(); ExtendedBolus extendedBolus = new ExtendedBolus();
extendedBolus.date = datetime.getTime(); extendedBolus.date = datetime;
extendedBolus.source = Source.PUMP; extendedBolus.source = Source.PUMP;
extendedBolus.pumpId = datetime.getTime(); extendedBolus.pumpId = datetime;
String status = ""; String status = "";
switch (recordCode) { switch (recordCode) {
case DanaRPump.TEMPSTART: case DanaRPump.TEMPSTART:
if (L.isEnabled(L.PUMPCOMM)) 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.percentRate = param1;
temporaryBasal.durationInMinutes = param2; temporaryBasal.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal); TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
@ -85,13 +85,13 @@ public class MsgHistoryEvents_v2 extends MessageBase {
break; break;
case DanaRPump.TEMPSTOP: case DanaRPump.TEMPSTOP:
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT TEMPSTOP (" + recordCode + ") " + datetime.toLocaleString()); log.debug("EVENT TEMPSTOP (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime));
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal); TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
status = "TEMPSTOP " + DateUtil.timeString(datetime); status = "TEMPSTOP " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.EXTENDEDSTART: case DanaRPump.EXTENDEDSTART:
if (L.isEnabled(L.PUMPCOMM)) 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.insulin = param1 / 100d;
extendedBolus.durationInMinutes = param2; extendedBolus.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
@ -99,43 +99,43 @@ public class MsgHistoryEvents_v2 extends MessageBase {
break; break;
case DanaRPump.EXTENDEDSTOP: case DanaRPump.EXTENDEDSTOP:
if (L.isEnabled(L.PUMPCOMM)) 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); TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
status = "EXTENDEDSTOP " + DateUtil.timeString(datetime); status = "EXTENDEDSTOP " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.BOLUS: case DanaRPump.BOLUS:
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime.getTime()); DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime);
if (detailedBolusInfo == null) { if (detailedBolusInfo == null) {
detailedBolusInfo = new DetailedBolusInfo(); detailedBolusInfo = new DetailedBolusInfo();
} }
detailedBolusInfo.date = datetime.getTime(); detailedBolusInfo.date = datetime;
detailedBolusInfo.source = Source.PUMP; detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = datetime.getTime(); detailedBolusInfo.pumpId = datetime;
detailedBolusInfo.insulin = param1 / 100d; detailedBolusInfo.insulin = param1 / 100d;
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
if (L.isEnabled(L.PUMPCOMM)) 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); status = "BOLUS " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.DUALBOLUS: case DanaRPump.DUALBOLUS:
detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime.getTime()); detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime);
if (detailedBolusInfo == null) { if (detailedBolusInfo == null) {
detailedBolusInfo = new DetailedBolusInfo(); detailedBolusInfo = new DetailedBolusInfo();
} }
detailedBolusInfo.date = datetime.getTime(); detailedBolusInfo.date = datetime;
detailedBolusInfo.source = Source.PUMP; detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = datetime.getTime(); detailedBolusInfo.pumpId = datetime;
detailedBolusInfo.insulin = param1 / 100d; detailedBolusInfo.insulin = param1 / 100d;
newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
if (L.isEnabled(L.PUMPCOMM)) 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); status = "DUALBOLUS " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.DUALEXTENDEDSTART: case DanaRPump.DUALEXTENDEDSTART:
if (L.isEnabled(L.PUMPCOMM)) 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.insulin = param1 / 100d;
extendedBolus.durationInMinutes = param2; extendedBolus.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
@ -143,55 +143,55 @@ public class MsgHistoryEvents_v2 extends MessageBase {
break; break;
case DanaRPump.DUALEXTENDEDSTOP: case DanaRPump.DUALEXTENDEDSTOP:
if (L.isEnabled(L.PUMPCOMM)) 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); TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
status = "DUALEXTENDEDSTOP " + DateUtil.timeString(datetime); status = "DUALEXTENDEDSTOP " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.SUSPENDON: case DanaRPump.SUSPENDON:
if (L.isEnabled(L.PUMPCOMM)) 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); status = "SUSPENDON " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.SUSPENDOFF: case DanaRPump.SUSPENDOFF:
if (L.isEnabled(L.PUMPCOMM)) 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); status = "SUSPENDOFF " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.REFILL: case DanaRPump.REFILL:
if (L.isEnabled(L.PUMPCOMM)) 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); status = "REFILL " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.PRIME: case DanaRPump.PRIME:
if (L.isEnabled(L.PUMPCOMM)) 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); status = "PRIME " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.PROFILECHANGE: case DanaRPump.PROFILECHANGE:
if (L.isEnabled(L.PUMPCOMM)) 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); status = "PROFILECHANGE " + DateUtil.timeString(datetime);
break; break;
case DanaRPump.CARBS: case DanaRPump.CARBS:
DetailedBolusInfo emptyCarbsInfo = new DetailedBolusInfo(); DetailedBolusInfo emptyCarbsInfo = new DetailedBolusInfo();
emptyCarbsInfo.carbs = param1; emptyCarbsInfo.carbs = param1;
emptyCarbsInfo.date = datetime.getTime(); emptyCarbsInfo.date = datetime;
emptyCarbsInfo.source = Source.PUMP; emptyCarbsInfo.source = Source.PUMP;
emptyCarbsInfo.pumpId = datetime.getTime(); emptyCarbsInfo.pumpId = datetime;
newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(emptyCarbsInfo, false); newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(emptyCarbsInfo, false);
if (L.isEnabled(L.PUMPCOMM)) 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); status = "CARBS " + DateUtil.timeString(datetime);
break; break;
default: default:
if (L.isEnabled(L.PUMPCOMM)) 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); status = "UNKNOWN " + DateUtil.timeString(datetime);
break; break;
} }
if (datetime.getTime() > lastEventTimeLoaded) if (datetime > lastEventTimeLoaded)
lastEventTimeLoaded = datetime.getTime(); lastEventTimeLoaded = datetime;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.processinghistory) + ": " + status)); 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) { 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); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
return df.format(date); return df.format(date);
} }
public static String dateString(long mills) { 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); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
return df.format(mills); return df.format(mills);
} }
public static String timeString(Date date) { public static String timeString(Date date) {
//return DateUtils.formatDateTime(MainApp.instance(), date.getTime(), DateUtils.FORMAT_SHOW_TIME);
return new DateTime(date).toString(DateTimeFormat.shortTime()); return new DateTime(date).toString(DateTimeFormat.shortTime());
} }
public static String timeString(long mills) { public static String timeString(long mills) {
//return DateUtils.formatDateTime(MainApp.instance(), mills, DateUtils.FORMAT_SHOW_TIME);
return new DateTime(mills).toString(DateTimeFormat.shortTime()); 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) { public static String dateAndTimeString(Date date) {
return dateString(date) + " " + timeString(date); return dateString(date) + " " + timeString(date);
} }
@ -130,6 +130,10 @@ public class DateUtil {
return dateString(mills) + " " + timeString(mills); return dateString(mills) + " " + timeString(mills);
} }
public static String dateAndTimeFullString(long mills) {
return dateString(mills) + " " + timeFullString(mills);
}
public static String minAgo(long time) { public static String minAgo(long time) {
int mins = (int) ((now() - time) / 1000 / 60); int mins = (int) ((now() - time) / 1000 / 60);
return MainApp.gs(R.string.minago, mins); return MainApp.gs(R.string.minago, mins);