store pairing key per pump
This commit is contained in:
parent
8bbee37b70
commit
97f69c50fd
6 changed files with 142 additions and 112 deletions
|
@ -51,6 +51,7 @@ public class Notification {
|
|||
public static final int TOAST_ALARM = 22;
|
||||
public static final int WRONGBASALSTEP = 23;
|
||||
public static final int BOLUS_DELIVERY_ERROR = 24;
|
||||
public static final int UNSUPPORTED_FIRMWARE = 25;
|
||||
|
||||
|
||||
public int id;
|
||||
|
|
|
@ -232,7 +232,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
|||
}
|
||||
pumpDescription.basalStep = pump.basalStep;
|
||||
pumpDescription.bolusStep = pump.bolusStep;
|
||||
log.debug("RS connected");
|
||||
log.debug("RS connected:" + from);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@ package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
|
|||
import android.annotation.TargetApi;
|
||||
import android.os.Build;
|
||||
|
||||
import com.cozmo.danar.util.BleCommandUtil;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
|
||||
import com.cozmo.danar.util.BleCommandUtil;
|
||||
|
||||
public class DanaRS_Packet {
|
||||
protected static final int TYPE_START = 0;
|
||||
protected static final int OPCODE_START = 1;
|
||||
|
@ -43,7 +43,9 @@ public class DanaRS_Packet {
|
|||
|
||||
public byte[] getRequestParams() {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
// STATIC FUNCTIONS
|
||||
|
||||
|
@ -114,6 +116,7 @@ public class DanaRS_Packet {
|
|||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
|
||||
public static String asciiStringFromBuff(byte[] buff, int offset, int length) {
|
||||
byte[] strbuff = new byte[length];
|
||||
System.arraycopy(buff, offset, strbuff, 0, length);
|
||||
|
@ -137,6 +140,18 @@ public class DanaRS_Packet {
|
|||
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) {
|
||||
int len = s.length();
|
||||
byte[] data = new byte[len / 2];
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
|
||||
|
||||
import com.cozmo.danar.util.BleCommandUtil;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
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;
|
||||
|
||||
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("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
|
||||
|
|
|
@ -31,6 +31,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
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.PairingProgressDialog;
|
||||
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') {
|
||||
log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (OK)" + " " + DanaRS_Packet.toHexString(inputBuffer));
|
||||
// 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);
|
||||
if (pairingKey != null) {
|
||||
byte[] encodedPairingKey = DanaRS_Packet.hexToBytes(pairingKey);
|
||||
|
@ -504,8 +505,8 @@ public class BLEComm {
|
|||
SendTimeInfo();
|
||||
byte[] pairingKey = {inputBuffer[2], inputBuffer[3]};
|
||||
// store pairing key to preferences
|
||||
SP.putString(R.string.key_danars_pairingkey, DanaRS_Packet.toHexString(pairingKey));
|
||||
log.debug("Got pairing key: " + 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.bytesToHex(pairingKey));
|
||||
break;
|
||||
// time and user password information. last packet in handshake
|
||||
case (byte) BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION:
|
||||
|
|
|
@ -706,7 +706,7 @@
|
|||
<string name="pairingok">Paring OK</string>
|
||||
<string name="pairingtimedout">Paring timed out</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_name" translatable="false">danars_name</string>
|
||||
<string name="danars_nodeviceavailable">No Device Available</string>
|
||||
|
@ -732,5 +732,6 @@
|
|||
<string name="gettingtempbasalstatus">Getting temporary basal status</string>
|
||||
<string name="gettingpumpsettings">Gettings pump settings</string>
|
||||
<string name="gettingpumptime">Getting pump time</string>
|
||||
<string name="unsupportedpumpfirmware">Unsupported pump firmware</string>
|
||||
</resources>
|
||||
|
||||
|
|
Loading…
Reference in a new issue