store pairing key per pump

This commit is contained in:
Milos Kozak 2017-10-02 22:21:11 +02:00
parent 8bbee37b70
commit 97f69c50fd
6 changed files with 142 additions and 112 deletions

View file

@ -51,6 +51,7 @@ public class Notification {
public static final int TOAST_ALARM = 22; public static final int TOAST_ALARM = 22;
public static final int WRONGBASALSTEP = 23; public static final int WRONGBASALSTEP = 23;
public static final int BOLUS_DELIVERY_ERROR = 24; public static final int BOLUS_DELIVERY_ERROR = 24;
public static final int UNSUPPORTED_FIRMWARE = 25;
public int id; public int id;

View file

@ -232,7 +232,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
} }
pumpDescription.basalStep = pump.basalStep; pumpDescription.basalStep = pump.basalStep;
pumpDescription.bolusStep = pump.bolusStep; pumpDescription.bolusStep = pump.bolusStep;
log.debug("RS connected"); log.debug("RS connected:" + from);
} }
} }

View file

@ -3,11 +3,11 @@ package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.os.Build; import android.os.Build;
import com.cozmo.danar.util.BleCommandUtil;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
import com.cozmo.danar.util.BleCommandUtil;
public class DanaRS_Packet { public class DanaRS_Packet {
protected static final int TYPE_START = 0; protected static final int TYPE_START = 0;
protected static final int OPCODE_START = 1; protected static final int OPCODE_START = 1;
@ -43,7 +43,9 @@ public class DanaRS_Packet {
public byte[] getRequestParams() { public byte[] getRequestParams() {
return null; return null;
}; }
;
// STATIC FUNCTIONS // STATIC FUNCTIONS
@ -114,6 +116,7 @@ public class DanaRS_Packet {
} }
@TargetApi(Build.VERSION_CODES.KITKAT) @TargetApi(Build.VERSION_CODES.KITKAT)
public static String asciiStringFromBuff(byte[] buff, int offset, int length) { public static String asciiStringFromBuff(byte[] buff, int offset, int length) {
byte[] strbuff = new byte[length]; byte[] strbuff = new byte[length];
System.arraycopy(buff, offset, strbuff, 0, length); System.arraycopy(buff, offset, strbuff, 0, length);
@ -137,6 +140,18 @@ public class DanaRS_Packet {
return sb.toString(); return sb.toString();
} }
final private static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
int v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
return new String(hexChars);
}
public static byte[] hexToBytes(String s) { public static byte[] hexToBytes(String s) {
int len = s.length(); int len = s.length();
byte[] data = new byte[len / 2]; byte[] data = new byte[len / 2];

View file

@ -1,10 +1,16 @@
package info.nightscout.androidaps.plugins.PumpDanaRS.comm; package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import com.cozmo.danar.util.BleCommandUtil; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
public class DanaRS_Packet_General_Get_Pump_Check extends DanaRS_Packet { public class DanaRS_Packet_General_Get_Pump_Check extends DanaRS_Packet {
@ -36,6 +42,12 @@ public class DanaRS_Packet_General_Get_Pump_Check extends DanaRS_Packet {
log.debug("Protocol: " + String.format("%02X ", pump.protocol)); log.debug("Protocol: " + String.format("%02X ", pump.protocol));
log.debug("Product Code: " + String.format("%02X ", pump.productCode)); log.debug("Product Code: " + String.format("%02X ", pump.productCode));
} }
if (pump.protocol == 1) {
Notification notification = new Notification(Notification.UNSUPPORTED_FIRMWARE, MainApp.sResources.getString(R.string.unsupportedpumpfirmware), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
} else {
MainApp.bus().post(new EventDismissNotification(Notification.UNSUPPORTED_FIRMWARE));
}
} }
@Override @Override

View file

@ -31,6 +31,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRS.activities.PairingHelperActivity; import info.nightscout.androidaps.plugins.PumpDanaRS.activities.PairingHelperActivity;
import info.nightscout.androidaps.plugins.PumpDanaRS.activities.PairingProgressDialog; import info.nightscout.androidaps.plugins.PumpDanaRS.activities.PairingProgressDialog;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRSMessageHashTable; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRSMessageHashTable;
@ -457,7 +458,7 @@ public class BLEComm {
if (inputBuffer.length == 4 && inputBuffer[2] == 'O' && inputBuffer[3] == 'K') { if (inputBuffer.length == 4 && inputBuffer[2] == 'O' && inputBuffer[3] == 'K') {
log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (OK)" + " " + DanaRS_Packet.toHexString(inputBuffer)); log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (OK)" + " " + DanaRS_Packet.toHexString(inputBuffer));
// Grab pairing key from preferences if exists // Grab pairing key from preferences if exists
String pairingKey = SP.getString(R.string.key_danars_pairingkey, null); String pairingKey = SP.getString(MainApp.sResources.getString(R.string.key_danars_pairingkey) + DanaRSPlugin.mDeviceName, null);
log.debug("Using stored pairing key: " + pairingKey); log.debug("Using stored pairing key: " + pairingKey);
if (pairingKey != null) { if (pairingKey != null) {
byte[] encodedPairingKey = DanaRS_Packet.hexToBytes(pairingKey); byte[] encodedPairingKey = DanaRS_Packet.hexToBytes(pairingKey);
@ -504,8 +505,8 @@ public class BLEComm {
SendTimeInfo(); SendTimeInfo();
byte[] pairingKey = {inputBuffer[2], inputBuffer[3]}; byte[] pairingKey = {inputBuffer[2], inputBuffer[3]};
// store pairing key to preferences // store pairing key to preferences
SP.putString(R.string.key_danars_pairingkey, DanaRS_Packet.toHexString(pairingKey)); SP.putString(MainApp.sResources.getString(R.string.key_danars_pairingkey) + DanaRSPlugin.mDeviceName, DanaRS_Packet.bytesToHex(pairingKey));
log.debug("Got pairing key: " + DanaRS_Packet.toHexString(pairingKey)); log.debug("Got pairing key: " + DanaRS_Packet.bytesToHex(pairingKey));
break; break;
// time and user password information. last packet in handshake // time and user password information. last packet in handshake
case (byte) BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION: case (byte) BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION:

View file

@ -706,7 +706,7 @@
<string name="pairingok">Paring OK</string> <string name="pairingok">Paring OK</string>
<string name="pairingtimedout">Paring timed out</string> <string name="pairingtimedout">Paring timed out</string>
<string name="pairing">PAIRING</string> <string name="pairing">PAIRING</string>
<string name="key_danars_pairingkey" translatable="false">danars_paring_key</string> <string name="key_danars_pairingkey" translatable="false">danars_paring_key_</string>
<string name="key_danars_address" translatable="false">danars_address</string> <string name="key_danars_address" translatable="false">danars_address</string>
<string name="key_danars_name" translatable="false">danars_name</string> <string name="key_danars_name" translatable="false">danars_name</string>
<string name="danars_nodeviceavailable">No Device Available</string> <string name="danars_nodeviceavailable">No Device Available</string>
@ -732,5 +732,6 @@
<string name="gettingtempbasalstatus">Getting temporary basal status</string> <string name="gettingtempbasalstatus">Getting temporary basal status</string>
<string name="gettingpumpsettings">Gettings pump settings</string> <string name="gettingpumpsettings">Gettings pump settings</string>
<string name="gettingpumptime">Getting pump time</string> <string name="gettingpumptime">Getting pump time</string>
<string name="unsupportedpumpfirmware">Unsupported pump firmware</string>
</resources> </resources>