- various changes

- reformatting everything
This commit is contained in:
Andy Rozman 2018-08-10 16:13:40 +01:00
parent fcdb2f9708
commit c9d35696cf
181 changed files with 4151 additions and 3393 deletions

View file

@ -177,7 +177,7 @@
<service android:name=".plugins.Persistentnotification.DummyService" />
<service
<service
android:name=".plugins.PumpMedtronic.service.RileyLinkMedtronicService"
android:enabled="true"
android:exported="true" />
@ -193,11 +193,12 @@
android:label="@string/title_activity_setup_wizard" />
<activity
android:name=".plugins.PumpCommon.dialog.RileylinkSettingsActivity"
android:name=".plugins.PumpCommon.hw.rileylink.dialog.RileyLinkStatusActivity"
android:label="@string/title_activity_rileylink_settings"
android:theme="@style/AppTheme"></activity>
android:theme="@style/Theme.AppCompat.NoTitle" />
<activity android:name=".SingleFragmentActivity"
<activity
android:name=".SingleFragmentActivity"
android:theme="@style/AppTheme" />
</application>

View file

@ -1,17 +1,17 @@
package info.nightscout.androidaps.plugins.PumpCommon;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import com.squareup.otto.Subscribe;
import java.util.Date;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import com.squareup.otto.Subscribe;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp;
@ -46,54 +46,45 @@ import info.nightscout.utils.DecimalFormatter;
// FIXME remove PumpDriver instances, just keep methods that do something here
public abstract class PumpPluginAbstract extends PluginBase implements PumpInterface, ConstraintsInterface {
protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult().success(false)
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_supported_by_pump));
protected static final PumpEnactResult OPERATION_NOT_YET_SUPPORTED = new PumpEnactResult().success(false)
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_yet_supported_by_pump));
// protected PumpStatus pumpStatusData;
private static final Logger LOG = LoggerFactory.getLogger(PumpPluginAbstract.class);
protected PumpDescription pumpDescription = new PumpDescription();
//protected PumpStatus pumpStatusData;
protected PumpDriverInterface pumpDriver;
protected PumpStatus pumpStatus;
protected String internalName;
protected ServiceConnection serviceConnection = null;
protected boolean serviceRunning = false;
protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult()
.success(false).enacted(false).comment(MainApp.gs(R.string.pump_operation_not_supported_by_pump));
protected static final PumpEnactResult OPERATION_NOT_YET_SUPPORTED = new PumpEnactResult()
.success(false).enacted(false).comment(MainApp.gs(R.string.pump_operation_not_yet_supported_by_pump));
// protected PumpPluginAbstract(PumpDriverInterface pumpDriverInterface, //
// String internalName, //
// String fragmentClassName, //
// int pluginName, //
// int pluginShortName, //
// PumpType pumpType) {
// this(pumpDriverInterface, //
// internalName, //
// new PluginDescription() //
// .mainType(PluginType.PUMP) //
// .fragmentClass(fragmentClassName) //
// .pluginName(pluginName) //
// .shortName(pluginShortName), //
// pumpType //
// );
// }
// protected PumpPluginAbstract(PumpDriverInterface pumpDriverInterface, //
// String internalName, //
// String fragmentClassName, //
// int pluginName, //
// int pluginShortName, //
// PumpType pumpType) {
// this(pumpDriverInterface, //
// internalName, //
// new PluginDescription() //
// .mainType(PluginType.PUMP) //
// .fragmentClass(fragmentClassName) //
// .pluginName(pluginName) //
// .shortName(pluginShortName), //
// pumpType //
// );
// }
protected PumpPluginAbstract(PumpDriverInterface pumpDriverInterface, //
String internalName, //
PluginDescription pluginDescription,
PumpType pumpType //
String internalName, //
PluginDescription pluginDescription, PumpType pumpType //
) {
super(pluginDescription);
LOG.error("After super called.");
this.pumpDriver = pumpDriverInterface;
this.internalName = internalName;
@ -105,7 +96,6 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
LOG.error("Before set description");
LOG.error("Before pumpDriver");
this.pumpDriver.initDriver(this.pumpStatus, this.pumpDescription);
@ -150,6 +140,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
*/
public abstract void onStartCustomActions();
/**
* Service class (same one you did serviceConnection for)
*
@ -174,10 +165,12 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
return pumpDriver.isInitialized();
}
public boolean isSuspended() {
return pumpDriver.isSuspended();
}
public boolean isBusy() {
return pumpDriver.isBusy();
}
@ -234,10 +227,9 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
} // base basal rate, not temp basal
// public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
// return pumpDriver.deliverTreatment(detailedBolusInfo);
// }
// public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
// return pumpDriver.deliverTreatment(detailedBolusInfo);
// }
public void stopBolusDelivering() {
pumpDriver.stopBolusDelivering();
@ -245,12 +237,15 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile,
boolean enforceNew) {
return pumpDriver.setTempBasalAbsolute(absoluteRate, durationInMinutes, profile, enforceNew);
}
@Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile,
boolean enforceNew) {
return pumpDriver.setTempBasalPercent(percent, durationInMinutes, profile, enforceNew);
}
@ -258,10 +253,11 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
return pumpDriver.setExtendedBolus(insulin, durationInMinutes);
}
//some pumps might set a very short temp close to 100% as cancelling a temp can be noisy
//when the cancel request is requested by the user (forced), the pump should always do a real cancel
// some pumps might set a very short temp close to 100% as cancelling a temp can be noisy
// when the cancel request is requested by the user (forced), the pump should always do a real cancel
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
return pumpDriver.cancelTempBasal(enforceNew);
}
@ -272,28 +268,27 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
return OPERATION_NOT_YET_SUPPORTED;
}
// Status to be passed to NS
// public JSONObject getJSONStatus(Profile profile, String profileName) {
// return pumpDriver.getJSONStatus(profile, profileName);
// }
// public JSONObject getJSONStatus(Profile profile, String profileName) {
// return pumpDriver.getJSONStatus(profile, profileName);
// }
public String deviceID() {
LOG.warn("deviceID [PumpPluginAbstract] - Not implemented.");
return "FakeDevice";
}
// Pump capabilities
// Pump capabilities
public PumpDescription getPumpDescription() {
return pumpDescription;
}
// Short info for SMS, Wear etc
// Short info for SMS, Wear etc
public boolean isFakingTempsByExtendedBoluses() {
LOG.warn("isFakingTempsByExtendedBoluses [PumpPluginAbstract] - Not implemented.");
@ -306,63 +301,63 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
return this.pumpDriver.loadTDDs();
}
// Constraints interface
// @Override
// public boolean isLoopEnabled() {
// return true;
// }
//
// @Override
// public boolean isClosedModeEnabled() {
// return true;
// }
//
// @Override
// public boolean isAutosensModeEnabled() {
// return true;
// }
//
// @Override
// public boolean isAMAModeEnabled() {
// return true;
// }
//
// @Override
// public boolean isSMBModeEnabled() {
// return true;
// }
//
// @Override
// public Double applyBasalConstraints(Double absoluteRate) {
// this.pumpStatus.constraintBasalRateAbsolute = absoluteRate;
// return absoluteRate;
// }
//
// @Override
// public Integer applyBasalConstraints(Integer percentRate) {
// this.pumpStatus.constraintBasalRatePercent = percentRate;
// return percentRate;
// }
//
// @Override
// public Double applyBolusConstraints(Double insulin) {
// this.pumpStatus.constraintBolus = insulin;
// return insulin;
// }
//
// @Override
// public Integer applyCarbsConstraints(Integer carbs) {
// this.pumpStatus.constraintCarbs = carbs;
// return carbs;
// }
//
// @Override
// public Double applyMaxIOBConstraints(Double maxIob) {
// this.pumpStatus.constraintMaxIob = maxIob;
// return maxIob;
// }
// @Override
// public boolean isLoopEnabled() {
// return true;
// }
//
// @Override
// public boolean isClosedModeEnabled() {
// return true;
// }
//
// @Override
// public boolean isAutosensModeEnabled() {
// return true;
// }
//
// @Override
// public boolean isAMAModeEnabled() {
// return true;
// }
//
// @Override
// public boolean isSMBModeEnabled() {
// return true;
// }
//
// @Override
// public Double applyBasalConstraints(Double absoluteRate) {
// this.pumpStatus.constraintBasalRateAbsolute = absoluteRate;
// return absoluteRate;
// }
//
// @Override
// public Integer applyBasalConstraints(Integer percentRate) {
// this.pumpStatus.constraintBasalRatePercent = percentRate;
// return percentRate;
// }
//
// @Override
// public Double applyBolusConstraints(Double insulin) {
// this.pumpStatus.constraintBolus = insulin;
// return insulin;
// }
//
// @Override
// public Integer applyCarbsConstraints(Integer carbs) {
// this.pumpStatus.constraintCarbs = carbs;
// return carbs;
// }
//
// @Override
// public Double applyMaxIOBConstraints(Double maxIob) {
// this.pumpStatus.constraintMaxIob = maxIob;
// return maxIob;
// }
@Override
public JSONObject getJSONStatus(Profile profile, String profileName) {
@ -387,7 +382,8 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
if (tb != null) {
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis(), profile));
extended.put("TempBasalAbsoluteRate",
tb.tempBasalConvertedToAbsolute(System.currentTimeMillis(), profile));
extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
}
@ -412,29 +408,33 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
return pump;
}
// FIXME i18n, null checks: iob, TDD
@Override
public String shortStatus(boolean veryShort) {
String ret = "";
if (pumpStatus.lastConnection != 0) {
Long agoMsec = System.currentTimeMillis() - pumpStatus.lastConnection;
int agoMin = (int) (agoMsec / 60d / 1000d);
int agoMin = (int)(agoMsec / 60d / 1000d);
ret += "LastConn: " + agoMin + " min ago\n";
}
if (pumpStatus.lastBolusTime.getTime() != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pumpStatus.lastBolusAmount) + "U @" + //
android.text.format.DateFormat.format("HH:mm", pumpStatus.lastBolusTime) + "\n";
android.text.format.DateFormat.format("HH:mm", pumpStatus.lastBolusTime) + "\n";
}
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis());
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin()
.getRealTempBasalFromHistory(System.currentTimeMillis());
if (activeTemp != null) {
ret += "Temp: " + activeTemp.toStringFull() + "\n";
}
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(
System.currentTimeMillis());
if (activeExtendedBolus != null) {
ret += "Extended: " + activeExtendedBolus.toString() + "\n";
}
if (!veryShort) {
ret += "TDD: " + DecimalFormatter.to0Decimal(pumpStatus.dailyTotalUnits) + " / " + pumpStatus.maxDailyTotalUnits + " U\n";
ret += "TDD: " + DecimalFormatter.to0Decimal(pumpStatus.dailyTotalUnits) + " / "
+ pumpStatus.maxDailyTotalUnits + " U\n";
}
ret += "IOB: " + pumpStatus.iob + "U\n";
ret += "Reserv: " + DecimalFormatter.to0Decimal(pumpStatus.reservoirRemainingUnits) + "U\n";
@ -450,9 +450,8 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
if (detailedBolusInfo.insulin == 0 && detailedBolusInfo.carbs == 0) {
// neither carbs nor bolus requested
LOG.error("deliverTreatment: Invalid input");
return new PumpEnactResult().success(false).enacted(false)
.bolusDelivered(0d).carbsDelivered(0d)
.comment(MainApp.gs(R.string.danar_invalidinput));
return new PumpEnactResult().success(false).enacted(false).bolusDelivered(0d).carbsDelivered(0d)
.comment(MainApp.gs(R.string.danar_invalidinput));
} else if (detailedBolusInfo.insulin > 0) {
// bolus needed, ask pump to deliver it
return deliverBolus(detailedBolusInfo);
@ -468,9 +467,8 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
LOG.debug("deliverTreatment: Carb only treatment.");
return new PumpEnactResult().success(true).enacted(true)
.bolusDelivered(0d).carbsDelivered(detailedBolusInfo.carbs)
.comment(MainApp.gs(R.string.virtualpump_resultok));
return new PumpEnactResult().success(true).enacted(true).bolusDelivered(0d)
.carbsDelivered(detailedBolusInfo.carbs).comment(MainApp.gs(R.string.virtualpump_resultok));
}
} finally {
triggerUIChange();
@ -486,25 +484,22 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
public PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) {
return new PumpEnactResult()
.success(false).enacted(false).comment(MainApp.gs(resourceId));
return new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(resourceId));
}
// Profile interface
// @Nullable
// public ProfileStore getProfile() {
// return this.pumpStatus.profileStore;
// }
//
// public String getUnits() {
// return this.pumpStatus.units;
// }
//
// public String getProfileName() {
// return this.pumpStatus.activeProfileName;
// }
// @Nullable
// public ProfileStore getProfile() {
// return this.pumpStatus.profileStore;
// }
//
// public String getUnits() {
// return this.pumpStatus.units;
// }
//
// public String getProfileName() {
// return this.pumpStatus.activeProfileName;
// }
}

View file

@ -12,8 +12,8 @@ public class DoseSettings {
private float minDose;
private Float maxDose;
public DoseSettings(float step, int durationStep, int maxDuration, float minDose, Float maxDose)
{
public DoseSettings(float step, int durationStep, int maxDuration, float minDose, Float maxDose) {
this.step = step;
this.durationStep = durationStep;
this.maxDuration = maxDuration;
@ -21,8 +21,8 @@ public class DoseSettings {
this.maxDose = maxDose;
}
public DoseSettings(float step, int durationStep, int maxDuration, float minDose)
{
public DoseSettings(float step, int durationStep, int maxDuration, float minDose) {
this(step, durationStep, maxDuration, minDose, null);
}
@ -31,18 +31,22 @@ public class DoseSettings {
return step;
}
public int getDurationStep() {
return durationStep;
}
public int getMaxDuration() {
return maxDuration;
}
public float getMinDose() {
return minDose;
}
public Float getMaxDose() {
return maxDose;
}

View file

@ -2,6 +2,8 @@ package info.nightscout.androidaps.plugins.PumpCommon.data;
import java.util.Date;
import org.joda.time.LocalDateTime;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpStatusType;
@ -14,7 +16,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
public abstract class PumpStatus {
// connection
public Date lastDataTime;
public LocalDateTime lastDataTime;
public long lastConnection = 0L;
// last bolus
@ -33,18 +35,11 @@ public abstract class PumpStatus {
// TDD
public Double dailyTotalUnits;
public String maxDailyTotalUnits;
protected PumpDescription pumpDescription;
public boolean validBasalRateProfileSelectedOnPump = true;
public PumpType pumpType = PumpType.GenericAAPS;
public ProfileStore profileStore;
public String units; // Constants.MGDL or Constants.MMOL
public PumpStatusType pumpStatusType = PumpStatusType.Running;
// TODO maybe not needed anymore in 2.0
public Double constraintBasalRateAbsolute;
public Integer constraintBasalRatePercent;
@ -52,6 +47,14 @@ public abstract class PumpStatus {
public Integer constraintCarbs;
public Double constraintMaxIob;
public Double[] basalsByHour;
// public double remainUnits = 0;
public int remainBattery = 0;
public double currentBasal = 0;
public int tempBasalInProgress = 0;
public int tempBasalRatio = 0;
public int tempBasalRemainMin = 0;
public Date tempBasalStart;
protected PumpDescription pumpDescription;
public PumpStatus(PumpDescription pumpDescription) {
@ -61,11 +64,25 @@ public abstract class PumpStatus {
}
// FIXME cleanup this is from RT2
// public long getTimeIndex() {
// return (long) Math.ceil(time.getTime() / 60000d);
// }
//
// public void setTimeIndex(long timeIndex) {
// this.timeIndex = timeIndex;
// }
//
// public long timeIndex;
//
// public Date time;
public abstract void initSettings();
public void setLastCommunicationToNow() {
this.lastDataTime = new Date();
this.lastDataTime = LocalDateTime.now();
this.lastConnection = System.currentTimeMillis();
}
@ -80,36 +97,12 @@ public abstract class PumpStatus {
return pumpType;
}
public void setPumpType(PumpType pumpType) {
this.pumpType = pumpType;
}
// FIXME cleanup this is from RT2
// public long getTimeIndex() {
// return (long) Math.ceil(time.getTime() / 60000d);
// }
//
// public void setTimeIndex(long timeIndex) {
// this.timeIndex = timeIndex;
// }
//
// public long timeIndex;
//
// public Date time;
//public double remainUnits = 0;
public int remainBattery = 0;
public double currentBasal = 0;
public int tempBasalInProgress = 0;
public int tempBasalRatio = 0;
public int tempBasalRemainMin = 0;
public Date tempBasalStart;
//public Date last_bolus_time;
//public double last_bolus_amount = 0;
// public Date last_bolus_time;
// public double last_bolus_amount = 0;
}

View file

@ -4,40 +4,36 @@ package info.nightscout.androidaps.plugins.PumpCommon.defs;
* Created by andy on 02/05/2018.
*/
public enum DoseStepSize
{
public enum DoseStepSize {
ComboBasal( //
new DoseStepSizeEntry(0f, 1f, 0.01f), //
new DoseStepSizeEntry(1f, 10f, 0.05f), //
new DoseStepSizeEntry(10f, Float.MAX_VALUE, 0.1f)), //
new DoseStepSizeEntry(0f, 1f, 0.01f), //
new DoseStepSizeEntry(1f, 10f, 0.05f), //
new DoseStepSizeEntry(10f, Float.MAX_VALUE, 0.1f)), //
MedtronicVeoBasal( //
new DoseStepSizeEntry(0f, 1f, 0.025f), //
new DoseStepSizeEntry(1f, 10f, 0.05f), //
new DoseStepSizeEntry(10f, Float.MAX_VALUE, 0.1f)), //
new DoseStepSizeEntry(0f, 1f, 0.025f), //
new DoseStepSizeEntry(1f, 10f, 0.05f), //
new DoseStepSizeEntry(10f, Float.MAX_VALUE, 0.1f)), //
;
DoseStepSizeEntry[] entries;
DoseStepSize(DoseStepSizeEntry...entries)
{
DoseStepSize(DoseStepSizeEntry... entries) {
this.entries = entries;
}
public float getStepSizeForAmount(float amount)
{
public float getStepSizeForAmount(float amount) {
for (DoseStepSizeEntry entry : entries) {
if (entry.from <= amount && entry.to > amount)
return entry.value;
}
// should never come to this
return entries[entries.length-1].value;
return entries[entries.length - 1].value;
}
@ -51,12 +47,9 @@ public enum DoseStepSize
sb.append(entry.from);
sb.append("-");
if (entry.to == Float.MAX_VALUE)
{
if (entry.to == Float.MAX_VALUE) {
sb.append("~}");
}
else
{
} else {
sb.append(entry.to);
sb.append("}, ");
}
@ -65,16 +58,16 @@ public enum DoseStepSize
return sb.toString();
}
static class DoseStepSizeEntry {
static class DoseStepSizeEntry
{
float from;
float to;
float value;
// to = this value is not included, but would actually mean <, so for rates between 0.025-0.975 u/h, we would have [from=0, to=10]
DoseStepSizeEntry(float from, float to, float value)
{
// to = this value is not included, but would actually mean <, so for rates between 0.025-0.975 u/h, we would
// have [from=0, to=10]
DoseStepSizeEntry(float from, float to, float value) {
this.from = from;
this.to = to;
this.value = value;

View file

@ -16,7 +16,6 @@ public enum PumpCapability {
// grouped
VirtualPump(Bolus, ExtendedBolus, TBR, BasalProfileSet, StoreCarbInfo), //
Bolus_TBR_Basal_Refill_Carb(Bolus, TBR, BasalProfileSet, Refill, StoreCarbInfo), //
Bolus_Extended_TBR_Basal_Carb(Bolus, ExtendedBolus, TBR, BasalProfileSet, StoreCarbInfo), //
Bolus_Extended_TBR_Basal_Refill_Carb(Bolus, ExtendedBolus, TBR, BasalProfileSet, Refill, StoreCarbInfo), //
@ -54,5 +53,4 @@ public enum PumpCapability {
return false;
}
}

View file

@ -11,10 +11,12 @@ public enum PumpStatusType {
private String statusString;
PumpStatusType(String statusString) {
this.statusString = statusString;
}
public String getStatus() {
return statusString;
}

View file

@ -1,12 +1,10 @@
package info.nightscout.androidaps.plugins.PumpCommon.defs;
import java.util.HashMap;
import java.util.Map;
import info.nightscout.androidaps.plugins.PumpCommon.data.DoseSettings;
/**
* Created by andy on 02/05/2018.
* <p>
@ -16,109 +14,112 @@ import info.nightscout.androidaps.plugins.PumpCommon.data.DoseSettings;
public enum PumpType {
Unknown("Unknown Pump", 0.1f, null, //
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10, 30, 24 * 60, 0f, 200f), //
0.01f, 0.01f, null, PumpCapability.None),
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10, 30, 24 * 60, 0f, 200f), //
0.01f, 0.01f, null, PumpCapability.None),
GenericAAPS("Generic AAPS", 0.1f, null, //
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10, 30, 24 * 60, 0f, 500f), //
0.01f, 0.01f, null, PumpCapability.VirtualPump), //
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10, 30, 24 * 60, 0f, 500f), //
0.01f, 0.01f, null, PumpCapability.VirtualPump), //
// Cellnovo
Cellnovo1("Cellnovo", 0.05f, null, //
new DoseSettings(0.05f, 30, 24 * 60, 1f, null),
PumpTempBasalType.Percent,
new DoseSettings(5, 30, 24 * 60, 0f, 200f), //
0.05f, 0.05f, null, PumpCapability.VirtualPump), //
new DoseSettings(0.05f, 30, 24 * 60, 1f, null), PumpTempBasalType.Percent, new DoseSettings(5, 30, 24 * 60, 0f,
200f), //
0.05f, 0.05f, null, PumpCapability.VirtualPump), //
// Accu-Chek
AccuChekCombo("Accu-Chek Combo", 0.1f, null, //
new DoseSettings(0.1f, 15, 12 * 60, 0.1f), //
PumpTempBasalType.Percent,
new DoseSettings(10, 15, 12 * 60, 0f, 500f), //
0.01f, 0.1f, DoseStepSize.ComboBasal, PumpCapability.Bolus_TBR_Basal_Refill_Carb), //
new DoseSettings(0.1f, 15, 12 * 60, 0.1f), //
PumpTempBasalType.Percent, new DoseSettings(10, 15, 12 * 60, 0f, 500f), //
0.01f, 0.1f, DoseStepSize.ComboBasal, PumpCapability.Bolus_TBR_Basal_Refill_Carb), //
AccuChekSpirit("Accu-Chek Spirit", 0.1f, null, //
new DoseSettings(0.1f, 15, 12 * 60, 0.1f), //
PumpTempBasalType.Percent,
new DoseSettings(10, 15, 12 * 60, 0f, 500f), //
0.01f, 0.1f, null, PumpCapability.VirtualPump), //
new DoseSettings(0.1f, 15, 12 * 60, 0.1f), //
PumpTempBasalType.Percent, new DoseSettings(10, 15, 12 * 60, 0f, 500f), //
0.01f, 0.1f, null, PumpCapability.VirtualPump), //
// Animas
AnimasVibe("Animas Vibe", 0.05f, null, // AnimasBolus?
new DoseSettings(0.05f, 30, 12 * 60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10, 30, 24 * 60, 0f, 200f), //
0.025f, 5f, 0f, null, PumpCapability.VirtualPump), //
new DoseSettings(0.05f, 30, 12 * 60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10, 30, 24 * 60, 0f, 200f), //
0.025f, 5f, 0f, null, PumpCapability.VirtualPump), //
AnimasPing("Animas Ping", AnimasVibe),
// Dana
DanaR("DanaR", 0.05f, null, //
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10f, 60, 24 * 60, 0f, 200f), //
0.04f, 0.01f, null, PumpCapability.Bolus_Extended_TBR_Basal_Refill_Carb),
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10f, 60, 24 * 60, 0f, 200f), //
0.04f, 0.01f, null, PumpCapability.Bolus_Extended_TBR_Basal_Refill_Carb),
DanaRKorean("DanaR Korean", 0.05f, null, //
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10f, 60, 24 * 60, 0f, 200f), //
0.1f, 0.01f, null, PumpCapability.Bolus_Extended_TBR_Basal_Refill_Carb),
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Percent, //
new DoseSettings(10f, 60, 24 * 60, 0f, 200f), //
0.1f, 0.01f, null, PumpCapability.Bolus_Extended_TBR_Basal_Refill_Carb),
DanaRS("DanaRS", DanaR),
DanaRv2("DanaRv2", DanaR),
// Insulet
Insulet_Omnipod("Insulet Omnipod", 0.05f, null, //
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05f, 30, 12 * 60, 0f, 5.0f), // cannot exceed max basal rate 30u/hr
0.05f, 0.05f, null, PumpCapability.VirtualPump),
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05f, 30, 12 * 60, 0f, 5.0f), // cannot exceed max basal rate 30u/hr
0.05f, 0.05f, null, PumpCapability.VirtualPump),
// Medtronic
Medtronic_512_712("Medtronic 512/712", 0.05f, null, //
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05f, 30, 24 * 60, 0f, 35f), //
0.05f, 0.05f, null, PumpCapability.VirtualPump), // TODO
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05f, 30, 24 * 60, 0f, 35f), //
0.05f, 0.05f, null, PumpCapability.VirtualPump), // TODO
Medtronic_515_715("Medtronic 515/715", Medtronic_512_712),
Medtronic_522_722("Medtronic 522/722", Medtronic_512_712),
Medtronic_523_723_Revel("Medtronic 553/753 (Revel)", 0.05f, null, //
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05f, 30, 24 * 60, 0f, 35f), //
0.025f, 0.025f, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPump), //
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05f, 30, 24 * 60, 0f, 35f), //
0.025f, 0.025f, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPump), //
Medtronic_554_754_Veo("Medtronic 554/754 (Veo)", Medtronic_523_723_Revel), // TODO
Medtronic_640G("Medtronic 640G", 0.025f, null, //
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05f, 30, 24 * 60, 0f, 35f), //
0.025f, 0.025f, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPump), //
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
PumpTempBasalType.Absolute, //
new DoseSettings(0.05f, 30, 24 * 60, 0f, 35f), //
0.025f, 0.025f, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPump), //
// Tandem
TandemTSlim("Tandem t:slim", 0.01f, null, //
new DoseSettings(0.01f, 15, 8 * 60, 0.4f),
PumpTempBasalType.Percent,
new DoseSettings(1, 15, 8 * 60, 0f, 250f), //
0.1f, 0.001f, null, PumpCapability.VirtualPump),
new DoseSettings(0.01f, 15, 8 * 60, 0.4f), PumpTempBasalType.Percent, new DoseSettings(1, 15, 8 * 60, 0f, 250f), //
0.1f, 0.001f, null, PumpCapability.VirtualPump),
TandemTFlex("Tandem t:flex", TandemTSlim), //
TandemTSlimG4("Tandem t:slim G4", TandemTSlim), //
TandemTSlimX2("Tandem t:slim X2", TandemTSlim), //
;
private static Map<String, PumpType> mapByDescription;
static {
mapByDescription = new HashMap<>();
for (PumpType pumpType : values()) {
mapByDescription.put(pumpType.getDescription(), pumpType);
}
}
private String description;
private float bolusSize;
private DoseStepSize specialBolusSize;
@ -130,17 +131,7 @@ public enum PumpType {
private float 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) {
@ -148,23 +139,33 @@ public enum PumpType {
this.parent = parent;
}
PumpType(String description, PumpType parent, PumpCapability pumpCapability) {
this.description = description;
this.parent = parent;
this.pumpCapability = pumpCapability;
}
PumpType(String description, float bolusSize, DoseStepSize specialBolusSize, //
DoseSettings extendedBolusSettings, //
PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, //
float baseBasalMinValue, float baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) {
this(description, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType, tbrSettings, baseBasalMinValue, null, baseBasalStep, baseBasalSpecialSteps, pumpCapability);
PumpType(String description, float bolusSize,
DoseStepSize specialBolusSize, //
DoseSettings extendedBolusSettings, //
PumpTempBasalType pumpTempBasalType,
DoseSettings tbrSettings, //
float baseBasalMinValue, float baseBasalStep, DoseStepSize baseBasalSpecialSteps,
PumpCapability pumpCapability) {
this(description, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType, tbrSettings,
baseBasalMinValue, null, baseBasalStep, baseBasalSpecialSteps, pumpCapability);
}
PumpType(String description, float bolusSize, DoseStepSize specialBolusSize, //
DoseSettings extendedBolusSettings, //
PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, //
float baseBasalMinValue, Float baseBasalMaxValue, float baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) {
PumpType(String description, float bolusSize,
DoseStepSize specialBolusSize, //
DoseSettings extendedBolusSettings, //
PumpTempBasalType pumpTempBasalType,
DoseSettings tbrSettings, //
float baseBasalMinValue, Float baseBasalMaxValue, float baseBasalStep, DoseStepSize baseBasalSpecialSteps,
PumpCapability pumpCapability) {
this.description = description;
this.bolusSize = bolusSize;
this.specialBolusSize = specialBolusSize;
@ -179,10 +180,20 @@ public enum PumpType {
}
public static PumpType getByDescription(String desc) {
if (mapByDescription.containsKey(desc)) {
return mapByDescription.get(desc);
} else {
return PumpType.GenericAAPS;
}
}
public String getDescription() {
return description;
}
public PumpCapability getPumpCapability() {
if (isParentSet())
@ -191,6 +202,7 @@ public enum PumpType {
return this.pumpCapability;
}
public float getBolusSize() {
return isParentSet() ? parent.bolusSize : bolusSize;
}
@ -246,15 +258,6 @@ public enum PumpType {
}
public static PumpType getByDescription(String desc) {
if (mapByDescription.containsKey(desc)) {
return mapByDescription.get(desc);
} else {
return PumpType.GenericAAPS;
}
}
public String getFullDescription(String i18nTemplate) {
String unit = getPumpTempBasalType() == PumpTempBasalType.Percent ? "%" : "";
@ -262,11 +265,14 @@ public enum PumpType {
DoseSettings eb = getExtendedBolusSettings();
DoseSettings tbr = getTbrSettings();
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);
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);
}
@ -289,5 +295,4 @@ public enum PumpType {
return ((getBaseBasalSpecialSteps() != null) || (getSpecialBolusSize() != null));
}
}

View file

@ -1,5 +1,11 @@
package info.nightscout.androidaps.plugins.PumpCommon.dialog;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.Manifest;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
@ -33,38 +39,75 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.PumpCommon.utils.LocationHelper;
import info.nightscout.utils.SP;
public class RileyLinkBLEScanActivity extends AppCompatActivity {
private static final Logger LOG = LoggerFactory.getLogger(RileyLinkBLEScanActivity.class);
private BluetoothAdapter mBluetoothAdapter;
private BluetoothLeScanner mLEScanner;
private LeDeviceListAdapter mLeDeviceListAdapter;
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 30241; // arbitrary.
private static final int REQUEST_ENABLE_BT = 30242; // arbitrary
// Stops scanning after 10 seconds.
private static final long SCAN_PERIOD = 30000;
public boolean mScanning;
private Handler mHandler;
public Snackbar snackbar;
public ScanSettings settings;
public List<ScanFilter> filters;
public ListView listBTScan;
public Toolbar toolbarBTScan;
public Context mContext = this;
private BluetoothAdapter mBluetoothAdapter;
private BluetoothLeScanner mLEScanner;
private LeDeviceListAdapter mLeDeviceListAdapter;
private Handler mHandler;
private ScanCallback mScanCallback = new ScanCallback() {
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 30241; // arbitrary.
private static final int REQUEST_ENABLE_BT = 30242; // arbitrary
// Stops scanning after 10 seconds.
private static final long SCAN_PERIOD = 30000;
@Override
public void onScanResult(int callbackType, ScanResult result) {
final BluetoothDevice device = result.getDevice();
runOnUiThread(new Runnable() {
@Override
public void run() {
if (device.getName() != null && device.getName().length() > 0) {
mLeDeviceListAdapter.addDevice(device);
mLeDeviceListAdapter.notifyDataSetChanged();
LOG.debug("Found BLE" + device.getName());
}
}
});
}
@Override
public void onBatchScanResults(final List<ScanResult> results) {
runOnUiThread(new Runnable() {
@Override
public void run() {
for (ScanResult result : results) {
BluetoothDevice device = result.getDevice();
if (device.getName() != null && device.getName().length() > 0) {
mLeDeviceListAdapter.addDevice(device);
LOG.debug("Found BLE" + result.toString());
} else {
LOG.error("Found BLE, but name appears to be missing. Ignoring. " + device.getAddress());
}
}
mLeDeviceListAdapter.notifyDataSetChanged();
}
});
}
@Override
public void onScanFailed(int errorCode) {
Log.e("Scan Failed", "Error Code: " + errorCode);
Toast.makeText(mContext, "Scan Failed " + errorCode, Toast.LENGTH_LONG).show();
}
};
@Override
@ -77,33 +120,35 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
mHandler = new Handler();
mLeDeviceListAdapter = new LeDeviceListAdapter();
listBTScan = (ListView) findViewById(R.id.rileylink_listBTScan);
listBTScan = (ListView)findViewById(R.id.rileylink_listBTScan);
listBTScan.setAdapter(mLeDeviceListAdapter);
listBTScan.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView textview = (TextView) view.findViewById(R.id.rileylink_device_address);
TextView textview = (TextView)view.findViewById(R.id.rileylink_device_address);
String bleAddress = textview.getText().toString();
SP.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress);
// //Notify that we have a new rileylinkAddressKey
// RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.INTENT_NEW_rileylinkAddressKey);
//
// LOG.debug("New rileylinkAddressKey: " + bleAddress);
//
// //Notify that we have a new pumpIDKey
// RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.INTENT_NEW_pumpIDKey);
// //Notify that we have a new rileylinkAddressKey
// RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.INTENT_NEW_rileylinkAddressKey);
//
// LOG.debug("New rileylinkAddressKey: " + bleAddress);
//
// //Notify that we have a new pumpIDKey
// RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.INTENT_NEW_pumpIDKey);
finish();
}
});
toolbarBTScan = (Toolbar) findViewById(R.id.rileylink_toolbarBTScan);
toolbarBTScan = (Toolbar)findViewById(R.id.rileylink_toolbarBTScan);
toolbarBTScan.setTitle(R.string.rileylink_scanner_title);
setSupportActionBar(toolbarBTScan);
snackbar = Snackbar.make(findViewById(R.id.RileyLinkScan), "Scanning...", Snackbar.LENGTH_INDEFINITE);
snackbar.setAction("STOP", new View.OnClickListener() {
@Override
public void onClick(View view) {
scanLeDevice(false);
@ -151,8 +196,9 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
// Use this check to determine whether BLE is supported on the device. Then
// you can selectively disable BLE-related features.
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
//your code that requires permission
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION);
// your code that requires permission
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
PERMISSION_REQUEST_COARSE_LOCATION);
}
// Ensures Bluetooth is available on the device and it is enabled. If not,
@ -197,12 +243,13 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
if (enable) {
// Stops scanning after a pre-defined scan period.
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
mScanning = false;
mLEScanner.stopScan(mScanCallback);
LOG.debug("scanLeDevice: Scanning Stop");
//Toast.makeText(mContext, "Scanning finished", Toast.LENGTH_SHORT).show();
// Toast.makeText(mContext, "Scanning finished", Toast.LENGTH_SHORT).show();
snackbar.dismiss();
}
}, SCAN_PERIOD);
@ -210,66 +257,27 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
mScanning = true;
mLEScanner.startScan(mScanCallback);
LOG.debug("scanLeDevice: Scanning Start");
//Toast.makeText(this, "Scanning", Toast.LENGTH_SHORT).show();
// Toast.makeText(this, "Scanning", Toast.LENGTH_SHORT).show();
snackbar.show();
} else {
mScanning = false;
mLEScanner.stopScan(mScanCallback);
LOG.debug("scanLeDevice: Scanning Stop");
//Toast.makeText(this, "Scanning finished", Toast.LENGTH_SHORT).show();
// Toast.makeText(this, "Scanning finished", Toast.LENGTH_SHORT).show();
snackbar.dismiss();
}
}
static class ViewHolder {
private ScanCallback mScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
final BluetoothDevice device = result.getDevice();
runOnUiThread(new Runnable() {
@Override
public void run() {
if (device.getName() != null && device.getName().length() > 0) {
mLeDeviceListAdapter.addDevice(device);
mLeDeviceListAdapter.notifyDataSetChanged();
LOG.debug("Found BLE" + device.getName());
}
}
});
}
@Override
public void onBatchScanResults(final List<ScanResult> results) {
runOnUiThread(new Runnable() {
@Override
public void run() {
for (ScanResult result : results) {
BluetoothDevice device = result.getDevice();
if (device.getName() != null && device.getName().length() > 0) {
mLeDeviceListAdapter.addDevice(device);
LOG.debug("Found BLE" + result.toString());
} else {
LOG.error("Found BLE, but name appears to be missing. Ignoring. " + device.getAddress());
}
}
mLeDeviceListAdapter.notifyDataSetChanged();
}
});
}
@Override
public void onScanFailed(int errorCode) {
Log.e("Scan Failed", "Error Code: " + errorCode);
Toast.makeText(mContext, "Scan Failed " + errorCode, Toast.LENGTH_LONG).show();
}
};
TextView deviceName;
TextView deviceAddress;
}
private class LeDeviceListAdapter extends BaseAdapter {
private ArrayList<BluetoothDevice> mLeDevices;
private LayoutInflater mInflator;
@ -325,19 +333,19 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
if (view == null) {
view = mInflator.inflate(R.layout.rileylink_scan_item, null);
viewHolder = new ViewHolder();
viewHolder.deviceAddress = (TextView) view.findViewById(R.id.rileylink_device_address);
viewHolder.deviceName = (TextView) view.findViewById(R.id.rileylink_device_name);
viewHolder.deviceAddress = (TextView)view.findViewById(R.id.rileylink_device_address);
viewHolder.deviceName = (TextView)view.findViewById(R.id.rileylink_device_name);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();
viewHolder = (ViewHolder)view.getTag();
}
BluetoothDevice device = mLeDevices.get(i);
String deviceName = device.getName();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if (SP.getString(RileyLinkConst.Prefs.RileyLinkAddress, "").compareTo(device.getAddress()) == 0) {
//viewHolder.deviceName.setTextColor(getColor(R.color.secondary_text_light));
//viewHolder.deviceAddress.setTextColor(getColor(R.color.secondary_text_light));
// viewHolder.deviceName.setTextColor(getColor(R.color.secondary_text_light));
// viewHolder.deviceAddress.setTextColor(getColor(R.color.secondary_text_light));
deviceName += " (" + getResources().getString(R.string.rileylink_scanner_selected_device) + ")";
}
viewHolder.deviceName.setText(deviceName);
@ -347,10 +355,4 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
}
}
static class ViewHolder {
TextView deviceName;
TextView deviceAddress;
}
}

View file

@ -1,116 +0,0 @@
package info.nightscout.androidaps.plugins.PumpCommon.dialog;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.plugins.PumpMedtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
/**
* Created by andy on 5/19/18.
*/
public class RileyLinkSettingsTab1 extends Fragment implements RefreshableInterface {
TextView connectionStatus;
TextView configuredAddress;
TextView connectedDevice;
TextView connectionError;
TextView deviceType;
TextView deviceModel;
TextView serialNumber;
TextView pumpFrequency;
TextView lastUsedFrequency;
TextView lastDeviceContact;
RileyLinkServiceData rileyLinkServiceData;
MedtronicPumpStatus medtronicPumpStatus;
boolean first = false;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.rileylink_settings_tab1, container, false);
return rootView;
}
@Override
public void onStart() {
super.onStart();
rileyLinkServiceData = RileyLinkUtil.getRileyLinkServiceData();
this.connectionStatus = (TextView) getActivity().findViewById(R.id.rls_t1_connection_status);
this.configuredAddress = (TextView) getActivity().findViewById(R.id.rls_t1_configured_address);
this.connectedDevice = (TextView) getActivity().findViewById(R.id.rls_t1_connected_device);
this.connectionError = (TextView) getActivity().findViewById(R.id.rls_t1_connection_error);
this.deviceType = (TextView) getActivity().findViewById(R.id.rls_t1_device_type);
this.deviceModel = (TextView) getActivity().findViewById(R.id.rls_t1_device_model);
this.serialNumber = (TextView) getActivity().findViewById(R.id.rls_t1_serial_number);
this.pumpFrequency = (TextView) getActivity().findViewById(R.id.rls_t1_pump_frequency);
this.lastUsedFrequency = (TextView) getActivity().findViewById(R.id.rls_t1_last_used_frequency);
this.lastDeviceContact = (TextView) getActivity().findViewById(R.id.rls_t1_last_device_contact);
if (!first) {
// 7-12
int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, //
R.id.rls_t1_tv08, R.id.rls_t1_tv09, R.id.rls_t1_tv10, R.id.rls_t1_tv11, R.id.rls_t1_tv12};
for (int id : ids) {
TextView tv = (TextView) getActivity().findViewById(id);
tv.setText(tv.getText() + ":");
}
first = true;
}
refreshData();
}
public void refreshData() {
// FIXME i18n
this.connectionStatus.setText(rileyLinkServiceData.serviceState.name());
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
// FIXME
this.connectedDevice.setText("???");
// FIXME i18n
this.connectionError.setText(rileyLinkServiceData.errorCode == null ? "-" : rileyLinkServiceData.errorCode.name());
this.medtronicPumpStatus = MedtronicUtil.getPumpStatus();
if (medtronicPumpStatus != null) {
this.deviceType.setText(RileyLinkTargetDevice.MedtronicPump.name());
this.deviceModel.setText(medtronicPumpStatus.pumpType.getDescription());
this.serialNumber.setText(medtronicPumpStatus.serialNumber);
this.pumpFrequency.setText(medtronicPumpStatus.pumpFrequency);
if (rileyLinkServiceData.lastGoodFrequency != null)
this.lastUsedFrequency.setText(rileyLinkServiceData.lastGoodFrequency.toString());
// FIXME
if (medtronicPumpStatus.lastConnection == 0)
this.lastDeviceContact.setText("" + medtronicPumpStatus.lastDataTime);
else
this.lastDeviceContact.setText("Never");
}
}
}

View file

@ -1,30 +0,0 @@
package info.nightscout.androidaps.plugins.PumpCommon.dialog;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import info.nightscout.androidaps.R;
/**
* Created by andy on 5/19/18.
*/
public class RileyLinkSettingsTab2 extends Fragment implements RefreshableInterface {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.rileylink_settings_tab2, container, false);
return rootView;
}
@Override
public void refreshData() {
}
}

View file

@ -14,18 +14,18 @@ import info.nightscout.androidaps.plugins.PumpCommon.data.PumpStatus;
public abstract class PumpDriverAbstract implements PumpDriverInterface {
protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult().success(false)
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_supported_by_pump));
protected static final PumpEnactResult OPERATION_NOT_YET_SUPPORTED = new PumpEnactResult().success(false)
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_yet_supported_by_pump));
protected PumpDescription pumpDescription;
protected PumpStatus pumpStatusData;
protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult()
.success(false).enacted(false).comment(MainApp.gs(R.string.pump_operation_not_supported_by_pump));
protected static final PumpEnactResult OPERATION_NOT_YET_SUPPORTED = new PumpEnactResult()
.success(false).enacted(false).comment(MainApp.gs(R.string.pump_operation_not_yet_supported_by_pump));
protected PumpDriverAbstract() {
}
public void initDriver(PumpStatus pumpStatus, PumpDescription pumpDescription) {
this.pumpDescription = pumpDescription;
this.pumpStatusData = pumpStatus;
@ -43,6 +43,7 @@ public abstract class PumpDriverAbstract implements PumpDriverInterface {
return this.pumpStatusData;
}
@Override
public PumpDescription getPumpDescription() {
return pumpDescription;
@ -55,6 +56,6 @@ public abstract class PumpDriverAbstract implements PumpDriverInterface {
return new Date();
}
return this.pumpStatusData.lastDataTime;
return this.pumpStatusData.lastDataTime.toDate();
}
}

