Dana: MessageBase -> kt

This commit is contained in:
Milos Kozak 2022-03-30 14:14:39 +02:00
parent c383f471a7
commit 5f163ac3a9
72 changed files with 345 additions and 371 deletions

View file

@ -10,7 +10,7 @@ class MsgCheckValue_k(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0xF0F1) setCommand(0xF0F1)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -13,7 +13,7 @@ class MsgInitConnStatusBasic_k(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0303) setCommand(0x0303)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -13,7 +13,7 @@ class MsgInitConnStatusBolus_k(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0302) setCommand(0x0302)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -14,7 +14,7 @@ class MsgInitConnStatusTime_k(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0301) setCommand(0x0301)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -18,7 +18,7 @@ class MsgSettingBasalProfileAll_k(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x3206) setCommand(0x3206)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -10,7 +10,7 @@ class MsgSettingBasal_k(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x3202) setCommand(0x3202)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -9,7 +9,7 @@ class MsgStatusBasic_k(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x020A) setCommand(0x020A)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -9,7 +9,7 @@ class MsgStatus_k(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x020B) setCommand(0x020B)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.danaRKorean.services; package info.nightscout.androidaps.danaRKorean.services;
import android.annotation.SuppressLint;
import android.os.Binder; import android.os.Binder;
import android.os.SystemClock; import android.os.SystemClock;
@ -89,7 +90,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
} }
} }
public void connect() { @SuppressLint("MissingPermission") public void connect() {
if (mConnectionInProgress) if (mConnectionInProgress)
return; return;
@ -135,7 +136,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
if (danaPump.isNewPump()) { if (danaPump.isNewPump()) {
mSerialIOThread.sendMessage(checkValue); mSerialIOThread.sendMessage(checkValue);
if (!checkValue.received) { if (!checkValue.isReceived()) {
return; return;
} }
} }
@ -280,7 +281,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
t.insulin = 0d; t.insulin = 0d;
return false; return false;
} }
while (!danaPump.getBolusStopped() && !start.failed) { while (!danaPump.getBolusStopped() && !start.getFailed()) {
SystemClock.sleep(100); SystemClock.sleep(100);
if ((System.currentTimeMillis() - danaPump.getBolusProgressLastTimeStamp()) > 15 * 1000L) { // if i didn't receive status for more than 15 sec expecting broken comm if ((System.currentTimeMillis() - danaPump.getBolusProgressLastTimeStamp()) > 15 * 1000L) { // if i didn't receive status for more than 15 sec expecting broken comm
danaPump.setBolusStopped(true); danaPump.setBolusStopped(true);
@ -294,7 +295,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
commandQueue.readStatus(rh.gs(R.string.bolus_ok), null); commandQueue.readStatus(rh.gs(R.string.bolus_ok), null);
} }
return !start.failed; return !start.getFailed();
} }
public boolean carbsEntry(int amount) { public boolean carbsEntry(int amount) {

View file

@ -16,7 +16,7 @@ class MsgCheckValue_v2(
init { init {
SetCommand(0xF0F1) setCommand(0xF0F1)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -21,21 +21,21 @@ class MsgHistoryEventsV2 constructor(
} }
init { init {
SetCommand(0xE003) setCommand(0xE003)
if (from > dateUtil.now()) { if (from > dateUtil.now()) {
aapsLogger.error("Asked to load from the future") aapsLogger.error("Asked to load from the future")
from = 0 from = 0
} }
if (from == 0L) { if (from == 0L) {
AddParamByte(0.toByte()) addParamByte(0.toByte())
AddParamByte(1.toByte()) addParamByte(1.toByte())
AddParamByte(1.toByte()) addParamByte(1.toByte())
AddParamByte(0.toByte()) addParamByte(0.toByte())
AddParamByte(0.toByte()) addParamByte(0.toByte())
} else { } else {
val gFrom = GregorianCalendar() val gFrom = GregorianCalendar()
gFrom.timeInMillis = from gFrom.timeInMillis = from
AddParamDate(gFrom) addParamDate(gFrom)
} }
aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + dateUtil.dateAndTimeString(from)) aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + dateUtil.dateAndTimeString(from))
danaPump.historyDoneReceived = false danaPump.historyDoneReceived = false

View file

@ -16,16 +16,16 @@ class MsgSetAPSTempBasalStart_v2(
val PARAM15MIN = 150 val PARAM15MIN = 150
init { init {
SetCommand(0xE002) setCommand(0xE002)
//HARDCODED LIMITS //HARDCODED LIMITS
if (percent < 0) percent = 0 if (percent < 0) percent = 0
if (percent > 500) percent = 500 if (percent > 500) percent = 500
AddParamInt(percent) addParamInt(percent)
if (thirtyMinutes && percent <= 200) { // 30 min is allowed up to 200% if (thirtyMinutes && percent <= 200) { // 30 min is allowed up to 200%
AddParamByte(PARAM30MIN.toByte()) addParamByte(PARAM30MIN.toByte())
aapsLogger.debug(LTag.PUMPCOMM, "APS Temp basal start percent: $percent duration 30 min") aapsLogger.debug(LTag.PUMPCOMM, "APS Temp basal start percent: $percent duration 30 min")
} else { } else {
AddParamByte(PARAM15MIN.toByte()) addParamByte(PARAM15MIN.toByte())
aapsLogger.debug(LTag.PUMPCOMM, "APS Temp basal start percent: $percent duration 15 min") aapsLogger.debug(LTag.PUMPCOMM, "APS Temp basal start percent: $percent duration 15 min")
} }
} }

View file

@ -11,13 +11,13 @@ class MsgSetHistoryEntry_v2(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0xE004) setCommand(0xE004)
AddParamByte(type.toByte()) addParamByte(type.toByte())
val gtime = GregorianCalendar() val gtime = GregorianCalendar()
gtime.timeInMillis = time gtime.timeInMillis = time
AddParamDateTime(gtime) addParamDateTime(gtime)
AddParamInt(param1) addParamInt(param1)
AddParamInt(param2) addParamInt(param2)
aapsLogger.debug(LTag.PUMPCOMM, "Set history entry: type: " + type + " date: " + Date(time).toString() + " param1: " + param1 + " param2: " + param2) aapsLogger.debug(LTag.PUMPCOMM, "Set history entry: type: " + type + " date: " + Date(time).toString() + " param1: " + param1 + " param2: " + param2)
} }

View file

@ -9,7 +9,7 @@ class MsgStatusAPS_v2(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0xE001) setCommand(0xE001)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.danaRv2.services; package info.nightscout.androidaps.danaRv2.services;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.os.Binder; import android.os.Binder;
import android.os.SystemClock; import android.os.SystemClock;
@ -106,7 +107,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
mBinder = new LocalBinder(); mBinder = new LocalBinder();
} }
public void connect() { @SuppressLint("MissingPermission") public void connect() {
if (mConnectionInProgress) if (mConnectionInProgress)
return; return;
@ -152,7 +153,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
if (danaPump.isNewPump()) { if (danaPump.isNewPump()) {
mSerialIOThread.sendMessage(checkValue); mSerialIOThread.sendMessage(checkValue);
if (!checkValue.received) { if (!checkValue.isReceived()) {
return; return;
} }
} }
@ -348,7 +349,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
DanaPump.HistoryEntry.CARBS.getValue(), carbtime, carbs, 0); DanaPump.HistoryEntry.CARBS.getValue(), carbtime, carbs, 0);
mSerialIOThread.sendMessage(msgSetHistoryEntry_v2); mSerialIOThread.sendMessage(msgSetHistoryEntry_v2);
danaPump.lastHistoryFetched = Math.min(danaPump.lastHistoryFetched, carbtime - T.Companion.mins(1).msecs()); danaPump.lastHistoryFetched = Math.min(danaPump.lastHistoryFetched, carbtime - T.Companion.mins(1).msecs());
if (!msgSetHistoryEntry_v2.isReceived() || msgSetHistoryEntry_v2.failed) if (!msgSetHistoryEntry_v2.isReceived() || msgSetHistoryEntry_v2.getFailed())
ErrorHelperActivity.Companion.runAlarm(context, rh.gs(R.string.carbs_store_error) ErrorHelperActivity.Companion.runAlarm(context, rh.gs(R.string.carbs_store_error)
, rh.gs(R.string.error), R.raw.boluserror); , rh.gs(R.string.error), R.raw.boluserror);
} }
@ -364,7 +365,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
t.insulin = 0d; t.insulin = 0d;
return false; return false;
} }
while (!danaPump.getBolusStopped() && !start.failed) { while (!danaPump.getBolusStopped() && !start.getFailed()) {
SystemClock.sleep(100); SystemClock.sleep(100);
if ((System.currentTimeMillis() - danaPump.getBolusProgressLastTimeStamp()) > 15 * 1000L) { // if i didn't receive status for more than 15 sec expecting broken comm if ((System.currentTimeMillis() - danaPump.getBolusProgressLastTimeStamp()) > 15 * 1000L) { // if i didn't receive status for more than 15 sec expecting broken comm
danaPump.setBolusStopped(true); danaPump.setBolusStopped(true);
@ -410,7 +411,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
rxBus.send(new EventPumpStatusChanged(rh.gs(R.string.disconnecting))); rxBus.send(new EventPumpStatusChanged(rh.gs(R.string.disconnecting)));
} }
}); });
return !start.failed; return !start.getFailed();
} }
public boolean carbsEntry(int amount, long time) { public boolean carbsEntry(int amount, long time) {
@ -472,7 +473,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
MsgSetUserOptions msg = new MsgSetUserOptions(injector); MsgSetUserOptions msg = new MsgSetUserOptions(injector);
mSerialIOThread.sendMessage(msg); mSerialIOThread.sendMessage(msg);
SystemClock.sleep(200); SystemClock.sleep(200);
return new PumpEnactResult(injector).success(!msg.failed); return new PumpEnactResult(injector).success(!msg.getFailed());
} }
} }

