medtronic-0.11.5-SNAPSHOT

- little more cleanup
- removed code that reads 1.5 days history on every start
This commit is contained in:
Andy Rozman 2019-06-26 13:26:03 +01:00
parent 32fad688fc
commit 570e93273c
19 changed files with 529 additions and 414 deletions

View file

@ -105,7 +105,7 @@ android {
multiDexEnabled true
versionCode 1500
// dev_version: 2.3.1-dev
version "medtronic-0.11.4-SNAPSHOT"
version "medtronic-0.11.5-SNAPSHOT"
buildConfigField "String", "VERSION", '"' + version + '"'
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'

View file

@ -156,7 +156,7 @@ public class MainApp extends Application {
File engineeringModeSemaphore = new File(extFilesDir, "engineering_mode");
engineeringMode = engineeringModeSemaphore.exists() && engineeringModeSemaphore.isFile();
devBranch = BuildConfig.VERSION.contains("dev");
devBranch = BuildConfig.VERSION.contains("dev") || BuildConfig.DEV_VERSION.contains("dev");
sBus = L.isEnabled(L.EVENTS) && devBranch ? new LoggingBus(ThreadEnforcer.ANY) : new Bus(ThreadEnforcer.ANY);
@ -271,11 +271,10 @@ public class MainApp extends Application {
private void setBTReceiver() {
// SP.putDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, null);
SP.remove(MedtronicConst.Statistics.LastPumpHistoryEntry); // FIXME remove
// SP.remove(MedtronicConst.Statistics.LastPumpHistoryEntry); // FIXME remove
// SP.putString(MedtronicConst.Prefs.PumpFrequency, "US (916 MHz)");
// RileyLink framework needs to know, when BT was reconnected, so that we can reconnect to RL device
// RileyLink framework needs to know, when BT was reconnected, so that we can reconnect to RL device,
// also detected if timezone/time/date changed and send notification to any active pump driver.
btReceiver = new BroadcastReceiver() {
@Override
@ -284,7 +283,7 @@ public class MainApp extends Application {
PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump();
if (action != null) {
if (action != null && activePump != null) {
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
switch (state) {
@ -294,7 +293,7 @@ public class MainApp extends Application {
break;
case BluetoothAdapter.STATE_ON: {
if (activePump != null && "Medtronic".equals(activePump.deviceID())) {
if ("Medtronic".equals(activePump.deviceID())) {
Log.v("MainApp", "Bluetooth on");
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.BluetoothReconnected);
}
@ -302,12 +301,10 @@ public class MainApp extends Application {
break;
}
} else {
if (activePump != null) {
activePump.timeDateOrTimeZoneChanged();
}
}
}
}
};
// Register for broadcasts on BluetoothAdapter state change

View file

@ -0,0 +1,398 @@
package info.nightscout.androidaps.plugins.pump.common.defs;
import java.util.HashMap;
import java.util.Map;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.common.data.DoseSettings;
import info.nightscout.androidaps.utils.Round;
/**
* Created by andy on 02/05/2018.
* <p>
* Most of this defintions is intended for VirtualPump only, but they can be used by other plugins.
*/
public enum PumpType {
GenericAAPS("Generic AAPS", 0.1d, null, //
new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Percent, //
new DoseSettings(10, 30, 24 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.01d, 0.01d, null, PumpCapability.VirtualPumpCapabilities), //
// Cellnovo
Cellnovo1("Cellnovo", 0.05d, null, //
new DoseSettings(0.05d, 30, 24 * 60, 1d, null),
PumpTempBasalType.Percent,
new DoseSettings(5, 30, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration30minAllowed, //
0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), //
// Accu-Chek
AccuChekCombo("Accu-Chek Combo", 0.1d, null, //
new DoseSettings(0.1d, 15, 12 * 60, 0.1d), //
PumpTempBasalType.Percent,
new DoseSettings(10, 15, 12 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.01d, 0.01d, DoseStepSize.ComboBasal, PumpCapability.ComboCapabilities), //
AccuChekSpirit("Accu-Chek Spirit", 0.1d, null, //
new DoseSettings(0.1d, 15, 12 * 60, 0.1d), //
PumpTempBasalType.Percent,
new DoseSettings(10, 15, 12 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.01d, 0.1d, null, PumpCapability.VirtualPumpCapabilities), //
AccuChekInsight("Accu-Chek Insight", 0.05d, DoseStepSize.InsightBolus, //
new DoseSettings(0.05d, 15, 24 * 60, 0.05d), //
PumpTempBasalType.Percent,
new DoseSettings(10, 15, 24 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.02d, 0.01d, null, PumpCapability.InsightCapabilities), //
AccuChekInsightBluetooth("Accu-Chek Insight", 0.01d, null, //
new DoseSettings(0.01d, 15, 24 * 60, 0.05d), //
PumpTempBasalType.Percent,
new DoseSettings(10, 15, 24 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.02d, 0.01d, DoseStepSize.InsightBolus, PumpCapability.InsightCapabilities), //
// Animas
AnimasVibe("Animas Vibe", 0.05d, null, // AnimasBolus?
new DoseSettings(0.05d, 30, 12 * 60, 0.05d), //
PumpTempBasalType.Percent, //
new DoseSettings(10, 30, 24 * 60, 0d, 300d), PumpCapability.BasalRate_Duration30minAllowed, //
0.025d, 5d, 0d, null, PumpCapability.VirtualPumpCapabilities), //
AnimasPing("Animas Ping", AnimasVibe),
// Dana
DanaR("DanaR", 0.05d, null, //
new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Percent, //
new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, //
0.04d, 0.01d, null, PumpCapability.DanaCapabilities),
DanaRKorean("DanaR Korean", 0.05d, null, //
new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Percent, //
new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, //
0.1d, 0.01d, null, PumpCapability.DanaCapabilities),
DanaRS("DanaRS", 0.05d, null, //
new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Percent, //
new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.04d, 0.01d, null, PumpCapability.DanaWithHistoryCapabilities),
DanaRv2("DanaRv2", DanaRS),
// Insulet
Insulet_Omnipod("Insulet Omnipod", 0.05d, null, //
new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05d, 30, 12 * 60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, // cannot exceed max basal rate 30u/hr
0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities),
// Medtronic
Medtronic_512_712("Medtronic 512/712", 0.05d, null, //
new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, //
<<<<<<< HEAD
new DoseSettings(0.05d, 30, 24*60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
0.05d, 0.05d, null, PumpCapability.MedtronicCapabilities), //
=======
new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), // TODO
>>>>>>> dev
Medtronic_515_715("Medtronic 515/715", Medtronic_512_712),
Medtronic_522_722("Medtronic 522/722", Medtronic_512_712),
Medtronic_523_723_Revel("Medtronic 523/723 (Revel)", 0.05d, null, //
new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, //
<<<<<<< HEAD
new DoseSettings(0.05d, 30, 24*60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.MedtronicCapabilities), //
=======
new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), //
>>>>>>> dev
Medtronic_554_754_Veo("Medtronic 554/754 (Veo)", Medtronic_523_723_Revel), // TODO
Medtronic_640G("Medtronic 640G", 0.025d, null, //
new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), //
// Tandem
TandemTSlim("Tandem t:slim", 0.01d, null, //
new DoseSettings(0.01d, 15, 8 * 60, 0.4d),
PumpTempBasalType.Percent,
new DoseSettings(1, 15, 8 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.1d, 0.001d, null, PumpCapability.VirtualPumpCapabilities),
TandemTFlex("Tandem t:flex", TandemTSlim), //
TandemTSlimG4("Tandem t:slim G4", TandemTSlim), //
TandemTSlimX2("Tandem t:slim X2", TandemTSlim), //
;
private String description;
private double bolusSize;
private DoseStepSize specialBolusSize;
private DoseSettings extendedBolusSettings;
private PumpTempBasalType pumpTempBasalType;
private DoseSettings tbrSettings;
private PumpCapability specialBasalDurations;
private double baseBasalMinValue; //
private Double baseBasalMaxValue;
private double baseBasalStep; //
private DoseStepSize baseBasalSpecialSteps; //
private PumpCapability pumpCapability;
private PumpType parent;
private static Map<String, PumpType> mapByDescription;
static {
mapByDescription = new HashMap<>();
for (PumpType pumpType : values()) {
mapByDescription.put(pumpType.getDescription(), pumpType);
}
}
PumpType(String description, PumpType parent) {
this.description = description;
this.parent = parent;
}
PumpType(String description, PumpType parent, PumpCapability pumpCapability) {
this.description = description;
this.parent = parent;
this.pumpCapability = pumpCapability;
}
PumpType(String description, double bolusSize, DoseStepSize specialBolusSize, //
DoseSettings extendedBolusSettings, //
PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, //
double baseBasalMinValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) {
this(description, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType, tbrSettings, specialBasalDurations, baseBasalMinValue, null, baseBasalStep, baseBasalSpecialSteps, pumpCapability);
}
PumpType(String description, double bolusSize, DoseStepSize specialBolusSize, //
DoseSettings extendedBolusSettings, //
PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, //
double baseBasalMinValue, Double baseBasalMaxValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) {
this.description = description;
this.bolusSize = bolusSize;
this.specialBolusSize = specialBolusSize;
this.extendedBolusSettings = extendedBolusSettings;
this.pumpTempBasalType = pumpTempBasalType;
this.tbrSettings = tbrSettings;
this.specialBasalDurations = specialBasalDurations;
this.baseBasalMinValue = baseBasalMinValue;
this.baseBasalMaxValue = baseBasalMaxValue;
this.baseBasalStep = baseBasalStep;
this.baseBasalSpecialSteps = baseBasalSpecialSteps;
this.pumpCapability = pumpCapability;
}
public String getDescription() {
return description;
}
public PumpCapability getPumpCapability() {
if (isParentSet())
return this.pumpCapability == null ? parent.pumpCapability : pumpCapability;
else
return this.pumpCapability;
}
public double getBolusSize() {
return isParentSet() ? parent.bolusSize : bolusSize;
}
public DoseStepSize getSpecialBolusSize() {
return isParentSet() ? parent.specialBolusSize : specialBolusSize;
}
public DoseSettings getExtendedBolusSettings() {
return isParentSet() ? parent.extendedBolusSettings : extendedBolusSettings;
}
public PumpTempBasalType getPumpTempBasalType() {
return isParentSet() ? parent.pumpTempBasalType : pumpTempBasalType;
}
public DoseSettings getTbrSettings() {
return isParentSet() ? parent.tbrSettings : tbrSettings;
}
public double getBaseBasalMinValue() {
return isParentSet() ? parent.baseBasalMinValue : baseBasalMinValue;
}
public Double getBaseBasalMaxValue() {
return isParentSet() ? parent.baseBasalMaxValue : baseBasalMaxValue;
}
public double getBaseBasalStep() {
return isParentSet() ? parent.baseBasalStep : baseBasalStep;
}
public DoseStepSize getBaseBasalSpecialSteps() {
return isParentSet() ? parent.baseBasalSpecialSteps : baseBasalSpecialSteps;
}
public PumpType getParent() {
return parent;
}
private boolean isParentSet() {
return this.parent != null;
}
public static PumpType getByDescription(String desc) {
if (mapByDescription.containsKey(desc)) {
return mapByDescription.get(desc);
} else {
return PumpType.GenericAAPS;
}
}
public String getFullDescription(String i18nTemplate, boolean hasExtendedBasals) {
String unit = getPumpTempBasalType() == PumpTempBasalType.Percent ? "%" : "";
DoseSettings eb = getExtendedBolusSettings();
DoseSettings tbr = getTbrSettings();
String extendedNote = hasExtendedBasals ? MainApp.gs(R.string.virtualpump_pump_def_extended_note) : "";
return String.format(i18nTemplate, //
getStep("" + getBolusSize(), getSpecialBolusSize()), //
eb.getStep(), eb.getDurationStep(), eb.getMaxDuration() / 60, //
getStep(getBaseBasalRange(), getBaseBasalSpecialSteps()), //
tbr.getMinDose() + unit + "-" + tbr.getMaxDose() + unit, tbr.getStep() + unit,
tbr.getDurationStep(), tbr.getMaxDuration() / 60, extendedNote);
}
private String getBaseBasalRange() {
Double maxValue = getBaseBasalMaxValue();
return maxValue == null ? "" + getBaseBasalMinValue() : getBaseBasalMinValue() + "-" + maxValue;
}
private String getStep(String step, DoseStepSize stepSize) {
if (stepSize != null)
return step + " [" + stepSize.getDescription() + "] *";
else
return "" + step;
}
public boolean hasExtendedBasals() {
return ((getBaseBasalSpecialSteps() != null) || (getSpecialBolusSize() != null));
}
public PumpCapability getSpecialBasalDurations() {
if (isParentSet()) {
return parent.getSpecialBasalDurations();
} else {
return specialBasalDurations == null ? //
PumpCapability.BasalRate_Duration15and30minNotAllowed : specialBasalDurations;
}
}
public double determineCorrectBolusSize(double bolusAmount) {
if (bolusAmount == 0.0d) {
return bolusAmount;
}
double bolusStepSize = getBolusSize();
if (getSpecialBolusSize() != null) {
DoseStepSize specialBolusSize = getSpecialBolusSize();
bolusStepSize = specialBolusSize.getStepSizeForAmount(bolusAmount);
}
return Round.roundTo(bolusAmount, bolusStepSize);
}
public double determineCorrectBolusStepSize(double bolusAmount) {
DoseStepSize specialBolusSize = getSpecialBolusSize();
if (specialBolusSize != null)
return specialBolusSize.getStepSizeForAmount(bolusAmount);
return getBolusSize();
}
public double determineCorrectExtendedBolusSize(double bolusAmount) {
if (bolusAmount == 0.0d) {
return bolusAmount;
}
double bolusStepSize;
if (getExtendedBolusSettings() == null) { // this should be never null
return 0.0d;
}
DoseSettings extendedBolusSettings = getExtendedBolusSettings();
bolusStepSize = extendedBolusSettings.getStep();
if (bolusAmount > extendedBolusSettings.getMaxDose()) {
bolusAmount = extendedBolusSettings.getMaxDose();
}
return Round.roundTo(bolusAmount, bolusStepSize);
}
public double determineCorrectBasalSize(double basalAmount) {
if (basalAmount == 0.0d) {
return basalAmount;
}
double basalStepSize;
if (getBaseBasalSpecialSteps() == null) {
basalStepSize = getBaseBasalStep();
} else {
DoseStepSize specialBolusSize = getBaseBasalSpecialSteps();
basalStepSize = specialBolusSize.getStepSizeForAmount((double) basalAmount);
}
if (basalAmount > getTbrSettings().getMaxDose())
basalAmount = getTbrSettings().getMaxDose().doubleValue();
return Round.roundTo(basalAmount, basalStepSize);
}
}

View file

@ -28,7 +28,6 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.Rile
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkTargetFrequency;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.operations.BLECommOperationResult;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
@ -173,7 +172,7 @@ public class RFSpy {
// prepend length, and send it.
byte[] prepended = ByteUtil.concat(new byte[]{(byte) (bytes.length)}, bytes);
LOG.debug("writeToData (raw={})", HexDump.toHexStringDisplayable(prepended));
LOG.debug("writeToData (raw={})", ByteUtil.getHex(prepended));
BLECommOperationResult writeCheck = rileyLinkBle.writeCharacteristic_blocking(radioServiceUUID, radioDataUUID,
prepended);

View file

@ -1,13 +1,5 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Semaphore;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
@ -19,6 +11,14 @@ import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.os.SystemClock;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Semaphore;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
@ -30,7 +30,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.operation
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.operations.DescriptorWriteOperation;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil;
/**
@ -69,9 +69,9 @@ public class RileyLinkBLE {
if (gattDebugEnabled && isLogEnabled()) {
LOG.trace(ThreadUtil.sig() + "onCharacteristicChanged "
+ GattAttributes.lookup(characteristic.getUuid()) + " "
+ HexDump.toHexString(characteristic.getValue()));
+ ByteUtil.getHex(characteristic.getValue()));
if (characteristic.getUuid().equals(UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT))) {
LOG.debug("Response Count is " + HexDump.toHexString(characteristic.getValue()));
LOG.debug("Response Count is " + ByteUtil.getHex(characteristic.getValue()));
}
}
if (radioResponseCountNotified != null) {
@ -89,7 +89,7 @@ public class RileyLinkBLE {
if (gattDebugEnabled && isLogEnabled()) {
LOG.trace(ThreadUtil.sig() + "onCharacteristicRead ("
+ GattAttributes.lookup(characteristic.getUuid()) + ") " + statusMessage + ":"
+ HexDump.toHexString(characteristic.getValue()));
+ ByteUtil.getHex(characteristic.getValue()));
}
mCurrentOperation.gattOperationCompletionCallback(characteristic.getUuid(), characteristic.getValue());
}
@ -103,7 +103,7 @@ public class RileyLinkBLE {
final String uuidString = GattAttributes.lookup(characteristic.getUuid());
if (gattDebugEnabled && isLogEnabled()) {
LOG.trace(ThreadUtil.sig() + "onCharacteristicWrite " + getGattStatusMessage(status) + " "
+ uuidString + " " + HexDump.toHexString(characteristic.getValue()));
+ uuidString + " " + ByteUtil.getHex(characteristic.getValue()));
}
mCurrentOperation.gattOperationCompletionCallback(characteristic.getUuid(), characteristic.getValue());
}
@ -167,7 +167,7 @@ public class RileyLinkBLE {
super.onDescriptorWrite(gatt, descriptor, status);
if (gattDebugEnabled && isLogEnabled()) {
LOG.warn("onDescriptorWrite " + GattAttributes.lookup(descriptor.getUuid()) + " "
+ getGattStatusMessage(status) + " written: " + HexDump.toHexString(descriptor.getValue()));
+ getGattStatusMessage(status) + " written: " + ByteUtil.getHex(descriptor.getValue()));
}
mCurrentOperation.gattOperationCompletionCallback(descriptor.getUuid(), descriptor.getValue());
}

View file

@ -434,4 +434,5 @@ public class ByteUtil {
return outArray;
}
}

View file

@ -1,51 +0,0 @@
package info.nightscout.androidaps.plugins.pump.common.utils;
import java.util.Map;
import com.crashlytics.android.answers.AnswersEvent;
import com.crashlytics.android.answers.CustomEvent;
import com.google.common.base.Splitter;
import info.nightscout.androidaps.BuildConfig;
/**
* Created by andy on 10/26/18.
*/
public class FabricUtil {
public static void createEvent(String eventName, Map<String, String> map) {
CustomEvent customEvent = new CustomEvent("MedtronicDecode4b6bError") //
.putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) //
.putCustomAttribute("version", BuildConfig.VERSION);
int attributes = 2;
boolean interrupted = false;
if (map != null) {
for (Map.Entry<String, String> entry : map.entrySet()) {
int part = 1;
if (interrupted)
break;
for (final String token : Splitter.fixedLength(AnswersEvent.MAX_STRING_LENGTH).split(entry.getValue())) {
if (attributes == AnswersEvent.MAX_NUM_ATTRIBUTES) {
interrupted = true;
break;
}
customEvent.putCustomAttribute(entry.getKey() + "_" + part, token);
attributes++;
}
}
}
// FIXME andy!!!
// FabricPrivacy.getInstance().logCustom(customEvent);
}
}

View file

@ -1,232 +0,0 @@
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package info.nightscout.androidaps.plugins.pump.common.utils;
import java.util.List;
/**
* Clone of Android's HexDump class, for use in debugging. Cosmetic changes
* only.
*/
public class HexDump {
private final static char[] HEX_DIGITS = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
public static String dumpHexString(byte[] array) {
return dumpHexString(array, 0, array.length);
}
public static String dumpHexString(byte[] array, int offset, int length) {
StringBuilder result = new StringBuilder();
byte[] line = new byte[16];
int lineIndex = 0;
result.append("\n0x");
result.append(toHexString(offset));
for (int i = offset; i < offset + length; i++) {
if (lineIndex == 16) {
result.append(" ");
for (int j = 0; j < 16; j++) {
if (line[j] > ' ' && line[j] < '~') {
result.append(new String(line, j, 1));
} else {
result.append(".");
}
}
result.append("\n0x");
result.append(toHexString(i));
lineIndex = 0;
}
byte b = array[i];
result.append(" ");
result.append(HEX_DIGITS[(b >>> 4) & 0x0F]);
result.append(HEX_DIGITS[b & 0x0F]);
line[lineIndex++] = b;
}
if (lineIndex != 16) {
int count = (16 - lineIndex) * 3;
count++;
for (int i = 0; i < count; i++) {
result.append(" ");
}
for (int i = 0; i < lineIndex; i++) {
if (line[i] > ' ' && line[i] < '~') {
result.append(new String(line, i, 1));
} else {
result.append(".");
}
}
}
return result.toString();
}
public static String toHexString(byte b) {
return toHexString(toByteArray(b));
}
public static String toHexString(byte[] array) {
return toHexString(array, 0, array.length);
}
public static String toHexString(byte[] array, int offset, int length) {
char[] buf = new char[length * 2];
int bufIndex = 0;
for (int i = offset; i < offset + length; i++) {
byte b = array[i];
buf[bufIndex++] = HEX_DIGITS[(b >>> 4) & 0x0F];
buf[bufIndex++] = HEX_DIGITS[b & 0x0F];
}
return new String(buf);
}
public static String toHexStringDisplayable(byte[] arr) {
StringBuilder sb = new StringBuilder();
if (arr == null) {
sb.append("Null array");
} else {
if (arr.length == 0) {
sb.append("Zero-length array");
} else {
for (byte element : arr) {
sb.append(getCorrectHexValue(element));
sb.append(" ");
}
}
}
return sb.toString();
}
public static String toHexStringDisplayable(List<Byte> data) {
StringBuilder sb = new StringBuilder();
for (byte element : data) {
sb.append(getCorrectHexValue(element));
sb.append(" ");
}
return sb.toString();
}
public static String getCorrectHexValue(byte inp) {
String hx = Integer.toHexString((char)inp);
hx = hx.toUpperCase();
if (hx.length() == 0)
return "00";
else if (hx.length() == 1)
return "0" + hx;
else if (hx.length() == 2)
return hx;
else if (hx.length() == 4)
return hx.substring(2);
else {
System.out.println("HEX ERROR !!!!!!!!!!!!!!!!");
}
// System.out.print(Integer.toHexString((char)arr[i]) + " ");
return null;
}
public static String toHexString(int i) {
return toHexString(toByteArray(i));
}
public static String toHexString(short i) {
return toHexString(toByteArray(i));
}
public static byte[] toByteArray(byte b) {
byte[] array = new byte[1];
array[0] = b;
return array;
}
public static byte[] toByteArray(int i) {
byte[] array = new byte[4];
array[3] = (byte)(i & 0xFF);
array[2] = (byte)((i >> 8) & 0xFF);
array[1] = (byte)((i >> 16) & 0xFF);
array[0] = (byte)((i >> 24) & 0xFF);
return array;
}
public static byte[] toByteArray(short i) {
byte[] array = new byte[2];
array[1] = (byte)(i & 0xFF);
array[0] = (byte)((i >> 8) & 0xFF);
return array;
}
private static int toByte(char c) {
if (c >= '0' && c <= '9')
return (c - '0');
if (c >= 'A' && c <= 'F')
return (c - 'A' + 10);
if (c >= 'a' && c <= 'f')
return (c - 'a' + 10);
throw new RuntimeException("Invalid hex char '" + c + "'");
}
public static byte[] hexStringToByteArray(String hexString) {
int length = hexString.length();
byte[] buffer = new byte[length / 2];
for (int i = 0; i < length; i += 2) {
buffer[i / 2] = (byte)((toByte(hexString.charAt(i)) << 4) | toByte(hexString.charAt(i + 1)));
}
return buffer;
}
}

View file

@ -9,6 +9,7 @@ import java.util.List;
/**
* Created by geoff on 4/28/15.
* modified by Andy
*/
public class StringUtil {

View file

@ -26,7 +26,6 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RawHistoryPage;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry;
@ -51,7 +50,7 @@ import info.nightscout.androidaps.utils.SP;
/**
* Original file created by geoff on 5/30/16.
*
* <p>
* Split into 2 implementations, so that we can split it by target device. - Andy
* This was mostly rewritten from Original version, and lots of commands and
* functionality added.
@ -645,7 +644,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
if (contents != null) {
if (contents.length >= expectedLength) {
LOG.trace("{}: Content: {}", method, HexDump.toHexStringDisplayable(contents));
LOG.trace("{}: Content: {}", method, ByteUtil.getHex(contents));
return null;
} else {
@ -897,7 +896,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
if (debugSetCommands)
LOG.debug("{}: Body - {}", commandType.getCommandDescription(),
HexDump.toHexStringDisplayable(body));
ByteUtil.getHex(body));
PumpMessage msg = makePumpMessage(commandType, new CarelinkLongMessageBody(body));

View file

@ -10,7 +10,6 @@ import java.util.Map;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BatteryStatusDTO;
@ -42,7 +41,7 @@ public class MedtronicConverter {
}
if (isLogEnabled())
LOG.debug("Raw response before convert: " + HexDump.toHexStringDisplayable(rawContent));
LOG.debug("Raw response before convert: " + ByteUtil.getHex(rawContent));
this.pumpModel = MedtronicUtil.getMedtronicPumpModel();

View file

@ -11,13 +11,12 @@ import java.util.Map;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
/**
* This file was taken from GGC - GNU Gluco Control (ggc.sourceforge.net), application for diabetes
* management and modified/extended for AAPS.
*
* <p>
* Author: Andy {andy.rozman@gmail.com}
*/
@ -198,21 +197,21 @@ public abstract class MedtronicHistoryEntry implements MedtronicHistoryEntryInte
if (head != null) {
sb.append(", head=");
sb.append(HexDump.toHexStringDisplayable(this.head));
sb.append(ByteUtil.getHex(this.head));
}
if (datetime != null) {
sb.append(", datetime=");
sb.append(HexDump.toHexStringDisplayable(this.datetime));
sb.append(ByteUtil.getHex(this.datetime));
}
if (body != null) {
sb.append(", body=");
sb.append(HexDump.toHexStringDisplayable(this.body));
sb.append(ByteUtil.getHex(this.body));
}
sb.append(", rawData=");
sb.append(HexDump.toHexStringDisplayable(this.rawData));
sb.append(ByteUtil.getHex(this.rawData));
sb.append("]");
// sb.append(" DT: ");
@ -298,7 +297,7 @@ public abstract class MedtronicHistoryEntry implements MedtronicHistoryEntryInte
if (head == null) {
return "Unidentified record. ";
} else {
return "HistoryRecord: head=[" + HexDump.toHexStringDisplayable(this.head) + "]";
return "HistoryRecord: head=[" + ByteUtil.getHex(this.head) + "]";
}
}

View file

@ -12,7 +12,6 @@ import java.util.Locale;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.MedtronicHistoryDecoder;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RecordDecodeStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile;
@ -27,7 +26,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
/**
* This file was taken from GGC - GNU Gluco Control (ggc.sourceforge.net), application for diabetes
* management and modified/extended for AAPS.
*
* <p>
* Author: Andy {andy.rozman@gmail.com}
*/
@ -117,8 +116,8 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
listRawData.add(dataClear.get(counter));
counter++;
} catch (Exception ex) {
LOG.error("OpCode: " + HexDump.getCorrectHexValue((byte) opCode) + ", Invalid package: "
+ HexDump.toHexStringDisplayable(listRawData));
LOG.error("OpCode: " + ByteUtil.getHex((byte) opCode) + ", Invalid package: "
+ ByteUtil.getHex(listRawData));
// throw ex;
incompletePacket = true;
break;

View file

@ -7,14 +7,14 @@ import org.slf4j.LoggerFactory;
import java.util.Objects;
import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.MedtronicHistoryEntry;
/**
* This file was taken from GGC - GNU Gluco Control (ggc.sourceforge.net), application for diabetes
* management and modified/extended for AAPS.
*
* <p>
* Author: Andy {andy.rozman@gmail.com}
*/
@ -69,7 +69,7 @@ public class PumpHistoryEntry extends MedtronicHistoryEntry {
public String getToStringStart() {
return "PumpHistoryRecord [type=" + StringUtil.getStringInLength(entryType.name(), 20) + " ["
+ StringUtil.getStringInLength("" + getOpCode(), 3) + ", 0x"
+ HexDump.getCorrectHexValue((byte) getOpCode()) + "]";
+ ByteUtil.getHex((byte) getOpCode()) + "]";
}

View file

@ -1,6 +1,6 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm.message;
import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
/**
* Created by geoff on 5/29/16.
@ -25,7 +25,7 @@ public class MessageBody {
StringBuilder sb = new StringBuilder(getClass().getSimpleName());
sb.append(" [txData=");
sb.append(HexDump.toHexStringDisplayable(getTxData()));
sb.append(ByteUtil.getHex(getTxData()));
sb.append("]");
return sb.toString();

View file

@ -6,7 +6,6 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RLMessage;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
/**
@ -170,7 +169,7 @@ public class PumpMessage implements RLMessage {
if (showData) {
sb.append(", rawResponse=");
sb.append(HexDump.toHexStringDisplayable(getRawContent()));
sb.append(ByteUtil.getHex(getRawContent()));
}
sb.append("]");
@ -186,7 +185,7 @@ public class PumpMessage implements RLMessage {
sb.append(packetType == null ? "null" : packetType.name());
sb.append(", address=(");
sb.append(HexDump.toHexStringDisplayable(this.address));
sb.append(ByteUtil.getHex(this.address));
sb.append("), commandType=");
sb.append(commandType == null ? "null" : commandType.name());

View file

@ -52,7 +52,6 @@ import info.nightscout.androidaps.utils.SP;
/**
* Created by andy on 10/12/18.
*/
// TODO clean up this class (remove/comment logs)
public class MedtronicHistoryData {
private static final Logger LOG = LoggerFactory.getLogger(L.PUMP);
@ -248,6 +247,7 @@ public class MedtronicHistoryData {
this.sort(this.allHistory);
if (isLogEnabled())
LOG.debug("All History records [afterFilterCount={}, removedItemsCount={}, newItemsCount={}]",
allHistory.size(), removeList.size(), newHistory.size());
} else {
@ -273,14 +273,18 @@ public class MedtronicHistoryData {
return (col == null || col.isEmpty());
}
private boolean isCollectionNotEmpty(List col) {
return (col != null && !col.isEmpty());
}
public boolean isPumpSuspended() {
List<PumpHistoryEntry> items = getDataForSuspends(false);
List<PumpHistoryEntry> items = getDataForPumpSuspends();
showLogs("isPumpSuspended: ", MedtronicUtil.gsonInstance.toJson(items));
if (!isCollectionEmpty(items)) {
if (isCollectionNotEmpty(items)) {
PumpHistoryEntryType pumpHistoryEntryType = items.get(0).getEntryType();
@ -290,6 +294,7 @@ public class MedtronicHistoryData {
pumpHistoryEntryType == PumpHistoryEntryType.Resume || //
pumpHistoryEntryType == PumpHistoryEntryType.Prime);
if (isLogEnabled())
LOG.debug("isPumpSuspended. Last entry type={}, isSuspended={}", pumpHistoryEntryType, isSuspended);
return isSuspended;
@ -299,20 +304,15 @@ public class MedtronicHistoryData {
}
private List<PumpHistoryEntry> getDataForSuspends(boolean forHistory) {
private List<PumpHistoryEntry> getDataForPumpSuspends() {
List<PumpHistoryEntry> newAndAll = new ArrayList<>();
if (!isCollectionEmpty(this.allHistory)) {
if (forHistory) {
// TODO we filter all history ang get last 2
} else {
if (isCollectionNotEmpty(this.allHistory)) {
newAndAll.addAll(this.allHistory);
}
}
if (!isCollectionEmpty(this.newHistory)) {
if (isCollectionNotEmpty(this.newHistory)) {
for (PumpHistoryEntry pumpHistoryEntry : newHistory) {
if (!newAndAll.contains(pumpHistoryEntry)) {
@ -336,10 +336,7 @@ public class MedtronicHistoryData {
PumpHistoryEntryType.NoDeliveryAlarm, //
PumpHistoryEntryType.BasalProfileStart);
if (!forHistory) {
newAndAll2 = filterPumpSuspend(newAndAll2, 10); // just last 10 (of relevant), for history we already
// filtered
}
newAndAll2 = filterPumpSuspend(newAndAll2, 10);
return newAndAll2;
}
@ -369,10 +366,16 @@ public class MedtronicHistoryData {
// TDD
List<PumpHistoryEntry> tdds = getFilteredItems(PumpHistoryEntryType.EndResultTotals, getTDDType());
if (isLogEnabled())
LOG.debug("ProcessHistoryData: TDD [count={}, items={}]", tdds.size(), gson.toJson(tdds));
if (!isCollectionEmpty(tdds)) {
if (isCollectionNotEmpty(tdds)) {
try {
processTDDs(tdds);
} catch (Exception ex) {
LOG.error("ProcessHistoryData: Error processing TDD entries: " + ex.getMessage(), ex);
throw ex;
}
}
pumpTime = MedtronicUtil.getPumpTime();
@ -380,6 +383,7 @@ public class MedtronicHistoryData {
// Bolus
List<PumpHistoryEntry> treatments = getFilteredItems(PumpHistoryEntryType.Bolus);
if (isLogEnabled())
LOG.debug("ProcessHistoryData: Bolus [count={}, items={}]", treatments.size(), gson.toJson(treatments));
if (treatments.size() > 0) {
@ -387,12 +391,14 @@ public class MedtronicHistoryData {
processBolusEntries(treatments);
} catch (Exception ex) {
LOG.error("ProcessHistoryData: Error processing Bolus entries: " + ex.getMessage(), ex);
throw ex;
}
}
// TBR
List<PumpHistoryEntry> tbrs = getFilteredItems(PumpHistoryEntryType.TempBasalCombined);
if (isLogEnabled())
LOG.debug("ProcessHistoryData: TBRs Processed [count={}, items={}]", tbrs.size(), gson.toJson(tbrs));
if (tbrs.size() > 0) {
@ -400,6 +406,7 @@ public class MedtronicHistoryData {
processTBREntries(tbrs);
} catch (Exception ex) {
LOG.error("ProcessHistoryData: Error processing TBR entries: " + ex.getMessage(), ex);
throw ex;
}
}
@ -410,16 +417,19 @@ public class MedtronicHistoryData {
suspends = getSuspends();
} catch (Exception ex) {
LOG.error("ProcessHistoryData: Error getting Suspend entries: " + ex.getMessage(), ex);
throw ex;
}
if (isLogEnabled())
LOG.debug("ProcessHistoryData: 'Delivery Suspend' Processed [count={}, items={}]", suspends.size(),
gson.toJson(suspends));
if (suspends != null && suspends.size() > 0) {
if (isCollectionNotEmpty(suspends)) {
try {
processSuspends(suspends);
} catch (Exception ex) {
LOG.error("ProcessHistoryData: Error processing Suspends entries: " + ex.getMessage(), ex);
throw ex;
}
}
}
@ -543,6 +553,7 @@ public class MedtronicHistoryData {
List<? extends DbObjectBase> entriesFromHistory = getDatabaseEntries(dateDifference, ProcessHistoryRecord.TBR);
if (isLogEnabled())
LOG.debug(ProcessHistoryRecord.TBR.getDescription() + " List (before filter): {}, FromDb={}", gson.toJson(entryList),
gson.toJson(entriesFromHistory));
@ -579,11 +590,10 @@ public class MedtronicHistoryData {
if (processDTO != null) {
processList.add(processDTO);
processDTO = null;
}
if (!isCollectionEmpty(processList)) {
if (isCollectionNotEmpty(processList)) {
for (TempBasalProcessDTO tempBasalProcessDTO : processList) {

View file

@ -12,7 +12,6 @@ import java.util.List;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.FabricUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
/**
@ -286,7 +285,7 @@ public class BasalProfile {
LOG.error(" rawBasalValues: " + ByteUtil.getHex(this.getRawData()));
LOG.error("=============================================================================");
FabricUtil.createEvent("MedtronicBasalProfileGetByHourError", null);
//FabricUtil.createEvent("MedtronicBasalProfileGetByHourError", null);
}
if (entries == null || entries.size() == 0) {

View file

@ -5,16 +5,16 @@ import android.content.Intent;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.joda.time.LocalTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.joda.time.LocalTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
@ -26,9 +26,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.ClockDTO;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.PumpSettingDTO;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType;
@ -95,8 +93,8 @@ public class MedtronicUtil extends RileyLinkUtil {
public static byte[] getByteArrayFromUnsignedShort(int shortValue, boolean returnFixedSize) {
byte highByte = (byte)(shortValue >> 8 & 0xFF);
byte lowByte = (byte)(shortValue & 0xFF);
byte highByte = (byte) (shortValue >> 8 & 0xFF);
byte lowByte = (byte) (shortValue & 0xFF);
if (highByte > 0) {
return createByteArray(highByte, lowByte);
@ -130,7 +128,7 @@ public class MedtronicUtil extends RileyLinkUtil {
public static double decodeBasalInsulin(int i) {
return (double)i / 40.0d;
return (double) i / 40.0d;
}
@ -173,7 +171,7 @@ public class MedtronicUtil extends RileyLinkUtil {
scrollRate = 1;
}
int strokes = (int)(amount * ((strokesPerUnit * 1.0d) / (scrollRate * 1.0d))) * scrollRate;
int strokes = (int) (amount * ((strokesPerUnit * 1.0d) / (scrollRate * 1.0d))) * scrollRate;
byte[] body = ByteUtil.fromHexString(String.format("%02x%0" + (2 * length) + "x", length, strokes));
@ -183,7 +181,7 @@ public class MedtronicUtil extends RileyLinkUtil {
public static byte[] createCommandBody(byte[] input) {
return ByteUtil.concat((byte)input.length, input);
return ByteUtil.concat((byte) input.length, input);
}
@ -211,7 +209,7 @@ public class MedtronicUtil extends RileyLinkUtil {
scrollRate = 2;
}
int strokes = (int)(amount * (strokesPerUnit / (scrollRate * 1.0d)));
int strokes = (int) (amount * (strokesPerUnit / (scrollRate * 1.0d)));
strokes *= scrollRate;
@ -249,21 +247,21 @@ public class MedtronicUtil extends RileyLinkUtil {
public static byte[] buildCommandPayload(MedtronicCommandType commandType, byte[] parameters) {
return buildCommandPayload((byte)commandType.commandCode, parameters);
return buildCommandPayload((byte) commandType.commandCode, parameters);
}
public static byte[] buildCommandPayload(byte commandType, byte[] parameters) {
// A7 31 65 51 C0 00 52
byte commandLength = (byte)(parameters == null ? 2 : 2 + parameters.length);
byte commandLength = (byte) (parameters == null ? 2 : 2 + parameters.length);
ByteBuffer sendPayloadBuffer = ByteBuffer.allocate(ENVELOPE_SIZE + commandLength); // + CRC_SIZE
sendPayloadBuffer.order(ByteOrder.BIG_ENDIAN);
byte[] serialNumberBCD = RileyLinkUtil.getRileyLinkServiceData().pumpIDBytes;
sendPayloadBuffer.put((byte)0xA7);
sendPayloadBuffer.put((byte) 0xA7);
sendPayloadBuffer.put(serialNumberBCD[0]);
sendPayloadBuffer.put(serialNumberBCD[1]);
sendPayloadBuffer.put(serialNumberBCD[2]);
@ -271,9 +269,9 @@ public class MedtronicUtil extends RileyLinkUtil {
sendPayloadBuffer.put(commandType);
if (parameters == null) {
sendPayloadBuffer.put((byte)0x00);
sendPayloadBuffer.put((byte) 0x00);
} else {
sendPayloadBuffer.put((byte)parameters.length); // size
sendPayloadBuffer.put((byte) parameters.length); // size
for (byte val : parameters) {
sendPayloadBuffer.put(val);
@ -283,7 +281,7 @@ public class MedtronicUtil extends RileyLinkUtil {
byte[] payload = sendPayloadBuffer.array();
if (L.isEnabled(L.PUMPCOMM))
LOG.info(HexDump.toHexStringDisplayable(payload));
LOG.debug("buildCommandPayload [{}]", ByteUtil.getHex(payload));
// int crc = computeCRC8WithPolynomial(payload, 0, payload.length - 1);
@ -323,7 +321,7 @@ public class MedtronicUtil extends RileyLinkUtil {
List<Byte> frameData = ByteUtil.getListFromByteArray(substring);
if (isEmptyFrame(frameData)) {
byte b = (byte)frame;
byte b = (byte) frame;
// b |= 0x80;
b |= 0b1000_0000;
// b |= doneBit;
@ -336,7 +334,7 @@ public class MedtronicUtil extends RileyLinkUtil {
done = true;
} else {
frameData.add(0, (byte)frame);
frameData.add(0, (byte) frame);
}
// System.out.println("Subarray: " + ByteUtil.getCompactString(substring));
@ -355,7 +353,7 @@ public class MedtronicUtil extends RileyLinkUtil {
if (!lastFrame) {
List<Byte> frameData = new ArrayList<>();
byte b = (byte)frame;
byte b = (byte) frame;
b |= 0b1000_0000;
// b |= doneBit;
@ -377,7 +375,7 @@ public class MedtronicUtil extends RileyLinkUtil {
int missing = BIG_FRAME_LENGTH - frameData.size();
for (int i = 0; i < missing; i++) {
frameData.add((byte)0x00);
frameData.add((byte) 0x00);
}
}
@ -434,7 +432,7 @@ public class MedtronicUtil extends RileyLinkUtil {
public static MedtronicCommunicationManager getMedtronicCommunicationManager() {
return (MedtronicCommunicationManager)RileyLinkUtil.rileyLinkCommunicationManager;
return (MedtronicCommunicationManager) RileyLinkUtil.rileyLinkCommunicationManager;
}