View file

@ -12,6 +12,7 @@ public interface PumpDriverInterface extends PumpInterface {
void initDriver(PumpStatus pumpStatus, PumpDescription pumpDescription);
PumpStatus getPumpStatusData();
}

View file

@ -1,10 +1,10 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink;
import android.content.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.content.Context;
import info.nightscout.androidaps.plugins.PumpCommon.data.PumpStatus;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RFSpy;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.FrequencyScanResults;
@ -23,7 +23,6 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
import info.nightscout.utils.SP;
/**
* This is abstract class for RileyLink Communication, this one needs to be extended by specific "Pump" class.
* <p>
@ -35,20 +34,23 @@ public abstract class RileyLinkCommunicationManager {
protected final RFSpy rfspy;
protected final Context context;
private double[] scanFrequencies;
protected int receiverDeviceAwakeForMinutes = 1; // override this in constructor of specific implementation
protected String receiverDeviceID; // String representation of receiver device (ex. Pump (xxxxxx) or Pod (yyyyyy))
protected long lastGoodReceiverCommunicationTime = 0;
protected PumpStatus pumpStatus;
protected RileyLinkServiceData rileyLinkServiceData;
protected RileyLinkTargetFrequency targetFrequency;
private double[] scanFrequencies;
// internal flag
private boolean showPumpMessages = true;
protected RileyLinkTargetFrequency targetFrequency;
private int timeoutCount = 0;
private long nextWakeUpRequired = 0L;
// protected PumpMessage sendAndListen(RLMessage msg) {
// return sendAndListen(msg, 4000); // 2000
// }
public RileyLinkCommunicationManager(Context context, RFSpy rfspy, RileyLinkTargetFrequency targetFrequency) {
this.context = context;
this.rfspy = rfspy;
@ -64,14 +66,6 @@ public abstract class RileyLinkCommunicationManager {
protected abstract void configurePumpSpecificSettings();
// protected PumpMessage sendAndListen(RLMessage msg) {
// return sendAndListen(msg, 4000); // 2000
// }
private int timeoutCount = 0;
// All pump communications go through this function.
protected <E extends RLMessage> E sendAndListen(RLMessage msg, int timeout_ms, Class<E> clazz) {
@ -83,7 +77,7 @@ public abstract class RileyLinkCommunicationManager {
E response = createResponseMessage(rfSpyResponse.getRadioResponse().getPayload(), clazz);
//PumpMessage rval = new PumpMessage(resp.getRadioResponse().getPayload());
// PumpMessage rval = new PumpMessage(resp.getRadioResponse().getPayload());
if (response.isValid()) {
// Mark this as the last time we heard from the pump.
rememberLastGoodDeviceCommunicationTime();
@ -94,10 +88,11 @@ public abstract class RileyLinkCommunicationManager {
timeoutCount++;
if (timeoutCount >= 5) {
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.NoContactWithDevice);
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError,
RileyLinkError.NoContactWithDevice);
timeoutCount = 0;
tuneForDevice();
//RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_quickTune);
// RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_quickTune);
}
}
@ -118,9 +113,6 @@ public abstract class RileyLinkCommunicationManager {
}
private long nextWakeUpRequired = 0L;
public int getNotConnectedCount() {
return rfspy != null ? rfspy.notConnectedCount : 0;
}
@ -129,9 +121,9 @@ public abstract class RileyLinkCommunicationManager {
// FIXME change wakeup
// TODO we might need to fix this. Maybe make pump awake for shorter time (battery factor for pump) - Andy
public void wakeUp(int duration_minutes, boolean force) {
// If it has been longer than n minutes, do wakeup. Otherwise assume pump is still awake.
// If it has been longer than n minutes, do wakeup. Otherwise assume pump is still awake.
// **** FIXME: this wakeup doesn't seem to work well... must revisit
//receiverDeviceAwakeForMinutes = duration_minutes;
// receiverDeviceAwakeForMinutes = duration_minutes;
MedtronicUtil.setPumpDeviceState(PumpDeviceState.WakingUp);
@ -142,7 +134,8 @@ public abstract class RileyLinkCommunicationManager {
LOG.info("Waking pump...");
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData); // simple
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 200, (byte) 0, (byte) 0, 25000, (byte) 0);
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte)0, (byte)200,
(byte)0, (byte)0, 25000, (byte)0);
LOG.info("wakeup: raw response is " + ByteUtil.shortHexString(resp.getRaw()));
// FIXME wakeUp successful !!!!!!!!!!!!!!!!!!
@ -152,18 +145,18 @@ public abstract class RileyLinkCommunicationManager {
LOG.trace("Last pump communication was recent, not waking pump.");
}
// long lastGoodPlus = getLastGoodReceiverCommunicationTime() + (receiverDeviceAwakeForMinutes * 60 * 1000);
// long lastGoodPlus = getLastGoodReceiverCommunicationTime() + (receiverDeviceAwakeForMinutes * 60 * 1000);
//
// if (System.currentTimeMillis() > lastGoodPlus || force) {
// LOG.info("Waking pump...");
// if (System.currentTimeMillis() > lastGoodPlus || force) {
// LOG.info("Waking pump...");
//
// byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.PowerOn);
// RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 200, (byte) 0, (byte) 0, 15000, (byte) 0);
// LOG.info("wakeup: raw response is " + ByteUtil.shortHexString(resp.getRaw()));
// } else {
// LOG.trace("Last pump communication was recent, not waking pump.");
// }
// byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.PowerOn);
// RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 200, (byte)
// 0, (byte) 0, 15000, (byte) 0);
// LOG.info("wakeup: raw response is " + ByteUtil.shortHexString(resp.getRaw()));
// } else {
// LOG.trace("Last pump communication was recent, not waking pump.");
// }
}
@ -178,7 +171,8 @@ public abstract class RileyLinkCommunicationManager {
/**
* If user changes pump and one pump is running in US freq, and other in WW, then previously set frequency would be invalid,
* If user changes pump and one pump is running in US freq, and other in WW, then previously set frequency would be
* invalid,
* so we would need to retune. This checks that saved frequency is correct range.
*
* @param frequency
@ -217,7 +211,8 @@ public abstract class RileyLinkCommunicationManager {
for (int j = 0; j < tries; j++) {
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData);
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 0, (byte) 0, (byte) 0, 1500, (byte) 0);
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte)0, (byte)0,
(byte)0, (byte)0, 1500, (byte)0);
if (resp.wasTimeout()) {
LOG.error("scanForPump: Failed to find pump at frequency {}", frequencies[i]);
} else if (resp.looksLikeRadioPacket()) {
@ -234,17 +229,17 @@ public abstract class RileyLinkCommunicationManager {
trial.tries++;
}
sumRSSI += -99.0 * (trial.tries - trial.successes);
trial.averageRSSI = (double) (sumRSSI) / (double) (trial.tries);
trial.averageRSSI = (double)(sumRSSI) / (double)(trial.tries);
results.trials.add(trial);
}
StringBuilder stringBuilder = new StringBuilder("Scan results:\n");
for (int k = 0; k < results.trials.size(); k++) {
FrequencyTrial one = results.trials.get(k);
stringBuilder.append(String.format("Scan Result[%s]: Freq=%s, avg RSSI = %s\n", "" + k, "" + one.frequencyMHz, "" + one.averageRSSI));
stringBuilder.append(String.format("Scan Result[%s]: Freq=%s, avg RSSI = %s\n", "" + k, ""
+ one.frequencyMHz, "" + one.averageRSSI));
}
LOG.debug(stringBuilder.toString());
@ -268,10 +263,10 @@ public abstract class RileyLinkCommunicationManager {
private int tune_tryFrequency(double freqMHz) {
rfspy.setBaseFrequency(freqMHz);
//RLMessage msg = makeRLMessage(RLMessageType.ReadSimpleData);
// RLMessage msg = makeRLMessage(RLMessageType.ReadSimpleData);
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData);
RadioPacket pkt = new RadioPacket(pumpMsgContent);
RFSpyResponse resp = rfspy.transmitThenReceive(pkt, (byte) 0, (byte) 0, (byte) 0, (byte) 0, rfspy.EXPECTED_MAX_BLUETOOTH_LATENCY_MS, (byte) 0);
RFSpyResponse resp = rfspy.transmitThenReceive(pkt, (byte)0, (byte)0, (byte)0, (byte)0, 1500, (byte)0);
if (resp.wasTimeout()) {
LOG.warn("tune_tryFrequency: no pump response at frequency {}", freqMHz);
} else if (resp.looksLikeRadioPacket()) {
@ -280,7 +275,8 @@ public abstract class RileyLinkCommunicationManager {
LOG.warn("tune_tryFrequency: saw response level {} at frequency {}", radioResponse.rssi, freqMHz);
return radioResponse.rssi;
} else {
LOG.warn("tune_tryFrequency: invalid radio response:" + ByteUtil.shortHexString(radioResponse.getPayload()));
LOG.warn("tune_tryFrequency: invalid radio response:"
+ ByteUtil.shortHexString(radioResponse.getPayload()));
}
}
return 0;
@ -297,7 +293,7 @@ public abstract class RileyLinkCommunicationManager {
// Try again at larger step size
stepsize += 0.05;
} else {
if ((int) (evenBetterFrequency * 100) == (int) (betterFrequency * 100)) {
if ((int)(evenBetterFrequency * 100) == (int)(betterFrequency * 100)) {
// value did not change, so we're done.
break;
}

View file

@ -12,7 +12,7 @@ public class RileyLinkConst {
public static final String RileyLinkReady = Prefix + "RileyLink_Ready";
public static final String RileyLinkGattFailed = Prefix + "RileyLink_Gatt_Failed";
//public static final String RileyLinkError = Prefix + "RileyLink_Ready";
// public static final String RileyLinkError = Prefix + "RileyLink_Ready";
public static final String BluetoothConnected = Prefix + "Bluetooth_Connected";
public static final String BluetoothReconnected = Prefix + "Bluetooth_Reconnected";
@ -35,6 +35,7 @@ public class RileyLinkConst {
}
public class IPC {
// needs to br renamed (and maybe removed)
public static final String MSG_PUMP_quickTune = Prefix + "MSG_PUMP_quickTune";
public static final String MSG_PUMP_tunePump = Prefix + "MSG_PUMP_tunePump";

View file

@ -1,14 +1,14 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE;
@ -16,6 +16,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.Riley
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.RileyLinkService;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.data.ServiceNotification;
@ -25,7 +26,6 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
import info.nightscout.androidaps.plugins.PumpMedtronic.events.EventMedtronicDeviceStatusChange;
/**
* Created by andy on 17/05/2018.
*/
@ -33,22 +33,23 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.events.EventMedtronicDev
public class RileyLinkUtil {
private static final Logger LOG = LoggerFactory.getLogger(RileyLinkUtil.class);
protected static List<RLHistoryItem> historyRileyLink = new ArrayList<>();
protected static RileyLinkCommunicationManager rileyLinkCommunicationManager;
static ServiceTask currentTask;
private static Context context;
private static RileyLinkBLE rileyLinkBLE;
private static RileyLinkServiceData rileyLinkServiceData;
private static List<RLHistoryItem> historyRileyLink = new ArrayList<>();
//private static PumpType pumpType;
//private static MedtronicPumpStatus medtronicPumpStatus;
// private static PumpType pumpType;
// private static MedtronicPumpStatus medtronicPumpStatus;
private static RileyLinkService rileyLinkService;
protected static RileyLinkCommunicationManager rileyLinkCommunicationManager;
//private static RileyLinkIPCConnection rileyLinkIPCConnection;
// private static RileyLinkIPCConnection rileyLinkIPCConnection;
private static MedtronicDeviceType medtronicPumpModel;
private static RileyLinkTargetFrequency rileyLinkTargetFrequency;
//private static MedtronicPumpStatus pumpStatus;
// private static MedtronicPumpStatus pumpStatus;
// BAD dependencies in Classes: RileyLinkService
private static RileyLinkTargetFrequency rileyLinkTargetFrequency;
// Broadcasts: RileyLinkBLE, RileyLinkService,
private static RileyLinkTargetDevice targetDevice;
public static void setContext(Context contextIn) {
@ -62,13 +63,13 @@ public class RileyLinkUtil {
}
public static void setServiceState(RileyLinkServiceState newState) {
setServiceState(newState, null);
public static RileyLinkServiceState getServiceState() {
return RileyLinkUtil.rileyLinkServiceData.serviceState;
}
public static RileyLinkServiceState getServiceState() {
return RileyLinkUtil.rileyLinkServiceData.serviceState;
public static void setServiceState(RileyLinkServiceState newState) {
setServiceState(newState, null);
}
@ -81,23 +82,25 @@ public class RileyLinkUtil {
RileyLinkUtil.rileyLinkServiceData.serviceState = newState;
RileyLinkUtil.rileyLinkServiceData.errorCode = errorCode;
LOG.warn("RileyLink State Changed: {} {}", newState, errorCode == null ? "" : " - Error State: " + errorCode.name());
LOG.warn("RileyLink State Changed: {} {}", newState,
errorCode == null ? "" : " - Error State: " + errorCode.name());
RileyLinkUtil.historyRileyLink.add(new RLHistoryItem(RileyLinkUtil.rileyLinkServiceData.serviceState, RileyLinkUtil.rileyLinkServiceData.errorCode));
RileyLinkUtil.historyRileyLink.add(new RLHistoryItem(RileyLinkUtil.rileyLinkServiceData.serviceState,
RileyLinkUtil.rileyLinkServiceData.errorCode, targetDevice));
MainApp.bus().post(new EventMedtronicDeviceStatusChange(newState, errorCode));
}
public static void setRileyLinkBLE(RileyLinkBLE rileyLinkBLEIn) {
RileyLinkUtil.rileyLinkBLE = rileyLinkBLEIn;
}
public static RileyLinkBLE getRileyLinkBLE() {
return RileyLinkUtil.rileyLinkBLE;
}
public static void setRileyLinkBLE(RileyLinkBLE rileyLinkBLEIn) {
RileyLinkUtil.rileyLinkBLE = rileyLinkBLEIn;
}
public static RileyLinkServiceData getRileyLinkServiceData() {
return RileyLinkUtil.rileyLinkServiceData;
}
@ -113,18 +116,13 @@ public class RileyLinkUtil {
}
public static void setRileyLinkService(RileyLinkService rileyLinkService) {
RileyLinkUtil.rileyLinkService = rileyLinkService;
}
public static RileyLinkService getRileyLinkService() {
return RileyLinkUtil.rileyLinkService;
}
public static void setRileyLinkCommunicationManager(RileyLinkCommunicationManager rileyLinkCommunicationManager) {
RileyLinkUtil.rileyLinkCommunicationManager = rileyLinkCommunicationManager;
public static void setRileyLinkService(RileyLinkService rileyLinkService) {
RileyLinkUtil.rileyLinkService = rileyLinkService;
}
@ -133,13 +131,16 @@ public class RileyLinkUtil {
}
public static void setRileyLinkCommunicationManager(RileyLinkCommunicationManager rileyLinkCommunicationManager) {
RileyLinkUtil.rileyLinkCommunicationManager = rileyLinkCommunicationManager;
}
public static boolean sendNotification(ServiceNotification notification, Integer clientHashcode) {
return RileyLinkUtil.rileyLinkService.sendNotification(notification, clientHashcode);
}
static ServiceTask currentTask;
// FIXME remove ?
public static void setCurrentTask(ServiceTask task) {
if (currentTask == null) {
@ -170,14 +171,18 @@ public class RileyLinkUtil {
// make a new bundle to send as the message data
transport.setServiceResult(serviceResult);
// FIXME
//transport.setTransportType(RT2Const.IPC.MSG_ServiceResult);
//rileyLinkIPCConnection.sendTransport(transport, clientHashcode);
// transport.setTransportType(RT2Const.IPC.MSG_ServiceResult);
// rileyLinkIPCConnection.sendTransport(transport, clientHashcode);
}
// public static void setRileyLinkIPCConnection(RileyLinkIPCConnection rileyLinkIPCConnection) {
// RileyLinkUtil.rileyLinkIPCConnection = rileyLinkIPCConnection;
// }
// public static void setRileyLinkIPCConnection(RileyLinkIPCConnection rileyLinkIPCConnection) {
// RileyLinkUtil.rileyLinkIPCConnection = rileyLinkIPCConnection;
// }
public static RileyLinkTargetFrequency getRileyLinkTargetFrequency() {
return RileyLinkUtil.rileyLinkTargetFrequency;
}
public static void setRileyLinkTargetFrequency(RileyLinkTargetFrequency rileyLinkTargetFrequency) {
@ -185,15 +190,25 @@ public class RileyLinkUtil {
}
public static RileyLinkTargetFrequency getRileyLinkTargetFrequency() {
return RileyLinkUtil.rileyLinkTargetFrequency;
}
public static boolean isSame(Double d1, Double d2) {
double diff = d1 - d2;
return (Math.abs(diff) <= 0.000001);
}
public static List<RLHistoryItem> getRileyLinkHistory() {
return historyRileyLink;
}
public static RileyLinkTargetDevice getTargetDevice() {
return targetDevice;
}
public static void setTargetDevice(RileyLinkTargetDevice targetDevice) {
RileyLinkUtil.targetDevice = targetDevice;
}
}

View file

@ -1,11 +1,11 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble;
import android.os.SystemClock;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.UUID;
import android.os.SystemClock;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.GattAttributes;
@ -26,18 +26,13 @@ import info.nightscout.androidaps.plugins.PumpCommon.utils.ThreadUtil;
*/
public class RFSpy {
private static final Logger LOG = LoggerFactory.getLogger(RFSpy.class);
public static final long RILEYLINK_FREQ_XTAL = 24000000;
public static final int EXPECTED_MAX_BLUETOOTH_LATENCY_MS = 7500; // 1500
private static final Logger LOG = LoggerFactory.getLogger(RFSpy.class);
public int notConnectedCount = 0;
private RileyLinkBLE rileyLinkBle;
private RFSpyReader reader;
private RileyLinkTargetFrequency selectedTargetFrequency;
private UUID radioServiceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO);
private UUID radioDataUUID = UUID.fromString(GattAttributes.CHARA_RADIO_DATA);
private UUID radioVersionUUID = UUID.fromString(GattAttributes.CHARA_RADIO_VERSION);
@ -54,6 +49,7 @@ public class RFSpy {
// Starts an async task to read when data is available
public void startReader() {
rileyLinkBle.registerRadioResponseCountNotification(new Runnable() {
@Override
public void run() {
newDataIsAvailable();
@ -70,8 +66,6 @@ public class RFSpy {
}
public int notConnectedCount = 0;
// This gets the version from the BLE113, not from the CC1110.
// I.e., this gets the version from the BLE interface, not from the radio.
public String getVersion() {
@ -84,6 +78,7 @@ public class RFSpy {
}
}
public String getRadioVersion() {
RFSpyResponse resp = writeToData(RFSpyCommand.GetVersion, null, EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
if (resp == null) {
@ -105,19 +100,21 @@ public class RFSpy {
byte[] junkInBuffer = reader.poll(0);
while (junkInBuffer != null) {
LOG.warn(ThreadUtil.sig() + "writeToData: draining read queue, found this: " + ByteUtil.shortHexString(junkInBuffer));
LOG.warn(ThreadUtil.sig() + "writeToData: draining read queue, found this: "
+ ByteUtil.shortHexString(junkInBuffer));
junkInBuffer = reader.poll(0);
}
// prepend length, and send it.
byte[] prepended = ByteUtil.concat(new byte[]{(byte) (bytes.length)}, bytes);
BLECommOperationResult writeCheck = rileyLinkBle.writeCharacteristic_blocking(radioServiceUUID, radioDataUUID, prepended);
byte[] prepended = ByteUtil.concat(new byte[] { (byte)(bytes.length) }, bytes);
BLECommOperationResult writeCheck = rileyLinkBle.writeCharacteristic_blocking(radioServiceUUID, radioDataUUID,
prepended);
if (writeCheck.resultCode != BLECommOperationResult.RESULT_SUCCESS) {
LOG.error("BLE Write operation failed, code=" + writeCheck.resultCode);
return new RFSpyResponse(); // will be a null (invalid) response
}
SystemClock.sleep(100);
//Log.i(TAG,ThreadUtil.sig()+String.format(" writeToData:(timeout %d) %s",(responseTimeout_ms),ByteUtil.shortHexString(prepended)));
// Log.i(TAG,ThreadUtil.sig()+String.format(" writeToData:(timeout %d) %s",(responseTimeout_ms),ByteUtil.shortHexString(prepended)));
byte[] rawResponse = reader.poll(responseTimeout_ms);
RFSpyResponse resp = new RFSpyResponse(command, rawResponse);
if (rawResponse == null) {
@ -139,16 +136,18 @@ public class RFSpy {
LOG.info("writeToData: decoded radio response is " + ByteUtil.shortHexString(responsePayload));
resetNotConnectedCount();
}
//Log.i(TAG, "writeToData: raw response is " + ByteUtil.shortHexString(rawResponse));
// Log.i(TAG, "writeToData: raw response is " + ByteUtil.shortHexString(rawResponse));
}
}
return resp;
}
private void resetNotConnectedCount() {
this.notConnectedCount = 0;
}
private byte[] getByteArray(byte... input) {
return input;
}
@ -173,52 +172,60 @@ public class RFSpy {
public RFSpyResponse transmit(RadioPacket radioPacket) {
return transmit(radioPacket, (byte) 0, (byte) 0, (byte) 0xFF);
return transmit(radioPacket, (byte)0, (byte)0, (byte)0xFF);
}
public RFSpyResponse transmit(RadioPacket radioPacket, byte sendChannel, byte repeatCount, byte delay_ms) {
// append checksum, encode data, send it.
byte[] fullPacket = ByteUtil.concat(getByteArray(sendChannel, repeatCount, delay_ms), radioPacket.getEncoded());
RFSpyResponse response = writeToData(RFSpyCommand.Send, fullPacket, delay_ms + EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
RFSpyResponse response = writeToData(RFSpyCommand.Send, fullPacket, delay_ms
+ EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
return response;
}
public RFSpyResponse receive(byte listenChannel, int timeout_ms, byte retryCount) {
int receiveDelay = timeout_ms * (retryCount + 1);
byte[] listen = getByteArray(listenChannel, (byte) ((timeout_ms >> 24) & 0x0FF), (byte) ((timeout_ms >> 16) & 0x0FF), (byte) ((timeout_ms >> 8) & 0x0FF), (byte) (timeout_ms & 0x0FF), retryCount);
byte[] listen = getByteArray(listenChannel, (byte)((timeout_ms >> 24) & 0x0FF),
(byte)((timeout_ms >> 16) & 0x0FF), (byte)((timeout_ms >> 8) & 0x0FF), (byte)(timeout_ms & 0x0FF),
retryCount);
return writeToData(RFSpyCommand.GetPacket, listen, receiveDelay);
}
public RFSpyResponse transmitThenReceive(RadioPacket pkt, int timeout_ms) {
return transmitThenReceive(pkt, (byte) 0, (byte) 0, (byte) 0, (byte) 0, timeout_ms, (byte) 0);
return transmitThenReceive(pkt, (byte)0, (byte)0, (byte)0, (byte)0, timeout_ms, (byte)0);
}
public RFSpyResponse transmitThenReceive(RadioPacket pkt, byte sendChannel, byte repeatCount, byte delay_ms, byte listenChannel, int timeout_ms, byte retryCount) {
public RFSpyResponse transmitThenReceive(RadioPacket pkt, byte sendChannel, byte repeatCount, byte delay_ms,
byte listenChannel, int timeout_ms, byte retryCount) {
int sendDelay = repeatCount * delay_ms;
int receiveDelay = timeout_ms * (retryCount + 1);
byte[] sendAndListen = getByteArray(sendChannel, repeatCount, delay_ms, listenChannel, (byte) ((timeout_ms >> 24) & 0x0FF), (byte) ((timeout_ms >> 16) & 0x0FF), (byte) ((timeout_ms >> 8) & 0x0FF), (byte) (timeout_ms & 0x0FF), (byte) retryCount);
byte[] sendAndListen = getByteArray(sendChannel, repeatCount, delay_ms, listenChannel,
(byte)((timeout_ms >> 24) & 0x0FF), (byte)((timeout_ms >> 16) & 0x0FF), (byte)((timeout_ms >> 8) & 0x0FF),
(byte)(timeout_ms & 0x0FF), (byte)retryCount);
byte[] fullPacket = ByteUtil.concat(sendAndListen, pkt.getEncoded());
return writeToData(RFSpyCommand.SendAndListen, fullPacket, sendDelay + receiveDelay + EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
return writeToData(RFSpyCommand.SendAndListen, fullPacket, sendDelay + receiveDelay
+ EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
}
public RFSpyResponse updateRegister(CC111XRegister reg, int val) {
byte[] updateRegisterPkt = getByteArray(reg.value, (byte) val);
RFSpyResponse resp = writeToData(RFSpyCommand.UpdateRegister, updateRegisterPkt, EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
byte[] updateRegisterPkt = getByteArray(reg.value, (byte)val);
RFSpyResponse resp = writeToData(RFSpyCommand.UpdateRegister, updateRegisterPkt,
EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
return resp;
}
public void setBaseFrequency(double freqMHz) {
int value = (int) (freqMHz * 1000000 / ((double) (RILEYLINK_FREQ_XTAL) / Math.pow(2.0, 16.0)));
updateRegister(CC111XRegister.freq0, (byte) (value & 0xff));
updateRegister(CC111XRegister.freq1, (byte) ((value >> 8) & 0xff));
updateRegister(CC111XRegister.freq2, (byte) ((value >> 16) & 0xff));
int value = (int)(freqMHz * 1000000 / ((double)(RILEYLINK_FREQ_XTAL) / Math.pow(2.0, 16.0)));
updateRegister(CC111XRegister.freq0, (byte)(value & 0xff));
updateRegister(CC111XRegister.freq1, (byte)((value >> 8) & 0xff));
updateRegister(CC111XRegister.freq2, (byte)((value >> 16) & 0xff));
LOG.warn("Set frequency to {}", freqMHz);
configureRadioForRegion(RileyLinkUtil.getRileyLinkTargetFrequency());
@ -234,24 +241,24 @@ public class RFSpy {
switch (frequency) {
case Medtronic_WorldWide: {
setRXFilterMode(RXFilterMode.Wide);
//updateRegister(CC111X_MDMCFG3, (byte) 0x66);
//updateRegister(CC111X_MDMCFG2, (byte) 0x33);
// updateRegister(CC111X_MDMCFG3, (byte) 0x66);
// updateRegister(CC111X_MDMCFG2, (byte) 0x33);
updateRegister(CC111XRegister.mdmcfg1, 0x62);
updateRegister(CC111XRegister.mdmcfg0, 0x1A);
updateRegister(CC111XRegister.deviatn, 0x13);
}
break;
break;
case Medtronic_US: {
setRXFilterMode(RXFilterMode.Narrow);
//updateRegister(CC111X_MDMCFG3, (byte) 0x66);
//updateRegister(CC111X_MDMCFG2, (byte) 0x33);
// updateRegister(CC111X_MDMCFG3, (byte) 0x66);
// updateRegister(CC111X_MDMCFG2, (byte) 0x33);
updateRegister(CC111XRegister.mdmcfg1, 0x61);
updateRegister(CC111XRegister.mdmcfg0, 0x7E);
updateRegister(CC111XRegister.deviatn, 0x15);
}
break;
break;
case Omnipod: {
LOG.debug("No region configuration for RfSpy and {}", frequency.name());
@ -269,11 +276,10 @@ public class RFSpy {
private void setRXFilterMode(RXFilterMode mode) {
byte drate_e = (byte) 0x9; // exponent of symbol rate (16kbps)
byte drate_e = (byte)0x9; // exponent of symbol rate (16kbps)
byte chanbw = mode.value;
updateRegister(CC111XRegister.mdmcfg4, (byte) (chanbw | drate_e));
updateRegister(CC111XRegister.mdmcfg4, (byte)(chanbw | drate_e));
}
}

View file

@ -1,16 +1,16 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble;
import android.os.AsyncTask;
import android.os.SystemClock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.UUID;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.os.AsyncTask;
import android.os.SystemClock;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.GattAttributes;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations.BLECommOperationResult;
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
@ -22,24 +22,23 @@ import info.nightscout.androidaps.plugins.PumpCommon.utils.ThreadUtil;
public class RFSpyReader {
private static final Logger LOG = LoggerFactory.getLogger(RFSpyReader.class);
//private Context context;
AsyncTask<Void, Void, Void> readerTask;
// private Context context;
private RileyLinkBLE rileyLinkBle;
private Semaphore waitForRadioData = new Semaphore(0, true);
AsyncTask<Void, Void, Void> readerTask;
private LinkedBlockingQueue<byte[]> mDataQueue = new LinkedBlockingQueue<>();
private int acquireCount = 0;
private int releaseCount = 0;
public RFSpyReader(/*Context context,*/ RileyLinkBLE rileyLinkBle) {
//this.context = context;
public RFSpyReader(/* Context context, */RileyLinkBLE rileyLinkBle) {
// this.context = context;
this.rileyLinkBle = rileyLinkBle;
}
public void init(/*Context context,*/ RileyLinkBLE rileyLinkBLE) {
//this.context = context;
public void init(/* Context context, */RileyLinkBLE rileyLinkBLE) {
// this.context = context;
this.rileyLinkBle = rileyLinkBLE;
}
@ -54,14 +53,16 @@ public class RFSpyReader {
// This timeout must be coordinated with the length of the RFSpy radio operation or Bad Things Happen.
public byte[] poll(int timeout_ms) {
LOG.trace(ThreadUtil.sig() + "Entering poll at t==" + SystemClock.uptimeMillis() + ", timeout is " + timeout_ms + " mDataQueue size is " + mDataQueue.size());
LOG.trace(ThreadUtil.sig() + "Entering poll at t==" + SystemClock.uptimeMillis() + ", timeout is " + timeout_ms
+ " mDataQueue size is " + mDataQueue.size());
if (mDataQueue.isEmpty())
try {
// block until timeout or data available.
// returns null if timeout.
byte[] dataFromQueue = mDataQueue.poll(timeout_ms, TimeUnit.MILLISECONDS);
if (dataFromQueue != null) {
LOG.debug("Got data [" + ByteUtil.shortHexString(dataFromQueue) + "] at t==" + SystemClock.uptimeMillis());
LOG.debug("Got data [" + ByteUtil.shortHexString(dataFromQueue) + "] at t=="
+ SystemClock.uptimeMillis());
} else {
LOG.debug("Got data [null] at t==" + SystemClock.uptimeMillis());
}
@ -77,13 +78,15 @@ public class RFSpyReader {
public void newDataIsAvailable() {
releaseCount++;
LOG.trace(ThreadUtil.sig() + "waitForRadioData released(count=" + releaseCount + ") at t=" + SystemClock.uptimeMillis());
LOG.trace(ThreadUtil.sig() + "waitForRadioData released(count=" + releaseCount + ") at t="
+ SystemClock.uptimeMillis());
waitForRadioData.release();
}
public void start() {
readerTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
UUID serviceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO);
@ -93,7 +96,8 @@ public class RFSpyReader {
try {
acquireCount++;
waitForRadioData.acquire();
LOG.trace(ThreadUtil.sig() + "waitForRadioData acquired (count=" + acquireCount + ") at t=" + SystemClock.uptimeMillis());
LOG.trace(ThreadUtil.sig() + "waitForRadioData acquired (count=" + acquireCount + ") at t="
+ SystemClock.uptimeMillis());
SystemClock.sleep(100);
SystemClock.sleep(1);
result = rileyLinkBle.readCharacteristic_blocking(serviceUUID, radioDataUUID);
@ -101,7 +105,7 @@ public class RFSpyReader {
if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) {
// only data up to the first null is valid
for(int i = 0; i < result.value.length; i++) {
for (int i = 0; i < result.value.length; i++) {
if (result.value[i] == 0) {
result.value = ByteUtil.substring(result.value, 0, i);
break;

View file

@ -1,10 +1,10 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble;
import java.util.ArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC;
@ -13,17 +13,18 @@ import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC;
*/
public class RFTools {
public static final byte[] codes = new byte[] { 21, 49, 50, 35, 52, 37, 38, 22, 26, 25, 42, 11, 44, 13, 14, 28 };
private static final Logger LOG = LoggerFactory.getLogger(RFTools.class);
private final static char[] HEX_DIGITS = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
/*
CodeSymbols is an ordered list of translations
6bits -> 4 bits, in order from 0x0 to 0xF
The 6 bit codes are what is used on the RF side of the RileyLink
to communicate with a Medtronic pump.
* CodeSymbols is an ordered list of translations
* 6bits -> 4 bits, in order from 0x0 to 0xF
* The 6 bit codes are what is used on the RF side of the RileyLink
* to communicate with a Medtronic pump.
*/
public static byte[] CodeSymbols = {0x15, 0x31, 0x32, 0x23, 0x34, 0x25, 0x26, 0x16, 0x1a, 0x19, 0x2a, 0x0b, 0x2c, 0x0d, 0x0e, 0x1c};
public static byte[] CodeSymbols = {
0x15, 0x31, 0x32, 0x23, 0x34, 0x25, 0x26, 0x16, 0x1a, 0x19, 0x2a, 0x0b, 0x2c, 0x0d, 0x0e, 0x1c };
public static byte[] appendChecksum(final byte[] input) {
@ -36,15 +37,51 @@ public class RFTools {
byte[] rval = new byte[input.length + 1];
System.arraycopy(input, 0, rval, 0, input.length);
byte mycrc = CRC.crc8(input);
LOG.debug(String.format("Adding checksum 0x%02X to %d byte array from 0x%02X to 0x%02X", mycrc, input.length, input[0], input[input.length - 1]));
LOG.debug(String.format("Adding checksum 0x%02X to %d byte array from 0x%02X to 0x%02X", mycrc, input.length,
input[0], input[input.length - 1]));
rval[input.length] = mycrc;
return rval;
}
/*
* + (NSData*)encode4b6b:(NSData*)data {
* NSMutableData *outData = [NSMutableData data];
* NSMutableData *dataPlusCrc = [data mutableCopy];
* unsigned char crc = [MinimedPacket crcForData:data];
* [dataPlusCrc appendBytes:&crc length:1];
* char codes[16] = {21,49,50,35,52,37,38,22,26,25,42,11,44,13,14,28};
* const unsigned char *inBytes = [dataPlusCrc bytes];
* unsigned int acc = 0x0;
* int bitcount = 0;
* for (int i=0; i < dataPlusCrc.length; i++) {
* acc <<= 6;
* acc |= codes[inBytes[i] >> 4];
* bitcount += 6;
*
* acc <<= 6;
* acc |= codes[inBytes[i] & 0x0f];
* bitcount += 6;
*
* while (bitcount >= 8) {
* unsigned char outByte = acc >> (bitcount-8) & 0xff;
* [outData appendBytes:&outByte length:1];
* bitcount -= 8;
* acc &= (0xffff >> (16-bitcount));
* }
* }
* if (bitcount > 0) {
* acc <<= (8-bitcount);
* unsigned char outByte = acc & 0xff;
* [outData appendBytes:&outByte length:1];
* }
* return outData;
* }
*/
public static ArrayList<Byte> fromBytes(byte[] data) {
ArrayList<Byte> rval = new ArrayList<>();
for(int i = 0; i < data.length; i++) {
for (int i = 0; i < data.length; i++) {
rval.add(data[i]);
}
return rval;
@ -53,53 +90,16 @@ public class RFTools {
public static byte[] toBytes(ArrayList<Byte> data) {
byte[] rval = new byte[data.size()];
for(int i = 0; i < data.size(); i++) {
for (int i = 0; i < data.size(); i++) {
rval[i] = data.get(i);
}
return rval;
}
/*
+ (NSData*)encode4b6b:(NSData*)data {
NSMutableData *outData = [NSMutableData data];
NSMutableData *dataPlusCrc = [data mutableCopy];
unsigned char crc = [MinimedPacket crcForData:data];
[dataPlusCrc appendBytes:&crc length:1];
char codes[16] = {21,49,50,35,52,37,38,22,26,25,42,11,44,13,14,28};
const unsigned char *inBytes = [dataPlusCrc bytes];
unsigned int acc = 0x0;
int bitcount = 0;
for (int i=0; i < dataPlusCrc.length; i++) {
acc <<= 6;
acc |= codes[inBytes[i] >> 4];
bitcount += 6;
acc <<= 6;
acc |= codes[inBytes[i] & 0x0f];
bitcount += 6;
while (bitcount >= 8) {
unsigned char outByte = acc >> (bitcount-8) & 0xff;
[outData appendBytes:&outByte length:1];
bitcount -= 8;
acc &= (0xffff >> (16-bitcount));
}
}
if (bitcount > 0) {
acc <<= (8-bitcount);
unsigned char outByte = acc & 0xff;
[outData appendBytes:&outByte length:1];
}
return outData;
}
*/
public static final byte[] codes = new byte[]{21, 49, 50, 35, 52, 37, 38, 22, 26, 25, 42, 11, 44, 13, 14, 28};
/* O(n) lookup. Run on an O(n) translation of a byte-stream, gives O(n**2) performance. Sigh. */
/* O(n) lookup. Run on an O(n) translation of a byte-stream, gives O(n**2) performance. Sigh. */
public static int codeIndex(byte b) {
for(int i = 0; i < codes.length; i++) {
for (int i = 0; i < codes.length; i++) {
if (b == codes[i]) {
return i;
}
@ -119,7 +119,7 @@ public class RFTools {
int acc = 0;
int bitcount = 0;
int i;
for(i = 0; i < inData.size(); i++) {
for (i = 0; i < inData.size(); i++) {
acc <<= 6;
acc |= codes[(inData.get(i) >> 4) & 0x0f];
bitcount += 6;
@ -129,7 +129,7 @@ public class RFTools {
bitcount += 6;
while (bitcount >= 8) {
byte outByte = (byte) (acc >> (bitcount - 8) & 0xff);
byte outByte = (byte)(acc >> (bitcount - 8) & 0xff);
outData.add(outByte);
bitcount -= 8;
acc &= (0xffff >> (16 - bitcount));
@ -140,18 +140,17 @@ public class RFTools {
acc |= 0x14; // marks uneven packet boundary.
bitcount += 6;
if (bitcount >= 8) {
byte outByte = (byte) ((acc >> (bitcount - 8)) & 0xff);
byte outByte = (byte)((acc >> (bitcount - 8)) & 0xff);
outData.add(outByte);
bitcount -= 8;
// acc &= (0xffff >> (16 - bitcount));
}
while (bitcount >= 8) {
outData.add((byte) 0);
outData.add((byte)0);
bitcount -= 8;
}
}
// convert back to byte[]
byte[] rval = toBytes(outData);
@ -162,14 +161,14 @@ public class RFTools {
public static void test() {
/*
{0xa7} -> {0xa9, 0x60}
{0xa7, 0x12} -> {0xa9, 0x6c, 0x72}
{0xa7, 0x12, 0xa7} -> {0xa9, 0x6c, 0x72, 0xa9, 0x60}
*/
* {0xa7} -> {0xa9, 0x60}
* {0xa7, 0x12} -> {0xa9, 0x6c, 0x72}
* {0xa7, 0x12, 0xa7} -> {0xa9, 0x6c, 0x72, 0xa9, 0x60}
*/
/* test compare */
byte[] s1 = {0, 1, 2};
byte[] s2 = {2, 1, 0, 3};
byte[] s3 = {0, 1, 2, 3};
byte[] s1 = { 0, 1, 2 };
byte[] s2 = { 2, 1, 0, 3 };
byte[] s3 = { 0, 1, 2, 3 };
if (ByteUtil.compare(s1, s1) != 0) {
LOG.error("test: compare failed.");
}
@ -182,21 +181,24 @@ public class RFTools {
if (ByteUtil.compare(s1, s3) >= 0) {
LOG.error("test: compare failed.");
}
//testCompose(new byte[] {(byte)0xa7, (byte)0xa7});
byte[] bs = encode4b6b(new byte[]{(byte) 0xa7});
byte[] out = new byte[]{(byte) (0xa9), 0x65};
// testCompose(new byte[] {(byte)0xa7, (byte)0xa7});
byte[] bs = encode4b6b(new byte[] { (byte)0xa7 });
byte[] out = new byte[] { (byte)(0xa9), 0x65 };
if (ByteUtil.compare(bs, out) != 0) {
LOG.error("encode Data failed: expected " + ByteUtil.shortHexString(out) + " but got " + ByteUtil.shortHexString(bs));
LOG.error("encode Data failed: expected " + ByteUtil.shortHexString(out) + " but got "
+ ByteUtil.shortHexString(bs));
}
bs = encode4b6b(new byte[]{(byte) 0xa7, 0x12});
out = new byte[]{(byte) (0xa9), 0x6c, 0x72};
bs = encode4b6b(new byte[] { (byte)0xa7, 0x12 });
out = new byte[] { (byte)(0xa9), 0x6c, 0x72 };
if (ByteUtil.compare(bs, out) != 0) {
LOG.error("encode Data failed: expected " + ByteUtil.shortHexString(out) + " but got " + ByteUtil.shortHexString(bs));
LOG.error("encode Data failed: expected " + ByteUtil.shortHexString(out) + " but got "
+ ByteUtil.shortHexString(bs));
}
bs = encode4b6b(new byte[]{(byte) 0xa7, 0x12, (byte) 0xa7});
out = new byte[]{(byte) (0xa9), 0x6c, 0x72, (byte) 0xa9, 0x65};
bs = encode4b6b(new byte[] { (byte)0xa7, 0x12, (byte)0xa7 });
out = new byte[] { (byte)(0xa9), 0x6c, 0x72, (byte)0xa9, 0x65 };
if (ByteUtil.compare(bs, out) != 0) {
LOG.error("encode Data failed: expected " + ByteUtil.shortHexString(out) + " but got " + ByteUtil.shortHexString(bs));
LOG.error("encode Data failed: expected " + ByteUtil.shortHexString(out) + " but got "
+ ByteUtil.shortHexString(bs));
}
return;
}
@ -204,17 +206,17 @@ public class RFTools {
public static byte[] decode4b6b(byte[] raw) throws NumberFormatException {
/*
if ((raw.length % 2) != 0) {
LOG.error("Warning: data is odd number of bytes");
}
*/
byte[] rval = new byte[]{};
* if ((raw.length % 2) != 0) {
* LOG.error("Warning: data is odd number of bytes");
* }
*/
byte[] rval = new byte[] {};
int availableBits = 0;
int codingErrors = 0;
int x = 0;
//Log.w(TAG,"decode4b6b: untested code");
//Log.w(TAG,String.format("Decoding %d bytes: %s",raw.length,ByteUtil.shortHexString(raw)));
for(int i = 0; i < raw.length; i++) {
// Log.w(TAG,"decode4b6b: untested code");
// Log.w(TAG,String.format("Decoding %d bytes: %s",raw.length,ByteUtil.shortHexString(raw)));
for (int i = 0; i < raw.length; i++) {
int unsignedValue = raw[i];
if (unsignedValue < 0) {
unsignedValue += 256;
@ -224,27 +226,31 @@ public class RFTools {
if (availableBits >= 12) {
// take top six
int highcode = (x >> (availableBits - 6)) & 0x3F;
int highIndex = codeIndex((byte) (highcode));
int highIndex = codeIndex((byte)(highcode));
// take bottom six
int lowcode = (x >> (availableBits - 12)) & 0x3F;
int lowIndex = codeIndex((byte) (lowcode));
int lowIndex = codeIndex((byte)(lowcode));
// special case at end of transmission on uneven boundaries:
if ((highIndex >= 0) && (lowIndex >= 0)) {
byte decoded = (byte) ((highIndex << 4) + lowIndex);
byte decoded = (byte)((highIndex << 4) + lowIndex);
rval = ByteUtil.concat(rval, decoded);
/*
LOG.debug(String.format("i=%d,x=0x%08X,0x%02X->0x%02X, 0x%02X->0x%02X, result: 0x%02X, %d bits remaining, errors %d, bytes remaining: %s",
i,x,highcode,highIndex, lowcode, lowIndex,decoded,availableBits,codingErrors,ByteUtil.shortHexString(ByteUtil.substring(raw,i+1,raw.length-i-1))));
*/
* LOG.debug(String.format(
* "i=%d,x=0x%08X,0x%02X->0x%02X, 0x%02X->0x%02X, result: 0x%02X, %d bits remaining, errors %d, bytes remaining: %s"
* ,
* i,x,highcode,highIndex, lowcode,
* lowIndex,decoded,availableBits,codingErrors,ByteUtil.shortHexString
* (ByteUtil.substring(raw,i+1,raw.length-i-1))));
*/
} else {
//LOG.debug(String.format("i=%d,x=%08X, coding error: highcode=0x%02X, lowcode=0x%02X, %d bits remaining",i,x,highcode,lowcode,availableBits));
// LOG.debug(String.format("i=%d,x=%08X, coding error: highcode=0x%02X, lowcode=0x%02X, %d bits remaining",i,x,highcode,lowcode,availableBits));
codingErrors++;
}
availableBits -= 12;
x = x & (0x0000ffff >> (16 - availableBits));
} else {
//LOG.debug(String.format("i=%d, skip: x=0x%08X, available bits %d",i,x,availableBits));
// LOG.debug(String.format("i=%d, skip: x=0x%08X, available bits %d",i,x,availableBits));
}
}
if (availableBits != 0) {
@ -270,14 +276,11 @@ public class RFTools {
}
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 toHexString(byte[] array, int offset, int length) {
char[] buf = new char[length * 2];
int bufIndex = 0;
for(int i = offset; i < offset + length; i++) {
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];
@ -286,5 +289,4 @@ public class RFTools {
return new String(buf);
}
}

View file

@ -1,5 +1,13 @@
package info.nightscout.androidaps.plugins.PumpCommon.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;
@ -12,14 +20,6 @@ import android.content.Context;
import android.os.SystemClock;
import android.widget.Toast;
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.plugins.PumpCommon.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.GattAttributes;
@ -40,22 +40,16 @@ import info.nightscout.androidaps.plugins.PumpCommon.utils.ThreadUtil;
public class RileyLinkBLE {
private static final Logger LOG = LoggerFactory.getLogger(RFTools.class);
private final Context context;
public boolean gattDebugEnabled = true;
boolean manualDisconnect = false;
private BluetoothAdapter bluetoothAdapter;
private BluetoothGattCallback bluetoothGattCallback;
private final Context context;
private BluetoothDevice rileyLinkDevice;
private BluetoothGatt bluetoothConnectionGatt = null;
private BLECommOperation mCurrentOperation;
private Semaphore gattOperationSema = new Semaphore(1, true);
private Runnable radioResponseCountNotified;
private boolean mIsConnected = false;
@ -67,10 +61,13 @@ public class RileyLinkBLE {
bluetoothGattCallback = new BluetoothGattCallback() {
@Override
public void onCharacteristicChanged(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {
public void onCharacteristicChanged(final BluetoothGatt gatt,
final BluetoothGattCharacteristic characteristic) {
super.onCharacteristicChanged(gatt, characteristic);
if (gattDebugEnabled) {
LOG.trace(ThreadUtil.sig() + "onCharacteristicChanged " + GattAttributes.lookup(characteristic.getUuid()) + " " + HexDump.toHexString(characteristic.getValue()));
LOG.trace(ThreadUtil.sig() + "onCharacteristicChanged "
+ GattAttributes.lookup(characteristic.getUuid()) + " "
+ HexDump.toHexString(characteristic.getValue()));
if (characteristic.getUuid().equals(UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT))) {
LOG.debug("Response Count is " + HexDump.toHexString(characteristic.getValue()));
}
@ -82,25 +79,29 @@ public class RileyLinkBLE {
@Override
public void onCharacteristicRead(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, int status) {
public void onCharacteristicRead(final BluetoothGatt gatt,
final BluetoothGattCharacteristic characteristic, int status) {
super.onCharacteristicRead(gatt, characteristic, status);
final String statusMessage = getGattStatusMessage(status);
if (gattDebugEnabled) {
LOG.trace(ThreadUtil.sig() + "onCharacteristicRead (" + GattAttributes.lookup(characteristic.getUuid()) + ") " + statusMessage + ":" + HexDump.toHexString(characteristic.getValue()));
LOG.trace(ThreadUtil.sig() + "onCharacteristicRead ("
+ GattAttributes.lookup(characteristic.getUuid()) + ") " + statusMessage + ":"
+ HexDump.toHexString(characteristic.getValue()));
}
mCurrentOperation.gattOperationCompletionCallback(characteristic.getUuid(), characteristic.getValue());
}
@Override
public void onCharacteristicWrite(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, int status) {
public void onCharacteristicWrite(final BluetoothGatt gatt,
final BluetoothGattCharacteristic characteristic, int status) {
super.onCharacteristicWrite(gatt, characteristic, status);
final String uuidString = GattAttributes.lookup(characteristic.getUuid());
if (gattDebugEnabled) {
LOG.trace(ThreadUtil.sig() + "onCharacteristicWrite " + getGattStatusMessage(status) + " " + uuidString + " " + HexDump.toHexString(characteristic.getValue()));
LOG.trace(ThreadUtil.sig() + "onCharacteristicWrite " + getGattStatusMessage(status) + " "
+ uuidString + " " + HexDump.toHexString(characteristic.getValue()));
}
mCurrentOperation.gattOperationCompletionCallback(characteristic.getUuid(), characteristic.getValue());
}
@ -142,8 +143,9 @@ public class RileyLinkBLE {
}
} else if ((newState == BluetoothProfile.STATE_CONNECTING) || //
(newState == BluetoothProfile.STATE_DISCONNECTING)) {
//LOG.debug("We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" : "Disconnecting");
(newState == BluetoothProfile.STATE_DISCONNECTING)) {
// LOG.debug("We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" :
// "Disconnecting");
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnected);
if (manualDisconnect)
@ -159,7 +161,8 @@ public class RileyLinkBLE {
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
super.onDescriptorWrite(gatt, descriptor, status);
if (gattDebugEnabled) {
LOG.warn("onDescriptorWrite " + GattAttributes.lookup(descriptor.getUuid()) + " " + getGattStatusMessage(status) + " written: " + HexDump.toHexString(descriptor.getValue()));
LOG.warn("onDescriptorWrite " + GattAttributes.lookup(descriptor.getUuid()) + " "
+ getGattStatusMessage(status) + " written: " + HexDump.toHexString(descriptor.getValue()));
}
mCurrentOperation.gattOperationCompletionCallback(descriptor.getUuid(), descriptor.getValue());
}
@ -232,10 +235,12 @@ public class RileyLinkBLE {
if (rileyLinkFound) {
mIsConnected = true;
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkReady);
//RileyLinkUtil.sendNotification(new ServiceNotification(RileyLinkConst.Intents.RileyLinkReady), null);
// RileyLinkUtil.sendNotification(new
// ServiceNotification(RileyLinkConst.Intents.RileyLinkReady), null);
} else {
mIsConnected = false;
RileyLinkUtil.setServiceState(RileyLinkServiceState.RileyLinkError, RileyLinkError.DeviceIsNotRileyLink);
RileyLinkUtil.setServiceState(RileyLinkServiceState.RileyLinkError,
RileyLinkError.DeviceIsNotRileyLink);
}
} else {
@ -309,7 +314,7 @@ public class RileyLinkBLE {
debugService(serviceI, indentCount + 4);
}
}
//}
// }
}
@ -336,7 +341,7 @@ public class RileyLinkBLE {
public boolean enableNotifications() {
BLECommOperationResult result = setNotification_blocking(UUID.fromString(GattAttributes.SERVICE_RADIO), //
UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT));
UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT));
if (result.resultCode != BLECommOperationResult.RESULT_SUCCESS) {
LOG.error("Error setting response count notification");
return false;
@ -369,9 +374,6 @@ public class RileyLinkBLE {
}
boolean manualDisconnect = false;
public void disconnect() {
mIsConnected = false;
LOG.warn("Closing GATT connection");
@ -380,8 +382,8 @@ public class RileyLinkBLE {
// Not sure if to disconnect or to close first..
bluetoothConnectionGatt.disconnect();
manualDisconnect = true;
//bluetoothConnectionGatt.close();
//bluetoothConnectionGatt = null;
// bluetoothConnectionGatt.close();
// bluetoothConnectionGatt = null;
}
}
@ -414,7 +416,8 @@ public class RileyLinkBLE {
LOG.error("BT Device not supported");
// TODO: 11/07/2016 UI update for user
} else {
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic(charaUUID);
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID)
.getCharacteristic(charaUUID);
// Tell Android that we want the notifications
bluetoothConnectionGatt.setCharacteristicNotification(chara, true);
List<BluetoothGattDescriptor> list = chara.getDescriptors();
@ -425,7 +428,8 @@ public class RileyLinkBLE {
}
BluetoothGattDescriptor descr = list.get(0);
// Tell the remote device to send the notifications
mCurrentOperation = new DescriptorWriteOperation(bluetoothConnectionGatt, descr, BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mCurrentOperation = new DescriptorWriteOperation(bluetoothConnectionGatt, descr,
BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mCurrentOperation.execute(this);
if (mCurrentOperation.timedOut) {
rval.resultCode = BLECommOperationResult.RESULT_TIMEOUT;
@ -464,14 +468,15 @@ public class RileyLinkBLE {
} else {
if (bluetoothConnectionGatt.getService(serviceUUID) == null) {
// Catch if the service is not supported by the BLE device
// GGW: Tue Jul 12 01:14:01 UTC 2016: This can also happen if the
// GGW: Tue Jul 12 01:14:01 UTC 2016: This can also happen if the
// app that created the bluetoothConnectionGatt has been destroyed/created,
// e.g. when the user switches from portrait to landscape.
rval.resultCode = BLECommOperationResult.RESULT_NONE;
LOG.error("BT Device not supported");
// TODO: 11/07/2016 UI update for user
} else {
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic(charaUUID);
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID)
.getCharacteristic(charaUUID);
mCurrentOperation = new CharacteristicWriteOperation(bluetoothConnectionGatt, chara, value);
mCurrentOperation.execute(this);
if (mCurrentOperation.timedOut) {
@ -506,7 +511,8 @@ public class RileyLinkBLE {
if (mCurrentOperation != null) {
rval.resultCode = BLECommOperationResult.RESULT_BUSY;
} else {
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic(charaUUID);
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic(
charaUUID);
mCurrentOperation = new CharacteristicReadOperation(bluetoothConnectionGatt, chara);
mCurrentOperation.execute(this);
if (mCurrentOperation.timedOut) {
@ -545,5 +551,4 @@ public class RileyLinkBLE {
return statusMessage;
}
}

View file

@ -8,11 +8,14 @@ import java.util.Comparator;
* Created by geoff on 5/30/16.
*/
public class FrequencyScanResults {
public ArrayList<FrequencyTrial> trials = new ArrayList<>();
public double bestFrequencyMHz = 0.0;
public void sort() {
Collections.sort(trials, new Comparator<FrequencyTrial>() {
@Override
public int compare(FrequencyTrial trial1, FrequencyTrial trial2) {
return trial1.averageRSSI.compareTo(trial2.averageRSSI);

View file

@ -4,6 +4,7 @@ package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data;
* Created by geoff on 5/30/16.
*/
public class FrequencyTrial {
public int tries = 0;
public int successes = 0;
public Double averageRSSI = 0.0;

View file

@ -41,7 +41,6 @@ public class GattAttributes {
attributes.put(CHARA_GAP_NAME, "Name"); //
attributes.put(CHARA_GAP_NUM, "Number"); //
attributes.put(SERVICE_BATTERY, "Battery Service");
attributes.put(SERVICE_RADIO, "Radio Interface"); // a
@ -85,5 +84,4 @@ public class GattAttributes {
return attributesRileyLinkSpecific.containsKey(uuid.toString());
}
}

View file

@ -6,6 +6,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RFSpy
* Created by geoff on 5/26/16.
*/
public class RFSpyResponse {
// 0xaa == timeout
// 0xbb == interrupted
// 0xcc == zero-data
@ -53,7 +54,7 @@ public class RFSpyResponse {
public boolean wasTimeout() {
if ((raw.length == 1) || (raw.length == 2)) {
if (raw[0] == (byte) 0xaa) {
if (raw[0] == (byte)0xaa) {
return true;
}
}
@ -63,7 +64,7 @@ public class RFSpyResponse {
public boolean wasInterrupted() {
if ((raw.length == 1) || (raw.length == 2)) {
if (raw[0] == (byte) 0xbb) {
if (raw[0] == (byte)0xbb) {
return true;
}
}
@ -73,7 +74,7 @@ public class RFSpyResponse {
public boolean isOK() {
if ((raw.length == 1) || (raw.length == 2)) {
if (raw[0] == (byte) 0x01) {
if (raw[0] == (byte)0x01) {
return true;
}
}

View file

@ -7,6 +7,7 @@ public interface RLMessage {
byte[] getTxData();
boolean isValid();
}

View file

@ -9,6 +9,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC;
*/
public class RadioPacket {
protected byte[] pkt;
@ -21,15 +22,17 @@ public class RadioPacket {
return pkt;
}
public byte[] getWithCRC() {
byte[] withCRC = ByteUtil.concat(pkt, CRC.crc8(pkt));
return withCRC;
}
public byte[] getEncoded() {
byte[] withCRC = ByteUtil.concat(pkt, CRC.crc8(pkt));
byte[] encoded = RFTools.encode4b6b(withCRC);
byte[] withNullTerm = ByteUtil.concat(encoded, (byte) 0);
byte[] withNullTerm = ByteUtil.concat(encoded, (byte)0);
return withNullTerm;
}

View file

@ -31,6 +31,7 @@ public class RadioResponse {
init(rxData);
}
public RadioResponse(RFSpyCommand command, byte[] raw) {
this.command = command;
@ -40,12 +41,10 @@ public class RadioResponse {
public boolean isValid() {
if (command!=null && !command.isEncoded())
{
if (command != null && !command.isEncoded()) {
return true;
}
if (!decodedOK) {
return false;
}
@ -71,7 +70,7 @@ public class RadioResponse {
byte[] encodedPayload = ByteUtil.substring(rxData, 2, rxData.length - 2);
try {
boolean isEncoded = command==null || command.isEncoded();
boolean isEncoded = command == null || command.isEncoded();
if (isEncoded) {
byte[] decodeThis = RFTools.decode4b6b(encodedPayload);
@ -80,15 +79,15 @@ public class RadioResponse {
byte calculatedCRC = CRC.crc8(decodedPayload);
receivedCRC = decodeThis[decodeThis.length - 1];
if (receivedCRC != calculatedCRC) {
LOG.error(String.format("RadioResponse: CRC mismatch, calculated 0x%02x, received 0x%02x", calculatedCRC, receivedCRC));
LOG.error(String.format("RadioResponse: CRC mismatch, calculated 0x%02x, received 0x%02x",
calculatedCRC, receivedCRC));
}
}
else {
} else {
decodedOK = true;
decodedPayload = encodedPayload;
}
//byte[] decodeThis = RFTools.decode4b6b(encodedPayload);
// byte[] decodeThis = RFTools.decode4b6b(encodedPayload);
} catch (NumberFormatException e) {
decodedOK = false;
LOG.error("Failed to decode radio data: " + ByteUtil.shortHexString(encodedPayload));

View file

@ -37,11 +37,12 @@ public enum CC111XRegister {
paTable0(0x2e), //
;
public byte value;
CC111XRegister(int value) {
this.value = (byte) value;
this.value = (byte)value;
}
}

View file

@ -21,12 +21,12 @@ public enum RFSpyCommand {
RFSpyCommand(int code) {
this.code = (byte) code;
this.code = (byte)code;
}
RFSpyCommand(int code, boolean encoded) {
this.code = (byte) code;
this.code = (byte)code;
this.encoded = encoded;
}

View file

@ -14,6 +14,6 @@ public enum RXFilterMode {
RXFilterMode(int value) {
this.value = (byte) value;
this.value = (byte)value;
}
}

View file

@ -25,8 +25,7 @@ public enum RileyLinkTargetFrequency {
public double[] getScanFrequencies() {
if (maxFrequency == minFrequency)
{
if (maxFrequency == minFrequency) {
double freq[] = new double[1];
freq[0] = minFrequency;
@ -35,11 +34,11 @@ public enum RileyLinkTargetFrequency {
double diff = maxFrequency - minFrequency;
int count = (int) (diff / step);
int count = (int)(diff / step);
double freq[] = new double[count];
for(int i = 0; i < count; i++) {
for (int i = 0; i < count; i++) {
freq[i] = (minFrequency + (i * step));
}

View file

@ -1,10 +1,10 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations;
import android.bluetooth.BluetoothGatt;
import java.util.UUID;
import java.util.concurrent.Semaphore;
import android.bluetooth.BluetoothGatt;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE;
/**
@ -18,16 +18,20 @@ public abstract class BLECommOperation {
protected BluetoothGatt gatt;
protected Semaphore operationComplete = new Semaphore(0, true);
// This is to be run on the main thread
public abstract void execute(RileyLinkBLE comm);
public void gattOperationCompletionCallback(UUID uuid, byte[] value) {
}
public int getGattOperationTimeout_ms() {
return 22000;
}
public byte[] getValue() {
return value;
}

View file

@ -4,8 +4,6 @@ package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operation
* Created by geoff on 5/26/16.
*/
public class BLECommOperationResult {
public byte[] value;
public int resultCode;
public static final int RESULT_NONE = 0;
public static final int RESULT_SUCCESS = 1;
@ -13,4 +11,6 @@ public class BLECommOperationResult {
public static final int RESULT_BUSY = 3;
public static final int RESULT_INTERRUPTED = 4;
public static final int RESULT_NOT_CONFIGURED = 5;
public byte[] value;
public int resultCode;
}

View file

@ -1,14 +1,14 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.os.SystemClock;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.os.SystemClock;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.GattAttributes;
@ -22,11 +22,13 @@ public class CharacteristicReadOperation extends BLECommOperation {
private BluetoothGattCharacteristic characteristic;
public CharacteristicReadOperation(BluetoothGatt gatt, BluetoothGattCharacteristic chara) {
this.gatt = gatt;
this.characteristic = chara;
}
@Override
public void execute(RileyLinkBLE comm) {
gatt.readCharacteristic(characteristic);
@ -34,7 +36,8 @@ public class CharacteristicReadOperation extends BLECommOperation {
try {
boolean didAcquire = operationComplete.tryAcquire(getGattOperationTimeout_ms(), TimeUnit.MILLISECONDS);
if (didAcquire) {
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier understanding of the sequence of events.
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier
// understanding of the sequence of events.
// success
} else {
LOG.error("Timeout waiting for gatt write operation to complete");
@ -47,15 +50,16 @@ public class CharacteristicReadOperation extends BLECommOperation {
value = characteristic.getValue();
}
@Override
public void gattOperationCompletionCallback(UUID uuid, byte[] value) {
super.gattOperationCompletionCallback(uuid, value);
if (!characteristic.getUuid().equals(uuid)) {
LOG.error(String.format("Completion callback: UUID does not match! out of sequence? Found: %s, should be %s",
GattAttributes.lookup(characteristic.getUuid()), GattAttributes.lookup(uuid)));
LOG.error(String.format(
"Completion callback: UUID does not match! out of sequence? Found: %s, should be %s",
GattAttributes.lookup(characteristic.getUuid()), GattAttributes.lookup(uuid)));
}
operationComplete.release();
}
}

View file

@ -1,14 +1,14 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.os.SystemClock;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.os.SystemClock;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.GattAttributes;
@ -22,12 +22,14 @@ public class CharacteristicWriteOperation extends BLECommOperation {
private BluetoothGattCharacteristic characteristic;
public CharacteristicWriteOperation(BluetoothGatt gatt, BluetoothGattCharacteristic chara, byte[] value) {
this.gatt = gatt;
this.characteristic = chara;
this.value = value;
}
@Override
public void execute(RileyLinkBLE comm) {
@ -37,7 +39,8 @@ public class CharacteristicWriteOperation extends BLECommOperation {
try {
boolean didAcquire = operationComplete.tryAcquire(getGattOperationTimeout_ms(), TimeUnit.MILLISECONDS);
if (didAcquire) {
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier understanding of the sequence of events.
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier
// understanding of the sequence of events.
// success
} else {
LOG.error("Timeout waiting for gatt write operation to complete");
@ -50,15 +53,16 @@ public class CharacteristicWriteOperation extends BLECommOperation {
}
// This will be run on the IBinder thread
@Override
public void gattOperationCompletionCallback(UUID uuid, byte[] value) {
if (!characteristic.getUuid().equals(uuid)) {
LOG.error(String.format("Completion callback: UUID does not match! out of sequence? Found: %s, should be %s",
GattAttributes.lookup(characteristic.getUuid()), GattAttributes.lookup(uuid)));
LOG.error(String.format(
"Completion callback: UUID does not match! out of sequence? Found: %s, should be %s",
GattAttributes.lookup(characteristic.getUuid()), GattAttributes.lookup(uuid)));
}
operationComplete.release();
}
}

View file

@ -1,14 +1,14 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattDescriptor;
import android.os.SystemClock;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattDescriptor;
import android.os.SystemClock;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE;
@ -28,12 +28,14 @@ public class DescriptorWriteOperation extends BLECommOperation {
this.value = value;
}
@Override
public void gattOperationCompletionCallback(UUID uuid, byte[] value) {
super.gattOperationCompletionCallback(uuid, value);
operationComplete.release();
}
@Override
public void execute(RileyLinkBLE comm) {
descr.setValue(value);
@ -42,7 +44,8 @@ public class DescriptorWriteOperation extends BLECommOperation {
try {
boolean didAcquire = operationComplete.tryAcquire(getGattOperationTimeout_ms(), TimeUnit.MILLISECONDS);
if (didAcquire) {
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier understanding of the sequence of events.
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier
// understanding of the sequence of events.
// success
} else {
LOG.error("Timeout waiting for descriptor write operation to complete");

View file

@ -2,8 +2,12 @@ package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.data;
import org.joda.time.LocalDateTime;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicCommandType;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState;
/**
* Created by andy on 5/19/18.
@ -11,15 +15,38 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLink
public class RLHistoryItem {
private MedtronicCommandType medtronicCommandType;
private LocalDateTime dateTime;
private RLHistoryItemSource source;
private RileyLinkServiceState serviceState;
private RileyLinkError errorCode;
private RileyLinkTargetDevice targetDevice;
private PumpDeviceState pumpDeviceState;
public RLHistoryItem(RileyLinkServiceState serviceState, RileyLinkError errorCode) {
public RLHistoryItem(RileyLinkServiceState serviceState, RileyLinkError errorCode,
RileyLinkTargetDevice targetDevice) {
this.targetDevice = targetDevice;
this.dateTime = new LocalDateTime();
this.serviceState = serviceState;
this.errorCode = errorCode;
this.source = RLHistoryItemSource.RileyLink;
}
public RLHistoryItem(PumpDeviceState pumpDeviceState, RileyLinkTargetDevice targetDevice) {
this.pumpDeviceState = pumpDeviceState;
this.dateTime = new LocalDateTime();
this.targetDevice = targetDevice;
this.source = RLHistoryItemSource.MedtronicPump;
}
public RLHistoryItem(MedtronicCommandType medtronicCommandType) {
this.dateTime = new LocalDateTime();
this.medtronicCommandType = medtronicCommandType;
source = RLHistoryItemSource.MedtronicCommand;
}
@ -36,4 +63,53 @@ public class RLHistoryItem {
public RileyLinkError getErrorCode() {
return errorCode;
}
public String getDescription() {
// TODO extend when we have Omnipod
switch (this.source) {
case RileyLink:
return "State: " + MainApp.gs(serviceState.getResourceId(targetDevice))
+ (this.errorCode == null ? "" : ", Error Code: " + errorCode);
case MedtronicPump:
return MainApp.gs(pumpDeviceState.getResourceId());
case MedtronicCommand:
return medtronicCommandType.name();
default:
return "Unknown Description";
}
}
public RLHistoryItemSource getSource() {
return source;
}
public PumpDeviceState getPumpDeviceState() {
return pumpDeviceState;
}
public enum RLHistoryItemSource {
RileyLink("RileyLink"), //
MedtronicPump("Medtronic"), //
MedtronicCommand("Medtronic");
private String desc;
RLHistoryItemSource(String desc) {
this.desc = desc;
}
public String getDesc() {
return desc;
}
}
}

View file

@ -10,7 +10,6 @@ public enum RileyLinkError {
// Configuration
// BT
NoBluetoothAdapter(R.string.rileylink_error_no_bt_adapter), //
BluetoothDisabled(R.string.rileylink_error_bt_disabled), //
@ -24,10 +23,10 @@ public enum RileyLinkError {
NoContactWithDevice(R.string.rileylink_error_pump_unreachable, R.string.rileylink_error_pod_unreachable), //
;
int resourceId;
Integer resourceIdPod;
RileyLinkError(int resourceId) {
this.resourceId = resourceId;
}
@ -43,7 +42,8 @@ public enum RileyLinkError {
if (this.resourceIdPod != null) {
return targetDevice == RileyLinkTargetDevice.MedtronicPump ? //
this.resourceId : this.resourceIdPod;
this.resourceId
: this.resourceIdPod;
} else {
return this.resourceId;
}

View file

@ -11,78 +11,84 @@ public enum RileyLinkServiceState {
NotStarted(R.string.rileylink_state_not_started), //
// Bluetooth
BluetoothInitializing(R.string.rileylink_state_bt_init), // (S) init BT (if error no BT interface -> Disabled, BT not enabled -> BluetoothError)
//BluetoothNotAvailable, // (E) BT not available, would happen only if device has no BT
BluetoothInitializing(R.string.rileylink_state_bt_init), // (S) init BT (if error no BT interface -> Disabled, BT
// not enabled -> BluetoothError)
// BluetoothNotAvailable, // (E) BT not available, would happen only if device has no BT
BluetoothError(R.string.rileylink_state_bt_error), // (E) if BT gets disabled ( -> EnableBluetooth)
BluetoothReady(R.string.rileylink_state_bt_ready), // (OK)
// RileyLink
RileyLinkInitializing(R.string.rileylink_state_rl_init), // (S) start Gatt discovery (OK -> RileyLinkReady, Error -> BluetoothEnabled) ??
RileyLinkInitializing(R.string.rileylink_state_rl_init), // (S) start Gatt discovery (OK -> RileyLinkReady, Error ->
// BluetoothEnabled) ??
RileyLinkError(R.string.rileylink_state_rl_error), // (E)
RileyLinkReady(R.string.rileylink_state_connected), // (OK) if tunning was already done we go to PumpConnectorReady
// Tunning
TuneUpDevice(R.string.rileylink_state_pc_tune_up), // (S)
PumpConnectorError(R.string.rileylink_state_pc_error), // either TuneUp Error or pump couldn't not be contacted error
PumpConnectorError(R.string.rileylink_state_pc_error), // either TuneUp Error or pump couldn't not be contacted
// error
PumpConnectorReady(R.string.rileylink_state_connected), // (OK) RileyLink Ready for Pump Communication
//Initializing, // get all parameters required for connection (if not possible -> Disabled, if sucessful -> EnableBluetooth)
// Initializing, // get all parameters required for connection (if not possible -> Disabled, if sucessful ->
// EnableBluetooth)
// EnableBlueTooth, // enable BT (if error no BT interface -> Disabled, BT not enabled -> BluetoothError)
// BlueToothEnabled, // -> InitializeRileyLink
// RileyLinkInitialized, //
//EnableBlueTooth, // enable BT (if error no BT interface -> Disabled, BT not enabled -> BluetoothError)
//BlueToothEnabled, // -> InitializeRileyLink
//RileyLinkInitialized, //
//RileyLinkConnected, // -> TuneUpPump (on 1st), else PumpConnectorReady
//PumpConnected, //
// RileyLinkConnected, // -> TuneUpPump (on 1st), else PumpConnectorReady
// PumpConnected, //
;
int resourceId;
Integer resourceIdPod;
RileyLinkServiceState(int resourceId) {
this.resourceId = resourceId;
}
RileyLinkServiceState(int resourceId, int resourceIdPod) {
this.resourceId = resourceId;
this.resourceIdPod = resourceIdPod;
}
public static boolean isReady(RileyLinkServiceState serviceState) {
return (serviceState == RileyLinkReady || serviceState == PumpConnectorReady);
}
public int getResourceId(RileyLinkTargetDevice targetDevice) {
if (this.resourceIdPod != null) {
return targetDevice == RileyLinkTargetDevice.MedtronicPump ? //
this.resourceId : this.resourceIdPod;
return (targetDevice == null || targetDevice == RileyLinkTargetDevice.MedtronicPump) ? //
this.resourceId
: this.resourceIdPod;
} else {
return this.resourceId;
}
}
public static boolean isReady(RileyLinkServiceState serviceState) {
return (serviceState == RileyLinkReady || serviceState == PumpConnectorReady);
}
public boolean isConnecting() {
return (this == RileyLinkServiceState.BluetoothInitializing || //
//this == RileyLinkServiceState.BluetoothError || //
this == RileyLinkServiceState.BluetoothReady || //
this == RileyLinkServiceState.RileyLinkInitializing //
//this == RileyLinkServiceState.RileyLinkError
// this == RileyLinkServiceState.BluetoothError || //
this == RileyLinkServiceState.BluetoothReady || //
this == RileyLinkServiceState.RileyLinkInitializing //
// this == RileyLinkServiceState.RileyLinkError
);
}
public boolean isError() {
return (
this == RileyLinkServiceState.BluetoothError || //
//this == RileyLinkServiceState.PumpConnectorError || //
this == RileyLinkServiceState.RileyLinkError);
return (this == RileyLinkServiceState.BluetoothError || //
// this == RileyLinkServiceState.PumpConnectorError || //
this == RileyLinkServiceState.RileyLinkError);
}
}

View file

@ -1,22 +1,33 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs;
import info.nightscout.androidaps.R;
/**
* Created by andy on 5/19/18.
*/
public enum RileyLinkTargetDevice {
MedtronicPump(true), //
Omnipod(false), //
MedtronicPump(R.string.rileylink_target_device_medtronic, true), //
Omnipod(R.string.rileylink_target_device_omnipod, false), //
;
private int resourceId;
private boolean tuneUpEnabled;
RileyLinkTargetDevice(boolean tuneUpEnabled) {
RileyLinkTargetDevice(int resourceId, boolean tuneUpEnabled) {
this.resourceId = resourceId;
this.tuneUpEnabled = tuneUpEnabled;
}
public boolean isTuneUpEnabled() {
return tuneUpEnabled;
}
public int getResourceId() {
return resourceId;
}
}

View file

@ -1,4 +1,7 @@
package info.nightscout.androidaps.plugins.PumpCommon.dialog;
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.dialog;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
@ -11,17 +14,14 @@ import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpCommon.dialog.RefreshableInterface;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.RileyLinkServiceData;
public class RileylinkSettingsActivity extends AppCompatActivity {
public class RileyLinkStatusActivity extends AppCompatActivity {
@BindView(R.id.rls_t1_connection_status)
TextView connectionStatus;
@ -34,79 +34,74 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
@BindView(R.id.rls_t1_connection_error)
TextView connectionError;
RileyLinkServiceData rileyLinkServiceData;
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link FragmentPagerAdapter} derivative, which will keep every
* fragments for each of the sections. We use a {@link FragmentPagerAdapter} derivative, which will keep every
* loaded fragment in memory. If this becomes too memory intensive, it
* may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
* may be best to switch to a {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
private SectionsPagerAdapter mSectionsPagerAdapter;
private FloatingActionButton floatingActionButton;
private TabLayout tabLayout;
RileyLinkServiceData rileyLinkServiceData;
/**
* The {@link ViewPager} that will host the section contents.
*/
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rileylink_settings);
setContentView(R.layout.rileylink_status);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.rileylink_settings_container);
//mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager = (ViewPager)findViewById(R.id.rileylink_settings_container);
// mViewPager.setAdapter(mSectionsPagerAdapter);
setupViewPager(mViewPager);
tabLayout = (TabLayout) findViewById(R.id.rileylink_settings_tabs);
tabLayout = (TabLayout)findViewById(R.id.rileylink_settings_tabs);
tabLayout.setupWithViewPager(mViewPager);
floatingActionButton = (FloatingActionButton) findViewById(R.id.rileylink_settings_fab);
floatingActionButton = (FloatingActionButton)findViewById(R.id.rileylink_settings_fab);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RefreshableInterface selectableInterface = (RefreshableInterface) mSectionsPagerAdapter.getItem(tabLayout.getSelectedTabPosition());
RefreshableInterface selectableInterface = (RefreshableInterface)mSectionsPagerAdapter
.getItem(tabLayout.getSelectedTabPosition());
selectableInterface.refreshData();
//refreshData(tabLayout.getSelectedTabPosition());
// refreshData(tabLayout.getSelectedTabPosition());
//Toast.makeText(getApplicationContext(), "Test pos: " + tabLayout.getSelectedTabPosition(), Toast.LENGTH_LONG);
// Toast.makeText(getApplicationContext(), "Test pos: " + tabLayout.getSelectedTabPosition(),
// Toast.LENGTH_LONG);
}
});
this.connectionStatus = (TextView) findViewById(R.id.rls_t1_connection_status);
this.configuredAddress = (TextView) findViewById(R.id.rls_t1_configured_address);
this.connectedDevice = (TextView) findViewById(R.id.rls_t1_connected_device);
this.connectionError = (TextView) findViewById(R.id.rls_t1_connection_error);
this.connectionStatus = (TextView)findViewById(R.id.rls_t1_connection_status);
this.configuredAddress = (TextView)findViewById(R.id.rls_t1_configured_address);
this.connectedDevice = (TextView)findViewById(R.id.rls_t1_connected_device);
this.connectionError = (TextView)findViewById(R.id.rls_t1_connection_error);
rileyLinkServiceData = RileyLinkUtil.getRileyLinkServiceData();
// // 7-12
// int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, //
// R.id.rls_t1_tv08, R.id.rls_t1_tv09, R.id.rls_t1_tv10, R.id.rls_t1_tv11, R.id.rls_t1_tv12};
//
// for (int id : ids) {
//
// TextView tv = (TextView) findViewById(id);
// tv.setText(tv.getText() + ":");
// }
// // 7-12
// int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, //
// R.id.rls_t1_tv08, R.id.rls_t1_tv09, R.id.rls_t1_tv10, R.id.rls_t1_tv11, R.id.rls_t1_tv12};
//
// for (int id : ids) {
//
// TextView tv = (TextView) findViewById(id);
// tv.setText(tv.getText() + ":");
// }
//refreshData(0);
//refreshData(1);
// refreshData(0);
// refreshData(1);
}
@ -124,7 +119,6 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
}
}
@ -132,14 +126,13 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mSectionsPagerAdapter.addFragment(new RileyLinkSettingsTab1(), MainApp.gs(R.string.rileylink_settings_tab1));
mSectionsPagerAdapter.addFragment(new RileyLinkSettingsTab2(), MainApp.gs(R.string.rileylink_settings_tab2));
//mSectionsPagerAdapter.addFragment(new RileyLinkSettingsTab3(), "Tab 3");
mSectionsPagerAdapter.addFragment(new RileyLinkStatusGeneral(), MainApp.gs(R.string.rileylink_settings_tab1));
mSectionsPagerAdapter.addFragment(new RileyLinkStatusHistory(), MainApp.gs(R.string.rileylink_settings_tab2));
// mSectionsPagerAdapter.addFragment(new RileyLinkSettingsTab3(), "Tab 3");
mViewPager.setAdapter(mSectionsPagerAdapter);
}
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
@ -150,6 +143,7 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
List<String> fragmentTitle = new ArrayList<>();
int lastSelectedPosition = 0;
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@ -161,17 +155,20 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
return fragmentList.get(position);
}
@Override
public int getCount() {
// Show 3 total pages.
return fragmentList.size();
}
public void addFragment(Fragment fragment, String title) {
this.fragmentList.add(fragment);
this.fragmentTitle.add(title);
}
@Override
public CharSequence getPageTitle(int position) {
return fragmentTitle.get(position);

View file

@ -0,0 +1,156 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.dialog;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpCommon.dialog.RefreshableInterface;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.PumpCommon.utils.StringUtil;
/**
* Created by andy on 5/19/18.
*/
// FIXME needs to be implemented
@Deprecated
public class RileyLinkStatusDevice extends Fragment implements RefreshableInterface {
// @BindView(R.id.rileylink_history_list)
ListView listView;
RileyLinkCommandListAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.rileylink_status_device, container, false);
adapter = new RileyLinkCommandListAdapter();
return rootView;
}
@Override
public void onStart() {
super.onStart();
this.listView = (ListView)getActivity().findViewById(R.id.rileylink_history_list);
listView.setAdapter(adapter);
refreshData();
}
@Override
public void refreshData() {
// adapter.addItemsAndClean(RileyLinkUtil.getRileyLinkHistory());
}
static class ViewHolder {
TextView itemTime;
TextView itemSource;
TextView itemDescription;
}
private class RileyLinkCommandListAdapter extends BaseAdapter {
private List<RLHistoryItem> historyItemList;
private LayoutInflater mInflator;
public RileyLinkCommandListAdapter() {
super();
historyItemList = new ArrayList<>();
mInflator = RileyLinkStatusDevice.this.getLayoutInflater();
}
public void addItem(RLHistoryItem item) {
if (!historyItemList.contains(item)) {
historyItemList.add(item);
notifyDataSetChanged();
}
}
public RLHistoryItem getHistoryItem(int position) {
return historyItemList.get(position);
}
public void addItemsAndClean(List<RLHistoryItem> items) {
this.historyItemList.clear();
for (RLHistoryItem item : items) {
if (!historyItemList.contains(item)) {
historyItemList.add(item);
}
}
notifyDataSetChanged();
}
public void clear() {
historyItemList.clear();
notifyDataSetChanged();
}
@Override
public int getCount() {
return historyItemList.size();
}
@Override
public Object getItem(int i) {
return historyItemList.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
RileyLinkStatusDevice.ViewHolder viewHolder;
// General ListView optimization code.
if (view == null) {
view = mInflator.inflate(R.layout.rileylink_status_device_item, null);
viewHolder = new RileyLinkStatusDevice.ViewHolder();
viewHolder.itemTime = (TextView)view.findViewById(R.id.rileylink_history_time);
viewHolder.itemSource = (TextView)view.findViewById(R.id.rileylink_history_source);
viewHolder.itemDescription = (TextView)view.findViewById(R.id.rileylink_history_description);
view.setTag(viewHolder);
} else {
viewHolder = (RileyLinkStatusDevice.ViewHolder)view.getTag();
}
RLHistoryItem item = historyItemList.get(i);
viewHolder.itemTime.setText(StringUtil.toDateTimeString(item.getDateTime()));
viewHolder.itemSource.setText("Riley Link"); // for now
viewHolder.itemDescription.setText(item.getDescription());
return view;
}
}
}

View file

@ -0,0 +1,127 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.dialog;
import java.util.Locale;
import org.joda.time.LocalDateTime;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpCommon.dialog.RefreshableInterface;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.plugins.PumpCommon.utils.StringUtil;
import info.nightscout.androidaps.plugins.PumpMedtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
/**
* Created by andy on 5/19/18.
*/
public class RileyLinkStatusGeneral extends Fragment implements RefreshableInterface {
TextView connectionStatus;
TextView configuredAddress;
TextView connectedDevice;
TextView connectionError;
TextView deviceType;
TextView deviceModel;
TextView serialNumber;
TextView pumpFrequency;
TextView lastUsedFrequency;
TextView lastDeviceContact;
RileyLinkServiceData rileyLinkServiceData;
MedtronicPumpStatus medtronicPumpStatus;
boolean first = false;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.rileylink_status_general, container, false);
return rootView;
}
@Override
public void onStart() {
super.onStart();
rileyLinkServiceData = RileyLinkUtil.getRileyLinkServiceData();
this.connectionStatus = getActivity().findViewById(R.id.rls_t1_connection_status);
this.configuredAddress = getActivity().findViewById(R.id.rls_t1_configured_address);
this.connectedDevice = getActivity().findViewById(R.id.rls_t1_connected_device);
this.connectionError = getActivity().findViewById(R.id.rls_t1_connection_error);
this.deviceType = getActivity().findViewById(R.id.rls_t1_device_type);
this.deviceModel = getActivity().findViewById(R.id.rls_t1_device_model);
this.serialNumber = getActivity().findViewById(R.id.rls_t1_serial_number);
this.pumpFrequency = getActivity().findViewById(R.id.rls_t1_pump_frequency);
this.lastUsedFrequency = getActivity().findViewById(R.id.rls_t1_last_used_frequency);
this.lastDeviceContact = getActivity().findViewById(R.id.rls_t1_last_device_contact);
if (!first) {
// 7-12
int[] ids = { R.id.rls_t1_tv02, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, //
R.id.rls_t1_tv08, R.id.rls_t1_tv09, R.id.rls_t1_tv10, R.id.rls_t1_tv11, R.id.rls_t1_tv12 };
for (int id : ids) {
TextView tv = (TextView)getActivity().findViewById(id);
tv.setText(tv.getText() + ":");
}
first = true;
}
refreshData();
}
public void refreshData() {
RileyLinkTargetDevice targetDevice = RileyLinkUtil.getTargetDevice();
this.connectionStatus.setText(MainApp.gs(rileyLinkServiceData.serviceState.getResourceId(targetDevice)));
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
this.connectionError.setText(rileyLinkServiceData.errorCode == null ? //
"-"
: MainApp.gs(rileyLinkServiceData.errorCode.getResourceId(targetDevice)));
// TODO add handling for Omnipod pump status
this.medtronicPumpStatus = MedtronicUtil.getPumpStatus();
if (medtronicPumpStatus != null) {
this.deviceType.setText(MainApp.gs(RileyLinkUtil.getTargetDevice().getResourceId()));
this.deviceModel.setText(medtronicPumpStatus.pumpType.getDescription());
this.serialNumber.setText(medtronicPumpStatus.serialNumber);
this.pumpFrequency.setText(medtronicPumpStatus.pumpFrequency);
if (MedtronicUtil.getMedtronicPumpModel() != null) // FIXME change this when we have omnipod
this.connectedDevice.setText("Medtronic " + MedtronicUtil.getMedtronicPumpModel().getPumpModel());
else
this.connectedDevice.setText("???");
if (rileyLinkServiceData.lastGoodFrequency != null)
this.lastUsedFrequency.setText(String.format(Locale.ENGLISH, "%.2f MHz",
rileyLinkServiceData.lastGoodFrequency));
// FIXME
if (medtronicPumpStatus.lastConnection != 0)
this.lastDeviceContact.setText(StringUtil.toDateTimeString(new LocalDateTime(
medtronicPumpStatus.lastDataTime)));
else
this.lastDeviceContact.setText("Never");
}
}
}

View file

@ -0,0 +1,172 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.dialog;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpCommon.dialog.RefreshableInterface;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.PumpCommon.utils.StringUtil;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState;
/**
* Created by andy on 5/19/18.
*/
public class RileyLinkStatusHistory extends Fragment implements RefreshableInterface {
// @BindView(R.id.rileylink_history_list)
ListView listView;
RileyLinkHistoryListAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.rileylink_status_history, container, false);
adapter = new RileyLinkHistoryListAdapter();
return rootView;
}
@Override
public void onStart() {
super.onStart();
this.listView = (ListView)getActivity().findViewById(R.id.rileylink_history_list);
listView.setAdapter(adapter);
refreshData();
}
@Override
public void refreshData() {
adapter.addItemsAndClean(RileyLinkUtil.getRileyLinkHistory());
}
static class ViewHolder {
TextView itemTime;
TextView itemSource;
TextView itemDescription;
}
private class RileyLinkHistoryListAdapter extends BaseAdapter {
private List<RLHistoryItem> historyItemList;
private LayoutInflater mInflator;
public RileyLinkHistoryListAdapter() {
super();
historyItemList = new ArrayList<>();
mInflator = RileyLinkStatusHistory.this.getLayoutInflater();
}
public void addItem(RLHistoryItem item) {
if (!historyItemList.contains(item)) {
historyItemList.add(item);
notifyDataSetChanged();
}
}
public RLHistoryItem getHistoryItem(int position) {
return historyItemList.get(position);
}
public void addItemsAndClean(List<RLHistoryItem> items) {
this.historyItemList.clear();
for (RLHistoryItem item : items) {
if (!historyItemList.contains(item) && isValidItem(item)) {
historyItemList.add(item);
}
}
notifyDataSetChanged();
}
private boolean isValidItem(RLHistoryItem item) {
PumpDeviceState pumpState = item.getPumpDeviceState();
if ((pumpState != null) && //
(pumpState == PumpDeviceState.Sleeping || //
pumpState == PumpDeviceState.Active || //
pumpState == PumpDeviceState.WakingUp //
))
return false;
return true;
}
public void clear() {
historyItemList.clear();
notifyDataSetChanged();
}
@Override
public int getCount() {
return historyItemList.size();
}
@Override
public Object getItem(int i) {
return historyItemList.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
RileyLinkStatusHistory.ViewHolder viewHolder;
// General ListView optimization code.
if (view == null) {
view = mInflator.inflate(R.layout.rileylink_status_history_item, null);
viewHolder = new RileyLinkStatusHistory.ViewHolder();
viewHolder.itemTime = (TextView)view.findViewById(R.id.rileylink_history_time);
viewHolder.itemSource = (TextView)view.findViewById(R.id.rileylink_history_source);
viewHolder.itemDescription = (TextView)view.findViewById(R.id.rileylink_history_description);
view.setTag(viewHolder);
} else {
viewHolder = (RileyLinkStatusHistory.ViewHolder)view.getTag();
}
RLHistoryItem item = historyItemList.get(i);
viewHolder.itemTime.setText(StringUtil.toDateTimeString(item.getDateTime()));
viewHolder.itemSource.setText(item.getSource().getDesc()); // for now
viewHolder.itemDescription.setText(item.getDescription());
return view;
}
}
}

View file

@ -1,5 +1,10 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service;
import static info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil.getRileyLinkCommunicationManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
@ -9,9 +14,6 @@ import android.content.IntentFilter;
import android.os.PowerManager;
import android.support.v4.content.LocalBroadcastManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkCommunicationManager;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
@ -30,37 +32,29 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.ServiceTaskExecutor;
import info.nightscout.utils.SP;
import static info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil.getRileyLinkCommunicationManager;
//import static info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.;
/**
* Created by andy on 5/6/18.
* Split from original file and renamed.
*/
public abstract class RileyLinkService extends Service {
protected static final String WAKELOCKNAME = "com.gxwtech.roundtrip2.RoundtripServiceWakeLock";
private static final Logger LOG = LoggerFactory.getLogger(RileyLinkService.class);
protected BluetoothAdapter bluetoothAdapter;
protected static volatile PowerManager.WakeLock lockStatic = null;
// Our hardware/software connection
public RileyLinkBLE rileyLinkBLE; // android-bluetooth management
protected BluetoothAdapter bluetoothAdapter;
protected RFSpy rfspy; // interface for RL xxx Mhz radio.
//protected boolean needBluetoothPermission = true;
//protected RileyLinkIPCConnection rileyLinkIPCConnection;
// protected boolean needBluetoothPermission = true;
// protected RileyLinkIPCConnection rileyLinkIPCConnection;
protected Context context;
//public RileyLinkCommunicationManager pumpCommunicationManager;
// public RileyLinkCommunicationManager pumpCommunicationManager;
protected BroadcastReceiver mBroadcastReceiver;
protected RileyLinkServiceData rileyLinkServiceData;
protected RileyLinkTargetFrequency rileyLinkTargetFrequency;
protected static final String WAKELOCKNAME = "com.gxwtech.roundtrip2.RoundtripServiceWakeLock";
protected static volatile PowerManager.WakeLock lockStatic = null;
public RileyLinkService(Context context) {
super();
@ -116,16 +110,17 @@ public abstract class RileyLinkService extends Service {
super.onCreate();
LOG.debug("onCreate");
//rileyLinkIPCConnection = new RileyLinkIPCConnection(context); // TODO We might be able to remove this -- Andy
//RileyLinkUtil.setRileyLinkIPCConnection(rileyLinkIPCConnection);
// rileyLinkIPCConnection = new RileyLinkIPCConnection(context); // TODO We might be able to remove this -- Andy
// RileyLinkUtil.setRileyLinkIPCConnection(rileyLinkIPCConnection);
mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
/* here we can listen for local broadcasts, then send ourselves
* a specific intent to deal with them, if we wish
*/
/*
* here we can listen for local broadcasts, then send ourselves
* a specific intent to deal with them, if we wish
*/
if (intent == null) {
LOG.error("onReceive: received null intent");
} else {
@ -135,18 +130,22 @@ public abstract class RileyLinkService extends Service {
} else {
if (action.equals(RileyLinkConst.Intents.BluetoothConnected)) {
//rileyLinkIPCConnection.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_note_FindingRileyLink), null);
// rileyLinkIPCConnection.sendNotification(new
// ServiceNotification(RT2Const.IPC.MSG_note_FindingRileyLink), null);
ServiceTaskExecutor.startTask(new DiscoverGattServicesTask());
} else if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnected)) {
if (bluetoothAdapter.isEnabled()) {
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothReady, RileyLinkError.RileyLinkUnreachable);
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothReady,
RileyLinkError.RileyLinkUnreachable);
} else {
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled);
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError,
RileyLinkError.BluetoothDisabled);
}
} else if (action.equals(RileyLinkConst.Intents.RileyLinkReady)) {
LOG.warn("MedtronicConst.Intents.RileyLinkReady");
// FIXME
//rileyLinkIPCConnection.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_note_WakingPump), null);
// rileyLinkIPCConnection.sendNotification(new
// ServiceNotification(RT2Const.IPC.MSG_note_WakingPump), null);
rileyLinkBLE.enableNotifications();
rfspy.startReader(); // call startReader from outside?
@ -163,7 +162,8 @@ public abstract class RileyLinkService extends Service {
LOG.info("Announcing RileyLink open For business");
} else if (action.equals(RileyLinkConst.Intents.BluetoothReconnected)) {
LOG.debug("Reconnecting Bluetooth");
//rileyLinkIPCConnection.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_note_FindingRileyLink), null);
// rileyLinkIPCConnection.sendNotification(new
// ServiceNotification(RT2Const.IPC.MSG_note_FindingRileyLink), null);
bluetoothInit();
ServiceTaskExecutor.startTask(new DiscoverGattServicesTask(true));
} else if (action.equals(RileyLinkConst.IPC.MSG_PUMP_tunePump)) {
@ -183,56 +183,56 @@ public abstract class RileyLinkService extends Service {
if (RileylinkBLEAddress.equals("")) {
LOG.error("No Rileylink BLE Address saved in app");
} else {
//showBusy("Configuring Service", 50);
//rileyLinkBLE.findRileyLink(RileylinkBLEAddress);
// showBusy("Configuring Service", 50);
// rileyLinkBLE.findRileyLink(RileylinkBLEAddress);
reconfigureRileyLink(RileylinkBLEAddress);
//MainApp.getServiceClientConnection().setThisRileylink(RileylinkBLEAddress);
// MainApp.getServiceClientConnection().setThisRileylink(RileylinkBLEAddress);
}
}
/*
* else if (RT2Const.serviceLocal.INTENT_sessionCompleted.equals(action)) {
* Bundle bundle = intent.getBundleExtra(RT2Const.IPC.bundleKey);
* if (bundle != null) {
* ServiceTransport transport = new ServiceTransport(bundle);
* //rileyLinkIPCConnection.sendTransport(transport, transport.getSenderHashcode());
* //RileyLinkUtil.send
* } else {
* LOG.error("sessionCompleted: no bundle!");
* }
* }
*/
/*else if (RT2Const.serviceLocal.INTENT_sessionCompleted.equals(action)) {
Bundle bundle = intent.getBundleExtra(RT2Const.IPC.bundleKey);
if (bundle != null) {
ServiceTransport transport = new ServiceTransport(bundle);
//rileyLinkIPCConnection.sendTransport(transport, transport.getSenderHashcode());
//RileyLinkUtil.send
} else {
LOG.error("sessionCompleted: no bundle!");
}
}*/
/*else
if (case RT2Const.local.INTENT_serviceConnected:
case RT2Const.local.INTENT_NEW_rileylinkAddressKey:
showIdle();
/**
* Client MUST send a "UseThisRileylink" message because it asserts that
* the user has given explicit permission to use bluetooth.
*
* We can change the format so that it is a simple "bluetooth OK" message,
* rather than an explicit address of a Rileylink, and the Service can
* use the last known good value. But the kick-off of bluetooth ops must
* come from an Activity.
*/
/* String RileylinkBLEAddress = SP.getString(MedtronicConst.Prefs.RileyLinkAddress, "");
if (RileylinkBLEAddress.equals("")) {
// TODO: 11/07/2016 @TIM UI message for user
Log.e(TAG, "No Rileylink BLE Address saved in app");
} else {
//showBusy("Configuring Service", 50);
MainApp.getServiceClientConnection().setThisRileylink(RileylinkBLEAddress);
}
break;
case RT2Const.local.INTENT_NEW_pumpIDKey:
MainApp.getServiceClientConnection().sendPUMP_useThisDevice(SP.getString(MedtronicConst.Prefs.PumpSerial, ""));
break;
*/
/*
* else
*
* if (case RT2Const.local.INTENT_serviceConnected:
* case RT2Const.local.INTENT_NEW_rileylinkAddressKey:
* showIdle();
* /**
* Client MUST send a "UseThisRileylink" message because it asserts that
* the user has given explicit permission to use bluetooth.
*
* We can change the format so that it is a simple "bluetooth OK" message,
* rather than an explicit address of a Rileylink, and the Service can
* use the last known good value. But the kick-off of bluetooth ops must
* come from an Activity.
*/
/*
* String RileylinkBLEAddress = SP.getString(MedtronicConst.Prefs.RileyLinkAddress, "");
* if (RileylinkBLEAddress.equals("")) {
* // TODO: 11/07/2016 @TIM UI message for user
* Log.e(TAG, "No Rileylink BLE Address saved in app");
* } else {
* //showBusy("Configuring Service", 50);
* MainApp.getServiceClientConnection().setThisRileylink(RileylinkBLEAddress);
* }
* break;
* case RT2Const.local.INTENT_NEW_pumpIDKey:
* MainApp.getServiceClientConnection().sendPUMP_useThisDevice(SP.getString(MedtronicConst.Prefs.
* PumpSerial, ""));
* break;
*/
else {
LOG.error("Unhandled broadcast: action=" + action);
@ -249,14 +249,14 @@ public abstract class RileyLinkService extends Service {
intentFilter.addAction(RileyLinkConst.Intents.RileyLinkDisconnected);
intentFilter.addAction(RileyLinkConst.Intents.BluetoothReconnected);
intentFilter.addAction(RileyLinkConst.Intents.RileyLinkNewAddressSet);
//intentFilter.addAction(RT2Const.serviceLocal.ipcBound);
//intentFilter.addAction(RT2Const.IPC.MSG_BLE_accessGranted);
//intentFilter.addAction(RT2Const.IPC.MSG_BLE_accessDenied);
//intentFilter.addAction(RT2Const.IPC.MSG_BLE_useThisDevice);
// intentFilter.addAction(RT2Const.serviceLocal.ipcBound);
// intentFilter.addAction(RT2Const.IPC.MSG_BLE_accessGranted);
// intentFilter.addAction(RT2Const.IPC.MSG_BLE_accessDenied);
// intentFilter.addAction(RT2Const.IPC.MSG_BLE_useThisDevice);
intentFilter.addAction(RileyLinkConst.IPC.MSG_PUMP_tunePump);
//intentFilter.addAction(RT2Const.IPC.MSG_PUMP_useThisAddress);
// intentFilter.addAction(RT2Const.IPC.MSG_PUMP_useThisAddress);
intentFilter.addAction(RileyLinkConst.IPC.MSG_ServiceCommand);
//intentFilter.addAction(RileyLinkConst.serviceLocal.INTENT_sessionCompleted);
// intentFilter.addAction(RileyLinkConst.serviceLocal.INTENT_sessionCompleted);
addPumpSpecificIntents(intentFilter);
@ -268,10 +268,13 @@ public abstract class RileyLinkService extends Service {
public abstract RileyLinkCommunicationManager getDeviceCommunicationManager();
public abstract void addPumpSpecificIntents(IntentFilter intentFilter);
public abstract void handlePumpSpecificIntents(Intent intent);
public abstract void handleIncomingServiceTransport(Intent intent);
@ -280,24 +283,24 @@ public abstract class RileyLinkService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
LOG.debug("onStartCommand");
// if (intent != null) {
// PowerManager.WakeLock lock = getLock(this.getApplicationContext());
//
// if (!lock.isHeld() || (flags & START_FLAG_REDELIVERY) != 0) {
// lock.acquire();
// }
//
// // This will end up running onHandleIntent
// super.onStartCommand(intent, flags, startId);
// } else {
// LOG.error("Received null intent?");
// }
// if (intent != null) {
// PowerManager.WakeLock lock = getLock(this.getApplicationContext());
//
// if (!lock.isHeld() || (flags & START_FLAG_REDELIVERY) != 0) {
// lock.acquire();
// }
//
// // This will end up running onHandleIntent
// super.onStartCommand(intent, flags, startId);
// } else {
// LOG.error("Received null intent?");
// }
RileyLinkUtil.setContext(getApplicationContext());
//bluetoothInit();
// bluetoothInit();
//return (START_REDELIVER_INTENT | START_STICKY);
// return (START_REDELIVER_INTENT | START_STICKY);
return (START_STICKY);
}
@ -339,22 +342,24 @@ public abstract class RileyLinkService extends Service {
LOG.info("No change to RL address. Not reconnecting.");
return false;
} else {
LOG.warn("Disconnecting from old RL (" + rileyLinkServiceData.rileylinkAddress + "), reconnecting to new: " + deviceAddress);
LOG.warn("Disconnecting from old RL (" + rileyLinkServiceData.rileylinkAddress
+ "), reconnecting to new: " + deviceAddress);
rileyLinkBLE.disconnect();
// prolly need to shut down listening thread too?
//SP.putString(MedtronicConst.Prefs.RileyLinkAddress, deviceAddress);
// SP.putString(MedtronicConst.Prefs.RileyLinkAddress, deviceAddress);
rileyLinkServiceData.rileylinkAddress = deviceAddress;
rileyLinkBLE.findRileyLink(rileyLinkServiceData.rileylinkAddress);
return true;
}
} else {
//Toast.makeText(context, "Using RL " + deviceAddress, Toast.LENGTH_SHORT).show();
// Toast.makeText(context, "Using RL " + deviceAddress, Toast.LENGTH_SHORT).show();
LOG.debug("handleIPCMessage: Using RL " + deviceAddress);
if (RileyLinkUtil.getServiceState() == RileyLinkServiceState.NotStarted) {
if (!bluetoothInit()) {
LOG.error("RileyLink can't get activated, Bluetooth is not functioning correctly. {}", RileyLinkUtil.getError().name());
LOG.error("RileyLink can't get activated, Bluetooth is not functioning correctly. {}",
RileyLinkUtil.getError().name());
return false;
}
}
@ -365,33 +370,35 @@ public abstract class RileyLinkService extends Service {
}
}
//
// public synchronized static PowerManager.WakeLock getLock(Context context) {
// if (lockStatic == null) {
// PowerManager mgr = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
//
// lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCKNAME);
// lockStatic.setReferenceCounted(true);
// }
//
// return lockStatic;
// }
//
// public synchronized static PowerManager.WakeLock getLock(Context context) {
// if (lockStatic == null) {
// PowerManager mgr = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
//
// lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCKNAME);
// lockStatic.setReferenceCounted(true);
// }
//
// return lockStatic;
// }
public void sendServiceTransportResponse(ServiceTransport transport, ServiceResult serviceResult) {
// get the key (hashcode) of the client who requested this
/*Integer clientHashcode = transport.getSenderHashcode();
// make a new bundle to send as the message data
transport.setServiceResult(serviceResult);
// FIXME
transport.setTransportType(RT2Const.IPC.MSG_ServiceResult); */
//rileyLinkIPCConnection.sendTransport(transport, clientHashcode);
/*
* Integer clientHashcode = transport.getSenderHashcode();
* // make a new bundle to send as the message data
* transport.setServiceResult(serviceResult);
* // FIXME
* transport.setTransportType(RT2Const.IPC.MSG_ServiceResult);
*/
// rileyLinkIPCConnection.sendTransport(transport, clientHashcode);
LOG.error("sendServiceTransportResponse not implemented.");
}
public boolean sendNotification(ServiceNotification notification, Integer clientHashcode) {
//return rileyLinkIPCConnection.sendNotification(notification, clientHashcode);
// return rileyLinkIPCConnection.sendNotification(notification, clientHashcode);
LOG.error("sendNotification not implemented.");
return false;
}
@ -399,10 +406,10 @@ public abstract class RileyLinkService extends Service {
protected void sendBLERequestForAccess() {
// FIXME
//serviceConnection.sendMessage(RT2Const.IPC.MSG_BLE_requestAccess);
// serviceConnection.sendMessage(RT2Const.IPC.MSG_BLE_requestAccess);
//Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
//startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
// Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
// startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
@ -425,7 +432,7 @@ public abstract class RileyLinkService extends Service {
// we have an old frequency, so let's start there.
newFrequency = getDeviceCommunicationManager().quickTuneForPump(lastGoodFrequency);
if (newFrequency == 0.0) {
// quick scan failed to find pump. Try full scan
// quick scan failed to find pump. Try full scan
LOG.warn("Failed to find pump near last saved frequency, doing full scan");
newFrequency = getDeviceCommunicationManager().tuneForDevice();
}
@ -447,7 +454,8 @@ public abstract class RileyLinkService extends Service {
if (newFrequency == 0.0d) {
// error tuning pump, pump not present ??
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.TuneUpOfDeviceFailed);
RileyLinkUtil
.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.TuneUpOfDeviceFailed);
}
}

View file

@ -1,9 +1,8 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkTargetDevice;
/**
* Created by andy on 16/05/2018.

View file

@ -6,6 +6,7 @@ import android.os.Bundle;
* Created by geoff on 6/25/16.
*/
public class ServiceCommand extends ServiceMessage {
public ServiceCommand() {
map = new Bundle();
}

View file

@ -8,6 +8,7 @@ import android.os.Bundle;
* Base class for all messages passed between service and client
*/
public class ServiceMessage {
protected Bundle map = new Bundle();
@ -36,5 +37,4 @@ public class ServiceMessage {
return map.getString("ServiceMessageType");
}
}

View file

@ -5,10 +5,10 @@ import android.os.Bundle;
/**
* Created by geoff on 7/6/16.
* <p>
* These are "one liner" messages between client and service.
* Must still be contained within ServiceTransports
* These are "one liner" messages between client and service. Must still be contained within ServiceTransports
*/
public class ServiceNotification extends ServiceMessage {
public ServiceNotification() {
}
@ -36,14 +36,13 @@ public class ServiceNotification extends ServiceMessage {
}
public void setNotificationType(String notificationType) {
map.putString("NotificationType", notificationType);
}
public String getNotificationType() {
return map.getString("NotificationType", "");
}
public void setNotificationType(String notificationType) {
map.putString("NotificationType", notificationType);
}
}

View file

@ -6,6 +6,13 @@ import android.os.Bundle;
* Created by geoff on 6/25/16.
*/
public class ServiceResult extends ServiceMessage {
public static final int ERROR_MALFORMED_PUMP_RESPONSE = 1;
public static final int ERROR_NULL_PUMP_RESPONSE = 2;
public static final int ERROR_INVALID_PUMP_RESPONSE = 3;
public static final int ERROR_PUMP_BUSY = 4;
public ServiceResult() {
init();
}
@ -20,6 +27,22 @@ public class ServiceResult extends ServiceMessage {
}
public static final String getErrorDescription(int errorCode) {
switch (errorCode) {
case ERROR_MALFORMED_PUMP_RESPONSE:
return "Malformed Pump Response";
case ERROR_NULL_PUMP_RESPONSE:
return "Null pump response";
case ERROR_INVALID_PUMP_RESPONSE:
return "Invalid pump response";
case ERROR_PUMP_BUSY:
return "A pump command session is already in progress";
default:
return "Unknown error code (" + errorCode + ")";
}
}
@Override
public void init() {
super.init();
@ -29,13 +52,13 @@ public class ServiceResult extends ServiceMessage {
}
public void setServiceResultType(String serviceResultType) {
map.putString("ServiceResultType", serviceResultType);
public String getServiceResultType() {
return map.getString("ServiceResultType", "ServiceResult");
}
public String getServiceResultType() {
return map.getString("ServiceResultType", "ServiceResult");
public void setServiceResultType(String serviceResultType) {
map.putString("ServiceResultType", serviceResultType);
}
@ -56,28 +79,6 @@ public class ServiceResult extends ServiceMessage {
}
public static final int ERROR_MALFORMED_PUMP_RESPONSE = 1;
public static final int ERROR_NULL_PUMP_RESPONSE = 2;
public static final int ERROR_INVALID_PUMP_RESPONSE = 3;
public static final int ERROR_PUMP_BUSY = 4;
public static final String getErrorDescription(int errorCode) {
switch (errorCode) {
case ERROR_MALFORMED_PUMP_RESPONSE:
return "Malformed Pump Response";
case ERROR_NULL_PUMP_RESPONSE:
return "Null pump response";
case ERROR_INVALID_PUMP_RESPONSE:
return "Invalid pump response";
case ERROR_PUMP_BUSY:
return "A pump command session is already in progress";
default:
return "Unknown error code (" + errorCode + ")";
}
}
public boolean resultIsOK() {
return ("OK".equals(map.getString("result", "")));
}
@ -92,5 +93,4 @@ public class ServiceResult extends ServiceMessage {
return map.getString("result", "");
}
}

View file

@ -6,8 +6,7 @@ import android.os.Parcel;
/**
* Created by geoff on 7/6/16.
* <p>
* This class exists to hold a ServiceCommand along with transport variables
* such as time sent, time received, sender.
* This class exists to hold a ServiceCommand along with transport variables such as time sent, time received, sender.
* May also contain result, if the command is completed.
*/
public class ServiceTransport extends ServiceMessage {
@ -39,13 +38,18 @@ public class ServiceTransport extends ServiceMessage {
}
public Integer getSenderHashcode() {
return map.getInt("senderHashCode", 0);
}
public void setSenderHashcode(Integer senderHashcode) {
map.putInt("senderHashcode", senderHashcode);
}
public Integer getSenderHashcode() {
return map.getInt("senderHashCode", 0);
public ServiceCommand getServiceCommand() {
return new ServiceCommand(map.getBundle("ServiceCommand"));
}
@ -55,13 +59,13 @@ public class ServiceTransport extends ServiceMessage {
}
public ServiceCommand getServiceCommand() {
return new ServiceCommand(map.getBundle("ServiceCommand"));
public boolean hasServiceCommand() {
return (getMap().containsKey("ServiceCommand"));
}
public boolean hasServiceCommand() {
return (getMap().containsKey("ServiceCommand"));
public String getTransportType() {
return map.getString("transportType", "unknown");
}
@ -72,8 +76,8 @@ public class ServiceTransport extends ServiceMessage {
}
public String getTransportType() {
return map.getString("transportType", "unknown");
public ServiceResult getServiceResult() {
return new ServiceResult(map.getBundle("ServiceResult"));
}
@ -83,13 +87,13 @@ public class ServiceTransport extends ServiceMessage {
}
public ServiceResult getServiceResult() {
return new ServiceResult(map.getBundle("ServiceResult"));
public boolean hasServiceResult() {
return (getMap().containsKey("ServiceResult"));
}
public boolean hasServiceResult() {
return (getMap().containsKey("ServiceResult"));
public ServiceNotification getServiceNotification() {
return new ServiceNotification(map.getBundle("ServiceNotification"));
}
@ -99,11 +103,6 @@ public class ServiceTransport extends ServiceMessage {
}
public ServiceNotification getServiceNotification() {
return new ServiceNotification(map.getBundle("ServiceNotification"));
}
public boolean hasServiceNotification() {
return (map.containsKey("ServiceNotification"));
}

View file

@ -12,10 +12,10 @@ import info.nightscout.utils.SP;
/**
* Created by geoff on 7/9/16.
* <p>
* This class is intended to be run by the Service, for the Service.
* Not intended for clients to run.
* This class is intended to be run by the Service, for the Service. Not intended for clients to run.
*/
public class InitializePumpManagerTask extends ServiceTask {
private static final String TAG = "InitPumpManagerTask";
@ -35,7 +35,10 @@ public class InitializePumpManagerTask extends ServiceTask {
// FIXME
double lastGoodFrequency = SP.getDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, 0.0d);
if ((lastGoodFrequency > 0.0d) && RileyLinkUtil.getRileyLinkCommunicationManager().isValidFrequency(lastGoodFrequency)) {
RileyLinkUtil.getRileyLinkServiceData().lastGoodFrequency = lastGoodFrequency;
if ((lastGoodFrequency > 0.0d)
&& RileyLinkUtil.getRileyLinkCommunicationManager().isValidFrequency(lastGoodFrequency)) {
Log.i(TAG, String.format("Setting radio frequency to %.2fMHz", lastGoodFrequency));
RileyLinkUtil.getRileyLinkCommunicationManager().setRadioFrequencyForPump(lastGoodFrequency);
@ -45,13 +48,14 @@ public class InitializePumpManagerTask extends ServiceTask {
// FIXME maybe remove in AAPS
if (foundThePump) {
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorReady);
//RileyLinkUtil.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_PUMP_pumpFound), null);
// RileyLinkUtil.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_PUMP_pumpFound), null);
} else {
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.NoContactWithDevice);
//RileyLinkUtil.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_PUMP_pumpLost), null);
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError,
RileyLinkError.NoContactWithDevice);
// RileyLinkUtil.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_PUMP_pumpLost), null);
}
//RileyLinkUtil.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_note_Idle), null);
// RileyLinkUtil.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_note_Idle), null);
} else {
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_tunePump);
}

View file

@ -6,6 +6,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.data.S
* Created by geoff on 7/10/16.
*/
public class PumpTask extends ServiceTask {
public PumpTask() {
super();
}

View file

@ -6,9 +6,10 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.data.S
* Created by geoff on 7/9/16.
*/
public class ServiceTask implements Runnable {
private static final String TAG = "ServiceTask(base)";
protected ServiceTransport mTransport;
public boolean completed = false;
protected ServiceTransport mTransport;
public ServiceTask() {
@ -46,9 +47,8 @@ public class ServiceTask implements Runnable {
}
/*
protected void sendResponse(ServiceResult result) {
RoundtripService.getInstance().sendServiceTransportResponse(mTransport,result);
}
*/
* protected void sendResponse(ServiceResult result) {
* RoundtripService.getInstance().sendServiceTransportResponse(mTransport,result);
* }
*/
}

View file

@ -1,17 +1,18 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks;
import android.util.Log;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import android.util.Log;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
/**
* Created by geoff on 7/9/16.
*/
public class ServiceTaskExecutor extends ThreadPoolExecutor {
private static final String TAG = "ServiceTaskExecutor";
private static ServiceTaskExecutor instance;
private static LinkedBlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<>();
@ -20,15 +21,17 @@ public class ServiceTaskExecutor extends ThreadPoolExecutor {
instance = new ServiceTaskExecutor();
}
public static ServiceTaskExecutor getInstance() {
return instance;
}
private ServiceTaskExecutor() {
super(1, 1, 10000, TimeUnit.MILLISECONDS, taskQueue);
}
public static ServiceTaskExecutor getInstance() {
return instance;
}
public static ServiceTask startTask(ServiceTask task) {
instance.execute(task); // task will be run on async thread from pool.
return task;
@ -38,7 +41,7 @@ public class ServiceTaskExecutor extends ThreadPoolExecutor {
// FIXME
protected void beforeExecute(Thread t, Runnable r) {
// This is run on either caller UI thread or Service UI thread.
ServiceTask task = (ServiceTask) r;
ServiceTask task = (ServiceTask)r;
Log.v(TAG, "About to run task " + task.getClass().getSimpleName());
RileyLinkUtil.setCurrentTask(task);
task.preOp();
@ -48,7 +51,7 @@ public class ServiceTaskExecutor extends ThreadPoolExecutor {
// FIXME
protected void afterExecute(Runnable r, Throwable t) {
// This is run on either caller UI thread or Service UI thread.
ServiceTask task = (ServiceTask) r;
ServiceTask task = (ServiceTask)r;
task.postOp();
Log.v(TAG, "Finishing task " + task.getClass().getSimpleName());
RileyLinkUtil.finishCurrentTask(task);

View file

@ -8,7 +8,6 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.service.RileyLinkMedtron
*/
public class WakeAndTuneTask extends PumpTask {
public WakeAndTuneTask() {
}

View file

@ -7,18 +7,20 @@ import java.util.List;
* Created by geoff on 4/28/15.
*/
public class ByteUtil {
private final static char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
private final static char[] HEX_DIGITS = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
private final static String HEX_DIGITS_STR = "0123456789ABCDEF";
public static byte highByte(short s) {
return (byte) (s / 256);
return (byte)(s / 256);
}
public static byte lowByte(short s) {
return (byte) (s % 256);
return (byte)(s % 256);
}
@ -26,8 +28,8 @@ public class ByteUtil {
return (b < 0) ? b + 256 : b;
}
/* For Reference: static void System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length) */
/* For Reference: static void System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length) */
public static byte[] concat(byte[] a, byte[] b) {
@ -78,7 +80,7 @@ public class ByteUtil {
if (ra.length == 0) {
return rval;
}
for(int i = 0; i < ra.length; i++) {
for (int i = 0; i < ra.length; i++) {
rval = rval + HEX_DIGITS[(ra[i] & 0xF0) >> 4];
rval = rval + HEX_DIGITS[(ra[i] & 0x0F)];
if (i < ra.length - 1) {
@ -91,8 +93,8 @@ public class ByteUtil {
public static String showPrintable(byte[] ra) {
String s = new String();
for(int i = 0; i < ra.length; i++) {
char c = (char) ra[i];
for (int i = 0; i < ra.length; i++) {
char c = (char)ra[i];
if (((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) {
s = s + c;
} else {
@ -105,12 +107,12 @@ public class ByteUtil {
public static byte[] fromHexString(String src) {
String s = src.toUpperCase();
byte[] rval = new byte[]{};
byte[] rval = new byte[] {};
if ((s.length() % 2) != 0) {
// invalid hex string!
return null;
}
for(int i = 0; i < s.length(); i += 2) {
for (int i = 0; i < s.length(); i += 2) {
int highNibbleOrd = HEX_DIGITS_STR.indexOf(s.charAt(i));
if (highNibbleOrd < 0) {
// Not a hex digit.
@ -121,7 +123,7 @@ public class ByteUtil {
// Not a hex digit
return null;
}
rval = concat(rval, (byte) (highNibbleOrd * 16 + lowNibbleOrd));
rval = concat(rval, (byte)(highNibbleOrd * 16 + lowNibbleOrd));
}
return rval;
}
@ -129,7 +131,7 @@ public class ByteUtil {
public static byte[] fromByteArray(List<Byte> byteArray) {
byte[] rval = new byte[byteArray.size()];
for(int i = 0; i < byteArray.size(); i++) {
for (int i = 0; i < byteArray.size(); i++) {
rval[i] = byteArray.get(i);
}
return rval;
@ -138,7 +140,7 @@ public class ByteUtil {
public static ArrayList<Byte> toByteArray(byte[] data) {
ArrayList<Byte> rval = new ArrayList<>(data.length);
for(int i = 0; i < data.length; i++) {
for (int i = 0; i < data.length; i++) {
rval.add(i, new Byte(data[i]));
}
return rval;
@ -157,7 +159,7 @@ public class ByteUtil {
return -1;
}
int acc = 0;
for(i = 0; i < len1; i++) {
for (i = 0; i < len1; i++) {
acc += s1[i];
acc -= s2[i];
if (acc != 0) {
@ -171,10 +173,10 @@ public class ByteUtil {
/**
* Converts 4 (or less) ints into int. (Shorts are objects, so you can send null if you have less parameters)
*
* @param b1 short 1
* @param b2 short 2
* @param b3 short 3
* @param b4 short 4
* @param b1 short 1
* @param b2 short 2
* @param b3 short 3
* @param b4 short 4
* @param flag Conversion Flag (Big Endian, Little endian)
* @return int value
*/
@ -218,16 +220,10 @@ public class ByteUtil {
}
public enum BitConversion {
LITTLE_ENDIAN, // 20 0 0 0 = reverse
BIG_ENDIAN // 0 0 0 20 = normal - java
}
public static List<Byte> getListFromByteArray(byte[] array) {
List<Byte> listOut = new ArrayList<Byte>();
for(byte val : array) {
for (byte val : array) {
listOut.add(val);
}
@ -240,4 +236,9 @@ public class ByteUtil {
return k;
}
public enum BitConversion {
LITTLE_ENDIAN, // 20 0 0 0 = reverse
BIG_ENDIAN // 0 0 0 20 = normal - java
}
}

View file

@ -5,17 +5,71 @@ package info.nightscout.androidaps.plugins.PumpCommon.utils;
*/
public class CRC {
static final int[] crc8lookup = new int[]{0, 155, 173, 54, 193, 90, 108, 247, 25, 130, 180, 47, 216, 67, 117, 238, 50, 169, //
159, 4, 243, 104, 94, 197, 43, 176, 134, 29, 234, 113, 71, 220, 100, 255, 201, 82, 165, 62, 8, 147, 125, 230, 208, 75, //
188, 39, 17, 138, 86, 205, 251, 96, 151, 12, 58, 161, 79, 212, 226, 121, 142, 21, 35, 184, 200, 83, 101, 254, 9, 146, //
164, 63, 209, 74, 124, 231, 16, 139, 189, 38, 250, 97, 87, 204, 59, 160, 150, 13, 227, 120, 78, 213, 34, 185, 143, 20, //
172, 55, 1, 154, 109, 246, 192, 91, 181, 46, 24, 131, 116, 239, 217, 66, 158, 5, 51, 168, 95, 196, 242, 105, 135, 28, 42, //
177, 70, 221, 235, 112, 11, 144, 166, 61, 202, 81, 103, 252, 18, 137, 191, 36, 211, 72, 126, 229, 57, 162, 148, 15, 248, //
99, 85, 206, 32, 187, 141, 22, 225, 122, 76, 215, 111, 244, 194, 89, 174, 53, 3, 152, 118, 237, 219, 64, 183, 44, 26, 129, //
93, 198, 240, 107, 156, 7, 49, 170, 68, 223, 233, 114, 133, 30, 40, 179, 195, 88, 110, 245, 2, 153, 175, 52, 218, 65, 119, //
236, 27, 128, 182, 45, 241, 106, 92, 199, 48, 171, 157, 6, 232, 115, 69, 222, 41, 178, 132, 31, 167, 60, 10, 145, 102, 253, //
203, 80, 190, 37, 19, 136, 127, 228, 210, 73, 149, 14, 56, 163, 84, 207, 249, 98, 140, 23, 33, 186, 77, 214, 224, 123};
static final int[] crc8lookup = new int[] {
0, 155, 173, 54, 193, 90, 108, 247, 25,
130,
180,
47,
216,
67,
117,
238,
50,
169, //
159, 4, 243, 104, 94, 197, 43, 176, 134, 29, 234, 113, 71, 220, 100, 255, 201,
82,
165,
62,
8,
147,
125,
230,
208,
75, //
188, 39, 17, 138, 86, 205, 251, 96, 151, 12, 58, 161, 79, 212, 226, 121, 142, 21,
35,
184,
200,
83,
101,
254,
9,
146, //
164, 63, 209, 74, 124, 231, 16, 139, 189, 38, 250, 97, 87, 204, 59, 160, 150, 13, 227,
120,
78,
213,
34,
185,
143,
20, //
172, 55, 1, 154, 109, 246, 192, 91, 181, 46, 24, 131, 116, 239, 217, 66, 158, 5, 51, 168, 95,
196,
242,
105,
135,
28,
42, //
177, 70, 221, 235, 112, 11, 144, 166, 61, 202, 81, 103, 252, 18, 137, 191, 36, 211, 72, 126, 229,
57,
162,
148,
15,
248, //
99, 85, 206, 32, 187, 141, 22, 225, 122, 76, 215, 111, 244, 194, 89, 174, 53, 3, 152, 118, 237, 219, 64,
183,
44,
26,
129, //
93, 198, 240, 107, 156, 7, 49, 170, 68, 223, 233, 114, 133, 30, 40, 179, 195, 88, 110, 245, 2, 153, 175, 52,
218,
65,
119, //
236, 27, 128, 182, 45, 241, 106, 92, 199, 48, 171, 157, 6, 232, 115, 69, 222, 41, 178, 132, 31, 167, 60, 10,
145, 102,
253, //
203, 80, 190, 37, 19, 136, 127, 228, 210, 73, 149, 14, 56, 163, 84, 207, 249, 98, 140, 23, 33, 186, 77, 214,
224, 123 };
public static byte crc8(byte[] data, int len) {
@ -26,16 +80,16 @@ public class CRC {
if (len > data.length) {
len = data.length;
}
for(int i = 0; i < len; i++) {
for (int i = 0; i < len; i++) {
int tmp = result;
int tmp2 = tmp ^ data[i];
int tmp3 = tmp2 & 0xFF;
int idx = tmp3;
result = (byte) crc8lookup[idx];
// log(String.format("iter=%d,tmp=0x%02x, tmp2=0x%02x, tmp3=0x%02x, lookup=0x%02x",i,tmp,tmp2,tmp3,result));
result = (byte)crc8lookup[idx];
// log(String.format("iter=%d,tmp=0x%02x, tmp2=0x%02x, tmp3=0x%02x, lookup=0x%02x",i,tmp,tmp2,tmp3,result));
}
// orig python:
//result = klass.lookup[ ( result ^ block[ i ] & 0xFF ) ]
// result = klass.lookup[ ( result ^ block[ i ] & 0xFF ) ]
return result;
}
@ -51,18 +105,19 @@ public class CRC {
int polynomial = 0x1021;
if (data != null) {
if (data.length > 0) {
for(int j = 0; j < data.length; j++) {
for (int j = 0; j < data.length; j++) {
byte b = data[j];
for(int i = 0; i < 8; i++) {
for (int i = 0; i < 8; i++) {
boolean bit = ((b >> (7 - i) & 1) == 1);
boolean c15 = ((crc >> 15 & 1) == 1);
crc <<= 1;
if (c15 ^ bit) crc ^= polynomial;
if (c15 ^ bit)
crc ^= polynomial;
}
}
}
}
crc &= 0xffff;
return new byte[]{(byte) ((crc & 0xFF00) >> 8), (byte) (crc & 0xFF)};
return new byte[] { (byte)((crc & 0xFF00) >> 8), (byte)(crc & 0xFF) };
}
}

View file

@ -23,7 +23,9 @@ import java.util.List;
* 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'};
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) {
@ -40,11 +42,11 @@ public class HexDump {
result.append("\n0x");
result.append(toHexString(offset));
for(int i = offset; i < offset + length; i++) {
for (int i = offset; i < offset + length; i++) {
if (lineIndex == 16) {
result.append(" ");
for(int j = 0; j < 16; j++) {
for (int j = 0; j < 16; j++) {
if (line[j] > ' ' && line[j] < '~') {
result.append(new String(line, j, 1));
} else {
@ -68,11 +70,11 @@ public class HexDump {
if (lineIndex != 16) {
int count = (16 - lineIndex) * 3;
count++;
for(int i = 0; i < count; i++) {
for (int i = 0; i < count; i++) {
result.append(" ");
}
for(int i = 0; i < lineIndex; i++) {
for (int i = 0; i < lineIndex; i++) {
if (line[i] > ' ' && line[i] < '~') {
result.append(new String(line, i, 1));
} else {
@ -99,7 +101,7 @@ public class HexDump {
char[] buf = new char[length * 2];
int bufIndex = 0;
for(int i = offset; i < offset + length; i++) {
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];
@ -120,7 +122,7 @@ public class HexDump {
sb.append("Zero-length array");
} else {
for(byte element : arr) {
for (byte element : arr) {
sb.append(getCorrectHexValue(element));
sb.append(" ");
}
@ -134,7 +136,7 @@ public class HexDump {
public static String toHexStringDisplayable(List<Byte> data) {
StringBuilder sb = new StringBuilder();
for(byte element : data) {
for (byte element : data) {
sb.append(getCorrectHexValue(element));
sb.append(" ");
}
@ -144,7 +146,7 @@ public class HexDump {
public static String getCorrectHexValue(byte inp) {
String hx = Integer.toHexString((char) inp);
String hx = Integer.toHexString((char)inp);
hx = hx.toUpperCase();
if (hx.length() == 0)
@ -185,10 +187,10 @@ public class HexDump {
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);
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;
}
@ -197,8 +199,8 @@ public class HexDump {
public static byte[] toByteArray(short i) {
byte[] array = new byte[2];
array[1] = (byte) (i & 0xFF);
array[0] = (byte) ((i >> 8) & 0xFF);
array[1] = (byte)(i & 0xFF);
array[0] = (byte)((i >> 8) & 0xFF);
return array;
}
@ -220,12 +222,11 @@ public class HexDump {
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)));
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

@ -10,11 +10,11 @@ import android.os.Build;
import info.nightscout.androidaps.R;
/**
* Helper for checking if location services are enabled on the device.
*/
public class LocationHelper {
/**
* Determine if GPS is currently enabled.
* <p>
@ -24,10 +24,11 @@ public class LocationHelper {
* @return true if location is enabled, false otherwise.
*/
public static boolean isLocationEnabled(Context context) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
LocationManager locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
/**
* Prompt the user to enable GPS location if it isn't already on.
*
@ -44,6 +45,7 @@ public class LocationHelper {
builder.setTitle(R.string.location_not_found_title);
builder.setMessage(R.string.location_not_found_message);
builder.setPositiveButton(R.string.location_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
parent.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
@ -52,6 +54,7 @@ public class LocationHelper {
builder.create().show();
}
/**
* Prompt the user to enable GPS location on devices that need it for Bluetooth discovery.
* <p>
@ -66,8 +69,9 @@ public class LocationHelper {
}
}
//public static Boolean locationPermission(ActivityWithMenu act) {
// return ActivityCompat.checkSelfPermission(act, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
//}
// public static Boolean locationPermission(ActivityWithMenu act) {
// return ActivityCompat.checkSelfPermission(act, Manifest.permission.ACCESS_FINE_LOCATION) ==
// PackageManager.PERMISSION_GRANTED;
// }
}

View file

@ -11,13 +11,12 @@ import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
public class PumpUtil {
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType)
{
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType) {
setPumpDescription(pumpDescription, pumpType, false);
}
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType, boolean isVirtualPump)
{
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType, boolean isVirtualPump) {
PumpCapability pumpCapability = isVirtualPump ? PumpCapability.VirtualPump : pumpType.getPumpCapability();
pumpDescription.isBolusCapable = pumpCapability.hasCapability(PumpCapability.Bolus);
@ -30,14 +29,11 @@ public class PumpUtil {
pumpDescription.isTempBasalCapable = pumpCapability.hasCapability(PumpCapability.TBR);
if (pumpType.getPumpTempBasalType()==PumpTempBasalType.Percent)
{
if (pumpType.getPumpTempBasalType() == PumpTempBasalType.Percent) {
pumpDescription.tempBasalStyle = PumpDescription.PERCENT;
pumpDescription.maxTempPercent = pumpType.getTbrSettings().getMaxDose().intValue();
pumpDescription.tempPercentStep = (int)pumpType.getTbrSettings().getStep();
}
else
{
} else {
pumpDescription.tempBasalStyle = PumpDescription.ABSOLUTE;
pumpDescription.maxTempAbsolute = pumpType.getTbrSettings().getMaxDose();
pumpDescription.tempAbsoluteStep = pumpType.getTbrSettings().getStep();
@ -46,7 +42,6 @@ public class PumpUtil {
pumpDescription.tempDurationStep = pumpType.getTbrSettings().getDurationStep();
pumpDescription.tempMaxDuration = pumpType.getTbrSettings().getMaxDuration();
pumpDescription.isSetBasalProfileCapable = pumpCapability.hasCapability(PumpCapability.BasalProfileSet);
pumpDescription.basalStep = pumpType.getBaseBasalStep();
pumpDescription.basalMinimumRate = pumpType.getBaseBasalMinValue();
@ -55,5 +50,4 @@ public class PumpUtil {
pumpDescription.storesCarbInfo = pumpCapability.hasCapability(PumpCapability.StoreCarbInfo);
}
}

View file

@ -1,18 +1,18 @@
package info.nightscout.androidaps.plugins.PumpCommon.utils;
import org.joda.time.LocalDateTime;
import java.nio.charset.Charset;
import java.text.DecimalFormat;
import java.util.ArrayList;
import org.joda.time.LocalDateTime;
/**
* Created by geoff on 4/28/15.
*/
public class StringUtil {
public static DecimalFormat DecimalFormaters[] = {new DecimalFormat("#0"), new DecimalFormat("#0.0"), new DecimalFormat("#0.00"), new DecimalFormat("#0.000")};
public static DecimalFormat DecimalFormaters[] = {
new DecimalFormat("#0"), new DecimalFormat("#0.0"), new DecimalFormat("#0.00"), new DecimalFormat("#0.000") };
public static String fromBytes(byte[] ra) {
@ -25,7 +25,7 @@ public class StringUtil {
int sz = ra.size();
String rval = "";
int n;
for(n = 0; n < sz; n++) {
for (n = 0; n < sz; n++) {
rval = rval + ra.get(n);
if (n < sz - 1) {
rval = rval + joiner;

View file

@ -4,6 +4,7 @@ package info.nightscout.androidaps.plugins.PumpCommon.utils;
* Created by geoff on 5/27/16.
*/
public class ThreadUtil {
public static long getThreadId() {
return Thread.currentThread().getId();
}

View file

@ -1,5 +1,9 @@
package info.nightscout.androidaps.plugins.PumpMedtronic;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.annotation.SuppressLint;
import android.app.Activity;
@ -15,18 +19,14 @@ import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.crashlytics.android.Crashlytics;
import com.joanzapata.iconify.widget.IconTextView;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
@ -34,11 +34,11 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpCommon.dialog.RileylinkSettingsActivity;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.dialog.RileyLinkStatusActivity;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicCommandType;
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.PumpMedtronic.driver.MedtronicPumpStatus;
@ -53,10 +53,40 @@ import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SetWarnColor;
public class MedtronicFragment extends SubscriberFragment {
private static Logger LOG = LoggerFactory.getLogger(MedtronicFragment.class);
private static Logger LOG = LoggerFactory.getLogger(MedtronicFragment.class);
@BindView(R.id.medtronic_lastconnection)
TextView lastConnectionView;
@BindView(R.id.medtronic_lastbolus)
TextView lastBolusView;
@BindView(R.id.medtronic_basabasalrate)
TextView basaBasalRateView;
// @BindView(R.id.medtronic_btconnection)
// TextView btConnectionView;
@BindView(R.id.medtronic_tempbasal)
TextView tempBasalView;
@BindView(R.id.medtronic_pumpstate_battery)
TextView batteryView;
@BindView(R.id.medtronic_rl_status)
IconTextView rileyLinkStatus;
@BindView(R.id.medtronic_reservoir)
TextView reservoirView;
@BindView(R.id.medtronic_errors)
TextView errorsView;
@BindView(R.id.medtronic_queue)
TextView queueView;
@BindView(R.id.overview_pumpstatuslayout)
LinearLayout pumpStatusLayout;
@BindView(R.id.overview_pump_medtronic)
TextView overviewPumpMedtronicView;
@BindView(R.id.medtronic_pump_status)
IconTextView pumpStatusIconView;
@BindView(R.id.medtronic_refresh)
Button refreshButton;
private Handler loopHandler = new Handler();
private Runnable refreshLoop = new Runnable() {
@Override
public void run() {
updateGUI();
@ -64,53 +94,11 @@ public class MedtronicFragment extends SubscriberFragment {
}
};
@BindView(R.id.medtronic_lastconnection)
TextView lastConnectionView;
//@BindView(R.id.medtronic_btconnection)
//TextView btConnectionView;
@BindView(R.id.medtronic_lastbolus)
TextView lastBolusView;
@BindView(R.id.medtronic_basabasalrate)
TextView basaBasalRateView;
@BindView(R.id.medtronic_tempbasal)
TextView tempBasalView;
@BindView(R.id.medtronic_pumpstate_battery)
TextView batteryView;
@BindView(R.id.medtronic_rl_status)
IconTextView rileyLinkStatus;
@BindView(R.id.medtronic_reservoir)
TextView reservoirView;
@BindView(R.id.medtronic_errors)
TextView errorsView;
@BindView(R.id.medtronic_queue)
TextView queueView;
@BindView(R.id.overview_pumpstatuslayout)
LinearLayout pumpStatusLayout;
@BindView(R.id.overview_pump_medtronic)
TextView overviewPumpMedtronicView;
@BindView(R.id.medtronic_pump_status)
IconTextView pumpStatusIconView;
@BindView(R.id.medtronic_refresh)
Button refreshButton;
public MedtronicFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -124,9 +112,9 @@ public class MedtronicFragment extends SubscriberFragment {
loopHandler.removeCallbacks(refreshLoop);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
try {
View view = inflater.inflate(R.layout.medtronic_fragment, container, false);
unbinder = ButterKnife.bind(this, view);
@ -148,17 +136,20 @@ public class MedtronicFragment extends SubscriberFragment {
return null;
}
@OnClick(R.id.medtronic_history)
void onHistoryClick() {
//startActivity(new Intent(getContext(), DanaRHistoryActivity.class));
// startActivity(new Intent(getContext(), DanaRHistoryActivity.class));
}
@OnClick(R.id.medtronic_refresh)
void onRefreshClick() {
refreshButton.setEnabled(false);
MedtronicPumpPlugin.getPlugin().resetStatusState();
ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked refresh", new Callback() {
@Override
public void run() {
refreshButton.setEnabled(true);
@ -166,9 +157,10 @@ public class MedtronicFragment extends SubscriberFragment {
});
}
@OnClick(R.id.medtronic_stats)
void onStatsClick() {
startActivity(new Intent(getContext(), RileylinkSettingsActivity.class));
startActivity(new Intent(getContext(), RileyLinkStatusActivity.class));
}
@ -182,18 +174,17 @@ public class MedtronicFragment extends SubscriberFragment {
public void onStatusEvent(final EventMedtronicDeviceStatusChange eventStatusChange) {
LOG.info("onStatusEvent(EventMedtronicDeviceStatusChange): {}", eventStatusChange);
Activity activity = getActivity();
//final String status = c.textStatus();
// final String status = c.textStatus();
if (activity != null) {
activity.runOnUiThread(
new Runnable() {
@Override
public void run() {
activity.runOnUiThread(new Runnable() {
MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
setDeviceStatus(pumpStatus);
}
}
);
@Override
public void run() {
MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
setDeviceStatus(pumpStatus);
}
});
}
}
@ -201,7 +192,8 @@ public class MedtronicFragment extends SubscriberFragment {
private void setDeviceStatus(MedtronicPumpStatus pumpStatus) {
pumpStatus.rileyLinkServiceState = (RileyLinkServiceState) checkStatusSet(pumpStatus.rileyLinkServiceState, RileyLinkUtil.getServiceState());
pumpStatus.rileyLinkServiceState = (RileyLinkServiceState)checkStatusSet(pumpStatus.rileyLinkServiceState,
RileyLinkUtil.getServiceState());
if (pumpStatus.rileyLinkServiceState != null) {
@ -222,7 +214,7 @@ public class MedtronicFragment extends SubscriberFragment {
}
}
pumpStatus.rileyLinkError = (RileyLinkError) checkStatusSet(pumpStatus.rileyLinkError, RileyLinkUtil.getError());
pumpStatus.rileyLinkError = (RileyLinkError)checkStatusSet(pumpStatus.rileyLinkError, RileyLinkUtil.getError());
if (pumpStatus.rileyLinkError != null) {
int resourceId = pumpStatus.rileyLinkError.getResourceId(getTargetDevice());
@ -230,11 +222,11 @@ public class MedtronicFragment extends SubscriberFragment {
} else
errorsView.setText("-");
pumpStatus.pumpDeviceState = (PumpDeviceState) checkStatusSet(pumpStatus.pumpDeviceState, MedtronicUtil.getPumpDeviceState());
pumpStatus.pumpDeviceState = (PumpDeviceState)checkStatusSet(pumpStatus.pumpDeviceState,
MedtronicUtil.getPumpDeviceState());
if (pumpStatus.pumpDeviceState != null) {
// TODO Pump State
// TODO Pump State
switch (pumpStatus.pumpDeviceState) {
case Sleeping:
@ -260,17 +252,17 @@ public class MedtronicFragment extends SubscriberFragment {
pumpStatusIconView.setText(" " + cmd.name());
}
break;
break;
// // FIXME
//
// pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name());
// break;
//
// // FIXME
//
// pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name());
// break;
// // FIXME
//
// pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name());
// break;
//
// // FIXME
//
// pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name());
// break;
default:
LOG.warn("Unknown pump state: " + pumpStatus.pumpDeviceState);
}
@ -278,7 +270,6 @@ public class MedtronicFragment extends SubscriberFragment {
pumpStatusIconView.setText("{fa-bed} ");
}
if (queueView != null) {
Spanned status = ConfigBuilderPlugin.getCommandQueue().spannedStatus();
if (status.toString().equals("")) {
@ -289,7 +280,6 @@ public class MedtronicFragment extends SubscriberFragment {
}
}
}
@ -320,32 +310,37 @@ public class MedtronicFragment extends SubscriberFragment {
updateGUI();
}
@Subscribe
public void onStatusEvent(final EventTempBasalChange s) {
updateGUI();
}
@Subscribe
public void onStatusEvent(final EventExtendedBolusChange s) {
updateGUI();
}
@Subscribe
public void onStatusEvent(final EventQueueChanged s) {
updateGUI();
}
// GUI functions
@Override
protected void updateGUI() {
Activity activity = getActivity();
if (activity != null && basaBasalRateView != null)
activity.runOnUiThread(new Runnable() {
@SuppressLint("SetTextI18n")
@Override
public void run() {
MedtronicPumpPlugin plugin = (MedtronicPumpPlugin) MedtronicPumpPlugin.getPlugin();
MedtronicPumpPlugin plugin = (MedtronicPumpPlugin)MedtronicPumpPlugin.getPlugin();
MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
setDeviceStatus(pumpStatus);
@ -384,22 +379,23 @@ public class MedtronicFragment extends SubscriberFragment {
lastBolusView.setText("");
}
// base basal rate
basaBasalRateView.setText("(" + (pumpStatus.activeProfileName) + ") " + MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate()));
basaBasalRateView.setText("(" + (pumpStatus.activeProfileName) + ") "
+ MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate()));
// FIXME temp basal - check - maybe set as combo ??
if (ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses()) {
if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) {
tempBasalView.setText(TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
tempBasalView.setText(TreatmentsPlugin.getPlugin()
.getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
} else {
tempBasalView.setText("");
}
} else {
// v2 plugin
if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
tempBasalView.setText(TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
tempBasalView.setText(TreatmentsPlugin.getPlugin()
.getTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
} else {
tempBasalView.setText("");
}
@ -410,7 +406,8 @@ public class MedtronicFragment extends SubscriberFragment {
SetWarnColor.setColorInverse(batteryView, pumpStatus.batteryRemaining, 51d, 26d);
// reservoir
reservoirView.setText(DecimalFormatter.to0Decimal(pumpStatus.reservoirRemainingUnits) + " / " + pumpStatus.reservoirFullUnits + " " + MainApp.gs(R.string.insulin_unit_shortname));
reservoirView.setText(DecimalFormatter.to0Decimal(pumpStatus.reservoirRemainingUnits) + " / "
+ pumpStatus.reservoirFullUnits + " " + MainApp.gs(R.string.insulin_unit_shortname));
SetWarnColor.setColorInverse(reservoirView, pumpStatus.reservoirRemainingUnits, 50d, 20d);
errorsView.setText(pumpStatus.getErrorInfo());

View file

@ -1,18 +1,19 @@
package info.nightscout.androidaps.plugins.PumpMedtronic;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.joda.time.LocalDateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
@ -30,6 +31,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpCommon.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.ServiceTaskExecutor;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.WakeAndTuneTask;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.ui.MedtronicUIComm;
@ -53,10 +55,8 @@ import info.nightscout.utils.SP;
public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInterface {
private static final Logger LOG = LoggerFactory.getLogger(MedtronicPumpPlugin.class);
private RileyLinkMedtronicService medtronicService;
protected static MedtronicPumpPlugin plugin = null;
private RileyLinkMedtronicService medtronicService;
private MedtronicPumpStatus pumpStatusLocal = null;
private MedtronicUIComm medtronicUIComm = new MedtronicUIComm();
@ -68,32 +68,24 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
private Map<MedtronicStatusRefreshType, Long> statusRefreshMap = new HashMap<>();
public static MedtronicPumpPlugin getPlugin() {
if (plugin == null)
plugin = new MedtronicPumpPlugin();
return plugin;
}
private MedtronicPumpPlugin() {
// super(new PluginDescription() //
// .mainType(PluginType.PUMP) //
// .fragmentClass(MedtronicFragment.class.getName()) //
// .pluginName(R.string.medtronic_name) //
// .shortName(R.string.medtronic_name_short) //
// .preferencesId(R.xml.pref_medtronic));
// super(new PluginDescription() //
// .mainType(PluginType.PUMP) //
// .fragmentClass(MedtronicFragment.class.getName()) //
// .pluginName(R.string.medtronic_name) //
// .shortName(R.string.medtronic_name_short) //
// .preferencesId(R.xml.pref_medtronic));
super(new MedtronicPumpDriver(), //
"MedtronicPump", //
new PluginDescription() //
.mainType(PluginType.PUMP) //
.fragmentClass(MedtronicFragment.class.getName()) //
.pluginName(R.string.medtronic_name) //
.shortName(R.string.medtronic_name_short) //
.preferencesId(R.xml.pref_medtronic), //
PumpType.Medtronic_512_712 // we default to most basic model, correct model from config is loaded later
"MedtronicPump", //
new PluginDescription() //
.mainType(PluginType.PUMP) //
.fragmentClass(MedtronicFragment.class.getName()) //
.pluginName(R.string.medtronic_name) //
.shortName(R.string.medtronic_name_short) //
.preferencesId(R.xml.pref_medtronic), //
PumpType.Medtronic_512_712 // we default to most basic model, correct model from config is loaded later
);
serviceConnection = new ServiceConnection() {
@ -103,9 +95,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
medtronicService = null;
}
public void onServiceConnected(ComponentName name, IBinder service) {
LOG.debug("RileyLinkMedtronicService is connected");
RileyLinkMedtronicService.LocalBinder mLocalBinder = (RileyLinkMedtronicService.LocalBinder) service;
RileyLinkMedtronicService.LocalBinder mLocalBinder = (RileyLinkMedtronicService.LocalBinder)service;
medtronicService = mLocalBinder.getServiceInstance();
new Thread(() -> {
@ -126,12 +119,22 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
public static MedtronicPumpPlugin getPlugin() {
if (plugin == null)
plugin = new MedtronicPumpPlugin();
return plugin;
}
@Override
public void initPumpStatusData() {
this.pumpStatusLocal = new MedtronicPumpStatus(pumpDescription);
MedtronicUtil.setPumpStatus(pumpStatusLocal);
pumpStatusLocal.lastConnection = SP.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
pumpStatusLocal.lastDataTime = new LocalDateTime(pumpStatusLocal.lastConnection);
pumpStatusLocal.refreshConfiguration();
LOG.debug("initPumpStatusData: {}", this.pumpStatusLocal);
@ -164,6 +167,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
public void onStartCustomActions() {
// check status every minute
@ -178,7 +182,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
} while (serviceRunning);
}).start();
}
@ -193,6 +196,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
return "Medtronic";
}
@Override
public PumpDescription getPumpDescription() {
return this.pumpDescription;
@ -216,6 +220,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
return isServiceSet() && medtronicService.isInitialized();
}
// FIXME
public boolean isSuspended() {
return isServiceSet() && medtronicService.isSuspended();
@ -246,7 +251,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
getMDTPumpStatus();
if (firstRun) {
initializePump(true);
} else {
@ -261,6 +265,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
firstRun = true;
}
private void refreshAnyStatusThatNeedsToBeRefreshed() {
if (!doWeHaveAnyStatusNeededRefereshing()) {
@ -277,7 +282,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
case PumpHistory: {
readPumpHistory();
}
break;
break;
case PumpTime:
case BatteryStatus:
@ -287,7 +292,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
scheduleNextRefresh(refreshType.getKey());
resetTime = true;
}
break;
break;
}
}
}
@ -310,6 +315,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
return false;
}
private void initializePump(boolean realInit) {
LOG.error("initializePump - start");
@ -322,7 +328,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
} else {
if (pumpStatusLocal.medtronicDeviceType != MedtronicUtil.getMedtronicPumpModel()) {
LOG.warn("Configured pump is not the same as one detected.");
Notification notification = new Notification(Notification.MEDTRONIC_PUMP_ALARM, MainApp.gs(R.string.medtronic_error_pump_type_set_differs_from_detected), Notification.NORMAL);
Notification notification = new Notification(Notification.MEDTRONIC_PUMP_ALARM,
MainApp.gs(R.string.medtronic_error_pump_type_set_differs_from_detected), Notification.NORMAL);
MainApp.bus().post(new EventNewNotification(notification));
}
}
@ -331,7 +338,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
// pump history handling - special, updates every 5 minutes ???
readPumpHistory();
// TODO rewrite reading of data to be done in background or different thread perhaps ??
// remaining insulin (>50 = 4h; 50-20 = 1h; 15m)
@ -352,7 +358,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
// read profile (once, later its controlled by isThisProfileSet method)
medtronicUIComm.executeCommand(MedtronicCommandType.GetBasalProfileSTD);
// TODO handle if tunning was needed (more than 5 timeouts)
int errorCount = medtronicUIComm.getInvalidResponsesCount();
@ -406,7 +411,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
index++;
}
if (!invalid) {
LOG.debug("Basal profile is same as AAPS one.");
} else {
@ -427,12 +431,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
@Override
public Date lastDataTime() {
if (pumpStatusLocal != null && pumpStatusLocal.lastDataTime != null) {
return pumpStatusLocal.lastDataTime;
return pumpStatusLocal.lastDataTime.toDate();
}
return new Date();
}
@Override
public double getBaseBasalRate() {
return getMDTPumpStatus().getBasalProfileForHour();
@ -462,9 +467,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
LOG.error("MedtronicPumpPlugin::deliverBolus Not fully implemented - Just base command.");
// TODO should wait and display bolus delivery
MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetBolus, detailedBolusInfo.insulin);
MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetBolus,
detailedBolusInfo.insulin);
Boolean response = (Boolean) responseTask.returnData;
Boolean response = (Boolean)responseTask.returnData;
// TODO display bolus
@ -472,128 +478,133 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
// FIXME this needs to be fixed to read info from history
boolean treatmentCreated = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
getMDTPumpStatus().reservoirRemainingUnits -= detailedBolusInfo.insulin; // we subtract insulin, exact amount will be visible with next remainingInsulin update.
getMDTPumpStatus().reservoirRemainingUnits -= detailedBolusInfo.insulin; // we subtract insulin, exact
// amount will be visible with
// next remainingInsulin
// update.
incrementStatistics(detailedBolusInfo.isSMB ? MedtronicConst.Statistics.SMBBoluses : MedtronicConst.Statistics.StandardBoluses);
incrementStatistics(detailedBolusInfo.isSMB ? MedtronicConst.Statistics.SMBBoluses
: MedtronicConst.Statistics.StandardBoluses);
}
readPumpHistory();
return new PumpEnactResult().success(response).enacted(response);
// pump.activity = MainApp.gs(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin);
// MainApp.bus().post(new EventComboPumpUpdateGUI());
//
// // check pump is ready and all pump bolus records are known
// CommandResult stateResult = runCommand(null, 2, () -> ruffyScripter.readQuickInfo(1));
// if (!stateResult.success) {
// return new PumpEnactResult().success(false).enacted(false)
// .comment(MainApp.gs(R.string.combo_error_no_connection_no_bolus_delivered));
// }
// if (stateResult.reservoirLevel != -1 && stateResult.reservoirLevel - 0.5 < detailedBolusInfo.insulin) {
// return new PumpEnactResult().success(false).enacted(false)
// .comment(MainApp.gs(R.string.combo_reservoir_level_insufficient_for_bolus));
// }
// // the commands above ensured a connection was made, which updated this field
// if (pumpHistoryChanged) {
// return new PumpEnactResult().success(false).enacted(false)
// .comment(MainApp.gs(R.string.combo_bolus_rejected_due_to_pump_history_change));
// }
//
// Bolus previousBolus = stateResult.history != null && !stateResult.history.bolusHistory.isEmpty()
// ? stateResult.history.bolusHistory.get(0)
// : new Bolus(0, 0, false);
//
// // reject a bolus if one with the exact same size was successfully delivered
// // within the last 1-2 minutes
// if (Math.abs(previousBolus.amount - detailedBolusInfo.insulin) < 0.01
// && previousBolus.timestamp + 60 * 1000 > System.currentTimeMillis()) {
// log.debug("Bolu request rejected, same bolus was successfully delivered very recently");
// return new PumpEnactResult().success(false).enacted(false)
// .comment(MainApp.gs(R.string.bolus_frequency_exceeded));
// }
//
//
//
// if (cancelBolus) {
// return new PumpEnactResult().success(true).enacted(false);
// }
//
// BolusProgressReporter progressReporter = detailedBolusInfo.isSMB ? nullBolusProgressReporter : bolusProgressReporter;
//
// // start bolus delivery
// scripterIsBolusing = true;
// runCommand(null, 0,
// () -> ruffyScripter.deliverBolus(detailedBolusInfo.insulin, progressReporter));
// scripterIsBolusing = false;
//
// // Note that the result of the issued bolus command is not checked. If there was
// // a connection problem, ruffyscripter tried to recover and we can just check the
// // history below to see what was actually delivered
//
// // get last bolus from pump history for verification
// // (reads 2 records to update `recentBoluses` further down)
// CommandResult postBolusStateResult = runCommand(null, 3, () -> ruffyScripter.readQuickInfo(2));
// if (!postBolusStateResult.success) {
// return new PumpEnactResult().success(false).enacted(false)
// .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed));
// }
// Bolus lastPumpBolus = postBolusStateResult.history != null && !postBolusStateResult.history.bolusHistory.isEmpty()
// ? postBolusStateResult.history.bolusHistory.get(0)
// : null;
//
// // no bolus delivered?
// if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus)) {
// if (cancelBolus) {
// return new PumpEnactResult().success(true).enacted(false);
// } else {
// return new PumpEnactResult()
// .success(false)
// .enacted(false)
// .comment(MainApp.gs(R.string.combo_error_no_bolus_delivered));
// }
// }
//
// // at least some insulin delivered, so add it to treatments
// if (!addBolusToTreatments(detailedBolusInfo, lastPumpBolus))
// return new PumpEnactResult().success(false).enacted(true)
// .comment(MainApp.gs(R.string.combo_error_updating_treatment_record));
//
// // check pump bolus record has a sane timestamp
// long now = System.currentTimeMillis();
// if (lastPumpBolus.timestamp < now - 10 * 60 * 1000 || lastPumpBolus.timestamp > now + 10 * 60 * 1000) {
// Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_suspious_bolus_time), Notification.URGENT);
// MainApp.bus().post(new EventNewNotification(notification));
// }
//
// // update `recentBoluses` so the bolus was just delivered won't be detected as a new
// // bolus that has been delivered on the pump
// recentBoluses = postBolusStateResult.history.bolusHistory;
//
// // only a partial bolus was delivered
// if (Math.abs(lastPumpBolus.amount - detailedBolusInfo.insulin) > 0.01) {
// if (cancelBolus) {
// return new PumpEnactResult().success(true).enacted(true);
// }
// return new PumpEnactResult().success(false).enacted(true)
// .comment(MainApp.gs(R.string.combo_error_partial_bolus_delivered,
// lastPumpBolus.amount, detailedBolusInfo.insulin));
// }
//
// // full bolus was delivered successfully
// incrementBolusCount();
// return new PumpEnactResult()
// .success(true)
// .enacted(lastPumpBolus.amount > 0)
// .bolusDelivered(lastPumpBolus.amount)
// .carbsDelivered(detailedBolusInfo.carbs);
// pump.activity = MainApp.gs(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin);
// MainApp.bus().post(new EventComboPumpUpdateGUI());
//
// // check pump is ready and all pump bolus records are known
// CommandResult stateResult = runCommand(null, 2, () -> ruffyScripter.readQuickInfo(1));
// if (!stateResult.success) {
// return new PumpEnactResult().success(false).enacted(false)
// .comment(MainApp.gs(R.string.combo_error_no_connection_no_bolus_delivered));
// }
// if (stateResult.reservoirLevel != -1 && stateResult.reservoirLevel - 0.5 < detailedBolusInfo.insulin) {
// return new PumpEnactResult().success(false).enacted(false)
// .comment(MainApp.gs(R.string.combo_reservoir_level_insufficient_for_bolus));
// }
// // the commands above ensured a connection was made, which updated this field
// if (pumpHistoryChanged) {
// return new PumpEnactResult().success(false).enacted(false)
// .comment(MainApp.gs(R.string.combo_bolus_rejected_due_to_pump_history_change));
// }
//
// Bolus previousBolus = stateResult.history != null && !stateResult.history.bolusHistory.isEmpty()
// ? stateResult.history.bolusHistory.get(0)
// : new Bolus(0, 0, false);
//
// // reject a bolus if one with the exact same size was successfully delivered
// // within the last 1-2 minutes
// if (Math.abs(previousBolus.amount - detailedBolusInfo.insulin) < 0.01
// && previousBolus.timestamp + 60 * 1000 > System.currentTimeMillis()) {
// log.debug("Bolu request rejected, same bolus was successfully delivered very recently");
// return new PumpEnactResult().success(false).enacted(false)
// .comment(MainApp.gs(R.string.bolus_frequency_exceeded));
// }
//
//
//
// if (cancelBolus) {
// return new PumpEnactResult().success(true).enacted(false);
// }
//
// BolusProgressReporter progressReporter = detailedBolusInfo.isSMB ? nullBolusProgressReporter :
// bolusProgressReporter;
//
// // start bolus delivery
// scripterIsBolusing = true;
// runCommand(null, 0,
// () -> ruffyScripter.deliverBolus(detailedBolusInfo.insulin, progressReporter));
// scripterIsBolusing = false;
//
// // Note that the result of the issued bolus command is not checked. If there was
// // a connection problem, ruffyscripter tried to recover and we can just check the
// // history below to see what was actually delivered
//
// // get last bolus from pump history for verification
// // (reads 2 records to update `recentBoluses` further down)
// CommandResult postBolusStateResult = runCommand(null, 3, () -> ruffyScripter.readQuickInfo(2));
// if (!postBolusStateResult.success) {
// return new PumpEnactResult().success(false).enacted(false)
// .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed));
// }
// Bolus lastPumpBolus = postBolusStateResult.history != null &&
// !postBolusStateResult.history.bolusHistory.isEmpty()
// ? postBolusStateResult.history.bolusHistory.get(0)
// : null;
//
// // no bolus delivered?
// if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus)) {
// if (cancelBolus) {
// return new PumpEnactResult().success(true).enacted(false);
// } else {
// return new PumpEnactResult()
// .success(false)
// .enacted(false)
// .comment(MainApp.gs(R.string.combo_error_no_bolus_delivered));
// }
// }
//
// // at least some insulin delivered, so add it to treatments
// if (!addBolusToTreatments(detailedBolusInfo, lastPumpBolus))
// return new PumpEnactResult().success(false).enacted(true)
// .comment(MainApp.gs(R.string.combo_error_updating_treatment_record));
//
// // check pump bolus record has a sane timestamp
// long now = System.currentTimeMillis();
// if (lastPumpBolus.timestamp < now - 10 * 60 * 1000 || lastPumpBolus.timestamp > now + 10 * 60 * 1000) {
// Notification notification = new Notification(Notification.COMBO_PUMP_ALARM,
// MainApp.gs(R.string.combo_suspious_bolus_time), Notification.URGENT);
// MainApp.bus().post(new EventNewNotification(notification));
// }
//
// // update `recentBoluses` so the bolus was just delivered won't be detected as a new
// // bolus that has been delivered on the pump
// recentBoluses = postBolusStateResult.history.bolusHistory;
//
// // only a partial bolus was delivered
// if (Math.abs(lastPumpBolus.amount - detailedBolusInfo.insulin) > 0.01) {
// if (cancelBolus) {
// return new PumpEnactResult().success(true).enacted(true);
// }
// return new PumpEnactResult().success(false).enacted(true)
// .comment(MainApp.gs(R.string.combo_error_partial_bolus_delivered,
// lastPumpBolus.amount, detailedBolusInfo.insulin));
// }
//
// // full bolus was delivered successfully
// incrementBolusCount();
// return new PumpEnactResult()
// .success(true)
// .enacted(lastPumpBolus.amount > 0)
// .bolusDelivered(lastPumpBolus.amount)
// .carbsDelivered(detailedBolusInfo.carbs);
} finally {
// pump.activity = null;
// MainApp.bus().post(new EventComboPumpUpdateGUI());
// pump.activity = null;
// MainApp.bus().post(new EventComboPumpUpdateGUI());
MainApp.bus().post(new EventRefreshOverview("Bolus"));
// cancelBolus = false;
// cancelBolus = false;
triggerUIChange();
}
}
@ -609,7 +620,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
// if enforceNew===true current temp basal is canceled and new TBR set (duration is prolonged),
// if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile,
boolean enforceNew) {
LOG.error("MedtronicPumpPlugin::setTempBasalAbsolute Not fully implemented - Just base command.");
@ -625,7 +637,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
// TODO translate
return new PumpEnactResult().success(false).enacted(false).comment("Couldn't read current TBR.");
} else {
LOG.info("MedtronicPumpPlugin::setTempBasalAbsolute: Current Basal: duration: {} min, rate={}", tbrCurrent.getDurationMinutes(), tbrCurrent.getInsulinRate());
LOG.info("MedtronicPumpPlugin::setTempBasalAbsolute: Current Basal: duration: {} min, rate={}",
tbrCurrent.getDurationMinutes(), tbrCurrent.getInsulinRate());
}
// FIXME doesn't work correctly. Read current TBR first
@ -647,7 +660,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
// if not the same rate, we cancel and start new
}
// if TBR is running we will cancel it.
if (tbrCurrent.getInsulinRate() != 0.0f && tbrCurrent.getDurationMinutes() > 0) {
LOG.info("MedtronicPumpPlugin::setTempBasalAbsolute - TBR running - so canceling it.");
@ -656,21 +668,22 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
MedtronicUITask responseTask2 = medtronicUIComm.executeCommand(MedtronicCommandType.CancelTBR);
Boolean response = (Boolean) responseTask2.returnData;
Boolean response = (Boolean)responseTask2.returnData;
if (response) {
LOG.info("MedtronicPumpPlugin::setTempBasalAbsolute - Current TBR cancelled.");
} else {
LOG.error("MedtronicPumpPlugin::setTempBasalAbsolute - Cancel TBR failed.");
return new PumpEnactResult().success(false).enacted(false).comment("Couldn't cancel current TBR. Stopping operation. ");
return new PumpEnactResult().success(false).enacted(false)
.comment("Couldn't cancel current TBR. Stopping operation. ");
}
}
// now start new TBR
MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetTemporaryBasal, absoluteRate, durationInMinutes);
MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetTemporaryBasal,
absoluteRate, durationInMinutes);
Boolean response = (Boolean) responseTask.returnData;
Boolean response = (Boolean)responseTask.returnData;
LOG.info("MedtronicPumpPlugin::setTempBasalAbsolute - setTBR. Response: " + response);
@ -681,11 +694,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
pumpStatusLocal.tempBasalLength = durationInMinutes;
// FIXME should be read from history
TemporaryBasal tempStart = new TemporaryBasal()
.date(System.currentTimeMillis())
.duration(durationInMinutes)
.absolute(absoluteRate)
.source(Source.USER);
TemporaryBasal tempStart = new TemporaryBasal().date(System.currentTimeMillis())
.duration(durationInMinutes).absolute(absoluteRate).source(Source.USER);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStart);
incrementStatistics(MedtronicConst.Statistics.TBRsSet);
@ -740,13 +750,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
statusRefreshMap.put(refreshType, getTimeInFutureFromMinutes(min));
}
break;
break;
case Configuration:
case PumpHistory: {
statusRefreshMap.put(refreshType, getTimeInFutureFromMinutes(refreshType.getRefreshTime() + additionalTimeInMinutes));
statusRefreshMap.put(refreshType, getTimeInFutureFromMinutes(refreshType.getRefreshTime()
+ additionalTimeInMinutes));
}
break;
break;
}
}
@ -774,7 +785,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.ReadTemporaryBasal);
if (responseTask.hasData()) {
TempBasalPair tbr = (TempBasalPair) responseTask.returnData;
TempBasalPair tbr = (TempBasalPair)responseTask.returnData;
// we sometimes get rate returned even if TBR is no longer running
if (tbr.getDurationMinutes() == 0) {
@ -787,6 +798,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
}
// TODO
@Override
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
@ -807,7 +819,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
MedtronicUITask responseTask2 = medtronicUIComm.executeCommand(MedtronicCommandType.CancelTBR);
Boolean response = (Boolean) responseTask2.returnData;
Boolean response = (Boolean)responseTask2.returnData;
if (response) {
LOG.info("MedtronicPumpPlugin::cancelTempBasal - Cancel TBR successful.");
@ -826,7 +838,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
public PumpEnactResult setNewBasalProfile(Profile profile) {
LOG.warn("MedtronicPumpPlugin::setNewBasalProfile NOT IMPLEMENTED YET.");
return new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(R.string.medtronic_cmd_profile_not_set));
return new PumpEnactResult().success(false).enacted(false)
.comment(MainApp.gs(R.string.medtronic_cmd_profile_not_set));
}
@ -841,7 +854,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
@Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile,
boolean enforceNew) {
LOG.error("setTempBasalPercent NOT IMPLEMENTED.");
// we will never come here unless somebody has played with configuration in PumpType
return OPERATION_NOT_SUPPORTED;

View file

@ -1,15 +1,15 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm;
import android.content.Context;
import android.os.SystemClock;
import java.util.ArrayList;
import java.util.Map;
import org.joda.time.Instant;
import org.joda.time.LocalDateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Map;
import android.content.Context;
import android.os.SystemClock;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkCommunicationManager;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RFSpy;
@ -40,7 +40,6 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.PumpMedtronic.service.RileyLinkMedtronicService;
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
/**
* Original file created by geoff on 5/30/16.
* <p>
@ -53,9 +52,9 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
private static final int DEFAULT_TIMEOUT = 2000;
static MedtronicCommunicationManager medtronicCommunicationManager;
private MedtronicConverter medtronicConverter;
String errorMessage;
private MedtronicConverter medtronicConverter;
private boolean debugSetCommands = true;
public MedtronicCommunicationManager(Context context, RFSpy rfspy, RileyLinkTargetFrequency targetFrequency) {
@ -65,6 +64,11 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
}
public static MedtronicCommunicationManager getInstance() {
return medtronicCommunicationManager;
}
@Override
protected void configurePumpSpecificSettings() {
pumpStatus = MedtronicUtil.getPumpStatus();
@ -74,7 +78,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
@Override
public <E extends RLMessage> E createResponseMessage(byte[] payload, Class<E> clazz) {
PumpMessage pumpMessage = new PumpMessage(payload);
return (E) pumpMessage;
return (E)pumpMessage;
}
@ -86,7 +90,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
MedtronicDeviceType pumpModel = getPumpModel();
// Andy (4.6.2018): we do retry if no data returned. We might need to do that everywhere, but that might require little bit of rewrite of RF Code.
// Andy (4.6.2018): we do retry if no data returned. We might need to do that everywhere, but that might require
// little bit of rewrite of RF Code.
if (pumpModel == MedtronicDeviceType.Unknown_Device) {
SystemClock.sleep(1000);
@ -94,7 +99,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
pumpModel = getPumpModel();
}
boolean connected = (pumpModel != MedtronicDeviceType.Unknown_Device);
if (connected) {
@ -102,10 +106,10 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
setLastConnectionTime();
}
return (pumpModel != MedtronicDeviceType.Unknown_Device);
}
private void setLastConnectionTime() {
// FIXME rename
@ -113,29 +117,21 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// FIXME set to SP
}
private void checkFirstConnectionTime() {
// FIXME set to SP
}
public static MedtronicCommunicationManager getInstance() {
return medtronicCommunicationManager;
}
private boolean debugSetCommands = true;
// FIXME remove debugs - Andy
private PumpMessage runCommandWithArgs(PumpMessage msg) {
if (debugSetCommands)
LOG.debug("Run command with Args: ");
PumpMessage rval;
PumpMessage shortMessage = makePumpMessage(msg.commandType, new CarelinkShortMessageBody(new byte[]{0}));
PumpMessage shortMessage = makePumpMessage(msg.commandType, new CarelinkShortMessageBody(new byte[] { 0 }));
// look for ack from short message
PumpMessage shortResponse = sendAndListen(shortMessage);
if (shortResponse.commandType == MedtronicCommandType.CommandACK) {
@ -157,7 +153,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
LOG.debug("Run command with Args (Long): {}", commandType.name());
PumpMessage rval = null;
PumpMessage shortMessage = makePumpMessage(commandType, new CarelinkShortMessageBody(new byte[]{0}));
PumpMessage shortMessage = makePumpMessage(commandType, new CarelinkShortMessageBody(new byte[] { 0 }));
// look for ack from short message
PumpMessage shortResponse = sendAndListen(shortMessage);
@ -167,7 +163,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
return new PumpMessage("No ACK after start message.");
}
int start = 0;
int frameNr = 1;
int len = 0;
@ -190,7 +185,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
byte frame[] = new byte[65];
frame[0] = (byte) frameNr;
frame[0] = (byte)frameNr;
System.arraycopy(content, start, frame, 1, len);
@ -214,11 +209,9 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
} while (true);
return rval;
//return new PumpMessage("No ACK");
// return new PumpMessage("No ACK");
}
@ -226,17 +219,19 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
public Page getPumpHistoryPage(int pageNumber) {
RawHistoryPage rval = new RawHistoryPage();
wakeUp(receiverDeviceAwakeForMinutes, false);
PumpMessage getHistoryMsg = makePumpMessage(MedtronicCommandType.GetHistoryData, new GetHistoryPageCarelinkMessageBody(pageNumber));
//LOG.info("getPumpHistoryPage("+pageNumber+"): "+ByteUtil.shortHexString(getHistoryMsg.getTxData()));
PumpMessage getHistoryMsg = makePumpMessage(MedtronicCommandType.GetHistoryData,
new GetHistoryPageCarelinkMessageBody(pageNumber));
// LOG.info("getPumpHistoryPage("+pageNumber+"): "+ByteUtil.shortHexString(getHistoryMsg.getTxData()));
// Ask the pump to transfer history (we get first frame?)
PumpMessage firstResponse = runCommandWithArgs(getHistoryMsg);
//LOG.info("getPumpHistoryPage("+pageNumber+"): " + ByteUtil.shortHexString(firstResponse.getContents()));
// LOG.info("getPumpHistoryPage("+pageNumber+"): " + ByteUtil.shortHexString(firstResponse.getContents()));
PumpMessage ackMsg = makePumpMessage(MedtronicCommandType.CommandACK, new PumpAckMessageBody());
GetHistoryPageCarelinkMessageBody currentResponse = new GetHistoryPageCarelinkMessageBody(firstResponse.getMessageBody().getTxData());
GetHistoryPageCarelinkMessageBody currentResponse = new GetHistoryPageCarelinkMessageBody(firstResponse
.getMessageBody().getTxData());
int expectedFrameNum = 1;
boolean done = false;
//while (expectedFrameNum == currentResponse.getFrameNumber()) {
// while (expectedFrameNum == currentResponse.getFrameNumber()) {
int failures = 0;
while (!done) {
// examine current response for problems.
@ -249,7 +244,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
}
// handle successful frame data
rval.appendData(currentResponse.getFrameData());
RileyLinkMedtronicService.getInstance().announceProgress(((100 / 16) * currentResponse.getFrameNumber() + 1));
RileyLinkMedtronicService.getInstance().announceProgress(
((100 / 16) * currentResponse.getFrameNumber() + 1));
LOG.info("getPumpHistoryPage: Got frame " + currentResponse.getFrameNumber());
// Do we need to ask for the next frame?
if (expectedFrameNum < 16) { // This number may not be correct for pumps other than 522/722
@ -261,13 +257,15 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
if (frameData == null) {
LOG.error("null frame data, retrying");
} else if (currentResponse.getFrameNumber() != expectedFrameNum) {
LOG.warn("Expected frame number {}, received {} (retrying)", expectedFrameNum, currentResponse.getFrameNumber());
LOG.warn("Expected frame number {}, received {} (retrying)", expectedFrameNum,
currentResponse.getFrameNumber());
} else if (frameData.length == 0) {
LOG.warn("Frame has zero length, retrying");
}
failures++;
if (failures == 6) {
LOG.error("6 failures in attempting to download frame {} of page {}, giving up.", expectedFrameNum, pageNumber);
LOG.error("6 failures in attempting to download frame {} of page {}, giving up.", expectedFrameNum,
pageNumber);
done = true; // failure completion.
}
}
@ -287,7 +285,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
rval.dumpToDebug();
Page page = new Page();
//page.parseFrom(rval.getData(),PumpModel.MM522);
// page.parseFrom(rval.getData(),PumpModel.MM522);
// FIXME
page.parseFrom(rval.getData(), MedtronicDeviceType.Medtronic_522);
@ -329,7 +327,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// See ButtonPressCarelinkMessageBody
public void pressButton(int which) {
wakeUp(receiverDeviceAwakeForMinutes, false);
PumpMessage pressButtonMessage = makePumpMessage(MedtronicCommandType.PushButton, new ButtonPressCarelinkMessageBody(which));
PumpMessage pressButtonMessage = makePumpMessage(MedtronicCommandType.PushButton,
new ButtonPressCarelinkMessageBody(which));
PumpMessage resp = sendAndListen(pressButtonMessage);
if (resp.commandType != MedtronicCommandType.CommandACK) {
LOG.error("Pump did not ack button press.");
@ -338,32 +337,30 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// FIXME
//@Override
// public RLMessage makeRLMessage(RLMessageType type, byte[] data) {
// switch (type) {
// case PowerOn:
// return makePumpMessage(MedtronicCommandType.RFPowerOn, new CarelinkShortMessageBody(data));
// @Override
// public RLMessage makeRLMessage(RLMessageType type, byte[] data) {
// switch (type) {
// case PowerOn:
// return makePumpMessage(MedtronicCommandType.RFPowerOn, new CarelinkShortMessageBody(data));
//
// case ReadSimpleData:
// return makePumpMessage(MedtronicCommandType.PumpModel, new GetPumpModelCarelinkMessageBody());
// case ReadSimpleData:
// return makePumpMessage(MedtronicCommandType.PumpModel, new GetPumpModelCarelinkMessageBody());
//
// }
// return null;
// }
// @Override
// public RLMessage makeRLMessage(byte[] data) {
// return makePumpMessage(data);
// }
// }
// return null;
// }
// @Override
// public RLMessage makeRLMessage(byte[] data) {
// return makePumpMessage(data);
// }
@Override
public byte[] createPumpMessageContent(RLMessageType type) {
switch (type) {
case PowerOn:
return MedtronicUtil.buildCommandPayload(MedtronicCommandType.RFPowerOn, //
new byte[]{2, 1, (byte) receiverDeviceAwakeForMinutes}); // maybe this is better FIXME
new byte[] { 2, 1, (byte)receiverDeviceAwakeForMinutes }); // maybe this is better FIXME
case ReadSimpleData:
return MedtronicUtil.buildCommandPayload(MedtronicCommandType.PumpModel, null);
@ -373,12 +370,13 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
protected PumpMessage makePumpMessage(MedtronicCommandType messageType, byte[] body) {
return makePumpMessage(messageType, body == null ? new CarelinkShortMessageBody() : new CarelinkShortMessageBody(body));
return makePumpMessage(messageType, body == null ? new CarelinkShortMessageBody()
: new CarelinkShortMessageBody(body));
}
protected PumpMessage makePumpMessage(MedtronicCommandType messageType) {
return makePumpMessage(messageType, (byte[]) null);
return makePumpMessage(messageType, (byte[])null);
}
@ -389,12 +387,12 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
}
// protected PumpMessage makePumpMessage(byte[] typeAndBody) {
// PumpMessage msg = new PumpMessage();
// msg.init(ByteUtil.concat(ByteUtil.concat(new byte[]{PacketType.Carelink.getValue()}, rileyLinkServiceData.pumpIDBytes), typeAndBody));
// return msg;
// }
// protected PumpMessage makePumpMessage(byte[] typeAndBody) {
// PumpMessage msg = new PumpMessage();
// msg.init(ByteUtil.concat(ByteUtil.concat(new byte[]{PacketType.Carelink.getValue()},
// rileyLinkServiceData.pumpIDBytes), typeAndBody));
// return msg;
// }
private PumpMessage sendAndGetResponse(MedtronicCommandType commandType) {
@ -413,6 +411,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
return sendAndGetResponse(commandType, bodyData, DEFAULT_TIMEOUT);
}
/**
* Main wrapper method for sending data - (for getting responses)
*
@ -445,23 +444,22 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// FIXME remove
// private PumpMessage sendAndGetACK(MedtronicCommandType commandType, byte[] bodyData, int timeoutMs) {
// // wakeUp
// wakeUp(receiverDeviceAwakeForMinutes, false);
// private PumpMessage sendAndGetACK(MedtronicCommandType commandType, byte[] bodyData, int timeoutMs) {
// // wakeUp
// wakeUp(receiverDeviceAwakeForMinutes, false);
//
// // create message
// PumpMessage msg;
// // create message
// PumpMessage msg;
//
// if (bodyData == null)
// msg = makePumpMessage(commandType);
// else
// msg = makePumpMessage(commandType, bodyData);
// if (bodyData == null)
// msg = makePumpMessage(commandType);
// else
// msg = makePumpMessage(commandType, bodyData);
//
// // send and wait for ACK
// PumpMessage response = send(msg, timeoutMs);
// return response;
// }
// // send and wait for ACK
// PumpMessage response = send(msg, timeoutMs);
// return response;
// }
protected PumpMessage sendAndListen(RLMessage msg) {
return sendAndListen(msg, 4000); // 2000
@ -484,7 +482,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
for (int retries = 0; retries < MAX_COMMAND_RETRIES; retries++) {
PumpMessage response = sendAndGetResponse(commandType, bodyData, DEFAULT_TIMEOUT + (DEFAULT_TIMEOUT * retries));
PumpMessage response = sendAndGetResponse(commandType, bodyData, DEFAULT_TIMEOUT
+ (DEFAULT_TIMEOUT * retries));
String check = checkResponseContent(response, commandType.commandDescription, commandType.expectedLength);
@ -497,7 +496,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
return dataResponse;
} else {
this.errorMessage = check;
//return null;
// return null;
}
}
@ -514,7 +513,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
return responseData;
}
byte[] contents = response.getRawContent();
if (contents != null) {
@ -523,7 +521,9 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
return null;
} else {
String responseData = String.format("%s: Cannot return data. Data is too short [expected=%s, received=%s].", method, "" + expectedLength, "" + contents.length);
String responseData = String.format(
"%s: Cannot return data. Data is too short [expected=%s, received=%s].", method, ""
+ expectedLength, "" + contents.length);
LOG.warn(responseData);
return responseData;
@ -537,48 +537,46 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// TODO remove not needed - probably
// @Deprecated
// private void executeSetCommand(MedtronicCommandType commandType, byte[] bodyData) {
// @Deprecated
// private void executeSetCommand(MedtronicCommandType commandType, byte[] bodyData) {
//
// LOG.debug("Executing Set for {} - 1st call", commandType.name());
// LOG.debug("Executing Set for {} - 1st call", commandType.name());
//
// // first we send command without paramters and wait for ACK
// PumpMessage pumpMessage = sendAndGetACK(commandType, null, 4000);
// // first we send command without paramters and wait for ACK
// PumpMessage pumpMessage = sendAndGetACK(commandType, null, 4000);
//
// // FIXME check if ACK
// LOG.debug("Response 1 - {}", HexDump.toHexStringDisplayable(pumpMessage.getRawContent()));
// // FIXME check if ACK
// LOG.debug("Response 1 - {}", HexDump.toHexStringDisplayable(pumpMessage.getRawContent()));
//
//
// LOG.debug("Executing Set for {} - 2nd call", commandType.name());
// // second we send command with parameters and full package 64 bits with zeroed empty places
// LOG.debug("Executing Set for {} - 2nd call", commandType.name());
// // second we send command with parameters and full package 64 bits with zeroed empty places
//
// byte newBodyData[] = new byte[64];
// for(int i = 0; i < 64; i++) {
// newBodyData[i] = 0x00;
// }
// byte newBodyData[] = new byte[64];
// for(int i = 0; i < 64; i++) {
// newBodyData[i] = 0x00;
// }
//
// newBodyData[0] = (byte) bodyData.length;
// newBodyData[0] = (byte) bodyData.length;
//
// for(int i = 0; i < bodyData.length; i++) {
// newBodyData[i + 1] = bodyData[i];
// }
// for(int i = 0; i < bodyData.length; i++) {
// newBodyData[i + 1] = bodyData[i];
// }
//
// PumpMessage pumpMessage2 = sendAndGetACK(commandType, newBodyData, 4000);
// PumpMessage pumpMessage2 = sendAndGetACK(commandType, newBodyData, 4000);
//
//
// LOG.debug("Response 2 - {}", HexDump.toHexStringDisplayable(pumpMessage.getRawContent()));
// LOG.debug("Response 2 - {}", HexDump.toHexStringDisplayable(pumpMessage.getRawContent()));
//
// }
// }
// PUMP SPECIFIC COMMANDS
public Float getRemainingInsulin() {
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.GetRemainingInsulin);
return responseObject == null ? null : (Float) responseObject;
return responseObject == null ? null : (Float)responseObject;
}
@ -587,10 +585,10 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.PumpModel);
if (!MedtronicUtil.isModelSet()) {
MedtronicUtil.setMedtronicPumpModel((MedtronicDeviceType) responseObject);
MedtronicUtil.setMedtronicPumpModel((MedtronicDeviceType)responseObject);
}
return responseObject == null ? null : (MedtronicDeviceType) responseObject;
return responseObject == null ? null : (MedtronicDeviceType)responseObject;
}
@ -598,7 +596,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.GetBasalProfileSTD);
return responseObject == null ? null : (BasalProfile) responseObject;
return responseObject == null ? null : (BasalProfile)responseObject;
}
@ -606,7 +604,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.RealTimeClock);
return responseObject == null ? null : (LocalDateTime) responseObject;
return responseObject == null ? null : (LocalDateTime)responseObject;
}
@ -614,15 +612,16 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.ReadTemporaryBasal);
return responseObject == null ? null : (TempBasalPair) responseObject;
return responseObject == null ? null : (TempBasalPair)responseObject;
}
public Map<String, PumpSettingDTO> getPumpSettings() {
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.getSettings(MedtronicUtil.getMedtronicPumpModel()));
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.getSettings(MedtronicUtil
.getMedtronicPumpModel()));
return responseObject == null ? null : (Map<String, PumpSettingDTO>) responseObject;
return responseObject == null ? null : (Map<String, PumpSettingDTO>)responseObject;
}
@ -639,7 +638,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
LOG.debug("Set Bolus: Body - {}", HexDump.toHexStringDisplayable(body));
PumpMessage msg = makePumpMessage(MedtronicCommandType.SetBolus, //
new CarelinkLongMessageBody(ByteUtil.concat((byte) body.length, body)));
new CarelinkLongMessageBody(ByteUtil.concat((byte)body.length, body)));
PumpMessage pumpMessage = runCommandWithArgs(msg);
@ -661,7 +660,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
LOG.debug("Set TBR: Body - {}", HexDump.toHexStringDisplayable(body));
PumpMessage msg = makePumpMessage(MedtronicCommandType.SetTemporaryBasal, //
new CarelinkLongMessageBody(tbr.getAsRawData()));
new CarelinkLongMessageBody(tbr.getAsRawData()));
PumpMessage pumpMessage = runCommandWithArgs(msg);
@ -682,13 +681,12 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.GetBatteryStatus);
return responseObject == null ? null : (BatteryStatusDTO) responseObject;
return responseObject == null ? null : (BatteryStatusDTO)responseObject;
}
// FIXME --- After this line commands in development --- REMOVE THIS COMMANDS
// TODO test
// TODO remove, we will see state from History
@ -707,7 +705,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// TODO remove, we will see bolus status from History
public PumpMessage getBolusStatus() {
PumpMessage response = sendAndGetResponse(MedtronicCommandType.SetBolus, new byte[]{0x03, 0x00, 0x00, 0x00}, 4000);
PumpMessage response = sendAndGetResponse(MedtronicCommandType.SetBolus, new byte[] { 0x03, 0x00, 0x00, 0x00 },
4000);
byte[] data = response.getRawContent();
@ -722,59 +721,83 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// TODO generateRawData (check if it works correctly) and test
public Boolean setBasalProfile(BasalProfile basalProfile) {
// [RileyLinkDevice] ======================== Save Basal Profile ===========================
// [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 1 bytes), 0,
// 0.180000, 3)
// [PeripheralManager+RileyLink] RL Send: 19050000000000000000b4030000a9659a6b19b199c555b2c000
// [PeripheralManager+RileyLink] RL Recv(single): bb
// [PeripheralManager+RileyLink] RileyLink response: PacketResponse(code:
// RileyLinkBLEKit.ResponseCode.commandInterrupted, packet: nil)
// [PeripheralManager+RileyLink] RL Recv(single): dd0dbca9659a6b19b156655534d500
// [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 65 bytes), 0,
// 0.180000, 3)
// [PeripheralManager+RileyLink] RL Send:
// 79050000000000000000b4030000a9659a6b19b199c571c9a555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555556000
// 2018-06-30 15:03:13.333962-0500 Loop[24609:13622692] [PeripheralManager+RileyLink] RL Recv(single):
// dd10bda9659a6b19b156655534d500
// 2018-06-30 15:03:13.334927-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink,
// setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
// 2018-06-30 15:03:13.337923-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send:
// 79050000000000000000b4030000a9659a6b19b199c5725555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555ac000
// 2018-06-30 15:03:14.114024-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single):
// dd0ebea9659a6b19b156655534d500
// 2018-06-30 15:03:14.115017-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink,
// setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
// 2018-06-30 15:03:14.117600-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send:
// 79050000000000000000b4030000a9659a6b19b199c6a355555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555570e000
// 2018-06-30 15:03:15.644502-0500 Loop[24609:13622692] [PeripheralManager+RileyLink] RL Recv(single):
// dd0ebfa9659a6b19b156655534d500
// 2018-06-30 15:03:15.645388-0500 Loop[24609:13622484] [RileyLinkDevice] ------------------------ Save Basal
// Profile ---------------------------
// [RileyLinkDevice] ======================== Save Basal Profile ===========================
// [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 1 bytes), 0, 0.180000, 3)
// [PeripheralManager+RileyLink] RL Send: 19050000000000000000b4030000a9659a6b19b199c555b2c000
// [PeripheralManager+RileyLink] RL Recv(single): bb
// [PeripheralManager+RileyLink] RileyLink response: PacketResponse(code: RileyLinkBLEKit.ResponseCode.commandInterrupted, packet: nil)
// [PeripheralManager+RileyLink] RL Recv(single): dd0dbca9659a6b19b156655534d500
// [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
// [PeripheralManager+RileyLink] RL Send: 79050000000000000000b4030000a9659a6b19b199c571c9a555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555556000
// 2018-06-30 15:03:13.333962-0500 Loop[24609:13622692] [PeripheralManager+RileyLink] RL Recv(single): dd10bda9659a6b19b156655534d500
// 2018-06-30 15:03:13.334927-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
// 2018-06-30 15:03:13.337923-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send: 79050000000000000000b4030000a9659a6b19b199c5725555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555ac000
// 2018-06-30 15:03:14.114024-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single): dd0ebea9659a6b19b156655534d500
// 2018-06-30 15:03:14.115017-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
// 2018-06-30 15:03:14.117600-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send: 79050000000000000000b4030000a9659a6b19b199c6a355555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555570e000
// 2018-06-30 15:03:15.644502-0500 Loop[24609:13622692] [PeripheralManager+RileyLink] RL Recv(single): dd0ebfa9659a6b19b156655534d500
// 2018-06-30 15:03:15.645388-0500 Loop[24609:13622484] [RileyLinkDevice] ------------------------ Save Basal Profile ---------------------------
// 2018-06-30 15:03:12.167767-0500 Loop[24609:13622484] [RileyLinkDevice] ======================== Save Basal
// Profile ===========================
// 2018-06-30 15:03:12.168652-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink,
// setBasalProfileStandard, 3 bytes, 1 bytes), 0, 0.180000, 3)
// 2018-06-30 15:03:12.169518-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send:
// 19050000000000000000b4030000a9659a6b19b199c555b2c000
// 2018-06-30 15:03:12.463546-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single): bb
// 2018-06-30 15:03:12.463954-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RileyLink response:
// PacketResponse(code: RileyLinkBLEKit.ResponseCode.commandInterrupted, packet: nil)
// 2018-06-30 15:03:12.554051-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single):
// dd0dbca9659a6b19b156655534d500
// 2018-06-30 15:03:12.555175-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink,
// setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
// 2018-06-30 15:03:12.557953-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send:
// 79050000000000000000b4030000a9659a6b19b199c571c9a555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555556000
// 2018-06-30 15:03:13.333962-0500 Loop[24609:13622692] [PeripheralManager+RileyLink] RL Recv(single):
// dd10bda9659a6b19b156655534d500
// 2018-06-30 15:03:13.334927-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink,
// setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
// 2018-06-30 15:03:13.337923-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send:
// 79050000000000000000b4030000a9659a6b19b199c5725555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555ac000
// 2018-06-30 15:03:14.114024-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single):
// dd0ebea9659a6b19b156655534d500
// 2018-06-30 15:03:14.115017-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink,
// setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
// 2018-06-30 15:03:14.117600-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send:
// 79050000000000000000b4030000a9659a6b19b199c6a355555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555570e000
// 2018-06-30 15:03:15.644502-0500 Loop[24609:13622692] [PeripheralManager+RileyLink] RL Recv(single):
// dd0ebfa9659a6b19b156655534d500
// 2018-06-30 15:03:15.645388-0500 Loop[24609:13622484] [RileyLinkDevice] ------------------------ Save Basal
// Profile ---------------------------
// byte[] body = basalProfile.generateRawData();
// 2018-06-30 15:03:12.167767-0500 Loop[24609:13622484] [RileyLinkDevice] ======================== Save Basal Profile ===========================
// 2018-06-30 15:03:12.168652-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 1 bytes), 0, 0.180000, 3)
// 2018-06-30 15:03:12.169518-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send: 19050000000000000000b4030000a9659a6b19b199c555b2c000
// 2018-06-30 15:03:12.463546-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single): bb
// 2018-06-30 15:03:12.463954-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RileyLink response: PacketResponse(code: RileyLinkBLEKit.ResponseCode.commandInterrupted, packet: nil)
// 2018-06-30 15:03:12.554051-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single): dd0dbca9659a6b19b156655534d500
// 2018-06-30 15:03:12.555175-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
// 2018-06-30 15:03:12.557953-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send: 79050000000000000000b4030000a9659a6b19b199c571c9a555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555556000
// 2018-06-30 15:03:13.333962-0500 Loop[24609:13622692] [PeripheralManager+RileyLink] RL Recv(single): dd10bda9659a6b19b156655534d500
// 2018-06-30 15:03:13.334927-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
// 2018-06-30 15:03:13.337923-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send: 79050000000000000000b4030000a9659a6b19b199c5725555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555ac000
// 2018-06-30 15:03:14.114024-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single): dd0ebea9659a6b19b156655534d500
// 2018-06-30 15:03:14.115017-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
// 2018-06-30 15:03:14.117600-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send: 79050000000000000000b4030000a9659a6b19b199c6a355555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555570e000
// 2018-06-30 15:03:15.644502-0500 Loop[24609:13622692] [PeripheralManager+RileyLink] RL Recv(single): dd0ebfa9659a6b19b156655534d500
// 2018-06-30 15:03:15.645388-0500 Loop[24609:13622484] [RileyLinkDevice] ------------------------ Save Basal Profile ---------------------------
//byte[] body = basalProfile.generateRawData();
byte[] body = new byte[]{32, 0, 0, 38, 0, 13, 44, 0, 19, 38, 0, 28};
byte[] body = new byte[] { 32, 0, 0, 38, 0, 13, 44, 0, 19, 38, 0, 28 };
PumpMessage responseMessage;
if (debugSetCommands)
LOG.debug("Set Basal Profile: Body [{}] - {}", body.length, HexDump.toHexStringDisplayable(body));
// if (body.length <= 64) {
// if (body.length <= 64) {
//
// PumpMessage msg = makePumpMessage(MedtronicCommandType.SetBasalProfileA, //
// new CarelinkLongMessageBody(ByteUtil.concat((byte) body.length, body)));
// PumpMessage msg = makePumpMessage(MedtronicCommandType.SetBasalProfileA, //
// new CarelinkLongMessageBody(ByteUtil.concat((byte) body.length, body)));
//
// responseMessage = runCommandWithArgs(msg);
// } else
// responseMessage = runCommandWithArgs(msg);
// } else
{
responseMessage = runCommandWithArgsLong(MedtronicCommandType.SetBasalProfileA, body);
@ -788,31 +811,29 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
}
// public byte[] getFullMessageBody(byte[] bodyData, int length) {
// byte newBodyData[] = getEmptyMessage(length);
//
// newBodyData[0] = (byte) bodyData.length;
//
// for (int i = 0; i < bodyData.length; i++) {
// newBodyData[i + 1] = bodyData[i];
// }
//
// return newBodyData;
// }
// public byte[] getEmptyMessage(int length) {
// byte newBodyData[] = new byte[length];
// for (int i = 0; i < length; i++) {
// newBodyData[i] = 0x00;
// }
//
// return newBodyData;
// }
// public byte[] getFullMessageBody(byte[] bodyData, int length) {
// byte newBodyData[] = getEmptyMessage(length);
//
// newBodyData[0] = (byte) bodyData.length;
//
// for (int i = 0; i < bodyData.length; i++) {
// newBodyData[i + 1] = bodyData[i];
// }
//
// return newBodyData;
// }
// public byte[] getEmptyMessage(int length) {
// byte newBodyData[] = new byte[length];
// for (int i = 0; i < length; i++) {
// newBodyData[i] = 0x00;
// }
//
// return newBodyData;
// }
public PumpMessage cancelBolus() {
//? maybe suspend and resume
// ? maybe suspend and resume
return null;
}
@ -830,44 +851,44 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
return null;
}
// Set TBR 100%
// Cancel TBR (set TBR 100%) 100%
// Get Status (40%)
// Set Bolus 100%
// Set Extended Bolus 20%
// Cancel Bolus 0% -- NOT SUPPORTED
// Cancel Extended Bolus 0% -- NOT SUPPORTED
// Set TBR 100%
// Cancel TBR (set TBR 100%) 100%
// Get Status (40%)
// Get Basal Profile (0x92) Read STD 100%
// Set Basal Profile 0% -- NOT SUPPORTED
// Read History 60%
// Load TDD ?
// Set Bolus 100%
// Set Extended Bolus 20%
// Cancel Bolus 0% -- NOT SUPPORTED
// Cancel Extended Bolus 0% -- NOT SUPPORTED
// Get Basal Profile (0x92) Read STD 100%
// Set Basal Profile 0% -- NOT SUPPORTED
// Read History 60%
// Load TDD ?
// FIXME remove - each part needs to be gotten manually
public void updatePumpManagerStatus() {
//Integer resp = getRemainingBattery();
//pumpStatus.batteryRemaining = resp == null ? -1 : resp;
// Integer resp = getRemainingBattery();
// pumpStatus.batteryRemaining = resp == null ? -1 : resp;
//pumpStatus.remainUnits = getRemainingInsulin();
// pumpStatus.remainUnits = getRemainingInsulin();
/* current basal */
//TempBasalPair basalRate = getCurrentBasalRate();
// TempBasalPair basalRate = getCurrentBasalRate();
// FIXME
// byte[] basalRateBytes = resp.getContents();
// if (basalRateBytes != null) {
// if (basalRateBytes.length == 2) {
// /**
// * 0x98 0x06
// * 0x98 is "basal rate"
// * 0x06 is what? Not currently running a temp basal, current basal is "standard" at 0
// */
// double basalRate = ByteUtil.asUINT8(basalRateBytes[1]);
// pumpStatus.currentBasal = basalRate;
// }
// }
// byte[] basalRateBytes = resp.getContents();
// if (basalRateBytes != null) {
// if (basalRateBytes.length == 2) {
// /**
// * 0x98 0x06
// * 0x98 is "basal rate"
// * 0x06 is what? Not currently running a temp basal, current basal is "standard" at 0
// */
// double basalRate = ByteUtil.asUINT8(basalRateBytes[1]);
// pumpStatus.currentBasal = basalRate;
// }
// }
// get last bolus amount
// get last bolus time
// get tempBasalInProgress
@ -877,11 +898,10 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// get pump time
LocalDateTime clockResult = getPumpTime();
if (clockResult != null) {
//pumpStatus.time = clockResult.toDate();
// pumpStatus.time = clockResult.toDate();
}
// get last sync time
}
}

View file

@ -28,15 +28,15 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data;
* GGW: TODO: examine src/ecc1/medtronic for better history parsing
*/
import android.os.Bundle;
import android.util.Log;
import org.joda.time.DateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.joda.time.DateTime;
import android.os.Bundle;
import android.util.Log;
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC;
import info.nightscout.androidaps.plugins.PumpCommon.utils.HexDump;
@ -49,14 +49,14 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType
@Deprecated
public class Page {
private final static String TAG = "Page";
private static final boolean DEBUG_PAGE = true;
private byte[] crc;
private byte[] data;
//protected PumpModel model;
// protected PumpModel model;
public static MedtronicDeviceType model = MedtronicDeviceType.Medtronic_522;
public List<Record> mRecordList;
private byte[] crc;
private byte[] data;
public Page() {
@ -65,6 +65,104 @@ public class Page {
}
/*
* attemptParseRecord will attempt to create a subclass of Record from the given
* data and offset. It will return NULL if it fails. If it succeeds, the returned
* subclass of Record can be examined for its length, so that the next attempt can be made.
*
* TODO maybe try to change this, so that we can loose all the classes and using enum instead with full
* configuration. Its something to think about for later versions -- Andy
*/
public static <T extends Record> T attemptParseRecord(byte[] data, int offsetStart) {
// no data?
if (data == null) {
return null;
}
// invalid offset?
if (data.length < offsetStart) {
return null;
}
// Log.d(TAG,String.format("checking for handler for record type 0x%02X at index %d",data[offsetStart],offsetStart));
RecordTypeEnum en = RecordTypeEnum.fromByte(data[offsetStart]);
T record = en.getRecordClassInstance(model);
if (record != null) {
// have to do this to set the record's opCode
byte[] tmpData = new byte[data.length];
System.arraycopy(data, offsetStart, tmpData, 0, data.length - offsetStart);
boolean didParse = record.parseWithOffset(tmpData, model, offsetStart);
if (!didParse) {
Log.e(
TAG,
String.format("attemptParseRecord: class %s (opcode 0x%02X) failed to parse at offset %d",
record.getShortTypeName(), data[offsetStart], offsetStart));
}
}
return record;
}
public static DateTime parseSimpleDate(byte[] data, int offset) {
DateTime timeStamp = null;
int seconds = 0;
int minutes = 0;
int hour = 0;
// int high = data[0] >> 4;
int low = data[0 + offset] & 0x1F;
// int year_high = data[1] >> 4;
int mhigh = (data[0 + offset] & 0xE0) >> 4;
int mlow = (data[1 + offset] & 0x80) >> 7;
int month = mhigh + mlow;
int dayOfMonth = low + 1;
// python code says year is data[1] & 0x0F, but that will cause problem in 2016.
// Hopefully, the remaining bits are part of the year...
int year = data[1 + offset] & 0x3F;
/*
* Log.w(TAG, String.format("Attempting to create DateTime from: %04d-%02d-%02d %02d:%02d:%02d",
* year + 2000, month, dayOfMonth, hour, minutes, seconds));
*/
try {
timeStamp = new DateTime(year + 2000, month, dayOfMonth, hour, minutes, seconds);
} catch (org.joda.time.IllegalFieldValueException e) {
// Log.e(TAG,"Illegal DateTime field");
// e.printStackTrace();
return null;
}
return timeStamp;
}
public static void discoverRecords(byte[] data) {
int i = 0;
boolean done = false;
ArrayList<Integer> keyLocations = new ArrayList();
while (!done) {
RecordTypeEnum en = RecordTypeEnum.fromByte(data[i]);
if (en != RecordTypeEnum.Null) {
keyLocations.add(i);
Log.v(TAG, String.format("Possible record of type %s found at index %d", en, i));
}
/*
* DateTime ts = parseSimpleDate(data,i);
* if (ts != null) {
* if (ts.year().get() == 2015) {
* Log.w(TAG, String.format("Possible simple date at index %d", i));
* }
* }
*/
i = i + 1;
done = (i >= data.length - 2);
}
// for each of the discovered key locations, attempt to parse a sequence of records
for (RecordTypeEnum en : RecordTypeEnum.values()) {
}
for (int ix = 0; ix < keyLocations.size(); ix++) {
}
}
public byte[] getRawData() {
if (data == null) {
return crc;
@ -91,7 +189,8 @@ public class Page {
this.model = model;
int pageOffset = 0;
if ((rawPage == null) || (rawPage.length == 0)) return false;
if ((rawPage == null) || (rawPage.length == 0))
return false;
this.data = Arrays.copyOfRange(rawPage, 0, rawPage.length - 2);
this.crc = Arrays.copyOfRange(rawPage, rawPage.length - 2, rawPage.length);
byte[] expectedCrc = CRC.calculate16CCITT(this.data);
@ -99,7 +198,10 @@ public class Page {
Log.i(TAG, String.format("Data length: %d", data.length));
}
if (!Arrays.equals(crc, expectedCrc)) {
Log.w(TAG, String.format("CRC does not match expected value. Expected: %s Was: %s", HexDump.toHexString(expectedCrc), HexDump.toHexString(crc)));
Log.w(
TAG,
String.format("CRC does not match expected value. Expected: %s Was: %s",
HexDump.toHexString(expectedCrc), HexDump.toHexString(crc)));
} else {
if (DEBUG_PAGE) {
Log.i(TAG, "CRC OK");
@ -110,7 +212,9 @@ public class Page {
while (pageOffset < data.length) {
if (data[pageOffset] == 0) {
if (record != null) {
Log.i(TAG, String.format("End of page or Previous parse fail: prev opcode 0x%02x, curr offset %d, %d bytes remaining", record.getRecordOp(), pageOffset, data.length - pageOffset + 1));
Log.i(TAG, String.format(
"End of page or Previous parse fail: prev opcode 0x%02x, curr offset %d, %d bytes remaining",
record.getRecordOp(), pageOffset, data.length - pageOffset + 1));
break;
} else {
Log.i(TAG, "WTF?");
@ -132,8 +236,8 @@ public class Page {
ArrayList<Record> pickyRecords = new ArrayList<>();
pickyRecords.addAll(mRecordList);
parseByDates(rawPage, model);
for(Record r : mRecordList) {
for(Record r2 : pickyRecords) {
for (Record r : mRecordList) {
for (Record r2 : pickyRecords) {
if (r.getFoundAtOffset() == r2.getFoundAtOffset()) {
Log.v(TAG, "Found matching record at offset " + r.getFoundAtOffset());
}
@ -147,7 +251,7 @@ public class Page {
mRecordList = new ArrayList<>();
if (rawPage.length != 1024) {
Log.e(TAG, "Unexpected page size. Expected: 1024 Was: " + rawPage.length);
//return false;
// return false;
}
Page.model = model;
if (DEBUG_PAGE) {
@ -166,7 +270,10 @@ public class Page {
Log.i(TAG, String.format("Data length: %d", data.length));
}
if (!Arrays.equals(crc, expectedCrc)) {
Log.w(TAG, String.format("CRC does not match expected value. Expected: %s Was: %s", HexDump.toHexString(expectedCrc), HexDump.toHexString(crc)));
Log.w(
TAG,
String.format("CRC does not match expected value. Expected: %s Was: %s",
HexDump.toHexString(expectedCrc), HexDump.toHexString(crc)));
} else {
if (DEBUG_PAGE) {
Log.i(TAG, "CRC OK");
@ -201,7 +308,6 @@ public class Page {
pageOffset++;
}
return true;
}
@ -210,7 +316,7 @@ public class Page {
mRecordList = new ArrayList<>(); // wipe old contents each time when parsing.
if (rawPage.length != 1024) {
Log.e(TAG, "Unexpected page size. Expected: 1024 Was: " + rawPage.length);
//return false;
// return false;
}
this.model = model;
if (DEBUG_PAGE) {
@ -229,7 +335,10 @@ public class Page {
Log.i(TAG, String.format("Data length: %d", data.length));
}
if (!Arrays.equals(crc, expectedCrc)) {
Log.w(TAG, String.format("CRC does not match expected value. Expected: %s Was: %s", HexDump.toHexString(expectedCrc), HexDump.toHexString(crc)));
Log.w(
TAG,
String.format("CRC does not match expected value. Expected: %s Was: %s",
HexDump.toHexString(expectedCrc), HexDump.toHexString(crc)));
} else {
if (DEBUG_PAGE) {
Log.i(TAG, "CRC OK");
@ -249,12 +358,14 @@ public class Page {
record = null;
}
} else {
Log.v(TAG, "Zero opcode encountered -- end of page. " + (rawPage.length - dataIndex) + " bytes remaining.");
Log.v(TAG, "Zero opcode encountered -- end of page. " + (rawPage.length - dataIndex)
+ " bytes remaining.");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Possible parsing problem: ");
stringBuilder.append("Previous record: " + previousRecord);
stringBuilder.append(" Content of previous record: " + HexDump.toHexStringDisplayable(previousRecord.getRawbytes()));
stringBuilder.append(" Content of previous record: "
+ HexDump.toHexStringDisplayable(previousRecord.getRawbytes()));
int remainingData = rawPage.length - dataIndex;
byte[] tmpData = new byte[remainingData + 10];
@ -269,10 +380,13 @@ public class Page {
if (record != null) {
if (record instanceof IgnoredHistoryEntry) {
IgnoredHistoryEntry he = (IgnoredHistoryEntry) record;
Log.v(TAG, "parseFrom: found event " + he.getShortTypeName() + " length=" + record.getLength() + " offset=" + record.getFoundAtOffset() + " -- IGNORING");
IgnoredHistoryEntry he = (IgnoredHistoryEntry)record;
Log.v(TAG, "parseFrom: found event " + he.getShortTypeName() + " length=" + record.getLength()
+ " offset=" + record.getFoundAtOffset() + " -- IGNORING");
} else {
Log.v(TAG, "parseFrom: found event " + record.getClass().getSimpleName() + " length=" + record.getLength() + " offset=" + record.getFoundAtOffset());
Log.v(TAG,
"parseFrom: found event " + record.getClass().getSimpleName() + " length=" + record.getLength()
+ " offset=" + record.getFoundAtOffset());
mRecordList.add(record);
}
@ -283,19 +397,19 @@ public class Page {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Possible parsing problem: ");
stringBuilder.append("Previous record: " + previousRecord);
stringBuilder.append(" Content of previous record: " + HexDump.toHexStringDisplayable(previousRecord.getRawbytes()));
stringBuilder.append(" Content of previous record: "
+ HexDump.toHexStringDisplayable(previousRecord.getRawbytes()));
int remainingData = data.length - dataIndex;
byte[] tmpData = Arrays.copyOfRange(data, dataIndex, 1022);
//new byte[remainingData];
//System.arraycopy(data, dataIndex, tmpData, 0, remainingData - 2);
// new byte[remainingData];
// System.arraycopy(data, dataIndex, tmpData, 0, remainingData - 2);
stringBuilder.append(" Remaining data: " + HexDump.toHexStringDisplayable(tmpData));
Log.e(TAG, String.format("parseFrom: Failed to parse opcode 0x%02x, offset=%d", data[dataIndex], dataIndex));
Log.e(TAG,
String.format("parseFrom: Failed to parse opcode 0x%02x, offset=%d", data[dataIndex], dataIndex));
done = true;
}
if (dataIndex >= data.length - 2) {
@ -308,7 +422,7 @@ public class Page {
if (DEBUG_PAGE) {
Log.i(TAG, String.format("Number of records: %d", mRecordList.size()));
int index = 1;
for(Record r : mRecordList) {
for (Record r : mRecordList) {
Log.v(TAG, String.format("Record #%d: %s", index, r.getShortTypeName()));
index += 1;
}
@ -317,112 +431,17 @@ public class Page {
}
/* attemptParseRecord will attempt to create a subclass of Record from the given
* data and offset. It will return NULL if it fails. If it succeeds, the returned
* subclass of Record can be examined for its length, so that the next attempt can be made.
/*
*
* TODO maybe try to change this, so that we can loose all the classes and using enum instead with full
* configuration. Its something to think about for later versions -- Andy
*/
public static <T extends Record> T attemptParseRecord(byte[] data, int offsetStart) {
// no data?
if (data == null) {
return null;
}
// invalid offset?
if (data.length < offsetStart) {
return null;
}
//Log.d(TAG,String.format("checking for handler for record type 0x%02X at index %d",data[offsetStart],offsetStart));
RecordTypeEnum en = RecordTypeEnum.fromByte(data[offsetStart]);
T record = en.getRecordClassInstance(model);
if (record != null) {
// have to do this to set the record's opCode
byte[] tmpData = new byte[data.length];
System.arraycopy(data, offsetStart, tmpData, 0, data.length - offsetStart);
boolean didParse = record.parseWithOffset(tmpData, model, offsetStart);
if (!didParse) {
Log.e(TAG, String.format("attemptParseRecord: class %s (opcode 0x%02X) failed to parse at offset %d", record.getShortTypeName(), data[offsetStart], offsetStart));
}
}
return record;
}
public static DateTime parseSimpleDate(byte[] data, int offset) {
DateTime timeStamp = null;
int seconds = 0;
int minutes = 0;
int hour = 0;
//int high = data[0] >> 4;
int low = data[0 + offset] & 0x1F;
//int year_high = data[1] >> 4;
int mhigh = (data[0 + offset] & 0xE0) >> 4;
int mlow = (data[1 + offset] & 0x80) >> 7;
int month = mhigh + mlow;
int dayOfMonth = low + 1;
// python code says year is data[1] & 0x0F, but that will cause problem in 2016.
// Hopefully, the remaining bits are part of the year...
int year = data[1 + offset] & 0x3F;
/*
Log.w(TAG, String.format("Attempting to create DateTime from: %04d-%02d-%02d %02d:%02d:%02d",
year + 2000, month, dayOfMonth, hour, minutes, seconds));
*/
try {
timeStamp = new DateTime(year + 2000, month, dayOfMonth, hour, minutes, seconds);
} catch (org.joda.time.IllegalFieldValueException e) {
//Log.e(TAG,"Illegal DateTime field");
//e.printStackTrace();
return null;
}
return timeStamp;
}
public static void discoverRecords(byte[] data) {
int i = 0;
boolean done = false;
ArrayList<Integer> keyLocations = new ArrayList();
while (!done) {
RecordTypeEnum en = RecordTypeEnum.fromByte(data[i]);
if (en != RecordTypeEnum.Null) {
keyLocations.add(i);
Log.v(TAG, String.format("Possible record of type %s found at index %d", en, i));
}
/*
DateTime ts = parseSimpleDate(data,i);
if (ts != null) {
if (ts.year().get() == 2015) {
Log.w(TAG, String.format("Possible simple date at index %d", i));
}
}
*/
i = i + 1;
done = (i >= data.length - 2);
}
// for each of the discovered key locations, attempt to parse a sequence of records
for(RecordTypeEnum en : RecordTypeEnum.values()) {
}
for(int ix = 0; ix < keyLocations.size(); ix++) {
}
}
/*
*
* For IPC serialization
*
* For IPC serialization
*/
/*
private byte[] crc;
private byte[] data;
protected PumpModel model;
public List<Record> mRecordList;
*/
* private byte[] crc;
* private byte[] data;
* protected PumpModel model;
* public List<Record> mRecordList;
*/
public Bundle pack() {
Bundle bundle = new Bundle();
@ -430,7 +449,7 @@ public class Page {
bundle.putByteArray("data", data);
bundle.putString("model", model.name());
ArrayList<Bundle> records = new ArrayList<>();
for(int i = 0; i < mRecordList.size(); i++) {
for (int i = 0; i < mRecordList.size(); i++) {
try {
records.add(mRecordList.get(i).dictionaryRepresentation());
} catch (NullPointerException e) {
@ -449,7 +468,7 @@ public class Page {
ArrayList<Bundle> records = in.getParcelableArrayList("mRecordList");
mRecordList = new ArrayList<>();
if (records != null) {
for(int i = 0; i < records.size(); i++) {
for (int i = 0; i < records.size(); i++) {
Record r = RecordTypeEnum.getRecordClassInstance(records.get(i), model);
r.readFromBundle(records.get(i));
mRecordList.add(r);
@ -457,5 +476,4 @@ public class Page {
}
}
}

View file

@ -1,11 +1,11 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data;
import android.util.Log;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import android.util.Log;
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC;
@ -15,6 +15,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
* Created by geoff on 6/4/16.
*/
public class RawHistoryPage {
private static final String TAG = "RawHistoryPage";
private static final Logger LOG = LoggerFactory.getLogger(RawHistoryPage.class);
byte[] data = new byte[0];
@ -54,9 +55,11 @@ public class RawHistoryPage {
int crcStored = ByteUtil.toInt(data[1022], data[1023]);
if (crcCalculated != crcStored) {
LOG.error("Stored CRC ({}) is different than calculated ({}), but ignored for now.", crcStored, crcCalculated);
LOG.error("Stored CRC ({}) is different than calculated ({}), but ignored for now.", crcStored,
crcCalculated);
} else {
if (MedtronicUtil.isLowLevelDebug()) LOG.debug("CRC ok.");
if (MedtronicUtil.isLowLevelDebug())
LOG.debug("CRC ok.");
}
return crcCalculated == crcStored;
@ -76,5 +79,4 @@ public class RawHistoryPage {
}
}
}

View file

@ -8,16 +8,20 @@ import org.joda.time.LocalDateTime;
* Exists to easily merge 2 byte timestamps and 5 byte timestamps.
*/
public class PumpTimeStamp {
private LocalDateTime localDateTime;
public PumpTimeStamp() {
localDateTime = new LocalDateTime(1973, 1, 1, 1, 1);
}
public PumpTimeStamp(String stringRepresentation) {
localDateTime.parse(stringRepresentation);
}
public PumpTimeStamp(LocalDate localDate) {
try {
localDateTime = new LocalDateTime(localDate);
@ -27,14 +31,17 @@ public class PumpTimeStamp {
}
}
public PumpTimeStamp(LocalDateTime localDateTime) {
this.localDateTime = localDateTime;
}
public LocalDateTime getLocalDateTime() {
return localDateTime;
}
@Override
public String toString() {
return getLocalDateTime().toString();

View file

@ -8,10 +8,21 @@ abstract public class Record {
protected MedtronicDeviceType model;
protected byte recordOp;
//protected int length;
// protected int length;
protected int foundAtOffset;
protected byte[] rawbytes = new byte[0];
//protected String recordTypeName = this.getClass().getSimpleName();
// protected String recordTypeName = this.getClass().getSimpleName();
public Record() {
}
protected static int asUINT8(byte b) {
return (b < 0) ? b + 256 : b;
}
public String getRecordTypeName() {
@ -34,11 +45,6 @@ abstract public class Record {
}
public Record() {
}
public boolean parseWithOffset(byte[] data, MedtronicDeviceType model, int foundAtOffset) {
// keep track of where the record was found for later analysis
this.foundAtOffset = foundAtOffset;
@ -83,11 +89,6 @@ abstract public class Record {
}
protected static int asUINT8(byte b) {
return (b < 0) ? b + 256 : b;
}
public Bundle dictionaryRepresentation() {
Bundle rval = new Bundle();
writeToBundle(rval);

View file

@ -1,11 +1,11 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history;
import android.os.Bundle;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import android.os.Bundle;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record.AlarmClockReminderPumpEvent;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record.AlarmSensorPumpEvent;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record.BGReceivedPumpEvent;
@ -68,36 +68,35 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType
@Deprecated
public enum RecordTypeEnum {
Null((byte) 0x00, null, 0), //
Null((byte)0x00, null, 0), //
// Good Events
BolusNormal(0x01, BolusNormalPumpEvent.class), // OK
Prime((byte) 0x03, PrimePumpEvent.class), // OK
AlarmPump((byte) 0x06, PumpAlarmPumpEvent.class), //
ResultDailyTotal((byte) 0x07, ResultDailyTotalPumpEvent.class), // OK
ChangeBasalProfile_old_profile((byte) 0x08, ChangeBasalProfilePatternPumpEvent.class), // OK
ChangeBasalProfile_new_profile((byte) 0x09, ChangeBasalProfilePumpEvent.class), // OK
Prime((byte)0x03, PrimePumpEvent.class), // OK
AlarmPump((byte)0x06, PumpAlarmPumpEvent.class), //
ResultDailyTotal((byte)0x07, ResultDailyTotalPumpEvent.class), // OK
ChangeBasalProfile_old_profile((byte)0x08, ChangeBasalProfilePatternPumpEvent.class), // OK
ChangeBasalProfile_new_profile((byte)0x09, ChangeBasalProfilePumpEvent.class), // OK
CalBgForPh((byte) 0x0A, CalBgForPhPumpEvent.class), //
AlarmSensor((byte) 0x0B, AlarmSensorPumpEvent.class), //
ClearAlarm((byte) 0x0C, ClearAlarmPumpEvent.class), //
SelectBasalProfile((byte) 0x14, IgnoredHistoryEntry.class, 7), // OK
TempBasalDuration((byte) 0x16, TempBasalDurationPumpEvent.class), // OK
ChangeTime((byte) 0x17, ChangeTimePumpEvent.class), // OK
NewTimeSet((byte) 0x18, NewTimeSet.class), // OK
CalBgForPh((byte)0x0A, CalBgForPhPumpEvent.class), //
AlarmSensor((byte)0x0B, AlarmSensorPumpEvent.class), //
ClearAlarm((byte)0x0C, ClearAlarmPumpEvent.class), //
SelectBasalProfile((byte)0x14, IgnoredHistoryEntry.class, 7), // OK
TempBasalDuration((byte)0x16, TempBasalDurationPumpEvent.class), // OK
ChangeTime((byte)0x17, ChangeTimePumpEvent.class), // OK
NewTimeSet((byte)0x18, NewTimeSet.class), // OK
JournalEntryPumpLowBattery((byte) 0x19, JournalEntryPumpLowBatteryPumpEvent.class), //
RECORD_TYPE_BATTERY((byte) 0x1A, BatteryPumpEvent.class), //
JournalEntryPumpLowBattery((byte)0x19, JournalEntryPumpLowBatteryPumpEvent.class), //
RECORD_TYPE_BATTERY((byte)0x1A, BatteryPumpEvent.class), //
SetAutoOff(0x1b, 7), //
Suspend((byte) 0x1E, SuspendPumpEvent.class), // OK
Resume((byte) 0x1F, ResumePumpEvent.class), // OK
Suspend((byte)0x1E, SuspendPumpEvent.class), // OK
Resume((byte)0x1F, ResumePumpEvent.class), // OK
SelfTest(0x20, 7), //
Rewind((byte) 0x21, RewindPumpEvent.class), //
Rewind((byte)0x21, RewindPumpEvent.class), //
ClearSettings(0x22, 7), //
ChangeChildBlockEnable((byte) 0x23, ChangeChildBlockEnablePumpEvent.class), //
ChangeMaxBolus((byte) 0x24, ChangeMaxBolusPumpEvent.class), //
EnableDisableRemote((byte) 0x26, EnableDisableRemotePumpEvent.class), //
ChangeChildBlockEnable((byte)0x23, ChangeChildBlockEnablePumpEvent.class), //
ChangeMaxBolus((byte)0x24, ChangeMaxBolusPumpEvent.class), //
EnableDisableRemote((byte)0x26, EnableDisableRemotePumpEvent.class), //
ChangeMaxBasal(0x2c, 7), //
EnableBolusWizard(0x2d, 7), //
Andy2E(0x2e, 7), //
@ -105,9 +104,9 @@ public enum RecordTypeEnum {
Andy30(0x30, 7), //
ChangeBGReminderOffset(0x31, 7), //
ChangeAlarmClockTime(0x32, 7), //
tempBasal((byte) 0x33, TempBasalRatePumpEvent.class), //
journalEntryPumpLowReservoir((byte) 0x34, JournalEntryPumpLowReservoirPumpEvent.class), //
AlarmClockReminder((byte) 0x35, AlarmClockReminderPumpEvent.class), //
tempBasal((byte)0x33, TempBasalRatePumpEvent.class), //
journalEntryPumpLowReservoir((byte)0x34, JournalEntryPumpLowReservoirPumpEvent.class), //
AlarmClockReminder((byte)0x35, AlarmClockReminderPumpEvent.class), //
ChangeMeterId(0x36, 7), // 715 = 21 ??
MM512_Event_0x37(0x37, 7), //
MM512_Event_0x38(0x38, 7), //
@ -117,11 +116,11 @@ public enum RecordTypeEnum {
changeParadigmLinkID(0x3c, 7), //
MM512_Event_0x3D(0x3D, 7), //
MM512_Event_0x3E(0x3e, 7), //
bgReceived((byte) 0x3F, BGReceivedPumpEvent.class), //
bgReceived((byte)0x3F, BGReceivedPumpEvent.class), //
JournalEntryMealMarker(0x40, 7), //
JournalEntryExerciseMarker((byte) 0x41, JournalEntryExerciseMarkerPumpEvent.class), //
JournalEntryInsulinMarker((byte) 0x42, Unknown7ByteEvent1.class), //
journalEntryOtherMarker((byte) 0x43, InsulinMarkerEvent.class), //
JournalEntryExerciseMarker((byte)0x41, JournalEntryExerciseMarkerPumpEvent.class), //
JournalEntryInsulinMarker((byte)0x42, Unknown7ByteEvent1.class), //
journalEntryOtherMarker((byte)0x43, InsulinMarkerEvent.class), //
MM512_Event_0x44(0x44, 7), //
MM512_Event_0x45(0x45, 7), //
@ -135,52 +134,50 @@ public enum RecordTypeEnum {
MM512_Event_0x4d(0x4d, 7), //
MM512_Event_0x4e(0x4e, 7), //
// case changeBolusWizardSetup = 0x4f, 7), //
// case changeBolusWizardSetup = 0x4f, 7), //
changeSensorSetup2((byte)0x50, ChangeSensorSetup2PumpEvent.class), //
// case restoreMystery51 = 0x51, 7), //
// case restoreMystery52 = 0x52, 7), //
// case changeSensorAlarmSilenceConfig = 0x53, 7), //
// case restoreMystery54 = 0x54, 7), //
// case restoreMystery55 = 0x55, 7), //
ChangeSensorRateOfChangeAlertSetup((byte)0x56, ChangeSensorRateOfChangeAlertSetupPumpEvent.class), //
ChangeBolusScrollStepSize((byte)0x57, ChangeBolusScrollStepSizePumpEvent.class), //
ChangeBolusWizardSetup((byte)0x5A, ChangeBolusWizardSetupPumpEvent.class), //
BolusWizardBolusEstimate((byte)0x5B, BolusWizardBolusEstimatePumpEvent.class), //
unabsorbedInsulin((byte)0x5C, UnabsorbedInsulin.class), //
// case saveSettings = 0x5d, 7), //
changeVariableBolus((byte)0x5e, ChangeVariableBolusPumpEvent.class), //
changeAudioBolus((byte)0x5f, ChangeAudioBolusPumpEvent.class), //
ChangeBGReminderEnable((byte)0x60, ChangeBGReminderEnablePumpEvent.class), //
ChangeAlarmClockEnable((byte)0x61, ChangeAlarmClockEnablePumpEvent.class), //
changeSensorSetup2((byte) 0x50, ChangeSensorSetup2PumpEvent.class), //
// case restoreMystery51 = 0x51, 7), //
// case restoreMystery52 = 0x52, 7), //
// case changeSensorAlarmSilenceConfig = 0x53, 7), //
// case restoreMystery54 = 0x54, 7), //
// case restoreMystery55 = 0x55, 7), //
ChangeSensorRateOfChangeAlertSetup((byte) 0x56, ChangeSensorRateOfChangeAlertSetupPumpEvent.class), //
ChangeBolusScrollStepSize((byte) 0x57, ChangeBolusScrollStepSizePumpEvent.class), //
ChangeBolusWizardSetup((byte) 0x5A, ChangeBolusWizardSetupPumpEvent.class), //
BolusWizardBolusEstimate((byte) 0x5B, BolusWizardBolusEstimatePumpEvent.class), //
unabsorbedInsulin((byte) 0x5C, UnabsorbedInsulin.class), //
// case saveSettings = 0x5d, 7), //
changeVariableBolus((byte) 0x5e, ChangeVariableBolusPumpEvent.class), //
changeAudioBolus((byte) 0x5f, ChangeAudioBolusPumpEvent.class), //
ChangeBGReminderEnable((byte) 0x60, ChangeBGReminderEnablePumpEvent.class), //
ChangeAlarmClockEnable((byte) 0x61, ChangeAlarmClockEnablePumpEvent.class), //
ChangeTempBasalType((byte) 0x62, ChangeTempBasalTypePumpEvent.class), //
ChangeAlarmNotifyMode((byte) 0x63, ChangeAlarmNotifyModePumpEvent.class), //
ChangeTimeFormat((byte) 0x64, ChangeTimeFormatPumpEvent.class), //
ChangeReservoirWarningTime((byte) 0x65, ChangeReservoirWarningTimePumpEvent.class), //
ChangeBolusReminderEnable((byte) 0x66, ChangeBolusReminderEnablePumpEvent.class), //
ChangeBolusReminderTime((byte) 0x67, ChangeBolusReminderTimePumpEvent.class), //
DeleteBolusReminderTime((byte) 0x68, DeleteBolusReminderTimePumpEvent.class), //
ChangeTempBasalType((byte)0x62, ChangeTempBasalTypePumpEvent.class), //
ChangeAlarmNotifyMode((byte)0x63, ChangeAlarmNotifyModePumpEvent.class), //
ChangeTimeFormat((byte)0x64, ChangeTimeFormatPumpEvent.class), //
ChangeReservoirWarningTime((byte)0x65, ChangeReservoirWarningTimePumpEvent.class), //
ChangeBolusReminderEnable((byte)0x66, ChangeBolusReminderEnablePumpEvent.class), //
ChangeBolusReminderTime((byte)0x67, ChangeBolusReminderTimePumpEvent.class), //
DeleteBolusReminderTime((byte)0x68, DeleteBolusReminderTimePumpEvent.class), //
// case bolusReminder = 0x69, 7), //
DeleteAlarmClockTime((byte) 0x6a, DeleteAlarmClockTimePumpEvent.class), //
DeleteAlarmClockTime((byte)0x6a, DeleteAlarmClockTimePumpEvent.class), //
DailyTotal515(0x6c, 38), // FIXME
dailyTotal522((byte) 0x6D, Model522ResultTotalsPumpEvent.class), //
dailyTotal523((byte) 0x6E, IgnoredHistoryEntry.class, 52), // Sara6E // FIXME
ChangeCarbUnits((byte) 0x6f, ChangeCarbUnitsPumpEvent.class), //
basalProfileStart((byte) 0x7B, BasalProfileStart.class), //
ChangeWatchdogEnable((byte) 0x7c, ChangeWatchdogEnablePumpEvent.class), //
ChangeOtherDeviceID((byte) 0x7d, ChangeOtherDeviceIDPumpEvent.class), //
ChangeWatchdogMarriageProfile((byte) 0x81, ChangeWatchdogMarriageProfilePumpEvent.class), //
DeleteOtherDeviceID((byte) 0x82, DeleteOtherDeviceIDPumpEvent.class), //
ChangeCaptureEventEnable((byte) 0x83, ChangeCaptureEventEnablePumpEvent.class),
dailyTotal522((byte)0x6D, Model522ResultTotalsPumpEvent.class), //
dailyTotal523((byte)0x6E, IgnoredHistoryEntry.class, 52), // Sara6E // FIXME
ChangeCarbUnits((byte)0x6f, ChangeCarbUnitsPumpEvent.class), //
basalProfileStart((byte)0x7B, BasalProfileStart.class), //
ChangeWatchdogEnable((byte)0x7c, ChangeWatchdogEnablePumpEvent.class), //
ChangeOtherDeviceID((byte)0x7d, ChangeOtherDeviceIDPumpEvent.class), //
ChangeWatchdogMarriageProfile((byte)0x81, ChangeWatchdogMarriageProfilePumpEvent.class), //
DeleteOtherDeviceID((byte)0x82, DeleteOtherDeviceIDPumpEvent.class), //
ChangeCaptureEventEnable((byte)0x83, ChangeCaptureEventEnablePumpEvent.class),
// Irelevant records (events that don't concern us for AAPS usage)
;
private static final String TAG = "RecordTypeEnum";
private static Map<Byte, RecordTypeEnum> mapByOpCode = null;
private byte opcode;
private Class mRecordClass;
@ -188,24 +185,14 @@ public enum RecordTypeEnum {
private String shortTypeName;
public byte opcode() {
return opcode;
}
public Class recordClass() {
return mRecordClass;
}
RecordTypeEnum(int b, Class c) {
opcode = (byte) b;
opcode = (byte)b;
mRecordClass = c;
}
RecordTypeEnum(int b, Class c, int length) {
opcode = (byte) b;
opcode = (byte)b;
mRecordClass = c;
this.length = length;
}
@ -217,7 +204,7 @@ public enum RecordTypeEnum {
public static RecordTypeEnum fromByte(byte b) {
for(RecordTypeEnum en : RecordTypeEnum.values()) {
for (RecordTypeEnum en : RecordTypeEnum.values()) {
if (en.opcode() == b) {
return en;
}
@ -226,7 +213,21 @@ public enum RecordTypeEnum {
}
private static final String TAG = "RecordTypeEnum";
public static <T extends Record> T getRecordClassInstance(Bundle bundle, MedtronicDeviceType model) {
byte opcode = bundle.getByte("_opcode");
RecordTypeEnum e = RecordTypeEnum.fromByte(opcode);
return e.getRecordClassInstance(model);
}
public byte opcode() {
return opcode;
}
public Class recordClass() {
return mRecordClass;
}
public <T extends Record> T getRecordClassInstance(MedtronicDeviceType model) {
@ -242,7 +243,7 @@ public enum RecordTypeEnum {
// if this is IgnoredHistoryEntry we need to set type so that we get correct length and name
if (record instanceof IgnoredHistoryEntry) {
IgnoredHistoryEntry he = (IgnoredHistoryEntry) record;
IgnoredHistoryEntry he = (IgnoredHistoryEntry)record;
he.init(this);
}
}
@ -261,13 +262,6 @@ public enum RecordTypeEnum {
}
public static <T extends Record> T getRecordClassInstance(Bundle bundle, MedtronicDeviceType model) {
byte opcode = bundle.getByte("_opcode");
RecordTypeEnum e = RecordTypeEnum.fromByte(opcode);
return e.getRecordClassInstance(model);
}
public int getLength() {
return length;
}

View file

@ -1,30 +1,33 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history;
import android.util.Log;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import android.util.Log;
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
/**
* Created by geoff on 6/4/16.
*/
public class TimeFormat {
public static final String standardFormatString = "YYYY-MM-dd HH:mm:ss";
private static final boolean DEBUG_TIMEFORMAT = false;
private static final String TAG = "TimeFormat";
public TimeFormat() {
}
public static final String standardFormatString = "YYYY-MM-dd HH:mm:ss";
public static DateTimeFormatter standardFormatter() {
return DateTimeFormat.forPattern(standardFormatString);
}
public static LocalDate parse2ByteDate(byte[] data, int offset) throws org.joda.time.IllegalFieldValueException {
int low = ByteUtil.asUINT8(data[0 + offset]) & 0x1F;
int mhigh = (ByteUtil.asUINT8(data[0 + offset]) & 0xE0) >> 4;
@ -33,29 +36,29 @@ public class TimeFormat {
int dayOfMonth = low + 1;
int year = 2000 + (ByteUtil.asUINT8(data[offset + 1]) & 0x7F);
/*
Log.w(TAG, String.format("Attempting to create DateTime from: %04d-%02d-%02d %02d:%02d:%02d",
year + 2000, month, dayOfMonth, hour, minutes, seconds));
*/
// try {
* Log.w(TAG, String.format("Attempting to create DateTime from: %04d-%02d-%02d %02d:%02d:%02d",
* year + 2000, month, dayOfMonth, hour, minutes, seconds));
*/
// try {
LocalDate rval = new LocalDate(year, month, dayOfMonth);
return rval;
/*
} catch (org.joda.time.IllegalFieldValueException e) {
Log.e(TAG,"Illegal DateTime field");
//e.printStackTrace();
return new LocalDate(1973,3,3);
}
*/
* } catch (org.joda.time.IllegalFieldValueException e) {
* Log.e(TAG,"Illegal DateTime field");
* //e.printStackTrace();
* return new LocalDate(1973,3,3);
* }
*/
}
// for relation to old code, replace offset with headerSize
public static LocalDateTime parse5ByteDate(byte[] data, int offset) throws org.joda.time.IllegalFieldValueException {
//offset = headerSize;
// offset = headerSize;
if (DEBUG_TIMEFORMAT) {
Log.w(TAG, String.format("bytes to parse: 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X",
data[offset], data[offset + 1], data[offset + 2], data[offset + 3], data[offset + 4]));
Log.w(TAG, String.format("bytes to parse: 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X", data[offset],
data[offset + 1], data[offset + 2], data[offset + 3], data[offset + 4]));
}
int seconds = data[offset] & 0x3F;
int minutes = data[offset + 1] & 0x3F;
@ -63,22 +66,22 @@ public class TimeFormat {
int dayOfMonth = data[offset + 3] & 0x1F;
// Yes, the month bits are stored in the high bits above seconds and minutes!!
int month = ((data[offset] >> 4) & 0x0c) + ((data[offset + 1] >> 6) & 0x03);
int year = data[offset + 4] & 0x3F; // Assuming this is correct, need to verify. Otherwise this will be a problem in 2016.
int year = data[offset + 4] & 0x3F; // Assuming this is correct, need to verify. Otherwise this will be a
// problem in 2016.
/*
Log.w(TAG,String.format("Attempting to create DateTime from: %04d-%02d-%02d %02d:%02d:%02d",
year+2000,month,dayOfMonth,hour,minutes,seconds));
*/
// try {
* Log.w(TAG,String.format("Attempting to create DateTime from: %04d-%02d-%02d %02d:%02d:%02d",
* year+2000,month,dayOfMonth,hour,minutes,seconds));
*/
// try {
LocalDateTime timeStamp = new LocalDateTime(year + 2000, month, dayOfMonth, hour, minutes, seconds);
return timeStamp;
/*
} catch (org.joda.time.IllegalFieldValueException e) {
Log.e(TAG, "Illegal DateTime field");
//e.printStackTrace();
return new LocalDateTime(1973,2,2,2,2);
}
*/
* } catch (org.joda.time.IllegalFieldValueException e) {
* Log.e(TAG, "Illegal DateTime field");
* //e.printStackTrace();
* return new LocalDateTime(1973,2,2,2,2);
* }
*/
}
}

View file

@ -11,8 +11,15 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType
* Many of the subclasses of this class only override the opcode.
*/
abstract public class TimeStampedRecord extends Record {
//private final static String TAG = "TimeStampedRecord";
// private final static String TAG = "TimeStampedRecord";
private final static boolean DEBUG_TIMESTAMPEDRECORD = false;
protected PumpTimeStamp timestamp;
public TimeStampedRecord() {
timestamp = new PumpTimeStamp();
}
@Override
@ -26,14 +33,6 @@ abstract public class TimeStampedRecord extends Record {
}
protected PumpTimeStamp timestamp;
public TimeStampedRecord() {
timestamp = new PumpTimeStamp();
}
@Override
public PumpTimeStamp getTimestamp() {
return timestamp;

View file

@ -10,11 +10,13 @@ public class AlarmClockReminderPumpEvent extends TimeStampedRecord {
public AlarmClockReminderPumpEvent() {
}
@Override
public String getShortTypeName() {
return "Alarm Reminder";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -1,25 +1,28 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
/**
* Created by geoff on 6/5/16.
*/
public class AlarmSensorPumpEvent extends TimeStampedRecord {
public AlarmSensorPumpEvent() {
}
@Override
public int getLength() {
return 8;
}
@Override
public String getShortTypeName() {
return "Alarm Sensor";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record;
import android.os.Bundle;
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
@ -8,6 +7,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
public class BGReceivedPumpEvent extends TimeStampedRecord {
private int amount = 0;
private byte[] meter = new byte[3];

View file

@ -6,6 +6,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
public class BasalProfileStart extends TimeStampedRecord {
private static final String TAG = "BasalProfileStart";
private int offset = 0;
private double rate = 0.0;
@ -36,7 +37,7 @@ public class BasalProfileStart extends TimeStampedRecord {
profileIndex = asUINT8(data[1]);
offset = asUINT8(data[7]) * 30 * 1000 * 60;
rate = (double) (asUINT8(data[8])) / 40.0;
rate = (double)(asUINT8(data[8])) / 40.0;
return true;
}

View file

@ -3,14 +3,17 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.recor
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
public class BatteryPumpEvent extends TimeStampedRecord {
public BatteryPumpEvent() {
}
@Override
public String getShortTypeName() {
return "Battery";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record;
import android.os.Bundle;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.PumpTimeStamp;
@ -9,6 +8,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
public class BolusNormalPumpEvent extends TimeStampedRecord {
private final static String TAG = "BolusNormalPumpEvent";
private double programmedAmount = 0.0;

View file

@ -20,7 +20,7 @@ public class BolusWizardBolusEstimatePumpEvent extends TimeStampedRecord {
public BolusWizardBolusEstimatePumpEvent() {
correctionEstimate = (double) 0.0;
correctionEstimate = (double)0.0;
bloodGlucose = 0;
carbohydrates = 0;
carbRatio = 0.0;
@ -141,24 +141,24 @@ public class BolusWizardBolusEstimatePumpEvent extends TimeStampedRecord {
carbohydrates = (asUINT8(data[8]) & 0x0c << 6) + asUINT8(data[7]);
bloodGlucose = (asUINT8(data[8]) & 0x03 << 8) + asUINT8(data[1]);
foodEstimate = insulinDecode(asUINT8(data[14]), asUINT8(data[15]));
correctionEstimate = (double) ((asUINT8(data[16]) & 0b111000) << 5 + asUINT8(data[13])) / 40.0;
correctionEstimate = (double)((asUINT8(data[16]) & 0b111000) << 5 + asUINT8(data[13])) / 40.0;
bolusEstimate = insulinDecode(asUINT8(data[19]), asUINT8(data[20]));
unabsorbedInsulinTotal = insulinDecode(asUINT8(data[17]), asUINT8(data[18]));
bgTargetLow = asUINT8(data[12]);
bgTargetHigh = asUINT8(data[21]);
insulinSensitivity = asUINT8(data[11]);
carbRatio = (double) (((asUINT8(data[9]) & 0x07) << 8) + asUINT8(data[10])) / 40.0;
carbRatio = (double)(((asUINT8(data[9]) & 0x07) << 8) + asUINT8(data[10])) / 40.0;
} else {
carbohydrates = asUINT8(data[7]);
bloodGlucose = ((asUINT8(data[8]) & 0x03) << 8) + asUINT8(data[1]);
foodEstimate = (double) (asUINT8(data[13])) / 10.0;
correctionEstimate = (double) ((asUINT8(data[14]) << 8) + asUINT8(data[12])) / 10.0;
bolusEstimate = (double) (asUINT8(data[18])) / 10.0;
unabsorbedInsulinTotal = (double) (asUINT8(data[16])) / 10.0;
foodEstimate = (double)(asUINT8(data[13])) / 10.0;
correctionEstimate = (double)((asUINT8(data[14]) << 8) + asUINT8(data[12])) / 10.0;
bolusEstimate = (double)(asUINT8(data[18])) / 10.0;
unabsorbedInsulinTotal = (double)(asUINT8(data[16])) / 10.0;
bgTargetLow = asUINT8(data[11]);
bgTargetHigh = asUINT8(data[19]);
insulinSensitivity = asUINT8(data[10]);
carbRatio = (double) asUINT8(data[9]);
carbRatio = (double)asUINT8(data[9]);
}
return true;

View file

@ -6,6 +6,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
public class CalBgForPhPumpEvent extends TimeStampedRecord {
private int amount = 0;

View file

@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
* Created by geoff on 6/5/16.
*/
public class ChangeAlarmClockEnablePumpEvent extends TimeStampedRecord {
public ChangeAlarmClockEnablePumpEvent() {
}
@Override
public String getShortTypeName() {
return "Alarm Clock Enable";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -3,18 +3,20 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.recor
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
public class ChangeAlarmNotifyModePumpEvent extends TimeStampedRecord {
public ChangeAlarmNotifyModePumpEvent() {
}
@Override
public String getShortTypeName() {
return "Ch Alarm Notify Mode";
}
@Override
public boolean isAAPSRelevant() {
return false;
}
}

View file

@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
* Created by geoff on 6/5/16.
*/
public class ChangeAudioBolusPumpEvent extends TimeStampedRecord {
public ChangeAudioBolusPumpEvent() {
}
@Override
public String getShortTypeName() {
return "Ch Audio Bolus";
}
@Override
public boolean isAAPSRelevant() {
return true;

View file

@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
* Created by geoff on 6/5/16.
*/
public class ChangeBGReminderEnablePumpEvent extends TimeStampedRecord {
public ChangeBGReminderEnablePumpEvent() {
}
@Override
public String getShortTypeName() {
return "Ch BG Rmndr Enable";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -6,19 +6,23 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
* Created by geoff on 6/5/16.
*/
public class ChangeBasalProfilePatternPumpEvent extends TimeStampedRecord {
public ChangeBasalProfilePatternPumpEvent() {
}
@Override
public int getLength() {
return 152;
}
@Override
public String getShortTypeName() {
return "Ch Basal Prof Pat";
}
@Override
public boolean isAAPSRelevant() {
return true;

View file

@ -3,19 +3,23 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.recor
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
public class ChangeBasalProfilePumpEvent extends TimeStampedRecord {
public ChangeBasalProfilePumpEvent() {
}
@Override
public int getLength() {
return 152;
}
@Override
public String getShortTypeName() {
return "Ch Basal Profile";
}
@Override
public boolean isAAPSRelevant() {
return true;

View file

@ -6,19 +6,23 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
* Created by geoff on 6/5/16.
*/
public class ChangeBolusReminderEnablePumpEvent extends TimeStampedRecord {
public ChangeBolusReminderEnablePumpEvent() {
}
@Override
public int getLength() {
return 9;
}
@Override
public String getShortTypeName() {
return "Ch Bolus Rmndr Enable";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -6,19 +6,23 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
* Created by geoff on 6/5/16.
*/
public class ChangeBolusReminderTimePumpEvent extends TimeStampedRecord {
public ChangeBolusReminderTimePumpEvent() {
}
@Override
public String getShortTypeName() {
return "Ch Bolus Rmndr Time";
}
@Override
public int getLength() {
return 9;
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
* Created by geoff on 6/5/16.
*/
public class ChangeBolusScrollStepSizePumpEvent extends TimeStampedRecord {
public ChangeBolusScrollStepSizePumpEvent() {
}
@Override
public String getShortTypeName() {
return "Ch Bolus Scroll SS";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
public class ChangeBolusWizardSetupPumpEvent extends TimeStampedRecord {
@ -8,16 +7,19 @@ public class ChangeBolusWizardSetupPumpEvent extends TimeStampedRecord {
public ChangeBolusWizardSetupPumpEvent() {
}
@Override
public int getLength() {
return 144;
}
@Override
public String getShortTypeName() {
return "Ch Bolus Wizard Setup";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
* Created by geoff on 6/5/16.
*/
public class ChangeCaptureEventEnablePumpEvent extends TimeStampedRecord {
public ChangeCaptureEventEnablePumpEvent() {
}
@Override
public String getShortTypeName() {
return "Ch Capture Event Ena";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
* Created by geoff on 6/5/16.
*/
public class ChangeCarbUnitsPumpEvent extends TimeStampedRecord {
public ChangeCarbUnitsPumpEvent() {
}
@Override
public String getShortTypeName() {
return "Ch Carb Units";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
* Created by geoff on 6/5/16.
*/
public class ChangeChildBlockEnablePumpEvent extends TimeStampedRecord {
public ChangeChildBlockEnablePumpEvent() {
}
@Override
public String getShortTypeName() {
return "Ch Child Block Ena";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
* Created by geoff on 6/5/16.
*/
public class ChangeMaxBolusPumpEvent extends TimeStampedRecord {
public ChangeMaxBolusPumpEvent() {
}
@Override
public String getShortTypeName() {
return "Ch Max Bolux";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
public class ChangeOtherDeviceIDPumpEvent extends TimeStampedRecord {
@ -8,16 +7,19 @@ public class ChangeOtherDeviceIDPumpEvent extends TimeStampedRecord {
public ChangeOtherDeviceIDPumpEvent() {
}
@Override
public int getLength() {
return 37;
}
@Override
public String getShortTypeName() {
return "Ch Other Dev ID";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
* Created by geoff on 6/5/16.
*/
public class ChangeReservoirWarningTimePumpEvent extends TimeStampedRecord {
public ChangeReservoirWarningTimePumpEvent() {
}
@Override
public String getShortTypeName() {
return "Ch Res Warn Time";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -6,19 +6,23 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
* Created by geoff on 6/5/16.
*/
public class ChangeSensorRateOfChangeAlertSetupPumpEvent extends TimeStampedRecord {
public ChangeSensorRateOfChangeAlertSetupPumpEvent() {
}
@Override
public int getLength() {
return 12;
}
@Override
public String getShortTypeName() {
return "Ch Sensor ROC Alert";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -6,19 +6,23 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
* Created by geoff on 6/5/16.
*/
public class ChangeSensorSetup2PumpEvent extends TimeStampedRecord {
public ChangeSensorSetup2PumpEvent() {
}
@Override
public int getLength() {
return 37;
}
@Override
public String getShortTypeName() {
return "Ch Sensor Setup2";
}
@Override
public boolean isAAPSRelevant() {
return false;

View file

@ -9,6 +9,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType
* Created by geoff on 6/5/16.
*/
public class ChangeTempBasalTypePumpEvent extends TimeStampedRecord {
private boolean isPercent = false; // either absolute or percent

Some files were not shown because too many files have changed in this diff Show more