View file

@ -74,10 +74,11 @@ public class SerialIOThread extends Thread {
message = hashTable.findMessage(command); message = hashTable.findMessage(command);
} }
aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + message.getMessageName() + " " + MessageBase.toHexString(extractedBuff)); aapsLogger.debug(LTag.PUMPBTCOMM,
"<<<<< " + message.getMessageName() + " " + MessageBase.Companion.toHexString(extractedBuff));
// process the message content // process the message content
message.received = true; message.setReceived(true);
message.handleMessage(extractedBuff); message.handleMessage(extractedBuff);
synchronized (message) { synchronized (message) {
message.notify(); message.notify();
@ -108,7 +109,7 @@ public class SerialIOThread extends Thread {
return null; return null;
} }
if (mReadBuff[length - 2] != (byte) 0x2E || mReadBuff[length - 1] != (byte) 0x2E) { if (mReadBuff[length - 2] != (byte) 0x2E || mReadBuff[length - 1] != (byte) 0x2E) {
aapsLogger.error("wrong packet lenght=" + length + " data " + MessageBase.toHexString(mReadBuff)); aapsLogger.error("wrong packet lenght=" + length + " data " + MessageBase.Companion.toHexString(mReadBuff));
disconnect("wrong packet"); disconnect("wrong packet");
return null; return null;
} }
@ -134,7 +135,7 @@ public class SerialIOThread extends Thread {
mReadBuff = unprocessedData; mReadBuff = unprocessedData;
return extractedBuff; return extractedBuff;
} else { } else {
aapsLogger.error("Wrong beginning of packet len=" + mReadBuff.length + " " + MessageBase.toHexString(mReadBuff)); aapsLogger.error("Wrong beginning of packet len=" + mReadBuff.length + " " + MessageBase.Companion.toHexString(mReadBuff));
disconnect("Wrong beginning of packet"); disconnect("Wrong beginning of packet");
return null; return null;
} }
@ -148,7 +149,7 @@ public class SerialIOThread extends Thread {
processedMessage = message; processedMessage = message;
byte[] messageBytes = message.getRawMessageBytes(); byte[] messageBytes = message.getRawMessageBytes();
aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + message.getMessageName() + " " + MessageBase.toHexString(messageBytes)); aapsLogger.debug(LTag.PUMPBTCOMM, ">>>>> " + message.getMessageName() + " " + MessageBase.Companion.toHexString(messageBytes));
try { try {
mOutputStream.write(messageBytes); mOutputStream.write(messageBytes);

View file

@ -1,250 +0,0 @@
package info.nightscout.androidaps.danar.comm;
import android.annotation.TargetApi;
import android.os.Build;
import org.joda.time.DateTime;
import org.joda.time.IllegalInstantException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.dana.DanaPump;
import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao;
import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.danaRv2.DanaRv2Plugin;
import info.nightscout.androidaps.danar.DanaRPlugin;
import info.nightscout.androidaps.interfaces.ActivePlugin;
import info.nightscout.androidaps.interfaces.CommandQueue;
import info.nightscout.androidaps.interfaces.ConfigBuilder;
import info.nightscout.androidaps.interfaces.PumpSync;
import info.nightscout.shared.logging.AAPSLogger;
import info.nightscout.shared.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.TemporaryBasalStorage;
import info.nightscout.androidaps.utils.CRC;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
/*
* 00 01 02 03 04 05 06
*
* 7E 7E len F1 CMD SUB data CRC CRC 2E 2E
*/
public class MessageBase {
@Inject public AAPSLogger aapsLogger;
@Inject public DateUtil dateUtil;
@Inject public DanaPump danaPump;
@Inject public DanaRPlugin danaRPlugin;
@Inject public DanaRKoreanPlugin danaRKoreanPlugin;
@Inject public DanaRv2Plugin danaRv2Plugin;
@Inject public RxBus rxBus;
@Inject public ResourceHelper rh;
@Inject public ActivePlugin activePlugin;
@Inject public ConfigBuilder configBuilder;
@Inject public CommandQueue commandQueue;
@Inject public DetailedBolusInfoStorage detailedBolusInfoStorage;
@Inject public TemporaryBasalStorage temporaryBasalStorage;
@Inject public ConstraintChecker constraintChecker;
@Inject public PumpSync pumpSync;
@Inject public DanaHistoryRecordDao danaHistoryRecordDao;
HasAndroidInjector injector;
public byte[] buffer = new byte[512];
private int position = 6;
public boolean received = false;
public boolean failed = false;
public MessageBase(HasAndroidInjector injector) {
injector.androidInjector().inject(this);
this.injector = injector;
}
public void SetCommand(int cmd) {
this.buffer[4] = (byte) (cmd >> 8 & 0xFF);
this.buffer[5] = (byte) (cmd & 0xFF);
}
public void AddParamByte(byte data) {
this.buffer[this.position++] = data;
}
public void AddParamInt(int data) {
this.buffer[this.position++] = (byte) (data >> 8 & 0xFF);
this.buffer[this.position++] = (byte) (data & 0xFF);
}
public void AddParamDate(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_OF_DAY)));
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_OF_DAY)));
AddParamByte((byte) (date.get(Calendar.MINUTE)));
AddParamByte((byte) (date.get(Calendar.SECOND)));
}
public void AddParamDateTimeReversed(long timestamp) {
GregorianCalendar date = new GregorianCalendar();
date.setTimeInMillis(timestamp);
AddParamByte((byte) (date.get(Calendar.SECOND)));
AddParamByte((byte) (date.get(Calendar.MINUTE)));
AddParamByte((byte) (date.get(Calendar.HOUR_OF_DAY)));
AddParamByte((byte) (date.get(Calendar.DAY_OF_MONTH)));
AddParamByte((byte) (date.get(Calendar.MONTH) + 1));
AddParamByte((byte) (date.get(Calendar.YEAR) - 1900 - 100));
}
public byte[] getRawMessageBytes() {
this.buffer[0] = (byte) 0x7E;
this.buffer[1] = (byte) 0x7E;
int length = this.position - 3;
this.buffer[2] = (byte) length;
this.buffer[3] = (byte) 0xF1;
this.AddParamInt(CRC.INSTANCE.getCrc16(this.buffer, 3, length));
this.buffer[length + 5] = (byte) 0x2E;
this.buffer[length + 6] = (byte) 0x2E;
return Arrays.copyOf(buffer, length + 7);
}
public String getMessageName() {
return MessageOriginalNames.INSTANCE.getName(getCommand());
}
public void handleMessage(byte[] bytes) {
if (bytes.length > 6) {
int command = (bytes[5] & 0xFF) | ((bytes[4] << 8) & 0xFF00);
aapsLogger.debug(LTag.PUMPCOMM, "UNPROCESSED MSG: " + getMessageName() + " Command: " + String.format("%04X", command) + " Data: " + toHexString(bytes));
} else {
aapsLogger.debug(LTag.PUMPCOMM, "MISFORMATTED MSG: " + toHexString(bytes));
}
}
public void handleMessageNotReceived() {
}
public int getCommand() {
return byteFromRawBuff(buffer, 5) | (byteFromRawBuff(buffer, 4) << 8);
}
public int byteFromRawBuff(byte[] buff, int offset) {
return buff[offset] & 0xFF;
}
public int intFromBuff(byte[] buff, int offset, int length) {
offset += 6;
switch (length) {
case 1:
return byteFromRawBuff(buff, offset);
case 2:
return (byteFromRawBuff(buff, offset) << 8) + byteFromRawBuff(buff, offset + 1);
case 3:
return (byteFromRawBuff(buff, offset + 2) << 16) + (byteFromRawBuff(buff, offset + 1) << 8) + byteFromRawBuff(buff, offset);
case 4:
return (byteFromRawBuff(buff, offset + 3) << 24) + (byteFromRawBuff(buff, offset + 2) << 16) + (byteFromRawBuff(buff, offset + 1) << 8) + byteFromRawBuff(buff, offset);
}
return 0;
}
public long dateTimeFromBuff(byte[] buff, int offset) {
return
new DateTime(
2000 + intFromBuff(buff, offset, 1),
intFromBuff(buff, offset + 1, 1),
intFromBuff(buff, offset + 2, 1),
intFromBuff(buff, offset + 3, 1),
intFromBuff(buff, offset + 4, 1),
0
).getMillis();
}
public synchronized long dateTimeSecFromBuff(byte[] buff, int offset) {
try {
return new DateTime(
2000 + intFromBuff(buff, offset, 1),
intFromBuff(buff, offset + 1, 1),
intFromBuff(buff, offset + 2, 1),
intFromBuff(buff, offset + 3, 1),
intFromBuff(buff, offset + 4, 1),
intFromBuff(buff, offset + 5, 1)
).getMillis();
} catch (IllegalInstantException e) {
// expect
// org.joda.time.IllegalInstantException: Illegal instant due to time zone offset transition (daylight savings time 'gap')
// add 1 hour
return new DateTime(
2000 + intFromBuff(buff, offset, 1),
intFromBuff(buff, offset + 1, 1),
intFromBuff(buff, offset + 2, 1),
intFromBuff(buff, offset + 3, 1) + 1,
intFromBuff(buff, offset + 4, 1),
intFromBuff(buff, offset + 5, 1)
).getMillis();
}
}
public long dateFromBuff(byte[] buff, int offset) {
return
new DateTime(
2000 + intFromBuff(buff, offset, 1),
intFromBuff(buff, offset + 1, 1),
intFromBuff(buff, offset + 2, 1),
0,
0
).getMillis();
}
@TargetApi(Build.VERSION_CODES.KITKAT)
public static String stringFromBuff(byte[] buff, int offset, int length) {
byte[] strBuff = new byte[length];
System.arraycopy(buff, offset + 6, strBuff, 0, length);
return new String(strBuff, StandardCharsets.UTF_8);
}
@TargetApi(Build.VERSION_CODES.KITKAT)
public static String asciiStringFromBuff(byte[] buff, int offset, int length) {
byte[] strBuff = new byte[length];
System.arraycopy(buff, offset + 6, strBuff, 0, length);
for (int pos = 0; pos < length; pos++)
strBuff[pos] += 65; // "A"
return new String(strBuff, StandardCharsets.UTF_8);
}
public static String toHexString(byte[] buff) {
StringBuilder sb = new StringBuilder();
int count = 0;
for (byte element : buff) {
sb.append(String.format("%02x ", element));
if (++count % 4 == 0) sb.append(" ");
}
return sb.toString();
}
public boolean isReceived() {
return received;
}
}

