This commit is contained in:
Milos Kozak 2020-04-25 09:23:19 +02:00
parent 8db0dbd78d
commit e8f69fc1c0
28 changed files with 236 additions and 195 deletions

View file

@ -32,6 +32,8 @@ import info.nightscout.androidaps.plugins.insulin.InsulinFragment
import info.nightscout.androidaps.plugins.profile.local.LocalProfileFragment
import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment
import info.nightscout.androidaps.plugins.pump.combo.ComboFragment
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusGeneralFragment
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusHistoryFragment
import info.nightscout.androidaps.plugins.pump.danaR.DanaRFragment
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightFragment
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicFragment
@ -113,4 +115,7 @@ abstract class FragmentsModule {
@ContributesAndroidInjector abstract fun contributesWizardInfoDialog(): WizardInfoDialog
@ContributesAndroidInjector abstract fun contributesPasswordCheck(): PasswordCheck
@ContributesAndroidInjector abstract fun contributesRileyLinkStatusGeneral(): RileyLinkStatusGeneralFragment
@ContributesAndroidInjector abstract fun contributesRileyLinkStatusHistoryFragment(): RileyLinkStatusHistoryFragment
}

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.dependencyInjection
import dagger.Module
import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkBluetoothStateReceiver
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkBroadcastReceiver
import info.nightscout.androidaps.receivers.*
@Module
@ -17,4 +18,6 @@ abstract class ReceiversModule {
@ContributesAndroidInjector abstract fun contributesRileyLinkBluetoothStateReceiver(): RileyLinkBluetoothStateReceiver
@ContributesAndroidInjector abstract fun contributesSmsReceiver(): SmsReceiver
@ContributesAndroidInjector abstract fun contributesTimeDateOrTZChangeReceiver(): TimeDateOrTZChangeReceiver
@ContributesAndroidInjector abstract fun contributesRileyLinkBroadcastReceiver(): RileyLinkBroadcastReceiver
}

View file

@ -60,6 +60,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
@Inject SP sp;
@Inject RxBusWrapper rxBus;
@Inject ResourceHelper resourceHelper;
@Inject RileyLinkUtil rileyLinkUtil;
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 30241; // arbitrary.
private static final int REQUEST_ENABLE_BT = 30242; // arbitrary
@ -108,7 +109,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
sp.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress);
RileyLinkUtil.getRileyLinkSelectPreference().setSummary(bleAddress);
rileyLinkUtil.getRileyLinkSelectPreference().setSummary(bleAddress);
MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
pumpStatus.verifyConfiguration(); // force reloading of address
@ -189,7 +190,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
}
// disable currently selected RL, so that we can discover it
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnect);
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnect);
}

View file

