- various changes
- reformatting everything
This commit is contained in:
parent
fcdb2f9708
commit
c9d35696cf
|
@ -193,11 +193,12 @@
|
|||
android:label="@string/title_activity_setup_wizard" />
|
||||
|
||||
<activity
|
||||
android:name=".plugins.PumpCommon.dialog.RileylinkSettingsActivity"
|
||||
android:name=".plugins.PumpCommon.hw.rileylink.dialog.RileyLinkStatusActivity"
|
||||
android:label="@string/title_activity_rileylink_settings"
|
||||
android:theme="@style/AppTheme"></activity>
|
||||
android:theme="@style/Theme.AppCompat.NoTitle" />
|
||||
|
||||
<activity android:name=".SingleFragmentActivity"
|
||||
<activity
|
||||
android:name=".SingleFragmentActivity"
|
||||
android:theme="@style/AppTheme" />
|
||||
</application>
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
import java.util.Date;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Date;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import info.nightscout.androidaps.BuildConfig;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
|
@ -46,26 +46,20 @@ import info.nightscout.utils.DecimalFormatter;
|
|||
// FIXME remove PumpDriver instances, just keep methods that do something here
|
||||
public abstract class PumpPluginAbstract extends PluginBase implements PumpInterface, ConstraintsInterface {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PumpPluginAbstract.class);
|
||||
|
||||
protected PumpDescription pumpDescription = new PumpDescription();
|
||||
protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult().success(false)
|
||||
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_supported_by_pump));
|
||||
protected static final PumpEnactResult OPERATION_NOT_YET_SUPPORTED = new PumpEnactResult().success(false)
|
||||
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_yet_supported_by_pump));
|
||||
// protected PumpStatus pumpStatusData;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PumpPluginAbstract.class);
|
||||
protected PumpDescription pumpDescription = new PumpDescription();
|
||||
protected PumpDriverInterface pumpDriver;
|
||||
protected PumpStatus pumpStatus;
|
||||
protected String internalName;
|
||||
|
||||
protected ServiceConnection serviceConnection = null;
|
||||
protected boolean serviceRunning = false;
|
||||
|
||||
|
||||
protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult()
|
||||
.success(false).enacted(false).comment(MainApp.gs(R.string.pump_operation_not_supported_by_pump));
|
||||
|
||||
protected static final PumpEnactResult OPERATION_NOT_YET_SUPPORTED = new PumpEnactResult()
|
||||
.success(false).enacted(false).comment(MainApp.gs(R.string.pump_operation_not_yet_supported_by_pump));
|
||||
|
||||
|
||||
// protected PumpPluginAbstract(PumpDriverInterface pumpDriverInterface, //
|
||||
// String internalName, //
|
||||
// String fragmentClassName, //
|
||||
|
@ -83,17 +77,14 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
// );
|
||||
// }
|
||||
|
||||
|
||||
protected PumpPluginAbstract(PumpDriverInterface pumpDriverInterface, //
|
||||
String internalName, //
|
||||
PluginDescription pluginDescription,
|
||||
PumpType pumpType //
|
||||
PluginDescription pluginDescription, PumpType pumpType //
|
||||
) {
|
||||
super(pluginDescription);
|
||||
|
||||
LOG.error("After super called.");
|
||||
|
||||
|
||||
this.pumpDriver = pumpDriverInterface;
|
||||
this.internalName = internalName;
|
||||
|
||||
|
@ -105,7 +96,6 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
|
||||
LOG.error("Before set description");
|
||||
|
||||
|
||||
LOG.error("Before pumpDriver");
|
||||
|
||||
this.pumpDriver.initDriver(this.pumpStatus, this.pumpDescription);
|
||||
|
@ -150,6 +140,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
*/
|
||||
public abstract void onStartCustomActions();
|
||||
|
||||
|
||||
/**
|
||||
* Service class (same one you did serviceConnection for)
|
||||
*
|
||||
|
@ -174,10 +165,12 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
return pumpDriver.isInitialized();
|
||||
}
|
||||
|
||||
|
||||
public boolean isSuspended() {
|
||||
return pumpDriver.isSuspended();
|
||||
}
|
||||
|
||||
|
||||
public boolean isBusy() {
|
||||
return pumpDriver.isBusy();
|
||||
}
|
||||
|
@ -238,19 +231,21 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
// return pumpDriver.deliverTreatment(detailedBolusInfo);
|
||||
// }
|
||||
|
||||
|
||||
public void stopBolusDelivering() {
|
||||
pumpDriver.stopBolusDelivering();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile,
|
||||
boolean enforceNew) {
|
||||
return pumpDriver.setTempBasalAbsolute(absoluteRate, durationInMinutes, profile, enforceNew);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile,
|
||||
boolean enforceNew) {
|
||||
return pumpDriver.setTempBasalPercent(percent, durationInMinutes, profile, enforceNew);
|
||||
}
|
||||
|
||||
|
@ -258,10 +253,11 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||
return pumpDriver.setExtendedBolus(insulin, durationInMinutes);
|
||||
}
|
||||
|
||||
|
||||
// some pumps might set a very short temp close to 100% as cancelling a temp can be noisy
|
||||
// when the cancel request is requested by the user (forced), the pump should always do a real cancel
|
||||
|
||||
|
||||
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
||||
return pumpDriver.cancelTempBasal(enforceNew);
|
||||
}
|
||||
|
@ -272,28 +268,27 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
return OPERATION_NOT_YET_SUPPORTED;
|
||||
}
|
||||
|
||||
// Status to be passed to NS
|
||||
|
||||
// Status to be passed to NS
|
||||
|
||||
// public JSONObject getJSONStatus(Profile profile, String profileName) {
|
||||
// return pumpDriver.getJSONStatus(profile, profileName);
|
||||
// }
|
||||
|
||||
|
||||
public String deviceID() {
|
||||
LOG.warn("deviceID [PumpPluginAbstract] - Not implemented.");
|
||||
return "FakeDevice";
|
||||
}
|
||||
|
||||
// Pump capabilities
|
||||
|
||||
// Pump capabilities
|
||||
|
||||
public PumpDescription getPumpDescription() {
|
||||
return pumpDescription;
|
||||
}
|
||||
|
||||
// Short info for SMS, Wear etc
|
||||
|
||||
// Short info for SMS, Wear etc
|
||||
|
||||
public boolean isFakingTempsByExtendedBoluses() {
|
||||
LOG.warn("isFakingTempsByExtendedBoluses [PumpPluginAbstract] - Not implemented.");
|
||||
|
@ -306,6 +301,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
return this.pumpDriver.loadTDDs();
|
||||
}
|
||||
|
||||
|
||||
// Constraints interface
|
||||
|
||||
// @Override
|
||||
|
@ -363,7 +359,6 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
// return maxIob;
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public JSONObject getJSONStatus(Profile profile, String profileName) {
|
||||
|
||||
|
@ -387,7 +382,8 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
|
||||
TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (tb != null) {
|
||||
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(System.currentTimeMillis(), profile));
|
||||
extended.put("TempBasalAbsoluteRate",
|
||||
tb.tempBasalConvertedToAbsolute(System.currentTimeMillis(), profile));
|
||||
extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
|
||||
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
|
||||
}
|
||||
|
@ -412,6 +408,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
return pump;
|
||||
}
|
||||
|
||||
|
||||
// FIXME i18n, null checks: iob, TDD
|
||||
@Override
|
||||
public String shortStatus(boolean veryShort) {
|
||||
|
@ -425,16 +422,19 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pumpStatus.lastBolusAmount) + "U @" + //
|
||||
android.text.format.DateFormat.format("HH:mm", pumpStatus.lastBolusTime) + "\n";
|
||||
}
|
||||
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis());
|
||||
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin()
|
||||
.getRealTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (activeTemp != null) {
|
||||
ret += "Temp: " + activeTemp.toStringFull() + "\n";
|
||||
}
|
||||
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(
|
||||
System.currentTimeMillis());
|
||||
if (activeExtendedBolus != null) {
|
||||
ret += "Extended: " + activeExtendedBolus.toString() + "\n";
|
||||
}
|
||||
if (!veryShort) {
|
||||
ret += "TDD: " + DecimalFormatter.to0Decimal(pumpStatus.dailyTotalUnits) + " / " + pumpStatus.maxDailyTotalUnits + " U\n";
|
||||
ret += "TDD: " + DecimalFormatter.to0Decimal(pumpStatus.dailyTotalUnits) + " / "
|
||||
+ pumpStatus.maxDailyTotalUnits + " U\n";
|
||||
}
|
||||
ret += "IOB: " + pumpStatus.iob + "U\n";
|
||||
ret += "Reserv: " + DecimalFormatter.to0Decimal(pumpStatus.reservoirRemainingUnits) + "U\n";
|
||||
|
@ -450,8 +450,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
if (detailedBolusInfo.insulin == 0 && detailedBolusInfo.carbs == 0) {
|
||||
// neither carbs nor bolus requested
|
||||
LOG.error("deliverTreatment: Invalid input");
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
.bolusDelivered(0d).carbsDelivered(0d)
|
||||
return new PumpEnactResult().success(false).enacted(false).bolusDelivered(0d).carbsDelivered(0d)
|
||||
.comment(MainApp.gs(R.string.danar_invalidinput));
|
||||
} else if (detailedBolusInfo.insulin > 0) {
|
||||
// bolus needed, ask pump to deliver it
|
||||
|
@ -468,9 +467,8 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
|
||||
LOG.debug("deliverTreatment: Carb only treatment.");
|
||||
|
||||
return new PumpEnactResult().success(true).enacted(true)
|
||||
.bolusDelivered(0d).carbsDelivered(detailedBolusInfo.carbs)
|
||||
.comment(MainApp.gs(R.string.virtualpump_resultok));
|
||||
return new PumpEnactResult().success(true).enacted(true).bolusDelivered(0d)
|
||||
.carbsDelivered(detailedBolusInfo.carbs).comment(MainApp.gs(R.string.virtualpump_resultok));
|
||||
}
|
||||
} finally {
|
||||
triggerUIChange();
|
||||
|
@ -486,11 +484,9 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
|
||||
|
||||
public PumpEnactResult getOperationNotSupportedWithCustomText(int resourceId) {
|
||||
return new PumpEnactResult()
|
||||
.success(false).enacted(false).comment(MainApp.gs(resourceId));
|
||||
return new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(resourceId));
|
||||
}
|
||||
|
||||
|
||||
// Profile interface
|
||||
|
||||
// @Nullable
|
||||
|
@ -506,5 +502,4 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
// return this.pumpStatus.activeProfileName;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ public class DoseSettings {
|
|||
private float minDose;
|
||||
private Float maxDose;
|
||||
|
||||
public DoseSettings(float step, int durationStep, int maxDuration, float minDose, Float maxDose)
|
||||
{
|
||||
|
||||
public DoseSettings(float step, int durationStep, int maxDuration, float minDose, Float maxDose) {
|
||||
this.step = step;
|
||||
this.durationStep = durationStep;
|
||||
this.maxDuration = maxDuration;
|
||||
|
@ -21,8 +21,8 @@ public class DoseSettings {
|
|||
this.maxDose = maxDose;
|
||||
}
|
||||
|
||||
public DoseSettings(float step, int durationStep, int maxDuration, float minDose)
|
||||
{
|
||||
|
||||
public DoseSettings(float step, int durationStep, int maxDuration, float minDose) {
|
||||
this(step, durationStep, maxDuration, minDose, null);
|
||||
}
|
||||
|
||||
|
@ -31,18 +31,22 @@ public class DoseSettings {
|
|||
return step;
|
||||
}
|
||||
|
||||
|
||||
public int getDurationStep() {
|
||||
return durationStep;
|
||||
}
|
||||
|
||||
|
||||
public int getMaxDuration() {
|
||||
return maxDuration;
|
||||
}
|
||||
|
||||
|
||||
public float getMinDose() {
|
||||
return minDose;
|
||||
}
|
||||
|
||||
|
||||
public Float getMaxDose() {
|
||||
return maxDose;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package info.nightscout.androidaps.plugins.PumpCommon.data;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import org.joda.time.LocalDateTime;
|
||||
|
||||
import info.nightscout.androidaps.data.ProfileStore;
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpStatusType;
|
||||
|
@ -14,7 +16,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
|
|||
public abstract class PumpStatus {
|
||||
|
||||
// connection
|
||||
public Date lastDataTime;
|
||||
public LocalDateTime lastDataTime;
|
||||
public long lastConnection = 0L;
|
||||
|
||||
// last bolus
|
||||
|
@ -33,18 +35,11 @@ public abstract class PumpStatus {
|
|||
// TDD
|
||||
public Double dailyTotalUnits;
|
||||
public String maxDailyTotalUnits;
|
||||
|
||||
|
||||
protected PumpDescription pumpDescription;
|
||||
public boolean validBasalRateProfileSelectedOnPump = true;
|
||||
|
||||
public PumpType pumpType = PumpType.GenericAAPS;
|
||||
|
||||
|
||||
public ProfileStore profileStore;
|
||||
public String units; // Constants.MGDL or Constants.MMOL
|
||||
public PumpStatusType pumpStatusType = PumpStatusType.Running;
|
||||
|
||||
// TODO maybe not needed anymore in 2.0
|
||||
public Double constraintBasalRateAbsolute;
|
||||
public Integer constraintBasalRatePercent;
|
||||
|
@ -52,6 +47,14 @@ public abstract class PumpStatus {
|
|||
public Integer constraintCarbs;
|
||||
public Double constraintMaxIob;
|
||||
public Double[] basalsByHour;
|
||||
// public double remainUnits = 0;
|
||||
public int remainBattery = 0;
|
||||
public double currentBasal = 0;
|
||||
public int tempBasalInProgress = 0;
|
||||
public int tempBasalRatio = 0;
|
||||
public int tempBasalRemainMin = 0;
|
||||
public Date tempBasalStart;
|
||||
protected PumpDescription pumpDescription;
|
||||
|
||||
|
||||
public PumpStatus(PumpDescription pumpDescription) {
|
||||
|
@ -61,29 +64,6 @@ public abstract class PumpStatus {
|
|||
}
|
||||
|
||||
|
||||
public abstract void initSettings();
|
||||
|
||||
|
||||
public void setLastCommunicationToNow() {
|
||||
this.lastDataTime = new Date();
|
||||
this.lastConnection = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
public abstract String getErrorInfo();
|
||||
|
||||
|
||||
public abstract void refreshConfiguration();
|
||||
|
||||
|
||||
public PumpType getPumpType() {
|
||||
return pumpType;
|
||||
}
|
||||
|
||||
public void setPumpType(PumpType pumpType) {
|
||||
this.pumpType = pumpType;
|
||||
}
|
||||
|
||||
// FIXME cleanup this is from RT2
|
||||
|
||||
// public long getTimeIndex() {
|
||||
|
@ -98,18 +78,31 @@ public abstract class PumpStatus {
|
|||
//
|
||||
// public Date time;
|
||||
|
||||
//public double remainUnits = 0;
|
||||
public int remainBattery = 0;
|
||||
public abstract void initSettings();
|
||||
|
||||
public double currentBasal = 0;
|
||||
|
||||
public int tempBasalInProgress = 0;
|
||||
public int tempBasalRatio = 0;
|
||||
public int tempBasalRemainMin = 0;
|
||||
public Date tempBasalStart;
|
||||
public void setLastCommunicationToNow() {
|
||||
this.lastDataTime = LocalDateTime.now();
|
||||
this.lastConnection = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
public abstract String getErrorInfo();
|
||||
|
||||
|
||||
public abstract void refreshConfiguration();
|
||||
|
||||
|
||||
public PumpType getPumpType() {
|
||||
return pumpType;
|
||||
}
|
||||
|
||||
|
||||
public void setPumpType(PumpType pumpType) {
|
||||
this.pumpType = pumpType;
|
||||
}
|
||||
|
||||
// public Date last_bolus_time;
|
||||
// public double last_bolus_amount = 0;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,7 @@ package info.nightscout.androidaps.plugins.PumpCommon.defs;
|
|||
* Created by andy on 02/05/2018.
|
||||
*/
|
||||
|
||||
public enum DoseStepSize
|
||||
{
|
||||
public enum DoseStepSize {
|
||||
|
||||
ComboBasal( //
|
||||
new DoseStepSizeEntry(0f, 1f, 0.01f), //
|
||||
|
@ -19,18 +18,15 @@ public enum DoseStepSize
|
|||
|
||||
;
|
||||
|
||||
|
||||
DoseStepSizeEntry[] entries;
|
||||
|
||||
|
||||
DoseStepSize(DoseStepSizeEntry...entries)
|
||||
{
|
||||
DoseStepSize(DoseStepSizeEntry... entries) {
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
|
||||
public float getStepSizeForAmount(float amount)
|
||||
{
|
||||
public float getStepSizeForAmount(float amount) {
|
||||
for (DoseStepSizeEntry entry : entries) {
|
||||
if (entry.from <= amount && entry.to > amount)
|
||||
return entry.value;
|
||||
|
@ -51,12 +47,9 @@ public enum DoseStepSize
|
|||
sb.append(entry.from);
|
||||
sb.append("-");
|
||||
|
||||
if (entry.to == Float.MAX_VALUE)
|
||||
{
|
||||
if (entry.to == Float.MAX_VALUE) {
|
||||
sb.append("~}");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sb.append(entry.to);
|
||||
sb.append("}, ");
|
||||
}
|
||||
|
@ -65,16 +58,16 @@ public enum DoseStepSize
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
static class DoseStepSizeEntry {
|
||||
|
||||
static class DoseStepSizeEntry
|
||||
{
|
||||
float from;
|
||||
float to;
|
||||
float value;
|
||||
|
||||
// to = this value is not included, but would actually mean <, so for rates between 0.025-0.975 u/h, we would have [from=0, to=10]
|
||||
DoseStepSizeEntry(float from, float to, float value)
|
||||
{
|
||||
|
||||
// to = this value is not included, but would actually mean <, so for rates between 0.025-0.975 u/h, we would
|
||||
// have [from=0, to=10]
|
||||
DoseStepSizeEntry(float from, float to, float value) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.value = value;
|
||||
|
|
|
@ -16,7 +16,6 @@ public enum PumpCapability {
|
|||
// grouped
|
||||
VirtualPump(Bolus, ExtendedBolus, TBR, BasalProfileSet, StoreCarbInfo), //
|
||||
|
||||
|
||||
Bolus_TBR_Basal_Refill_Carb(Bolus, TBR, BasalProfileSet, Refill, StoreCarbInfo), //
|
||||
Bolus_Extended_TBR_Basal_Carb(Bolus, ExtendedBolus, TBR, BasalProfileSet, StoreCarbInfo), //
|
||||
Bolus_Extended_TBR_Basal_Refill_Carb(Bolus, ExtendedBolus, TBR, BasalProfileSet, Refill, StoreCarbInfo), //
|
||||
|
@ -54,5 +53,4 @@ public enum PumpCapability {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,10 +11,12 @@ public enum PumpStatusType {
|
|||
|
||||
private String statusString;
|
||||
|
||||
|
||||
PumpStatusType(String statusString) {
|
||||
this.statusString = statusString;
|
||||
}
|
||||
|
||||
|
||||
public String getStatus() {
|
||||
return statusString;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.defs;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.data.DoseSettings;
|
||||
|
||||
|
||||
/**
|
||||
* Created by andy on 02/05/2018.
|
||||
* <p>
|
||||
|
@ -30,26 +28,22 @@ public enum PumpType {
|
|||
// Cellnovo
|
||||
|
||||
Cellnovo1("Cellnovo", 0.05f, null, //
|
||||
new DoseSettings(0.05f, 30, 24 * 60, 1f, null),
|
||||
PumpTempBasalType.Percent,
|
||||
new DoseSettings(5, 30, 24 * 60, 0f, 200f), //
|
||||
new DoseSettings(0.05f, 30, 24 * 60, 1f, null), PumpTempBasalType.Percent, new DoseSettings(5, 30, 24 * 60, 0f,
|
||||
200f), //
|
||||
0.05f, 0.05f, null, PumpCapability.VirtualPump), //
|
||||
|
||||
// Accu-Chek
|
||||
|
||||
AccuChekCombo("Accu-Chek Combo", 0.1f, null, //
|
||||
new DoseSettings(0.1f, 15, 12 * 60, 0.1f), //
|
||||
PumpTempBasalType.Percent,
|
||||
new DoseSettings(10, 15, 12 * 60, 0f, 500f), //
|
||||
PumpTempBasalType.Percent, new DoseSettings(10, 15, 12 * 60, 0f, 500f), //
|
||||
0.01f, 0.1f, DoseStepSize.ComboBasal, PumpCapability.Bolus_TBR_Basal_Refill_Carb), //
|
||||
|
||||
AccuChekSpirit("Accu-Chek Spirit", 0.1f, null, //
|
||||
new DoseSettings(0.1f, 15, 12 * 60, 0.1f), //
|
||||
PumpTempBasalType.Percent,
|
||||
new DoseSettings(10, 15, 12 * 60, 0f, 500f), //
|
||||
PumpTempBasalType.Percent, new DoseSettings(10, 15, 12 * 60, 0f, 500f), //
|
||||
0.01f, 0.1f, null, PumpCapability.VirtualPump), //
|
||||
|
||||
|
||||
// Animas
|
||||
AnimasVibe("Animas Vibe", 0.05f, null, // AnimasBolus?
|
||||
new DoseSettings(0.05f, 30, 12 * 60, 0.05f), //
|
||||
|
@ -75,7 +69,6 @@ public enum PumpType {
|
|||
DanaRS("DanaRS", DanaR),
|
||||
DanaRv2("DanaRv2", DanaR),
|
||||
|
||||
|
||||
// Insulet
|
||||
Insulet_Omnipod("Insulet Omnipod", 0.05f, null, //
|
||||
new DoseSettings(0.05f, 30, 8 * 60, 0.05f), //
|
||||
|
@ -109,9 +102,7 @@ public enum PumpType {
|
|||
|
||||
// Tandem
|
||||
TandemTSlim("Tandem t:slim", 0.01f, null, //
|
||||
new DoseSettings(0.01f, 15, 8 * 60, 0.4f),
|
||||
PumpTempBasalType.Percent,
|
||||
new DoseSettings(1, 15, 8 * 60, 0f, 250f), //
|
||||
new DoseSettings(0.01f, 15, 8 * 60, 0.4f), PumpTempBasalType.Percent, new DoseSettings(1, 15, 8 * 60, 0f, 250f), //
|
||||
0.1f, 0.001f, null, PumpCapability.VirtualPump),
|
||||
|
||||
TandemTFlex("Tandem t:flex", TandemTSlim), //
|
||||
|
@ -119,6 +110,16 @@ public enum PumpType {
|
|||
TandemTSlimX2("Tandem t:slim X2", TandemTSlim), //
|
||||
;
|
||||
|
||||
private static Map<String, PumpType> mapByDescription;
|
||||
|
||||
static {
|
||||
mapByDescription = new HashMap<>();
|
||||
|
||||
for (PumpType pumpType : values()) {
|
||||
mapByDescription.put(pumpType.getDescription(), pumpType);
|
||||
}
|
||||
}
|
||||
|
||||
private String description;
|
||||
private float bolusSize;
|
||||
private DoseStepSize specialBolusSize;
|
||||
|
@ -130,17 +131,7 @@ public enum PumpType {
|
|||
private float baseBasalStep; //
|
||||
private DoseStepSize baseBasalSpecialSteps; //
|
||||
private PumpCapability pumpCapability;
|
||||
|
||||
private PumpType parent;
|
||||
private static Map<String, PumpType> mapByDescription;
|
||||
|
||||
static {
|
||||
mapByDescription = new HashMap<>();
|
||||
|
||||
for (PumpType pumpType : values()) {
|
||||
mapByDescription.put(pumpType.getDescription(), pumpType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PumpType(String description, PumpType parent) {
|
||||
|
@ -148,23 +139,33 @@ public enum PumpType {
|
|||
this.parent = parent;
|
||||
}
|
||||
|
||||
|
||||
PumpType(String description, PumpType parent, PumpCapability pumpCapability) {
|
||||
this.description = description;
|
||||
this.parent = parent;
|
||||
this.pumpCapability = pumpCapability;
|
||||
}
|
||||
|
||||
PumpType(String description, float bolusSize, DoseStepSize specialBolusSize, //
|
||||
|
||||
PumpType(String description, float bolusSize,
|
||||
DoseStepSize specialBolusSize, //
|
||||
DoseSettings extendedBolusSettings, //
|
||||
PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, //
|
||||
float baseBasalMinValue, float baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) {
|
||||
this(description, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType, tbrSettings, baseBasalMinValue, null, baseBasalStep, baseBasalSpecialSteps, pumpCapability);
|
||||
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, //
|
||||
|
||||
PumpType(String description, float bolusSize,
|
||||
DoseStepSize specialBolusSize, //
|
||||
DoseSettings extendedBolusSettings, //
|
||||
PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, //
|
||||
float baseBasalMinValue, Float baseBasalMaxValue, float baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) {
|
||||
PumpTempBasalType pumpTempBasalType,
|
||||
DoseSettings tbrSettings, //
|
||||
float baseBasalMinValue, Float baseBasalMaxValue, float baseBasalStep, DoseStepSize baseBasalSpecialSteps,
|
||||
PumpCapability pumpCapability) {
|
||||
this.description = description;
|
||||
this.bolusSize = bolusSize;
|
||||
this.specialBolusSize = specialBolusSize;
|
||||
|
@ -179,10 +180,20 @@ public enum PumpType {
|
|||
}
|
||||
|
||||
|
||||
public static PumpType getByDescription(String desc) {
|
||||
if (mapByDescription.containsKey(desc)) {
|
||||
return mapByDescription.get(desc);
|
||||
} else {
|
||||
return PumpType.GenericAAPS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
public PumpCapability getPumpCapability() {
|
||||
|
||||
if (isParentSet())
|
||||
|
@ -191,6 +202,7 @@ public enum PumpType {
|
|||
return this.pumpCapability;
|
||||
}
|
||||
|
||||
|
||||
public float getBolusSize() {
|
||||
return isParentSet() ? parent.bolusSize : bolusSize;
|
||||
}
|
||||
|
@ -246,15 +258,6 @@ public enum PumpType {
|
|||
}
|
||||
|
||||
|
||||
public static PumpType getByDescription(String desc) {
|
||||
if (mapByDescription.containsKey(desc)) {
|
||||
return mapByDescription.get(desc);
|
||||
} else {
|
||||
return PumpType.GenericAAPS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getFullDescription(String i18nTemplate) {
|
||||
|
||||
String unit = getPumpTempBasalType() == PumpTempBasalType.Percent ? "%" : "";
|
||||
|
@ -262,11 +265,14 @@ public enum PumpType {
|
|||
DoseSettings eb = getExtendedBolusSettings();
|
||||
DoseSettings tbr = getTbrSettings();
|
||||
|
||||
return String.format(i18nTemplate, //
|
||||
return String.format(
|
||||
i18nTemplate, //
|
||||
getStep("" + getBolusSize(), getSpecialBolusSize()), //
|
||||
eb.getStep(), eb.getDurationStep(), eb.getMaxDuration() / 60, //
|
||||
eb.getStep(), eb.getDurationStep(),
|
||||
eb.getMaxDuration() / 60, //
|
||||
getStep(getBaseBasalRange(), getBaseBasalSpecialSteps()), //
|
||||
tbr.getMinDose() + unit + "-" + tbr.getMaxDose() + unit, tbr.getStep() + unit, tbr.getDurationStep(), tbr.getMaxDuration() / 60);
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.dialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import android.Manifest;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
|
@ -33,38 +39,75 @@ import android.widget.ListView;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkConst;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.utils.LocationHelper;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
|
||||
public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RileyLinkBLEScanActivity.class);
|
||||
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private BluetoothLeScanner mLEScanner;
|
||||
private LeDeviceListAdapter mLeDeviceListAdapter;
|
||||
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 30241; // arbitrary.
|
||||
private static final int REQUEST_ENABLE_BT = 30242; // arbitrary
|
||||
// Stops scanning after 10 seconds.
|
||||
private static final long SCAN_PERIOD = 30000;
|
||||
public boolean mScanning;
|
||||
private Handler mHandler;
|
||||
public Snackbar snackbar;
|
||||
public ScanSettings settings;
|
||||
public List<ScanFilter> filters;
|
||||
public ListView listBTScan;
|
||||
public Toolbar toolbarBTScan;
|
||||
public Context mContext = this;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private BluetoothLeScanner mLEScanner;
|
||||
private LeDeviceListAdapter mLeDeviceListAdapter;
|
||||
private Handler mHandler;
|
||||
private ScanCallback mScanCallback = new ScanCallback() {
|
||||
|
||||
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 30241; // arbitrary.
|
||||
private static final int REQUEST_ENABLE_BT = 30242; // arbitrary
|
||||
// Stops scanning after 10 seconds.
|
||||
private static final long SCAN_PERIOD = 30000;
|
||||
@Override
|
||||
public void onScanResult(int callbackType, ScanResult result) {
|
||||
final BluetoothDevice device = result.getDevice();
|
||||
runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (device.getName() != null && device.getName().length() > 0) {
|
||||
mLeDeviceListAdapter.addDevice(device);
|
||||
mLeDeviceListAdapter.notifyDataSetChanged();
|
||||
LOG.debug("Found BLE" + device.getName());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBatchScanResults(final List<ScanResult> results) {
|
||||
runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (ScanResult result : results) {
|
||||
BluetoothDevice device = result.getDevice();
|
||||
if (device.getName() != null && device.getName().length() > 0) {
|
||||
mLeDeviceListAdapter.addDevice(device);
|
||||
LOG.debug("Found BLE" + result.toString());
|
||||
} else {
|
||||
LOG.error("Found BLE, but name appears to be missing. Ignoring. " + device.getAddress());
|
||||
}
|
||||
}
|
||||
mLeDeviceListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onScanFailed(int errorCode) {
|
||||
Log.e("Scan Failed", "Error Code: " + errorCode);
|
||||
Toast.makeText(mContext, "Scan Failed " + errorCode, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -80,6 +123,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
|||
listBTScan = (ListView)findViewById(R.id.rileylink_listBTScan);
|
||||
listBTScan.setAdapter(mLeDeviceListAdapter);
|
||||
listBTScan.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
TextView textview = (TextView)view.findViewById(R.id.rileylink_device_address);
|
||||
|
@ -104,6 +148,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
|||
|
||||
snackbar = Snackbar.make(findViewById(R.id.RileyLinkScan), "Scanning...", Snackbar.LENGTH_INDEFINITE);
|
||||
snackbar.setAction("STOP", new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
scanLeDevice(false);
|
||||
|
@ -152,7 +197,8 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
|||
// you can selectively disable BLE-related features.
|
||||
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
// your code that requires permission
|
||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION);
|
||||
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
|
||||
PERMISSION_REQUEST_COARSE_LOCATION);
|
||||
}
|
||||
|
||||
// Ensures Bluetooth is available on the device and it is enabled. If not,
|
||||
|
@ -197,6 +243,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
|||
if (enable) {
|
||||
// Stops scanning after a pre-defined scan period.
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mScanning = false;
|
||||
|
@ -223,53 +270,14 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
static class ViewHolder {
|
||||
|
||||
private ScanCallback mScanCallback = new ScanCallback() {
|
||||
@Override
|
||||
public void onScanResult(int callbackType, ScanResult result) {
|
||||
final BluetoothDevice device = result.getDevice();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (device.getName() != null && device.getName().length() > 0) {
|
||||
mLeDeviceListAdapter.addDevice(device);
|
||||
mLeDeviceListAdapter.notifyDataSetChanged();
|
||||
LOG.debug("Found BLE" + device.getName());
|
||||
TextView deviceName;
|
||||
TextView deviceAddress;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@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 ArrayList<BluetoothDevice> mLeDevices;
|
||||
private LayoutInflater mInflator;
|
||||
|
||||
|
@ -347,10 +355,4 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static class ViewHolder {
|
||||
TextView deviceName;
|
||||
TextView deviceAddress;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
|
@ -14,18 +14,18 @@ import info.nightscout.androidaps.plugins.PumpCommon.data.PumpStatus;
|
|||
|
||||
public abstract class PumpDriverAbstract implements PumpDriverInterface {
|
||||
|
||||
protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult().success(false)
|
||||
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_supported_by_pump));
|
||||
protected static final PumpEnactResult OPERATION_NOT_YET_SUPPORTED = new PumpEnactResult().success(false)
|
||||
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_yet_supported_by_pump));
|
||||
protected PumpDescription pumpDescription;
|
||||
protected PumpStatus pumpStatusData;
|
||||
|
||||
protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult()
|
||||
.success(false).enacted(false).comment(MainApp.gs(R.string.pump_operation_not_supported_by_pump));
|
||||
|
||||
protected static final PumpEnactResult OPERATION_NOT_YET_SUPPORTED = new PumpEnactResult()
|
||||
.success(false).enacted(false).comment(MainApp.gs(R.string.pump_operation_not_yet_supported_by_pump));
|
||||
|
||||
protected PumpDriverAbstract() {
|
||||
}
|
||||
|
||||
|
||||
public void initDriver(PumpStatus pumpStatus, PumpDescription pumpDescription) {
|
||||
this.pumpDescription = pumpDescription;
|
||||
this.pumpStatusData = pumpStatus;
|
||||
|
@ -43,6 +43,7 @@ public abstract class PumpDriverAbstract implements PumpDriverInterface {
|
|||
return this.pumpStatusData;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PumpDescription getPumpDescription() {
|
||||
return pumpDescription;
|
||||
|
@ -55,6 +56,6 @@ public abstract class PumpDriverAbstract implements PumpDriverInterface {
|
|||
return new Date();
|
||||
}
|
||||
|
||||
return this.pumpStatusData.lastDataTime;
|
||||
return this.pumpStatusData.lastDataTime.toDate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ public interface PumpDriverInterface extends PumpInterface {
|
|||
|
||||
void initDriver(PumpStatus pumpStatus, PumpDescription pumpDescription);
|
||||
|
||||
|
||||
PumpStatus getPumpStatusData();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.data.PumpStatus;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RFSpy;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.FrequencyScanResults;
|
||||
|
@ -23,7 +23,6 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState;
|
|||
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
|
||||
/**
|
||||
* This is abstract class for RileyLink Communication, this one needs to be extended by specific "Pump" class.
|
||||
* <p>
|
||||
|
@ -35,20 +34,23 @@ public abstract class RileyLinkCommunicationManager {
|
|||
|
||||
protected final RFSpy rfspy;
|
||||
protected final Context context;
|
||||
|
||||
private double[] scanFrequencies;
|
||||
|
||||
protected int receiverDeviceAwakeForMinutes = 1; // override this in constructor of specific implementation
|
||||
protected String receiverDeviceID; // String representation of receiver device (ex. Pump (xxxxxx) or Pod (yyyyyy))
|
||||
protected long lastGoodReceiverCommunicationTime = 0;
|
||||
protected PumpStatus pumpStatus;
|
||||
protected RileyLinkServiceData rileyLinkServiceData;
|
||||
|
||||
protected RileyLinkTargetFrequency targetFrequency;
|
||||
private double[] scanFrequencies;
|
||||
// internal flag
|
||||
private boolean showPumpMessages = true;
|
||||
protected RileyLinkTargetFrequency targetFrequency;
|
||||
private int timeoutCount = 0;
|
||||
private long nextWakeUpRequired = 0L;
|
||||
|
||||
|
||||
// protected PumpMessage sendAndListen(RLMessage msg) {
|
||||
// return sendAndListen(msg, 4000); // 2000
|
||||
// }
|
||||
|
||||
public RileyLinkCommunicationManager(Context context, RFSpy rfspy, RileyLinkTargetFrequency targetFrequency) {
|
||||
this.context = context;
|
||||
this.rfspy = rfspy;
|
||||
|
@ -64,14 +66,6 @@ public abstract class RileyLinkCommunicationManager {
|
|||
protected abstract void configurePumpSpecificSettings();
|
||||
|
||||
|
||||
// protected PumpMessage sendAndListen(RLMessage msg) {
|
||||
// return sendAndListen(msg, 4000); // 2000
|
||||
// }
|
||||
|
||||
|
||||
private int timeoutCount = 0;
|
||||
|
||||
|
||||
// All pump communications go through this function.
|
||||
protected <E extends RLMessage> E sendAndListen(RLMessage msg, int timeout_ms, Class<E> clazz) {
|
||||
|
||||
|
@ -94,7 +88,8 @@ public abstract class RileyLinkCommunicationManager {
|
|||
timeoutCount++;
|
||||
|
||||
if (timeoutCount >= 5) {
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.NoContactWithDevice);
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError,
|
||||
RileyLinkError.NoContactWithDevice);
|
||||
timeoutCount = 0;
|
||||
tuneForDevice();
|
||||
// RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_quickTune);
|
||||
|
@ -118,9 +113,6 @@ public abstract class RileyLinkCommunicationManager {
|
|||
}
|
||||
|
||||
|
||||
private long nextWakeUpRequired = 0L;
|
||||
|
||||
|
||||
public int getNotConnectedCount() {
|
||||
return rfspy != null ? rfspy.notConnectedCount : 0;
|
||||
}
|
||||
|
@ -142,7 +134,8 @@ public abstract class RileyLinkCommunicationManager {
|
|||
LOG.info("Waking pump...");
|
||||
|
||||
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData); // simple
|
||||
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 200, (byte) 0, (byte) 0, 25000, (byte) 0);
|
||||
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte)0, (byte)200,
|
||||
(byte)0, (byte)0, 25000, (byte)0);
|
||||
LOG.info("wakeup: raw response is " + ByteUtil.shortHexString(resp.getRaw()));
|
||||
|
||||
// FIXME wakeUp successful !!!!!!!!!!!!!!!!!!
|
||||
|
@ -152,14 +145,14 @@ public abstract class RileyLinkCommunicationManager {
|
|||
LOG.trace("Last pump communication was recent, not waking pump.");
|
||||
}
|
||||
|
||||
|
||||
// long lastGoodPlus = getLastGoodReceiverCommunicationTime() + (receiverDeviceAwakeForMinutes * 60 * 1000);
|
||||
//
|
||||
// if (System.currentTimeMillis() > lastGoodPlus || force) {
|
||||
// LOG.info("Waking pump...");
|
||||
//
|
||||
// byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.PowerOn);
|
||||
// RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 200, (byte) 0, (byte) 0, 15000, (byte) 0);
|
||||
// RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 200, (byte)
|
||||
// 0, (byte) 0, 15000, (byte) 0);
|
||||
// LOG.info("wakeup: raw response is " + ByteUtil.shortHexString(resp.getRaw()));
|
||||
// } else {
|
||||
// LOG.trace("Last pump communication was recent, not waking pump.");
|
||||
|
@ -178,7 +171,8 @@ public abstract class RileyLinkCommunicationManager {
|
|||
|
||||
|
||||
/**
|
||||
* If user changes pump and one pump is running in US freq, and other in WW, then previously set frequency would be invalid,
|
||||
* If user changes pump and one pump is running in US freq, and other in WW, then previously set frequency would be
|
||||
* invalid,
|
||||
* so we would need to retune. This checks that saved frequency is correct range.
|
||||
*
|
||||
* @param frequency
|
||||
|
@ -217,7 +211,8 @@ public abstract class RileyLinkCommunicationManager {
|
|||
for (int j = 0; j < tries; j++) {
|
||||
|
||||
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData);
|
||||
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte) 0, (byte) 0, (byte) 0, (byte) 0, 1500, (byte) 0);
|
||||
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte)0, (byte)0,
|
||||
(byte)0, (byte)0, 1500, (byte)0);
|
||||
if (resp.wasTimeout()) {
|
||||
LOG.error("scanForPump: Failed to find pump at frequency {}", frequencies[i]);
|
||||
} else if (resp.looksLikeRadioPacket()) {
|
||||
|
@ -238,13 +233,13 @@ public abstract class RileyLinkCommunicationManager {
|
|||
results.trials.add(trial);
|
||||
}
|
||||
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder("Scan results:\n");
|
||||
|
||||
for (int k = 0; k < results.trials.size(); k++) {
|
||||
FrequencyTrial one = results.trials.get(k);
|
||||
|
||||
stringBuilder.append(String.format("Scan Result[%s]: Freq=%s, avg RSSI = %s\n", "" + k, "" + one.frequencyMHz, "" + one.averageRSSI));
|
||||
stringBuilder.append(String.format("Scan Result[%s]: Freq=%s, avg RSSI = %s\n", "" + k, ""
|
||||
+ one.frequencyMHz, "" + one.averageRSSI));
|
||||
}
|
||||
|
||||
LOG.debug(stringBuilder.toString());
|
||||
|
@ -271,7 +266,7 @@ public abstract class RileyLinkCommunicationManager {
|
|||
// RLMessage msg = makeRLMessage(RLMessageType.ReadSimpleData);
|
||||
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData);
|
||||
RadioPacket pkt = new RadioPacket(pumpMsgContent);
|
||||
RFSpyResponse resp = rfspy.transmitThenReceive(pkt, (byte) 0, (byte) 0, (byte) 0, (byte) 0, rfspy.EXPECTED_MAX_BLUETOOTH_LATENCY_MS, (byte) 0);
|
||||
RFSpyResponse resp = rfspy.transmitThenReceive(pkt, (byte)0, (byte)0, (byte)0, (byte)0, 1500, (byte)0);
|
||||
if (resp.wasTimeout()) {
|
||||
LOG.warn("tune_tryFrequency: no pump response at frequency {}", freqMHz);
|
||||
} else if (resp.looksLikeRadioPacket()) {
|
||||
|
@ -280,7 +275,8 @@ public abstract class RileyLinkCommunicationManager {
|
|||
LOG.warn("tune_tryFrequency: saw response level {} at frequency {}", radioResponse.rssi, freqMHz);
|
||||
return radioResponse.rssi;
|
||||
} else {
|
||||
LOG.warn("tune_tryFrequency: invalid radio response:" + ByteUtil.shortHexString(radioResponse.getPayload()));
|
||||
LOG.warn("tune_tryFrequency: invalid radio response:"
|
||||
+ ByteUtil.shortHexString(radioResponse.getPayload()));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -35,6 +35,7 @@ public class RileyLinkConst {
|
|||
}
|
||||
|
||||
public class IPC {
|
||||
|
||||
// needs to br renamed (and maybe removed)
|
||||
public static final String MSG_PUMP_quickTune = Prefix + "MSG_PUMP_quickTune";
|
||||
public static final String MSG_PUMP_tunePump = Prefix + "MSG_PUMP_tunePump";
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE;
|
||||
|
@ -16,6 +16,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.Riley
|
|||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.data.RLHistoryItem;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkError;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkServiceState;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkTargetDevice;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.RileyLinkService;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.RileyLinkServiceData;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.data.ServiceNotification;
|
||||
|
@ -25,7 +26,6 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.
|
|||
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.events.EventMedtronicDeviceStatusChange;
|
||||
|
||||
|
||||
/**
|
||||
* Created by andy on 17/05/2018.
|
||||
*/
|
||||
|
@ -33,22 +33,23 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.events.EventMedtronicDev
|
|||
public class RileyLinkUtil {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RileyLinkUtil.class);
|
||||
|
||||
protected static List<RLHistoryItem> historyRileyLink = new ArrayList<>();
|
||||
protected static RileyLinkCommunicationManager rileyLinkCommunicationManager;
|
||||
static ServiceTask currentTask;
|
||||
private static Context context;
|
||||
private static RileyLinkBLE rileyLinkBLE;
|
||||
private static RileyLinkServiceData rileyLinkServiceData;
|
||||
private static List<RLHistoryItem> historyRileyLink = new ArrayList<>();
|
||||
// private static PumpType pumpType;
|
||||
// private static MedtronicPumpStatus medtronicPumpStatus;
|
||||
private static RileyLinkService rileyLinkService;
|
||||
protected static RileyLinkCommunicationManager rileyLinkCommunicationManager;
|
||||
// private static RileyLinkIPCConnection rileyLinkIPCConnection;
|
||||
private static MedtronicDeviceType medtronicPumpModel;
|
||||
private static RileyLinkTargetFrequency rileyLinkTargetFrequency;
|
||||
// private static MedtronicPumpStatus pumpStatus;
|
||||
// BAD dependencies in Classes: RileyLinkService
|
||||
private static RileyLinkTargetFrequency rileyLinkTargetFrequency;
|
||||
|
||||
// Broadcasts: RileyLinkBLE, RileyLinkService,
|
||||
private static RileyLinkTargetDevice targetDevice;
|
||||
|
||||
|
||||
public static void setContext(Context contextIn) {
|
||||
|
@ -62,13 +63,13 @@ public class RileyLinkUtil {
|
|||
}
|
||||
|
||||
|
||||
public static void setServiceState(RileyLinkServiceState newState) {
|
||||
setServiceState(newState, null);
|
||||
public static RileyLinkServiceState getServiceState() {
|
||||
return RileyLinkUtil.rileyLinkServiceData.serviceState;
|
||||
}
|
||||
|
||||
|
||||
public static RileyLinkServiceState getServiceState() {
|
||||
return RileyLinkUtil.rileyLinkServiceData.serviceState;
|
||||
public static void setServiceState(RileyLinkServiceState newState) {
|
||||
setServiceState(newState, null);
|
||||
}
|
||||
|
||||
|
||||
|
@ -81,23 +82,25 @@ public class RileyLinkUtil {
|
|||
RileyLinkUtil.rileyLinkServiceData.serviceState = newState;
|
||||
RileyLinkUtil.rileyLinkServiceData.errorCode = errorCode;
|
||||
|
||||
LOG.warn("RileyLink State Changed: {} {}", newState, errorCode == null ? "" : " - Error State: " + errorCode.name());
|
||||
LOG.warn("RileyLink State Changed: {} {}", newState,
|
||||
errorCode == null ? "" : " - Error State: " + errorCode.name());
|
||||
|
||||
RileyLinkUtil.historyRileyLink.add(new RLHistoryItem(RileyLinkUtil.rileyLinkServiceData.serviceState, RileyLinkUtil.rileyLinkServiceData.errorCode));
|
||||
RileyLinkUtil.historyRileyLink.add(new RLHistoryItem(RileyLinkUtil.rileyLinkServiceData.serviceState,
|
||||
RileyLinkUtil.rileyLinkServiceData.errorCode, targetDevice));
|
||||
MainApp.bus().post(new EventMedtronicDeviceStatusChange(newState, errorCode));
|
||||
}
|
||||
|
||||
|
||||
public static void setRileyLinkBLE(RileyLinkBLE rileyLinkBLEIn) {
|
||||
RileyLinkUtil.rileyLinkBLE = rileyLinkBLEIn;
|
||||
}
|
||||
|
||||
|
||||
public static RileyLinkBLE getRileyLinkBLE() {
|
||||
return RileyLinkUtil.rileyLinkBLE;
|
||||
}
|
||||
|
||||
|
||||
public static void setRileyLinkBLE(RileyLinkBLE rileyLinkBLEIn) {
|
||||
RileyLinkUtil.rileyLinkBLE = rileyLinkBLEIn;
|
||||
}
|
||||
|
||||
|
||||
public static RileyLinkServiceData getRileyLinkServiceData() {
|
||||
return RileyLinkUtil.rileyLinkServiceData;
|
||||
}
|
||||
|
@ -113,18 +116,13 @@ public class RileyLinkUtil {
|
|||
}
|
||||
|
||||
|
||||
public static void setRileyLinkService(RileyLinkService rileyLinkService) {
|
||||
RileyLinkUtil.rileyLinkService = rileyLinkService;
|
||||
}
|
||||
|
||||
|
||||
public static RileyLinkService getRileyLinkService() {
|
||||
return RileyLinkUtil.rileyLinkService;
|
||||
}
|
||||
|
||||
|
||||
public static void setRileyLinkCommunicationManager(RileyLinkCommunicationManager rileyLinkCommunicationManager) {
|
||||
RileyLinkUtil.rileyLinkCommunicationManager = rileyLinkCommunicationManager;
|
||||
public static void setRileyLinkService(RileyLinkService rileyLinkService) {
|
||||
RileyLinkUtil.rileyLinkService = rileyLinkService;
|
||||
}
|
||||
|
||||
|
||||
|
@ -133,13 +131,16 @@ public class RileyLinkUtil {
|
|||
}
|
||||
|
||||
|
||||
public static void setRileyLinkCommunicationManager(RileyLinkCommunicationManager rileyLinkCommunicationManager) {
|
||||
RileyLinkUtil.rileyLinkCommunicationManager = rileyLinkCommunicationManager;
|
||||
}
|
||||
|
||||
|
||||
public static boolean sendNotification(ServiceNotification notification, Integer clientHashcode) {
|
||||
return RileyLinkUtil.rileyLinkService.sendNotification(notification, clientHashcode);
|
||||
}
|
||||
|
||||
|
||||
static ServiceTask currentTask;
|
||||
|
||||
// FIXME remove ?
|
||||
public static void setCurrentTask(ServiceTask task) {
|
||||
if (currentTask == null) {
|
||||
|
@ -179,14 +180,13 @@ public class RileyLinkUtil {
|
|||
// RileyLinkUtil.rileyLinkIPCConnection = rileyLinkIPCConnection;
|
||||
// }
|
||||
|
||||
|
||||
public static void setRileyLinkTargetFrequency(RileyLinkTargetFrequency rileyLinkTargetFrequency) {
|
||||
RileyLinkUtil.rileyLinkTargetFrequency = rileyLinkTargetFrequency;
|
||||
public static RileyLinkTargetFrequency getRileyLinkTargetFrequency() {
|
||||
return RileyLinkUtil.rileyLinkTargetFrequency;
|
||||
}
|
||||
|
||||
|
||||
public static RileyLinkTargetFrequency getRileyLinkTargetFrequency() {
|
||||
return RileyLinkUtil.rileyLinkTargetFrequency;
|
||||
public static void setRileyLinkTargetFrequency(RileyLinkTargetFrequency rileyLinkTargetFrequency) {
|
||||
RileyLinkUtil.rileyLinkTargetFrequency = rileyLinkTargetFrequency;
|
||||
}
|
||||
|
||||
|
||||
|
@ -196,4 +196,19 @@ public class RileyLinkUtil {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble;
|
||||
|
||||
import android.os.SystemClock;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.UUID;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.GattAttributes;
|
||||
|
@ -26,18 +26,13 @@ import info.nightscout.androidaps.plugins.PumpCommon.utils.ThreadUtil;
|
|||
*/
|
||||
public class RFSpy {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RFSpy.class);
|
||||
|
||||
|
||||
public static final long RILEYLINK_FREQ_XTAL = 24000000;
|
||||
|
||||
|
||||
public static final int EXPECTED_MAX_BLUETOOTH_LATENCY_MS = 7500; // 1500
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RFSpy.class);
|
||||
public int notConnectedCount = 0;
|
||||
private RileyLinkBLE rileyLinkBle;
|
||||
private RFSpyReader reader;
|
||||
private RileyLinkTargetFrequency selectedTargetFrequency;
|
||||
|
||||
private UUID radioServiceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO);
|
||||
private UUID radioDataUUID = UUID.fromString(GattAttributes.CHARA_RADIO_DATA);
|
||||
private UUID radioVersionUUID = UUID.fromString(GattAttributes.CHARA_RADIO_VERSION);
|
||||
|
@ -54,6 +49,7 @@ public class RFSpy {
|
|||
// Starts an async task to read when data is available
|
||||
public void startReader() {
|
||||
rileyLinkBle.registerRadioResponseCountNotification(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
newDataIsAvailable();
|
||||
|
@ -70,8 +66,6 @@ public class RFSpy {
|
|||
}
|
||||
|
||||
|
||||
public int notConnectedCount = 0;
|
||||
|
||||
// This gets the version from the BLE113, not from the CC1110.
|
||||
// I.e., this gets the version from the BLE interface, not from the radio.
|
||||
public String getVersion() {
|
||||
|
@ -84,6 +78,7 @@ public class RFSpy {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public String getRadioVersion() {
|
||||
RFSpyResponse resp = writeToData(RFSpyCommand.GetVersion, null, EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
|
||||
if (resp == null) {
|
||||
|
@ -105,13 +100,15 @@ public class RFSpy {
|
|||
byte[] junkInBuffer = reader.poll(0);
|
||||
|
||||
while (junkInBuffer != null) {
|
||||
LOG.warn(ThreadUtil.sig() + "writeToData: draining read queue, found this: " + ByteUtil.shortHexString(junkInBuffer));
|
||||
LOG.warn(ThreadUtil.sig() + "writeToData: draining read queue, found this: "
|
||||
+ ByteUtil.shortHexString(junkInBuffer));
|
||||
junkInBuffer = reader.poll(0);
|
||||
}
|
||||
|
||||
// prepend length, and send it.
|
||||
byte[] prepended = ByteUtil.concat(new byte[] { (byte)(bytes.length) }, bytes);
|
||||
BLECommOperationResult writeCheck = rileyLinkBle.writeCharacteristic_blocking(radioServiceUUID, radioDataUUID, prepended);
|
||||
BLECommOperationResult writeCheck = rileyLinkBle.writeCharacteristic_blocking(radioServiceUUID, radioDataUUID,
|
||||
prepended);
|
||||
if (writeCheck.resultCode != BLECommOperationResult.RESULT_SUCCESS) {
|
||||
LOG.error("BLE Write operation failed, code=" + writeCheck.resultCode);
|
||||
return new RFSpyResponse(); // will be a null (invalid) response
|
||||
|
@ -145,10 +142,12 @@ public class RFSpy {
|
|||
return resp;
|
||||
}
|
||||
|
||||
|
||||
private void resetNotConnectedCount() {
|
||||
this.notConnectedCount = 0;
|
||||
}
|
||||
|
||||
|
||||
private byte[] getByteArray(byte... input) {
|
||||
return input;
|
||||
}
|
||||
|
@ -180,14 +179,17 @@ public class RFSpy {
|
|||
public RFSpyResponse transmit(RadioPacket radioPacket, byte sendChannel, byte repeatCount, byte delay_ms) {
|
||||
// append checksum, encode data, send it.
|
||||
byte[] fullPacket = ByteUtil.concat(getByteArray(sendChannel, repeatCount, delay_ms), radioPacket.getEncoded());
|
||||
RFSpyResponse response = writeToData(RFSpyCommand.Send, fullPacket, delay_ms + EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
|
||||
RFSpyResponse response = writeToData(RFSpyCommand.Send, fullPacket, delay_ms
|
||||
+ EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
public RFSpyResponse receive(byte listenChannel, int timeout_ms, byte retryCount) {
|
||||
int receiveDelay = timeout_ms * (retryCount + 1);
|
||||
byte[] listen = getByteArray(listenChannel, (byte) ((timeout_ms >> 24) & 0x0FF), (byte) ((timeout_ms >> 16) & 0x0FF), (byte) ((timeout_ms >> 8) & 0x0FF), (byte) (timeout_ms & 0x0FF), retryCount);
|
||||
byte[] listen = getByteArray(listenChannel, (byte)((timeout_ms >> 24) & 0x0FF),
|
||||
(byte)((timeout_ms >> 16) & 0x0FF), (byte)((timeout_ms >> 8) & 0x0FF), (byte)(timeout_ms & 0x0FF),
|
||||
retryCount);
|
||||
return writeToData(RFSpyCommand.GetPacket, listen, receiveDelay);
|
||||
}
|
||||
|
||||
|
@ -197,19 +199,24 @@ public class RFSpy {
|
|||
}
|
||||
|
||||
|
||||
public RFSpyResponse transmitThenReceive(RadioPacket pkt, byte sendChannel, byte repeatCount, byte delay_ms, byte listenChannel, int timeout_ms, byte retryCount) {
|
||||
public RFSpyResponse transmitThenReceive(RadioPacket pkt, byte sendChannel, byte repeatCount, byte delay_ms,
|
||||
byte listenChannel, int timeout_ms, byte retryCount) {
|
||||
|
||||
int sendDelay = repeatCount * delay_ms;
|
||||
int receiveDelay = timeout_ms * (retryCount + 1);
|
||||
byte[] sendAndListen = getByteArray(sendChannel, repeatCount, delay_ms, listenChannel, (byte) ((timeout_ms >> 24) & 0x0FF), (byte) ((timeout_ms >> 16) & 0x0FF), (byte) ((timeout_ms >> 8) & 0x0FF), (byte) (timeout_ms & 0x0FF), (byte) retryCount);
|
||||
byte[] sendAndListen = getByteArray(sendChannel, repeatCount, delay_ms, listenChannel,
|
||||
(byte)((timeout_ms >> 24) & 0x0FF), (byte)((timeout_ms >> 16) & 0x0FF), (byte)((timeout_ms >> 8) & 0x0FF),
|
||||
(byte)(timeout_ms & 0x0FF), (byte)retryCount);
|
||||
byte[] fullPacket = ByteUtil.concat(sendAndListen, pkt.getEncoded());
|
||||
return writeToData(RFSpyCommand.SendAndListen, fullPacket, sendDelay + receiveDelay + EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
|
||||
return writeToData(RFSpyCommand.SendAndListen, fullPacket, sendDelay + receiveDelay
|
||||
+ EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
|
||||
}
|
||||
|
||||
|
||||
public RFSpyResponse updateRegister(CC111XRegister reg, int val) {
|
||||
byte[] updateRegisterPkt = getByteArray(reg.value, (byte)val);
|
||||
RFSpyResponse resp = writeToData(RFSpyCommand.UpdateRegister, updateRegisterPkt, EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
|
||||
RFSpyResponse resp = writeToData(RFSpyCommand.UpdateRegister, updateRegisterPkt,
|
||||
EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
@ -275,5 +282,4 @@ public class RFSpy {
|
|||
updateRegister(CC111XRegister.mdmcfg4, (byte)(chanbw | drate_e));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.GattAttributes;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations.BLECommOperationResult;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
|
||||
|
@ -22,11 +22,10 @@ import info.nightscout.androidaps.plugins.PumpCommon.utils.ThreadUtil;
|
|||
public class RFSpyReader {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RFSpyReader.class);
|
||||
|
||||
AsyncTask<Void, Void, Void> readerTask;
|
||||
// private Context context;
|
||||
private RileyLinkBLE rileyLinkBle;
|
||||
private Semaphore waitForRadioData = new Semaphore(0, true);
|
||||
AsyncTask<Void, Void, Void> readerTask;
|
||||
private LinkedBlockingQueue<byte[]> mDataQueue = new LinkedBlockingQueue<>();
|
||||
private int acquireCount = 0;
|
||||
private int releaseCount = 0;
|
||||
|
@ -54,14 +53,16 @@ public class RFSpyReader {
|
|||
|
||||
// This timeout must be coordinated with the length of the RFSpy radio operation or Bad Things Happen.
|
||||
public byte[] poll(int timeout_ms) {
|
||||
LOG.trace(ThreadUtil.sig() + "Entering poll at t==" + SystemClock.uptimeMillis() + ", timeout is " + timeout_ms + " mDataQueue size is " + mDataQueue.size());
|
||||
LOG.trace(ThreadUtil.sig() + "Entering poll at t==" + SystemClock.uptimeMillis() + ", timeout is " + timeout_ms
|
||||
+ " mDataQueue size is " + mDataQueue.size());
|
||||
if (mDataQueue.isEmpty())
|
||||
try {
|
||||
// block until timeout or data available.
|
||||
// returns null if timeout.
|
||||
byte[] dataFromQueue = mDataQueue.poll(timeout_ms, TimeUnit.MILLISECONDS);
|
||||
if (dataFromQueue != null) {
|
||||
LOG.debug("Got data [" + ByteUtil.shortHexString(dataFromQueue) + "] at t==" + SystemClock.uptimeMillis());
|
||||
LOG.debug("Got data [" + ByteUtil.shortHexString(dataFromQueue) + "] at t=="
|
||||
+ SystemClock.uptimeMillis());
|
||||
} else {
|
||||
LOG.debug("Got data [null] at t==" + SystemClock.uptimeMillis());
|
||||
}
|
||||
|
@ -77,13 +78,15 @@ public class RFSpyReader {
|
|||
public void newDataIsAvailable() {
|
||||
releaseCount++;
|
||||
|
||||
LOG.trace(ThreadUtil.sig() + "waitForRadioData released(count=" + releaseCount + ") at t=" + SystemClock.uptimeMillis());
|
||||
LOG.trace(ThreadUtil.sig() + "waitForRadioData released(count=" + releaseCount + ") at t="
|
||||
+ SystemClock.uptimeMillis());
|
||||
waitForRadioData.release();
|
||||
}
|
||||
|
||||
|
||||
public void start() {
|
||||
readerTask = new AsyncTask<Void, Void, Void>() {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
UUID serviceUUID = UUID.fromString(GattAttributes.SERVICE_RADIO);
|
||||
|
@ -93,7 +96,8 @@ public class RFSpyReader {
|
|||
try {
|
||||
acquireCount++;
|
||||
waitForRadioData.acquire();
|
||||
LOG.trace(ThreadUtil.sig() + "waitForRadioData acquired (count=" + acquireCount + ") at t=" + SystemClock.uptimeMillis());
|
||||
LOG.trace(ThreadUtil.sig() + "waitForRadioData acquired (count=" + acquireCount + ") at t="
|
||||
+ SystemClock.uptimeMillis());
|
||||
SystemClock.sleep(100);
|
||||
SystemClock.sleep(1);
|
||||
result = rileyLinkBle.readCharacteristic_blocking(serviceUUID, radioDataUUID);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC;
|
||||
|
||||
|
@ -13,17 +13,18 @@ import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC;
|
|||
*/
|
||||
public class RFTools {
|
||||
|
||||
public static final byte[] codes = new byte[] { 21, 49, 50, 35, 52, 37, 38, 22, 26, 25, 42, 11, 44, 13, 14, 28 };
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RFTools.class);
|
||||
|
||||
|
||||
private final static char[] HEX_DIGITS = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
/*
|
||||
CodeSymbols is an ordered list of translations
|
||||
6bits -> 4 bits, in order from 0x0 to 0xF
|
||||
The 6 bit codes are what is used on the RF side of the RileyLink
|
||||
to communicate with a Medtronic pump.
|
||||
|
||||
* CodeSymbols is an ordered list of translations
|
||||
* 6bits -> 4 bits, in order from 0x0 to 0xF
|
||||
* The 6 bit codes are what is used on the RF side of the RileyLink
|
||||
* to communicate with a Medtronic pump.
|
||||
*/
|
||||
public static byte[] CodeSymbols = {0x15, 0x31, 0x32, 0x23, 0x34, 0x25, 0x26, 0x16, 0x1a, 0x19, 0x2a, 0x0b, 0x2c, 0x0d, 0x0e, 0x1c};
|
||||
public static byte[] CodeSymbols = {
|
||||
0x15, 0x31, 0x32, 0x23, 0x34, 0x25, 0x26, 0x16, 0x1a, 0x19, 0x2a, 0x0b, 0x2c, 0x0d, 0x0e, 0x1c };
|
||||
|
||||
|
||||
public static byte[] appendChecksum(final byte[] input) {
|
||||
|
@ -36,12 +37,48 @@ public class RFTools {
|
|||
byte[] rval = new byte[input.length + 1];
|
||||
System.arraycopy(input, 0, rval, 0, input.length);
|
||||
byte mycrc = CRC.crc8(input);
|
||||
LOG.debug(String.format("Adding checksum 0x%02X to %d byte array from 0x%02X to 0x%02X", mycrc, input.length, input[0], input[input.length - 1]));
|
||||
LOG.debug(String.format("Adding checksum 0x%02X to %d byte array from 0x%02X to 0x%02X", mycrc, input.length,
|
||||
input[0], input[input.length - 1]));
|
||||
rval[input.length] = mycrc;
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* + (NSData*)encode4b6b:(NSData*)data {
|
||||
* NSMutableData *outData = [NSMutableData data];
|
||||
* NSMutableData *dataPlusCrc = [data mutableCopy];
|
||||
* unsigned char crc = [MinimedPacket crcForData:data];
|
||||
* [dataPlusCrc appendBytes:&crc length:1];
|
||||
* char codes[16] = {21,49,50,35,52,37,38,22,26,25,42,11,44,13,14,28};
|
||||
* const unsigned char *inBytes = [dataPlusCrc bytes];
|
||||
* unsigned int acc = 0x0;
|
||||
* int bitcount = 0;
|
||||
* for (int i=0; i < dataPlusCrc.length; i++) {
|
||||
* acc <<= 6;
|
||||
* acc |= codes[inBytes[i] >> 4];
|
||||
* bitcount += 6;
|
||||
*
|
||||
* acc <<= 6;
|
||||
* acc |= codes[inBytes[i] & 0x0f];
|
||||
* bitcount += 6;
|
||||
*
|
||||
* while (bitcount >= 8) {
|
||||
* unsigned char outByte = acc >> (bitcount-8) & 0xff;
|
||||
* [outData appendBytes:&outByte length:1];
|
||||
* bitcount -= 8;
|
||||
* acc &= (0xffff >> (16-bitcount));
|
||||
* }
|
||||
* }
|
||||
* if (bitcount > 0) {
|
||||
* acc <<= (8-bitcount);
|
||||
* unsigned char outByte = acc & 0xff;
|
||||
* [outData appendBytes:&outByte length:1];
|
||||
* }
|
||||
* return outData;
|
||||
* }
|
||||
*/
|
||||
|
||||
public static ArrayList<Byte> fromBytes(byte[] data) {
|
||||
ArrayList<Byte> rval = new ArrayList<>();
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
|
@ -59,43 +96,6 @@ public class RFTools {
|
|||
return rval;
|
||||
}
|
||||
|
||||
/*
|
||||
+ (NSData*)encode4b6b:(NSData*)data {
|
||||
NSMutableData *outData = [NSMutableData data];
|
||||
NSMutableData *dataPlusCrc = [data mutableCopy];
|
||||
unsigned char crc = [MinimedPacket crcForData:data];
|
||||
[dataPlusCrc appendBytes:&crc length:1];
|
||||
char codes[16] = {21,49,50,35,52,37,38,22,26,25,42,11,44,13,14,28};
|
||||
const unsigned char *inBytes = [dataPlusCrc bytes];
|
||||
unsigned int acc = 0x0;
|
||||
int bitcount = 0;
|
||||
for (int i=0; i < dataPlusCrc.length; i++) {
|
||||
acc <<= 6;
|
||||
acc |= codes[inBytes[i] >> 4];
|
||||
bitcount += 6;
|
||||
|
||||
acc <<= 6;
|
||||
acc |= codes[inBytes[i] & 0x0f];
|
||||
bitcount += 6;
|
||||
|
||||
while (bitcount >= 8) {
|
||||
unsigned char outByte = acc >> (bitcount-8) & 0xff;
|
||||
[outData appendBytes:&outByte length:1];
|
||||
bitcount -= 8;
|
||||
acc &= (0xffff >> (16-bitcount));
|
||||
}
|
||||
}
|
||||
if (bitcount > 0) {
|
||||
acc <<= (8-bitcount);
|
||||
unsigned char outByte = acc & 0xff;
|
||||
[outData appendBytes:&outByte length:1];
|
||||
}
|
||||
return outData;
|
||||
}
|
||||
*/
|
||||
|
||||
public static final byte[] codes = new byte[]{21, 49, 50, 35, 52, 37, 38, 22, 26, 25, 42, 11, 44, 13, 14, 28};
|
||||
|
||||
|
||||
/* O(n) lookup. Run on an O(n) translation of a byte-stream, gives O(n**2) performance. Sigh. */
|
||||
public static int codeIndex(byte b) {
|
||||
|
@ -151,7 +151,6 @@ public class RFTools {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// convert back to byte[]
|
||||
byte[] rval = toBytes(outData);
|
||||
|
||||
|
@ -162,9 +161,9 @@ public class RFTools {
|
|||
|
||||
public static void test() {
|
||||
/*
|
||||
{0xa7} -> {0xa9, 0x60}
|
||||
{0xa7, 0x12} -> {0xa9, 0x6c, 0x72}
|
||||
{0xa7, 0x12, 0xa7} -> {0xa9, 0x6c, 0x72, 0xa9, 0x60}
|
||||
* {0xa7} -> {0xa9, 0x60}
|
||||
* {0xa7, 0x12} -> {0xa9, 0x6c, 0x72}
|
||||
* {0xa7, 0x12, 0xa7} -> {0xa9, 0x6c, 0x72, 0xa9, 0x60}
|
||||
*/
|
||||
/* test compare */
|
||||
byte[] s1 = { 0, 1, 2 };
|
||||
|
@ -186,17 +185,20 @@ public class RFTools {
|
|||
byte[] bs = encode4b6b(new byte[] { (byte)0xa7 });
|
||||
byte[] out = new byte[] { (byte)(0xa9), 0x65 };
|
||||
if (ByteUtil.compare(bs, out) != 0) {
|
||||
LOG.error("encode Data failed: expected " + ByteUtil.shortHexString(out) + " but got " + ByteUtil.shortHexString(bs));
|
||||
LOG.error("encode Data failed: expected " + ByteUtil.shortHexString(out) + " but got "
|
||||
+ ByteUtil.shortHexString(bs));
|
||||
}
|
||||
bs = encode4b6b(new byte[] { (byte)0xa7, 0x12 });
|
||||
out = new byte[] { (byte)(0xa9), 0x6c, 0x72 };
|
||||
if (ByteUtil.compare(bs, out) != 0) {
|
||||
LOG.error("encode Data failed: expected " + ByteUtil.shortHexString(out) + " but got " + ByteUtil.shortHexString(bs));
|
||||
LOG.error("encode Data failed: expected " + ByteUtil.shortHexString(out) + " but got "
|
||||
+ ByteUtil.shortHexString(bs));
|
||||
}
|
||||
bs = encode4b6b(new byte[] { (byte)0xa7, 0x12, (byte)0xa7 });
|
||||
out = new byte[] { (byte)(0xa9), 0x6c, 0x72, (byte)0xa9, 0x65 };
|
||||
if (ByteUtil.compare(bs, out) != 0) {
|
||||
LOG.error("encode Data failed: expected " + ByteUtil.shortHexString(out) + " but got " + ByteUtil.shortHexString(bs));
|
||||
LOG.error("encode Data failed: expected " + ByteUtil.shortHexString(out) + " but got "
|
||||
+ ByteUtil.shortHexString(bs));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -204,9 +206,9 @@ public class RFTools {
|
|||
|
||||
public static byte[] decode4b6b(byte[] raw) throws NumberFormatException {
|
||||
/*
|
||||
if ((raw.length % 2) != 0) {
|
||||
LOG.error("Warning: data is odd number of bytes");
|
||||
}
|
||||
* if ((raw.length % 2) != 0) {
|
||||
* LOG.error("Warning: data is odd number of bytes");
|
||||
* }
|
||||
*/
|
||||
byte[] rval = new byte[] {};
|
||||
int availableBits = 0;
|
||||
|
@ -233,8 +235,12 @@ public class RFTools {
|
|||
byte decoded = (byte)((highIndex << 4) + lowIndex);
|
||||
rval = ByteUtil.concat(rval, decoded);
|
||||
/*
|
||||
LOG.debug(String.format("i=%d,x=0x%08X,0x%02X->0x%02X, 0x%02X->0x%02X, result: 0x%02X, %d bits remaining, errors %d, bytes remaining: %s",
|
||||
i,x,highcode,highIndex, lowcode, lowIndex,decoded,availableBits,codingErrors,ByteUtil.shortHexString(ByteUtil.substring(raw,i+1,raw.length-i-1))));
|
||||
* LOG.debug(String.format(
|
||||
* "i=%d,x=0x%08X,0x%02X->0x%02X, 0x%02X->0x%02X, result: 0x%02X, %d bits remaining, errors %d, bytes remaining: %s"
|
||||
* ,
|
||||
* i,x,highcode,highIndex, lowcode,
|
||||
* lowIndex,decoded,availableBits,codingErrors,ByteUtil.shortHexString
|
||||
* (ByteUtil.substring(raw,i+1,raw.length-i-1))));
|
||||
*/
|
||||
} else {
|
||||
// LOG.debug(String.format("i=%d,x=%08X, coding error: highcode=0x%02X, lowcode=0x%02X, %d bits remaining",i,x,highcode,lowcode,availableBits));
|
||||
|
@ -270,9 +276,6 @@ public class RFTools {
|
|||
}
|
||||
|
||||
|
||||
private final static char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
|
||||
|
||||
public static String toHexString(byte[] array, int offset, int length) {
|
||||
char[] buf = new char[length * 2];
|
||||
|
||||
|
@ -286,5 +289,4 @@ public class RFTools {
|
|||
return new String(buf);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
|
@ -12,14 +20,6 @@ import android.content.Context;
|
|||
import android.os.SystemClock;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkConst;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.GattAttributes;
|
||||
|
@ -40,22 +40,16 @@ import info.nightscout.androidaps.plugins.PumpCommon.utils.ThreadUtil;
|
|||
public class RileyLinkBLE {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RFTools.class);
|
||||
|
||||
private final Context context;
|
||||
public boolean gattDebugEnabled = true;
|
||||
|
||||
boolean manualDisconnect = false;
|
||||
private BluetoothAdapter bluetoothAdapter;
|
||||
private BluetoothGattCallback bluetoothGattCallback;
|
||||
|
||||
private final Context context;
|
||||
|
||||
private BluetoothDevice rileyLinkDevice;
|
||||
private BluetoothGatt bluetoothConnectionGatt = null;
|
||||
|
||||
private BLECommOperation mCurrentOperation;
|
||||
private Semaphore gattOperationSema = new Semaphore(1, true);
|
||||
|
||||
private Runnable radioResponseCountNotified;
|
||||
|
||||
private boolean mIsConnected = false;
|
||||
|
||||
|
||||
|
@ -67,10 +61,13 @@ public class RileyLinkBLE {
|
|||
bluetoothGattCallback = new BluetoothGattCallback() {
|
||||
|
||||
@Override
|
||||
public void onCharacteristicChanged(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {
|
||||
public void onCharacteristicChanged(final BluetoothGatt gatt,
|
||||
final BluetoothGattCharacteristic characteristic) {
|
||||
super.onCharacteristicChanged(gatt, characteristic);
|
||||
if (gattDebugEnabled) {
|
||||
LOG.trace(ThreadUtil.sig() + "onCharacteristicChanged " + GattAttributes.lookup(characteristic.getUuid()) + " " + HexDump.toHexString(characteristic.getValue()));
|
||||
LOG.trace(ThreadUtil.sig() + "onCharacteristicChanged "
|
||||
+ GattAttributes.lookup(characteristic.getUuid()) + " "
|
||||
+ HexDump.toHexString(characteristic.getValue()));
|
||||
if (characteristic.getUuid().equals(UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT))) {
|
||||
LOG.debug("Response Count is " + HexDump.toHexString(characteristic.getValue()));
|
||||
}
|
||||
|
@ -82,25 +79,29 @@ public class RileyLinkBLE {
|
|||
|
||||
|
||||
@Override
|
||||
public void onCharacteristicRead(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, int status) {
|
||||
public void onCharacteristicRead(final BluetoothGatt gatt,
|
||||
final BluetoothGattCharacteristic characteristic, int status) {
|
||||
super.onCharacteristicRead(gatt, characteristic, status);
|
||||
|
||||
|
||||
final String statusMessage = getGattStatusMessage(status);
|
||||
if (gattDebugEnabled) {
|
||||
LOG.trace(ThreadUtil.sig() + "onCharacteristicRead (" + GattAttributes.lookup(characteristic.getUuid()) + ") " + statusMessage + ":" + HexDump.toHexString(characteristic.getValue()));
|
||||
LOG.trace(ThreadUtil.sig() + "onCharacteristicRead ("
|
||||
+ GattAttributes.lookup(characteristic.getUuid()) + ") " + statusMessage + ":"
|
||||
+ HexDump.toHexString(characteristic.getValue()));
|
||||
}
|
||||
mCurrentOperation.gattOperationCompletionCallback(characteristic.getUuid(), characteristic.getValue());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCharacteristicWrite(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, int status) {
|
||||
public void onCharacteristicWrite(final BluetoothGatt gatt,
|
||||
final BluetoothGattCharacteristic characteristic, int status) {
|
||||
super.onCharacteristicWrite(gatt, characteristic, status);
|
||||
|
||||
final String uuidString = GattAttributes.lookup(characteristic.getUuid());
|
||||
if (gattDebugEnabled) {
|
||||
LOG.trace(ThreadUtil.sig() + "onCharacteristicWrite " + getGattStatusMessage(status) + " " + uuidString + " " + HexDump.toHexString(characteristic.getValue()));
|
||||
LOG.trace(ThreadUtil.sig() + "onCharacteristicWrite " + getGattStatusMessage(status) + " "
|
||||
+ uuidString + " " + HexDump.toHexString(characteristic.getValue()));
|
||||
}
|
||||
mCurrentOperation.gattOperationCompletionCallback(characteristic.getUuid(), characteristic.getValue());
|
||||
}
|
||||
|
@ -143,7 +144,8 @@ public class RileyLinkBLE {
|
|||
|
||||
} else if ((newState == BluetoothProfile.STATE_CONNECTING) || //
|
||||
(newState == BluetoothProfile.STATE_DISCONNECTING)) {
|
||||
//LOG.debug("We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" : "Disconnecting");
|
||||
// LOG.debug("We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" :
|
||||
// "Disconnecting");
|
||||
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
|
||||
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnected);
|
||||
if (manualDisconnect)
|
||||
|
@ -159,7 +161,8 @@ public class RileyLinkBLE {
|
|||
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
||||
super.onDescriptorWrite(gatt, descriptor, status);
|
||||
if (gattDebugEnabled) {
|
||||
LOG.warn("onDescriptorWrite " + GattAttributes.lookup(descriptor.getUuid()) + " " + getGattStatusMessage(status) + " written: " + HexDump.toHexString(descriptor.getValue()));
|
||||
LOG.warn("onDescriptorWrite " + GattAttributes.lookup(descriptor.getUuid()) + " "
|
||||
+ getGattStatusMessage(status) + " written: " + HexDump.toHexString(descriptor.getValue()));
|
||||
}
|
||||
mCurrentOperation.gattOperationCompletionCallback(descriptor.getUuid(), descriptor.getValue());
|
||||
}
|
||||
|
@ -232,10 +235,12 @@ public class RileyLinkBLE {
|
|||
if (rileyLinkFound) {
|
||||
mIsConnected = true;
|
||||
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkReady);
|
||||
//RileyLinkUtil.sendNotification(new ServiceNotification(RileyLinkConst.Intents.RileyLinkReady), null);
|
||||
// RileyLinkUtil.sendNotification(new
|
||||
// ServiceNotification(RileyLinkConst.Intents.RileyLinkReady), null);
|
||||
} else {
|
||||
mIsConnected = false;
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.RileyLinkError, RileyLinkError.DeviceIsNotRileyLink);
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.RileyLinkError,
|
||||
RileyLinkError.DeviceIsNotRileyLink);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -369,9 +374,6 @@ public class RileyLinkBLE {
|
|||
}
|
||||
|
||||
|
||||
boolean manualDisconnect = false;
|
||||
|
||||
|
||||
public void disconnect() {
|
||||
mIsConnected = false;
|
||||
LOG.warn("Closing GATT connection");
|
||||
|
@ -414,7 +416,8 @@ public class RileyLinkBLE {
|
|||
LOG.error("BT Device not supported");
|
||||
// TODO: 11/07/2016 UI update for user
|
||||
} else {
|
||||
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic(charaUUID);
|
||||
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID)
|
||||
.getCharacteristic(charaUUID);
|
||||
// Tell Android that we want the notifications
|
||||
bluetoothConnectionGatt.setCharacteristicNotification(chara, true);
|
||||
List<BluetoothGattDescriptor> list = chara.getDescriptors();
|
||||
|
@ -425,7 +428,8 @@ public class RileyLinkBLE {
|
|||
}
|
||||
BluetoothGattDescriptor descr = list.get(0);
|
||||
// Tell the remote device to send the notifications
|
||||
mCurrentOperation = new DescriptorWriteOperation(bluetoothConnectionGatt, descr, BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
|
||||
mCurrentOperation = new DescriptorWriteOperation(bluetoothConnectionGatt, descr,
|
||||
BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
|
||||
mCurrentOperation.execute(this);
|
||||
if (mCurrentOperation.timedOut) {
|
||||
rval.resultCode = BLECommOperationResult.RESULT_TIMEOUT;
|
||||
|
@ -471,7 +475,8 @@ public class RileyLinkBLE {
|
|||
LOG.error("BT Device not supported");
|
||||
// TODO: 11/07/2016 UI update for user
|
||||
} else {
|
||||
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic(charaUUID);
|
||||
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID)
|
||||
.getCharacteristic(charaUUID);
|
||||
mCurrentOperation = new CharacteristicWriteOperation(bluetoothConnectionGatt, chara, value);
|
||||
mCurrentOperation.execute(this);
|
||||
if (mCurrentOperation.timedOut) {
|
||||
|
@ -506,7 +511,8 @@ public class RileyLinkBLE {
|
|||
if (mCurrentOperation != null) {
|
||||
rval.resultCode = BLECommOperationResult.RESULT_BUSY;
|
||||
} else {
|
||||
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic(charaUUID);
|
||||
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic(
|
||||
charaUUID);
|
||||
mCurrentOperation = new CharacteristicReadOperation(bluetoothConnectionGatt, chara);
|
||||
mCurrentOperation.execute(this);
|
||||
if (mCurrentOperation.timedOut) {
|
||||
|
@ -545,5 +551,4 @@ public class RileyLinkBLE {
|
|||
return statusMessage;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,11 +8,14 @@ import java.util.Comparator;
|
|||
* Created by geoff on 5/30/16.
|
||||
*/
|
||||
public class FrequencyScanResults {
|
||||
|
||||
public ArrayList<FrequencyTrial> trials = new ArrayList<>();
|
||||
public double bestFrequencyMHz = 0.0;
|
||||
|
||||
|
||||
public void sort() {
|
||||
Collections.sort(trials, new Comparator<FrequencyTrial>() {
|
||||
|
||||
@Override
|
||||
public int compare(FrequencyTrial trial1, FrequencyTrial trial2) {
|
||||
return trial1.averageRSSI.compareTo(trial2.averageRSSI);
|
||||
|
|
|
@ -4,6 +4,7 @@ package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data;
|
|||
* Created by geoff on 5/30/16.
|
||||
*/
|
||||
public class FrequencyTrial {
|
||||
|
||||
public int tries = 0;
|
||||
public int successes = 0;
|
||||
public Double averageRSSI = 0.0;
|
||||
|
|
|
@ -41,7 +41,6 @@ public class GattAttributes {
|
|||
attributes.put(CHARA_GAP_NAME, "Name"); //
|
||||
attributes.put(CHARA_GAP_NUM, "Number"); //
|
||||
|
||||
|
||||
attributes.put(SERVICE_BATTERY, "Battery Service");
|
||||
|
||||
attributes.put(SERVICE_RADIO, "Radio Interface"); // a
|
||||
|
@ -85,5 +84,4 @@ public class GattAttributes {
|
|||
return attributesRileyLinkSpecific.containsKey(uuid.toString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RFSpy
|
|||
* Created by geoff on 5/26/16.
|
||||
*/
|
||||
public class RFSpyResponse {
|
||||
|
||||
// 0xaa == timeout
|
||||
// 0xbb == interrupted
|
||||
// 0xcc == zero-data
|
||||
|
|
|
@ -7,6 +7,7 @@ public interface RLMessage {
|
|||
|
||||
byte[] getTxData();
|
||||
|
||||
|
||||
boolean isValid();
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC;
|
|||
*/
|
||||
|
||||
public class RadioPacket {
|
||||
|
||||
protected byte[] pkt;
|
||||
|
||||
|
||||
|
@ -21,11 +22,13 @@ public class RadioPacket {
|
|||
return pkt;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getWithCRC() {
|
||||
byte[] withCRC = ByteUtil.concat(pkt, CRC.crc8(pkt));
|
||||
return withCRC;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getEncoded() {
|
||||
byte[] withCRC = ByteUtil.concat(pkt, CRC.crc8(pkt));
|
||||
byte[] encoded = RFTools.encode4b6b(withCRC);
|
||||
|
|
|
@ -31,6 +31,7 @@ public class RadioResponse {
|
|||
init(rxData);
|
||||
}
|
||||
|
||||
|
||||
public RadioResponse(RFSpyCommand command, byte[] raw) {
|
||||
|
||||
this.command = command;
|
||||
|
@ -40,12 +41,10 @@ public class RadioResponse {
|
|||
|
||||
public boolean isValid() {
|
||||
|
||||
if (command!=null && !command.isEncoded())
|
||||
{
|
||||
if (command != null && !command.isEncoded()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (!decodedOK) {
|
||||
return false;
|
||||
}
|
||||
|
@ -80,10 +79,10 @@ public class RadioResponse {
|
|||
byte calculatedCRC = CRC.crc8(decodedPayload);
|
||||
receivedCRC = decodeThis[decodeThis.length - 1];
|
||||
if (receivedCRC != calculatedCRC) {
|
||||
LOG.error(String.format("RadioResponse: CRC mismatch, calculated 0x%02x, received 0x%02x", calculatedCRC, receivedCRC));
|
||||
LOG.error(String.format("RadioResponse: CRC mismatch, calculated 0x%02x, received 0x%02x",
|
||||
calculatedCRC, receivedCRC));
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
decodedOK = true;
|
||||
decodedPayload = encodedPayload;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ public enum CC111XRegister {
|
|||
paTable0(0x2e), //
|
||||
|
||||
;
|
||||
|
||||
public byte value;
|
||||
|
||||
|
||||
|
|
|
@ -25,8 +25,7 @@ public enum RileyLinkTargetFrequency {
|
|||
|
||||
public double[] getScanFrequencies() {
|
||||
|
||||
if (maxFrequency == minFrequency)
|
||||
{
|
||||
if (maxFrequency == minFrequency) {
|
||||
double freq[] = new double[1];
|
||||
freq[0] = minFrequency;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE;
|
||||
|
||||
/**
|
||||
|
@ -18,16 +18,20 @@ public abstract class BLECommOperation {
|
|||
protected BluetoothGatt gatt;
|
||||
protected Semaphore operationComplete = new Semaphore(0, true);
|
||||
|
||||
|
||||
// This is to be run on the main thread
|
||||
public abstract void execute(RileyLinkBLE comm);
|
||||
|
||||
|
||||
public void gattOperationCompletionCallback(UUID uuid, byte[] value) {
|
||||
}
|
||||
|
||||
|
||||
public int getGattOperationTimeout_ms() {
|
||||
return 22000;
|
||||
}
|
||||
|
||||
|
||||
public byte[] getValue() {
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operation
|
|||
* Created by geoff on 5/26/16.
|
||||
*/
|
||||
public class BLECommOperationResult {
|
||||
public byte[] value;
|
||||
public int resultCode;
|
||||
|
||||
public static final int RESULT_NONE = 0;
|
||||
public static final int RESULT_SUCCESS = 1;
|
||||
|
@ -13,4 +11,6 @@ public class BLECommOperationResult {
|
|||
public static final int RESULT_BUSY = 3;
|
||||
public static final int RESULT_INTERRUPTED = 4;
|
||||
public static final int RESULT_NOT_CONFIGURED = 5;
|
||||
public byte[] value;
|
||||
public int resultCode;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.os.SystemClock;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.GattAttributes;
|
||||
|
@ -22,11 +22,13 @@ public class CharacteristicReadOperation extends BLECommOperation {
|
|||
|
||||
private BluetoothGattCharacteristic characteristic;
|
||||
|
||||
|
||||
public CharacteristicReadOperation(BluetoothGatt gatt, BluetoothGattCharacteristic chara) {
|
||||
this.gatt = gatt;
|
||||
this.characteristic = chara;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(RileyLinkBLE comm) {
|
||||
gatt.readCharacteristic(characteristic);
|
||||
|
@ -34,7 +36,8 @@ public class CharacteristicReadOperation extends BLECommOperation {
|
|||
try {
|
||||
boolean didAcquire = operationComplete.tryAcquire(getGattOperationTimeout_ms(), TimeUnit.MILLISECONDS);
|
||||
if (didAcquire) {
|
||||
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier understanding of the sequence of events.
|
||||
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier
|
||||
// understanding of the sequence of events.
|
||||
// success
|
||||
} else {
|
||||
LOG.error("Timeout waiting for gatt write operation to complete");
|
||||
|
@ -47,15 +50,16 @@ public class CharacteristicReadOperation extends BLECommOperation {
|
|||
value = characteristic.getValue();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void gattOperationCompletionCallback(UUID uuid, byte[] value) {
|
||||
super.gattOperationCompletionCallback(uuid, value);
|
||||
if (!characteristic.getUuid().equals(uuid)) {
|
||||
LOG.error(String.format("Completion callback: UUID does not match! out of sequence? Found: %s, should be %s",
|
||||
LOG.error(String.format(
|
||||
"Completion callback: UUID does not match! out of sequence? Found: %s, should be %s",
|
||||
GattAttributes.lookup(characteristic.getUuid()), GattAttributes.lookup(uuid)));
|
||||
}
|
||||
operationComplete.release();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.os.SystemClock;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data.GattAttributes;
|
||||
|
@ -22,12 +22,14 @@ public class CharacteristicWriteOperation extends BLECommOperation {
|
|||
|
||||
private BluetoothGattCharacteristic characteristic;
|
||||
|
||||
|
||||
public CharacteristicWriteOperation(BluetoothGatt gatt, BluetoothGattCharacteristic chara, byte[] value) {
|
||||
this.gatt = gatt;
|
||||
this.characteristic = chara;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(RileyLinkBLE comm) {
|
||||
|
||||
|
@ -37,7 +39,8 @@ public class CharacteristicWriteOperation extends BLECommOperation {
|
|||
try {
|
||||
boolean didAcquire = operationComplete.tryAcquire(getGattOperationTimeout_ms(), TimeUnit.MILLISECONDS);
|
||||
if (didAcquire) {
|
||||
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier understanding of the sequence of events.
|
||||
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier
|
||||
// understanding of the sequence of events.
|
||||
// success
|
||||
} else {
|
||||
LOG.error("Timeout waiting for gatt write operation to complete");
|
||||
|
@ -50,15 +53,16 @@ public class CharacteristicWriteOperation extends BLECommOperation {
|
|||
|
||||
}
|
||||
|
||||
|
||||
// This will be run on the IBinder thread
|
||||
@Override
|
||||
public void gattOperationCompletionCallback(UUID uuid, byte[] value) {
|
||||
if (!characteristic.getUuid().equals(uuid)) {
|
||||
LOG.error(String.format("Completion callback: UUID does not match! out of sequence? Found: %s, should be %s",
|
||||
LOG.error(String.format(
|
||||
"Completion callback: UUID does not match! out of sequence? Found: %s, should be %s",
|
||||
GattAttributes.lookup(characteristic.getUuid()), GattAttributes.lookup(uuid)));
|
||||
}
|
||||
operationComplete.release();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.operations;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattDescriptor;
|
||||
import android.os.SystemClock;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattDescriptor;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkBLE;
|
||||
|
||||
|
@ -28,12 +28,14 @@ public class DescriptorWriteOperation extends BLECommOperation {
|
|||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void gattOperationCompletionCallback(UUID uuid, byte[] value) {
|
||||
super.gattOperationCompletionCallback(uuid, value);
|
||||
operationComplete.release();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(RileyLinkBLE comm) {
|
||||
descr.setValue(value);
|
||||
|
@ -42,7 +44,8 @@ public class DescriptorWriteOperation extends BLECommOperation {
|
|||
try {
|
||||
boolean didAcquire = operationComplete.tryAcquire(getGattOperationTimeout_ms(), TimeUnit.MILLISECONDS);
|
||||
if (didAcquire) {
|
||||
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier understanding of the sequence of events.
|
||||
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier
|
||||
// understanding of the sequence of events.
|
||||
// success
|
||||
} else {
|
||||
LOG.error("Timeout waiting for descriptor write operation to complete");
|
||||
|
|
|
@ -2,8 +2,12 @@ package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.data;
|
|||
|
||||
import org.joda.time.LocalDateTime;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkError;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkServiceState;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkTargetDevice;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicCommandType;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState;
|
||||
|
||||
/**
|
||||
* Created by andy on 5/19/18.
|
||||
|
@ -11,15 +15,38 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLink
|
|||
|
||||
public class RLHistoryItem {
|
||||
|
||||
private MedtronicCommandType medtronicCommandType;
|
||||
private LocalDateTime dateTime;
|
||||
private RLHistoryItemSource source;
|
||||
private RileyLinkServiceState serviceState;
|
||||
private RileyLinkError errorCode;
|
||||
|
||||
private RileyLinkTargetDevice targetDevice;
|
||||
private PumpDeviceState pumpDeviceState;
|
||||
|
||||
public RLHistoryItem(RileyLinkServiceState serviceState, RileyLinkError errorCode) {
|
||||
|
||||
public RLHistoryItem(RileyLinkServiceState serviceState, RileyLinkError errorCode,
|
||||
RileyLinkTargetDevice targetDevice) {
|
||||
this.targetDevice = targetDevice;
|
||||
this.dateTime = new LocalDateTime();
|
||||
this.serviceState = serviceState;
|
||||
this.errorCode = errorCode;
|
||||
this.source = RLHistoryItemSource.RileyLink;
|
||||
}
|
||||
|
||||
|
||||
public RLHistoryItem(PumpDeviceState pumpDeviceState, RileyLinkTargetDevice targetDevice) {
|
||||
this.pumpDeviceState = pumpDeviceState;
|
||||
this.dateTime = new LocalDateTime();
|
||||
this.targetDevice = targetDevice;
|
||||
this.source = RLHistoryItemSource.MedtronicPump;
|
||||
}
|
||||
|
||||
|
||||
public RLHistoryItem(MedtronicCommandType medtronicCommandType) {
|
||||
this.dateTime = new LocalDateTime();
|
||||
this.medtronicCommandType = medtronicCommandType;
|
||||
source = RLHistoryItemSource.MedtronicCommand;
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,4 +63,53 @@ public class RLHistoryItem {
|
|||
public RileyLinkError getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
|
||||
// TODO extend when we have Omnipod
|
||||
switch (this.source) {
|
||||
case RileyLink:
|
||||
return "State: " + MainApp.gs(serviceState.getResourceId(targetDevice))
|
||||
+ (this.errorCode == null ? "" : ", Error Code: " + errorCode);
|
||||
|
||||
case MedtronicPump:
|
||||
return MainApp.gs(pumpDeviceState.getResourceId());
|
||||
|
||||
case MedtronicCommand:
|
||||
return medtronicCommandType.name();
|
||||
|
||||
default:
|
||||
return "Unknown Description";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public RLHistoryItemSource getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
|
||||
public PumpDeviceState getPumpDeviceState() {
|
||||
return pumpDeviceState;
|
||||
}
|
||||
|
||||
public enum RLHistoryItemSource {
|
||||
RileyLink("RileyLink"), //
|
||||
MedtronicPump("Medtronic"), //
|
||||
MedtronicCommand("Medtronic");
|
||||
|
||||
private String desc;
|
||||
|
||||
|
||||
RLHistoryItemSource(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ public enum RileyLinkError {
|
|||
|
||||
// Configuration
|
||||
|
||||
|
||||
// BT
|
||||
NoBluetoothAdapter(R.string.rileylink_error_no_bt_adapter), //
|
||||
BluetoothDisabled(R.string.rileylink_error_bt_disabled), //
|
||||
|
@ -24,10 +23,10 @@ public enum RileyLinkError {
|
|||
NoContactWithDevice(R.string.rileylink_error_pump_unreachable, R.string.rileylink_error_pod_unreachable), //
|
||||
;
|
||||
|
||||
|
||||
int resourceId;
|
||||
Integer resourceIdPod;
|
||||
|
||||
|
||||
RileyLinkError(int resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
@ -43,7 +42,8 @@ public enum RileyLinkError {
|
|||
if (this.resourceIdPod != null) {
|
||||
|
||||
return targetDevice == RileyLinkTargetDevice.MedtronicPump ? //
|
||||
this.resourceId : this.resourceIdPod;
|
||||
this.resourceId
|
||||
: this.resourceIdPod;
|
||||
} else {
|
||||
return this.resourceId;
|
||||
}
|
||||
|
|
|
@ -11,23 +11,26 @@ public enum RileyLinkServiceState {
|
|||
NotStarted(R.string.rileylink_state_not_started), //
|
||||
|
||||
// Bluetooth
|
||||
BluetoothInitializing(R.string.rileylink_state_bt_init), // (S) init BT (if error no BT interface -> Disabled, BT not enabled -> BluetoothError)
|
||||
BluetoothInitializing(R.string.rileylink_state_bt_init), // (S) init BT (if error no BT interface -> Disabled, BT
|
||||
// not enabled -> BluetoothError)
|
||||
// BluetoothNotAvailable, // (E) BT not available, would happen only if device has no BT
|
||||
BluetoothError(R.string.rileylink_state_bt_error), // (E) if BT gets disabled ( -> EnableBluetooth)
|
||||
BluetoothReady(R.string.rileylink_state_bt_ready), // (OK)
|
||||
|
||||
// RileyLink
|
||||
RileyLinkInitializing(R.string.rileylink_state_rl_init), // (S) start Gatt discovery (OK -> RileyLinkReady, Error -> BluetoothEnabled) ??
|
||||
RileyLinkInitializing(R.string.rileylink_state_rl_init), // (S) start Gatt discovery (OK -> RileyLinkReady, Error ->
|
||||
// BluetoothEnabled) ??
|
||||
RileyLinkError(R.string.rileylink_state_rl_error), // (E)
|
||||
RileyLinkReady(R.string.rileylink_state_connected), // (OK) if tunning was already done we go to PumpConnectorReady
|
||||
|
||||
// Tunning
|
||||
TuneUpDevice(R.string.rileylink_state_pc_tune_up), // (S)
|
||||
PumpConnectorError(R.string.rileylink_state_pc_error), // either TuneUp Error or pump couldn't not be contacted error
|
||||
PumpConnectorError(R.string.rileylink_state_pc_error), // either TuneUp Error or pump couldn't not be contacted
|
||||
// error
|
||||
PumpConnectorReady(R.string.rileylink_state_connected), // (OK) RileyLink Ready for Pump Communication
|
||||
|
||||
//Initializing, // get all parameters required for connection (if not possible -> Disabled, if sucessful -> EnableBluetooth)
|
||||
|
||||
// Initializing, // get all parameters required for connection (if not possible -> Disabled, if sucessful ->
|
||||
// EnableBluetooth)
|
||||
|
||||
// EnableBlueTooth, // enable BT (if error no BT interface -> Disabled, BT not enabled -> BluetoothError)
|
||||
// BlueToothEnabled, // -> InitializeRileyLink
|
||||
|
@ -37,36 +40,39 @@ public enum RileyLinkServiceState {
|
|||
|
||||
// PumpConnected, //
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
int resourceId;
|
||||
Integer resourceIdPod;
|
||||
|
||||
|
||||
RileyLinkServiceState(int resourceId) {
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
|
||||
RileyLinkServiceState(int resourceId, int resourceIdPod) {
|
||||
this.resourceId = resourceId;
|
||||
this.resourceIdPod = resourceIdPod;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isReady(RileyLinkServiceState serviceState) {
|
||||
return (serviceState == RileyLinkReady || serviceState == PumpConnectorReady);
|
||||
}
|
||||
|
||||
|
||||
public int getResourceId(RileyLinkTargetDevice targetDevice) {
|
||||
if (this.resourceIdPod != null) {
|
||||
|
||||
return targetDevice == RileyLinkTargetDevice.MedtronicPump ? //
|
||||
this.resourceId : this.resourceIdPod;
|
||||
return (targetDevice == null || targetDevice == RileyLinkTargetDevice.MedtronicPump) ? //
|
||||
this.resourceId
|
||||
: this.resourceIdPod;
|
||||
} else {
|
||||
return this.resourceId;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isReady(RileyLinkServiceState serviceState) {
|
||||
return (serviceState == RileyLinkReady || serviceState == PumpConnectorReady);
|
||||
}
|
||||
|
||||
public boolean isConnecting() {
|
||||
|
||||
|
@ -78,10 +84,10 @@ public enum RileyLinkServiceState {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
public boolean isError() {
|
||||
|
||||
return (
|
||||
this == RileyLinkServiceState.BluetoothError || //
|
||||
return (this == RileyLinkServiceState.BluetoothError || //
|
||||
// this == RileyLinkServiceState.PumpConnectorError || //
|
||||
this == RileyLinkServiceState.RileyLinkError);
|
||||
}
|
||||
|
|
|
@ -1,22 +1,33 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
|
||||
/**
|
||||
* Created by andy on 5/19/18.
|
||||
*/
|
||||
|
||||
public enum RileyLinkTargetDevice {
|
||||
MedtronicPump(true), //
|
||||
Omnipod(false), //
|
||||
MedtronicPump(R.string.rileylink_target_device_medtronic, true), //
|
||||
Omnipod(R.string.rileylink_target_device_omnipod, false), //
|
||||
;
|
||||
|
||||
private int resourceId;
|
||||
private boolean tuneUpEnabled;
|
||||
|
||||
RileyLinkTargetDevice(boolean tuneUpEnabled) {
|
||||
|
||||
RileyLinkTargetDevice(int resourceId, boolean tuneUpEnabled) {
|
||||
this.resourceId = resourceId;
|
||||
|
||||
this.tuneUpEnabled = tuneUpEnabled;
|
||||
}
|
||||
|
||||
|
||||
public boolean isTuneUpEnabled() {
|
||||
return tuneUpEnabled;
|
||||
}
|
||||
|
||||
|
||||
public int getResourceId() {
|
||||
return resourceId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.dialog;
|
||||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.dialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
|
@ -11,17 +14,14 @@ import android.support.v7.app.AppCompatActivity;
|
|||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.dialog.RefreshableInterface;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.RileyLinkServiceData;
|
||||
|
||||
public class RileylinkSettingsActivity extends AppCompatActivity {
|
||||
|
||||
public class RileyLinkStatusActivity extends AppCompatActivity {
|
||||
|
||||
@BindView(R.id.rls_t1_connection_status)
|
||||
TextView connectionStatus;
|
||||
|
@ -34,36 +34,30 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
|
|||
|
||||
@BindView(R.id.rls_t1_connection_error)
|
||||
TextView connectionError;
|
||||
|
||||
RileyLinkServiceData rileyLinkServiceData;
|
||||
/**
|
||||
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
||||
* fragments for each of the sections. We use a
|
||||
* {@link FragmentPagerAdapter} derivative, which will keep every
|
||||
* fragments for each of the sections. We use a {@link FragmentPagerAdapter} derivative, which will keep every
|
||||
* loaded fragment in memory. If this becomes too memory intensive, it
|
||||
* may be best to switch to a
|
||||
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
|
||||
* may be best to switch to a {@link android.support.v4.app.FragmentStatePagerAdapter}.
|
||||
*/
|
||||
private SectionsPagerAdapter mSectionsPagerAdapter;
|
||||
private FloatingActionButton floatingActionButton;
|
||||
private TabLayout tabLayout;
|
||||
|
||||
RileyLinkServiceData rileyLinkServiceData;
|
||||
|
||||
/**
|
||||
* The {@link ViewPager} that will host the section contents.
|
||||
*/
|
||||
private ViewPager mViewPager;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.rileylink_settings);
|
||||
|
||||
setContentView(R.layout.rileylink_status);
|
||||
|
||||
// Create the adapter that will return a fragment for each of the three
|
||||
// primary sections of the activity.
|
||||
|
||||
|
||||
// Set up the ViewPager with the sections adapter.
|
||||
mViewPager = (ViewPager)findViewById(R.id.rileylink_settings_container);
|
||||
// mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
|
@ -72,18 +66,20 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
|
|||
tabLayout = (TabLayout)findViewById(R.id.rileylink_settings_tabs);
|
||||
tabLayout.setupWithViewPager(mViewPager);
|
||||
|
||||
|
||||
floatingActionButton = (FloatingActionButton)findViewById(R.id.rileylink_settings_fab);
|
||||
floatingActionButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
RefreshableInterface selectableInterface = (RefreshableInterface) mSectionsPagerAdapter.getItem(tabLayout.getSelectedTabPosition());
|
||||
RefreshableInterface selectableInterface = (RefreshableInterface)mSectionsPagerAdapter
|
||||
.getItem(tabLayout.getSelectedTabPosition());
|
||||
selectableInterface.refreshData();
|
||||
|
||||
// refreshData(tabLayout.getSelectedTabPosition());
|
||||
|
||||
//Toast.makeText(getApplicationContext(), "Test pos: " + tabLayout.getSelectedTabPosition(), Toast.LENGTH_LONG);
|
||||
// Toast.makeText(getApplicationContext(), "Test pos: " + tabLayout.getSelectedTabPosition(),
|
||||
// Toast.LENGTH_LONG);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -92,7 +88,6 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
|
|||
this.connectedDevice = (TextView)findViewById(R.id.rls_t1_connected_device);
|
||||
this.connectionError = (TextView)findViewById(R.id.rls_t1_connection_error);
|
||||
|
||||
|
||||
rileyLinkServiceData = RileyLinkUtil.getRileyLinkServiceData();
|
||||
|
||||
// // 7-12
|
||||
|
@ -124,7 +119,6 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
|
|||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -132,14 +126,13 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
|
|||
|
||||
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||
|
||||
mSectionsPagerAdapter.addFragment(new RileyLinkSettingsTab1(), MainApp.gs(R.string.rileylink_settings_tab1));
|
||||
mSectionsPagerAdapter.addFragment(new RileyLinkSettingsTab2(), MainApp.gs(R.string.rileylink_settings_tab2));
|
||||
mSectionsPagerAdapter.addFragment(new RileyLinkStatusGeneral(), MainApp.gs(R.string.rileylink_settings_tab1));
|
||||
mSectionsPagerAdapter.addFragment(new RileyLinkStatusHistory(), MainApp.gs(R.string.rileylink_settings_tab2));
|
||||
// mSectionsPagerAdapter.addFragment(new RileyLinkSettingsTab3(), "Tab 3");
|
||||
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
|
||||
* one of the sections/tabs/pages.
|
||||
|
@ -150,6 +143,7 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
|
|||
List<String> fragmentTitle = new ArrayList<>();
|
||||
int lastSelectedPosition = 0;
|
||||
|
||||
|
||||
public SectionsPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
@ -161,17 +155,20 @@ public class RileylinkSettingsActivity extends AppCompatActivity {
|
|||
return fragmentList.get(position);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
// Show 3 total pages.
|
||||
return fragmentList.size();
|
||||
}
|
||||
|
||||
|
||||
public void addFragment(Fragment fragment, String title) {
|
||||
this.fragmentList.add(fragment);
|
||||
this.fragmentTitle.add(title);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return fragmentTitle.get(position);
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,10 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service;
|
||||
|
||||
import static info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil.getRileyLinkCommunicationManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import android.app.Service;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.BroadcastReceiver;
|
||||
|
@ -9,9 +14,6 @@ import android.content.IntentFilter;
|
|||
import android.os.PowerManager;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkCommunicationManager;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkConst;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
|
||||
|
@ -30,37 +32,29 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.
|
|||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.ServiceTaskExecutor;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
import static info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil.getRileyLinkCommunicationManager;
|
||||
|
||||
//import static info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.;
|
||||
|
||||
|
||||
/**
|
||||
* Created by andy on 5/6/18.
|
||||
* Split from original file and renamed.
|
||||
*/
|
||||
public abstract class RileyLinkService extends Service {
|
||||
|
||||
protected static final String WAKELOCKNAME = "com.gxwtech.roundtrip2.RoundtripServiceWakeLock";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RileyLinkService.class);
|
||||
|
||||
|
||||
protected BluetoothAdapter bluetoothAdapter;
|
||||
|
||||
protected static volatile PowerManager.WakeLock lockStatic = null;
|
||||
// Our hardware/software connection
|
||||
public RileyLinkBLE rileyLinkBLE; // android-bluetooth management
|
||||
protected BluetoothAdapter bluetoothAdapter;
|
||||
protected RFSpy rfspy; // interface for RL xxx Mhz radio.
|
||||
// protected boolean needBluetoothPermission = true;
|
||||
// protected RileyLinkIPCConnection rileyLinkIPCConnection;
|
||||
protected Context context;
|
||||
// public RileyLinkCommunicationManager pumpCommunicationManager;
|
||||
protected BroadcastReceiver mBroadcastReceiver;
|
||||
|
||||
protected RileyLinkServiceData rileyLinkServiceData;
|
||||
protected RileyLinkTargetFrequency rileyLinkTargetFrequency;
|
||||
|
||||
protected static final String WAKELOCKNAME = "com.gxwtech.roundtrip2.RoundtripServiceWakeLock";
|
||||
protected static volatile PowerManager.WakeLock lockStatic = null;
|
||||
|
||||
|
||||
public RileyLinkService(Context context) {
|
||||
super();
|
||||
|
@ -119,11 +113,12 @@ public abstract class RileyLinkService extends Service {
|
|||
// rileyLinkIPCConnection = new RileyLinkIPCConnection(context); // TODO We might be able to remove this -- Andy
|
||||
// RileyLinkUtil.setRileyLinkIPCConnection(rileyLinkIPCConnection);
|
||||
|
||||
|
||||
mBroadcastReceiver = new BroadcastReceiver() {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
/* here we can listen for local broadcasts, then send ourselves
|
||||
/*
|
||||
* here we can listen for local broadcasts, then send ourselves
|
||||
* a specific intent to deal with them, if we wish
|
||||
*/
|
||||
if (intent == null) {
|
||||
|
@ -135,18 +130,22 @@ public abstract class RileyLinkService extends Service {
|
|||
} else {
|
||||
|
||||
if (action.equals(RileyLinkConst.Intents.BluetoothConnected)) {
|
||||
//rileyLinkIPCConnection.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_note_FindingRileyLink), null);
|
||||
// rileyLinkIPCConnection.sendNotification(new
|
||||
// ServiceNotification(RT2Const.IPC.MSG_note_FindingRileyLink), null);
|
||||
ServiceTaskExecutor.startTask(new DiscoverGattServicesTask());
|
||||
} else if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnected)) {
|
||||
if (bluetoothAdapter.isEnabled()) {
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothReady, RileyLinkError.RileyLinkUnreachable);
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothReady,
|
||||
RileyLinkError.RileyLinkUnreachable);
|
||||
} else {
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled);
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError,
|
||||
RileyLinkError.BluetoothDisabled);
|
||||
}
|
||||
} else if (action.equals(RileyLinkConst.Intents.RileyLinkReady)) {
|
||||
LOG.warn("MedtronicConst.Intents.RileyLinkReady");
|
||||
// FIXME
|
||||
//rileyLinkIPCConnection.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_note_WakingPump), null);
|
||||
// rileyLinkIPCConnection.sendNotification(new
|
||||
// ServiceNotification(RT2Const.IPC.MSG_note_WakingPump), null);
|
||||
rileyLinkBLE.enableNotifications();
|
||||
rfspy.startReader(); // call startReader from outside?
|
||||
|
||||
|
@ -163,7 +162,8 @@ public abstract class RileyLinkService extends Service {
|
|||
LOG.info("Announcing RileyLink open For business");
|
||||
} else if (action.equals(RileyLinkConst.Intents.BluetoothReconnected)) {
|
||||
LOG.debug("Reconnecting Bluetooth");
|
||||
//rileyLinkIPCConnection.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_note_FindingRileyLink), null);
|
||||
// rileyLinkIPCConnection.sendNotification(new
|
||||
// ServiceNotification(RT2Const.IPC.MSG_note_FindingRileyLink), null);
|
||||
bluetoothInit();
|
||||
ServiceTaskExecutor.startTask(new DiscoverGattServicesTask(true));
|
||||
} else if (action.equals(RileyLinkConst.IPC.MSG_PUMP_tunePump)) {
|
||||
|
@ -190,26 +190,26 @@ public abstract class RileyLinkService extends Service {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* else if (RT2Const.serviceLocal.INTENT_sessionCompleted.equals(action)) {
|
||||
* Bundle bundle = intent.getBundleExtra(RT2Const.IPC.bundleKey);
|
||||
* if (bundle != null) {
|
||||
* ServiceTransport transport = new ServiceTransport(bundle);
|
||||
* //rileyLinkIPCConnection.sendTransport(transport, transport.getSenderHashcode());
|
||||
* //RileyLinkUtil.send
|
||||
* } else {
|
||||
* LOG.error("sessionCompleted: no bundle!");
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*else if (RT2Const.serviceLocal.INTENT_sessionCompleted.equals(action)) {
|
||||
Bundle bundle = intent.getBundleExtra(RT2Const.IPC.bundleKey);
|
||||
if (bundle != null) {
|
||||
ServiceTransport transport = new ServiceTransport(bundle);
|
||||
//rileyLinkIPCConnection.sendTransport(transport, transport.getSenderHashcode());
|
||||
//RileyLinkUtil.send
|
||||
} else {
|
||||
LOG.error("sessionCompleted: no bundle!");
|
||||
}
|
||||
}*/
|
||||
|
||||
/*else
|
||||
|
||||
if (case RT2Const.local.INTENT_serviceConnected:
|
||||
case RT2Const.local.INTENT_NEW_rileylinkAddressKey:
|
||||
showIdle();
|
||||
/**
|
||||
/*
|
||||
* else
|
||||
*
|
||||
* if (case RT2Const.local.INTENT_serviceConnected:
|
||||
* case RT2Const.local.INTENT_NEW_rileylinkAddressKey:
|
||||
* showIdle();
|
||||
* /**
|
||||
* Client MUST send a "UseThisRileylink" message because it asserts that
|
||||
* the user has given explicit permission to use bluetooth.
|
||||
*
|
||||
|
@ -218,22 +218,22 @@ public abstract class RileyLinkService extends Service {
|
|||
* use the last known good value. But the kick-off of bluetooth ops must
|
||||
* come from an Activity.
|
||||
*/
|
||||
/* String RileylinkBLEAddress = SP.getString(MedtronicConst.Prefs.RileyLinkAddress, "");
|
||||
if (RileylinkBLEAddress.equals("")) {
|
||||
// TODO: 11/07/2016 @TIM UI message for user
|
||||
Log.e(TAG, "No Rileylink BLE Address saved in app");
|
||||
} else {
|
||||
//showBusy("Configuring Service", 50);
|
||||
MainApp.getServiceClientConnection().setThisRileylink(RileylinkBLEAddress);
|
||||
}
|
||||
break;
|
||||
case RT2Const.local.INTENT_NEW_pumpIDKey:
|
||||
MainApp.getServiceClientConnection().sendPUMP_useThisDevice(SP.getString(MedtronicConst.Prefs.PumpSerial, ""));
|
||||
break;
|
||||
|
||||
/*
|
||||
* String RileylinkBLEAddress = SP.getString(MedtronicConst.Prefs.RileyLinkAddress, "");
|
||||
* if (RileylinkBLEAddress.equals("")) {
|
||||
* // TODO: 11/07/2016 @TIM UI message for user
|
||||
* Log.e(TAG, "No Rileylink BLE Address saved in app");
|
||||
* } else {
|
||||
* //showBusy("Configuring Service", 50);
|
||||
* MainApp.getServiceClientConnection().setThisRileylink(RileylinkBLEAddress);
|
||||
* }
|
||||
* break;
|
||||
* case RT2Const.local.INTENT_NEW_pumpIDKey:
|
||||
* MainApp.getServiceClientConnection().sendPUMP_useThisDevice(SP.getString(MedtronicConst.Prefs.
|
||||
* PumpSerial, ""));
|
||||
* break;
|
||||
*/
|
||||
|
||||
|
||||
else {
|
||||
LOG.error("Unhandled broadcast: action=" + action);
|
||||
}
|
||||
|
@ -268,10 +268,13 @@ public abstract class RileyLinkService extends Service {
|
|||
|
||||
public abstract RileyLinkCommunicationManager getDeviceCommunicationManager();
|
||||
|
||||
|
||||
public abstract void addPumpSpecificIntents(IntentFilter intentFilter);
|
||||
|
||||
|
||||
public abstract void handlePumpSpecificIntents(Intent intent);
|
||||
|
||||
|
||||
public abstract void handleIncomingServiceTransport(Intent intent);
|
||||
|
||||
|
||||
|
@ -339,7 +342,8 @@ public abstract class RileyLinkService extends Service {
|
|||
LOG.info("No change to RL address. Not reconnecting.");
|
||||
return false;
|
||||
} else {
|
||||
LOG.warn("Disconnecting from old RL (" + rileyLinkServiceData.rileylinkAddress + "), reconnecting to new: " + deviceAddress);
|
||||
LOG.warn("Disconnecting from old RL (" + rileyLinkServiceData.rileylinkAddress
|
||||
+ "), reconnecting to new: " + deviceAddress);
|
||||
rileyLinkBLE.disconnect();
|
||||
// prolly need to shut down listening thread too?
|
||||
// SP.putString(MedtronicConst.Prefs.RileyLinkAddress, deviceAddress);
|
||||
|
@ -354,7 +358,8 @@ public abstract class RileyLinkService extends Service {
|
|||
|
||||
if (RileyLinkUtil.getServiceState() == RileyLinkServiceState.NotStarted) {
|
||||
if (!bluetoothInit()) {
|
||||
LOG.error("RileyLink can't get activated, Bluetooth is not functioning correctly. {}", RileyLinkUtil.getError().name());
|
||||
LOG.error("RileyLink can't get activated, Bluetooth is not functioning correctly. {}",
|
||||
RileyLinkUtil.getError().name());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -365,6 +370,7 @@ public abstract class RileyLinkService extends Service {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// public synchronized static PowerManager.WakeLock getLock(Context context) {
|
||||
// if (lockStatic == null) {
|
||||
|
@ -377,14 +383,15 @@ public abstract class RileyLinkService extends Service {
|
|||
// return lockStatic;
|
||||
// }
|
||||
|
||||
|
||||
public void sendServiceTransportResponse(ServiceTransport transport, ServiceResult serviceResult) {
|
||||
// get the key (hashcode) of the client who requested this
|
||||
/*Integer clientHashcode = transport.getSenderHashcode();
|
||||
// make a new bundle to send as the message data
|
||||
transport.setServiceResult(serviceResult);
|
||||
// FIXME
|
||||
transport.setTransportType(RT2Const.IPC.MSG_ServiceResult); */
|
||||
/*
|
||||
* Integer clientHashcode = transport.getSenderHashcode();
|
||||
* // make a new bundle to send as the message data
|
||||
* transport.setServiceResult(serviceResult);
|
||||
* // FIXME
|
||||
* transport.setTransportType(RT2Const.IPC.MSG_ServiceResult);
|
||||
*/
|
||||
// rileyLinkIPCConnection.sendTransport(transport, clientHashcode);
|
||||
LOG.error("sendServiceTransportResponse not implemented.");
|
||||
}
|
||||
|
@ -447,7 +454,8 @@ public abstract class RileyLinkService extends Service {
|
|||
|
||||
if (newFrequency == 0.0d) {
|
||||
// error tuning pump, pump not present ??
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.TuneUpOfDeviceFailed);
|
||||
RileyLinkUtil
|
||||
.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.TuneUpOfDeviceFailed);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkTargetDevice;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkError;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkServiceState;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkTargetDevice;
|
||||
|
||||
/**
|
||||
* Created by andy on 16/05/2018.
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.os.Bundle;
|
|||
* Created by geoff on 6/25/16.
|
||||
*/
|
||||
public class ServiceCommand extends ServiceMessage {
|
||||
|
||||
public ServiceCommand() {
|
||||
map = new Bundle();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.os.Bundle;
|
|||
* Base class for all messages passed between service and client
|
||||
*/
|
||||
public class ServiceMessage {
|
||||
|
||||
protected Bundle map = new Bundle();
|
||||
|
||||
|
||||
|
@ -36,5 +37,4 @@ public class ServiceMessage {
|
|||
return map.getString("ServiceMessageType");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@ import android.os.Bundle;
|
|||
/**
|
||||
* Created by geoff on 7/6/16.
|
||||
* <p>
|
||||
* These are "one liner" messages between client and service.
|
||||
* Must still be contained within ServiceTransports
|
||||
* These are "one liner" messages between client and service. Must still be contained within ServiceTransports
|
||||
*/
|
||||
public class ServiceNotification extends ServiceMessage {
|
||||
|
||||
public ServiceNotification() {
|
||||
}
|
||||
|
||||
|
@ -36,14 +36,13 @@ public class ServiceNotification extends ServiceMessage {
|
|||
}
|
||||
|
||||
|
||||
public void setNotificationType(String notificationType) {
|
||||
map.putString("NotificationType", notificationType);
|
||||
}
|
||||
|
||||
|
||||
public String getNotificationType() {
|
||||
return map.getString("NotificationType", "");
|
||||
}
|
||||
|
||||
|
||||
public void setNotificationType(String notificationType) {
|
||||
map.putString("NotificationType", notificationType);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,13 @@ import android.os.Bundle;
|
|||
* Created by geoff on 6/25/16.
|
||||
*/
|
||||
public class ServiceResult extends ServiceMessage {
|
||||
|
||||
public static final int ERROR_MALFORMED_PUMP_RESPONSE = 1;
|
||||
public static final int ERROR_NULL_PUMP_RESPONSE = 2;
|
||||
public static final int ERROR_INVALID_PUMP_RESPONSE = 3;
|
||||
public static final int ERROR_PUMP_BUSY = 4;
|
||||
|
||||
|
||||
public ServiceResult() {
|
||||
init();
|
||||
}
|
||||
|
@ -20,6 +27,22 @@ public class ServiceResult extends ServiceMessage {
|
|||
}
|
||||
|
||||
|
||||
public static final String getErrorDescription(int errorCode) {
|
||||
switch (errorCode) {
|
||||
case ERROR_MALFORMED_PUMP_RESPONSE:
|
||||
return "Malformed Pump Response";
|
||||
case ERROR_NULL_PUMP_RESPONSE:
|
||||
return "Null pump response";
|
||||
case ERROR_INVALID_PUMP_RESPONSE:
|
||||
return "Invalid pump response";
|
||||
case ERROR_PUMP_BUSY:
|
||||
return "A pump command session is already in progress";
|
||||
default:
|
||||
return "Unknown error code (" + errorCode + ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
|
@ -29,13 +52,13 @@ public class ServiceResult extends ServiceMessage {
|
|||
}
|
||||
|
||||
|
||||
public void setServiceResultType(String serviceResultType) {
|
||||
map.putString("ServiceResultType", serviceResultType);
|
||||
public String getServiceResultType() {
|
||||
return map.getString("ServiceResultType", "ServiceResult");
|
||||
}
|
||||
|
||||
|
||||
public String getServiceResultType() {
|
||||
return map.getString("ServiceResultType", "ServiceResult");
|
||||
public void setServiceResultType(String serviceResultType) {
|
||||
map.putString("ServiceResultType", serviceResultType);
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,28 +79,6 @@ public class ServiceResult extends ServiceMessage {
|
|||
}
|
||||
|
||||
|
||||
public static final int ERROR_MALFORMED_PUMP_RESPONSE = 1;
|
||||
public static final int ERROR_NULL_PUMP_RESPONSE = 2;
|
||||
public static final int ERROR_INVALID_PUMP_RESPONSE = 3;
|
||||
public static final int ERROR_PUMP_BUSY = 4;
|
||||
|
||||
|
||||
public static final String getErrorDescription(int errorCode) {
|
||||
switch (errorCode) {
|
||||
case ERROR_MALFORMED_PUMP_RESPONSE:
|
||||
return "Malformed Pump Response";
|
||||
case ERROR_NULL_PUMP_RESPONSE:
|
||||
return "Null pump response";
|
||||
case ERROR_INVALID_PUMP_RESPONSE:
|
||||
return "Invalid pump response";
|
||||
case ERROR_PUMP_BUSY:
|
||||
return "A pump command session is already in progress";
|
||||
default:
|
||||
return "Unknown error code (" + errorCode + ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean resultIsOK() {
|
||||
return ("OK".equals(map.getString("result", "")));
|
||||
}
|
||||
|
@ -92,5 +93,4 @@ public class ServiceResult extends ServiceMessage {
|
|||
return map.getString("result", "");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@ import android.os.Parcel;
|
|||
/**
|
||||
* Created by geoff on 7/6/16.
|
||||
* <p>
|
||||
* This class exists to hold a ServiceCommand along with transport variables
|
||||
* such as time sent, time received, sender.
|
||||
* This class exists to hold a ServiceCommand along with transport variables such as time sent, time received, sender.
|
||||
* May also contain result, if the command is completed.
|
||||
*/
|
||||
public class ServiceTransport extends ServiceMessage {
|
||||
|
@ -39,13 +38,18 @@ public class ServiceTransport extends ServiceMessage {
|
|||
}
|
||||
|
||||
|
||||
public Integer getSenderHashcode() {
|
||||
return map.getInt("senderHashCode", 0);
|
||||
}
|
||||
|
||||
|
||||
public void setSenderHashcode(Integer senderHashcode) {
|
||||
map.putInt("senderHashcode", senderHashcode);
|
||||
}
|
||||
|
||||
|
||||
public Integer getSenderHashcode() {
|
||||
return map.getInt("senderHashCode", 0);
|
||||
public ServiceCommand getServiceCommand() {
|
||||
return new ServiceCommand(map.getBundle("ServiceCommand"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,13 +59,13 @@ public class ServiceTransport extends ServiceMessage {
|
|||
}
|
||||
|
||||
|
||||
public ServiceCommand getServiceCommand() {
|
||||
return new ServiceCommand(map.getBundle("ServiceCommand"));
|
||||
public boolean hasServiceCommand() {
|
||||
return (getMap().containsKey("ServiceCommand"));
|
||||
}
|
||||
|
||||
|
||||
public boolean hasServiceCommand() {
|
||||
return (getMap().containsKey("ServiceCommand"));
|
||||
public String getTransportType() {
|
||||
return map.getString("transportType", "unknown");
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,8 +76,8 @@ public class ServiceTransport extends ServiceMessage {
|
|||
}
|
||||
|
||||
|
||||
public String getTransportType() {
|
||||
return map.getString("transportType", "unknown");
|
||||
public ServiceResult getServiceResult() {
|
||||
return new ServiceResult(map.getBundle("ServiceResult"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -83,13 +87,13 @@ public class ServiceTransport extends ServiceMessage {
|
|||
}
|
||||
|
||||
|
||||
public ServiceResult getServiceResult() {
|
||||
return new ServiceResult(map.getBundle("ServiceResult"));
|
||||
public boolean hasServiceResult() {
|
||||
return (getMap().containsKey("ServiceResult"));
|
||||
}
|
||||
|
||||
|
||||
public boolean hasServiceResult() {
|
||||
return (getMap().containsKey("ServiceResult"));
|
||||
public ServiceNotification getServiceNotification() {
|
||||
return new ServiceNotification(map.getBundle("ServiceNotification"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -99,11 +103,6 @@ public class ServiceTransport extends ServiceMessage {
|
|||
}
|
||||
|
||||
|
||||
public ServiceNotification getServiceNotification() {
|
||||
return new ServiceNotification(map.getBundle("ServiceNotification"));
|
||||
}
|
||||
|
||||
|
||||
public boolean hasServiceNotification() {
|
||||
return (map.containsKey("ServiceNotification"));
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ import info.nightscout.utils.SP;
|
|||
/**
|
||||
* Created by geoff on 7/9/16.
|
||||
* <p>
|
||||
* This class is intended to be run by the Service, for the Service.
|
||||
* Not intended for clients to run.
|
||||
* This class is intended to be run by the Service, for the Service. Not intended for clients to run.
|
||||
*/
|
||||
public class InitializePumpManagerTask extends ServiceTask {
|
||||
|
||||
private static final String TAG = "InitPumpManagerTask";
|
||||
|
||||
|
||||
|
@ -35,7 +35,10 @@ public class InitializePumpManagerTask extends ServiceTask {
|
|||
// FIXME
|
||||
double lastGoodFrequency = SP.getDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, 0.0d);
|
||||
|
||||
if ((lastGoodFrequency > 0.0d) && RileyLinkUtil.getRileyLinkCommunicationManager().isValidFrequency(lastGoodFrequency)) {
|
||||
RileyLinkUtil.getRileyLinkServiceData().lastGoodFrequency = lastGoodFrequency;
|
||||
|
||||
if ((lastGoodFrequency > 0.0d)
|
||||
&& RileyLinkUtil.getRileyLinkCommunicationManager().isValidFrequency(lastGoodFrequency)) {
|
||||
|
||||
Log.i(TAG, String.format("Setting radio frequency to %.2fMHz", lastGoodFrequency));
|
||||
RileyLinkUtil.getRileyLinkCommunicationManager().setRadioFrequencyForPump(lastGoodFrequency);
|
||||
|
@ -47,7 +50,8 @@ public class InitializePumpManagerTask extends ServiceTask {
|
|||
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorReady);
|
||||
// RileyLinkUtil.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_PUMP_pumpFound), null);
|
||||
} else {
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.NoContactWithDevice);
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError,
|
||||
RileyLinkError.NoContactWithDevice);
|
||||
// RileyLinkUtil.sendNotification(new ServiceNotification(RT2Const.IPC.MSG_PUMP_pumpLost), null);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.data.S
|
|||
* Created by geoff on 7/10/16.
|
||||
*/
|
||||
public class PumpTask extends ServiceTask {
|
||||
|
||||
public PumpTask() {
|
||||
super();
|
||||
}
|
||||
|
|
|
@ -6,9 +6,10 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.data.S
|
|||
* Created by geoff on 7/9/16.
|
||||
*/
|
||||
public class ServiceTask implements Runnable {
|
||||
|
||||
private static final String TAG = "ServiceTask(base)";
|
||||
protected ServiceTransport mTransport;
|
||||
public boolean completed = false;
|
||||
protected ServiceTransport mTransport;
|
||||
|
||||
|
||||
public ServiceTask() {
|
||||
|
@ -46,9 +47,8 @@ public class ServiceTask implements Runnable {
|
|||
}
|
||||
|
||||
/*
|
||||
protected void sendResponse(ServiceResult result) {
|
||||
RoundtripService.getInstance().sendServiceTransportResponse(mTransport,result);
|
||||
}
|
||||
* protected void sendResponse(ServiceResult result) {
|
||||
* RoundtripService.getInstance().sendServiceTransportResponse(mTransport,result);
|
||||
* }
|
||||
*/
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
|
||||
|
||||
/**
|
||||
* Created by geoff on 7/9/16.
|
||||
*/
|
||||
public class ServiceTaskExecutor extends ThreadPoolExecutor {
|
||||
|
||||
private static final String TAG = "ServiceTaskExecutor";
|
||||
private static ServiceTaskExecutor instance;
|
||||
private static LinkedBlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<>();
|
||||
|
@ -20,15 +21,17 @@ public class ServiceTaskExecutor extends ThreadPoolExecutor {
|
|||
instance = new ServiceTaskExecutor();
|
||||
}
|
||||
|
||||
public static ServiceTaskExecutor getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private ServiceTaskExecutor() {
|
||||
super(1, 1, 10000, TimeUnit.MILLISECONDS, taskQueue);
|
||||
}
|
||||
|
||||
|
||||
public static ServiceTaskExecutor getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
public static ServiceTask startTask(ServiceTask task) {
|
||||
instance.execute(task); // task will be run on async thread from pool.
|
||||
return task;
|
||||
|
|
|
@ -8,7 +8,6 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.service.RileyLinkMedtron
|
|||
*/
|
||||
public class WakeAndTuneTask extends PumpTask {
|
||||
|
||||
|
||||
public WakeAndTuneTask() {
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,9 @@ import java.util.List;
|
|||
* Created by geoff on 4/28/15.
|
||||
*/
|
||||
public class ByteUtil {
|
||||
private final static char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
|
||||
private final static char[] HEX_DIGITS = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
private final static String HEX_DIGITS_STR = "0123456789ABCDEF";
|
||||
|
||||
|
@ -26,8 +28,8 @@ public class ByteUtil {
|
|||
return (b < 0) ? b + 256 : b;
|
||||
}
|
||||
|
||||
/* For Reference: static void System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length) */
|
||||
|
||||
/* For Reference: static void System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length) */
|
||||
|
||||
public static byte[] concat(byte[] a, byte[] b) {
|
||||
|
||||
|
@ -218,12 +220,6 @@ public class ByteUtil {
|
|||
}
|
||||
|
||||
|
||||
public enum BitConversion {
|
||||
LITTLE_ENDIAN, // 20 0 0 0 = reverse
|
||||
BIG_ENDIAN // 0 0 0 20 = normal - java
|
||||
}
|
||||
|
||||
|
||||
public static List<Byte> getListFromByteArray(byte[] array) {
|
||||
List<Byte> listOut = new ArrayList<Byte>();
|
||||
|
||||
|
@ -240,4 +236,9 @@ public class ByteUtil {
|
|||
return k;
|
||||
}
|
||||
|
||||
public enum BitConversion {
|
||||
LITTLE_ENDIAN, // 20 0 0 0 = reverse
|
||||
BIG_ENDIAN // 0 0 0 20 = normal - java
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,17 +5,71 @@ package info.nightscout.androidaps.plugins.PumpCommon.utils;
|
|||
*/
|
||||
public class CRC {
|
||||
|
||||
static final int[] crc8lookup = new int[]{0, 155, 173, 54, 193, 90, 108, 247, 25, 130, 180, 47, 216, 67, 117, 238, 50, 169, //
|
||||
159, 4, 243, 104, 94, 197, 43, 176, 134, 29, 234, 113, 71, 220, 100, 255, 201, 82, 165, 62, 8, 147, 125, 230, 208, 75, //
|
||||
188, 39, 17, 138, 86, 205, 251, 96, 151, 12, 58, 161, 79, 212, 226, 121, 142, 21, 35, 184, 200, 83, 101, 254, 9, 146, //
|
||||
164, 63, 209, 74, 124, 231, 16, 139, 189, 38, 250, 97, 87, 204, 59, 160, 150, 13, 227, 120, 78, 213, 34, 185, 143, 20, //
|
||||
172, 55, 1, 154, 109, 246, 192, 91, 181, 46, 24, 131, 116, 239, 217, 66, 158, 5, 51, 168, 95, 196, 242, 105, 135, 28, 42, //
|
||||
177, 70, 221, 235, 112, 11, 144, 166, 61, 202, 81, 103, 252, 18, 137, 191, 36, 211, 72, 126, 229, 57, 162, 148, 15, 248, //
|
||||
99, 85, 206, 32, 187, 141, 22, 225, 122, 76, 215, 111, 244, 194, 89, 174, 53, 3, 152, 118, 237, 219, 64, 183, 44, 26, 129, //
|
||||
93, 198, 240, 107, 156, 7, 49, 170, 68, 223, 233, 114, 133, 30, 40, 179, 195, 88, 110, 245, 2, 153, 175, 52, 218, 65, 119, //
|
||||
236, 27, 128, 182, 45, 241, 106, 92, 199, 48, 171, 157, 6, 232, 115, 69, 222, 41, 178, 132, 31, 167, 60, 10, 145, 102, 253, //
|
||||
203, 80, 190, 37, 19, 136, 127, 228, 210, 73, 149, 14, 56, 163, 84, 207, 249, 98, 140, 23, 33, 186, 77, 214, 224, 123};
|
||||
|
||||
static final int[] crc8lookup = new int[] {
|
||||
0, 155, 173, 54, 193, 90, 108, 247, 25,
|
||||
130,
|
||||
180,
|
||||
47,
|
||||
216,
|
||||
67,
|
||||
117,
|
||||
238,
|
||||
50,
|
||||
169, //
|
||||
159, 4, 243, 104, 94, 197, 43, 176, 134, 29, 234, 113, 71, 220, 100, 255, 201,
|
||||
82,
|
||||
165,
|
||||
62,
|
||||
8,
|
||||
147,
|
||||
125,
|
||||
230,
|
||||
208,
|
||||
75, //
|
||||
188, 39, 17, 138, 86, 205, 251, 96, 151, 12, 58, 161, 79, 212, 226, 121, 142, 21,
|
||||
35,
|
||||
184,
|
||||
200,
|
||||
83,
|
||||
101,
|
||||
254,
|
||||
9,
|
||||
146, //
|
||||
164, 63, 209, 74, 124, 231, 16, 139, 189, 38, 250, 97, 87, 204, 59, 160, 150, 13, 227,
|
||||
120,
|
||||
78,
|
||||
213,
|
||||
34,
|
||||
185,
|
||||
143,
|
||||
20, //
|
||||
172, 55, 1, 154, 109, 246, 192, 91, 181, 46, 24, 131, 116, 239, 217, 66, 158, 5, 51, 168, 95,
|
||||
196,
|
||||
242,
|
||||
105,
|
||||
135,
|
||||
28,
|
||||
42, //
|
||||
177, 70, 221, 235, 112, 11, 144, 166, 61, 202, 81, 103, 252, 18, 137, 191, 36, 211, 72, 126, 229,
|
||||
57,
|
||||
162,
|
||||
148,
|
||||
15,
|
||||
248, //
|
||||
99, 85, 206, 32, 187, 141, 22, 225, 122, 76, 215, 111, 244, 194, 89, 174, 53, 3, 152, 118, 237, 219, 64,
|
||||
183,
|
||||
44,
|
||||
26,
|
||||
129, //
|
||||
93, 198, 240, 107, 156, 7, 49, 170, 68, 223, 233, 114, 133, 30, 40, 179, 195, 88, 110, 245, 2, 153, 175, 52,
|
||||
218,
|
||||
65,
|
||||
119, //
|
||||
236, 27, 128, 182, 45, 241, 106, 92, 199, 48, 171, 157, 6, 232, 115, 69, 222, 41, 178, 132, 31, 167, 60, 10,
|
||||
145, 102,
|
||||
253, //
|
||||
203, 80, 190, 37, 19, 136, 127, 228, 210, 73, 149, 14, 56, 163, 84, 207, 249, 98, 140, 23, 33, 186, 77, 214,
|
||||
224, 123 };
|
||||
|
||||
|
||||
public static byte crc8(byte[] data, int len) {
|
||||
|
@ -57,7 +111,8 @@ public class CRC {
|
|||
boolean bit = ((b >> (7 - i) & 1) == 1);
|
||||
boolean c15 = ((crc >> 15 & 1) == 1);
|
||||
crc <<= 1;
|
||||
if (c15 ^ bit) crc ^= polynomial;
|
||||
if (c15 ^ bit)
|
||||
crc ^= polynomial;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,9 @@ import java.util.List;
|
|||
* only.
|
||||
*/
|
||||
public class HexDump {
|
||||
private final static char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
|
||||
private final static char[] HEX_DIGITS = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
|
||||
public static String dumpHexString(byte[] array) {
|
||||
|
@ -227,5 +229,4 @@ public class HexDump {
|
|||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -10,11 +10,11 @@ import android.os.Build;
|
|||
|
||||
import info.nightscout.androidaps.R;
|
||||
|
||||
|
||||
/**
|
||||
* Helper for checking if location services are enabled on the device.
|
||||
*/
|
||||
public class LocationHelper {
|
||||
|
||||
/**
|
||||
* Determine if GPS is currently enabled.
|
||||
* <p>
|
||||
|
@ -28,6 +28,7 @@ public class LocationHelper {
|
|||
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prompt the user to enable GPS location if it isn't already on.
|
||||
*
|
||||
|
@ -44,6 +45,7 @@ public class LocationHelper {
|
|||
builder.setTitle(R.string.location_not_found_title);
|
||||
builder.setMessage(R.string.location_not_found_message);
|
||||
builder.setPositiveButton(R.string.location_yes, new DialogInterface.OnClickListener() {
|
||||
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
parent.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
|
||||
}
|
||||
|
@ -52,6 +54,7 @@ public class LocationHelper {
|
|||
builder.create().show();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prompt the user to enable GPS location on devices that need it for Bluetooth discovery.
|
||||
* <p>
|
||||
|
@ -67,7 +70,8 @@ public class LocationHelper {
|
|||
}
|
||||
|
||||
// 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;
|
||||
// }
|
||||
|
||||
}
|
|
@ -11,13 +11,12 @@ import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
|
|||
|
||||
public class PumpUtil {
|
||||
|
||||
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType)
|
||||
{
|
||||
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType) {
|
||||
setPumpDescription(pumpDescription, pumpType, false);
|
||||
}
|
||||
|
||||
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType, boolean isVirtualPump)
|
||||
{
|
||||
|
||||
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType, boolean isVirtualPump) {
|
||||
PumpCapability pumpCapability = isVirtualPump ? PumpCapability.VirtualPump : pumpType.getPumpCapability();
|
||||
|
||||
pumpDescription.isBolusCapable = pumpCapability.hasCapability(PumpCapability.Bolus);
|
||||
|
@ -30,14 +29,11 @@ public class PumpUtil {
|
|||
|
||||
pumpDescription.isTempBasalCapable = pumpCapability.hasCapability(PumpCapability.TBR);
|
||||
|
||||
if (pumpType.getPumpTempBasalType()==PumpTempBasalType.Percent)
|
||||
{
|
||||
if (pumpType.getPumpTempBasalType() == PumpTempBasalType.Percent) {
|
||||
pumpDescription.tempBasalStyle = PumpDescription.PERCENT;
|
||||
pumpDescription.maxTempPercent = pumpType.getTbrSettings().getMaxDose().intValue();
|
||||
pumpDescription.tempPercentStep = (int)pumpType.getTbrSettings().getStep();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
pumpDescription.tempBasalStyle = PumpDescription.ABSOLUTE;
|
||||
pumpDescription.maxTempAbsolute = pumpType.getTbrSettings().getMaxDose();
|
||||
pumpDescription.tempAbsoluteStep = pumpType.getTbrSettings().getStep();
|
||||
|
@ -46,7 +42,6 @@ public class PumpUtil {
|
|||
pumpDescription.tempDurationStep = pumpType.getTbrSettings().getDurationStep();
|
||||
pumpDescription.tempMaxDuration = pumpType.getTbrSettings().getMaxDuration();
|
||||
|
||||
|
||||
pumpDescription.isSetBasalProfileCapable = pumpCapability.hasCapability(PumpCapability.BasalProfileSet);
|
||||
pumpDescription.basalStep = pumpType.getBaseBasalStep();
|
||||
pumpDescription.basalMinimumRate = pumpType.getBaseBasalMinValue();
|
||||
|
@ -55,5 +50,4 @@ public class PumpUtil {
|
|||
pumpDescription.storesCarbInfo = pumpCapability.hasCapability(PumpCapability.StoreCarbInfo);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.utils;
|
||||
|
||||
import org.joda.time.LocalDateTime;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.joda.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* Created by geoff on 4/28/15.
|
||||
*/
|
||||
public class StringUtil {
|
||||
|
||||
|
||||
public static DecimalFormat DecimalFormaters[] = {new DecimalFormat("#0"), new DecimalFormat("#0.0"), new DecimalFormat("#0.00"), new DecimalFormat("#0.000")};
|
||||
public static DecimalFormat DecimalFormaters[] = {
|
||||
new DecimalFormat("#0"), new DecimalFormat("#0.0"), new DecimalFormat("#0.00"), new DecimalFormat("#0.000") };
|
||||
|
||||
|
||||
public static String fromBytes(byte[] ra) {
|
||||
|
|
|
@ -4,6 +4,7 @@ package info.nightscout.androidaps.plugins.PumpCommon.utils;
|
|||
* Created by geoff on 5/27/16.
|
||||
*/
|
||||
public class ThreadUtil {
|
||||
|
||||
public static long getThreadId() {
|
||||
return Thread.currentThread().getId();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package info.nightscout.androidaps.plugins.PumpMedtronic;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
|
@ -15,18 +19,14 @@ import android.widget.Button;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
import com.crashlytics.android.Crashlytics;
|
||||
import com.joanzapata.iconify.widget.IconTextView;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||
|
@ -34,11 +34,11 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
|||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.dialog.RileylinkSettingsActivity;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkError;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkServiceState;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.defs.RileyLinkTargetDevice;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.dialog.RileyLinkStatusActivity;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicCommandType;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.driver.MedtronicPumpStatus;
|
||||
|
@ -53,10 +53,40 @@ import info.nightscout.utils.DecimalFormatter;
|
|||
import info.nightscout.utils.SetWarnColor;
|
||||
|
||||
public class MedtronicFragment extends SubscriberFragment {
|
||||
private static Logger LOG = LoggerFactory.getLogger(MedtronicFragment.class);
|
||||
|
||||
private static Logger LOG = LoggerFactory.getLogger(MedtronicFragment.class);
|
||||
@BindView(R.id.medtronic_lastconnection)
|
||||
TextView lastConnectionView;
|
||||
@BindView(R.id.medtronic_lastbolus)
|
||||
TextView lastBolusView;
|
||||
@BindView(R.id.medtronic_basabasalrate)
|
||||
TextView basaBasalRateView;
|
||||
|
||||
// @BindView(R.id.medtronic_btconnection)
|
||||
// TextView btConnectionView;
|
||||
@BindView(R.id.medtronic_tempbasal)
|
||||
TextView tempBasalView;
|
||||
@BindView(R.id.medtronic_pumpstate_battery)
|
||||
TextView batteryView;
|
||||
@BindView(R.id.medtronic_rl_status)
|
||||
IconTextView rileyLinkStatus;
|
||||
@BindView(R.id.medtronic_reservoir)
|
||||
TextView reservoirView;
|
||||
@BindView(R.id.medtronic_errors)
|
||||
TextView errorsView;
|
||||
@BindView(R.id.medtronic_queue)
|
||||
TextView queueView;
|
||||
@BindView(R.id.overview_pumpstatuslayout)
|
||||
LinearLayout pumpStatusLayout;
|
||||
@BindView(R.id.overview_pump_medtronic)
|
||||
TextView overviewPumpMedtronicView;
|
||||
@BindView(R.id.medtronic_pump_status)
|
||||
IconTextView pumpStatusIconView;
|
||||
@BindView(R.id.medtronic_refresh)
|
||||
Button refreshButton;
|
||||
private Handler loopHandler = new Handler();
|
||||
private Runnable refreshLoop = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
updateGUI();
|
||||
|
@ -64,53 +94,11 @@ public class MedtronicFragment extends SubscriberFragment {
|
|||
}
|
||||
};
|
||||
|
||||
@BindView(R.id.medtronic_lastconnection)
|
||||
TextView lastConnectionView;
|
||||
|
||||
//@BindView(R.id.medtronic_btconnection)
|
||||
//TextView btConnectionView;
|
||||
|
||||
@BindView(R.id.medtronic_lastbolus)
|
||||
TextView lastBolusView;
|
||||
|
||||
@BindView(R.id.medtronic_basabasalrate)
|
||||
TextView basaBasalRateView;
|
||||
|
||||
@BindView(R.id.medtronic_tempbasal)
|
||||
TextView tempBasalView;
|
||||
|
||||
@BindView(R.id.medtronic_pumpstate_battery)
|
||||
TextView batteryView;
|
||||
|
||||
@BindView(R.id.medtronic_rl_status)
|
||||
IconTextView rileyLinkStatus;
|
||||
|
||||
@BindView(R.id.medtronic_reservoir)
|
||||
TextView reservoirView;
|
||||
|
||||
@BindView(R.id.medtronic_errors)
|
||||
TextView errorsView;
|
||||
|
||||
|
||||
@BindView(R.id.medtronic_queue)
|
||||
TextView queueView;
|
||||
|
||||
@BindView(R.id.overview_pumpstatuslayout)
|
||||
LinearLayout pumpStatusLayout;
|
||||
|
||||
@BindView(R.id.overview_pump_medtronic)
|
||||
TextView overviewPumpMedtronicView;
|
||||
|
||||
@BindView(R.id.medtronic_pump_status)
|
||||
IconTextView pumpStatusIconView;
|
||||
|
||||
@BindView(R.id.medtronic_refresh)
|
||||
Button refreshButton;
|
||||
|
||||
|
||||
public MedtronicFragment() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -124,9 +112,9 @@ public class MedtronicFragment extends SubscriberFragment {
|
|||
loopHandler.removeCallbacks(refreshLoop);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
try {
|
||||
View view = inflater.inflate(R.layout.medtronic_fragment, container, false);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
|
@ -148,17 +136,20 @@ public class MedtronicFragment extends SubscriberFragment {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
@OnClick(R.id.medtronic_history)
|
||||
void onHistoryClick() {
|
||||
// startActivity(new Intent(getContext(), DanaRHistoryActivity.class));
|
||||
}
|
||||
|
||||
|
||||
@OnClick(R.id.medtronic_refresh)
|
||||
void onRefreshClick() {
|
||||
refreshButton.setEnabled(false);
|
||||
MedtronicPumpPlugin.getPlugin().resetStatusState();
|
||||
|
||||
ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked refresh", new Callback() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
refreshButton.setEnabled(true);
|
||||
|
@ -166,9 +157,10 @@ public class MedtronicFragment extends SubscriberFragment {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
@OnClick(R.id.medtronic_stats)
|
||||
void onStatsClick() {
|
||||
startActivity(new Intent(getContext(), RileylinkSettingsActivity.class));
|
||||
startActivity(new Intent(getContext(), RileyLinkStatusActivity.class));
|
||||
}
|
||||
|
||||
|
||||
|
@ -184,16 +176,15 @@ public class MedtronicFragment extends SubscriberFragment {
|
|||
Activity activity = getActivity();
|
||||
// final String status = c.textStatus();
|
||||
if (activity != null) {
|
||||
activity.runOnUiThread(
|
||||
new Runnable() {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
|
||||
setDeviceStatus(pumpStatus);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -201,7 +192,8 @@ public class MedtronicFragment extends SubscriberFragment {
|
|||
|
||||
private void setDeviceStatus(MedtronicPumpStatus pumpStatus) {
|
||||
|
||||
pumpStatus.rileyLinkServiceState = (RileyLinkServiceState) checkStatusSet(pumpStatus.rileyLinkServiceState, RileyLinkUtil.getServiceState());
|
||||
pumpStatus.rileyLinkServiceState = (RileyLinkServiceState)checkStatusSet(pumpStatus.rileyLinkServiceState,
|
||||
RileyLinkUtil.getServiceState());
|
||||
|
||||
if (pumpStatus.rileyLinkServiceState != null) {
|
||||
|
||||
|
@ -230,8 +222,8 @@ public class MedtronicFragment extends SubscriberFragment {
|
|||
} else
|
||||
errorsView.setText("-");
|
||||
|
||||
|
||||
pumpStatus.pumpDeviceState = (PumpDeviceState) checkStatusSet(pumpStatus.pumpDeviceState, MedtronicUtil.getPumpDeviceState());
|
||||
pumpStatus.pumpDeviceState = (PumpDeviceState)checkStatusSet(pumpStatus.pumpDeviceState,
|
||||
MedtronicUtil.getPumpDeviceState());
|
||||
|
||||
if (pumpStatus.pumpDeviceState != null) {
|
||||
// TODO Pump State
|
||||
|
@ -278,7 +270,6 @@ public class MedtronicFragment extends SubscriberFragment {
|
|||
pumpStatusIconView.setText("{fa-bed} ");
|
||||
}
|
||||
|
||||
|
||||
if (queueView != null) {
|
||||
Spanned status = ConfigBuilderPlugin.getCommandQueue().spannedStatus();
|
||||
if (status.toString().equals("")) {
|
||||
|
@ -289,7 +280,6 @@ public class MedtronicFragment extends SubscriberFragment {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -320,27 +310,32 @@ public class MedtronicFragment extends SubscriberFragment {
|
|||
updateGUI();
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventTempBasalChange s) {
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventExtendedBolusChange s) {
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventQueueChanged s) {
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
|
||||
// GUI functions
|
||||
@Override
|
||||
protected void updateGUI() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null && basaBasalRateView != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -384,22 +379,23 @@ public class MedtronicFragment extends SubscriberFragment {
|
|||
lastBolusView.setText("");
|
||||
}
|
||||
|
||||
|
||||
// base basal rate
|
||||
basaBasalRateView.setText("(" + (pumpStatus.activeProfileName) + ") " + MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate()));
|
||||
|
||||
basaBasalRateView.setText("(" + (pumpStatus.activeProfileName) + ") "
|
||||
+ MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate()));
|
||||
|
||||
// FIXME temp basal - check - maybe set as combo ??
|
||||
if (ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses()) {
|
||||
if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) {
|
||||
tempBasalView.setText(TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
|
||||
tempBasalView.setText(TreatmentsPlugin.getPlugin()
|
||||
.getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
|
||||
} else {
|
||||
tempBasalView.setText("");
|
||||
}
|
||||
} else {
|
||||
// v2 plugin
|
||||
if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
|
||||
tempBasalView.setText(TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
|
||||
tempBasalView.setText(TreatmentsPlugin.getPlugin()
|
||||
.getTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
|
||||
} else {
|
||||
tempBasalView.setText("");
|
||||
}
|
||||
|
@ -410,7 +406,8 @@ public class MedtronicFragment extends SubscriberFragment {
|
|||
SetWarnColor.setColorInverse(batteryView, pumpStatus.batteryRemaining, 51d, 26d);
|
||||
|
||||
// reservoir
|
||||
reservoirView.setText(DecimalFormatter.to0Decimal(pumpStatus.reservoirRemainingUnits) + " / " + pumpStatus.reservoirFullUnits + " " + MainApp.gs(R.string.insulin_unit_shortname));
|
||||
reservoirView.setText(DecimalFormatter.to0Decimal(pumpStatus.reservoirRemainingUnits) + " / "
|
||||
+ pumpStatus.reservoirFullUnits + " " + MainApp.gs(R.string.insulin_unit_shortname));
|
||||
SetWarnColor.setColorInverse(reservoirView, pumpStatus.reservoirRemainingUnits, 50d, 20d);
|
||||
|
||||
errorsView.setText(pumpStatus.getErrorInfo());
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
package info.nightscout.androidaps.plugins.PumpMedtronic;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.IBinder;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
|
@ -30,6 +31,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
|||
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.PumpPluginAbstract;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkConst;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.ServiceTaskExecutor;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.WakeAndTuneTask;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.ui.MedtronicUIComm;
|
||||
|
@ -53,10 +55,8 @@ import info.nightscout.utils.SP;
|
|||
public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInterface {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MedtronicPumpPlugin.class);
|
||||
|
||||
|
||||
private RileyLinkMedtronicService medtronicService;
|
||||
protected static MedtronicPumpPlugin plugin = null;
|
||||
private RileyLinkMedtronicService medtronicService;
|
||||
private MedtronicPumpStatus pumpStatusLocal = null;
|
||||
private MedtronicUIComm medtronicUIComm = new MedtronicUIComm();
|
||||
|
||||
|
@ -68,13 +68,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
private Map<MedtronicStatusRefreshType, Long> statusRefreshMap = new HashMap<>();
|
||||
|
||||
|
||||
public static MedtronicPumpPlugin getPlugin() {
|
||||
if (plugin == null)
|
||||
plugin = new MedtronicPumpPlugin();
|
||||
return plugin;
|
||||
}
|
||||
|
||||
|
||||
private MedtronicPumpPlugin() {
|
||||
|
||||
// super(new PluginDescription() //
|
||||
|
@ -84,7 +77,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
// .shortName(R.string.medtronic_name_short) //
|
||||
// .preferencesId(R.xml.pref_medtronic));
|
||||
|
||||
|
||||
super(new MedtronicPumpDriver(), //
|
||||
"MedtronicPump", //
|
||||
new PluginDescription() //
|
||||
|
@ -103,6 +95,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
medtronicService = null;
|
||||
}
|
||||
|
||||
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
LOG.debug("RileyLinkMedtronicService is connected");
|
||||
RileyLinkMedtronicService.LocalBinder mLocalBinder = (RileyLinkMedtronicService.LocalBinder)service;
|
||||
|
@ -126,12 +119,22 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
}
|
||||
|
||||
|
||||
public static MedtronicPumpPlugin getPlugin() {
|
||||
if (plugin == null)
|
||||
plugin = new MedtronicPumpPlugin();
|
||||
return plugin;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initPumpStatusData() {
|
||||
|
||||
this.pumpStatusLocal = new MedtronicPumpStatus(pumpDescription);
|
||||
MedtronicUtil.setPumpStatus(pumpStatusLocal);
|
||||
|
||||
pumpStatusLocal.lastConnection = SP.getLong(RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
|
||||
pumpStatusLocal.lastDataTime = new LocalDateTime(pumpStatusLocal.lastConnection);
|
||||
|
||||
pumpStatusLocal.refreshConfiguration();
|
||||
|
||||
LOG.debug("initPumpStatusData: {}", this.pumpStatusLocal);
|
||||
|
@ -164,6 +167,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
}
|
||||
|
||||
|
||||
public void onStartCustomActions() {
|
||||
|
||||
// check status every minute
|
||||
|
@ -178,7 +182,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
} while (serviceRunning);
|
||||
|
||||
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
@ -193,6 +196,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
return "Medtronic";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PumpDescription getPumpDescription() {
|
||||
return this.pumpDescription;
|
||||
|
@ -216,6 +220,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
return isServiceSet() && medtronicService.isInitialized();
|
||||
}
|
||||
|
||||
|
||||
// FIXME
|
||||
public boolean isSuspended() {
|
||||
return isServiceSet() && medtronicService.isSuspended();
|
||||
|
@ -246,7 +251,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
getMDTPumpStatus();
|
||||
|
||||
|
||||
if (firstRun) {
|
||||
initializePump(true);
|
||||
} else {
|
||||
|
@ -261,6 +265,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
firstRun = true;
|
||||
}
|
||||
|
||||
|
||||
private void refreshAnyStatusThatNeedsToBeRefreshed() {
|
||||
|
||||
if (!doWeHaveAnyStatusNeededRefereshing()) {
|
||||
|
@ -310,6 +315,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void initializePump(boolean realInit) {
|
||||
|
||||
LOG.error("initializePump - start");
|
||||
|
@ -322,7 +328,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
} else {
|
||||
if (pumpStatusLocal.medtronicDeviceType != MedtronicUtil.getMedtronicPumpModel()) {
|
||||
LOG.warn("Configured pump is not the same as one detected.");
|
||||
Notification notification = new Notification(Notification.MEDTRONIC_PUMP_ALARM, MainApp.gs(R.string.medtronic_error_pump_type_set_differs_from_detected), Notification.NORMAL);
|
||||
Notification notification = new Notification(Notification.MEDTRONIC_PUMP_ALARM,
|
||||
MainApp.gs(R.string.medtronic_error_pump_type_set_differs_from_detected), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
}
|
||||
}
|
||||
|
@ -331,7 +338,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
// pump history handling - special, updates every 5 minutes ???
|
||||
readPumpHistory();
|
||||
|
||||
|
||||
// TODO rewrite reading of data to be done in background or different thread perhaps ??
|
||||
|
||||
// remaining insulin (>50 = 4h; 50-20 = 1h; 15m)
|
||||
|
@ -352,7 +358,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
// read profile (once, later its controlled by isThisProfileSet method)
|
||||
medtronicUIComm.executeCommand(MedtronicCommandType.GetBasalProfileSTD);
|
||||
|
||||
|
||||
// TODO handle if tunning was needed (more than 5 timeouts)
|
||||
int errorCount = medtronicUIComm.getInvalidResponsesCount();
|
||||
|
||||
|
@ -406,7 +411,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
index++;
|
||||
}
|
||||
|
||||
|
||||
if (!invalid) {
|
||||
LOG.debug("Basal profile is same as AAPS one.");
|
||||
} else {
|
||||
|
@ -427,12 +431,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
@Override
|
||||
public Date lastDataTime() {
|
||||
if (pumpStatusLocal != null && pumpStatusLocal.lastDataTime != null) {
|
||||
return pumpStatusLocal.lastDataTime;
|
||||
return pumpStatusLocal.lastDataTime.toDate();
|
||||
}
|
||||
|
||||
return new Date();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getBaseBasalRate() {
|
||||
return getMDTPumpStatus().getBasalProfileForHour();
|
||||
|
@ -462,7 +467,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
LOG.error("MedtronicPumpPlugin::deliverBolus Not fully implemented - Just base command.");
|
||||
|
||||
// TODO should wait and display bolus delivery
|
||||
MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetBolus, detailedBolusInfo.insulin);
|
||||
MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetBolus,
|
||||
detailedBolusInfo.insulin);
|
||||
|
||||
Boolean response = (Boolean)responseTask.returnData;
|
||||
|
||||
|
@ -472,17 +478,19 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
// FIXME this needs to be fixed to read info from history
|
||||
boolean treatmentCreated = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
|
||||
|
||||
getMDTPumpStatus().reservoirRemainingUnits -= detailedBolusInfo.insulin; // we subtract insulin, exact amount will be visible with next remainingInsulin update.
|
||||
getMDTPumpStatus().reservoirRemainingUnits -= detailedBolusInfo.insulin; // we subtract insulin, exact
|
||||
// amount will be visible with
|
||||
// next remainingInsulin
|
||||
// update.
|
||||
|
||||
incrementStatistics(detailedBolusInfo.isSMB ? MedtronicConst.Statistics.SMBBoluses : MedtronicConst.Statistics.StandardBoluses);
|
||||
incrementStatistics(detailedBolusInfo.isSMB ? MedtronicConst.Statistics.SMBBoluses
|
||||
: MedtronicConst.Statistics.StandardBoluses);
|
||||
}
|
||||
|
||||
readPumpHistory();
|
||||
|
||||
|
||||
return new PumpEnactResult().success(response).enacted(response);
|
||||
|
||||
|
||||
// pump.activity = MainApp.gs(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin);
|
||||
// MainApp.bus().post(new EventComboPumpUpdateGUI());
|
||||
//
|
||||
|
@ -521,7 +529,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
// return new PumpEnactResult().success(true).enacted(false);
|
||||
// }
|
||||
//
|
||||
// BolusProgressReporter progressReporter = detailedBolusInfo.isSMB ? nullBolusProgressReporter : bolusProgressReporter;
|
||||
// BolusProgressReporter progressReporter = detailedBolusInfo.isSMB ? nullBolusProgressReporter :
|
||||
// bolusProgressReporter;
|
||||
//
|
||||
// // start bolus delivery
|
||||
// scripterIsBolusing = true;
|
||||
|
@ -540,7 +549,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
// return new PumpEnactResult().success(false).enacted(false)
|
||||
// .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed));
|
||||
// }
|
||||
// Bolus lastPumpBolus = postBolusStateResult.history != null && !postBolusStateResult.history.bolusHistory.isEmpty()
|
||||
// Bolus lastPumpBolus = postBolusStateResult.history != null &&
|
||||
// !postBolusStateResult.history.bolusHistory.isEmpty()
|
||||
// ? postBolusStateResult.history.bolusHistory.get(0)
|
||||
// : null;
|
||||
//
|
||||
|
@ -564,7 +574,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
// // check pump bolus record has a sane timestamp
|
||||
// long now = System.currentTimeMillis();
|
||||
// if (lastPumpBolus.timestamp < now - 10 * 60 * 1000 || lastPumpBolus.timestamp > now + 10 * 60 * 1000) {
|
||||
// Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_suspious_bolus_time), Notification.URGENT);
|
||||
// Notification notification = new Notification(Notification.COMBO_PUMP_ALARM,
|
||||
// MainApp.gs(R.string.combo_suspious_bolus_time), Notification.URGENT);
|
||||
// MainApp.bus().post(new EventNewNotification(notification));
|
||||
// }
|
||||
//
|
||||
|
@ -609,7 +620,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
// if enforceNew===true current temp basal is canceled and new TBR set (duration is prolonged),
|
||||
// if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed
|
||||
@Override
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile,
|
||||
boolean enforceNew) {
|
||||
|
||||
LOG.error("MedtronicPumpPlugin::setTempBasalAbsolute Not fully implemented - Just base command.");
|
||||
|
||||
|
@ -625,7 +637,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
// TODO translate
|
||||
return new PumpEnactResult().success(false).enacted(false).comment("Couldn't read current TBR.");
|
||||
} else {
|
||||
LOG.info("MedtronicPumpPlugin::setTempBasalAbsolute: Current Basal: duration: {} min, rate={}", tbrCurrent.getDurationMinutes(), tbrCurrent.getInsulinRate());
|
||||
LOG.info("MedtronicPumpPlugin::setTempBasalAbsolute: Current Basal: duration: {} min, rate={}",
|
||||
tbrCurrent.getDurationMinutes(), tbrCurrent.getInsulinRate());
|
||||
}
|
||||
|
||||
// FIXME doesn't work correctly. Read current TBR first
|
||||
|
@ -647,7 +660,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
// if not the same rate, we cancel and start new
|
||||
}
|
||||
|
||||
|
||||
// if TBR is running we will cancel it.
|
||||
if (tbrCurrent.getInsulinRate() != 0.0f && tbrCurrent.getDurationMinutes() > 0) {
|
||||
LOG.info("MedtronicPumpPlugin::setTempBasalAbsolute - TBR running - so canceling it.");
|
||||
|
@ -662,13 +674,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
LOG.info("MedtronicPumpPlugin::setTempBasalAbsolute - Current TBR cancelled.");
|
||||
} else {
|
||||
LOG.error("MedtronicPumpPlugin::setTempBasalAbsolute - Cancel TBR failed.");
|
||||
return new PumpEnactResult().success(false).enacted(false).comment("Couldn't cancel current TBR. Stopping operation. ");
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
.comment("Couldn't cancel current TBR. Stopping operation. ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// now start new TBR
|
||||
MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetTemporaryBasal, absoluteRate, durationInMinutes);
|
||||
MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetTemporaryBasal,
|
||||
absoluteRate, durationInMinutes);
|
||||
|
||||
Boolean response = (Boolean)responseTask.returnData;
|
||||
|
||||
|
@ -681,11 +694,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
pumpStatusLocal.tempBasalLength = durationInMinutes;
|
||||
|
||||
// FIXME should be read from history
|
||||
TemporaryBasal tempStart = new TemporaryBasal()
|
||||
.date(System.currentTimeMillis())
|
||||
.duration(durationInMinutes)
|
||||
.absolute(absoluteRate)
|
||||
.source(Source.USER);
|
||||
TemporaryBasal tempStart = new TemporaryBasal().date(System.currentTimeMillis())
|
||||
.duration(durationInMinutes).absolute(absoluteRate).source(Source.USER);
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStart);
|
||||
|
||||
incrementStatistics(MedtronicConst.Statistics.TBRsSet);
|
||||
|
@ -744,7 +754,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
case Configuration:
|
||||
case PumpHistory: {
|
||||
statusRefreshMap.put(refreshType, getTimeInFutureFromMinutes(refreshType.getRefreshTime() + additionalTimeInMinutes));
|
||||
statusRefreshMap.put(refreshType, getTimeInFutureFromMinutes(refreshType.getRefreshTime()
|
||||
+ additionalTimeInMinutes));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -787,6 +798,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO
|
||||
@Override
|
||||
public PumpEnactResult cancelTempBasal(boolean enforceNew) {
|
||||
|
@ -826,7 +838,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||
LOG.warn("MedtronicPumpPlugin::setNewBasalProfile NOT IMPLEMENTED YET.");
|
||||
|
||||
return new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(R.string.medtronic_cmd_profile_not_set));
|
||||
return new PumpEnactResult().success(false).enacted(false)
|
||||
.comment(MainApp.gs(R.string.medtronic_cmd_profile_not_set));
|
||||
}
|
||||
|
||||
|
||||
|
@ -841,7 +854,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
|
||||
@Override
|
||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile,
|
||||
boolean enforceNew) {
|
||||
LOG.error("setTempBasalPercent NOT IMPLEMENTED.");
|
||||
// we will never come here unless somebody has played with configuration in PumpType
|
||||
return OPERATION_NOT_SUPPORTED;
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package info.nightscout.androidaps.plugins.PumpMedtronic.comm;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemClock;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.joda.time.Instant;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import android.content.Context;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkCommunicationManager;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RFSpy;
|
||||
|
@ -40,7 +40,6 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState;
|
|||
import info.nightscout.androidaps.plugins.PumpMedtronic.service.RileyLinkMedtronicService;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
|
||||
|
||||
|
||||
/**
|
||||
* Original file created by geoff on 5/30/16.
|
||||
* <p>
|
||||
|
@ -53,9 +52,9 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
private static final int DEFAULT_TIMEOUT = 2000;
|
||||
|
||||
static MedtronicCommunicationManager medtronicCommunicationManager;
|
||||
private MedtronicConverter medtronicConverter;
|
||||
|
||||
String errorMessage;
|
||||
private MedtronicConverter medtronicConverter;
|
||||
private boolean debugSetCommands = true;
|
||||
|
||||
|
||||
public MedtronicCommunicationManager(Context context, RFSpy rfspy, RileyLinkTargetFrequency targetFrequency) {
|
||||
|
@ -65,6 +64,11 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
}
|
||||
|
||||
|
||||
public static MedtronicCommunicationManager getInstance() {
|
||||
return medtronicCommunicationManager;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void configurePumpSpecificSettings() {
|
||||
pumpStatus = MedtronicUtil.getPumpStatus();
|
||||
|
@ -86,7 +90,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
|
||||
MedtronicDeviceType pumpModel = getPumpModel();
|
||||
|
||||
// Andy (4.6.2018): we do retry if no data returned. We might need to do that everywhere, but that might require little bit of rewrite of RF Code.
|
||||
// Andy (4.6.2018): we do retry if no data returned. We might need to do that everywhere, but that might require
|
||||
// little bit of rewrite of RF Code.
|
||||
if (pumpModel == MedtronicDeviceType.Unknown_Device) {
|
||||
|
||||
SystemClock.sleep(1000);
|
||||
|
@ -94,7 +99,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
pumpModel = getPumpModel();
|
||||
}
|
||||
|
||||
|
||||
boolean connected = (pumpModel != MedtronicDeviceType.Unknown_Device);
|
||||
|
||||
if (connected) {
|
||||
|
@ -102,10 +106,10 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
setLastConnectionTime();
|
||||
}
|
||||
|
||||
|
||||
return (pumpModel != MedtronicDeviceType.Unknown_Device);
|
||||
}
|
||||
|
||||
|
||||
private void setLastConnectionTime() {
|
||||
|
||||
// FIXME rename
|
||||
|
@ -113,22 +117,14 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
|
||||
// FIXME set to SP
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void checkFirstConnectionTime() {
|
||||
// FIXME set to SP
|
||||
}
|
||||
|
||||
|
||||
public static MedtronicCommunicationManager getInstance() {
|
||||
return medtronicCommunicationManager;
|
||||
}
|
||||
|
||||
|
||||
private boolean debugSetCommands = true;
|
||||
|
||||
|
||||
// FIXME remove debugs - Andy
|
||||
private PumpMessage runCommandWithArgs(PumpMessage msg) {
|
||||
|
||||
|
@ -167,7 +163,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
return new PumpMessage("No ACK after start message.");
|
||||
}
|
||||
|
||||
|
||||
int start = 0;
|
||||
int frameNr = 1;
|
||||
int len = 0;
|
||||
|
@ -214,10 +209,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
|
||||
} while (true);
|
||||
|
||||
|
||||
return rval;
|
||||
|
||||
|
||||
// return new PumpMessage("No ACK");
|
||||
}
|
||||
|
||||
|
@ -226,14 +219,16 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
public Page getPumpHistoryPage(int pageNumber) {
|
||||
RawHistoryPage rval = new RawHistoryPage();
|
||||
wakeUp(receiverDeviceAwakeForMinutes, false);
|
||||
PumpMessage getHistoryMsg = makePumpMessage(MedtronicCommandType.GetHistoryData, new GetHistoryPageCarelinkMessageBody(pageNumber));
|
||||
PumpMessage getHistoryMsg = makePumpMessage(MedtronicCommandType.GetHistoryData,
|
||||
new GetHistoryPageCarelinkMessageBody(pageNumber));
|
||||
// LOG.info("getPumpHistoryPage("+pageNumber+"): "+ByteUtil.shortHexString(getHistoryMsg.getTxData()));
|
||||
// Ask the pump to transfer history (we get first frame?)
|
||||
PumpMessage firstResponse = runCommandWithArgs(getHistoryMsg);
|
||||
// LOG.info("getPumpHistoryPage("+pageNumber+"): " + ByteUtil.shortHexString(firstResponse.getContents()));
|
||||
|
||||
PumpMessage ackMsg = makePumpMessage(MedtronicCommandType.CommandACK, new PumpAckMessageBody());
|
||||
GetHistoryPageCarelinkMessageBody currentResponse = new GetHistoryPageCarelinkMessageBody(firstResponse.getMessageBody().getTxData());
|
||||
GetHistoryPageCarelinkMessageBody currentResponse = new GetHistoryPageCarelinkMessageBody(firstResponse
|
||||
.getMessageBody().getTxData());
|
||||
int expectedFrameNum = 1;
|
||||
boolean done = false;
|
||||
// while (expectedFrameNum == currentResponse.getFrameNumber()) {
|
||||
|
@ -249,7 +244,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
}
|
||||
// handle successful frame data
|
||||
rval.appendData(currentResponse.getFrameData());
|
||||
RileyLinkMedtronicService.getInstance().announceProgress(((100 / 16) * currentResponse.getFrameNumber() + 1));
|
||||
RileyLinkMedtronicService.getInstance().announceProgress(
|
||||
((100 / 16) * currentResponse.getFrameNumber() + 1));
|
||||
LOG.info("getPumpHistoryPage: Got frame " + currentResponse.getFrameNumber());
|
||||
// Do we need to ask for the next frame?
|
||||
if (expectedFrameNum < 16) { // This number may not be correct for pumps other than 522/722
|
||||
|
@ -261,13 +257,15 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
if (frameData == null) {
|
||||
LOG.error("null frame data, retrying");
|
||||
} else if (currentResponse.getFrameNumber() != expectedFrameNum) {
|
||||
LOG.warn("Expected frame number {}, received {} (retrying)", expectedFrameNum, currentResponse.getFrameNumber());
|
||||
LOG.warn("Expected frame number {}, received {} (retrying)", expectedFrameNum,
|
||||
currentResponse.getFrameNumber());
|
||||
} else if (frameData.length == 0) {
|
||||
LOG.warn("Frame has zero length, retrying");
|
||||
}
|
||||
failures++;
|
||||
if (failures == 6) {
|
||||
LOG.error("6 failures in attempting to download frame {} of page {}, giving up.", expectedFrameNum, pageNumber);
|
||||
LOG.error("6 failures in attempting to download frame {} of page {}, giving up.", expectedFrameNum,
|
||||
pageNumber);
|
||||
done = true; // failure completion.
|
||||
}
|
||||
}
|
||||
|
@ -329,7 +327,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
// See ButtonPressCarelinkMessageBody
|
||||
public void pressButton(int which) {
|
||||
wakeUp(receiverDeviceAwakeForMinutes, false);
|
||||
PumpMessage pressButtonMessage = makePumpMessage(MedtronicCommandType.PushButton, new ButtonPressCarelinkMessageBody(which));
|
||||
PumpMessage pressButtonMessage = makePumpMessage(MedtronicCommandType.PushButton,
|
||||
new ButtonPressCarelinkMessageBody(which));
|
||||
PumpMessage resp = sendAndListen(pressButtonMessage);
|
||||
if (resp.commandType != MedtronicCommandType.CommandACK) {
|
||||
LOG.error("Pump did not ack button press.");
|
||||
|
@ -351,13 +350,11 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
// @Override
|
||||
// public RLMessage makeRLMessage(byte[] data) {
|
||||
// return makePumpMessage(data);
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public byte[] createPumpMessageContent(RLMessageType type) {
|
||||
switch (type) {
|
||||
|
@ -373,7 +370,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
|
||||
|
||||
protected PumpMessage makePumpMessage(MedtronicCommandType messageType, byte[] body) {
|
||||
return makePumpMessage(messageType, body == null ? new CarelinkShortMessageBody() : new CarelinkShortMessageBody(body));
|
||||
return makePumpMessage(messageType, body == null ? new CarelinkShortMessageBody()
|
||||
: new CarelinkShortMessageBody(body));
|
||||
}
|
||||
|
||||
|
||||
|
@ -391,11 +389,11 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
|
||||
// protected PumpMessage makePumpMessage(byte[] typeAndBody) {
|
||||
// PumpMessage msg = new PumpMessage();
|
||||
// msg.init(ByteUtil.concat(ByteUtil.concat(new byte[]{PacketType.Carelink.getValue()}, rileyLinkServiceData.pumpIDBytes), typeAndBody));
|
||||
// msg.init(ByteUtil.concat(ByteUtil.concat(new byte[]{PacketType.Carelink.getValue()},
|
||||
// rileyLinkServiceData.pumpIDBytes), typeAndBody));
|
||||
// return msg;
|
||||
// }
|
||||
|
||||
|
||||
private PumpMessage sendAndGetResponse(MedtronicCommandType commandType) {
|
||||
|
||||
return sendAndGetResponse(commandType, null, DEFAULT_TIMEOUT);
|
||||
|
@ -413,6 +411,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
return sendAndGetResponse(commandType, bodyData, DEFAULT_TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Main wrapper method for sending data - (for getting responses)
|
||||
*
|
||||
|
@ -462,7 +461,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
// return response;
|
||||
// }
|
||||
|
||||
|
||||
protected PumpMessage sendAndListen(RLMessage msg) {
|
||||
return sendAndListen(msg, 4000); // 2000
|
||||
}
|
||||
|
@ -484,7 +482,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
|
||||
for (int retries = 0; retries < MAX_COMMAND_RETRIES; retries++) {
|
||||
|
||||
PumpMessage response = sendAndGetResponse(commandType, bodyData, DEFAULT_TIMEOUT + (DEFAULT_TIMEOUT * retries));
|
||||
PumpMessage response = sendAndGetResponse(commandType, bodyData, DEFAULT_TIMEOUT
|
||||
+ (DEFAULT_TIMEOUT * retries));
|
||||
|
||||
String check = checkResponseContent(response, commandType.commandDescription, commandType.expectedLength);
|
||||
|
||||
|
@ -514,7 +513,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
return responseData;
|
||||
}
|
||||
|
||||
|
||||
byte[] contents = response.getRawContent();
|
||||
|
||||
if (contents != null) {
|
||||
|
@ -523,7 +521,9 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
return null;
|
||||
|
||||
} else {
|
||||
String responseData = String.format("%s: Cannot return data. Data is too short [expected=%s, received=%s].", method, "" + expectedLength, "" + contents.length);
|
||||
String responseData = String.format(
|
||||
"%s: Cannot return data. Data is too short [expected=%s, received=%s].", method, ""
|
||||
+ expectedLength, "" + contents.length);
|
||||
|
||||
LOG.warn(responseData);
|
||||
return responseData;
|
||||
|
@ -570,10 +570,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
//
|
||||
// }
|
||||
|
||||
|
||||
// PUMP SPECIFIC COMMANDS
|
||||
|
||||
|
||||
public Float getRemainingInsulin() {
|
||||
|
||||
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.GetRemainingInsulin);
|
||||
|
@ -620,7 +618,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -688,7 +687,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
|
||||
// FIXME --- After this line commands in development --- REMOVE THIS COMMANDS
|
||||
|
||||
|
||||
// TODO test
|
||||
|
||||
// TODO remove, we will see state from History
|
||||
|
@ -707,7 +705,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
|
||||
// TODO remove, we will see bolus status from History
|
||||
public PumpMessage getBolusStatus() {
|
||||
PumpMessage response = sendAndGetResponse(MedtronicCommandType.SetBolus, new byte[]{0x03, 0x00, 0x00, 0x00}, 4000);
|
||||
PumpMessage response = sendAndGetResponse(MedtronicCommandType.SetBolus, new byte[] { 0x03, 0x00, 0x00, 0x00 },
|
||||
4000);
|
||||
|
||||
byte[] data = response.getRawContent();
|
||||
|
||||
|
@ -722,42 +721,66 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
// TODO generateRawData (check if it works correctly) and test
|
||||
public Boolean setBasalProfile(BasalProfile basalProfile) {
|
||||
|
||||
|
||||
// [RileyLinkDevice] ======================== Save Basal Profile ===========================
|
||||
// [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 1 bytes), 0, 0.180000, 3)
|
||||
// [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] 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 ---------------------------
|
||||
// [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 65 bytes), 0,
|
||||
// 0.180000, 3)
|
||||
// [PeripheralManager+RileyLink] RL Send:
|
||||
// 79050000000000000000b4030000a9659a6b19b199c571c9a555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555556000
|
||||
// 2018-06-30 15:03:13.333962-0500 Loop[24609:13622692] [PeripheralManager+RileyLink] RL Recv(single):
|
||||
// dd10bda9659a6b19b156655534d500
|
||||
// 2018-06-30 15:03:13.334927-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink,
|
||||
// setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
|
||||
// 2018-06-30 15:03:13.337923-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send:
|
||||
// 79050000000000000000b4030000a9659a6b19b199c5725555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555ac000
|
||||
// 2018-06-30 15:03:14.114024-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single):
|
||||
// dd0ebea9659a6b19b156655534d500
|
||||
// 2018-06-30 15:03:14.115017-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink,
|
||||
// setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
|
||||
// 2018-06-30 15:03:14.117600-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send:
|
||||
// 79050000000000000000b4030000a9659a6b19b199c6a355555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555570e000
|
||||
// 2018-06-30 15:03:15.644502-0500 Loop[24609:13622692] [PeripheralManager+RileyLink] RL Recv(single):
|
||||
// dd0ebfa9659a6b19b156655534d500
|
||||
// 2018-06-30 15:03:15.645388-0500 Loop[24609:13622484] [RileyLinkDevice] ------------------------ Save Basal
|
||||
// Profile ---------------------------
|
||||
|
||||
|
||||
// 2018-06-30 15:03:12.167767-0500 Loop[24609:13622484] [RileyLinkDevice] ======================== Save Basal Profile ===========================
|
||||
// 2018-06-30 15:03:12.168652-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 1 bytes), 0, 0.180000, 3)
|
||||
// 2018-06-30 15:03:12.169518-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send: 19050000000000000000b4030000a9659a6b19b199c555b2c000
|
||||
// 2018-06-30 15:03:12.167767-0500 Loop[24609:13622484] [RileyLinkDevice] ======================== Save Basal
|
||||
// Profile ===========================
|
||||
// 2018-06-30 15:03:12.168652-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink,
|
||||
// setBasalProfileStandard, 3 bytes, 1 bytes), 0, 0.180000, 3)
|
||||
// 2018-06-30 15:03:12.169518-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send:
|
||||
// 19050000000000000000b4030000a9659a6b19b199c555b2c000
|
||||
// 2018-06-30 15:03:12.463546-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single): bb
|
||||
// 2018-06-30 15:03:12.463954-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RileyLink response: PacketResponse(code: RileyLinkBLEKit.ResponseCode.commandInterrupted, packet: nil)
|
||||
// 2018-06-30 15:03:12.554051-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single): dd0dbca9659a6b19b156655534d500
|
||||
// 2018-06-30 15:03:12.555175-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
|
||||
// 2018-06-30 15:03:12.557953-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send: 79050000000000000000b4030000a9659a6b19b199c571c9a555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555556000
|
||||
// 2018-06-30 15:03:13.333962-0500 Loop[24609:13622692] [PeripheralManager+RileyLink] RL Recv(single): dd10bda9659a6b19b156655534d500
|
||||
// 2018-06-30 15:03:13.334927-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
|
||||
// 2018-06-30 15:03:13.337923-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send: 79050000000000000000b4030000a9659a6b19b199c5725555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555ac000
|
||||
// 2018-06-30 15:03:14.114024-0500 Loop[24609:13622486] [PeripheralManager+RileyLink] RL Recv(single): dd0ebea9659a6b19b156655534d500
|
||||
// 2018-06-30 15:03:14.115017-0500 Loop[24609:13622484] [PumpMessageSender] getResponse(PumpMessage(carelink, setBasalProfileStandard, 3 bytes, 65 bytes), 0, 0.180000, 3)
|
||||
// 2018-06-30 15:03:14.117600-0500 Loop[24609:13622484] [PeripheralManager+RileyLink] RL Send: 79050000000000000000b4030000a9659a6b19b199c6a355555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555570e000
|
||||
// 2018-06-30 15:03:15.644502-0500 Loop[24609:13622692] [PeripheralManager+RileyLink] RL Recv(single): dd0ebfa9659a6b19b156655534d500
|
||||
// 2018-06-30 15:03:15.645388-0500 Loop[24609:13622484] [RileyLinkDevice] ------------------------ Save Basal Profile ---------------------------
|
||||
|
||||
// 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();
|
||||
|
||||
|
@ -800,7 +823,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
// return newBodyData;
|
||||
// }
|
||||
|
||||
|
||||
// public byte[] getEmptyMessage(int length) {
|
||||
// byte newBodyData[] = new byte[length];
|
||||
// for (int i = 0; i < length; i++) {
|
||||
|
@ -810,7 +832,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
// return newBodyData;
|
||||
// }
|
||||
|
||||
|
||||
public PumpMessage cancelBolus() {
|
||||
// ? maybe suspend and resume
|
||||
return null;
|
||||
|
@ -830,6 +851,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
// Set TBR 100%
|
||||
// Cancel TBR (set TBR 100%) 100%
|
||||
// Get Status (40%)
|
||||
|
@ -844,7 +866,6 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
// Read History 60%
|
||||
// Load TDD ?
|
||||
|
||||
|
||||
// FIXME remove - each part needs to be gotten manually
|
||||
public void updatePumpManagerStatus() {
|
||||
// Integer resp = getRemainingBattery();
|
||||
|
@ -883,5 +904,4 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -28,15 +28,15 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data;
|
|||
* GGW: TODO: examine src/ecc1/medtronic for better history parsing
|
||||
*/
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.utils.HexDump;
|
||||
|
@ -49,14 +49,14 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType
|
|||
|
||||
@Deprecated
|
||||
public class Page {
|
||||
|
||||
private final static String TAG = "Page";
|
||||
private static final boolean DEBUG_PAGE = true;
|
||||
|
||||
private byte[] crc;
|
||||
private byte[] data;
|
||||
// protected PumpModel model;
|
||||
public static MedtronicDeviceType model = MedtronicDeviceType.Medtronic_522;
|
||||
public List<Record> mRecordList;
|
||||
private byte[] crc;
|
||||
private byte[] data;
|
||||
|
||||
|
||||
public Page() {
|
||||
|
@ -65,6 +65,104 @@ public class Page {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* attemptParseRecord will attempt to create a subclass of Record from the given
|
||||
* data and offset. It will return NULL if it fails. If it succeeds, the returned
|
||||
* subclass of Record can be examined for its length, so that the next attempt can be made.
|
||||
*
|
||||
* TODO maybe try to change this, so that we can loose all the classes and using enum instead with full
|
||||
* configuration. Its something to think about for later versions -- Andy
|
||||
*/
|
||||
public static <T extends Record> T attemptParseRecord(byte[] data, int offsetStart) {
|
||||
// no data?
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
// invalid offset?
|
||||
if (data.length < offsetStart) {
|
||||
return null;
|
||||
}
|
||||
// Log.d(TAG,String.format("checking for handler for record type 0x%02X at index %d",data[offsetStart],offsetStart));
|
||||
RecordTypeEnum en = RecordTypeEnum.fromByte(data[offsetStart]);
|
||||
T record = en.getRecordClassInstance(model);
|
||||
if (record != null) {
|
||||
// have to do this to set the record's opCode
|
||||
byte[] tmpData = new byte[data.length];
|
||||
System.arraycopy(data, offsetStart, tmpData, 0, data.length - offsetStart);
|
||||
boolean didParse = record.parseWithOffset(tmpData, model, offsetStart);
|
||||
if (!didParse) {
|
||||
Log.e(
|
||||
TAG,
|
||||
String.format("attemptParseRecord: class %s (opcode 0x%02X) failed to parse at offset %d",
|
||||
record.getShortTypeName(), data[offsetStart], offsetStart));
|
||||
}
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
|
||||
public static DateTime parseSimpleDate(byte[] data, int offset) {
|
||||
DateTime timeStamp = null;
|
||||
int seconds = 0;
|
||||
int minutes = 0;
|
||||
int hour = 0;
|
||||
// int high = data[0] >> 4;
|
||||
int low = data[0 + offset] & 0x1F;
|
||||
// int year_high = data[1] >> 4;
|
||||
int mhigh = (data[0 + offset] & 0xE0) >> 4;
|
||||
int mlow = (data[1 + offset] & 0x80) >> 7;
|
||||
int month = mhigh + mlow;
|
||||
int dayOfMonth = low + 1;
|
||||
// python code says year is data[1] & 0x0F, but that will cause problem in 2016.
|
||||
// Hopefully, the remaining bits are part of the year...
|
||||
int year = data[1 + offset] & 0x3F;
|
||||
/*
|
||||
* Log.w(TAG, String.format("Attempting to create DateTime from: %04d-%02d-%02d %02d:%02d:%02d",
|
||||
* year + 2000, month, dayOfMonth, hour, minutes, seconds));
|
||||
*/
|
||||
try {
|
||||
timeStamp = new DateTime(year + 2000, month, dayOfMonth, hour, minutes, seconds);
|
||||
} catch (org.joda.time.IllegalFieldValueException e) {
|
||||
// Log.e(TAG,"Illegal DateTime field");
|
||||
// e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
|
||||
public static void discoverRecords(byte[] data) {
|
||||
int i = 0;
|
||||
boolean done = false;
|
||||
|
||||
ArrayList<Integer> keyLocations = new ArrayList();
|
||||
while (!done) {
|
||||
RecordTypeEnum en = RecordTypeEnum.fromByte(data[i]);
|
||||
if (en != RecordTypeEnum.Null) {
|
||||
keyLocations.add(i);
|
||||
Log.v(TAG, String.format("Possible record of type %s found at index %d", en, i));
|
||||
}
|
||||
/*
|
||||
* DateTime ts = parseSimpleDate(data,i);
|
||||
* if (ts != null) {
|
||||
* if (ts.year().get() == 2015) {
|
||||
* Log.w(TAG, String.format("Possible simple date at index %d", i));
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
i = i + 1;
|
||||
done = (i >= data.length - 2);
|
||||
}
|
||||
// for each of the discovered key locations, attempt to parse a sequence of records
|
||||
for (RecordTypeEnum en : RecordTypeEnum.values()) {
|
||||
|
||||
}
|
||||
for (int ix = 0; ix < keyLocations.size(); ix++) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public byte[] getRawData() {
|
||||
if (data == null) {
|
||||
return crc;
|
||||
|
@ -91,7 +189,8 @@ public class Page {
|
|||
this.model = model;
|
||||
int pageOffset = 0;
|
||||
|
||||
if ((rawPage == null) || (rawPage.length == 0)) return false;
|
||||
if ((rawPage == null) || (rawPage.length == 0))
|
||||
return false;
|
||||
this.data = Arrays.copyOfRange(rawPage, 0, rawPage.length - 2);
|
||||
this.crc = Arrays.copyOfRange(rawPage, rawPage.length - 2, rawPage.length);
|
||||
byte[] expectedCrc = CRC.calculate16CCITT(this.data);
|
||||
|
@ -99,7 +198,10 @@ public class Page {
|
|||
Log.i(TAG, String.format("Data length: %d", data.length));
|
||||
}
|
||||
if (!Arrays.equals(crc, expectedCrc)) {
|
||||
Log.w(TAG, String.format("CRC does not match expected value. Expected: %s Was: %s", HexDump.toHexString(expectedCrc), HexDump.toHexString(crc)));
|
||||
Log.w(
|
||||
TAG,
|
||||
String.format("CRC does not match expected value. Expected: %s Was: %s",
|
||||
HexDump.toHexString(expectedCrc), HexDump.toHexString(crc)));
|
||||
} else {
|
||||
if (DEBUG_PAGE) {
|
||||
Log.i(TAG, "CRC OK");
|
||||
|
@ -110,7 +212,9 @@ public class Page {
|
|||
while (pageOffset < data.length) {
|
||||
if (data[pageOffset] == 0) {
|
||||
if (record != null) {
|
||||
Log.i(TAG, String.format("End of page or Previous parse fail: prev opcode 0x%02x, curr offset %d, %d bytes remaining", record.getRecordOp(), pageOffset, data.length - pageOffset + 1));
|
||||
Log.i(TAG, String.format(
|
||||
"End of page or Previous parse fail: prev opcode 0x%02x, curr offset %d, %d bytes remaining",
|
||||
record.getRecordOp(), pageOffset, data.length - pageOffset + 1));
|
||||
break;
|
||||
} else {
|
||||
Log.i(TAG, "WTF?");
|
||||
|
@ -166,7 +270,10 @@ public class Page {
|
|||
Log.i(TAG, String.format("Data length: %d", data.length));
|
||||
}
|
||||
if (!Arrays.equals(crc, expectedCrc)) {
|
||||
Log.w(TAG, String.format("CRC does not match expected value. Expected: %s Was: %s", HexDump.toHexString(expectedCrc), HexDump.toHexString(crc)));
|
||||
Log.w(
|
||||
TAG,
|
||||
String.format("CRC does not match expected value. Expected: %s Was: %s",
|
||||
HexDump.toHexString(expectedCrc), HexDump.toHexString(crc)));
|
||||
} else {
|
||||
if (DEBUG_PAGE) {
|
||||
Log.i(TAG, "CRC OK");
|
||||
|
@ -201,7 +308,6 @@ public class Page {
|
|||
pageOffset++;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -229,7 +335,10 @@ public class Page {
|
|||
Log.i(TAG, String.format("Data length: %d", data.length));
|
||||
}
|
||||
if (!Arrays.equals(crc, expectedCrc)) {
|
||||
Log.w(TAG, String.format("CRC does not match expected value. Expected: %s Was: %s", HexDump.toHexString(expectedCrc), HexDump.toHexString(crc)));
|
||||
Log.w(
|
||||
TAG,
|
||||
String.format("CRC does not match expected value. Expected: %s Was: %s",
|
||||
HexDump.toHexString(expectedCrc), HexDump.toHexString(crc)));
|
||||
} else {
|
||||
if (DEBUG_PAGE) {
|
||||
Log.i(TAG, "CRC OK");
|
||||
|
@ -249,12 +358,14 @@ public class Page {
|
|||
record = null;
|
||||
}
|
||||
} else {
|
||||
Log.v(TAG, "Zero opcode encountered -- end of page. " + (rawPage.length - dataIndex) + " bytes remaining.");
|
||||
Log.v(TAG, "Zero opcode encountered -- end of page. " + (rawPage.length - dataIndex)
|
||||
+ " bytes remaining.");
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("Possible parsing problem: ");
|
||||
stringBuilder.append("Previous record: " + previousRecord);
|
||||
stringBuilder.append(" Content of previous record: " + HexDump.toHexStringDisplayable(previousRecord.getRawbytes()));
|
||||
stringBuilder.append(" Content of previous record: "
|
||||
+ HexDump.toHexStringDisplayable(previousRecord.getRawbytes()));
|
||||
|
||||
int remainingData = rawPage.length - dataIndex;
|
||||
byte[] tmpData = new byte[remainingData + 10];
|
||||
|
@ -270,9 +381,12 @@ public class Page {
|
|||
if (record != null) {
|
||||
if (record instanceof IgnoredHistoryEntry) {
|
||||
IgnoredHistoryEntry he = (IgnoredHistoryEntry)record;
|
||||
Log.v(TAG, "parseFrom: found event " + he.getShortTypeName() + " length=" + record.getLength() + " offset=" + record.getFoundAtOffset() + " -- IGNORING");
|
||||
Log.v(TAG, "parseFrom: found event " + he.getShortTypeName() + " length=" + record.getLength()
|
||||
+ " offset=" + record.getFoundAtOffset() + " -- IGNORING");
|
||||
} else {
|
||||
Log.v(TAG, "parseFrom: found event " + record.getClass().getSimpleName() + " length=" + record.getLength() + " offset=" + record.getFoundAtOffset());
|
||||
Log.v(TAG,
|
||||
"parseFrom: found event " + record.getClass().getSimpleName() + " length=" + record.getLength()
|
||||
+ " offset=" + record.getFoundAtOffset());
|
||||
mRecordList.add(record);
|
||||
}
|
||||
|
||||
|
@ -283,19 +397,19 @@ public class Page {
|
|||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("Possible parsing problem: ");
|
||||
stringBuilder.append("Previous record: " + previousRecord);
|
||||
stringBuilder.append(" Content of previous record: " + HexDump.toHexStringDisplayable(previousRecord.getRawbytes()));
|
||||
stringBuilder.append(" Content of previous record: "
|
||||
+ HexDump.toHexStringDisplayable(previousRecord.getRawbytes()));
|
||||
|
||||
int remainingData = data.length - dataIndex;
|
||||
byte[] tmpData = Arrays.copyOfRange(data, dataIndex, 1022);
|
||||
|
||||
|
||||
// new byte[remainingData];
|
||||
// System.arraycopy(data, dataIndex, tmpData, 0, remainingData - 2);
|
||||
|
||||
stringBuilder.append(" Remaining data: " + HexDump.toHexStringDisplayable(tmpData));
|
||||
|
||||
|
||||
Log.e(TAG, String.format("parseFrom: Failed to parse opcode 0x%02x, offset=%d", data[dataIndex], dataIndex));
|
||||
Log.e(TAG,
|
||||
String.format("parseFrom: Failed to parse opcode 0x%02x, offset=%d", data[dataIndex], dataIndex));
|
||||
done = true;
|
||||
}
|
||||
if (dataIndex >= data.length - 2) {
|
||||
|
@ -317,113 +431,18 @@ 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
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
private byte[] crc;
|
||||
private byte[] data;
|
||||
protected PumpModel model;
|
||||
public List<Record> mRecordList;
|
||||
* private byte[] crc;
|
||||
* private byte[] data;
|
||||
* protected PumpModel model;
|
||||
* public List<Record> mRecordList;
|
||||
*/
|
||||
|
||||
|
||||
public Bundle pack() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putByteArray("crc", crc);
|
||||
|
@ -457,5 +476,4 @@ public class Page {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data;
|
||||
|
||||
import android.util.Log;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import android.util.Log;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.utils.CRC;
|
||||
|
@ -15,6 +15,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
|
|||
* Created by geoff on 6/4/16.
|
||||
*/
|
||||
public class RawHistoryPage {
|
||||
|
||||
private static final String TAG = "RawHistoryPage";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RawHistoryPage.class);
|
||||
byte[] data = new byte[0];
|
||||
|
@ -54,9 +55,11 @@ public class RawHistoryPage {
|
|||
int crcStored = ByteUtil.toInt(data[1022], data[1023]);
|
||||
|
||||
if (crcCalculated != crcStored) {
|
||||
LOG.error("Stored CRC ({}) is different than calculated ({}), but ignored for now.", crcStored, crcCalculated);
|
||||
LOG.error("Stored CRC ({}) is different than calculated ({}), but ignored for now.", crcStored,
|
||||
crcCalculated);
|
||||
} else {
|
||||
if (MedtronicUtil.isLowLevelDebug()) LOG.debug("CRC ok.");
|
||||
if (MedtronicUtil.isLowLevelDebug())
|
||||
LOG.debug("CRC ok.");
|
||||
}
|
||||
|
||||
return crcCalculated == crcStored;
|
||||
|
@ -76,5 +79,4 @@ public class RawHistoryPage {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,16 +8,20 @@ import org.joda.time.LocalDateTime;
|
|||
* Exists to easily merge 2 byte timestamps and 5 byte timestamps.
|
||||
*/
|
||||
public class PumpTimeStamp {
|
||||
|
||||
private LocalDateTime localDateTime;
|
||||
|
||||
|
||||
public PumpTimeStamp() {
|
||||
localDateTime = new LocalDateTime(1973, 1, 1, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
public PumpTimeStamp(String stringRepresentation) {
|
||||
localDateTime.parse(stringRepresentation);
|
||||
}
|
||||
|
||||
|
||||
public PumpTimeStamp(LocalDate localDate) {
|
||||
try {
|
||||
localDateTime = new LocalDateTime(localDate);
|
||||
|
@ -27,14 +31,17 @@ public class PumpTimeStamp {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public PumpTimeStamp(LocalDateTime localDateTime) {
|
||||
this.localDateTime = localDateTime;
|
||||
}
|
||||
|
||||
|
||||
public LocalDateTime getLocalDateTime() {
|
||||
return localDateTime;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getLocalDateTime().toString();
|
||||
|
|
|
@ -11,8 +11,19 @@ abstract public class Record {
|
|||
// protected int length;
|
||||
protected int foundAtOffset;
|
||||
protected byte[] rawbytes = new byte[0];
|
||||
|
||||
|
||||
// protected String recordTypeName = this.getClass().getSimpleName();
|
||||
|
||||
public Record() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected static int asUINT8(byte b) {
|
||||
return (b < 0) ? b + 256 : b;
|
||||
}
|
||||
|
||||
|
||||
public String getRecordTypeName() {
|
||||
return this.getClass().getSimpleName();
|
||||
|
@ -34,11 +45,6 @@ abstract public class Record {
|
|||
}
|
||||
|
||||
|
||||
public Record() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean parseWithOffset(byte[] data, MedtronicDeviceType model, int foundAtOffset) {
|
||||
// keep track of where the record was found for later analysis
|
||||
this.foundAtOffset = foundAtOffset;
|
||||
|
@ -83,11 +89,6 @@ abstract public class Record {
|
|||
}
|
||||
|
||||
|
||||
protected static int asUINT8(byte b) {
|
||||
return (b < 0) ? b + 256 : b;
|
||||
}
|
||||
|
||||
|
||||
public Bundle dictionaryRepresentation() {
|
||||
Bundle rval = new Bundle();
|
||||
writeToBundle(rval);
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record.AlarmClockReminderPumpEvent;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record.AlarmSensorPumpEvent;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record.BGReceivedPumpEvent;
|
||||
|
@ -86,7 +86,6 @@ public enum RecordTypeEnum {
|
|||
ChangeTime((byte)0x17, ChangeTimePumpEvent.class), // OK
|
||||
NewTimeSet((byte)0x18, NewTimeSet.class), // OK
|
||||
|
||||
|
||||
JournalEntryPumpLowBattery((byte)0x19, JournalEntryPumpLowBatteryPumpEvent.class), //
|
||||
RECORD_TYPE_BATTERY((byte)0x1A, BatteryPumpEvent.class), //
|
||||
SetAutoOff(0x1b, 7), //
|
||||
|
@ -135,7 +134,6 @@ public enum RecordTypeEnum {
|
|||
MM512_Event_0x4d(0x4d, 7), //
|
||||
MM512_Event_0x4e(0x4e, 7), //
|
||||
|
||||
|
||||
// case changeBolusWizardSetup = 0x4f, 7), //
|
||||
|
||||
changeSensorSetup2((byte)0x50, ChangeSensorSetup2PumpEvent.class), //
|
||||
|
@ -155,7 +153,6 @@ public enum RecordTypeEnum {
|
|||
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), //
|
||||
|
@ -178,9 +175,9 @@ public enum RecordTypeEnum {
|
|||
|
||||
// Irelevant records (events that don't concern us for AAPS usage)
|
||||
|
||||
|
||||
;
|
||||
|
||||
private static final String TAG = "RecordTypeEnum";
|
||||
private static Map<Byte, RecordTypeEnum> mapByOpCode = null;
|
||||
private byte opcode;
|
||||
private Class mRecordClass;
|
||||
|
@ -188,16 +185,6 @@ public enum RecordTypeEnum {
|
|||
private String shortTypeName;
|
||||
|
||||
|
||||
public byte opcode() {
|
||||
return opcode;
|
||||
}
|
||||
|
||||
|
||||
public Class recordClass() {
|
||||
return mRecordClass;
|
||||
}
|
||||
|
||||
|
||||
RecordTypeEnum(int b, Class c) {
|
||||
opcode = (byte)b;
|
||||
mRecordClass = c;
|
||||
|
@ -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) {
|
||||
|
@ -261,13 +262,6 @@ public enum RecordTypeEnum {
|
|||
}
|
||||
|
||||
|
||||
public static <T extends Record> T getRecordClassInstance(Bundle bundle, MedtronicDeviceType model) {
|
||||
byte opcode = bundle.getByte("_opcode");
|
||||
RecordTypeEnum e = RecordTypeEnum.fromByte(opcode);
|
||||
return e.getRecordClassInstance(model);
|
||||
}
|
||||
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
|
|
@ -1,30 +1,33 @@
|
|||
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
|
||||
|
||||
/**
|
||||
* Created by geoff on 6/4/16.
|
||||
*/
|
||||
public class TimeFormat {
|
||||
|
||||
public static final String standardFormatString = "YYYY-MM-dd HH:mm:ss";
|
||||
private static final boolean DEBUG_TIMEFORMAT = false;
|
||||
private static final String TAG = "TimeFormat";
|
||||
|
||||
|
||||
public TimeFormat() {
|
||||
}
|
||||
|
||||
public static final String standardFormatString = "YYYY-MM-dd HH:mm:ss";
|
||||
|
||||
public static DateTimeFormatter standardFormatter() {
|
||||
return DateTimeFormat.forPattern(standardFormatString);
|
||||
}
|
||||
|
||||
|
||||
public static LocalDate parse2ByteDate(byte[] data, int offset) throws org.joda.time.IllegalFieldValueException {
|
||||
int low = ByteUtil.asUINT8(data[0 + offset]) & 0x1F;
|
||||
int mhigh = (ByteUtil.asUINT8(data[0 + offset]) & 0xE0) >> 4;
|
||||
|
@ -33,29 +36,29 @@ public class TimeFormat {
|
|||
int dayOfMonth = low + 1;
|
||||
int year = 2000 + (ByteUtil.asUINT8(data[offset + 1]) & 0x7F);
|
||||
/*
|
||||
Log.w(TAG, String.format("Attempting to create DateTime from: %04d-%02d-%02d %02d:%02d:%02d",
|
||||
year + 2000, month, dayOfMonth, hour, minutes, seconds));
|
||||
* Log.w(TAG, String.format("Attempting to create DateTime from: %04d-%02d-%02d %02d:%02d:%02d",
|
||||
* year + 2000, month, dayOfMonth, hour, minutes, seconds));
|
||||
*/
|
||||
// try {
|
||||
LocalDate rval = new LocalDate(year, month, dayOfMonth);
|
||||
return rval;
|
||||
/*
|
||||
} catch (org.joda.time.IllegalFieldValueException e) {
|
||||
Log.e(TAG,"Illegal DateTime field");
|
||||
//e.printStackTrace();
|
||||
return new LocalDate(1973,3,3);
|
||||
}
|
||||
* } catch (org.joda.time.IllegalFieldValueException e) {
|
||||
* Log.e(TAG,"Illegal DateTime field");
|
||||
* //e.printStackTrace();
|
||||
* return new LocalDate(1973,3,3);
|
||||
* }
|
||||
*/
|
||||
}
|
||||
|
||||
// for relation to old code, replace offset with headerSize
|
||||
|
||||
// for relation to old code, replace offset with headerSize
|
||||
|
||||
public static LocalDateTime parse5ByteDate(byte[] data, int offset) throws org.joda.time.IllegalFieldValueException {
|
||||
// offset = headerSize;
|
||||
if (DEBUG_TIMEFORMAT) {
|
||||
Log.w(TAG, String.format("bytes to parse: 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X",
|
||||
data[offset], data[offset + 1], data[offset + 2], data[offset + 3], data[offset + 4]));
|
||||
Log.w(TAG, String.format("bytes to parse: 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X", data[offset],
|
||||
data[offset + 1], data[offset + 2], data[offset + 3], data[offset + 4]));
|
||||
}
|
||||
int seconds = data[offset] & 0x3F;
|
||||
int minutes = data[offset + 1] & 0x3F;
|
||||
|
@ -63,22 +66,22 @@ public class TimeFormat {
|
|||
int dayOfMonth = data[offset + 3] & 0x1F;
|
||||
// Yes, the month bits are stored in the high bits above seconds and minutes!!
|
||||
int month = ((data[offset] >> 4) & 0x0c) + ((data[offset + 1] >> 6) & 0x03);
|
||||
int year = data[offset + 4] & 0x3F; // Assuming this is correct, need to verify. Otherwise this will be a problem in 2016.
|
||||
int year = data[offset + 4] & 0x3F; // Assuming this is correct, need to verify. Otherwise this will be a
|
||||
// problem in 2016.
|
||||
/*
|
||||
Log.w(TAG,String.format("Attempting to create DateTime from: %04d-%02d-%02d %02d:%02d:%02d",
|
||||
year+2000,month,dayOfMonth,hour,minutes,seconds));
|
||||
* Log.w(TAG,String.format("Attempting to create DateTime from: %04d-%02d-%02d %02d:%02d:%02d",
|
||||
* year+2000,month,dayOfMonth,hour,minutes,seconds));
|
||||
*/
|
||||
// try {
|
||||
LocalDateTime timeStamp = new LocalDateTime(year + 2000, month, dayOfMonth, hour, minutes, seconds);
|
||||
return timeStamp;
|
||||
/*
|
||||
} catch (org.joda.time.IllegalFieldValueException e) {
|
||||
Log.e(TAG, "Illegal DateTime field");
|
||||
//e.printStackTrace();
|
||||
return new LocalDateTime(1973,2,2,2,2);
|
||||
}
|
||||
* } catch (org.joda.time.IllegalFieldValueException e) {
|
||||
* Log.e(TAG, "Illegal DateTime field");
|
||||
* //e.printStackTrace();
|
||||
* return new LocalDateTime(1973,2,2,2,2);
|
||||
* }
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,8 +11,15 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType
|
|||
* Many of the subclasses of this class only override the opcode.
|
||||
*/
|
||||
abstract public class TimeStampedRecord extends Record {
|
||||
|
||||
// private final static String TAG = "TimeStampedRecord";
|
||||
private final static boolean DEBUG_TIMESTAMPEDRECORD = false;
|
||||
protected PumpTimeStamp timestamp;
|
||||
|
||||
|
||||
public TimeStampedRecord() {
|
||||
timestamp = new PumpTimeStamp();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -26,14 +33,6 @@ abstract public class TimeStampedRecord extends Record {
|
|||
}
|
||||
|
||||
|
||||
protected PumpTimeStamp timestamp;
|
||||
|
||||
|
||||
public TimeStampedRecord() {
|
||||
timestamp = new PumpTimeStamp();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PumpTimeStamp getTimestamp() {
|
||||
return timestamp;
|
||||
|
|
|
@ -10,11 +10,13 @@ public class AlarmClockReminderPumpEvent extends TimeStampedRecord {
|
|||
public AlarmClockReminderPumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Alarm Reminder";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -1,25 +1,28 @@
|
|||
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record;
|
||||
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
|
||||
|
||||
/**
|
||||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class AlarmSensorPumpEvent extends TimeStampedRecord {
|
||||
|
||||
public AlarmSensorPumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 8;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Alarm Sensor";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil;
|
||||
|
@ -8,6 +7,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
|
||||
|
||||
public class BGReceivedPumpEvent extends TimeStampedRecord {
|
||||
|
||||
private int amount = 0;
|
||||
private byte[] meter = new byte[3];
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
|
||||
|
||||
public class BasalProfileStart extends TimeStampedRecord {
|
||||
|
||||
private static final String TAG = "BasalProfileStart";
|
||||
private int offset = 0;
|
||||
private double rate = 0.0;
|
||||
|
|
|
@ -3,14 +3,17 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.recor
|
|||
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
|
||||
|
||||
public class BatteryPumpEvent extends TimeStampedRecord {
|
||||
|
||||
public BatteryPumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Battery";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.PumpTimeStamp;
|
||||
|
@ -9,6 +8,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
|
||||
|
||||
public class BolusNormalPumpEvent extends TimeStampedRecord {
|
||||
|
||||
private final static String TAG = "BolusNormalPumpEvent";
|
||||
|
||||
private double programmedAmount = 0.0;
|
||||
|
|
|
@ -6,6 +6,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType;
|
||||
|
||||
public class CalBgForPhPumpEvent extends TimeStampedRecord {
|
||||
|
||||
private int amount = 0;
|
||||
|
||||
|
||||
|
|
|
@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeAlarmClockEnablePumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeAlarmClockEnablePumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Alarm Clock Enable";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -3,18 +3,20 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.recor
|
|||
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
|
||||
|
||||
public class ChangeAlarmNotifyModePumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeAlarmNotifyModePumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Alarm Notify Mode";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeAudioBolusPumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeAudioBolusPumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Audio Bolus";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return true;
|
||||
|
|
|
@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeBGReminderEnablePumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeBGReminderEnablePumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch BG Rmndr Enable";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -6,19 +6,23 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeBasalProfilePatternPumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeBasalProfilePatternPumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 152;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Basal Prof Pat";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return true;
|
||||
|
|
|
@ -3,19 +3,23 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.recor
|
|||
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
|
||||
|
||||
public class ChangeBasalProfilePumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeBasalProfilePumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 152;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Basal Profile";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return true;
|
||||
|
|
|
@ -6,19 +6,23 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeBolusReminderEnablePumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeBolusReminderEnablePumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Bolus Rmndr Enable";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -6,19 +6,23 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeBolusReminderTimePumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeBolusReminderTimePumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Bolus Rmndr Time";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeBolusScrollStepSizePumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeBolusScrollStepSizePumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Bolus Scroll SS";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record;
|
||||
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
|
||||
|
||||
public class ChangeBolusWizardSetupPumpEvent extends TimeStampedRecord {
|
||||
|
@ -8,16 +7,19 @@ public class ChangeBolusWizardSetupPumpEvent extends TimeStampedRecord {
|
|||
public ChangeBolusWizardSetupPumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 144;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Bolus Wizard Setup";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeCaptureEventEnablePumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeCaptureEventEnablePumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Capture Event Ena";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeCarbUnitsPumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeCarbUnitsPumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Carb Units";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeChildBlockEnablePumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeChildBlockEnablePumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Child Block Ena";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeMaxBolusPumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeMaxBolusPumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Max Bolux";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record;
|
||||
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
|
||||
|
||||
public class ChangeOtherDeviceIDPumpEvent extends TimeStampedRecord {
|
||||
|
@ -8,16 +7,19 @@ public class ChangeOtherDeviceIDPumpEvent extends TimeStampedRecord {
|
|||
public ChangeOtherDeviceIDPumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 37;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Other Dev ID";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeReservoirWarningTimePumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeReservoirWarningTimePumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Res Warn Time";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -6,19 +6,23 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeSensorRateOfChangeAlertSetupPumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeSensorRateOfChangeAlertSetupPumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 12;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Sensor ROC Alert";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -6,19 +6,23 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeSensorSetup2PumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeSensorSetup2PumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 37;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Sensor Setup2";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -9,6 +9,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicDeviceType
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeTempBasalTypePumpEvent extends TimeStampedRecord {
|
||||
|
||||
private boolean isPercent = false; // either absolute or percent
|
||||
|
||||
|
||||
|
|
|
@ -3,14 +3,17 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.recor
|
|||
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
|
||||
|
||||
public class ChangeTimeFormatPumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeTimeFormatPumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Time Format";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
|
@ -1,23 +1,26 @@
|
|||
package info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.record;
|
||||
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeStampedRecord;
|
||||
|
||||
public class ChangeTimePumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeTimePumpEvent() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 14;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Change Time";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return true;
|
||||
|
|
|
@ -6,14 +6,17 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.data.history.TimeSt
|
|||
* Created by geoff on 6/5/16.
|
||||
*/
|
||||
public class ChangeVariableBolusPumpEvent extends TimeStampedRecord {
|
||||
|
||||
public ChangeVariableBolusPumpEvent() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortTypeName() {
|
||||
return "Ch Var. Bolus";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAAPSRelevant() {
|
||||
return false;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue