From dec627946d5f4c2a9ca198080869ad5063613fc9 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 29 May 2017 16:45:09 +0200 Subject: [PATCH] 0xE004 DanaRv2 message --- .../plugins/PumpDanaR/comm/MessageBase.java | 9 ++++ .../PumpDanaR/comm/MessageOriginalNames.java | 8 ++-- .../PumpDanaRv2/comm/MessageHashTable_v2.java | 9 ++-- .../comm/MsgSetHistoryEntry_v2.java | 43 +++++++++++++++++++ 4 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetHistoryEntry_v2.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageBase.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageBase.java index 4045f28f6e..e9851d4df8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageBase.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageBase.java @@ -51,6 +51,15 @@ public class MessageBase { AddParamByte((byte) (date.get(Calendar.MINUTE))); } + public void AddParamDateTime(GregorianCalendar date) { + AddParamByte((byte) (date.get(Calendar.YEAR) - 1900 - 100)); + AddParamByte((byte) (date.get(Calendar.MONTH) + 1)); + AddParamByte((byte) (date.get(Calendar.DAY_OF_MONTH))); + AddParamByte((byte) (date.get(Calendar.HOUR))); + AddParamByte((byte) (date.get(Calendar.MINUTE))); + AddParamByte((byte) (date.get(Calendar.SECOND))); + } + public void AddParamDateTime(Date date) { AddParamByte((byte) (date.getSeconds())); AddParamByte((byte) (date.getMinutes())); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageOriginalNames.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageOriginalNames.java index afb1367b26..3712945094 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageOriginalNames.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageOriginalNames.java @@ -151,10 +151,10 @@ public class MessageOriginalNames { messageNames.put(0x43F2, "CMD_HISTORY_DATEOVER_ALL"); messageNames.put(0x4300, "CMD_HISTORY_DATEOVER_DONE"); - messageNames.put(0xE001, "CMD_PUMP_APS"); - messageNames.put(0xE002, "CMD_PUMPSET_APS"); - messageNames.put(0xE003, "CMD_HISTORY_APS"); - messageNames.put(0xE004, "CMD_PUMPSET_APSTEMP"); + messageNames.put(0xE001, "CMD_PUMPSTATUS_APS"); + messageNames.put(0xE002, "CMD_PUMPSET_APSTEMP"); + messageNames.put(0xE003, "CMD_GET_HISTORY"); + messageNames.put(0xE004, "CMD_SET_HISTORY_ENTRY"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java index 471e4cc6fa..9e2760b47b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java @@ -68,10 +68,11 @@ public class MessageHashTable_v2 { put(new MsgHistoryAll()); // 0x41F2 CMD_HISTORY_ALL put(new MsgHistoryNewDone()); // 0x42F1 CMD_HISTORY_NEW_DONE put(new MsgHistoryNew()); // 0x42F2 CMD_HISTORY_NEW - put(new MsgCheckValue_v2()); // 0xF0F1 CMD_PUMP_CHECK_VALUE - put(new MsgStatusAPS_v2()); // 0xE001 CMD_PUMP_APS - put(new MsgSetAPSTempBasalStart_v2()); // 0xE002 CMD_PUMPSET_APSTEMP - put(new MsgHistoryEvents_v2()); // 0xE003 CMD_HISTORY_EVENTS + put(new MsgCheckValue_v2()); // 0xF0F1 CMD_PUMP_CHECK_VALUE + put(new MsgStatusAPS_v2()); // 0xE001 CMD_PUMPSTATUS_APS + put(new MsgSetAPSTempBasalStart_v2()); // 0xE002 CMD_PUMPSET_APSTEMP + put(new MsgHistoryEvents_v2()); // 0xE003 CMD_GET_HISTORY + put(new MsgSetHistoryEntry_v2()); // 0xE004 CMD_SET_HISTORY_ENTRY } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetHistoryEntry_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetHistoryEntry_v2.java new file mode 100644 index 0000000000..ea65abaaa0 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgSetHistoryEntry_v2.java @@ -0,0 +1,43 @@ +package info.nightscout.androidaps.plugins.PumpDanaRv2.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; +import java.util.GregorianCalendar; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; + +public class MsgSetHistoryEntry_v2 extends MessageBase { + private static Logger log = LoggerFactory.getLogger(MsgSetHistoryEntry_v2.class); + + public MsgSetHistoryEntry_v2() { + SetCommand(0xE004); + } + + public MsgSetHistoryEntry_v2(int type, Date time, int param1, int param2) { + this(); + + AddParamByte((byte) type); + GregorianCalendar gtime = new GregorianCalendar(); + gtime.setTimeInMillis(time.getTime()); + AddParamDateTime(gtime); + AddParamInt(param1); + AddParamInt(param2); + if (Config.logDanaMessageDetail) + log.debug("Set history entry: type: " + type + " date: " + time.toString() + " param1: " + param1 + " param2: " + param2); + } + + @Override + public void handleMessage(byte[] bytes) { + int result = intFromBuff(bytes, 0, 1); + if (result != 1) { + failed = true; + log.debug("Set history entry result: " + result + " FAILED!!!"); + } else { + if (Config.logDanaMessageDetail) + log.debug("Set history entry result: " + result); + } + } +}