View file

@ -0,0 +1,220 @@
package info.nightscout.androidaps.danar.comm
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.dana.DanaPump
import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao
import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin
import info.nightscout.androidaps.danaRv2.DanaRv2Plugin
import info.nightscout.androidaps.danar.DanaRPlugin
import info.nightscout.androidaps.danar.comm.MessageOriginalNames.getName
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.CommandQueue
import info.nightscout.androidaps.interfaces.ConfigBuilder
import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.TemporaryBasalStorage
import info.nightscout.androidaps.utils.CRC.getCrc16
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import org.joda.time.DateTime
import org.joda.time.IllegalInstantException
import java.nio.charset.StandardCharsets
import java.util.*
import javax.inject.Inject
/*
* 00 01 02 03 04 05 06
*
* 7E 7E len F1 CMD SUB data CRC CRC 2E 2E
*/
open class MessageBase(injector: HasAndroidInjector) {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var danaPump: DanaPump
@Inject lateinit var danaRPlugin: DanaRPlugin
@Inject lateinit var danaRKoreanPlugin: DanaRKoreanPlugin
@Inject lateinit var danaRv2Plugin: DanaRv2Plugin
@Inject lateinit var rxBus: RxBus
@Inject lateinit var rh: ResourceHelper
@Inject lateinit var activePlugin: ActivePlugin
@Inject lateinit var configBuilder: ConfigBuilder
@Inject lateinit var commandQueue: CommandQueue
@Inject lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
@Inject lateinit var temporaryBasalStorage: TemporaryBasalStorage
@Inject lateinit var constraintChecker: ConstraintChecker
@Inject lateinit var pumpSync: PumpSync
@Inject lateinit var danaHistoryRecordDao: DanaHistoryRecordDao
var injector: HasAndroidInjector
var buffer = ByteArray(512)
private var position = 6
var isReceived = false
var failed = false
fun setCommand(cmd: Int) {
buffer[4] = (cmd shr 8 and 0xFF).toByte()
buffer[5] = (cmd and 0xFF).toByte()
}
fun addParamByte(data: Byte) {
buffer[position++] = data
}
fun addParamInt(data: Int) {
buffer[position++] = (data shr 8 and 0xFF).toByte()
buffer[position++] = (data and 0xFF).toByte()
}
fun addParamDate(date: GregorianCalendar) {
addParamByte((date[Calendar.YEAR] - 1900 - 100).toByte())
addParamByte((date[Calendar.MONTH] + 1).toByte())
addParamByte(date[Calendar.DAY_OF_MONTH].toByte())
addParamByte(date[Calendar.HOUR_OF_DAY].toByte())
addParamByte(date[Calendar.MINUTE].toByte())
}
fun addParamDateTime(date: GregorianCalendar) {
addParamByte((date[Calendar.YEAR] - 1900 - 100).toByte())
addParamByte((date[Calendar.MONTH] + 1).toByte())
addParamByte(date[Calendar.DAY_OF_MONTH].toByte())
addParamByte(date[Calendar.HOUR_OF_DAY].toByte())
addParamByte(date[Calendar.MINUTE].toByte())
addParamByte(date[Calendar.SECOND].toByte())
}
fun addParamDateTimeReversed(timestamp: Long) {
val date = GregorianCalendar()
date.timeInMillis = timestamp
addParamByte(date[Calendar.SECOND].toByte())
addParamByte(date[Calendar.MINUTE].toByte())
addParamByte(date[Calendar.HOUR_OF_DAY].toByte())
addParamByte(date[Calendar.DAY_OF_MONTH].toByte())
addParamByte((date[Calendar.MONTH] + 1).toByte())
addParamByte((date[Calendar.YEAR] - 1900 - 100).toByte())
}
val rawMessageBytes: ByteArray
get() {
buffer[0] = 0x7E.toByte()
buffer[1] = 0x7E.toByte()
val length = position - 3
buffer[2] = length.toByte()
buffer[3] = 0xF1.toByte()
addParamInt(getCrc16(buffer, 3, length).toInt())
buffer[length + 5] = 0x2E.toByte()
buffer[length + 6] = 0x2E.toByte()
return buffer.copyOf(length + 7)
}
val messageName: String?
get() = getName(command)
open fun handleMessage(bytes: ByteArray) {
if (bytes.size > 6) {
val command: Int = bytes[5].toInt() and 0xFF or (bytes[4].toInt() shl 8 and 0xFF00)
aapsLogger.debug(LTag.PUMPCOMM, "UNPROCESSED MSG: $messageName Command: ${String.format("%04X", command)} Data: ${toHexString(bytes)}")
} else {
aapsLogger.debug(LTag.PUMPCOMM, "MISFORMATTED MSG: ${toHexString(bytes)}")
}
}
open fun handleMessageNotReceived() {}
val command: Int
get() = byteFromRawBuff(buffer, 5) or (byteFromRawBuff(buffer, 4) shl 8)
private fun byteFromRawBuff(buff: ByteArray, offset: Int): Int {
return buff[offset].toInt() and 0xFF
}
fun intFromBuff(buff: ByteArray, buffOffset: Int, length: Int): Int {
val offset = buffOffset + 6
when (length) {
1 -> return byteFromRawBuff(buff, offset)
2 -> return (byteFromRawBuff(buff, offset) shl 8) + byteFromRawBuff(buff, offset + 1)
3 -> return (byteFromRawBuff(buff, offset + 2) shl 16) + (byteFromRawBuff(buff, offset + 1) shl 8) + byteFromRawBuff(buff, offset)
4 -> return (byteFromRawBuff(buff, offset + 3) shl 24) + (byteFromRawBuff(buff, offset + 2) shl 16) + (byteFromRawBuff(buff, offset + 1) shl 8) + byteFromRawBuff(buff, offset)
}
return 0
}
fun dateTimeFromBuff(buff: ByteArray, offset: Int): Long {
return DateTime(
2000 + intFromBuff(buff, offset, 1),
intFromBuff(buff, offset + 1, 1),
intFromBuff(buff, offset + 2, 1),
intFromBuff(buff, offset + 3, 1),
intFromBuff(buff, offset + 4, 1),
0
).millis
}
@Synchronized fun dateTimeSecFromBuff(buff: ByteArray, offset: Int): Long {
return try {
DateTime(
2000 + intFromBuff(buff, offset, 1),
intFromBuff(buff, offset + 1, 1),
intFromBuff(buff, offset + 2, 1),
intFromBuff(buff, offset + 3, 1),
intFromBuff(buff, offset + 4, 1),
intFromBuff(buff, offset + 5, 1)
).millis
} catch (e: IllegalInstantException) {
// expect
// org.joda.time.IllegalInstantException: Illegal instant due to time zone offset transition (daylight savings time 'gap')
// add 1 hour
DateTime(
2000 + intFromBuff(buff, offset, 1),
intFromBuff(buff, offset + 1, 1),
intFromBuff(buff, offset + 2, 1),
intFromBuff(buff, offset + 3, 1) + 1,
intFromBuff(buff, offset + 4, 1),
intFromBuff(buff, offset + 5, 1)
).millis
}
}
fun dateFromBuff(buff: ByteArray, offset: Int): Long {
return DateTime(
2000 + intFromBuff(buff, offset, 1),
intFromBuff(buff, offset + 1, 1),
intFromBuff(buff, offset + 2, 1),
0,
0
).millis
}
companion object {
fun stringFromBuff(buff: ByteArray, offset: Int, length: Int): String {
val strBuff = ByteArray(length)
System.arraycopy(buff, offset + 6, strBuff, 0, length)
return String(strBuff, StandardCharsets.UTF_8)
}
fun asciiStringFromBuff(buff: ByteArray, offset: Int, length: Int): String {
val strBuff = ByteArray(length)
System.arraycopy(buff, offset + 6, strBuff, 0, length)
for (pos in 0 until length) strBuff[pos] = (strBuff[pos] + 65).toByte() // "A"
return String(strBuff, StandardCharsets.UTF_8)
}
fun toHexString(buff: ByteArray): String {
val sb = StringBuilder()
for ((count, element) in buff.withIndex()) {
sb.append(String.format("%02x ", element))
if ((count + 1) % 4 == 0) sb.append(" ")
}
return sb.toString()
}
}
init {
@Suppress("LeakingThis")
injector.androidInjector().inject(this)
this.injector = injector
}
}

