- 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 android:name=".plugins.Persistentnotification.DummyService" />
<service <service
android:name=".plugins.PumpMedtronic.service.RileyLinkMedtronicService" android:name=".plugins.PumpMedtronic.service.RileyLinkMedtronicService"
android:enabled="true" android:enabled="true"
android:exported="true" /> android:exported="true" />
@ -185,7 +185,7 @@
<meta-data <meta-data
android:name="io.fabric.ApiKey" android:name="io.fabric.ApiKey"
android:value="59d462666c664c57b29e1d79ea123e01f8057cfa" /> android:value="59d462666c664c57b29e1d79ea123e01f8057cfa" />
<activity <activity
android:name=".setupwizard.SetupWizardActivity" android:name=".setupwizard.SetupWizardActivity"
android:configChanges="orientation|keyboardHidden|screenSize" android:configChanges="orientation|keyboardHidden|screenSize"
@ -193,11 +193,12 @@
android:label="@string/title_activity_setup_wizard" /> android:label="@string/title_activity_setup_wizard" />
<activity <activity
android:name=".plugins.PumpCommon.dialog.RileylinkSettingsActivity" android:name=".plugins.PumpCommon.hw.rileylink.dialog.RileyLinkStatusActivity"
android:label="@string/title_activity_rileylink_settings" 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" /> android:theme="@style/AppTheme" />
</application> </application>

View file

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

View file

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

View file

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

View file