@ -55,8 +55,8 @@ public abstract class RileyLinkCommunicationManager {
public RileyLinkCommunicationManager(Context context, RFSpy rfspy) {
this.context = context;
this.rfspy = rfspy;
this.rileyLinkServiceData = RileyLinkUtil.getRileyLinkServiceData();
RileyLinkUtil.setRileyLinkCommunicationManager(this);
this.rileyLinkServiceData = RileyLinkUtil.getInstance().getRileyLinkServiceData();
RileyLinkUtil.getInstance().setRileyLinkCommunicationManager(this);
configurePumpSpecificSettings();
}
@ -178,7 +178,7 @@ public abstract class RileyLinkCommunicationManager {
public double tuneForDevice() {
return scanForDevice(RileyLinkUtil.getRileyLinkTargetFrequency().getScanFrequencies());
return scanForDevice(RileyLinkUtil.getInstance().getRileyLinkTargetFrequency().getScanFrequencies());
}
@ -192,7 +192,7 @@ public abstract class RileyLinkCommunicationManager {
*/
public boolean isValidFrequency(double frequency) {
double[] scanFrequencies = RileyLinkUtil.getRileyLinkTargetFrequency().getScanFrequencies();
double[] scanFrequencies = RileyLinkUtil.getInstance().getRileyLinkTargetFrequency().getScanFrequencies();
if (scanFrequencies.length == 1) {
return RileyLinkUtil.isSame(scanFrequencies[0], frequency);

View file

@ -5,8 +5,7 @@ import android.content.Intent;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jetbrains.annotations.NotNull;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@ -15,9 +14,13 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.bus.RxBus;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.encoding.Encoding4b6b;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.encoding.Encoding4b6bGeoff;
@ -42,143 +45,160 @@ import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicDe
* Created by andy on 17/05/2018.
*/
@Singleton
public class RileyLinkUtil {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMP);
protected static List<RLHistoryItem> historyRileyLink = new ArrayList<>();
protected static RileyLinkCommunicationManager rileyLinkCommunicationManager;
protected List<RLHistoryItem> historyRileyLink = new ArrayList<>();
protected RileyLinkCommunicationManager rileyLinkCommunicationManager;
static ServiceTask currentTask;
private static Context context;
private static RileyLinkBLE rileyLinkBLE;
private static RileyLinkServiceData rileyLinkServiceData;
private static RileyLinkService rileyLinkService;
private static RileyLinkTargetFrequency rileyLinkTargetFrequency;
private RileyLinkBLE rileyLinkBLE;
private RileyLinkServiceData rileyLinkServiceData;
private RileyLinkService rileyLinkService;
private RileyLinkTargetFrequency rileyLinkTargetFrequency;
private static RileyLinkTargetDevice targetDevice;
private static RileyLinkEncodingType encoding;
private static RileyLinkSelectPreference rileyLinkSelectPreference;
private static Encoding4b6b encoding4b6b;
private static RileyLinkFirmwareVersion firmwareVersion;
private RileyLinkTargetDevice targetDevice;
private RileyLinkEncodingType encoding;
private RileyLinkSelectPreference rileyLinkSelectPreference;
private Encoding4b6b encoding4b6b;
private RileyLinkFirmwareVersion firmwareVersion;
public static void setContext(Context contextIn) {
RileyLinkUtil.context = contextIn;
@NotNull private final Context context;
@NotNull private final AAPSLogger aapsLogger;
@Nonnull private final RxBusWrapper rxBus;
@Inject
public RileyLinkUtil(
Context context,
AAPSLogger aapsLogger,
RxBusWrapper rxBus
) {
this.context = context;
this.aapsLogger = aapsLogger;
this.rxBus = rxBus;
instance = this;
}
private static RileyLinkUtil instance;
public static RileyLinkEncodingType getEncoding() {
// TODO: replace by injection
@Deprecated
public static RileyLinkUtil getInstance() {
if (instance == null) throw new IllegalStateException("RileyLinkUtil not initialized");
return instance;
}
public RileyLinkEncodingType getEncoding() {
return encoding;
}
public static void setEncoding(RileyLinkEncodingType encoding) {
RileyLinkUtil.encoding = encoding;
public void setEncoding(RileyLinkEncodingType encoding) {
this.encoding = encoding;
if (encoding == RileyLinkEncodingType.FourByteSixByteLocal) {
RileyLinkUtil.encoding4b6b = new Encoding4b6bGeoff();
this.encoding4b6b = new Encoding4b6bGeoff();
}
}
public static void sendBroadcastMessage(String message) {
if (context != null) {
Intent intent = new Intent(message);
LocalBroadcastManager.getInstance(RileyLinkUtil.context).sendBroadcast(intent);
}
public void sendBroadcastMessage(String message) {
Intent intent = new Intent(message);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
public static void setServiceState(RileyLinkServiceState newState) {
public void setServiceState(RileyLinkServiceState newState) {
setServiceState(newState, null);
}
public static RileyLinkError getError() {
if (RileyLinkUtil.rileyLinkServiceData != null)
return RileyLinkUtil.rileyLinkServiceData.errorCode;
public RileyLinkError getError() {
if (rileyLinkServiceData != null)
return rileyLinkServiceData.errorCode;
else
return null;
}
public static RileyLinkServiceState getServiceState() {
public RileyLinkServiceState getServiceState() {
return workWithServiceState(null, null, false);
}
public static void setServiceState(RileyLinkServiceState newState, RileyLinkError errorCode) {
public void setServiceState(RileyLinkServiceState newState, RileyLinkError errorCode) {
workWithServiceState(newState, errorCode, true);
}
private static synchronized RileyLinkServiceState workWithServiceState(RileyLinkServiceState newState,
RileyLinkError errorCode, boolean set) {
private synchronized RileyLinkServiceState workWithServiceState(RileyLinkServiceState newState,
RileyLinkError errorCode, boolean set) {
if (set) {
RileyLinkUtil.rileyLinkServiceData.serviceState = newState;
RileyLinkUtil.rileyLinkServiceData.errorCode = errorCode;
rileyLinkServiceData.serviceState = newState;
rileyLinkServiceData.errorCode = errorCode;
if (L.isEnabled(L.PUMP))
LOG.info("RileyLink State Changed: {} {}", newState, errorCode == null ? "" : " - Error State: "
+ errorCode.name());
aapsLogger.info(LTag.PUMP, "RileyLink State Changed: {} {}", newState, errorCode == null ? "" : " - Error State: "
+ errorCode.name());
RileyLinkUtil.historyRileyLink.add(new RLHistoryItem(RileyLinkUtil.rileyLinkServiceData.serviceState,
RileyLinkUtil.rileyLinkServiceData.errorCode, targetDevice));
RxBus.Companion.getINSTANCE().send(new EventMedtronicDeviceStatusChange(newState, errorCode));
historyRileyLink.add(new RLHistoryItem(rileyLinkServiceData.serviceState,
rileyLinkServiceData.errorCode, targetDevice));
rxBus.send(new EventMedtronicDeviceStatusChange(newState, errorCode));
return null;
} else {
return (RileyLinkUtil.rileyLinkServiceData == null || RileyLinkUtil.rileyLinkServiceData.serviceState == null) ? //
return (rileyLinkServiceData == null || rileyLinkServiceData.serviceState == null) ? //
RileyLinkServiceState.NotStarted
: RileyLinkUtil.rileyLinkServiceData.serviceState;
: rileyLinkServiceData.serviceState;
}
}
public static RileyLinkBLE getRileyLinkBLE() {
return RileyLinkUtil.rileyLinkBLE;
public RileyLinkBLE getRileyLinkBLE() {
return rileyLinkBLE;
}
public static void setRileyLinkBLE(RileyLinkBLE rileyLinkBLEIn) {
RileyLinkUtil.rileyLinkBLE = rileyLinkBLEIn;
public void setRileyLinkBLE(RileyLinkBLE rileyLinkBLEIn) {
rileyLinkBLE = rileyLinkBLEIn;
}
public static RileyLinkServiceData getRileyLinkServiceData() {
return RileyLinkUtil.rileyLinkServiceData;
public RileyLinkServiceData getRileyLinkServiceData() {
return rileyLinkServiceData;
}
public static void setRileyLinkServiceData(RileyLinkServiceData rileyLinkServiceData) {
RileyLinkUtil.rileyLinkServiceData = rileyLinkServiceData;
public void setRileyLinkServiceData(RileyLinkServiceData rileyLinkServiceData) {
this.rileyLinkServiceData = rileyLinkServiceData;
}
public static boolean hasPumpBeenTunned() {
return RileyLinkUtil.rileyLinkServiceData.tuneUpDone;
public boolean hasPumpBeenTunned() {
return rileyLinkServiceData.tuneUpDone;
}
public static RileyLinkService getRileyLinkService() {
return RileyLinkUtil.rileyLinkService;
public RileyLinkService getRileyLinkService() {
return rileyLinkService;
}
public static void setRileyLinkService(RileyLinkService rileyLinkService) {
RileyLinkUtil.rileyLinkService = rileyLinkService;
public void setRileyLinkService(RileyLinkService rileyLinkService) {
this.rileyLinkService = rileyLinkService;
}
public static RileyLinkCommunicationManager getRileyLinkCommunicationManager() {
return RileyLinkUtil.rileyLinkCommunicationManager;
public RileyLinkCommunicationManager getRileyLinkCommunicationManager() {
return rileyLinkCommunicationManager;
}
public static void setRileyLinkCommunicationManager(RileyLinkCommunicationManager rileyLinkCommunicationManager) {
RileyLinkUtil.rileyLinkCommunicationManager = rileyLinkCommunicationManager;
void setRileyLinkCommunicationManager(RileyLinkCommunicationManager rileyLinkCommunicationManager) {
this.rileyLinkCommunicationManager = rileyLinkCommunicationManager;
}
@ -222,13 +242,13 @@ public class RileyLinkUtil {
}
public static RileyLinkTargetFrequency getRileyLinkTargetFrequency() {
return RileyLinkUtil.rileyLinkTargetFrequency;
public RileyLinkTargetFrequency getRileyLinkTargetFrequency() {
return rileyLinkTargetFrequency;
}
public static void setRileyLinkTargetFrequency(RileyLinkTargetFrequency rileyLinkTargetFrequency) {
RileyLinkUtil.rileyLinkTargetFrequency = rileyLinkTargetFrequency;
public void setRileyLinkTargetFrequency(RileyLinkTargetFrequency rileyLinkTargetFrequency) {
this.rileyLinkTargetFrequency = rileyLinkTargetFrequency;
}
@ -286,44 +306,42 @@ public class RileyLinkUtil {
}
public static List<RLHistoryItem> getRileyLinkHistory() {
public List<RLHistoryItem> getRileyLinkHistory() {
return historyRileyLink;
}
public static RileyLinkTargetDevice getTargetDevice() {
public RileyLinkTargetDevice getTargetDevice() {
return targetDevice;
}
public static void setTargetDevice(RileyLinkTargetDevice targetDevice) {
RileyLinkUtil.targetDevice = targetDevice;
public void setTargetDevice(RileyLinkTargetDevice targetDevice) {
this.targetDevice = targetDevice;
}
public static void setRileyLinkSelectPreference(RileyLinkSelectPreference rileyLinkSelectPreference) {
RileyLinkUtil.rileyLinkSelectPreference = rileyLinkSelectPreference;
public void setRileyLinkSelectPreference(RileyLinkSelectPreference rileyLinkSelectPreference) {
this.rileyLinkSelectPreference = rileyLinkSelectPreference;
}
public static RileyLinkSelectPreference getRileyLinkSelectPreference() {
public RileyLinkSelectPreference getRileyLinkSelectPreference() {
return rileyLinkSelectPreference;
}
public static Encoding4b6b getEncoding4b6b() {
return RileyLinkUtil.encoding4b6b;
public Encoding4b6b getEncoding4b6b() {
return encoding4b6b;
}
public static void setFirmwareVersion(RileyLinkFirmwareVersion firmwareVersion) {
RileyLinkUtil.firmwareVersion = firmwareVersion;
public void setFirmwareVersion(RileyLinkFirmwareVersion firmwareVersion) {
this.firmwareVersion = firmwareVersion;
}
public static RileyLinkFirmwareVersion getFirmwareVersion() {
public RileyLinkFirmwareVersion getFirmwareVersion() {
return firmwareVersion;
}
}

View file

@ -90,7 +90,7 @@ public class RFSpy {
public void initializeRileyLink() {
bleVersion = getVersion();
firmwareVersion = getFirmwareVersion();
RileyLinkUtil.setFirmwareVersion(firmwareVersion);
RileyLinkUtil.getInstance().setFirmwareVersion(firmwareVersion);
}
@ -289,7 +289,7 @@ public class RFSpy {
this.currentFrequencyMHz = freqMHz;
configureRadioForRegion(RileyLinkUtil.getRileyLinkTargetFrequency());
configureRadioForRegion(RileyLinkUtil.getInstance().getRileyLinkTargetFrequency());
}
@ -396,7 +396,7 @@ public class RFSpy {
if (resp.isOK()) {
reader.setRileyLinkEncodingType(encoding);
RileyLinkUtil.setEncoding(encoding);
RileyLinkUtil.getInstance().setEncoding(encoding);
}
return resp;

View file

@ -142,7 +142,7 @@ public class RileyLinkBLE {
if (newState == BluetoothProfile.STATE_CONNECTED) {
if (status == BluetoothGatt.GATT_SUCCESS) {
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.BluetoothConnected);
RileyLinkUtil.getInstance().sendBroadcastMessage(RileyLinkConst.Intents.BluetoothConnected);
} else {
if (isLogEnabled())
LOG.debug("BT State connected, GATT status {} ({})", status, getGattStatusMessage(status));
@ -153,7 +153,7 @@ public class RileyLinkBLE {
// LOG.debug("We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" :
// "Disconnecting");
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnected);
RileyLinkUtil.getInstance().sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnected);
if (manualDisconnect)
close();
LOG.warn("RileyLink Disconnected.");
@ -240,19 +240,19 @@ public class RileyLinkBLE {
if (rileyLinkFound) {
mIsConnected = true;
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkReady);
RileyLinkUtil.getInstance().sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkReady);
// RileyLinkUtil.sendNotification(new
// ServiceNotification(RileyLinkConst.Intents.RileyLinkReady), null);
} else {
mIsConnected = false;
RileyLinkUtil.setServiceState(RileyLinkServiceState.RileyLinkError,
RileyLinkUtil.getInstance().setServiceState(RileyLinkServiceState.RileyLinkError,
RileyLinkError.DeviceIsNotRileyLink);
}
} else {
if (isLogEnabled())
LOG.debug("onServicesDiscovered " + getGattStatusMessage(status));
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkGattFailed);
RileyLinkUtil.getInstance().sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkGattFailed);
}
}
};

View file

@ -57,7 +57,7 @@ public class SendAndListen extends RileyLinkCommand {
// If firmware version is not set (error reading version from device, shouldn't happen),
// we will default to version 2
boolean isPacketV2 = RileyLinkUtil.getFirmwareVersion() != null ? RileyLinkUtil.getFirmwareVersion()
boolean isPacketV2 = RileyLinkUtil.getInstance().getFirmwareVersion() != null ? RileyLinkUtil.getInstance().getFirmwareVersion()
.isSameVersion(RileyLinkFirmwareVersion.Version2AndHigher) : true;
ArrayList<Byte> bytes = new ArrayList<Byte>();

View file

@ -17,7 +17,7 @@ public class SetPreamble extends RileyLinkCommand {
super();
// this command was not supported before 2.0
if (!RileyLinkUtil.getFirmwareVersion().isSameVersion(RileyLinkFirmwareVersion.Version2AndHigher)) {
if (!RileyLinkUtil.getInstance().getFirmwareVersion().isSameVersion(RileyLinkFirmwareVersion.Version2AndHigher)) {
throw new NotImplementedException("Old firmware does not support SetPreamble command");
}

View file

@ -33,7 +33,7 @@ public class RadioPacket {
public byte[] getEncoded() {
switch (RileyLinkUtil.getEncoding()) {
switch (RileyLinkUtil.getInstance().getEncoding()) {
case Manchester: { // We have this encoding in RL firmware
return pkt;
}
@ -41,7 +41,7 @@ public class RadioPacket {
case FourByteSixByteLocal: {
byte[] withCRC = getWithCRC();
byte[] encoded = RileyLinkUtil.getEncoding4b6b().encode4b6b(withCRC);
byte[] encoded = RileyLinkUtil.getInstance().getEncoding4b6b().encode4b6b(withCRC);
return ByteUtil.concat(encoded, (byte)0);
}
@ -50,7 +50,7 @@ public class RadioPacket {
}
default:
throw new NotImplementedException(("Encoding not supported: " + RileyLinkUtil.getEncoding().toString()));
throw new NotImplementedException(("Encoding not supported: " + RileyLinkUtil.getInstance().getEncoding().toString()));
}
}

View file

@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data;
import org.apache.commons.lang3.NotImplementedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
@ -75,8 +74,8 @@ public class RadioResponse {
}
byte[] encodedPayload;
if (RileyLinkFirmwareVersion.isSameVersion(RileyLinkUtil.getRileyLinkServiceData().versionCC110,
RileyLinkFirmwareVersion.Version2)) {
if (RileyLinkFirmwareVersion.isSameVersion(RileyLinkUtil.getInstance().getRileyLinkServiceData().versionCC110,
RileyLinkFirmwareVersion.Version2)) {
encodedPayload = ByteUtil.substring(rxData, 3, rxData.length - 3);
rssi = rxData[1];
responseNumber = rxData[2];
@ -92,23 +91,23 @@ public class RadioResponse {
// well, for non-radio commands we shouldn't even reach this point
// but getVersion is kind of exception
if (command != null && //
command.getCommandType() != RileyLinkCommandType.SendAndListen) {
command.getCommandType() != RileyLinkCommandType.SendAndListen) {
decodedOK = true;
decodedPayload = encodedPayload;
return;
}
switch (RileyLinkUtil.getEncoding()) {
switch (RileyLinkUtil.getInstance().getEncoding()) {
case Manchester:
case FourByteSixByteRileyLink: {
decodedOK = true;
decodedPayload = encodedPayload;
}
break;
break;
case FourByteSixByteLocal: {
byte[] decodeThis = RileyLinkUtil.getEncoding4b6b().decode4b6b(encodedPayload);
byte[] decodeThis = RileyLinkUtil.getInstance().getEncoding4b6b().decode4b6b(encodedPayload);
if (decodeThis != null && decodeThis.length > 2) {
decodedOK = true;
@ -118,17 +117,17 @@ public class RadioResponse {
byte calculatedCRC = CRC.crc8(decodedPayload);
if (receivedCRC != calculatedCRC) {
LOG.error(String.format("RadioResponse: CRC mismatch, calculated 0x%02x, received 0x%02x",
calculatedCRC, receivedCRC));
calculatedCRC, receivedCRC));
}
} else {
throw new RileyLinkCommunicationException(RileyLinkBLEError.TooShortOrNullResponse);
}
}
break;
break;
default:
throw new NotImplementedException("this {" + RileyLinkUtil.getEncoding().toString()
+ "} encoding is not supported");
throw new NotImplementedException("this {" + RileyLinkUtil.getInstance().getEncoding().toString()
+ "} encoding is not supported");
}
} catch (NumberFormatException e) {
decodedOK = false;

View file

@ -26,6 +26,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
public class RileyLinkStatusActivity extends NoSplashAppCompatActivity {
@Inject ResourceHelper resourceHelper;
@Inject RileyLinkUtil rileyLinkUtil;
TextView connectionStatus;
TextView configuredAddress;
@ -76,7 +77,7 @@ public class RileyLinkStatusActivity extends NoSplashAppCompatActivity {
this.connectedDevice = findViewById(R.id.rls_t1_connected_device);
this.connectionError = findViewById(R.id.rls_t1_connection_error);
rileyLinkServiceData = RileyLinkUtil.getRileyLinkServiceData();
rileyLinkServiceData = rileyLinkUtil.getRileyLinkServiceData();
// // 7-12
// int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, //
@ -114,8 +115,8 @@ public class RileyLinkStatusActivity extends NoSplashAppCompatActivity {
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mSectionsPagerAdapter.addFragment(new RileyLinkStatusGeneral(), resourceHelper.gs(R.string.rileylink_settings_tab1));
mSectionsPagerAdapter.addFragment(new RileyLinkStatusHistory(), resourceHelper.gs(R.string.rileylink_settings_tab2));
mSectionsPagerAdapter.addFragment(new RileyLinkStatusGeneralFragment(), resourceHelper.gs(R.string.rileylink_settings_tab1));
mSectionsPagerAdapter.addFragment(new RileyLinkStatusHistoryFragment(), resourceHelper.gs(R.string.rileylink_settings_tab2));
//mSectionsPagerAdapter.addFragment(new RileyLinkStatusDevice(), "Medtronic");
mViewPager.setAdapter(mSectionsPagerAdapter);

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -11,6 +10,9 @@ import org.joda.time.LocalDateTime;
import java.util.Locale;
import javax.inject.Inject;
import dagger.android.support.DaggerFragment;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
@ -27,7 +29,9 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
* Created by andy on 5/19/18.
*/
public class RileyLinkStatusGeneral extends Fragment implements RefreshableInterface {
public class RileyLinkStatusGeneralFragment extends DaggerFragment implements RefreshableInterface {
@Inject RileyLinkUtil rileyLinkUtil;
TextView connectionStatus;
TextView configuredAddress;
@ -58,7 +62,7 @@ public class RileyLinkStatusGeneral extends Fragment implements RefreshableInter
@Override
public void onStart() {
super.onStart();
rileyLinkServiceData = RileyLinkUtil.getRileyLinkServiceData();
rileyLinkServiceData = rileyLinkUtil.getRileyLinkServiceData();
this.connectionStatus = getActivity().findViewById(R.id.rls_t1_connection_status);
this.configuredAddress = getActivity().findViewById(R.id.rls_t1_configured_address);
@ -93,12 +97,12 @@ public class RileyLinkStatusGeneral extends Fragment implements RefreshableInter
public void refreshData() {
RileyLinkTargetDevice targetDevice = RileyLinkUtil.getTargetDevice();
RileyLinkTargetDevice targetDevice = rileyLinkUtil.getTargetDevice();
if (RileyLinkUtil.getServiceState()==null)
if (rileyLinkUtil.getServiceState() == null)
this.connectionStatus.setText(MainApp.gs(RileyLinkServiceState.NotStarted.getResourceId(targetDevice)));
else
this.connectionStatus.setText(MainApp.gs(RileyLinkUtil.getServiceState().getResourceId(targetDevice)));
this.connectionStatus.setText(MainApp.gs(rileyLinkUtil.getServiceState().getResourceId(targetDevice)));
if (rileyLinkServiceData != null) {
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
@ -109,7 +113,7 @@ public class RileyLinkStatusGeneral extends Fragment implements RefreshableInter
RileyLinkFirmwareVersion firmwareVersion = rileyLinkServiceData.versionCC110;
if (firmwareVersion==null) {
if (firmwareVersion == null) {
this.firmwareVersion.setText("BLE113: -\nCC110: -");
} else {
this.firmwareVersion.setText("BLE113: " + rileyLinkServiceData.versionBLE113 + //

View file

@ -12,6 +12,9 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import javax.inject.Inject;
import dagger.android.support.DaggerFragment;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
@ -23,7 +26,9 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
* Created by andy on 5/19/18.
*/
public class RileyLinkStatusHistory extends Fragment implements RefreshableInterface {
public class RileyLinkStatusHistoryFragment extends DaggerFragment implements RefreshableInterface {
@Inject RileyLinkUtil rileyLinkUtil;
RecyclerView recyclerView;
RecyclerViewAdapter recyclerViewAdapter;
@ -59,8 +64,8 @@ public class RileyLinkStatusHistory extends Fragment implements RefreshableInter
@Override
public void refreshData() {
if (RileyLinkUtil.getRileyLinkHistory()!=null) {
recyclerViewAdapter.addItemsAndClean(RileyLinkUtil.getRileyLinkHistory());
if (rileyLinkUtil.getRileyLinkHistory()!=null) {
recyclerViewAdapter.addItemsAndClean(rileyLinkUtil.getRileyLinkHistory());
}
}

View file

@ -15,6 +15,7 @@ import javax.inject.Inject
class RileyLinkBluetoothStateReceiver : DaggerBroadcastReceiver() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var rileyLinkUtil: RileyLinkUtil
override fun onReceive(context: Context, intent: Intent) {
super.onReceive(context, intent)
@ -27,7 +28,7 @@ class RileyLinkBluetoothStateReceiver : DaggerBroadcastReceiver() {
BluetoothAdapter.STATE_ON -> {
aapsLogger.debug("RileyLinkBluetoothStateReceiver: Bluetooth back on. Sending broadcast to RileyLink Framework")
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.BluetoothReconnected)
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.BluetoothReconnected)
}
}
}

View file

@ -5,20 +5,22 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service;
*/
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import dagger.android.DaggerBroadcastReceiver;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
@ -31,14 +33,17 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTask;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
/**
* I added this class outside of RileyLinkService, because for now it's very important part of RL framework and
* where we get a lot of problems. Especially merging between AAPS and RileyLinkAAPS. I might put it back at
* later time
*/
public class RileyLinkBroadcastReceiver extends BroadcastReceiver {
public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
@Inject RileyLinkUtil rileyLinkUtil;
@Inject SP sp;
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
@ -88,6 +93,7 @@ public class RileyLinkBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (intent == null) {
LOG.error("onReceive: received null intent");
@ -135,10 +141,9 @@ public class RileyLinkBroadcastReceiver extends BroadcastReceiver {
if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnected)) {
if (BluetoothAdapter.getDefaultAdapter().isEnabled()) {
RileyLinkUtil
.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.RileyLinkUnreachable);
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.RileyLinkUnreachable);
} else {
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled);
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled);
}
return true;
@ -166,14 +171,14 @@ public class RileyLinkBroadcastReceiver extends BroadcastReceiver {
LOG.debug("RfSpy Radio version (CC110): " + rlVersion.name());
this.serviceInstance.rileyLinkServiceData.versionCC110 = rlVersion;
ServiceTask task = new InitializePumpManagerTask(RileyLinkUtil.getTargetDevice());
ServiceTask task = new InitializePumpManagerTask(rileyLinkUtil.getTargetDevice());
ServiceTaskExecutor.startTask(task);
if (isLoggingEnabled())
LOG.info("Announcing RileyLink open For business");
return true;
} else if (action.equals(RileyLinkConst.Intents.RileyLinkNewAddressSet)) {
String RileylinkBLEAddress = SP.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
String RileylinkBLEAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
if (RileylinkBLEAddress.equals("")) {
LOG.error("No Rileylink BLE Address saved in app");
} else {

View file

@ -25,8 +25,6 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import static info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil.getRileyLinkCommunicationManager;
/**
* Created by andy on 5/6/18.
* Split from original file and renamed.
@ -36,6 +34,7 @@ public abstract class RileyLinkService extends DaggerService {
@Inject protected AAPSLogger aapsLogger;
@Inject protected SP sp;
@Inject protected Context context;
@Inject protected RileyLinkUtil rileyLinkUtil;
public RileyLinkBLE rileyLinkBLE; // android-bluetooth management
@ -50,9 +49,8 @@ public abstract class RileyLinkService extends DaggerService {
super.onCreate();
//LOG.debug("onCreate");
RileyLinkUtil.setContext(this.context);
RileyLinkUtil.setRileyLinkService(this);
RileyLinkUtil.setEncoding(getEncoding());
rileyLinkUtil.setRileyLinkService(this);
rileyLinkUtil.setEncoding(getEncoding());
initRileyLinkServiceData();
mBroadcastReceiver = new RileyLinkBroadcastReceiver(this, this.context);
@ -134,27 +132,26 @@ public abstract class RileyLinkService extends DaggerService {
// We've received a service startCommand, we grab the lock.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
RileyLinkUtil.setContext(getApplicationContext());
return (START_STICKY);
}
public boolean bluetoothInit() {
aapsLogger.debug(LTag.PUMPCOMM, "bluetoothInit: attempting to get an adapter");
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothInitializing);
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothInitializing);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
aapsLogger.error("Unable to obtain a BluetoothAdapter.");
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.NoBluetoothAdapter);
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.NoBluetoothAdapter);
} else {
if (!bluetoothAdapter.isEnabled()) {
aapsLogger.error("Bluetooth is not enabled.");
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled);
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled);
} else {
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothReady);
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothReady);
return true;
}
}
@ -167,11 +164,11 @@ public abstract class RileyLinkService extends DaggerService {
public boolean reconfigureRileyLink(String deviceAddress) {
if (rileyLinkBLE == null) {
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothInitializing);
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothInitializing);
return false;
}
RileyLinkUtil.setServiceState(RileyLinkServiceState.RileyLinkInitializing);
rileyLinkUtil.setServiceState(RileyLinkServiceState.RileyLinkInitializing);
if (rileyLinkBLE.isConnected()) {
if (deviceAddress.equals(rileyLinkServiceData.rileylinkAddress)) {
@ -192,10 +189,10 @@ public abstract class RileyLinkService extends DaggerService {
} else {
aapsLogger.debug(LTag.PUMPCOMM, "Using RL " + deviceAddress);
if (RileyLinkUtil.getServiceState() == RileyLinkServiceState.NotStarted) {
if (rileyLinkUtil.getServiceState() == RileyLinkServiceState.NotStarted) {
if (!bluetoothInit()) {
aapsLogger.error("RileyLink can't get activated, Bluetooth is not functioning correctly. {}",
RileyLinkUtil.getError() != null ? RileyLinkUtil.getError().name() : "Unknown error (null)");
rileyLinkUtil.getError() != null ? rileyLinkUtil.getError().name() : "Unknown error (null)");
return false;
}
}
@ -214,7 +211,7 @@ public abstract class RileyLinkService extends DaggerService {
// FIXME: This needs to be run in a session so that is interruptable, has a separate thread, etc.
public void doTuneUpDevice() {
RileyLinkUtil.setServiceState(RileyLinkServiceState.TuneUpDevice);
rileyLinkUtil.setServiceState(RileyLinkServiceState.TuneUpDevice);
MedtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
double lastGoodFrequency = 0.0d;
@ -239,11 +236,10 @@ public abstract class RileyLinkService extends DaggerService {
if (newFrequency == 0.0d) {
// error tuning pump, pump not present ??
RileyLinkUtil
.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.TuneUpOfDeviceFailed);
rileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.TuneUpOfDeviceFailed);
} else {
getRileyLinkCommunicationManager().clearNotConnectedCount();
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorReady);
rileyLinkUtil.getRileyLinkCommunicationManager().clearNotConnectedCount();
rileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorReady);
}
}
@ -255,7 +251,7 @@ public abstract class RileyLinkService extends DaggerService {
rileyLinkServiceData.rileylinkAddress = null;
}
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothReady);
rileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothReady);
}

View file

@ -23,8 +23,8 @@ public class DiscoverGattServicesTask extends ServiceTask {
public void run() {
if (needToConnect)
RileyLinkUtil.getRileyLinkBLE().connectGatt();
RileyLinkUtil.getInstance().getRileyLinkBLE().connectGatt();
RileyLinkUtil.getRileyLinkBLE().discoverServices();
RileyLinkUtil.getInstance().getRileyLinkBLE().discoverServices();
}
}

View file

@ -1,9 +1,6 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks;
import android.util.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
@ -13,7 +10,6 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLin
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
import info.nightscout.androidaps.utils.SP;
/**
@ -43,42 +39,42 @@ public class InitializePumpManagerTask extends ServiceTask {
double lastGoodFrequency = 0.0d;
if (RileyLinkUtil.getRileyLinkServiceData().lastGoodFrequency==null) {
if (RileyLinkUtil.getInstance().getRileyLinkServiceData().lastGoodFrequency == null) {
lastGoodFrequency = SP.getDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, 0.0d);
lastGoodFrequency = Math.round(lastGoodFrequency * 1000d) / 1000d;
RileyLinkUtil.getRileyLinkServiceData().lastGoodFrequency = lastGoodFrequency;
RileyLinkUtil.getInstance().getRileyLinkServiceData().lastGoodFrequency = lastGoodFrequency;
// if (RileyLinkUtil.getRileyLinkTargetFrequency() == null) {
// String pumpFrequency = SP.getString(MedtronicConst.Prefs.PumpFrequency, null);
// }
} else {
lastGoodFrequency = RileyLinkUtil.getRileyLinkServiceData().lastGoodFrequency;
lastGoodFrequency = RileyLinkUtil.getInstance().getRileyLinkServiceData().lastGoodFrequency;
}
if ((lastGoodFrequency > 0.0d)
&& RileyLinkUtil.getRileyLinkCommunicationManager().isValidFrequency(lastGoodFrequency)) {
&& RileyLinkUtil.getInstance().getRileyLinkCommunicationManager().isValidFrequency(lastGoodFrequency)) {
RileyLinkUtil.setServiceState(RileyLinkServiceState.RileyLinkReady);
RileyLinkUtil.getInstance().setServiceState(RileyLinkServiceState.RileyLinkReady);
if (L.isEnabled(L.PUMPCOMM))
LOG.info("Setting radio frequency to {} MHz", lastGoodFrequency);
RileyLinkUtil.getRileyLinkCommunicationManager().setRadioFrequencyForPump(lastGoodFrequency);
RileyLinkUtil.getInstance().getRileyLinkCommunicationManager().setRadioFrequencyForPump(lastGoodFrequency);
boolean foundThePump = RileyLinkUtil.getRileyLinkCommunicationManager().tryToConnectToDevice();
boolean foundThePump = RileyLinkUtil.getInstance().getRileyLinkCommunicationManager().tryToConnectToDevice();
if (foundThePump) {
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorReady);
RileyLinkUtil.getInstance().setServiceState(RileyLinkServiceState.PumpConnectorReady);
} else {
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorError,
RileyLinkError.NoContactWithDevice);
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_tunePump);
RileyLinkUtil.getInstance().setServiceState(RileyLinkServiceState.PumpConnectorError,
RileyLinkError.NoContactWithDevice);
RileyLinkUtil.getInstance().sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_tunePump);
}
} else {
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_tunePump);
RileyLinkUtil.getInstance().sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_tunePump);
}
}
}

View file

@ -19,7 +19,7 @@ public class RileyLinkSelectPreference extends Preference {
super(context);
setInitialSummaryValue();
MedtronicUtil.setRileyLinkSelectPreference(this);
MedtronicUtil.getInstance().setRileyLinkSelectPreference(this);
}
@ -27,7 +27,7 @@ public class RileyLinkSelectPreference extends Preference {
super(context, attrs);
setInitialSummaryValue();
MedtronicUtil.setRileyLinkSelectPreference(this);
MedtronicUtil.getInstance().setRileyLinkSelectPreference(this);
}

View file

@ -57,6 +57,7 @@ class MedtronicFragment : DaggerFragment() {
@Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var medtronicPumpPlugin: MedtronicPumpPlugin
@Inject lateinit var warnColors: WarnColors
@Inject lateinit var rileyLinkUtil: RileyLinkUtil
private var disposable: CompositeDisposable = CompositeDisposable()
@ -173,10 +174,10 @@ class MedtronicFragment : DaggerFragment() {
private fun setDeviceStatus() {
val pumpStatus: MedtronicPumpStatus = MedtronicUtil.getPumpStatus()
pumpStatus.rileyLinkServiceState = checkStatusSet(pumpStatus.rileyLinkServiceState,
RileyLinkUtil.getServiceState()) as RileyLinkServiceState?
rileyLinkUtil.getServiceState()) as RileyLinkServiceState?
val resourceId = pumpStatus.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.MedtronicPump)
val rileyLinkError = RileyLinkUtil.getError()
val rileyLinkError = rileyLinkUtil.getError()
medtronic_rl_status.text =
when {
pumpStatus.rileyLinkServiceState == RileyLinkServiceState.NotStarted -> resourceHelper.gs(resourceId)
@ -187,7 +188,7 @@ class MedtronicFragment : DaggerFragment() {
}
medtronic_rl_status.setTextColor(if (rileyLinkError != null) Color.RED else Color.WHITE)
pumpStatus.rileyLinkError = checkStatusSet(pumpStatus.rileyLinkError, RileyLinkUtil.getError()) as RileyLinkError?
pumpStatus.rileyLinkError = checkStatusSet(pumpStatus.rileyLinkError, rileyLinkUtil.getError()) as RileyLinkError?
medtronic_errors.text =
pumpStatus.rileyLinkError?.let {

View file

@ -53,6 +53,7 @@ import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkConfigurationTask;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor;
@ -95,6 +96,7 @@ import static info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUt
public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInterface {
private final SP sp;
private final RileyLinkUtil rileyLinkUtil;
protected static MedtronicPumpPlugin plugin = null;
private RileyLinkMedtronicService medtronicService;
@ -125,7 +127,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
ActivePluginProvider activePlugin,
SP sp,
CommandQueueProvider commandQueue,
FabricPrivacy fabricPrivacy
FabricPrivacy fabricPrivacy,
RileyLinkUtil rileyLinkUtil
) {
super(new PluginDescription() //
@ -139,7 +142,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
);
this.plugin = this;
this.rxBus = rxBus;
this.rileyLinkUtil = rileyLinkUtil;
this.sp = sp;
displayConnectionMessages = false;
@ -177,7 +180,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
@Override
protected void onStart() {
super.onStart();
medtronicUIComm = new MedtronicUIComm(aapsLogger, rxBus, getResourceHelper());
medtronicUIComm = new MedtronicUIComm(aapsLogger, rxBus, getResourceHelper(), rileyLinkUtil);
medtronicHistoryData = new MedtronicHistoryData(aapsLogger, sp, activePlugin);
}

View file

@ -16,6 +16,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
public class MedtronicUIComm {
private final AAPSLogger aapsLogger;
private final RileyLinkUtil rileyLinkUtil;
MedtronicCommunicationManager mcmInstance = null;
MedtronicUIPostprocessor uiPostprocessor;
@ -23,9 +24,11 @@ public class MedtronicUIComm {
public MedtronicUIComm(
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
ResourceHelper resourceHelper
ResourceHelper resourceHelper,
RileyLinkUtil rileyLinkUtil
) {
this.aapsLogger = aapsLogger;
this.rileyLinkUtil = rileyLinkUtil;
uiPostprocessor = new MedtronicUIPostprocessor(aapsLogger, rxBus, resourceHelper);
}
@ -108,6 +111,6 @@ public class MedtronicUIComm {
public void startTunning() {
RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_tunePump);
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.IPC.MSG_PUMP_tunePump);
}
}

View file

@ -69,7 +69,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
public class MedtronicHistoryData {
private static AAPSLogger aapsLogger;
private AAPSLogger aapsLogger;
private SP sp;
private ActivePluginProvider activePlugin;
@ -138,7 +138,7 @@ public class MedtronicHistoryData {
}
private static void showLogs(String header, String data) {
private void showLogs(String header, String data) {
if (header != null) {
aapsLogger.debug(LTag.PUMP, header);
}

View file

@ -211,7 +211,7 @@ public class MedtronicPumpStatus extends PumpStatus {
: RileyLinkTargetFrequency.Medtronic_WorldWide;
if (targetFrequency != newTargetFrequency) {
RileyLinkUtil.setRileyLinkTargetFrequency(newTargetFrequency);
RileyLinkUtil.getInstance().setRileyLinkTargetFrequency(newTargetFrequency);
targetFrequency = newTargetFrequency;
targetFrequencyChanged = true;
}
@ -311,12 +311,12 @@ public class MedtronicPumpStatus extends PumpStatus {
}
if (rileyLinkAddressChanged) {
MedtronicUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet);
MedtronicUtil.getInstance().sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet);
rileyLinkAddressChanged = false;
}
if (encodingChanged) {
RileyLinkUtil.getRileyLinkService().changeRileyLinkEncoding(encodingType);
RileyLinkUtil.getInstance().getRileyLinkService().changeRileyLinkEncoding(encodingType);
encodingChanged = false;
}
}

View file

@ -87,8 +87,8 @@ public class RileyLinkMedtronicService extends RileyLinkService {
rileyLinkServiceData = new RileyLinkServiceData(RileyLinkTargetDevice.MedtronicPump);
RileyLinkUtil.setRileyLinkServiceData(rileyLinkServiceData);
RileyLinkUtil.setTargetDevice(RileyLinkTargetDevice.MedtronicPump);
rileyLinkUtil.setRileyLinkServiceData(rileyLinkServiceData);
rileyLinkUtil.setTargetDevice(RileyLinkTargetDevice.MedtronicPump);
setPumpIDString(sp.getString(MedtronicConst.Prefs.PumpSerial, "000000"));
@ -99,7 +99,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
rfspy = new RFSpy(rileyLinkBLE);
rfspy.startReader();
RileyLinkUtil.setRileyLinkBLE(rileyLinkBLE);
rileyLinkUtil.setRileyLinkBLE(rileyLinkBLE);
// init rileyLinkCommunicationManager
medtronicCommunicationManager = new MedtronicCommunicationManager(context, rfspy);
@ -177,7 +177,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
// PumpInterface - REMOVE
public boolean isInitialized() {
return RileyLinkServiceState.isReady(RileyLinkUtil.getRileyLinkServiceData().serviceState);
return RileyLinkServiceState.isReady(rileyLinkUtil.getRileyLinkServiceData().serviceState);
}

View file

@ -2,7 +2,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusGeneral">
tools:context=".plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusGeneralFragment">
<ScrollView
android:layout_width="match_parent"

View file

@ -2,7 +2,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusHistory">
tools:context=".plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusHistoryFragment">
<LinearLayout
android:layout_width="match_parent"