View file

@ -11,7 +11,7 @@ class MsgBolusProgress(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0202) setCommand(0x0202)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -10,10 +10,10 @@ class MsgBolusStart(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0102) setCommand(0x0102)
// HARDCODED LIMIT // HARDCODED LIMIT
amount = constraintChecker.applyBolusConstraints(Constraint(amount)).value() amount = constraintChecker.applyBolusConstraints(Constraint(amount)).value()
AddParamInt((amount * 100).toInt()) addParamInt((amount * 100).toInt())
aapsLogger.debug(LTag.PUMPBTCOMM, "Bolus start : $amount") aapsLogger.debug(LTag.PUMPBTCOMM, "Bolus start : $amount")
} }

View file

@ -11,11 +11,11 @@ class MsgBolusStartWithSpeed(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0104) setCommand(0x0104)
// HARDCODED LIMIT // HARDCODED LIMIT
amount = constraintChecker.applyBolusConstraints(Constraint(amount)).value() amount = constraintChecker.applyBolusConstraints(Constraint(amount)).value()
AddParamInt((amount * 100).toInt()) addParamInt((amount * 100).toInt())
AddParamByte(speed.toByte()) addParamByte(speed.toByte())
aapsLogger.debug(LTag.PUMPBTCOMM, "Bolus start : $amount speed: $speed") aapsLogger.debug(LTag.PUMPBTCOMM, "Bolus start : $amount speed: $speed")
} }