@ -4,40 +4,36 @@ package info.nightscout.androidaps.plugins.PumpCommon.defs;
* Created by andy on 02/05/2018. * Created by andy on 02/05/2018.
*/ */
public enum DoseStepSize public enum DoseStepSize {
{
ComboBasal( // ComboBasal( //
new DoseStepSizeEntry(0f, 1f, 0.01f), // new DoseStepSizeEntry(0f, 1f, 0.01f), //
new DoseStepSizeEntry(1f, 10f, 0.05f), // new DoseStepSizeEntry(1f, 10f, 0.05f), //
new DoseStepSizeEntry(10f, Float.MAX_VALUE, 0.1f)), // new DoseStepSizeEntry(10f, Float.MAX_VALUE, 0.1f)), //
MedtronicVeoBasal( // MedtronicVeoBasal( //
new DoseStepSizeEntry(0f, 1f, 0.025f), // new DoseStepSizeEntry(0f, 1f, 0.025f), //
new DoseStepSizeEntry(1f, 10f, 0.05f), // new DoseStepSizeEntry(1f, 10f, 0.05f), //
new DoseStepSizeEntry(10f, Float.MAX_VALUE, 0.1f)), // new DoseStepSizeEntry(10f, Float.MAX_VALUE, 0.1f)), //
; ;
DoseStepSizeEntry[] entries; DoseStepSizeEntry[] entries;
DoseStepSize(DoseStepSizeEntry...entries) DoseStepSize(DoseStepSizeEntry... entries) {
{
this.entries = entries; this.entries = entries;
} }
public float getStepSizeForAmount(float amount) public float getStepSizeForAmount(float amount) {
{
for (DoseStepSizeEntry entry : entries) { for (DoseStepSizeEntry entry : entries) {
if (entry.from <= amount && entry.to > amount) if (entry.from <= amount && entry.to > amount)
return entry.value; return entry.value;
} }
// should never come to this // 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(entry.from);
sb.append("-"); sb.append("-");
if (entry.to == Float.MAX_VALUE) if (entry.to == Float.MAX_VALUE) {
{
sb.append("~}"); sb.append("~}");
} } else {
else
{
sb.append(entry.to); sb.append(entry.to);
sb.append("}, "); sb.append("}, ");
} }
@ -65,20 +58,20 @@ public enum DoseStepSize
return sb.toString(); return sb.toString();
} }
static class DoseStepSizeEntry {
static class DoseStepSizeEntry
{
float from; float from;
float to; float to;
float value; 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.from = from;
this.to = to; this.to = to;
this.value = value; this.value = value;
} }
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -12,7 +12,7 @@ public class RileyLinkConst {
public static final String RileyLinkReady = Prefix + "RileyLink_Ready"; public static final String RileyLinkReady = Prefix + "RileyLink_Ready";
public static final String RileyLinkGattFailed = Prefix + "RileyLink_Gatt_Failed"; 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 BluetoothConnected = Prefix + "Bluetooth_Connected";
public static final String BluetoothReconnected = Prefix + "Bluetooth_Reconnected"; public static final String BluetoothReconnected = Prefix + "Bluetooth_Reconnected";
@ -35,6 +35,7 @@ public class RileyLinkConst {
} }
public class IPC { public class IPC {
// needs to br renamed (and maybe removed) // needs to br renamed (and maybe removed)
public static final String MSG_PUMP_quickTune = Prefix + "MSG_PUMP_quickTune"; public static final String MSG_PUMP_quickTune = Prefix + "MSG_PUMP_quickTune";
public static final String MSG_PUMP_tunePump = Prefix + "MSG_PUMP_tunePump"; 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; package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink;
import android.content.Context; import java.util.ArrayList;
import android.content.Intent; import java.util.List;
import android.support.v4.content.LocalBroadcastManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList; import android.content.Context;
import java.util.List; import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE; 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.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkError; 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.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.RileyLinkService;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.RileyLinkServiceData; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.data.ServiceNotification; 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.defs.MedtronicDeviceType;
import info.nightscout.androidaps.plugins.PumpMedtronic.events.EventMedtronicDeviceStatusChange; import info.nightscout.androidaps.plugins.PumpMedtronic.events.EventMedtronicDeviceStatusChange;
/** /**
* Created by andy on 17/05/2018. * Created by andy on 17/05/2018.
*/ */
@ -33,22 +33,23 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.events.EventMedtronicDev
public class RileyLinkUtil { public class RileyLinkUtil {
private static final Logger LOG = LoggerFactory.getLogger(RileyLinkUtil.class); 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 Context context;
private static RileyLinkBLE rileyLinkBLE; private static RileyLinkBLE rileyLinkBLE;
private static RileyLinkServiceData rileyLinkServiceData; private static RileyLinkServiceData rileyLinkServiceData;
private static List<RLHistoryItem> historyRileyLink = new ArrayList<>(); // private static PumpType pumpType;
//private static PumpType pumpType; // private static MedtronicPumpStatus medtronicPumpStatus;
//private static MedtronicPumpStatus medtronicPumpStatus;
private static RileyLinkService rileyLinkService; private static RileyLinkService rileyLinkService;
protected static RileyLinkCommunicationManager rileyLinkCommunicationManager; // private static RileyLinkIPCConnection rileyLinkIPCConnection;
//private static RileyLinkIPCConnection rileyLinkIPCConnection;
private static MedtronicDeviceType medtronicPumpModel; private static MedtronicDeviceType medtronicPumpModel;
private static RileyLinkTargetFrequency rileyLinkTargetFrequency; // private static MedtronicPumpStatus pumpStatus;
//private static MedtronicPumpStatus pumpStatus;
// BAD dependencies in Classes: RileyLinkService // BAD dependencies in Classes: RileyLinkService
private static RileyLinkTargetFrequency rileyLinkTargetFrequency;
// Broadcasts: RileyLinkBLE, RileyLinkService, // Broadcasts: RileyLinkBLE, RileyLinkService,
private static RileyLinkTargetDevice targetDevice;
public static void setContext(Context contextIn) { public static void setContext(Context contextIn) {
@ -62,13 +63,13 @@ public class RileyLinkUtil {
} }
public static void setServiceState(RileyLinkServiceState newState) { public static RileyLinkServiceState getServiceState() {
setServiceState(newState, null); return RileyLinkUtil.rileyLinkServiceData.serviceState;
} }
public static RileyLinkServiceState getServiceState() { public static void setServiceState(RileyLinkServiceState newState) {
return RileyLinkUtil.rileyLinkServiceData.serviceState; setServiceState(newState, null);
} }
@ -81,23 +82,25 @@ public class RileyLinkUtil {
RileyLinkUtil.rileyLinkServiceData.serviceState = newState; RileyLinkUtil.rileyLinkServiceData.serviceState = newState;
RileyLinkUtil.rileyLinkServiceData.errorCode = errorCode; 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)); MainApp.bus().post(new EventMedtronicDeviceStatusChange(newState, errorCode));
} }
public static void setRileyLinkBLE(RileyLinkBLE rileyLinkBLEIn) {
RileyLinkUtil.rileyLinkBLE = rileyLinkBLEIn;
}
public static RileyLinkBLE getRileyLinkBLE() { public static RileyLinkBLE getRileyLinkBLE() {
return RileyLinkUtil.rileyLinkBLE; return RileyLinkUtil.rileyLinkBLE;
} }
public static void setRileyLinkBLE(RileyLinkBLE rileyLinkBLEIn) {
RileyLinkUtil.rileyLinkBLE = rileyLinkBLEIn;
}
public static RileyLinkServiceData getRileyLinkServiceData() { public static RileyLinkServiceData getRileyLinkServiceData() {
return RileyLinkUtil.rileyLinkServiceData; return RileyLinkUtil.rileyLinkServiceData;
} }
@ -113,18 +116,13 @@ public class RileyLinkUtil {
} }
public static void setRileyLinkService(RileyLinkService rileyLinkService) {
RileyLinkUtil.rileyLinkService = rileyLinkService;
}
public static RileyLinkService getRileyLinkService() { public static RileyLinkService getRileyLinkService() {
return RileyLinkUtil.rileyLinkService; return RileyLinkUtil.rileyLinkService;
} }
public static void setRileyLinkCommunicationManager(RileyLinkCommunicationManager rileyLinkCommunicationManager) { public static void setRileyLinkService(RileyLinkService rileyLinkService) {
RileyLinkUtil.rileyLinkCommunicationManager = rileyLinkCommunicationManager; 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) { public static boolean sendNotification(ServiceNotification notification, Integer clientHashcode) {
return RileyLinkUtil.rileyLinkService.sendNotification(notification, clientHashcode); return RileyLinkUtil.rileyLinkService.sendNotification(notification, clientHashcode);
} }
static ServiceTask currentTask;
// FIXME remove ? // FIXME remove ?
public static void setCurrentTask(ServiceTask task) { public static void setCurrentTask(ServiceTask task) {
if (currentTask == null) { if (currentTask == null) {
@ -170,14 +171,18 @@ public class RileyLinkUtil {
// make a new bundle to send as the message data // make a new bundle to send as the message data
transport.setServiceResult(serviceResult); transport.setServiceResult(serviceResult);
// FIXME // FIXME
//transport.setTransportType(RT2Const.IPC.MSG_ServiceResult); // transport.setTransportType(RT2Const.IPC.MSG_ServiceResult);
//rileyLinkIPCConnection.sendTransport(transport, clientHashcode); // rileyLinkIPCConnection.sendTransport(transport, clientHashcode);
} }
// public static void setRileyLinkIPCConnection(RileyLinkIPCConnection rileyLinkIPCConnection) { // public static void setRileyLinkIPCConnection(RileyLinkIPCConnection rileyLinkIPCConnection) {
// RileyLinkUtil.rileyLinkIPCConnection = rileyLinkIPCConnection; // RileyLinkUtil.rileyLinkIPCConnection = rileyLinkIPCConnection;
// } // }
public static RileyLinkTargetFrequency getRileyLinkTargetFrequency() {
return RileyLinkUtil.rileyLinkTargetFrequency;
}
public static void setRileyLinkTargetFrequency(RileyLinkTargetFrequency 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) { public static boolean isSame(Double d1, Double d2) {
double diff = d1 - d2; double diff = d1 - d2;
return (Math.abs(diff) <= 0.000001); 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; package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble;
import android.os.SystemClock; import java.util.UUID;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.RileyLinkUtil;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.GattAttributes; 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 { public class RFSpy {
private static final Logger LOG = LoggerFactory.getLogger(RFSpy.class);
public static final long RILEYLINK_FREQ_XTAL = 24000000; public static final long RILEYLINK_FREQ_XTAL = 24000000;
public static final int EXPECTED_MAX_BLUETOOTH_LATENCY_MS = 7500; // 1500 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 RileyLinkBLE rileyLinkBle;
private RFSpyReader reader; private RFSpyReader reader;
private RileyLinkTargetFrequency selectedTargetFrequency; private RileyLinkTargetFrequency selectedTargetFrequency;
private UUID radioServiceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO); private UUID radioServiceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO);
private UUID radioDataUUID = UUID.fromString(GattAttributes.CHARA_RADIO_DATA); private UUID radioDataUUID = UUID.fromString(GattAttributes.CHARA_RADIO_DATA);
private UUID radioVersionUUID = UUID.fromString(GattAttributes.CHARA_RADIO_VERSION); 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 // Starts an async task to read when data is available
public void startReader() { public void startReader() {
rileyLinkBle.registerRadioResponseCountNotification(new Runnable() { rileyLinkBle.registerRadioResponseCountNotification(new Runnable() {
@Override @Override
public void run() { public void run() {
newDataIsAvailable(); newDataIsAvailable();
@ -70,8 +66,6 @@ public class RFSpy {
} }
public int notConnectedCount = 0;
// This gets the version from the BLE113, not from the CC1110. // 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. // I.e., this gets the version from the BLE interface, not from the radio.
public String getVersion() { public String getVersion() {
@ -84,6 +78,7 @@ public class RFSpy {
} }
} }
public String getRadioVersion() { public String getRadioVersion() {
RFSpyResponse resp = writeToData(RFSpyCommand.GetVersion, null, EXPECTED_MAX_BLUETOOTH_LATENCY_MS); RFSpyResponse resp = writeToData(RFSpyCommand.GetVersion, null, EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
if (resp == null) { if (resp == null) {
@ -105,19 +100,21 @@ public class RFSpy {
byte[] junkInBuffer = reader.poll(0); byte[] junkInBuffer = reader.poll(0);
while (junkInBuffer != null) { 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); junkInBuffer = reader.poll(0);
} }
// prepend length, and send it. // prepend length, and send it.
byte[] prepended = ByteUtil.concat(new byte[]{(byte) (bytes.length)}, bytes); byte[] prepended = ByteUtil.concat(new byte[] { (byte)(bytes.length) }, bytes);
BLECommOperationResult writeCheck = rileyLinkBle.writeCharacteristic_blocking(radioServiceUUID, radioDataUUID, prepended); BLECommOperationResult writeCheck = rileyLinkBle.writeCharacteristic_blocking(radioServiceUUID, radioDataUUID,
prepended);
if (writeCheck.resultCode != BLECommOperationResult.RESULT_SUCCESS) { if (writeCheck.resultCode != BLECommOperationResult.RESULT_SUCCESS) {
LOG.error("BLE Write operation failed, code=" + writeCheck.resultCode); LOG.error("BLE Write operation failed, code=" + writeCheck.resultCode);
return new RFSpyResponse(); // will be a null (invalid) response return new RFSpyResponse(); // will be a null (invalid) response
} }
SystemClock.sleep(100); 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); byte[] rawResponse = reader.poll(responseTimeout_ms);
RFSpyResponse resp = new RFSpyResponse(command, rawResponse); RFSpyResponse resp = new RFSpyResponse(command, rawResponse);
if (rawResponse == null) { if (rawResponse == null) {
@ -139,16 +136,18 @@ public class RFSpy {
LOG.info("writeToData: decoded radio response is " + ByteUtil.shortHexString(responsePayload)); LOG.info("writeToData: decoded radio response is " + ByteUtil.shortHexString(responsePayload));
resetNotConnectedCount(); resetNotConnectedCount();
} }
//Log.i(TAG, "writeToData: raw response is " + ByteUtil.shortHexString(rawResponse)); // Log.i(TAG, "writeToData: raw response is " + ByteUtil.shortHexString(rawResponse));
} }
} }
return resp; return resp;
} }
private void resetNotConnectedCount() { private void resetNotConnectedCount() {
this.notConnectedCount = 0; this.notConnectedCount = 0;
} }
private byte[] getByteArray(byte... input) { private byte[] getByteArray(byte... input) {
return input; return input;
} }
@ -173,52 +172,60 @@ public class RFSpy {
public RFSpyResponse transmit(RadioPacket radioPacket) { 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) { public RFSpyResponse transmit(RadioPacket radioPacket, byte sendChannel, byte repeatCount, byte delay_ms) {
// append checksum, encode data, send it. // append checksum, encode data, send it.
byte[] fullPacket = ByteUtil.concat(getByteArray(sendChannel, repeatCount, delay_ms), radioPacket.getEncoded()); 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; return response;
} }
public RFSpyResponse receive(byte listenChannel, int timeout_ms, byte retryCount) { public RFSpyResponse receive(byte listenChannel, int timeout_ms, byte retryCount) {
int receiveDelay = timeout_ms * (retryCount + 1); 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); return writeToData(RFSpyCommand.GetPacket, listen, receiveDelay);
} }
public RFSpyResponse transmitThenReceive(RadioPacket pkt, int timeout_ms) { 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 sendDelay = repeatCount * delay_ms;
int receiveDelay = timeout_ms * (retryCount + 1); 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()); 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) { public RFSpyResponse updateRegister(CC111XRegister reg, int val) {
byte[] updateRegisterPkt = getByteArray(reg.value, (byte) val); byte[] updateRegisterPkt = getByteArray(reg.value, (byte)val);
RFSpyResponse resp = writeToData(RFSpyCommand.UpdateRegister, updateRegisterPkt, EXPECTED_MAX_BLUETOOTH_LATENCY_MS); RFSpyResponse resp = writeToData(RFSpyCommand.UpdateRegister, updateRegisterPkt,
EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
return resp; return resp;
} }
public void setBaseFrequency(double freqMHz) { public void setBaseFrequency(double freqMHz) {
int value = (int) (freqMHz * 1000000 / ((double) (RILEYLINK_FREQ_XTAL) / Math.pow(2.0, 16.0))); int value = (int)(freqMHz * 1000000 / ((double)(RILEYLINK_FREQ_XTAL) / Math.pow(2.0, 16.0)));
updateRegister(CC111XRegister.freq0, (byte) (value & 0xff)); updateRegister(CC111XRegister.freq0, (byte)(value & 0xff));
updateRegister(CC111XRegister.freq1, (byte) ((value >> 8) & 0xff)); updateRegister(CC111XRegister.freq1, (byte)((value >> 8) & 0xff));
updateRegister(CC111XRegister.freq2, (byte) ((value >> 16) & 0xff)); updateRegister(CC111XRegister.freq2, (byte)((value >> 16) & 0xff));
LOG.warn("Set frequency to {}", freqMHz); LOG.warn("Set frequency to {}", freqMHz);
configureRadioForRegion(RileyLinkUtil.getRileyLinkTargetFrequency()); configureRadioForRegion(RileyLinkUtil.getRileyLinkTargetFrequency());
@ -234,24 +241,24 @@ public class RFSpy {
switch (frequency) { switch (frequency) {
case Medtronic_WorldWide: { case Medtronic_WorldWide: {
setRXFilterMode(RXFilterMode.Wide); setRXFilterMode(RXFilterMode.Wide);
//updateRegister(CC111X_MDMCFG3, (byte) 0x66); // updateRegister(CC111X_MDMCFG3, (byte) 0x66);
//updateRegister(CC111X_MDMCFG2, (byte) 0x33); // updateRegister(CC111X_MDMCFG2, (byte) 0x33);
updateRegister(CC111XRegister.mdmcfg1, 0x62); updateRegister(CC111XRegister.mdmcfg1, 0x62);
updateRegister(CC111XRegister.mdmcfg0, 0x1A); updateRegister(CC111XRegister.mdmcfg0, 0x1A);
updateRegister(CC111XRegister.deviatn, 0x13); updateRegister(CC111XRegister.deviatn, 0x13);
} }
break; break;
case Medtronic_US: { case Medtronic_US: {
setRXFilterMode(RXFilterMode.Narrow); setRXFilterMode(RXFilterMode.Narrow);
//updateRegister(CC111X_MDMCFG3, (byte) 0x66); // updateRegister(CC111X_MDMCFG3, (byte) 0x66);
//updateRegister(CC111X_MDMCFG2, (byte) 0x33); // updateRegister(CC111X_MDMCFG2, (byte) 0x33);
updateRegister(CC111XRegister.mdmcfg1, 0x61); updateRegister(CC111XRegister.mdmcfg1, 0x61);
updateRegister(CC111XRegister.mdmcfg0, 0x7E); updateRegister(CC111XRegister.mdmcfg0, 0x7E);
updateRegister(CC111XRegister.deviatn, 0x15); updateRegister(CC111XRegister.deviatn, 0x15);
} }
break; break;
case Omnipod: { case Omnipod: {
LOG.debug("No region configuration for RfSpy and {}", frequency.name()); LOG.debug("No region configuration for RfSpy and {}", frequency.name());
@ -269,11 +276,10 @@ public class RFSpy {
private void setRXFilterMode(RXFilterMode mode) { 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; 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; 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.UUID;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit; 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.data.GattAttributes;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations.BLECommOperationResult; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations.BLECommOperationResult;
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil; import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
@ -22,24 +22,23 @@ import info.nightscout.androidaps.plugins.PumpCommon.utils.ThreadUtil;
public class RFSpyReader { public class RFSpyReader {
private static final Logger LOG = LoggerFactory.getLogger(RFSpyReader.class); private static final Logger LOG = LoggerFactory.getLogger(RFSpyReader.class);
AsyncTask<Void, Void, Void> readerTask;
//private Context context; // private Context context;
private RileyLinkBLE rileyLinkBle; private RileyLinkBLE rileyLinkBle;
private Semaphore waitForRadioData = new Semaphore(0, true); private Semaphore waitForRadioData = new Semaphore(0, true);
AsyncTask<Void, Void, Void> readerTask;
private LinkedBlockingQueue<byte[]> mDataQueue = new LinkedBlockingQueue<>(); private LinkedBlockingQueue<byte[]> mDataQueue = new LinkedBlockingQueue<>();
private int acquireCount = 0; private int acquireCount = 0;
private int releaseCount = 0; private int releaseCount = 0;
public RFSpyReader(/*Context context,*/ RileyLinkBLE rileyLinkBle) { public RFSpyReader(/* Context context, */RileyLinkBLE rileyLinkBle) {
//this.context = context; // this.context = context;
this.rileyLinkBle = rileyLinkBle; this.rileyLinkBle = rileyLinkBle;
} }
public void init(/*Context context,*/ RileyLinkBLE rileyLinkBLE) { public void init(/* Context context, */RileyLinkBLE rileyLinkBLE) {
//this.context = context; // this.context = context;
this.rileyLinkBle = rileyLinkBLE; 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. // This timeout must be coordinated with the length of the RFSpy radio operation or Bad Things Happen.
public byte[] poll(int timeout_ms) { 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()) if (mDataQueue.isEmpty())
try { try {
// block until timeout or data available. // block until timeout or data available.
// returns null if timeout. // returns null if timeout.
byte[] dataFromQueue = mDataQueue.poll(timeout_ms, TimeUnit.MILLISECONDS); byte[] dataFromQueue = mDataQueue.poll(timeout_ms, TimeUnit.MILLISECONDS);
if (dataFromQueue != null) { 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 { } else {
LOG.debug("Got data [null] at t==" + SystemClock.uptimeMillis()); LOG.debug("Got data [null] at t==" + SystemClock.uptimeMillis());
} }
@ -77,13 +78,15 @@ public class RFSpyReader {
public void newDataIsAvailable() { public void newDataIsAvailable() {
releaseCount++; 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(); waitForRadioData.release();
} }
public void start() { public void start() {
readerTask = new AsyncTask<Void, Void, Void>() { readerTask = new AsyncTask<Void, Void, Void>() {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
UUID serviceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO); UUID serviceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO);
@ -93,7 +96,8 @@ public class RFSpyReader {
try { try {
acquireCount++; acquireCount++;
waitForRadioData.acquire(); 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(100);
SystemClock.sleep(1); SystemClock.sleep(1);
result = rileyLinkBle.readCharacteristic_blocking(serviceUUID, radioDataUUID); result = rileyLinkBle.readCharacteristic_blocking(serviceUUID, radioDataUUID);
@ -101,7 +105,7 @@ public class RFSpyReader {
if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) { if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) {
// only data up to the first null is valid // 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) { if (result.value[i] == 0) {
result.value = ByteUtil.substring(result.value, 0, i); result.value = ByteUtil.substring(result.value, 0, i);
break; break;

View file

@ -1,10 +1,10 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble; package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble;
import java.util.ArrayList;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil; import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC; import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC;
@ -13,17 +13,18 @@ import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC;
*/ */
public class RFTools { 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 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 * CodeSymbols is an ordered list of translations
6bits -> 4 bits, in order from 0x0 to 0xF * 6bits -> 4 bits, in order from 0x0 to 0xF
The 6 bit codes are what is used on the RF side of the RileyLink * The 6 bit codes are what is used on the RF side of the RileyLink
to communicate with a Medtronic pump. * 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) { public static byte[] appendChecksum(final byte[] input) {
@ -36,15 +37,51 @@ public class RFTools {
byte[] rval = new byte[input.length + 1]; byte[] rval = new byte[input.length + 1];
System.arraycopy(input, 0, rval, 0, input.length); System.arraycopy(input, 0, rval, 0, input.length);
byte mycrc = CRC.crc8(input); 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; rval[input.length] = mycrc;
return rval; 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) { public static ArrayList<Byte> fromBytes(byte[] data) {
ArrayList<Byte> rval = new ArrayList<>(); 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]); rval.add(data[i]);
} }
return rval; return rval;
@ -53,53 +90,16 @@ public class RFTools {
public static byte[] toBytes(ArrayList<Byte> data) { public static byte[] toBytes(ArrayList<Byte> data) {
byte[] rval = new byte[data.size()]; 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); rval[i] = data.get(i);
} }
return rval; 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; /* O(n) lookup. Run on an O(n) translation of a byte-stream, gives O(n**2) performance. Sigh. */
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. */
public static int codeIndex(byte b) { 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]) { if (b == codes[i]) {
return i; return i;
} }
@ -119,7 +119,7 @@ public class RFTools {
int acc = 0; int acc = 0;
int bitcount = 0; int bitcount = 0;
int i; int i;
for(i = 0; i < inData.size(); i++) { for (i = 0; i < inData.size(); i++) {
acc <<= 6; acc <<= 6;
acc |= codes[(inData.get(i) >> 4) & 0x0f]; acc |= codes[(inData.get(i) >> 4) & 0x0f];
bitcount += 6; bitcount += 6;
@ -129,7 +129,7 @@ public class RFTools {
bitcount += 6; bitcount += 6;
while (bitcount >= 8) { while (bitcount >= 8) {
byte outByte = (byte) (acc >> (bitcount - 8) & 0xff); byte outByte = (byte)(acc >> (bitcount - 8) & 0xff);
outData.add(outByte); outData.add(outByte);
bitcount -= 8; bitcount -= 8;
acc &= (0xffff >> (16 - bitcount)); acc &= (0xffff >> (16 - bitcount));
@ -140,18 +140,17 @@ public class RFTools {
acc |= 0x14; // marks uneven packet boundary. acc |= 0x14; // marks uneven packet boundary.
bitcount += 6; bitcount += 6;
if (bitcount >= 8) { if (bitcount >= 8) {
byte outByte = (byte) ((acc >> (bitcount - 8)) & 0xff); byte outByte = (byte)((acc >> (bitcount - 8)) & 0xff);
outData.add(outByte); outData.add(outByte);
bitcount -= 8; bitcount -= 8;
// acc &= (0xffff >> (16 - bitcount)); // acc &= (0xffff >> (16 - bitcount));
} }
while (bitcount >= 8) { while (bitcount >= 8) {
outData.add((byte) 0); outData.add((byte)0);
bitcount -= 8; bitcount -= 8;
} }
} }
// convert back to byte[] // convert back to byte[]
byte[] rval = toBytes(outData); byte[] rval = toBytes(outData);
@ -162,14 +161,14 @@ public class RFTools {
public static void test() { public static void test() {
/* /*
{0xa7} -> {0xa9, 0x60} * {0xa7} -> {0xa9, 0x60}
{0xa7, 0x12} -> {0xa9, 0x6c, 0x72} * {0xa7, 0x12} -> {0xa9, 0x6c, 0x72}
{0xa7, 0x12, 0xa7} -> {0xa9, 0x6c, 0x72, 0xa9, 0x60} * {0xa7, 0x12, 0xa7} -> {0xa9, 0x6c, 0x72, 0xa9, 0x60}
*/ */
/* test compare */ /* test compare */
byte[] s1 = {0, 1, 2}; byte[] s1 = { 0, 1, 2 };
byte[] s2 = {2, 1, 0, 3}; byte[] s2 = { 2, 1, 0, 3 };
byte[] s3 = {0, 1, 2, 3}; byte[] s3 = { 0, 1, 2, 3 };
if (ByteUtil.compare(s1, s1) != 0) { if (ByteUtil.compare(s1, s1) != 0) {
LOG.error("test: compare failed."); LOG.error("test: compare failed.");
} }
@ -182,21 +181,24 @@ public class RFTools {
if (ByteUtil.compare(s1, s3) >= 0) { if (ByteUtil.compare(s1, s3) >= 0) {
LOG.error("test: compare failed."); LOG.error("test: compare failed.");
} }
//testCompose(new byte[] {(byte)0xa7, (byte)0xa7}); // testCompose(new byte[] {(byte)0xa7, (byte)0xa7});
byte[] bs = encode4b6b(new byte[]{(byte) 0xa7}); byte[] bs = encode4b6b(new byte[] { (byte)0xa7 });
byte[] out = new byte[]{(byte) (0xa9), 0x65}; byte[] out = new byte[] { (byte)(0xa9), 0x65 };
if (ByteUtil.compare(bs, out) != 0) { 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}); bs = encode4b6b(new byte[] { (byte)0xa7, 0x12 });
out = new byte[]{(byte) (0xa9), 0x6c, 0x72}; out = new byte[] { (byte)(0xa9), 0x6c, 0x72 };
if (ByteUtil.compare(bs, out) != 0) { 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}); bs = encode4b6b(new byte[] { (byte)0xa7, 0x12, (byte)0xa7 });
out = new byte[]{(byte) (0xa9), 0x6c, 0x72, (byte) 0xa9, 0x65}; out = new byte[] { (byte)(0xa9), 0x6c, 0x72, (byte)0xa9, 0x65 };
if (ByteUtil.compare(bs, out) != 0) { 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; return;
} }
@ -204,17 +206,17 @@ public class RFTools {
public static byte[] decode4b6b(byte[] raw) throws NumberFormatException { public static byte[] decode4b6b(byte[] raw) throws NumberFormatException {
/* /*
if ((raw.length % 2) != 0) { * if ((raw.length % 2) != 0) {
LOG.error("Warning: data is odd number of bytes"); * LOG.error("Warning: data is odd number of bytes");
} * }
*/ */
byte[] rval = new byte[]{}; byte[] rval = new byte[] {};
int availableBits = 0; int availableBits = 0;
int codingErrors = 0; int codingErrors = 0;
int x = 0; int x = 0;
//Log.w(TAG,"decode4b6b: untested code"); // Log.w(TAG,"decode4b6b: untested code");
//Log.w(TAG,String.format("Decoding %d bytes: %s",raw.length,ByteUtil.shortHexString(raw))); // Log.w(TAG,String.format("Decoding %d bytes: %s",raw.length,ByteUtil.shortHexString(raw)));
for(int i = 0; i < raw.length; i++) { for (int i = 0; i < raw.length; i++) {
int unsignedValue = raw[i]; int unsignedValue = raw[i];
if (unsignedValue < 0) { if (unsignedValue < 0) {
unsignedValue += 256; unsignedValue += 256;
@ -224,27 +226,31 @@ public class RFTools {
if (availableBits >= 12) { if (availableBits >= 12) {
// take top six // take top six
int highcode = (x >> (availableBits - 6)) & 0x3F; int highcode = (x >> (availableBits - 6)) & 0x3F;
int highIndex = codeIndex((byte) (highcode)); int highIndex = codeIndex((byte)(highcode));
// take bottom six // take bottom six
int lowcode = (x >> (availableBits - 12)) & 0x3F; 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: // special case at end of transmission on uneven boundaries:
if ((highIndex >= 0) && (lowIndex >= 0)) { if ((highIndex >= 0) && (lowIndex >= 0)) {
byte decoded = (byte) ((highIndex << 4) + lowIndex); byte decoded = (byte)((highIndex << 4) + lowIndex);
rval = ByteUtil.concat(rval, decoded); 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", * LOG.debug(String.format(
i,x,highcode,highIndex, lowcode, lowIndex,decoded,availableBits,codingErrors,ByteUtil.shortHexString(ByteUtil.substring(raw,i+1,raw.length-i-1)))); * "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 { } 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++; codingErrors++;
} }
availableBits -= 12; availableBits -= 12;
x = x & (0x0000ffff >> (16 - availableBits)); x = x & (0x0000ffff >> (16 - availableBits));
} else { } 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) { 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) { public static String toHexString(byte[] array, int offset, int length) {
char[] buf = new char[length * 2]; char[] buf = new char[length * 2];
int bufIndex = 0; int bufIndex = 0;
for(int i = offset; i < offset + length; i++) { for (int i = offset; i < offset + length; i++) {
byte b = array[i]; byte b = array[i];
buf[bufIndex++] = HEX_DIGITS[(b >>> 4) & 0x0F]; buf[bufIndex++] = HEX_DIGITS[(b >>> 4) & 0x0F];
buf[bufIndex++] = HEX_DIGITS[b & 0x0F]; buf[bufIndex++] = HEX_DIGITS[b & 0x0F];
@ -286,5 +289,4 @@ public class RFTools {
return new String(buf); return new String(buf);
} }
} }

View file

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

View file

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

View file

@ -10,7 +10,7 @@ import java.util.UUID;
public class GattAttributes { public class GattAttributes {
// NOTE: these uuid strings must be lower case! // NOTE: these uuid strings must be lower case!
public static String PREFIX = "0000"; public static String PREFIX = "0000";
public static String SUFFIX = "-0000-1000-8000-00805f9b34fb"; public static String SUFFIX = "-0000-1000-8000-00805f9b34fb";
public static String SERVICE_GAP = PREFIX + "1800" + SUFFIX; public static String SERVICE_GAP = PREFIX + "1800" + SUFFIX;
@ -41,7 +41,6 @@ public class GattAttributes {
attributes.put(CHARA_GAP_NAME, "Name"); // attributes.put(CHARA_GAP_NAME, "Name"); //
attributes.put(CHARA_GAP_NUM, "Number"); // attributes.put(CHARA_GAP_NUM, "Number"); //
attributes.put(SERVICE_BATTERY, "Battery Service"); attributes.put(SERVICE_BATTERY, "Battery Service");
attributes.put(SERVICE_RADIO, "Radio Interface"); // a attributes.put(SERVICE_RADIO, "Radio Interface"); // a
@ -85,5 +84,4 @@ public class GattAttributes {
return attributesRileyLinkSpecific.containsKey(uuid.toString()); 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. * Created by geoff on 5/26/16.
*/ */
public class RFSpyResponse { public class RFSpyResponse {
// 0xaa == timeout // 0xaa == timeout
// 0xbb == interrupted // 0xbb == interrupted
// 0xcc == zero-data // 0xcc == zero-data
@ -53,7 +54,7 @@ public class RFSpyResponse {
public boolean wasTimeout() { public boolean wasTimeout() {
if ((raw.length == 1) || (raw.length == 2)) { if ((raw.length == 1) || (raw.length == 2)) {
if (raw[0] == (byte) 0xaa) { if (raw[0] == (byte)0xaa) {
return true; return true;
} }
} }
@ -63,7 +64,7 @@ public class RFSpyResponse {
public boolean wasInterrupted() { public boolean wasInterrupted() {
if ((raw.length == 1) || (raw.length == 2)) { if ((raw.length == 1) || (raw.length == 2)) {
if (raw[0] == (byte) 0xbb) { if (raw[0] == (byte)0xbb) {
return true; return true;
} }
} }
@ -73,7 +74,7 @@ public class RFSpyResponse {
public boolean isOK() { public boolean isOK() {
if ((raw.length == 1) || (raw.length == 2)) { if ((raw.length == 1) || (raw.length == 2)) {
if (raw[0] == (byte) 0x01) { if (raw[0] == (byte)0x01) {
return true; return true;
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,10 +1,10 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations; package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations;
import android.bluetooth.BluetoothGatt;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import android.bluetooth.BluetoothGatt;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE;
/** /**
@ -18,16 +18,20 @@ public abstract class BLECommOperation {
protected BluetoothGatt gatt; protected BluetoothGatt gatt;
protected Semaphore operationComplete = new Semaphore(0, true); protected Semaphore operationComplete = new Semaphore(0, true);
// This is to be run on the main thread // This is to be run on the main thread
public abstract void execute(RileyLinkBLE comm); public abstract void execute(RileyLinkBLE comm);
public void gattOperationCompletionCallback(UUID uuid, byte[] value) { public void gattOperationCompletionCallback(UUID uuid, byte[] value) {
} }
public int getGattOperationTimeout_ms() { public int getGattOperationTimeout_ms() {
return 22000; return 22000;
} }
public byte[] getValue() { public byte[] getValue() {
return value; 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. * Created by geoff on 5/26/16.
*/ */
public class BLECommOperationResult { public class BLECommOperationResult {
public byte[] value;
public int resultCode;
public static final int RESULT_NONE = 0; public static final int RESULT_NONE = 0;
public static final int RESULT_SUCCESS = 1; 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_BUSY = 3;
public static final int RESULT_INTERRUPTED = 4; public static final int RESULT_INTERRUPTED = 4;
public static final int RESULT_NOT_CONFIGURED = 5; 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; package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations;
import android.bluetooth.BluetoothGatt; import java.util.UUID;
import android.bluetooth.BluetoothGattCharacteristic; import java.util.concurrent.TimeUnit;
import android.os.SystemClock;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.UUID; import android.bluetooth.BluetoothGatt;
import java.util.concurrent.TimeUnit; 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.RileyLinkBLE;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.GattAttributes; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.GattAttributes;
@ -22,11 +22,13 @@ public class CharacteristicReadOperation extends BLECommOperation {
private BluetoothGattCharacteristic characteristic; private BluetoothGattCharacteristic characteristic;
public CharacteristicReadOperation(BluetoothGatt gatt, BluetoothGattCharacteristic chara) { public CharacteristicReadOperation(BluetoothGatt gatt, BluetoothGattCharacteristic chara) {
this.gatt = gatt; this.gatt = gatt;
this.characteristic = chara; this.characteristic = chara;
} }
@Override @Override
public void execute(RileyLinkBLE comm) { public void execute(RileyLinkBLE comm) {
gatt.readCharacteristic(characteristic); gatt.readCharacteristic(characteristic);
@ -34,7 +36,8 @@ public class CharacteristicReadOperation extends BLECommOperation {
try { try {
boolean didAcquire = operationComplete.tryAcquire(getGattOperationTimeout_ms(), TimeUnit.MILLISECONDS); boolean didAcquire = operationComplete.tryAcquire(getGattOperationTimeout_ms(), TimeUnit.MILLISECONDS);
if (didAcquire) { 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 // success
} else { } else {
LOG.error("Timeout waiting for gatt write operation to complete"); LOG.error("Timeout waiting for gatt write operation to complete");
@ -47,15 +50,16 @@ public class CharacteristicReadOperation extends BLECommOperation {
value = characteristic.getValue(); value = characteristic.getValue();
} }
@Override @Override
public void gattOperationCompletionCallback(UUID uuid, byte[] value) { public void gattOperationCompletionCallback(UUID uuid, byte[] value) {
super.gattOperationCompletionCallback(uuid, value); super.gattOperationCompletionCallback(uuid, value);
if (!characteristic.getUuid().equals(uuid)) { if (!characteristic.getUuid().equals(uuid)) {
LOG.error(String.format("Completion callback: UUID does not match! out of sequence? Found: %s, should be %s", LOG.error(String.format(
GattAttributes.lookup(characteristic.getUuid()), GattAttributes.lookup(uuid))); "Completion callback: UUID does not match! out of sequence? Found: %s, should be %s",
GattAttributes.lookup(characteristic.getUuid()), GattAttributes.lookup(uuid)));
} }
operationComplete.release(); operationComplete.release();
} }
} }

View file

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

View file

@ -1,14 +1,14 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations; package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations;
import android.bluetooth.BluetoothGatt; import java.util.UUID;
import android.bluetooth.BluetoothGattDescriptor; import java.util.concurrent.TimeUnit;
import android.os.SystemClock;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.UUID; import android.bluetooth.BluetoothGatt;
import java.util.concurrent.TimeUnit; import android.bluetooth.BluetoothGattDescriptor;
import android.os.SystemClock;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE;
@ -28,12 +28,14 @@ public class DescriptorWriteOperation extends BLECommOperation {
this.value = value; this.value = value;
} }
@Override @Override
public void gattOperationCompletionCallback(UUID uuid, byte[] value) { public void gattOperationCompletionCallback(UUID uuid, byte[] value) {
super.gattOperationCompletionCallback(uuid, value); super.gattOperationCompletionCallback(uuid, value);
operationComplete.release(); operationComplete.release();
} }
@Override @Override
public void execute(RileyLinkBLE comm) { public void execute(RileyLinkBLE comm) {
descr.setValue(value); descr.setValue(value);
@ -42,7 +44,8 @@ public class DescriptorWriteOperation extends BLECommOperation {
try { try {
boolean didAcquire = operationComplete.tryAcquire(getGattOperationTimeout_ms(), TimeUnit.MILLISECONDS); boolean didAcquire = operationComplete.tryAcquire(getGattOperationTimeout_ms(), TimeUnit.MILLISECONDS);
if (didAcquire) { 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 // success
} else { } else {
LOG.error("Timeout waiting for descriptor write operation to complete"); 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 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.RileyLinkError;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkServiceState; 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. * Created by andy on 5/19/18.
@ -11,15 +15,38 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLink
public class RLHistoryItem { public class RLHistoryItem {
private MedtronicCommandType medtronicCommandType;
private LocalDateTime dateTime; private LocalDateTime dateTime;
private RLHistoryItemSource source;
private RileyLinkServiceState serviceState; private RileyLinkServiceState serviceState;
private RileyLinkError errorCode; 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.dateTime = new LocalDateTime();
this.serviceState = serviceState; this.serviceState = serviceState;
this.errorCode = errorCode; 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() { public RileyLinkError getErrorCode() {
return errorCode; 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 // Configuration
// BT // BT
NoBluetoothAdapter(R.string.rileylink_error_no_bt_adapter), // NoBluetoothAdapter(R.string.rileylink_error_no_bt_adapter), //
BluetoothDisabled(R.string.rileylink_error_bt_disabled), // 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), // NoContactWithDevice(R.string.rileylink_error_pump_unreachable, R.string.rileylink_error_pod_unreachable), //
; ;
int resourceId; int resourceId;
Integer resourceIdPod; Integer resourceIdPod;
RileyLinkError(int resourceId) { RileyLinkError(int resourceId) {
this.resourceId = resourceId; this.resourceId = resourceId;
} }
@ -43,7 +42,8 @@ public enum RileyLinkError {
if (this.resourceIdPod != null) { if (this.resourceIdPod != null) {
return targetDevice == RileyLinkTargetDevice.MedtronicPump ? // return targetDevice == RileyLinkTargetDevice.MedtronicPump ? //
this.resourceId : this.resourceIdPod; this.resourceId
: this.resourceIdPod;
} else { } else {
return this.resourceId; return this.resourceId;
} }

View file

@ -11,78 +11,84 @@ public enum RileyLinkServiceState {
NotStarted(R.string.rileylink_state_not_started), // NotStarted(R.string.rileylink_state_not_started), //
// Bluetooth // Bluetooth
BluetoothInitializing(R.string.rileylink_state_bt_init), // (S) init BT (if error no BT interface -> Disabled, BT not enabled -> BluetoothError) BluetoothInitializing(R.string.rileylink_state_bt_init), // (S) init BT (if error no BT interface -> Disabled, BT
//BluetoothNotAvailable, // (E) BT not available, would happen only if device has no 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) BluetoothError(R.string.rileylink_state_bt_error), // (E) if BT gets disabled ( -> EnableBluetooth)
BluetoothReady(R.string.rileylink_state_bt_ready), // (OK) BluetoothReady(R.string.rileylink_state_bt_ready), // (OK)
// RileyLink // 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) RileyLinkError(R.string.rileylink_state_rl_error), // (E)
RileyLinkReady(R.string.rileylink_state_connected), // (OK) if tunning was already done we go to PumpConnectorReady RileyLinkReady(R.string.rileylink_state_connected), // (OK) if tunning was already done we go to PumpConnectorReady
// Tunning // Tunning
TuneUpDevice(R.string.rileylink_state_pc_tune_up), // (S) 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 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) // RileyLinkConnected, // -> TuneUpPump (on 1st), else PumpConnectorReady
//BlueToothEnabled, // -> InitializeRileyLink
//RileyLinkInitialized, //
//RileyLinkConnected, // -> TuneUpPump (on 1st), else PumpConnectorReady
//PumpConnected, //
// PumpConnected, //
; ;
int resourceId; int resourceId;
Integer resourceIdPod; Integer resourceIdPod;
RileyLinkServiceState(int resourceId) { RileyLinkServiceState(int resourceId) {
this.resourceId = resourceId; this.resourceId = resourceId;
} }
RileyLinkServiceState(int resourceId, int resourceIdPod) { RileyLinkServiceState(int resourceId, int resourceIdPod) {
this.resourceId = resourceId; this.resourceId = resourceId;
this.resourceIdPod = resourceIdPod; this.resourceIdPod = resourceIdPod;
} }
public static boolean isReady(RileyLinkServiceState serviceState) {
return (serviceState == RileyLinkReady || serviceState == PumpConnectorReady);
}
public int getResourceId(RileyLinkTargetDevice targetDevice) { public int getResourceId(RileyLinkTargetDevice targetDevice) {
if (this.resourceIdPod != null) { if (this.resourceIdPod != null) {
return targetDevice == RileyLinkTargetDevice.MedtronicPump ? // return (targetDevice == null || targetDevice == RileyLinkTargetDevice.MedtronicPump) ? //
this.resourceId : this.resourceIdPod; this.resourceId
: this.resourceIdPod;
} else { } else {
return this.resourceId; return this.resourceId;
} }
} }
public static boolean isReady(RileyLinkServiceState serviceState) {
return (serviceState == RileyLinkReady || serviceState == PumpConnectorReady);
}
public boolean isConnecting() { public boolean isConnecting() {
return (this == RileyLinkServiceState.BluetoothInitializing || // return (this == RileyLinkServiceState.BluetoothInitializing || //
//this == RileyLinkServiceState.BluetoothError || // // this == RileyLinkServiceState.BluetoothError || //
this == RileyLinkServiceState.BluetoothReady || // this == RileyLinkServiceState.BluetoothReady || //
this == RileyLinkServiceState.RileyLinkInitializing // this == RileyLinkServiceState.RileyLinkInitializing //
//this == RileyLinkServiceState.RileyLinkError // this == RileyLinkServiceState.RileyLinkError
); );
} }
public boolean isError() { public boolean isError() {
return ( return (this == RileyLinkServiceState.BluetoothError || //
this == RileyLinkServiceState.BluetoothError || // // this == RileyLinkServiceState.PumpConnectorError || //
//this == RileyLinkServiceState.PumpConnectorError || // this == RileyLinkServiceState.RileyLinkError);
this == RileyLinkServiceState.RileyLinkError);
} }
} }

View file

@ -1,22 +1,33 @@
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs; package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs;
import info.nightscout.androidaps.R;
/** /**
* Created by andy on 5/19/18. * Created by andy on 5/19/18.
*/ */
public enum RileyLinkTargetDevice { public enum RileyLinkTargetDevice {
MedtronicPump(true), // MedtronicPump(R.string.rileylink_target_device_medtronic, true), //
Omnipod(false), // Omnipod(R.string.rileylink_target_device_omnipod, false), //
; ;
private int resourceId;
private boolean tuneUpEnabled; private boolean tuneUpEnabled;
RileyLinkTargetDevice(boolean tuneUpEnabled) {
RileyLinkTargetDevice(int resourceId, boolean tuneUpEnabled) {
this.resourceId = resourceId;
this.tuneUpEnabled = tuneUpEnabled; this.tuneUpEnabled = tuneUpEnabled;
} }
public boolean isTuneUpEnabled() { public boolean isTuneUpEnabled() {
return tuneUpEnabled; 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.os.Bundle;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
@ -11,17 +14,14 @@ import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView; import butterknife.BindView;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; 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.RileyLinkUtil;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.RileyLinkServiceData; 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) @BindView(R.id.rls_t1_connection_status)
TextView connectionStatus; TextView connectionStatus;
@ -34,79 +34,74 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
@BindView(R.id.rls_t1_connection_error) @BindView(R.id.rls_t1_connection_error)
TextView connectionError; TextView connectionError;
RileyLinkServiceData rileyLinkServiceData;
/** /**
* The {@link android.support.v4.view.PagerAdapter} that will provide * The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a * fragments for each of the sections. We use a {@link FragmentPagerAdapter} derivative, which will keep every
* {@link FragmentPagerAdapter} derivative, which will keep every
* loaded fragment in memory. If this becomes too memory intensive, it * loaded fragment in memory. If this becomes too memory intensive, it
* may be best to switch to a * may be best to switch to a {@link android.support.v4.app.FragmentStatePagerAdapter}.
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/ */
private SectionsPagerAdapter mSectionsPagerAdapter; private SectionsPagerAdapter mSectionsPagerAdapter;
private FloatingActionButton floatingActionButton; private FloatingActionButton floatingActionButton;
private TabLayout tabLayout; private TabLayout tabLayout;
RileyLinkServiceData rileyLinkServiceData;
/** /**
* The {@link ViewPager} that will host the section contents. * The {@link ViewPager} that will host the section contents.
*/ */
private ViewPager mViewPager; private ViewPager mViewPager;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(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 // Create the adapter that will return a fragment for each of the three
// primary sections of the activity. // primary sections of the activity.
// Set up the ViewPager with the sections adapter. // Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.rileylink_settings_container); mViewPager = (ViewPager)findViewById(R.id.rileylink_settings_container);
//mViewPager.setAdapter(mSectionsPagerAdapter); // mViewPager.setAdapter(mSectionsPagerAdapter);
setupViewPager(mViewPager); setupViewPager(mViewPager);
tabLayout = (TabLayout) findViewById(R.id.rileylink_settings_tabs); tabLayout = (TabLayout)findViewById(R.id.rileylink_settings_tabs);
tabLayout.setupWithViewPager(mViewPager); tabLayout.setupWithViewPager(mViewPager);
floatingActionButton = (FloatingActionButton)findViewById(R.id.rileylink_settings_fab);
floatingActionButton = (FloatingActionButton) findViewById(R.id.rileylink_settings_fab);
floatingActionButton.setOnClickListener(new View.OnClickListener() { floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
RefreshableInterface selectableInterface = (RefreshableInterface) mSectionsPagerAdapter.getItem(tabLayout.getSelectedTabPosition()); RefreshableInterface selectableInterface = (RefreshableInterface)mSectionsPagerAdapter
.getItem(tabLayout.getSelectedTabPosition());
selectableInterface.refreshData(); 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.connectionStatus = (TextView)findViewById(R.id.rls_t1_connection_status);
this.configuredAddress = (TextView) findViewById(R.id.rls_t1_configured_address); this.configuredAddress = (TextView)findViewById(R.id.rls_t1_configured_address);
this.connectedDevice = (TextView) findViewById(R.id.rls_t1_connected_device); this.connectedDevice = (TextView)findViewById(R.id.rls_t1_connected_device);
this.connectionError = (TextView) findViewById(R.id.rls_t1_connection_error); this.connectionError = (TextView)findViewById(R.id.rls_t1_connection_error);
rileyLinkServiceData = RileyLinkUtil.getRileyLinkServiceData(); rileyLinkServiceData = RileyLinkUtil.getRileyLinkServiceData();
// // 7-12 // // 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, // // 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}; // 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) { // for (int id : ids) {
// //
// TextView tv = (TextView) findViewById(id); // TextView tv = (TextView) findViewById(id);
// tv.setText(tv.getText() + ":"); // tv.setText(tv.getText() + ":");
// } // }
//refreshData(0); // refreshData(0);
//refreshData(1); // 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 = new SectionsPagerAdapter(getSupportFragmentManager());
mSectionsPagerAdapter.addFragment(new RileyLinkSettingsTab1(), MainApp.gs(R.string.rileylink_settings_tab1)); mSectionsPagerAdapter.addFragment(new RileyLinkStatusGeneral(), MainApp.gs(R.string.rileylink_settings_tab1));
mSectionsPagerAdapter.addFragment(new RileyLinkSettingsTab2(), MainApp.gs(R.string.rileylink_settings_tab2)); mSectionsPagerAdapter.addFragment(new RileyLinkStatusHistory(), MainApp.gs(R.string.rileylink_settings_tab2));
//mSectionsPagerAdapter.addFragment(new RileyLinkSettingsTab3(), "Tab 3"); // mSectionsPagerAdapter.addFragment(new RileyLinkSettingsTab3(), "Tab 3");
mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setAdapter(mSectionsPagerAdapter);
} }
/** /**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages. * one of the sections/tabs/pages.
@ -150,6 +143,7 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
List<String> fragmentTitle = new ArrayList<>(); List<String> fragmentTitle = new ArrayList<>();
int lastSelectedPosition = 0; int lastSelectedPosition = 0;
public SectionsPagerAdapter(FragmentManager fm) { public SectionsPagerAdapter(FragmentManager fm) {
super(fm); super(fm);
} }
@ -161,17 +155,20 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
return fragmentList.get(position); return fragmentList.get(position);
} }
@Override @Override
public int getCount() { public int getCount() {
// Show 3 total pages. // Show 3 total pages.
return fragmentList.size(); return fragmentList.size();
} }
public void addFragment(Fragment fragment, String title) { public void addFragment(Fragment fragment, String title) {
this.fragmentList.add(fragment); this.fragmentList.add(fragment);
this.fragmentTitle.add(title); this.fragmentTitle.add(title);
} }
@Override @Override
public CharSequence getPageTitle(int position) { public CharSequence getPageTitle(int position) {
return fragmentTitle.get(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; 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.app.Service;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@ -9,9 +14,6 @@ import android.content.IntentFilter;
import android.os.PowerManager; import android.os.PowerManager;
import android.support.v4.content.LocalBroadcastManager; 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.RileyLinkCommunicationManager;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkConst; 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.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.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.ServiceTaskExecutor;
import info.nightscout.utils.SP; 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.; //import static info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.;
/** /**
* Created by andy on 5/6/18. * Created by andy on 5/6/18.
* Split from original file and renamed. * Split from original file and renamed.
*/ */
public abstract class RileyLinkService extends Service { public abstract class RileyLinkService extends Service {
protected static final String WAKELOCKNAME = "com.gxwtech.roundtrip2.RoundtripServiceWakeLock";
private static final Logger LOG = LoggerFactory.getLogger(RileyLinkService.class); private static final Logger LOG = LoggerFactory.getLogger(RileyLinkService.class);
protected static volatile PowerManager.WakeLock lockStatic = null;
protected BluetoothAdapter bluetoothAdapter;
// Our hardware/software connection // Our hardware/software connection
public RileyLinkBLE rileyLinkBLE; // android-bluetooth management public RileyLinkBLE rileyLinkBLE; // android-bluetooth management
protected BluetoothAdapter bluetoothAdapter;
protected RFSpy rfspy; // interface for RL xxx Mhz radio. protected RFSpy rfspy; // interface for RL xxx Mhz radio.
//protected boolean needBluetoothPermission = true; // protected boolean needBluetoothPermission = true;
//protected RileyLinkIPCConnection rileyLinkIPCConnection; // protected RileyLinkIPCConnection rileyLinkIPCConnection;
protected Context context; protected Context context;
//public RileyLinkCommunicationManager pumpCommunicationManager; // public RileyLinkCommunicationManager pumpCommunicationManager;
protected BroadcastReceiver mBroadcastReceiver; protected BroadcastReceiver mBroadcastReceiver;
protected RileyLinkServiceData rileyLinkServiceData; protected RileyLinkServiceData rileyLinkServiceData;
protected RileyLinkTargetFrequency rileyLinkTargetFrequency; protected RileyLinkTargetFrequency rileyLinkTargetFrequency;
protected static final String WAKELOCKNAME = "com.gxwtech.roundtrip2.RoundtripServiceWakeLock";
protected static volatile PowerManager.WakeLock lockStatic = null;
public RileyLinkService(Context context) { public RileyLinkService(Context context) {
super(); super();
@ -116,16 +110,17 @@ public abstract class RileyLinkService extends Service {
super.onCreate(); super.onCreate();
LOG.debug("onCreate"); LOG.debug("onCreate");
//rileyLinkIPCConnection = new RileyLinkIPCConnection(context); // TODO We might be able to remove this -- Andy // rileyLinkIPCConnection = new RileyLinkIPCConnection(context); // TODO We might be able to remove this -- Andy
//RileyLinkUtil.setRileyLinkIPCConnection(rileyLinkIPCConnection); // RileyLinkUtil.setRileyLinkIPCConnection(rileyLinkIPCConnection);
mBroadcastReceiver = new BroadcastReceiver() { mBroadcastReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { 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) { if (intent == null) {
LOG.error("onReceive: received null intent"); LOG.error("onReceive: received null intent");
} else { } else {
@ -135,18 +130,22 @@ public abstract class RileyLinkService extends Service {
} else { } else {
if (action.equals(RileyLinkConst.Intents.BluetoothConnected)) { 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()); ServiceTaskExecutor.startTask(new DiscoverGattServicesTask());
} else if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnected)) { } else if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnected)) {
if (bluetoothAdapter.isEnabled()) { if (bluetoothAdapter.isEnabled()) {
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothReady, RileyLinkError.RileyLinkUnreachable); RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothReady,
RileyLinkError.RileyLinkUnreachable);
} else { } else {
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled); RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError,
RileyLinkError.BluetoothDisabled);
} }
} else if (action.equals(RileyLinkConst.Intents.RileyLinkReady)) { } else if (action.equals(RileyLinkConst.Intents.RileyLinkReady)) {
LOG.warn("MedtronicConst.Intents.RileyLinkReady"); LOG.warn("MedtronicConst.Intents.RileyLinkReady");
// FIXME // FIXME
//rileyLinkIPCConnection.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_note_WakingPump), null); // rileyLinkIPCConnection.sendNotification(new
// ServiceNotification(RT2Const.IPC.MSG_note_WakingPump), null);
rileyLinkBLE.enableNotifications(); rileyLinkBLE.enableNotifications();
rfspy.startReader(); // call startReader from outside? rfspy.startReader(); // call startReader from outside?
@ -163,7 +162,8 @@ public abstract class RileyLinkService extends Service {
LOG.info("Announcing RileyLink open For business"); LOG.info("Announcing RileyLink open For business");
} else if (action.equals(RileyLinkConst.Intents.BluetoothReconnected)) { } else if (action.equals(RileyLinkConst.Intents.BluetoothReconnected)) {
LOG.debug("Reconnecting Bluetooth"); 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(); bluetoothInit();
ServiceTaskExecutor.startTask(new DiscoverGattServicesTask(true)); ServiceTaskExecutor.startTask(new DiscoverGattServicesTask(true));
} else if (action.equals(RileyLinkConst.IPC.MSG_PUMP_tunePump)) { } else if (action.equals(RileyLinkConst.IPC.MSG_PUMP_tunePump)) {
@ -183,56 +183,56 @@ public abstract class RileyLinkService extends Service {
if (RileylinkBLEAddress.equals("")) { if (RileylinkBLEAddress.equals("")) {
LOG.error("No Rileylink BLE Address saved in app"); LOG.error("No Rileylink BLE Address saved in app");
} else { } else {
//showBusy("Configuring Service", 50); // showBusy("Configuring Service", 50);
//rileyLinkBLE.findRileyLink(RileylinkBLEAddress); // rileyLinkBLE.findRileyLink(RileylinkBLEAddress);
reconfigureRileyLink(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
/*else if (RT2Const.serviceLocal.INTENT_sessionCompleted.equals(action)) { *
Bundle bundle = intent.getBundleExtra(RT2Const.IPC.bundleKey); * if (case RT2Const.local.INTENT_serviceConnected:
if (bundle != null) { * case RT2Const.local.INTENT_NEW_rileylinkAddressKey:
ServiceTransport transport = new ServiceTransport(bundle); * showIdle();
//rileyLinkIPCConnection.sendTransport(transport, transport.getSenderHashcode()); * /**
//RileyLinkUtil.send * Client MUST send a "UseThisRileylink" message because it asserts that
} else { * the user has given explicit permission to use bluetooth.
LOG.error("sessionCompleted: no bundle!"); *
} * 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
/*else * come from an Activity.
*/
if (case RT2Const.local.INTENT_serviceConnected: /*
case RT2Const.local.INTENT_NEW_rileylinkAddressKey: * String RileylinkBLEAddress = SP.getString(MedtronicConst.Prefs.RileyLinkAddress, "");
showIdle(); * if (RileylinkBLEAddress.equals("")) {
/** * // TODO: 11/07/2016 @TIM UI message for user
* Client MUST send a "UseThisRileylink" message because it asserts that * Log.e(TAG, "No Rileylink BLE Address saved in app");
* the user has given explicit permission to use bluetooth. * } else {
* * //showBusy("Configuring Service", 50);
* We can change the format so that it is a simple "bluetooth OK" message, * MainApp.getServiceClientConnection().setThisRileylink(RileylinkBLEAddress);
* 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 * break;
* come from an Activity. * case RT2Const.local.INTENT_NEW_pumpIDKey:
*/ * MainApp.getServiceClientConnection().sendPUMP_useThisDevice(SP.getString(MedtronicConst.Prefs.
/* String RileylinkBLEAddress = SP.getString(MedtronicConst.Prefs.RileyLinkAddress, ""); * PumpSerial, ""));
if (RileylinkBLEAddress.equals("")) { * break;
// 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 { else {
LOG.error("Unhandled broadcast: action=" + action); 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.RileyLinkDisconnected);
intentFilter.addAction(RileyLinkConst.Intents.BluetoothReconnected); intentFilter.addAction(RileyLinkConst.Intents.BluetoothReconnected);
intentFilter.addAction(RileyLinkConst.Intents.RileyLinkNewAddressSet); intentFilter.addAction(RileyLinkConst.Intents.RileyLinkNewAddressSet);
//intentFilter.addAction(RT2Const.serviceLocal.ipcBound); // intentFilter.addAction(RT2Const.serviceLocal.ipcBound);
//intentFilter.addAction(RT2Const.IPC.MSG_BLE_accessGranted); // intentFilter.addAction(RT2Const.IPC.MSG_BLE_accessGranted);
//intentFilter.addAction(RT2Const.IPC.MSG_BLE_accessDenied); // intentFilter.addAction(RT2Const.IPC.MSG_BLE_accessDenied);
//intentFilter.addAction(RT2Const.IPC.MSG_BLE_useThisDevice); // intentFilter.addAction(RT2Const.IPC.MSG_BLE_useThisDevice);
intentFilter.addAction(RileyLinkConst.IPC.MSG_PUMP_tunePump); 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.IPC.MSG_ServiceCommand);
//intentFilter.addAction(RileyLinkConst.serviceLocal.INTENT_sessionCompleted); // intentFilter.addAction(RileyLinkConst.serviceLocal.INTENT_sessionCompleted);
addPumpSpecificIntents(intentFilter); addPumpSpecificIntents(intentFilter);
@ -268,10 +268,13 @@ public abstract class RileyLinkService extends Service {
public abstract RileyLinkCommunicationManager getDeviceCommunicationManager(); public abstract RileyLinkCommunicationManager getDeviceCommunicationManager();
public abstract void addPumpSpecificIntents(IntentFilter intentFilter); public abstract void addPumpSpecificIntents(IntentFilter intentFilter);
public abstract void handlePumpSpecificIntents(Intent intent); public abstract void handlePumpSpecificIntents(Intent intent);
public abstract void handleIncomingServiceTransport(Intent intent); public abstract void handleIncomingServiceTransport(Intent intent);
@ -280,24 +283,24 @@ public abstract class RileyLinkService extends Service {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
LOG.debug("onStartCommand"); LOG.debug("onStartCommand");
// if (intent != null) { // if (intent != null) {
// PowerManager.WakeLock lock = getLock(this.getApplicationContext()); // PowerManager.WakeLock lock = getLock(this.getApplicationContext());
// //
// if (!lock.isHeld() || (flags & START_FLAG_REDELIVERY) != 0) { // if (!lock.isHeld() || (flags & START_FLAG_REDELIVERY) != 0) {
// lock.acquire(); // lock.acquire();
// } // }
// //
// // This will end up running onHandleIntent // // This will end up running onHandleIntent
// super.onStartCommand(intent, flags, startId); // super.onStartCommand(intent, flags, startId);
// } else { // } else {
// LOG.error("Received null intent?"); // LOG.error("Received null intent?");
// } // }
RileyLinkUtil.setContext(getApplicationContext()); RileyLinkUtil.setContext(getApplicationContext());
//bluetoothInit(); // bluetoothInit();
//return (START_REDELIVER_INTENT | START_STICKY); // return (START_REDELIVER_INTENT | START_STICKY);
return (START_STICKY); return (START_STICKY);
} }
@ -339,22 +342,24 @@ public abstract class RileyLinkService extends Service {
LOG.info("No change to RL address. Not reconnecting."); LOG.info("No change to RL address. Not reconnecting.");
return false; return false;
} else { } 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(); rileyLinkBLE.disconnect();
// prolly need to shut down listening thread too? // prolly need to shut down listening thread too?
//SP.putString(MedtronicConst.Prefs.RileyLinkAddress, deviceAddress); // SP.putString(MedtronicConst.Prefs.RileyLinkAddress, deviceAddress);
rileyLinkServiceData.rileylinkAddress = deviceAddress; rileyLinkServiceData.rileylinkAddress = deviceAddress;
rileyLinkBLE.findRileyLink(rileyLinkServiceData.rileylinkAddress); rileyLinkBLE.findRileyLink(rileyLinkServiceData.rileylinkAddress);
return true; return true;
} }
} else { } 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); LOG.debug("handleIPCMessage: Using RL " + deviceAddress);
if (RileyLinkUtil.getServiceState() == RileyLinkServiceState.NotStarted) { if (RileyLinkUtil.getServiceState() == RileyLinkServiceState.NotStarted) {
if (!bluetoothInit()) { 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; 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) { public void sendServiceTransportResponse(ServiceTransport transport, ServiceResult serviceResult) {
// get the key (hashcode) of the client who requested this // get the key (hashcode) of the client who requested this
/*Integer clientHashcode = transport.getSenderHashcode(); /*
// make a new bundle to send as the message data * Integer clientHashcode = transport.getSenderHashcode();
transport.setServiceResult(serviceResult); * // make a new bundle to send as the message data
// FIXME * transport.setServiceResult(serviceResult);
transport.setTransportType(RT2Const.IPC.MSG_ServiceResult); */ * // FIXME
//rileyLinkIPCConnection.sendTransport(transport, clientHashcode); * transport.setTransportType(RT2Const.IPC.MSG_ServiceResult);
*/
// rileyLinkIPCConnection.sendTransport(transport, clientHashcode);
LOG.error("sendServiceTransportResponse not implemented."); LOG.error("sendServiceTransportResponse not implemented.");
} }
public boolean sendNotification(ServiceNotification notification, Integer clientHashcode) { public boolean sendNotification(ServiceNotification notification, Integer clientHashcode) {
//return rileyLinkIPCConnection.sendNotification(notification, clientHashcode); // return rileyLinkIPCConnection.sendNotification(notification, clientHashcode);
LOG.error("sendNotification not implemented."); LOG.error("sendNotification not implemented.");
return false; return false;
} }
@ -399,10 +406,10 @@ public abstract class RileyLinkService extends Service {
protected void sendBLERequestForAccess() { protected void sendBLERequestForAccess() {
// FIXME // FIXME
//serviceConnection.sendMessage(RT2Const.IPC.MSG_BLE_requestAccess); // serviceConnection.sendMessage(RT2Const.IPC.MSG_BLE_requestAccess);
//Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); // Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
//startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); // 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. // we have an old frequency, so let's start there.
newFrequency = getDeviceCommunicationManager().quickTuneForPump(lastGoodFrequency); newFrequency = getDeviceCommunicationManager().quickTuneForPump(lastGoodFrequency);
if (newFrequency == 0.0) { 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"); LOG.warn("Failed to find pump near last saved frequency, doing full scan");
newFrequency = getDeviceCommunicationManager().tuneForDevice(); newFrequency = getDeviceCommunicationManager().tuneForDevice();
} }
@ -447,7 +454,8 @@ public abstract class RileyLinkService extends Service {
if (newFrequency == 0.0d) { if (newFrequency == 0.0d) {
// error tuning pump, pump not present ?? // 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; 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.RileyLinkError;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkServiceState; 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. * Created by andy on 16/05/2018.

View file

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

View file

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

View file

@ -5,10 +5,10 @@ import android.os.Bundle;
/** /**
* Created by geoff on 7/6/16. * Created by geoff on 7/6/16.
* <p> * <p>
* These are "one liner" messages between client and service. * These are "one liner" messages between client and service. Must still be contained within ServiceTransports
* Must still be contained within ServiceTransports
*/ */
public class ServiceNotification extends ServiceMessage { public class ServiceNotification extends ServiceMessage {
public ServiceNotification() { public ServiceNotification() {
} }
@ -36,14 +36,13 @@ public class ServiceNotification extends ServiceMessage {
} }
public void setNotificationType(String notificationType) {
map.putString("NotificationType", notificationType);
}
public String getNotificationType() { public String getNotificationType() {
return map.getString("NotificationType", ""); 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. * Created by geoff on 6/25/16.
*/ */
public class ServiceResult extends ServiceMessage { 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() { public ServiceResult() {
init(); 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 @Override
public void init() { public void init() {
super.init(); super.init();
@ -29,13 +52,13 @@ public class ServiceResult extends ServiceMessage {
} }
public void setServiceResultType(String serviceResultType) { public String getServiceResultType() {
map.putString("ServiceResultType", serviceResultType); return map.getString("ServiceResultType", "ServiceResult");
} }
public String getServiceResultType() { public void setServiceResultType(String serviceResultType) {
return map.getString("ServiceResultType", "ServiceResult"); 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() { public boolean resultIsOK() {
return ("OK".equals(map.getString("result", ""))); return ("OK".equals(map.getString("result", "")));
} }
@ -92,5 +93,4 @@ public class ServiceResult extends ServiceMessage {
return map.getString("result", ""); return map.getString("result", "");
} }
} }

View file

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

View file

@ -12,10 +12,10 @@ import info.nightscout.utils.SP;
/** /**
* Created by geoff on 7/9/16. * Created by geoff on 7/9/16.
* <p> * <p>
* This class is intended to be run by the Service, for the Service. * This class is intended to be run by the Service, for the Service. Not intended for clients to run.
* Not intended for clients to run.
*/ */
public class InitializePumpManagerTask extends ServiceTask { public class InitializePumpManagerTask extends ServiceTask {
private static final String TAG = "InitPumpManagerTask"; private static final String TAG = "InitPumpManagerTask";
@ -35,7 +35,10 @@ public class InitializePumpManagerTask extends ServiceTask {
// FIXME // FIXME
double lastGoodFrequency = SP.getDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, 0.0d); 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)); Log.i(TAG, String.format("Setting radio frequency to %.2fMHz", lastGoodFrequency));
RileyLinkUtil.getRileyLinkCommunicationManager().setRadioFrequencyForPump(lastGoodFrequency); RileyLinkUtil.getRileyLinkCommunicationManager().setRadioFrequencyForPump(lastGoodFrequency);
@ -45,13 +48,14 @@ public class InitializePumpManagerTask extends ServiceTask {
// FIXME maybe remove in AAPS // FIXME maybe remove in AAPS
if (foundThePump) { if (foundThePump) {
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorReady); 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 { } else {
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.NoContactWithDevice); RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError,
//RileyLinkUtil.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_PUMP_pumpLost), null); 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 { } else {
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_tunePump); 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. * Created by geoff on 7/10/16.
*/ */
public class PumpTask extends ServiceTask { public class PumpTask extends ServiceTask {
public PumpTask() { public PumpTask() {
super(); 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. * Created by geoff on 7/9/16.
*/ */
public class ServiceTask implements Runnable { public class ServiceTask implements Runnable {
private static final String TAG = "ServiceTask(base)"; private static final String TAG = "ServiceTask(base)";
protected ServiceTransport mTransport;
public boolean completed = false; public boolean completed = false;
protected ServiceTransport mTransport;
public ServiceTask() { public ServiceTask() {
@ -46,9 +47,8 @@ public class ServiceTask implements Runnable {
} }
/* /*
protected void sendResponse(ServiceResult result) { * protected void sendResponse(ServiceResult result) {
RoundtripService.getInstance().sendServiceTransportResponse(mTransport,result); * RoundtripService.getInstance().sendServiceTransportResponse(mTransport,result);
} * }
*/ */
} }

View file

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

View file

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

View file

@ -7,18 +7,20 @@ import java.util.List;
* Created by geoff on 4/28/15. * Created by geoff on 4/28/15.
*/ */
public class ByteUtil { 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"; private final static String HEX_DIGITS_STR = "0123456789ABCDEF";
public static byte highByte(short s) { public static byte highByte(short s) {
return (byte) (s / 256); return (byte)(s / 256);
} }
public static byte lowByte(short s) { 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; 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) { public static byte[] concat(byte[] a, byte[] b) {
@ -78,7 +80,7 @@ public class ByteUtil {
if (ra.length == 0) { if (ra.length == 0) {
return rval; 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] & 0xF0) >> 4];
rval = rval + HEX_DIGITS[(ra[i] & 0x0F)]; rval = rval + HEX_DIGITS[(ra[i] & 0x0F)];
if (i < ra.length - 1) { if (i < ra.length - 1) {
@ -91,8 +93,8 @@ public class ByteUtil {
public static String showPrintable(byte[] ra) { public static String showPrintable(byte[] ra) {
String s = new String(); String s = new String();
for(int i = 0; i < ra.length; i++) { for (int i = 0; i < ra.length; i++) {
char c = (char) ra[i]; char c = (char)ra[i];
if (((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) { if (((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) {
s = s + c; s = s + c;
} else { } else {
@ -105,12 +107,12 @@ public class ByteUtil {
public static byte[] fromHexString(String src) { public static byte[] fromHexString(String src) {
String s = src.toUpperCase(); String s = src.toUpperCase();
byte[] rval = new byte[]{}; byte[] rval = new byte[] {};
if ((s.length() % 2) != 0) { if ((s.length() % 2) != 0) {
// invalid hex string! // invalid hex string!
return null; 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)); int highNibbleOrd = HEX_DIGITS_STR.indexOf(s.charAt(i));
if (highNibbleOrd < 0) { if (highNibbleOrd < 0) {
// Not a hex digit. // Not a hex digit.
@ -121,7 +123,7 @@ public class ByteUtil {
// Not a hex digit // Not a hex digit
return null; return null;
} }
rval = concat(rval, (byte) (highNibbleOrd * 16 + lowNibbleOrd)); rval = concat(rval, (byte)(highNibbleOrd * 16 + lowNibbleOrd));
} }
return rval; return rval;
} }
@ -129,7 +131,7 @@ public class ByteUtil {
public static byte[] fromByteArray(List<Byte> byteArray) { public static byte[] fromByteArray(List<Byte> byteArray) {
byte[] rval = new byte[byteArray.size()]; 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); rval[i] = byteArray.get(i);
} }
return rval; return rval;
@ -138,7 +140,7 @@ public class ByteUtil {
public static ArrayList<Byte> toByteArray(byte[] data) { public static ArrayList<Byte> toByteArray(byte[] data) {
ArrayList<Byte> rval = new ArrayList<>(data.length); 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])); rval.add(i, new Byte(data[i]));
} }
return rval; return rval;
@ -157,7 +159,7 @@ public class ByteUtil {
return -1; return -1;
} }
int acc = 0; int acc = 0;
for(i = 0; i < len1; i++) { for (i = 0; i < len1; i++) {
acc += s1[i]; acc += s1[i];
acc -= s2[i]; acc -= s2[i];
if (acc != 0) { 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) * 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 b1 short 1
* @param b2 short 2 * @param b2 short 2
* @param b3 short 3 * @param b3 short 3
* @param b4 short 4 * @param b4 short 4
* @param flag Conversion Flag (Big Endian, Little endian) * @param flag Conversion Flag (Big Endian, Little endian)
* @return int value * @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) { public static List<Byte> getListFromByteArray(byte[] array) {
List<Byte> listOut = new ArrayList<Byte>(); List<Byte> listOut = new ArrayList<Byte>();
for(byte val : array) { for (byte val : array) {
listOut.add(val); listOut.add(val);
} }
@ -240,4 +236,9 @@ public class ByteUtil {
return k; 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 { 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, // static final int[] crc8lookup = new int[] {
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, // 0, 155, 173, 54, 193, 90, 108, 247, 25,
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, // 130,
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, // 180,
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, // 47,
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, // 216,
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, // 67,
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, // 117,
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, // 238,
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}; 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) { public static byte crc8(byte[] data, int len) {
@ -26,16 +80,16 @@ public class CRC {
if (len > data.length) { if (len > data.length) {
len = data.length; len = data.length;
} }
for(int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
int tmp = result; int tmp = result;
int tmp2 = tmp ^ data[i]; int tmp2 = tmp ^ data[i];
int tmp3 = tmp2 & 0xFF; int tmp3 = tmp2 & 0xFF;
int idx = tmp3; int idx = tmp3;
result = (byte) crc8lookup[idx]; 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)); // log(String.format("iter=%d,tmp=0x%02x, tmp2=0x%02x, tmp3=0x%02x, lookup=0x%02x",i,tmp,tmp2,tmp3,result));
} }
// orig python: // orig python:
//result = klass.lookup[ ( result ^ block[ i ] & 0xFF ) ] // result = klass.lookup[ ( result ^ block[ i ] & 0xFF ) ]
return result; return result;
} }
@ -51,18 +105,19 @@ public class CRC {
int polynomial = 0x1021; int polynomial = 0x1021;
if (data != null) { if (data != null) {
if (data.length > 0) { if (data.length > 0) {
for(int j = 0; j < data.length; j++) { for (int j = 0; j < data.length; j++) {
byte b = data[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 bit = ((b >> (7 - i) & 1) == 1);
boolean c15 = ((crc >> 15 & 1) == 1); boolean c15 = ((crc >> 15 & 1) == 1);
crc <<= 1; crc <<= 1;
if (c15 ^ bit) crc ^= polynomial; if (c15 ^ bit)
crc ^= polynomial;
} }
} }
} }
} }
crc &= 0xffff; 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. * only.
*/ */
public class HexDump { 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) { public static String dumpHexString(byte[] array) {
@ -40,11 +42,11 @@ public class HexDump {
result.append("\n0x"); result.append("\n0x");
result.append(toHexString(offset)); result.append(toHexString(offset));
for(int i = offset; i < offset + length; i++) { for (int i = offset; i < offset + length; i++) {
if (lineIndex == 16) { if (lineIndex == 16) {
result.append(" "); result.append(" ");
for(int j = 0; j < 16; j++) { for (int j = 0; j < 16; j++) {
if (line[j] > ' ' && line[j] < '~') { if (line[j] > ' ' && line[j] < '~') {
result.append(new String(line, j, 1)); result.append(new String(line, j, 1));
} else { } else {
@ -68,11 +70,11 @@ public class HexDump {
if (lineIndex != 16) { if (lineIndex != 16) {
int count = (16 - lineIndex) * 3; int count = (16 - lineIndex) * 3;
count++; count++;
for(int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
result.append(" "); result.append(" ");
} }
for(int i = 0; i < lineIndex; i++) { for (int i = 0; i < lineIndex; i++) {
if (line[i] > ' ' && line[i] < '~') { if (line[i] > ' ' && line[i] < '~') {
result.append(new String(line, i, 1)); result.append(new String(line, i, 1));
} else { } else {
@ -99,7 +101,7 @@ public class HexDump {
char[] buf = new char[length * 2]; char[] buf = new char[length * 2];
int bufIndex = 0; int bufIndex = 0;
for(int i = offset; i < offset + length; i++) { for (int i = offset; i < offset + length; i++) {
byte b = array[i]; byte b = array[i];
buf[bufIndex++] = HEX_DIGITS[(b >>> 4) & 0x0F]; buf[bufIndex++] = HEX_DIGITS[(b >>> 4) & 0x0F];
buf[bufIndex++] = HEX_DIGITS[b & 0x0F]; buf[bufIndex++] = HEX_DIGITS[b & 0x0F];
@ -120,7 +122,7 @@ public class HexDump {
sb.append("Zero-length array"); sb.append("Zero-length array");
} else { } else {
for(byte element : arr) { for (byte element : arr) {
sb.append(getCorrectHexValue(element)); sb.append(getCorrectHexValue(element));
sb.append(" "); sb.append(" ");
} }
@ -134,7 +136,7 @@ public class HexDump {
public static String toHexStringDisplayable(List<Byte> data) { public static String toHexStringDisplayable(List<Byte> data) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for(byte element : data) { for (byte element : data) {
sb.append(getCorrectHexValue(element)); sb.append(getCorrectHexValue(element));
sb.append(" "); sb.append(" ");
} }
@ -144,7 +146,7 @@ public class HexDump {
public static String getCorrectHexValue(byte inp) { public static String getCorrectHexValue(byte inp) {
String hx = Integer.toHexString((char) inp); String hx = Integer.toHexString((char)inp);
hx = hx.toUpperCase(); hx = hx.toUpperCase();
if (hx.length() == 0) if (hx.length() == 0)
@ -185,10 +187,10 @@ public class HexDump {
public static byte[] toByteArray(int i) { public static byte[] toByteArray(int i) {
byte[] array = new byte[4]; byte[] array = new byte[4];
array[3] = (byte) (i & 0xFF); array[3] = (byte)(i & 0xFF);
array[2] = (byte) ((i >> 8) & 0xFF); array[2] = (byte)((i >> 8) & 0xFF);
array[1] = (byte) ((i >> 16) & 0xFF); array[1] = (byte)((i >> 16) & 0xFF);
array[0] = (byte) ((i >> 24) & 0xFF); array[0] = (byte)((i >> 24) & 0xFF);
return array; return array;
} }
@ -197,8 +199,8 @@ public class HexDump {
public static byte[] toByteArray(short i) { public static byte[] toByteArray(short i) {
byte[] array = new byte[2]; byte[] array = new byte[2];
array[1] = (byte) (i & 0xFF); array[1] = (byte)(i & 0xFF);
array[0] = (byte) ((i >> 8) & 0xFF); array[0] = (byte)((i >> 8) & 0xFF);
return array; return array;
} }
@ -220,12 +222,11 @@ public class HexDump {
int length = hexString.length(); int length = hexString.length();
byte[] buffer = new byte[length / 2]; byte[] buffer = new byte[length / 2];
for(int i = 0; i < length; i += 2) { for (int i = 0; i < length; i += 2) {
buffer[i / 2] = (byte) ((toByte(hexString.charAt(i)) << 4) | toByte(hexString.charAt(i + 1))); buffer[i / 2] = (byte)((toByte(hexString.charAt(i)) << 4) | toByte(hexString.charAt(i + 1)));
} }
return buffer; return buffer;
} }
} }

View file

@ -10,11 +10,11 @@ import android.os.Build;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
/** /**
* Helper for checking if location services are enabled on the device. * Helper for checking if location services are enabled on the device.
*/ */
public class LocationHelper { public class LocationHelper {
/** /**
* Determine if GPS is currently enabled. * Determine if GPS is currently enabled.
* <p> * <p>
@ -24,10 +24,11 @@ public class LocationHelper {
* @return true if location is enabled, false otherwise. * @return true if location is enabled, false otherwise.
*/ */
public static boolean isLocationEnabled(Context context) { 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); return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
} }
/** /**
* Prompt the user to enable GPS location if it isn't already on. * 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.setTitle(R.string.location_not_found_title);
builder.setMessage(R.string.location_not_found_message); builder.setMessage(R.string.location_not_found_message);
builder.setPositiveButton(R.string.location_yes, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.location_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
parent.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); parent.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
} }
@ -52,6 +54,7 @@ public class LocationHelper {
builder.create().show(); builder.create().show();
} }
/** /**
* Prompt the user to enable GPS location on devices that need it for Bluetooth discovery. * Prompt the user to enable GPS location on devices that need it for Bluetooth discovery.
* <p> * <p>
@ -66,8 +69,9 @@ public class LocationHelper {
} }
} }
//public static Boolean locationPermission(ActivityWithMenu act) { // public static Boolean locationPermission(ActivityWithMenu act) {
// return ActivityCompat.checkSelfPermission(act, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED; // 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 class PumpUtil {
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType) public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType) {
{
setPumpDescription(pumpDescription, pumpType, false); 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(); PumpCapability pumpCapability = isVirtualPump ? PumpCapability.VirtualPump : pumpType.getPumpCapability();
pumpDescription.isBolusCapable = pumpCapability.hasCapability(PumpCapability.Bolus); pumpDescription.isBolusCapable = pumpCapability.hasCapability(PumpCapability.Bolus);
@ -30,14 +29,11 @@ public class PumpUtil {
pumpDescription.isTempBasalCapable = pumpCapability.hasCapability(PumpCapability.TBR); pumpDescription.isTempBasalCapable = pumpCapability.hasCapability(PumpCapability.TBR);
if (pumpType.getPumpTempBasalType()==PumpTempBasalType.Percent) if (pumpType.getPumpTempBasalType() == PumpTempBasalType.Percent) {
{
pumpDescription.tempBasalStyle = PumpDescription.PERCENT; pumpDescription.tempBasalStyle = PumpDescription.PERCENT;
pumpDescription.maxTempPercent = pumpType.getTbrSettings().getMaxDose().intValue(); pumpDescription.maxTempPercent = pumpType.getTbrSettings().getMaxDose().intValue();
pumpDescription.tempPercentStep = (int)pumpType.getTbrSettings().getStep(); pumpDescription.tempPercentStep = (int)pumpType.getTbrSettings().getStep();
} } else {
else
{
pumpDescription.tempBasalStyle = PumpDescription.ABSOLUTE; pumpDescription.tempBasalStyle = PumpDescription.ABSOLUTE;
pumpDescription.maxTempAbsolute = pumpType.getTbrSettings().getMaxDose(); pumpDescription.maxTempAbsolute = pumpType.getTbrSettings().getMaxDose();
pumpDescription.tempAbsoluteStep = pumpType.getTbrSettings().getStep(); pumpDescription.tempAbsoluteStep = pumpType.getTbrSettings().getStep();
@ -46,7 +42,6 @@ public class PumpUtil {
pumpDescription.tempDurationStep = pumpType.getTbrSettings().getDurationStep(); pumpDescription.tempDurationStep = pumpType.getTbrSettings().getDurationStep();
pumpDescription.tempMaxDuration = pumpType.getTbrSettings().getMaxDuration(); pumpDescription.tempMaxDuration = pumpType.getTbrSettings().getMaxDuration();
pumpDescription.isSetBasalProfileCapable = pumpCapability.hasCapability(PumpCapability.BasalProfileSet); pumpDescription.isSetBasalProfileCapable = pumpCapability.hasCapability(PumpCapability.BasalProfileSet);
pumpDescription.basalStep = pumpType.getBaseBasalStep(); pumpDescription.basalStep = pumpType.getBaseBasalStep();
pumpDescription.basalMinimumRate = pumpType.getBaseBasalMinValue(); pumpDescription.basalMinimumRate = pumpType.getBaseBasalMinValue();
@ -55,5 +50,4 @@ public class PumpUtil {
pumpDescription.storesCarbInfo = pumpCapability.hasCapability(PumpCapability.StoreCarbInfo); pumpDescription.storesCarbInfo = pumpCapability.hasCapability(PumpCapability.StoreCarbInfo);
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -1,15 +1,15 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm; package info.nightscout.androidaps.plugins.PumpMedtronic.comm;
import android.content.Context; import java.util.ArrayList;
import android.os.SystemClock; import java.util.Map;
import org.joda.time.Instant; import org.joda.time.Instant;
import org.joda.time.LocalDateTime; import org.joda.time.LocalDateTime;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList; import android.content.Context;
import java.util.Map; import android.os.SystemClock;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkCommunicationManager; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkCommunicationManager;
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RFSpy; 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.service.RileyLinkMedtronicService;
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil; import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
/** /**
* Original file created by geoff on 5/30/16. * Original file created by geoff on 5/30/16.
* <p> * <p>
@ -53,9 +52,9 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
private static final int DEFAULT_TIMEOUT = 2000; private static final int DEFAULT_TIMEOUT = 2000;
static MedtronicCommunicationManager medtronicCommunicationManager; static MedtronicCommunicationManager medtronicCommunicationManager;
private MedtronicConverter medtronicConverter;
String errorMessage; String errorMessage;
private MedtronicConverter medtronicConverter;
private boolean debugSetCommands = true;
public MedtronicCommunicationManager(Context context, RFSpy rfspy, RileyLinkTargetFrequency targetFrequency) { public MedtronicCommunicationManager(Context context, RFSpy rfspy, RileyLinkTargetFrequency targetFrequency) {
@ -65,6 +64,11 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
} }
public static MedtronicCommunicationManager getInstance() {
return medtronicCommunicationManager;
}
@Override @Override
protected void configurePumpSpecificSettings() { protected void configurePumpSpecificSettings() {
pumpStatus = MedtronicUtil.getPumpStatus(); pumpStatus = MedtronicUtil.getPumpStatus();
@ -74,7 +78,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
@Override @Override
public <E extends RLMessage> E createResponseMessage(byte[] payload, Class<E> clazz) { public <E extends RLMessage> E createResponseMessage(byte[] payload, Class<E> clazz) {
PumpMessage pumpMessage = new PumpMessage(payload); PumpMessage pumpMessage = new PumpMessage(payload);
return (E) pumpMessage; return (E)pumpMessage;
} }
@ -86,7 +90,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
MedtronicDeviceType pumpModel = getPumpModel(); 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) { if (pumpModel == MedtronicDeviceType.Unknown_Device) {
SystemClock.sleep(1000); SystemClock.sleep(1000);
@ -94,7 +99,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
pumpModel = getPumpModel(); pumpModel = getPumpModel();
} }
boolean connected = (pumpModel != MedtronicDeviceType.Unknown_Device); boolean connected = (pumpModel != MedtronicDeviceType.Unknown_Device);
if (connected) { if (connected) {
@ -102,10 +106,10 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
setLastConnectionTime(); setLastConnectionTime();
} }
return (pumpModel != MedtronicDeviceType.Unknown_Device); return (pumpModel != MedtronicDeviceType.Unknown_Device);
} }
private void setLastConnectionTime() { private void setLastConnectionTime() {
// FIXME rename // FIXME rename
@ -113,29 +117,21 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// FIXME set to SP // FIXME set to SP
} }
private void checkFirstConnectionTime() { private void checkFirstConnectionTime() {
// FIXME set to SP // FIXME set to SP
} }
public static MedtronicCommunicationManager getInstance() {
return medtronicCommunicationManager;
}
private boolean debugSetCommands = true;
// FIXME remove debugs - Andy // FIXME remove debugs - Andy
private PumpMessage runCommandWithArgs(PumpMessage msg) { private PumpMessage runCommandWithArgs(PumpMessage msg) {
if (debugSetCommands) if (debugSetCommands)
LOG.debug("Run command with Args: "); LOG.debug("Run command with Args: ");
PumpMessage rval; 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 // look for ack from short message
PumpMessage shortResponse = sendAndListen(shortMessage); PumpMessage shortResponse = sendAndListen(shortMessage);
if (shortResponse.commandType == MedtronicCommandType.CommandACK) { if (shortResponse.commandType == MedtronicCommandType.CommandACK) {
@ -157,7 +153,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
LOG.debug("Run command with Args (Long): {}", commandType.name()); LOG.debug("Run command with Args (Long): {}", commandType.name());
PumpMessage rval = null; 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 // look for ack from short message
PumpMessage shortResponse = sendAndListen(shortMessage); PumpMessage shortResponse = sendAndListen(shortMessage);
@ -167,7 +163,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
return new PumpMessage("No ACK after start message."); return new PumpMessage("No ACK after start message.");
} }
int start = 0; int start = 0;
int frameNr = 1; int frameNr = 1;
int len = 0; int len = 0;
@ -190,7 +185,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
byte frame[] = new byte[65]; byte frame[] = new byte[65];
frame[0] = (byte) frameNr; frame[0] = (byte)frameNr;
System.arraycopy(content, start, frame, 1, len); System.arraycopy(content, start, frame, 1, len);
@ -214,11 +209,9 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
} while (true); } while (true);
return rval; 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) { public Page getPumpHistoryPage(int pageNumber) {
RawHistoryPage rval = new RawHistoryPage(); RawHistoryPage rval = new RawHistoryPage();
wakeUp(receiverDeviceAwakeForMinutes, false); wakeUp(receiverDeviceAwakeForMinutes, false);
PumpMessage getHistoryMsg = makePumpMessage(MedtronicCommandType.GetHistoryData, new GetHistoryPageCarelinkMessageBody(pageNumber)); PumpMessage getHistoryMsg = makePumpMessage(MedtronicCommandType.GetHistoryData,
//LOG.info("getPumpHistoryPage("+pageNumber+"): "+ByteUtil.shortHexString(getHistoryMsg.getTxData())); new GetHistoryPageCarelinkMessageBody(pageNumber));
// LOG.info("getPumpHistoryPage("+pageNumber+"): "+ByteUtil.shortHexString(getHistoryMsg.getTxData()));
// Ask the pump to transfer history (we get first frame?) // Ask the pump to transfer history (we get first frame?)
PumpMessage firstResponse = runCommandWithArgs(getHistoryMsg); 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()); PumpMessage ackMsg = makePumpMessage(MedtronicCommandType.CommandACK, new PumpAckMessageBody());
GetHistoryPageCarelinkMessageBody currentResponse = new GetHistoryPageCarelinkMessageBody(firstResponse.getMessageBody().getTxData()); GetHistoryPageCarelinkMessageBody currentResponse = new GetHistoryPageCarelinkMessageBody(firstResponse
.getMessageBody().getTxData());
int expectedFrameNum = 1; int expectedFrameNum = 1;
boolean done = false; boolean done = false;
//while (expectedFrameNum == currentResponse.getFrameNumber()) { // while (expectedFrameNum == currentResponse.getFrameNumber()) {
int failures = 0; int failures = 0;
while (!done) { while (!done) {
// examine current response for problems. // examine current response for problems.
@ -249,7 +244,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
} }
// handle successful frame data // handle successful frame data
rval.appendData(currentResponse.getFrameData()); 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()); LOG.info("getPumpHistoryPage: Got frame " + currentResponse.getFrameNumber());
// Do we need to ask for the next frame? // Do we need to ask for the next frame?
if (expectedFrameNum < 16) { // This number may not be correct for pumps other than 522/722 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) { if (frameData == null) {
LOG.error("null frame data, retrying"); LOG.error("null frame data, retrying");
} else if (currentResponse.getFrameNumber() != expectedFrameNum) { } 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) { } else if (frameData.length == 0) {
LOG.warn("Frame has zero length, retrying"); LOG.warn("Frame has zero length, retrying");
} }
failures++; failures++;
if (failures == 6) { 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. done = true; // failure completion.
} }
} }
@ -287,7 +285,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
rval.dumpToDebug(); rval.dumpToDebug();
Page page = new Page(); Page page = new Page();
//page.parseFrom(rval.getData(),PumpModel.MM522); // page.parseFrom(rval.getData(),PumpModel.MM522);
// FIXME // FIXME
page.parseFrom(rval.getData(), MedtronicDeviceType.Medtronic_522); page.parseFrom(rval.getData(), MedtronicDeviceType.Medtronic_522);
@ -329,7 +327,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// See ButtonPressCarelinkMessageBody // See ButtonPressCarelinkMessageBody
public void pressButton(int which) { public void pressButton(int which) {
wakeUp(receiverDeviceAwakeForMinutes, false); wakeUp(receiverDeviceAwakeForMinutes, false);
PumpMessage pressButtonMessage = makePumpMessage(MedtronicCommandType.PushButton, new ButtonPressCarelinkMessageBody(which)); PumpMessage pressButtonMessage = makePumpMessage(MedtronicCommandType.PushButton,
new ButtonPressCarelinkMessageBody(which));
PumpMessage resp = sendAndListen(pressButtonMessage); PumpMessage resp = sendAndListen(pressButtonMessage);
if (resp.commandType != MedtronicCommandType.CommandACK) { if (resp.commandType != MedtronicCommandType.CommandACK) {
LOG.error("Pump did not ack button press."); LOG.error("Pump did not ack button press.");
@ -338,32 +337,30 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// FIXME // FIXME
//@Override // @Override
// public RLMessage makeRLMessage(RLMessageType type, byte[] data) { // public RLMessage makeRLMessage(RLMessageType type, byte[] data) {
// switch (type) { // switch (type) {
// case PowerOn: // case PowerOn:
// return makePumpMessage(MedtronicCommandType.RFPowerOn, new CarelinkShortMessageBody(data)); // return makePumpMessage(MedtronicCommandType.RFPowerOn, new CarelinkShortMessageBody(data));
// //
// case ReadSimpleData: // case ReadSimpleData:
// return makePumpMessage(MedtronicCommandType.PumpModel, new GetPumpModelCarelinkMessageBody()); // return makePumpMessage(MedtronicCommandType.PumpModel, new GetPumpModelCarelinkMessageBody());
// //
// } // }
// return null; // return null;
// } // }
// @Override
// public RLMessage makeRLMessage(byte[] data) {
// return makePumpMessage(data);
// }
// @Override
// public RLMessage makeRLMessage(byte[] data) {
// return makePumpMessage(data);
// }
@Override @Override
public byte[] createPumpMessageContent(RLMessageType type) { public byte[] createPumpMessageContent(RLMessageType type) {
switch (type) { switch (type) {
case PowerOn: case PowerOn:
return MedtronicUtil.buildCommandPayload(MedtronicCommandType.RFPowerOn, // 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: case ReadSimpleData:
return MedtronicUtil.buildCommandPayload(MedtronicCommandType.PumpModel, null); return MedtronicUtil.buildCommandPayload(MedtronicCommandType.PumpModel, null);
@ -373,12 +370,13 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
protected PumpMessage makePumpMessage(MedtronicCommandType messageType, byte[] body) { 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) { 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) { // protected PumpMessage makePumpMessage(byte[] typeAndBody) {
// PumpMessage msg = new PumpMessage(); // PumpMessage msg = new PumpMessage();
// msg.init(ByteUtil.concat(ByteUtil.concat(new byte[]{PacketType.Carelink.getValue()}, rileyLinkServiceData.pumpIDBytes), typeAndBody)); // msg.init(ByteUtil.concat(ByteUtil.concat(new byte[]{PacketType.Carelink.getValue()},
// return msg; // rileyLinkServiceData.pumpIDBytes), typeAndBody));
// } // return msg;
// }
private PumpMessage sendAndGetResponse(MedtronicCommandType commandType) { private PumpMessage sendAndGetResponse(MedtronicCommandType commandType) {
@ -413,6 +411,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
return sendAndGetResponse(commandType, bodyData, DEFAULT_TIMEOUT); return sendAndGetResponse(commandType, bodyData, DEFAULT_TIMEOUT);
} }
/** /**
* Main wrapper method for sending data - (for getting responses) * Main wrapper method for sending data - (for getting responses)
* *
@ -445,23 +444,22 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// FIXME remove // FIXME remove
// private PumpMessage sendAndGetACK(MedtronicCommandType commandType, byte[] bodyData, int timeoutMs) { // private PumpMessage sendAndGetACK(MedtronicCommandType commandType, byte[] bodyData, int timeoutMs) {
// // wakeUp // // wakeUp
// wakeUp(receiverDeviceAwakeForMinutes, false); // wakeUp(receiverDeviceAwakeForMinutes, false);
// //
// // create message // // create message
// PumpMessage msg; // PumpMessage msg;
// //
// if (bodyData == null) // if (bodyData == null)
// msg = makePumpMessage(commandType); // msg = makePumpMessage(commandType);
// else // else
// msg = makePumpMessage(commandType, bodyData); // msg = makePumpMessage(commandType, bodyData);
// //
// // send and wait for ACK // // send and wait for ACK
// PumpMessage response = send(msg, timeoutMs); // PumpMessage response = send(msg, timeoutMs);
// return response; // return response;
// } // }
protected PumpMessage sendAndListen(RLMessage msg) { protected PumpMessage sendAndListen(RLMessage msg) {
return sendAndListen(msg, 4000); // 2000 return sendAndListen(msg, 4000); // 2000
@ -484,7 +482,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
for (int retries = 0; retries < MAX_COMMAND_RETRIES; retries++) { 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); String check = checkResponseContent(response, commandType.commandDescription, commandType.expectedLength);
@ -497,7 +496,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
return dataResponse; return dataResponse;
} else { } else {
this.errorMessage = check; this.errorMessage = check;
//return null; // return null;
} }
} }
@ -514,7 +513,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
return responseData; return responseData;
} }
byte[] contents = response.getRawContent(); byte[] contents = response.getRawContent();
if (contents != null) { if (contents != null) {
@ -523,7 +521,9 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
return null; return null;
} else { } 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); LOG.warn(responseData);
return responseData; return responseData;
@ -537,48 +537,46 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// TODO remove not needed - probably // TODO remove not needed - probably
// @Deprecated // @Deprecated
// private void executeSetCommand(MedtronicCommandType commandType, byte[] bodyData) { // 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 // // first we send command without paramters and wait for ACK
// PumpMessage pumpMessage = sendAndGetACK(commandType, null, 4000); // PumpMessage pumpMessage = sendAndGetACK(commandType, null, 4000);
// //
// // FIXME check if ACK // // FIXME check if ACK
// LOG.debug("Response 1 - {}", HexDump.toHexStringDisplayable(pumpMessage.getRawContent())); // LOG.debug("Response 1 - {}", HexDump.toHexStringDisplayable(pumpMessage.getRawContent()));
// //
// //
// LOG.debug("Executing Set for {} - 2nd call", commandType.name()); // LOG.debug("Executing Set for {} - 2nd call", commandType.name());
// // second we send command with parameters and full package 64 bits with zeroed empty places // // second we send command with parameters and full package 64 bits with zeroed empty places
// //
// byte newBodyData[] = new byte[64]; // byte newBodyData[] = new byte[64];
// for(int i = 0; i < 64; i++) { // for(int i = 0; i < 64; i++) {
// newBodyData[i] = 0x00; // newBodyData[i] = 0x00;
// } // }
// //
// newBodyData[0] = (byte) bodyData.length; // newBodyData[0] = (byte) bodyData.length;
// //
// for(int i = 0; i < bodyData.length; i++) { // for(int i = 0; i < bodyData.length; i++) {
// newBodyData[i + 1] = bodyData[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 // PUMP SPECIFIC COMMANDS
public Float getRemainingInsulin() { public Float getRemainingInsulin() {
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.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); Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.PumpModel);
if (!MedtronicUtil.isModelSet()) { 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); 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); 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); Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.ReadTemporaryBasal);
return responseObject == null ? null : (TempBasalPair) responseObject; return responseObject == null ? null : (TempBasalPair)responseObject;
} }
public Map<String, PumpSettingDTO> getPumpSettings() { 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)); LOG.debug("Set Bolus: Body - {}", HexDump.toHexStringDisplayable(body));
PumpMessage msg = makePumpMessage(MedtronicCommandType.SetBolus, // 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); PumpMessage pumpMessage = runCommandWithArgs(msg);
@ -661,7 +660,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
LOG.debug("Set TBR: Body - {}", HexDump.toHexStringDisplayable(body)); LOG.debug("Set TBR: Body - {}", HexDump.toHexStringDisplayable(body));
PumpMessage msg = makePumpMessage(MedtronicCommandType.SetTemporaryBasal, // PumpMessage msg = makePumpMessage(MedtronicCommandType.SetTemporaryBasal, //
new CarelinkLongMessageBody(tbr.getAsRawData())); new CarelinkLongMessageBody(tbr.getAsRawData()));
PumpMessage pumpMessage = runCommandWithArgs(msg); PumpMessage pumpMessage = runCommandWithArgs(msg);
@ -682,13 +681,12 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.GetBatteryStatus); 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 // FIXME --- After this line commands in development --- REMOVE THIS COMMANDS
// TODO test // TODO test
// TODO remove, we will see state from History // 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 // TODO remove, we will see bolus status from History
public PumpMessage getBolusStatus() { 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(); byte[] data = response.getRawContent();
@ -722,59 +721,83 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// TODO generateRawData (check if it works correctly) and test // TODO generateRawData (check if it works correctly) and test
public Boolean setBasalProfile(BasalProfile basalProfile) { 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 =========================== // 2018-06-30 15:03:12.167767-0500 Loop[24609:13622484] [RileyLinkDevice] ======================== Save Basal
// [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 1 bytes), 0, 0.180000, 3) // Profile ===========================
// [PeripheralManager+RileyLink] RL Send: 19050000000000000000b4030000a9659a6b19b199c555b2c000 // 2018-06-30 15:03:12.168652-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink,
// [PeripheralManager+RileyLink] RL Recv(single): bb // setBasalProfileStandard, 3 bytes, 1 bytes), 0, 0.180000, 3)
// [PeripheralManager+RileyLink] RileyLink response: PacketResponse(code: RileyLinkBLEKit.ResponseCode.commandInterrupted, packet: nil) // 2018-06-30 15:03:12.169518-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send:
// [PeripheralManager+RileyLink] RL Recv(single): dd0dbca9659a6b19b156655534d500 // 19050000000000000000b4030000a9659a6b19b199c555b2c000
// [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3) // 2018-06-30 15:03:12.463546-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single): bb
// [PeripheralManager+RileyLink] RL Send: 79050000000000000000b4030000a9659a6b19b199c571c9a555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555556000 // 2018-06-30 15:03:12.463954-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RileyLink response:
// 2018-06-30 15:03:13.333962-0500 Loop[24609:13622692] [PeripheralManager+RileyLink] RL Recv(single): dd10bda9659a6b19b156655534d500 // PacketResponse(code: RileyLinkBLEKit.ResponseCode.commandInterrupted, packet: nil)
// 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:12.554051-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single):
// 2018-06-30 15:03:13.337923-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send: 79050000000000000000b4030000a9659a6b19b199c5725555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555ac000 // dd0dbca9659a6b19b156655534d500
// 2018-06-30 15:03:14.114024-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single): dd0ebea9659a6b19b156655534d500 // 2018-06-30 15:03:12.555175-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink,
// 2018-06-30 15:03:14.115017-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3) // 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:12.557953-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send:
// 2018-06-30 15:03:15.644502-0500 Loop[24609:13622692] [PeripheralManager+RileyLink] RL Recv(single): dd0ebfa9659a6b19b156655534d500 // 79050000000000000000b4030000a9659a6b19b199c571c9a555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555556000
// 2018-06-30 15:03:15.645388-0500 Loop[24609:13622484] [RileyLinkDevice] ------------------------ Save Basal Profile --------------------------- // 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 =========================== byte[] body = new byte[] { 32, 0, 0, 38, 0, 13, 44, 0, 19, 38, 0, 28 };
// 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};
PumpMessage responseMessage; PumpMessage responseMessage;
if (debugSetCommands) if (debugSetCommands)
LOG.debug("Set Basal Profile: Body [{}] - {}", body.length, HexDump.toHexStringDisplayable(body)); LOG.debug("Set Basal Profile: Body [{}] - {}", body.length, HexDump.toHexStringDisplayable(body));
// if (body.length <= 64) { // if (body.length <= 64) {
// //
// PumpMessage msg = makePumpMessage(MedtronicCommandType.SetBasalProfileA, // // PumpMessage msg = makePumpMessage(MedtronicCommandType.SetBasalProfileA, //
// new CarelinkLongMessageBody(ByteUtil.concat((byte) body.length, body))); // new CarelinkLongMessageBody(ByteUtil.concat((byte) body.length, body)));
// //
// responseMessage = runCommandWithArgs(msg); // responseMessage = runCommandWithArgs(msg);
// } else // } else
{ {
responseMessage = runCommandWithArgsLong(MedtronicCommandType.SetBasalProfileA, body); responseMessage = runCommandWithArgsLong(MedtronicCommandType.SetBasalProfileA, body);
@ -788,31 +811,29 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
} }
// public byte[] getFullMessageBody(byte[] bodyData, int length) { // public byte[] getFullMessageBody(byte[] bodyData, int length) {
// byte newBodyData[] = getEmptyMessage(length); // byte newBodyData[] = getEmptyMessage(length);
// //
// newBodyData[0] = (byte) bodyData.length; // newBodyData[0] = (byte) bodyData.length;
// //
// for (int i = 0; i < bodyData.length; i++) { // for (int i = 0; i < bodyData.length; i++) {
// newBodyData[i + 1] = bodyData[i]; // newBodyData[i + 1] = bodyData[i];
// } // }
// //
// return newBodyData; // 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[] getEmptyMessage(int length) {
// byte newBodyData[] = new byte[length];
// for (int i = 0; i < length; i++) {
// newBodyData[i] = 0x00;
// }
//
// return newBodyData;
// }
public PumpMessage cancelBolus() { public PumpMessage cancelBolus() {
//? maybe suspend and resume // ? maybe suspend and resume
return null; return null;
} }
@ -830,44 +851,44 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
return null; return null;
} }
// Set TBR 100%
// Cancel TBR (set TBR 100%) 100%
// Get Status (40%)
// Set Bolus 100% // Set TBR 100%
// Set Extended Bolus 20% // Cancel TBR (set TBR 100%) 100%
// Cancel Bolus 0% -- NOT SUPPORTED // Get Status (40%)
// Cancel Extended Bolus 0% -- NOT SUPPORTED
// Get Basal Profile (0x92) Read STD 100% // Set Bolus 100%
// Set Basal Profile 0% -- NOT SUPPORTED // Set Extended Bolus 20%
// Read History 60% // Cancel Bolus 0% -- NOT SUPPORTED
// Load TDD ? // 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 // FIXME remove - each part needs to be gotten manually
public void updatePumpManagerStatus() { public void updatePumpManagerStatus() {
//Integer resp = getRemainingBattery(); // Integer resp = getRemainingBattery();
//pumpStatus.batteryRemaining = resp == null ? -1 : resp; // pumpStatus.batteryRemaining = resp == null ? -1 : resp;
//pumpStatus.remainUnits = getRemainingInsulin(); // pumpStatus.remainUnits = getRemainingInsulin();
/* current basal */ /* current basal */
//TempBasalPair basalRate = getCurrentBasalRate(); // TempBasalPair basalRate = getCurrentBasalRate();
// FIXME // FIXME
// byte[] basalRateBytes = resp.getContents(); // byte[] basalRateBytes = resp.getContents();
// if (basalRateBytes != null) { // if (basalRateBytes != null) {
// if (basalRateBytes.length == 2) { // if (basalRateBytes.length == 2) {
// /** // /**
// * 0x98 0x06 // * 0x98 0x06
// * 0x98 is "basal rate" // * 0x98 is "basal rate"
// * 0x06 is what? Not currently running a temp basal, current basal is "standard" at 0 // * 0x06 is what? Not currently running a temp basal, current basal is "standard" at 0
// */ // */
// double basalRate = ByteUtil.asUINT8(basalRateBytes[1]); // double basalRate = ByteUtil.asUINT8(basalRateBytes[1]);
// pumpStatus.currentBasal = basalRate; // pumpStatus.currentBasal = basalRate;
// } // }
// } // }
// get last bolus amount // get last bolus amount
// get last bolus time // get last bolus time
// get tempBasalInProgress // get tempBasalInProgress
@ -877,11 +898,10 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
// get pump time // get pump time
LocalDateTime clockResult = getPumpTime(); LocalDateTime clockResult = getPumpTime();
if (clockResult != null) { if (clockResult != null) {
//pumpStatus.time = clockResult.toDate(); // pumpStatus.time = clockResult.toDate();
} }
// get last sync time // 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 * 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.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; 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.ByteUtil;
import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC; import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC;
import info.nightscout.androidaps.plugins.PumpCommon.utils.HexDump; import info.nightscout.androidaps.plugins.PumpCommon.utils.HexDump;
@ -49,14 +49,14 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType
@Deprecated @Deprecated
public class Page { public class Page {
private final static String TAG = "Page"; private final static String TAG = "Page";
private static final boolean DEBUG_PAGE = true; private static final boolean DEBUG_PAGE = true;
// protected PumpModel model;
private byte[] crc;
private byte[] data;
//protected PumpModel model;
public static MedtronicDeviceType model = MedtronicDeviceType.Medtronic_522; public static MedtronicDeviceType model = MedtronicDeviceType.Medtronic_522;
public List<Record> mRecordList; public List<Record> mRecordList;
private byte[] crc;
private byte[] data;
public Page() { 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() { public byte[] getRawData() {
if (data == null) { if (data == null) {
return crc; return crc;
@ -91,7 +189,8 @@ public class Page {
this.model = model; this.model = model;
int pageOffset = 0; 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.data = Arrays.copyOfRange(rawPage, 0, rawPage.length - 2);
this.crc = Arrays.copyOfRange(rawPage, rawPage.length - 2, rawPage.length); this.crc = Arrays.copyOfRange(rawPage, rawPage.length - 2, rawPage.length);
byte[] expectedCrc = CRC.calculate16CCITT(this.data); byte[] expectedCrc = CRC.calculate16CCITT(this.data);
@ -99,7 +198,10 @@ public class Page {
Log.i(TAG, String.format("Data length: %d", data.length)); Log.i(TAG, String.format("Data length: %d", data.length));
} }
if (!Arrays.equals(crc, expectedCrc)) { 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 { } else {
if (DEBUG_PAGE) { if (DEBUG_PAGE) {
Log.i(TAG, "CRC OK"); Log.i(TAG, "CRC OK");
@ -110,7 +212,9 @@ public class Page {
while (pageOffset < data.length) { while (pageOffset < data.length) {
if (data[pageOffset] == 0) { if (data[pageOffset] == 0) {
if (record != null) { 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; break;
} else { } else {
Log.i(TAG, "WTF?"); Log.i(TAG, "WTF?");
@ -132,8 +236,8 @@ public class Page {
ArrayList<Record> pickyRecords = new ArrayList<>(); ArrayList<Record> pickyRecords = new ArrayList<>();
pickyRecords.addAll(mRecordList); pickyRecords.addAll(mRecordList);
parseByDates(rawPage, model); parseByDates(rawPage, model);
for(Record r : mRecordList) { for (Record r : mRecordList) {
for(Record r2 : pickyRecords) { for (Record r2 : pickyRecords) {
if (r.getFoundAtOffset() == r2.getFoundAtOffset()) { if (r.getFoundAtOffset() == r2.getFoundAtOffset()) {
Log.v(TAG, "Found matching record at offset " + r.getFoundAtOffset()); Log.v(TAG, "Found matching record at offset " + r.getFoundAtOffset());
} }
@ -147,7 +251,7 @@ public class Page {
mRecordList = new ArrayList<>(); mRecordList = new ArrayList<>();
if (rawPage.length != 1024) { if (rawPage.length != 1024) {
Log.e(TAG, "Unexpected page size. Expected: 1024 Was: " + rawPage.length); Log.e(TAG, "Unexpected page size. Expected: 1024 Was: " + rawPage.length);
//return false; // return false;
} }
Page.model = model; Page.model = model;
if (DEBUG_PAGE) { if (DEBUG_PAGE) {
@ -166,7 +270,10 @@ public class Page {
Log.i(TAG, String.format("Data length: %d", data.length)); Log.i(TAG, String.format("Data length: %d", data.length));
} }
if (!Arrays.equals(crc, expectedCrc)) { 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 { } else {
if (DEBUG_PAGE) { if (DEBUG_PAGE) {
Log.i(TAG, "CRC OK"); Log.i(TAG, "CRC OK");
@ -201,7 +308,6 @@ public class Page {
pageOffset++; pageOffset++;
} }
return true; return true;
} }
@ -210,7 +316,7 @@ public class Page {
mRecordList = new ArrayList<>(); // wipe old contents each time when parsing. mRecordList = new ArrayList<>(); // wipe old contents each time when parsing.
if (rawPage.length != 1024) { if (rawPage.length != 1024) {
Log.e(TAG, "Unexpected page size. Expected: 1024 Was: " + rawPage.length); Log.e(TAG, "Unexpected page size. Expected: 1024 Was: " + rawPage.length);
//return false; // return false;
} }
this.model = model; this.model = model;
if (DEBUG_PAGE) { if (DEBUG_PAGE) {
@ -229,7 +335,10 @@ public class Page {
Log.i(TAG, String.format("Data length: %d", data.length)); Log.i(TAG, String.format("Data length: %d", data.length));
} }
if (!Arrays.equals(crc, expectedCrc)) { 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 { } else {
if (DEBUG_PAGE) { if (DEBUG_PAGE) {
Log.i(TAG, "CRC OK"); Log.i(TAG, "CRC OK");
@ -249,12 +358,14 @@ public class Page {
record = null; record = null;
} }
} else { } 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 stringBuilder = new StringBuilder();
stringBuilder.append("Possible parsing problem: "); stringBuilder.append("Possible parsing problem: ");
stringBuilder.append("Previous record: " + previousRecord); 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; int remainingData = rawPage.length - dataIndex;
byte[] tmpData = new byte[remainingData + 10]; byte[] tmpData = new byte[remainingData + 10];
@ -269,10 +380,13 @@ public class Page {
if (record != null) { if (record != null) {
if (record instanceof IgnoredHistoryEntry) { if (record instanceof IgnoredHistoryEntry) {
IgnoredHistoryEntry he = (IgnoredHistoryEntry) record; IgnoredHistoryEntry he = (IgnoredHistoryEntry)record;
Log.v(TAG, "parseFrom: found event " + he.getShortTypeName() + " length=" + record.getLength() + " offset=" + record.getFoundAtOffset() + " -- IGNORING"); Log.v(TAG, "parseFrom: found event " + he.getShortTypeName() + " length=" + record.getLength()
+ " offset=" + record.getFoundAtOffset() + " -- IGNORING");
} else { } 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); mRecordList.add(record);
} }
@ -283,19 +397,19 @@ public class Page {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Possible parsing problem: "); stringBuilder.append("Possible parsing problem: ");
stringBuilder.append("Previous record: " + previousRecord); 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; int remainingData = data.length - dataIndex;
byte[] tmpData = Arrays.copyOfRange(data, dataIndex, 1022); byte[] tmpData = Arrays.copyOfRange(data, dataIndex, 1022);
// new byte[remainingData];
//new byte[remainingData]; // System.arraycopy(data, dataIndex, tmpData, 0, remainingData - 2);
//System.arraycopy(data, dataIndex, tmpData, 0, remainingData - 2);
stringBuilder.append(" Remaining data: " + HexDump.toHexStringDisplayable(tmpData)); stringBuilder.append(" Remaining data: " + HexDump.toHexStringDisplayable(tmpData));
Log.e(TAG,
Log.e(TAG, String.format("parseFrom: Failed to parse opcode 0x%02x, offset=%d", data[dataIndex], dataIndex)); String.format("parseFrom: Failed to parse opcode 0x%02x, offset=%d", data[dataIndex], dataIndex));
done = true; done = true;
} }
if (dataIndex >= data.length - 2) { if (dataIndex >= data.length - 2) {
@ -308,7 +422,7 @@ public class Page {
if (DEBUG_PAGE) { if (DEBUG_PAGE) {
Log.i(TAG, String.format("Number of records: %d", mRecordList.size())); Log.i(TAG, String.format("Number of records: %d", mRecordList.size()));
int index = 1; int index = 1;
for(Record r : mRecordList) { for (Record r : mRecordList) {
Log.v(TAG, String.format("Record #%d: %s", index, r.getShortTypeName())); Log.v(TAG, String.format("Record #%d: %s", index, r.getShortTypeName()));
index += 1; 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[] crc;
private byte[] data; * private byte[] data;
protected PumpModel model; * protected PumpModel model;
public List<Record> mRecordList; * public List<Record> mRecordList;
*/ */
public Bundle pack() { public Bundle pack() {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
@ -430,7 +449,7 @@ public class Page {
bundle.putByteArray("data", data); bundle.putByteArray("data", data);
bundle.putString("model", model.name()); bundle.putString("model", model.name());
ArrayList<Bundle> records = new ArrayList<>(); ArrayList<Bundle> records = new ArrayList<>();
for(int i = 0; i < mRecordList.size(); i++) { for (int i = 0; i < mRecordList.size(); i++) {
try { try {
records.add(mRecordList.get(i).dictionaryRepresentation()); records.add(mRecordList.get(i).dictionaryRepresentation());
} catch (NullPointerException e) { } catch (NullPointerException e) {
@ -449,7 +468,7 @@ public class Page {
ArrayList<Bundle> records = in.getParcelableArrayList("mRecordList"); ArrayList<Bundle> records = in.getParcelableArrayList("mRecordList");
mRecordList = new ArrayList<>(); mRecordList = new ArrayList<>();
if (records != null) { 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); Record r = RecordTypeEnum.getRecordClassInstance(records.get(i), model);
r.readFromBundle(records.get(i)); r.readFromBundle(records.get(i));
mRecordList.add(r); mRecordList.add(r);
@ -457,5 +476,4 @@ public class Page {
} }
} }
}
}

View file

@ -1,11 +1,11 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data; package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data;
import android.util.Log; import java.util.Arrays;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.ByteUtil;
import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC; 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. * Created by geoff on 6/4/16.
*/ */
public class RawHistoryPage { public class RawHistoryPage {
private static final String TAG = "RawHistoryPage"; private static final String TAG = "RawHistoryPage";
private static final Logger LOG = LoggerFactory.getLogger(RawHistoryPage.class); private static final Logger LOG = LoggerFactory.getLogger(RawHistoryPage.class);
byte[] data = new byte[0]; byte[] data = new byte[0];
@ -54,9 +55,11 @@ public class RawHistoryPage {
int crcStored = ByteUtil.toInt(data[1022], data[1023]); int crcStored = ByteUtil.toInt(data[1022], data[1023]);
if (crcCalculated != crcStored) { 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 { } else {
if (MedtronicUtil.isLowLevelDebug()) LOG.debug("CRC ok."); if (MedtronicUtil.isLowLevelDebug())
LOG.debug("CRC ok.");
} }
return crcCalculated == crcStored; 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. * Exists to easily merge 2 byte timestamps and 5 byte timestamps.
*/ */
public class PumpTimeStamp { public class PumpTimeStamp {
private LocalDateTime localDateTime; private LocalDateTime localDateTime;
public PumpTimeStamp() { public PumpTimeStamp() {
localDateTime = new LocalDateTime(1973, 1, 1, 1, 1); localDateTime = new LocalDateTime(1973, 1, 1, 1, 1);
} }
public PumpTimeStamp(String stringRepresentation) { public PumpTimeStamp(String stringRepresentation) {
localDateTime.parse(stringRepresentation); localDateTime.parse(stringRepresentation);
} }
public PumpTimeStamp(LocalDate localDate) { public PumpTimeStamp(LocalDate localDate) {
try { try {
localDateTime = new LocalDateTime(localDate); localDateTime = new LocalDateTime(localDate);
@ -27,14 +31,17 @@ public class PumpTimeStamp {
} }
} }
public PumpTimeStamp(LocalDateTime localDateTime) { public PumpTimeStamp(LocalDateTime localDateTime) {
this.localDateTime = localDateTime; this.localDateTime = localDateTime;
} }
public LocalDateTime getLocalDateTime() { public LocalDateTime getLocalDateTime() {
return localDateTime; return localDateTime;
} }
@Override @Override
public String toString() { public String toString() {
return getLocalDateTime().toString(); return getLocalDateTime().toString();

View file

@ -8,10 +8,21 @@ abstract public class Record {
protected MedtronicDeviceType model; protected MedtronicDeviceType model;
protected byte recordOp; protected byte recordOp;
//protected int length; // protected int length;
protected int foundAtOffset; protected int foundAtOffset;
protected byte[] rawbytes = new byte[0]; 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() { public String getRecordTypeName() {
@ -34,11 +45,6 @@ abstract public class Record {
} }
public Record() {
}
public boolean parseWithOffset(byte[] data, MedtronicDeviceType model, int foundAtOffset) { public boolean parseWithOffset(byte[] data, MedtronicDeviceType model, int foundAtOffset) {
// keep track of where the record was found for later analysis // keep track of where the record was found for later analysis
this.foundAtOffset = foundAtOffset; 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() { public Bundle dictionaryRepresentation() {
Bundle rval = new Bundle(); Bundle rval = new Bundle();
writeToBundle(rval); writeToBundle(rval);

View file

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

View file

@ -1,30 +1,33 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history; package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history;
import android.util.Log;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime; import org.joda.time.LocalDateTime;
import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.DateTimeFormatter;
import android.util.Log;
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil; import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
/** /**
* Created by geoff on 6/4/16. * Created by geoff on 6/4/16.
*/ */
public class TimeFormat { public class TimeFormat {
public static final String standardFormatString = "YYYY-MM-dd HH:mm:ss";
private static final boolean DEBUG_TIMEFORMAT = false; private static final boolean DEBUG_TIMEFORMAT = false;
private static final String TAG = "TimeFormat"; private static final String TAG = "TimeFormat";
public TimeFormat() { public TimeFormat() {
} }
public static final String standardFormatString = "YYYY-MM-dd HH:mm:ss";
public static DateTimeFormatter standardFormatter() { public static DateTimeFormatter standardFormatter() {
return DateTimeFormat.forPattern(standardFormatString); return DateTimeFormat.forPattern(standardFormatString);
} }
public static LocalDate parse2ByteDate(byte[] data, int offset) throws org.joda.time.IllegalFieldValueException { public static LocalDate parse2ByteDate(byte[] data, int offset) throws org.joda.time.IllegalFieldValueException {
int low = ByteUtil.asUINT8(data[0 + offset]) & 0x1F; int low = ByteUtil.asUINT8(data[0 + offset]) & 0x1F;
int mhigh = (ByteUtil.asUINT8(data[0 + offset]) & 0xE0) >> 4; int mhigh = (ByteUtil.asUINT8(data[0 + offset]) & 0xE0) >> 4;
@ -33,29 +36,29 @@ public class TimeFormat {
int dayOfMonth = low + 1; int dayOfMonth = low + 1;
int year = 2000 + (ByteUtil.asUINT8(data[offset + 1]) & 0x7F); 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", * Log.w(TAG, String.format("Attempting to create DateTime from: %04d-%02d-%02d %02d:%02d:%02d",
year + 2000, month, dayOfMonth, hour, minutes, seconds)); * year + 2000, month, dayOfMonth, hour, minutes, seconds));
*/ */
// try { // try {
LocalDate rval = new LocalDate(year, month, dayOfMonth); LocalDate rval = new LocalDate(year, month, dayOfMonth);
return rval; return rval;
/* /*
} catch (org.joda.time.IllegalFieldValueException e) { * } catch (org.joda.time.IllegalFieldValueException e) {
Log.e(TAG,"Illegal DateTime field"); * Log.e(TAG,"Illegal DateTime field");
//e.printStackTrace(); * //e.printStackTrace();
return new LocalDate(1973,3,3); * return new LocalDate(1973,3,3);
} * }
*/ */
} }
// for relation to old code, replace offset with headerSize // for relation to old code, replace offset with headerSize
public static LocalDateTime parse5ByteDate(byte[] data, int offset) throws org.joda.time.IllegalFieldValueException { public static LocalDateTime parse5ByteDate(byte[] data, int offset) throws org.joda.time.IllegalFieldValueException {
//offset = headerSize; // offset = headerSize;
if (DEBUG_TIMEFORMAT) { if (DEBUG_TIMEFORMAT) {
Log.w(TAG, String.format("bytes to parse: 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X", Log.w(TAG, String.format("bytes to parse: 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X", data[offset],
data[offset], data[offset + 1], data[offset + 2], data[offset + 3], data[offset + 4])); data[offset + 1], data[offset + 2], data[offset + 3], data[offset + 4]));
} }
int seconds = data[offset] & 0x3F; int seconds = data[offset] & 0x3F;
int minutes = data[offset + 1] & 0x3F; int minutes = data[offset + 1] & 0x3F;
@ -63,22 +66,22 @@ public class TimeFormat {
int dayOfMonth = data[offset + 3] & 0x1F; int dayOfMonth = data[offset + 3] & 0x1F;
// Yes, the month bits are stored in the high bits above seconds and minutes!! // 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 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", * Log.w(TAG,String.format("Attempting to create DateTime from: %04d-%02d-%02d %02d:%02d:%02d",
year+2000,month,dayOfMonth,hour,minutes,seconds)); * year+2000,month,dayOfMonth,hour,minutes,seconds));
*/ */
// try { // try {
LocalDateTime timeStamp = new LocalDateTime(year + 2000, month, dayOfMonth, hour, minutes, seconds); LocalDateTime timeStamp = new LocalDateTime(year + 2000, month, dayOfMonth, hour, minutes, seconds);
return timeStamp; return timeStamp;
/* /*
} catch (org.joda.time.IllegalFieldValueException e) { * } catch (org.joda.time.IllegalFieldValueException e) {
Log.e(TAG, "Illegal DateTime field"); * Log.e(TAG, "Illegal DateTime field");
//e.printStackTrace(); * //e.printStackTrace();
return new LocalDateTime(1973,2,2,2,2); * 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. * Many of the subclasses of this class only override the opcode.
*/ */
abstract public class TimeStampedRecord extends Record { 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; private final static boolean DEBUG_TIMESTAMPEDRECORD = false;
protected PumpTimeStamp timestamp;
public TimeStampedRecord() {
timestamp = new PumpTimeStamp();
}
@Override @Override
@ -26,14 +33,6 @@ abstract public class TimeStampedRecord extends Record {
} }
protected PumpTimeStamp timestamp;
public TimeStampedRecord() {
timestamp = new PumpTimeStamp();
}
@Override @Override
public PumpTimeStamp getTimestamp() { public PumpTimeStamp getTimestamp() {
return timestamp; return timestamp;

View file

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

View file

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

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record; package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record;
import android.os.Bundle; import android.os.Bundle;
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil; 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; import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
public class BGReceivedPumpEvent extends TimeStampedRecord { public class BGReceivedPumpEvent extends TimeStampedRecord {
private int amount = 0; private int amount = 0;
private byte[] meter = new byte[3]; 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; import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
public class BasalProfileStart extends TimeStampedRecord { public class BasalProfileStart extends TimeStampedRecord {
private static final String TAG = "BasalProfileStart"; private static final String TAG = "BasalProfileStart";
private int offset = 0; private int offset = 0;
private double rate = 0.0; private double rate = 0.0;
@ -36,7 +37,7 @@ public class BasalProfileStart extends TimeStampedRecord {
profileIndex = asUINT8(data[1]); profileIndex = asUINT8(data[1]);
offset = asUINT8(data[7]) * 30 * 1000 * 60; offset = asUINT8(data[7]) * 30 * 1000 * 60;
rate = (double) (asUINT8(data[8])) / 40.0; rate = (double)(asUINT8(data[8])) / 40.0;
return true; 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; import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
public class BatteryPumpEvent extends TimeStampedRecord { public class BatteryPumpEvent extends TimeStampedRecord {
public BatteryPumpEvent() { public BatteryPumpEvent() {
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Battery"; return "Battery";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; return false;

View file

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

View file

@ -20,7 +20,7 @@ public class BolusWizardBolusEstimatePumpEvent extends TimeStampedRecord {
public BolusWizardBolusEstimatePumpEvent() { public BolusWizardBolusEstimatePumpEvent() {
correctionEstimate = (double) 0.0; correctionEstimate = (double)0.0;
bloodGlucose = 0; bloodGlucose = 0;
carbohydrates = 0; carbohydrates = 0;
carbRatio = 0.0; carbRatio = 0.0;
@ -141,24 +141,24 @@ public class BolusWizardBolusEstimatePumpEvent extends TimeStampedRecord {
carbohydrates = (asUINT8(data[8]) & 0x0c << 6) + asUINT8(data[7]); carbohydrates = (asUINT8(data[8]) & 0x0c << 6) + asUINT8(data[7]);
bloodGlucose = (asUINT8(data[8]) & 0x03 << 8) + asUINT8(data[1]); bloodGlucose = (asUINT8(data[8]) & 0x03 << 8) + asUINT8(data[1]);
foodEstimate = insulinDecode(asUINT8(data[14]), asUINT8(data[15])); 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])); bolusEstimate = insulinDecode(asUINT8(data[19]), asUINT8(data[20]));
unabsorbedInsulinTotal = insulinDecode(asUINT8(data[17]), asUINT8(data[18])); unabsorbedInsulinTotal = insulinDecode(asUINT8(data[17]), asUINT8(data[18]));
bgTargetLow = asUINT8(data[12]); bgTargetLow = asUINT8(data[12]);
bgTargetHigh = asUINT8(data[21]); bgTargetHigh = asUINT8(data[21]);
insulinSensitivity = asUINT8(data[11]); 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 { } else {
carbohydrates = asUINT8(data[7]); carbohydrates = asUINT8(data[7]);
bloodGlucose = ((asUINT8(data[8]) & 0x03) << 8) + asUINT8(data[1]); bloodGlucose = ((asUINT8(data[8]) & 0x03) << 8) + asUINT8(data[1]);
foodEstimate = (double) (asUINT8(data[13])) / 10.0; foodEstimate = (double)(asUINT8(data[13])) / 10.0;
correctionEstimate = (double) ((asUINT8(data[14]) << 8) + asUINT8(data[12])) / 10.0; correctionEstimate = (double)((asUINT8(data[14]) << 8) + asUINT8(data[12])) / 10.0;
bolusEstimate = (double) (asUINT8(data[18])) / 10.0; bolusEstimate = (double)(asUINT8(data[18])) / 10.0;
unabsorbedInsulinTotal = (double) (asUINT8(data[16])) / 10.0; unabsorbedInsulinTotal = (double)(asUINT8(data[16])) / 10.0;
bgTargetLow = asUINT8(data[11]); bgTargetLow = asUINT8(data[11]);
bgTargetHigh = asUINT8(data[19]); bgTargetHigh = asUINT8(data[19]);
insulinSensitivity = asUINT8(data[10]); insulinSensitivity = asUINT8(data[10]);
carbRatio = (double) asUINT8(data[9]); carbRatio = (double)asUINT8(data[9]);
} }
return true; 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; import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
public class CalBgForPhPumpEvent extends TimeStampedRecord { public class CalBgForPhPumpEvent extends TimeStampedRecord {
private int amount = 0; 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. * Created by geoff on 6/5/16.
*/ */
public class ChangeAlarmClockEnablePumpEvent extends TimeStampedRecord { public class ChangeAlarmClockEnablePumpEvent extends TimeStampedRecord {
public ChangeAlarmClockEnablePumpEvent() { public ChangeAlarmClockEnablePumpEvent() {
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Alarm Clock Enable"; return "Alarm Clock Enable";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; 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; import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
public class ChangeAlarmNotifyModePumpEvent extends TimeStampedRecord { public class ChangeAlarmNotifyModePumpEvent extends TimeStampedRecord {
public ChangeAlarmNotifyModePumpEvent() { public ChangeAlarmNotifyModePumpEvent() {
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Alarm Notify Mode"; return "Ch Alarm Notify Mode";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; 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. * Created by geoff on 6/5/16.
*/ */
public class ChangeAudioBolusPumpEvent extends TimeStampedRecord { public class ChangeAudioBolusPumpEvent extends TimeStampedRecord {
public ChangeAudioBolusPumpEvent() { public ChangeAudioBolusPumpEvent() {
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Audio Bolus"; return "Ch Audio Bolus";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return true; 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. * Created by geoff on 6/5/16.
*/ */
public class ChangeBGReminderEnablePumpEvent extends TimeStampedRecord { public class ChangeBGReminderEnablePumpEvent extends TimeStampedRecord {
public ChangeBGReminderEnablePumpEvent() { public ChangeBGReminderEnablePumpEvent() {
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch BG Rmndr Enable"; return "Ch BG Rmndr Enable";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; 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. * Created by geoff on 6/5/16.
*/ */
public class ChangeBasalProfilePatternPumpEvent extends TimeStampedRecord { public class ChangeBasalProfilePatternPumpEvent extends TimeStampedRecord {
public ChangeBasalProfilePatternPumpEvent() { public ChangeBasalProfilePatternPumpEvent() {
} }
@Override @Override
public int getLength() { public int getLength() {
return 152; return 152;
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Basal Prof Pat"; return "Ch Basal Prof Pat";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return true; 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; import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
public class ChangeBasalProfilePumpEvent extends TimeStampedRecord { public class ChangeBasalProfilePumpEvent extends TimeStampedRecord {
public ChangeBasalProfilePumpEvent() { public ChangeBasalProfilePumpEvent() {
} }
@Override @Override
public int getLength() { public int getLength() {
return 152; return 152;
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Basal Profile"; return "Ch Basal Profile";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return true; 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. * Created by geoff on 6/5/16.
*/ */
public class ChangeBolusReminderEnablePumpEvent extends TimeStampedRecord { public class ChangeBolusReminderEnablePumpEvent extends TimeStampedRecord {
public ChangeBolusReminderEnablePumpEvent() { public ChangeBolusReminderEnablePumpEvent() {
} }
@Override @Override
public int getLength() { public int getLength() {
return 9; return 9;
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Bolus Rmndr Enable"; return "Ch Bolus Rmndr Enable";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; 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. * Created by geoff on 6/5/16.
*/ */
public class ChangeBolusReminderTimePumpEvent extends TimeStampedRecord { public class ChangeBolusReminderTimePumpEvent extends TimeStampedRecord {
public ChangeBolusReminderTimePumpEvent() { public ChangeBolusReminderTimePumpEvent() {
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Bolus Rmndr Time"; return "Ch Bolus Rmndr Time";
} }
@Override @Override
public int getLength() { public int getLength() {
return 9; return 9;
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; 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. * Created by geoff on 6/5/16.
*/ */
public class ChangeBolusScrollStepSizePumpEvent extends TimeStampedRecord { public class ChangeBolusScrollStepSizePumpEvent extends TimeStampedRecord {
public ChangeBolusScrollStepSizePumpEvent() { public ChangeBolusScrollStepSizePumpEvent() {
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Bolus Scroll SS"; return "Ch Bolus Scroll SS";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; return false;

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record; package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord; import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
public class ChangeBolusWizardSetupPumpEvent extends TimeStampedRecord { public class ChangeBolusWizardSetupPumpEvent extends TimeStampedRecord {
@ -8,16 +7,19 @@ public class ChangeBolusWizardSetupPumpEvent extends TimeStampedRecord {
public ChangeBolusWizardSetupPumpEvent() { public ChangeBolusWizardSetupPumpEvent() {
} }
@Override @Override
public int getLength() { public int getLength() {
return 144; return 144;
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Bolus Wizard Setup"; return "Ch Bolus Wizard Setup";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; 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. * Created by geoff on 6/5/16.
*/ */
public class ChangeCaptureEventEnablePumpEvent extends TimeStampedRecord { public class ChangeCaptureEventEnablePumpEvent extends TimeStampedRecord {
public ChangeCaptureEventEnablePumpEvent() { public ChangeCaptureEventEnablePumpEvent() {
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Capture Event Ena"; return "Ch Capture Event Ena";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; 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. * Created by geoff on 6/5/16.
*/ */
public class ChangeCarbUnitsPumpEvent extends TimeStampedRecord { public class ChangeCarbUnitsPumpEvent extends TimeStampedRecord {
public ChangeCarbUnitsPumpEvent() { public ChangeCarbUnitsPumpEvent() {
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Carb Units"; return "Ch Carb Units";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; 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. * Created by geoff on 6/5/16.
*/ */
public class ChangeChildBlockEnablePumpEvent extends TimeStampedRecord { public class ChangeChildBlockEnablePumpEvent extends TimeStampedRecord {
public ChangeChildBlockEnablePumpEvent() { public ChangeChildBlockEnablePumpEvent() {
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Child Block Ena"; return "Ch Child Block Ena";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; 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. * Created by geoff on 6/5/16.
*/ */
public class ChangeMaxBolusPumpEvent extends TimeStampedRecord { public class ChangeMaxBolusPumpEvent extends TimeStampedRecord {
public ChangeMaxBolusPumpEvent() { public ChangeMaxBolusPumpEvent() {
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Max Bolux"; return "Ch Max Bolux";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; return false;

View file

@ -1,6 +1,5 @@
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record; package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record;
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord; import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
public class ChangeOtherDeviceIDPumpEvent extends TimeStampedRecord { public class ChangeOtherDeviceIDPumpEvent extends TimeStampedRecord {
@ -8,16 +7,19 @@ public class ChangeOtherDeviceIDPumpEvent extends TimeStampedRecord {
public ChangeOtherDeviceIDPumpEvent() { public ChangeOtherDeviceIDPumpEvent() {
} }
@Override @Override
public int getLength() { public int getLength() {
return 37; return 37;
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Other Dev ID"; return "Ch Other Dev ID";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; 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. * Created by geoff on 6/5/16.
*/ */
public class ChangeReservoirWarningTimePumpEvent extends TimeStampedRecord { public class ChangeReservoirWarningTimePumpEvent extends TimeStampedRecord {
public ChangeReservoirWarningTimePumpEvent() { public ChangeReservoirWarningTimePumpEvent() {
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Res Warn Time"; return "Ch Res Warn Time";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; 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. * Created by geoff on 6/5/16.
*/ */
public class ChangeSensorRateOfChangeAlertSetupPumpEvent extends TimeStampedRecord { public class ChangeSensorRateOfChangeAlertSetupPumpEvent extends TimeStampedRecord {
public ChangeSensorRateOfChangeAlertSetupPumpEvent() { public ChangeSensorRateOfChangeAlertSetupPumpEvent() {
} }
@Override @Override
public int getLength() { public int getLength() {
return 12; return 12;
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Sensor ROC Alert"; return "Ch Sensor ROC Alert";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; 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. * Created by geoff on 6/5/16.
*/ */
public class ChangeSensorSetup2PumpEvent extends TimeStampedRecord { public class ChangeSensorSetup2PumpEvent extends TimeStampedRecord {
public ChangeSensorSetup2PumpEvent() { public ChangeSensorSetup2PumpEvent() {
} }
@Override @Override
public int getLength() { public int getLength() {
return 37; return 37;
} }
@Override @Override
public String getShortTypeName() { public String getShortTypeName() {
return "Ch Sensor Setup2"; return "Ch Sensor Setup2";
} }
@Override @Override
public boolean isAAPSRelevant() { public boolean isAAPSRelevant() {
return false; return false;

View file

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

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