View file

@ -10,7 +10,7 @@ class MsgBolusStop(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0101) setCommand(0x0101)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -9,7 +9,7 @@ class MsgCheckValue(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0xF0F1) setCommand(0xF0F1)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -10,7 +10,7 @@ class MsgError(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0601) setCommand(0x0601)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -8,7 +8,7 @@ class MsgHistoryAlarm(
) : MsgHistoryAll(injector) { ) : MsgHistoryAll(injector) {
init { init {
SetCommand(0x3105) setCommand(0x3105)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }
// Handle message taken from MsgHistoryAll // Handle message taken from MsgHistoryAll

View file

@ -12,7 +12,7 @@ open class MsgHistoryAll(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x41F2) setCommand(0x41F2)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -8,7 +8,7 @@ class MsgHistoryAllDone(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x41F1) setCommand(0x41F1)
danaPump.historyDoneReceived = false danaPump.historyDoneReceived = false
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -8,7 +8,7 @@ class MsgHistoryBasalHour(
) : MsgHistoryAll(injector) { ) : MsgHistoryAll(injector) {
init { init {
SetCommand(0x310A) setCommand(0x310A)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }
// Handle message taken from MsgHistoryAll // Handle message taken from MsgHistoryAll

View file

@ -8,7 +8,7 @@ class MsgHistoryBolus(
) : MsgHistoryAll(injector) { ) : MsgHistoryAll(injector) {
init { init {
SetCommand(0x3101) setCommand(0x3101)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }
// Handle message taken from MsgHistoryAll // Handle message taken from MsgHistoryAll

View file

@ -8,7 +8,7 @@ class MsgHistoryCarbo(
) : MsgHistoryAll(injector) { ) : MsgHistoryAll(injector) {
init { init {
SetCommand(0x3107) setCommand(0x3107)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }
// Handle message taken from MsgHistoryAll // Handle message taken from MsgHistoryAll

View file

@ -8,7 +8,7 @@ class MsgHistoryDailyInsulin(
) : MsgHistoryAll(injector) { ) : MsgHistoryAll(injector) {
init { init {
SetCommand(0x3102) setCommand(0x3102)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }
// Handle message taken from MsgHistoryAll // Handle message taken from MsgHistoryAll

View file

@ -8,7 +8,7 @@ class MsgHistoryDone(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x31F1) setCommand(0x31F1)
danaPump.historyDoneReceived = false danaPump.historyDoneReceived = false
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -8,7 +8,7 @@ class MsgHistoryError(
) : MsgHistoryAll(injector) { ) : MsgHistoryAll(injector) {
init { init {
SetCommand(0x3106) setCommand(0x3106)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }
// Handle message taken from MsgHistoryAll // Handle message taken from MsgHistoryAll

View file

@ -8,7 +8,7 @@ class MsgHistoryGlucose(
) : MsgHistoryAll(injector) { ) : MsgHistoryAll(injector) {
init { init {
SetCommand(0x3104) setCommand(0x3104)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }
// Handle message taken from MsgHistoryAll // Handle message taken from MsgHistoryAll

View file

@ -8,7 +8,7 @@ class MsgHistoryNew(
) : MsgHistoryAll(injector) { ) : MsgHistoryAll(injector) {
init { init {
SetCommand(0x42F2) setCommand(0x42F2)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }
// Handle message taken from MsgHistoryAll // Handle message taken from MsgHistoryAll

View file

@ -8,7 +8,7 @@ class MsgHistoryNewDone(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x42F1) setCommand(0x42F1)
danaPump.historyDoneReceived = false danaPump.historyDoneReceived = false
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -8,7 +8,7 @@ class MsgHistoryRefill(
) : MsgHistoryAll(injector) { ) : MsgHistoryAll(injector) {
init { init {
SetCommand(0x3108) setCommand(0x3108)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }
// Handle message taken from MsgHistoryAll // Handle message taken from MsgHistoryAll

View file

@ -8,7 +8,7 @@ class MsgHistorySuspend(
) : MsgHistoryAll(injector) { ) : MsgHistoryAll(injector) {
init { init {
SetCommand(0x3109) setCommand(0x3109)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }
// Handle message taken from MsgHistoryAll // Handle message taken from MsgHistoryAll

View file

@ -8,7 +8,7 @@ class MsgInitConnStatusBasic(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0303) setCommand(0x0303)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -12,7 +12,7 @@ class MsgInitConnStatusBolus(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0302) setCommand(0x0302)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -12,7 +12,7 @@ class MsgInitConnStatusOption(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0304) setCommand(0x0304)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -13,7 +13,7 @@ class MsgInitConnStatusTime(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0301) setCommand(0x0301)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -8,7 +8,7 @@ class MsgPCCommStart constructor(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x3001) setCommand(0x3001)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -8,7 +8,7 @@ class MsgPCCommStop(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x3002) setCommand(0x3002)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -10,8 +10,8 @@ class MsgSetActivateBasalProfile(
// index 0-3 // index 0-3
init { init {
SetCommand(0x330C) setCommand(0x330C)
AddParamByte(index) addParamByte(index)
aapsLogger.debug(LTag.PUMPCOMM, "Activate basal profile: $index") aapsLogger.debug(LTag.PUMPCOMM, "Activate basal profile: $index")
} }

View file

@ -14,10 +14,10 @@ class MsgSetBasalProfile(
// index 0-3 // index 0-3
init { init {
SetCommand(0x3306) setCommand(0x3306)
AddParamByte(index) addParamByte(index)
for (i in 0..23) { for (i in 0..23) {
AddParamInt((values[i] * 100).toInt()) addParamInt((values[i] * 100).toInt())
} }
aapsLogger.debug(LTag.PUMPCOMM, "Set basal profile: $index") aapsLogger.debug(LTag.PUMPCOMM, "Set basal profile: $index")
} }

View file

@ -11,19 +11,19 @@ class MsgSetCarbsEntry(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0402) setCommand(0x0402)
aapsLogger.debug(LTag.PUMPBTCOMM, "New message") aapsLogger.debug(LTag.PUMPBTCOMM, "New message")
val calendar = Calendar.getInstance() val calendar = Calendar.getInstance()
calendar.timeInMillis = time calendar.timeInMillis = time
AddParamByte(info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_CARBO) addParamByte(info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_CARBO)
AddParamByte((calendar[Calendar.YEAR] % 100).toByte()) addParamByte((calendar[Calendar.YEAR] % 100).toByte())
AddParamByte((calendar[Calendar.MONTH] + 1).toByte()) addParamByte((calendar[Calendar.MONTH] + 1).toByte())
AddParamByte(calendar[Calendar.DAY_OF_MONTH].toByte()) addParamByte(calendar[Calendar.DAY_OF_MONTH].toByte())
AddParamByte(calendar[Calendar.HOUR_OF_DAY].toByte()) addParamByte(calendar[Calendar.HOUR_OF_DAY].toByte())
AddParamByte(calendar[Calendar.MINUTE].toByte()) addParamByte(calendar[Calendar.MINUTE].toByte())
AddParamByte(calendar[Calendar.SECOND].toByte()) addParamByte(calendar[Calendar.SECOND].toByte())
AddParamByte(0x43.toByte()) //?? addParamByte(0x43.toByte()) //??
AddParamInt(amount) addParamInt(amount)
aapsLogger.debug(LTag.PUMPBTCOMM, "Set carb entry: " + amount + " date " + calendar.time.toString()) aapsLogger.debug(LTag.PUMPBTCOMM, "Set carb entry: " + amount + " date " + calendar.time.toString())
} }

View file

@ -12,14 +12,14 @@ class MsgSetExtendedBolusStart(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0407) setCommand(0x0407)
aapsLogger.debug(LTag.PUMPBTCOMM, "New message") aapsLogger.debug(LTag.PUMPBTCOMM, "New message")
// HARDCODED LIMITS // HARDCODED LIMITS
if (halfhours < 1) halfhours = 1 if (halfhours < 1) halfhours = 1
if (halfhours > 16) halfhours = 16 if (halfhours > 16) halfhours = 16
amount = constraintChecker.applyBolusConstraints(Constraint(amount)).value() amount = constraintChecker.applyBolusConstraints(Constraint(amount)).value()
AddParamInt((amount * 100).toInt()) addParamInt((amount * 100).toInt())
AddParamByte(halfhours) addParamByte(halfhours)
aapsLogger.debug(LTag.PUMPBTCOMM, "Set extended bolus start: " + (amount * 100).toInt() / 100.0 + "U halfhours: " + halfhours.toInt()) aapsLogger.debug(LTag.PUMPBTCOMM, "Set extended bolus start: " + (amount * 100).toInt() / 100.0 + "U halfhours: " + halfhours.toInt())
} }

View file

@ -8,7 +8,7 @@ class MsgSetExtendedBolusStop(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0406) setCommand(0x0406)
aapsLogger.debug(LTag.PUMPBTCOMM, "New message") aapsLogger.debug(LTag.PUMPBTCOMM, "New message")
} }

View file

@ -13,9 +13,9 @@ class MsgSetSingleBasalProfile(
// index 0-3 // index 0-3
init { init {
SetCommand(0x3302) setCommand(0x3302)
for (i in 0..23) { for (i in 0..23) {
AddParamInt((values[i] * 100).toInt()) addParamInt((values[i] * 100).toInt())
} }
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -10,15 +10,15 @@ class MsgSetTempBasalStart(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0401) setCommand(0x0401)
//HARDCODED LIMITS //HARDCODED LIMITS
if (percent < 0) percent = 0 if (percent < 0) percent = 0
if (percent > 200) percent = 200 if (percent > 200) percent = 200
if (durationInHours < 1) durationInHours = 1 if (durationInHours < 1) durationInHours = 1
if (durationInHours > 24) durationInHours = 24 if (durationInHours > 24) durationInHours = 24
AddParamByte((percent and 255).toByte()) addParamByte((percent and 255).toByte())
AddParamByte((durationInHours and 255).toByte()) addParamByte((durationInHours and 255).toByte())
aapsLogger.debug(LTag.PUMPCOMM, "Temp basal start percent: $percent duration hours: $durationInHours") aapsLogger.debug(LTag.PUMPCOMM, "Temp basal start percent: $percent duration hours: $durationInHours")
} }

View file

@ -8,7 +8,7 @@ class MsgSetTempBasalStop(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0403) setCommand(0x0403)
aapsLogger.debug(LTag.PUMPBTCOMM, "Temp basal stop") aapsLogger.debug(LTag.PUMPBTCOMM, "Temp basal stop")
} }

View file

@ -9,8 +9,8 @@ class MsgSetTime(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x330a) setCommand(0x330a)
AddParamDateTimeReversed(time) addParamDateTimeReversed(time)
aapsLogger.debug(LTag.PUMPCOMM, "New message: time:" + dateUtil.dateAndTimeString(time)) aapsLogger.debug(LTag.PUMPCOMM, "New message: time:" + dateUtil.dateAndTimeString(time))
} }

View file

@ -8,7 +8,7 @@ class MsgSetUserOptions(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x330B) setCommand(0x330B)
if (danaPump.userOptionsFromPump == null) { if (danaPump.userOptionsFromPump == null) {
// No options set -> Exiting // No options set -> Exiting
aapsLogger.debug(LTag.PUMPCOMM, "NO USER OPTIONS LOADED EXITING!") aapsLogger.debug(LTag.PUMPCOMM, "NO USER OPTIONS LOADED EXITING!")
@ -23,7 +23,7 @@ class MsgSetUserOptions(
danaPump.userOptionsFromPump!![9] = danaPump.shutdownHour.toByte() danaPump.userOptionsFromPump!![9] = danaPump.shutdownHour.toByte()
danaPump.userOptionsFromPump!![27] = danaPump.lowReservoirRate.toByte() danaPump.userOptionsFromPump!![27] = danaPump.lowReservoirRate.toByte()
for (element in danaPump.userOptionsFromPump!!) { for (element in danaPump.userOptionsFromPump!!) {
AddParamByte(element) addParamByte(element)
} }
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -8,7 +8,7 @@ class MsgSettingActiveProfile(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x320C) setCommand(0x320C)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -9,7 +9,7 @@ class MsgSettingBasal(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x3202) setCommand(0x3202)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -57,7 +57,7 @@ class MsgSettingBasalProfileAll(
} }
init { init {
SetCommand(0x3206) setCommand(0x3206)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }
} }

View file

@ -12,7 +12,7 @@ class MsgSettingGlucose(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x3209) setCommand(0x3209)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -8,7 +8,7 @@ class MsgSettingMaxValues(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x3205) setCommand(0x3205)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -12,7 +12,7 @@ class MsgSettingMeal(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x3203) setCommand(0x3203)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -9,7 +9,7 @@ class MsgSettingProfileRatios(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x3204) setCommand(0x3204)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -9,7 +9,7 @@ class MsgSettingProfileRatiosAll(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x320D) setCommand(0x320D)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -10,7 +10,7 @@ class MsgSettingPumpTime(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x320A) setCommand(0x320A)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -8,7 +8,7 @@ class MsgSettingShippingInfo(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x3207) setCommand(0x3207)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -9,7 +9,7 @@ class MsgSettingUserOptions(
init { init {
SetCommand(0x320B) setCommand(0x320B)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -8,7 +8,7 @@ class MsgStatus(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x020B) setCommand(0x020B)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -8,7 +8,7 @@ class MsgStatusBasic(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x020A) setCommand(0x020A)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -11,7 +11,7 @@ class MsgStatusBolusExtended(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0207) setCommand(0x0207)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -9,7 +9,7 @@ class MsgStatusProfile(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0204) setCommand(0x0204)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -11,7 +11,7 @@ class MsgStatusTempBasal(
) : MessageBase(injector) { ) : MessageBase(injector) {
init { init {
SetCommand(0x0205) setCommand(0x0205)
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.danar.services; package info.nightscout.androidaps.danar.services;
import android.annotation.SuppressLint;
import android.os.Binder; import android.os.Binder;
import android.os.SystemClock; import android.os.SystemClock;
@ -93,7 +94,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
} }
} }
public void connect() { @SuppressLint("MissingPermission") public void connect() {
if (mConnectionInProgress) if (mConnectionInProgress)
return; return;
@ -139,7 +140,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
if (danaPump.isNewPump()) { if (danaPump.isNewPump()) {
mSerialIOThread.sendMessage(checkValue); mSerialIOThread.sendMessage(checkValue);
if (!checkValue.received) { if (!checkValue.isReceived()) {
return; return;
} }
} }
@ -292,7 +293,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
t.insulin = 0d; t.insulin = 0d;
return false; return false;
} }
while (!danaPump.getBolusStopped() && !start.failed) { while (!danaPump.getBolusStopped() && !start.getFailed()) {
SystemClock.sleep(100); SystemClock.sleep(100);
if ((System.currentTimeMillis() - danaPump.getBolusProgressLastTimeStamp()) > 15 * 1000L) { // if i didn't receive status for more than 15 sec expecting broken comm if ((System.currentTimeMillis() - danaPump.getBolusProgressLastTimeStamp()) > 15 * 1000L) { // if i didn't receive status for more than 15 sec expecting broken comm
danaPump.setBolusStopped(true); danaPump.setBolusStopped(true);
@ -359,7 +360,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
commandQueue.readStatus(rh.gs(R.string.bolus_ok), null); commandQueue.readStatus(rh.gs(R.string.bolus_ok), null);
} }
} }
return !start.failed; return !start.getFailed();
} }
public boolean carbsEntry(int amount) { public boolean carbsEntry(int amount) {
@ -400,6 +401,6 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
MsgSetUserOptions msg = new MsgSetUserOptions(injector); MsgSetUserOptions msg = new MsgSetUserOptions(injector);
mSerialIOThread.sendMessage(msg); mSerialIOThread.sendMessage(msg);
SystemClock.sleep(200); SystemClock.sleep(200);
return new PumpEnactResult(injector).success(!msg.failed); return new PumpEnactResult(injector).success(!msg.getFailed());
} }
} }

View file

@ -20,7 +20,7 @@ class MessageHashTableRv2Test : DanaRTestBase() {
Assert.assertEquals(0xE001, testPacket.command.toLong()) Assert.assertEquals(0xE001, testPacket.command.toLong())
// try putting another command // try putting another command
val testMessage = MessageBase(injector) val testMessage = MessageBase(injector)
testMessage.SetCommand(0xE005) testMessage.setCommand(0xE005)
messageHashTableRv2.put(testMessage) messageHashTableRv2.put(testMessage)
Assert.assertEquals(0xE005, messageHashTableRv2.findMessage(0xE005).command.toLong()) Assert.assertEquals(0xE005, messageHashTableRv2.findMessage(0xE005).command.toLong())
} }