diff --git a/app/build.gradle b/app/build.gradle index 7260c8466d..6da0170851 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -64,11 +64,12 @@ android { multiDexEnabled true versionCode 1500 // dev_version: 2.0 - version "medtronic-0.5" + version "medtronic-0.6" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"' - buildConfigField "String", "DEV_VERSION", '"2.0i"' + buildConfigField "String", "DEV_VERSION", '"2.0"' + buildConfigField "String", "DEV_DATE", '"4.1.2019"' testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" ndk { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a1dcc7a30b..4a4e499191 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -51,6 +51,10 @@ + + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/MessageDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/MessageDialog.java new file mode 100644 index 0000000000..49890c3545 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/MessageDialog.java @@ -0,0 +1,95 @@ +package info.nightscout.androidaps.plugins.Overview.Dialogs; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +import info.nightscout.androidaps.R; + +public class MessageDialog extends DialogFragment implements View.OnClickListener { + + private static Logger log = LoggerFactory.getLogger(MessageDialog.class); + // Button muteButton; + Button okButton; + TextView statusView; + MessageHelperActivity helperActivity; + + static String status; + static String title; + + + // static int soundId; + + public MessageDialog() { + super(); + } + + + public void setStatus(String status) { + this.status = status; + } + + + public void setTitle(String title) { + this.title = title; + } + + + public void setHelperActivity(MessageHelperActivity activity) { + this.helperActivity = activity; + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + getDialog().setTitle(title); + View view = inflater.inflate(R.layout.overview_message_dialog, container, false); + // muteButton = (Button)view.findViewById(R.id.overview_error_mute); + okButton = (Button)view.findViewById(R.id.overview_message_ok); + statusView = (TextView)view.findViewById(R.id.overview_message_status); + // muteButton.setOnClickListener(this); + okButton.setOnClickListener(this); + setCancelable(false); + + // startAlarm(); + return view; + } + + + @Override + public void onResume() { + super.onResume(); + if (getDialog() != null) + getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + statusView.setText(status); + } + + + @Override + public void dismiss() { + super.dismissAllowingStateLoss(); + if (helperActivity != null) { + helperActivity.finish(); + } + } + + + @Override + public void onClick(View view) { + switch (view.getId()) { + + case R.id.overview_message_ok: + log.debug("Error dialog ok button pressed"); + dismiss(); + break; + } + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/MessageHelperActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/MessageHelperActivity.java new file mode 100644 index 0000000000..0cdc77b210 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/MessageHelperActivity.java @@ -0,0 +1,24 @@ +package info.nightscout.androidaps.plugins.Overview.Dialogs; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; + +public class MessageHelperActivity extends AppCompatActivity { + + public MessageHelperActivity() { + super(); + } + + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + MessageDialog messageDialog = new MessageDialog(); + messageDialog.setHelperActivity(this); + messageDialog.setStatus(getIntent().getStringExtra("status")); + + messageDialog.setTitle(getIntent().getStringExtra("title")); + messageDialog.show(this.getSupportFragmentManager(), "Message"); + + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/dialog/RileyLinkBLEScanActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/dialog/RileyLinkBLEScanActivity.java index d8a6be8200..ed9c2bf429 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/dialog/RileyLinkBLEScanActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/dialog/RileyLinkBLEScanActivity.java @@ -25,7 +25,6 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.ParcelUuid; -import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; @@ -65,7 +64,6 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { // Stops scanning after 30 seconds. private static final long SCAN_PERIOD = 30000; public boolean mScanning; - public Snackbar snackbar; public ScanSettings settings; public List filters; public ListView listBTScan; @@ -76,6 +74,9 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { private LeDeviceListAdapter mLeDeviceListAdapter; private Handler mHandler; + private String actionTitleStart, actionTitleStop; + private MenuItem menuItem; + @Override protected void onCreate(Bundle savedInstanceState) { @@ -109,8 +110,6 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { MainApp.bus().post(new EventMedtronicPumpConfigurationChanged()); - // RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet); - finish(); }); @@ -118,31 +117,21 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { toolbarBTScan.setTitle(R.string.rileylink_scanner_title); setSupportActionBar(toolbarBTScan); - // TODO remove snackbar, stop needs to be on same button as start - 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); - } - }); - prepareForScanning(); } - // @Override - // protected void onPause() { - // super.onPause(); - // scanLeDevice(false); - // mLeDeviceListAdapter.clear(); - // mLeDeviceListAdapter.notifyDataSetChanged(); - // } - @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_rileylink_ble_scan, menu); + + actionTitleStart = MainApp.gs(R.string.rileylink_scanner_scan_scan); + actionTitleStop = MainApp.gs(R.string.rileylink_scanner_scan_stop); + + menuItem = menu.getItem(0); + + menuItem.setTitle(actionTitleStart); + return true; } @@ -151,8 +140,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.rileylink_miScan: { - // FIXME - scanLeDevice(true); + scanLeDevice(menuItem.getTitle().equals(actionTitleStart)); return true; } @@ -166,7 +154,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { // https://developer.android.com/training/permissions/requesting.html // http://developer.radiusnetworks.com/2015/09/29/is-your-beacon-app-ready-for-android-6.html if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { - Toast.makeText(this, "R.string.ble_not_supported", Toast.LENGTH_SHORT).show(); + Toast.makeText(this, R.string.rileylink_scanner_ble_not_supported, Toast.LENGTH_SHORT).show(); } else { // Use this check to determine whether BLE is supported on the device. Then // you can selectively disable BLE-related features. @@ -179,7 +167,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to enable Bluetooth. if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) { - Toast.makeText(this, "R.string.ble_not_enabled", Toast.LENGTH_SHORT).show(); + Toast.makeText(this, R.string.rileylink_scanner_ble_not_enabled, Toast.LENGTH_SHORT).show(); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -197,7 +185,6 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { filters = Arrays.asList(new ScanFilter.Builder().setServiceUuid( ParcelUuid.fromString(GattAttributes.SERVICE_RADIO)).build()); - // scanLeDevice(true); } } @@ -224,8 +211,6 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { @Override public void onScanResult(int callbackType, final ScanResult scanRecord) { - // final BleAdvertisedData badata = RileyLinkUtil.parseAdertisedData(scanRecord); - Log.d(TAG, scanRecord.toString()); runOnUiThread(() -> { @@ -243,7 +228,6 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { boolean added = false; for (ScanResult result : results) { - if (addDevice(result)) added = true; } @@ -258,13 +242,6 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { BluetoothDevice device = result.getDevice(); - // BluetoothClass bluetoothClass = device.getBluetoothClass(); - // - // StringBuilder sb = new StringBuilder("Class: "); - // sb.append("MajorClass: " + bluetoothClass.getMajorDeviceClass()); - // sb.append("DeviceClass: " + bluetoothClass.getDeviceClass()); - // Log.d(TAG, sb.toString()); - // FIXME remove most of code List serviceUuids = result.getScanRecord().getServiceUuids(); if (serviceUuids == null || serviceUuids.size() == 0) { @@ -293,50 +270,53 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { ", type=" + device.getType(); // + ", alias=" + device.getAlias(); } - // @Override - // public void onScanFailed(int errorCode) { - // - // Log.e("Scan Failed", "Error Code: " + errorCode); - // Toast.makeText(mContext, "Scan Failed " + errorCode, Toast.LENGTH_LONG).show(); - // } + + @Override + public void onScanFailed(int errorCode) { + Log.e("Scan Failed", "Error Code: " + errorCode); + Toast.makeText(mContext, MainApp.gs(R.string.rileylink_scanner_scanning_error, errorCode), + Toast.LENGTH_LONG).show(); + } + }; private void scanLeDevice(final boolean enable) { - // FIXME - if (enable) { mLeDeviceListAdapter.clear(); mLeDeviceListAdapter.notifyDataSetChanged(); // Stops scanning after a pre-defined scan period. - mHandler.postDelayed(new Runnable() { + mHandler.postDelayed(() -> { - @Override - public void run() { + if (mScanning) { mScanning = false; mLEScanner.stopScan(mScanCallback2); LOG.debug("scanLeDevice: Scanning Stop"); - // Toast.makeText(mContext, "Scanning finished", Toast.LENGTH_SHORT).show(); - snackbar.dismiss(); + Toast.makeText(mContext, R.string.rileylink_scanner_scanning_finished, Toast.LENGTH_SHORT).show(); + menuItem.setTitle(actionTitleStart); } }, SCAN_PERIOD); mScanning = true; mLEScanner.startScan(filters, settings, mScanCallback2); LOG.debug("scanLeDevice: Scanning Start"); - // Toast.makeText(this, "Scanning", Toast.LENGTH_SHORT).show(); - snackbar.show(); + Toast.makeText(this, R.string.rileylink_scanner_scanning, Toast.LENGTH_SHORT).show(); + + menuItem.setTitle(actionTitleStop); + } else { - mScanning = false; - mLEScanner.stopScan(mScanCallback2); + if (mScanning) { + mScanning = false; + mLEScanner.stopScan(mScanCallback2); - LOG.debug("scanLeDevice: Scanning Stop"); - // Toast.makeText(this, "Scanning finished", Toast.LENGTH_SHORT).show(); - snackbar.dismiss(); + LOG.debug("scanLeDevice: Scanning Stop"); + Toast.makeText(this, R.string.rileylink_scanner_scanning_finished, Toast.LENGTH_SHORT).show(); + menuItem.setTitle(actionTitleStart); + } } } @@ -357,14 +337,6 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { } - // public void addDevice(BluetoothDevice device) { - // - // if (!mLeDevices.contains(device)) { - // mLeDevices.add(device); - // notifyDataSetChanged(); - // } - // } - public void addDevice(ScanResult result) { if (!mLeDevices.contains(result.getDevice())) { @@ -375,11 +347,6 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { } - // public BluetoothDevice getDevice(int position) { - // - // return rileyLinkDevices.get(position); - // } - public void clear() { mLeDevices.clear(); rileyLinkDevices.clear(); @@ -435,27 +402,12 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { deviceName += " (" + getResources().getString(R.string.rileylink_scanner_selected_device) + ")"; } - // if (deviceName == null) { - // BleAdvertisedData bleAdvertisedData = mapDevices.get(device); - // - // deviceName = bleAdvertisedData.getName(); - // - // Log.d(TAG, "Old name was null so we replaced it with " + deviceName); - // } - viewHolder.deviceName.setText(deviceName); viewHolder.deviceAddress.setText(device.getAddress()); return view; } - // public void addDevice(BluetoothDevice device, BleAdvertisedData bleAdvertisedData) { - // if (!mLeDevices.contains(device)) { - // mLeDevices.add(device); - // mapDevices.put(device, bleAdvertisedData); - // notifyDataSetChanged(); - // } - // } } static class ViewHolder { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/data/RadioResponse.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/data/RadioResponse.java index 3c1efc3204..c889fe776c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/data/RadioResponse.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/data/RadioResponse.java @@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.RileyLinkCommunicationException; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.command.RileyLinkCommand; +import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkBLEError; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkCommandType; import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs.RileyLinkFirmwareVersion; import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil; @@ -104,14 +105,19 @@ public class RadioResponse { case FourByteSixByteLocal: { byte[] decodeThis = RileyLinkUtil.getEncoding4b6b().decode4b6b(encodedPayload); - decodedOK = true; - decodedPayload = ByteUtil.substring(decodeThis, 0, decodeThis.length - 1); - receivedCRC = decodeThis[decodeThis.length - 1]; - byte calculatedCRC = CRC.crc8(decodedPayload); - if (receivedCRC != calculatedCRC) { - LOG.error(String.format("RadioResponse: CRC mismatch, calculated 0x%02x, received 0x%02x", - calculatedCRC, receivedCRC)); + if (decodeThis != null && decodeThis.length > 2) { + decodedOK = true; + + decodedPayload = ByteUtil.substring(decodeThis, 0, decodeThis.length - 1); + receivedCRC = decodeThis[decodeThis.length - 1]; + byte calculatedCRC = CRC.crc8(decodedPayload); + if (receivedCRC != calculatedCRC) { + LOG.error(String.format("RadioResponse: CRC mismatch, calculated 0x%02x, received 0x%02x", + calculatedCRC, receivedCRC)); + } + } else { + throw new RileyLinkCommunicationException(RileyLinkBLEError.TooShortOrNullResponse); } } break; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/defs/RileyLinkBLEError.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/defs/RileyLinkBLEError.java index d278e8ac34..83bed85f21 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/defs/RileyLinkBLEError.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/defs/RileyLinkBLEError.java @@ -7,7 +7,8 @@ package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.defs; public enum RileyLinkBLEError { CodingErrors("Coding Errors encpountered during decode of RileyLink packet."), // Timeout("Timeout"), // - Interrupted("Interrupted"); + Interrupted("Interrupted"), + TooShortOrNullResponse("Too short or null decoded response."); private String description; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java index 1366cad380..3ca5367f89 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java @@ -40,7 +40,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Actions.defs.CustomAction; import info.nightscout.androidaps.plugins.Actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; +import info.nightscout.androidaps.plugins.Overview.Dialogs.MessageHelperActivity; import info.nightscout.androidaps.plugins.PumpCommon.PumpPluginAbstract; import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpDriverState; import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType; @@ -513,7 +513,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter return true; } - LOG.info("isThisProfileSet: check"); + // LOG.info("isThisProfileSet: check"); + + LOG.info("isThisProfileSet: check [basalProfileChanged={}, basalByHourSet={}, isBasalProfileInvalid={}", + basalProfileChanged, getMDTPumpStatus().basalsByHour != null, isBasalProfileInvalid); if (!basalProfileChanged && getMDTPumpStatus().basalsByHour != null && !isBasalProfileInvalid) { if (isLoggingEnabled()) @@ -541,10 +544,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter boolean valid = false; boolean noData = false; - if (responseTask.haveData()) { + LOG.debug("isThisProfileSet: haveData={}", responseTask.hasData()); + + if (responseTask.hasData()) { valid = isProfileSame(profile); + LOG.debug("isThisProfileSet: valid={}", valid); + if (valid) { basalProfileChanged = false; } @@ -670,61 +677,56 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable); if (bolusDeliveryType == BolusDeliveryType.CancelDelivery) { - LOG.debug("MedtronicPumpPlugin::deliverBolus - Delivery Canceled."); + // LOG.debug("MedtronicPumpPlugin::deliverBolus - Delivery Canceled."); return setNotReachable(true, true); } - LOG.debug("MedtronicPumpPlugin::deliverBolus - Starting wait period."); + // LOG.debug("MedtronicPumpPlugin::deliverBolus - Starting wait period."); - SystemClock.sleep(10000); + int sleepTime = SP.getInt(MedtronicConst.Prefs.BolusDelay, 10) * 1000; + + SystemClock.sleep(sleepTime); if (bolusDeliveryType == BolusDeliveryType.CancelDelivery) { - LOG.debug("MedtronicPumpPlugin::deliverBolus - Delivery Canceled, before wait period."); + // LOG.debug("MedtronicPumpPlugin::deliverBolus - Delivery Canceled, before wait period."); return setNotReachable(true, true); } - LOG.debug("MedtronicPumpPlugin::deliverBolus - End wait period. Start delivery"); + // LOG.debug("MedtronicPumpPlugin::deliverBolus - End wait period. Start delivery"); try { bolusDeliveryType = BolusDeliveryType.Delivering; - // LOG.error("MedtronicPumpPlugin::deliverBolus Not fully implemented - Just base command."); + // LOG.debug("MedtronicPumpPlugin::deliverBolus - Start delivery"); MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetBolus, detailedBolusInfo.insulin); Boolean response = (Boolean)responseTask.returnData; - // TODO display bolus - - // setRefreshButtonEnabled(true); - setRefreshButtonEnabled(true); - bolusDeliveryType = BolusDeliveryType.Idle; + + // LOG.debug("MedtronicPumpPlugin::deliverBolus - Response: {}", response); if (response) { if (bolusDeliveryType == BolusDeliveryType.CancelDelivery) { - LOG.debug("MedtronicPumpPlugin::deliverBolus - Delivery Canceled after Bolus started."); + // LOG.debug("MedtronicPumpPlugin::deliverBolus - Delivery Canceled after Bolus started."); new Thread(() -> { // Looper.prepare(); - LOG.debug("MedtronicPumpPlugin::deliverBolus - Show dialog - before"); + // LOG.debug("MedtronicPumpPlugin::deliverBolus - Show dialog - before"); SystemClock.sleep(2000); - LOG.debug("MedtronicPumpPlugin::deliverBolus - Show dialog. Context: " - + MainApp.instance().getApplicationContext()); + // LOG.debug("MedtronicPumpPlugin::deliverBolus - Show dialog. Context: " + // + MainApp.instance().getApplicationContext()); - Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); - // i.putExtra("soundid", R.raw.boluserror); + Intent i = new Intent(MainApp.instance(), MessageHelperActivity.class); i.putExtra("status", MainApp.gs(R.string.medtronic_cmd_cancel_bolus_not_supported)); i.putExtra("title", MainApp.gs(R.string.combo_warning)); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); MainApp.instance().startActivity(i); - // OKDialog.show(MainApp.instance().getApplicationContext(), // - // MainApp.gs(R.string.combo_warning), // - // MainApp.gs(R.string.medtronic_cmd_cancel_bolus_not_supported), null); }).start(); } @@ -737,142 +739,21 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter incrementStatistics(detailedBolusInfo.isSMB ? MedtronicConst.Statistics.SMBBoluses : MedtronicConst.Statistics.StandardBoluses); - if (bolusDeliveryType == BolusDeliveryType.CancelDelivery) { - return new PumpEnactResult() // - .success(false) // - .enacted(response) // - .bolusDelivered(detailedBolusInfo.insulin) // - .carbsDelivered(detailedBolusInfo.carbs) // - .comment(MainApp.gs(R.string.medtronic_cmd_cancel_bolus_not_supported)); - } else { - return new PumpEnactResult().success(response) // - .enacted(response) // - .bolusDelivered(detailedBolusInfo.insulin) // - .carbsDelivered(detailedBolusInfo.carbs); - } - } else { + return new PumpEnactResult().success(response) // + .enacted(response) // + .bolusDelivered(detailedBolusInfo.insulin) // + .carbsDelivered(detailedBolusInfo.carbs); + } else { return new PumpEnactResult() // .success(bolusDeliveryType == BolusDeliveryType.CancelDelivery) // .enacted(false) // .comment(MainApp.gs(R.string.medtronic_cmd_bolus_could_not_be_delivered)); - } - // pump.activity = MainApp.gs(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin); - // MainApp.bus().post(new EventComboPumpUpdateGUI()); - // - // // check pump is ready and all pump bolus records are known - // CommandResult stateResult = runCommand(null, 2, () -> ruffyScripter.readQuickInfo(1)); - // if (!stateResult.success) { - // return new PumpEnactResult().success(false).enacted(false) - // .comment(MainApp.gs(R.string.combo_error_no_connection_no_bolus_delivered)); - // } - // if (stateResult.reservoirLevel != -1 && stateResult.reservoirLevel - 0.5 < detailedBolusInfo.insulin) { - // return new PumpEnactResult().success(false).enacted(false) - // .comment(MainApp.gs(R.string.combo_reservoir_level_insufficient_for_bolus)); - // } - // // the commands above ensured a connection was made, which updated this field - // if (pumpHistoryChanged) { - // return new PumpEnactResult().success(false).enacted(false) - // .comment(MainApp.gs(R.string.combo_bolus_rejected_due_to_pump_history_change)); - // } - // - // Bolus previousBolus = stateResult.history != null && !stateResult.history.bolusHistory.isEmpty() - // ? stateResult.history.bolusHistory.get(0) - // : new Bolus(0, 0, false); - // - // // reject a bolus if one with the exact same size was successfully delivered - // // within the last 1-2 minutes - // if (Math.abs(previousBolus.amount - detailedBolusInfo.insulin) < 0.01 - // && previousBolus.timestamp + 60 * 1000 > System.currentTimeMillis()) { - // log.debug("Bolu request rejected, same bolus was successfully delivered very recently"); - // return new PumpEnactResult().success(false).enacted(false) - // .comment(MainApp.gs(R.string.bolus_frequency_exceeded)); - // } - // - // - // - // if (cancelBolus) { - // return new PumpEnactResult().success(true).enacted(false); - // } - // - // BolusProgressReporter progressReporter = detailedBolusInfo.isSMB ? nullBolusProgressReporter : - // bolusProgressReporter; - // - // // start bolus delivery - // scripterIsBolusing = true; - // runCommand(null, 0, - // () -> ruffyScripter.deliverBolus(detailedBolusInfo.insulin, progressReporter)); - // scripterIsBolusing = false; - // - // // Note that the result of the issued bolus command is not checked. If there was - // // a connection problem, ruffyscripter tried to recover and we can just check the - // // history below to see what was actually delivered - // - // // get last bolus from pump history for verification - // // (reads 2 records to update `recentBoluses` further down) - // CommandResult postBolusStateResult = runCommand(null, 3, () -> ruffyScripter.readQuickInfo(2)); - // if (!postBolusStateResult.success) { - // return new PumpEnactResult().success(false).enacted(false) - // .comment(MainApp.gs(R.string.combo_error_bolus_verification_failed)); - // } - // Bolus lastPumpBolus = postBolusStateResult.history != null && - // !postBolusStateResult.history.bolusHistory.isEmpty() - // ? postBolusStateResult.history.bolusHistory.get(0) - // : null; - // - // // no bolus delivered? - // if (lastPumpBolus == null || lastPumpBolus.equals(previousBolus)) { - // if (cancelBolus) { - // return new PumpEnactResult().success(true).enacted(false); - // } else { - // return new PumpEnactResult() - // .success(false) - // .enacted(false) - // .comment(MainApp.gs(R.string.combo_error_no_bolus_delivered)); - // } - // } - // - // // at least some insulin delivered, so add it to treatments - // if (!addBolusToTreatments(detailedBolusInfo, lastPumpBolus)) - // return new PumpEnactResult().success(false).enacted(true) - // .comment(MainApp.gs(R.string.combo_error_updating_treatment_record)); - // - // // check pump bolus record has a sane timestamp - // long now = System.currentTimeMillis(); - // if (lastPumpBolus.timestamp < now - 10 * 60 * 1000 || lastPumpBolus.timestamp > now + 10 * 60 * 1000) { - // Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, - // MainApp.gs(R.string.combo_suspious_bolus_time), Notification.URGENT); - // MainApp.bus().post(new EventNewNotification(notification)); - // } - // - // // update `recentBoluses` so the bolus was just delivered won't be detected as a new - // // bolus that has been delivered on the pump - // recentBoluses = postBolusStateResult.history.bolusHistory; - // - // // only a partial bolus was delivered - // if (Math.abs(lastPumpBolus.amount - detailedBolusInfo.insulin) > 0.01) { - // if (cancelBolus) { - // return new PumpEnactResult().success(true).enacted(true); - // } - // return new PumpEnactResult().success(false).enacted(true) - // .comment(MainApp.gs(R.string.combo_error_partial_bolus_delivered, - // lastPumpBolus.amount, detailedBolusInfo.insulin)); - // } - // - // // full bolus was delivered successfully - // incrementBolusCount(); - // return new PumpEnactResult() - // .success(true) - // .enacted(lastPumpBolus.amount > 0) - // .bolusDelivered(lastPumpBolus.amount) - // .carbsDelivered(detailedBolusInfo.carbs); } finally { - // pump.activity = null; - // MainApp.bus().post(new EventComboPumpUpdateGUI()); MainApp.bus().post(new EventRefreshOverview("Bolus")); - // cancelBolus = false; + this.bolusDeliveryType = BolusDeliveryType.Idle; triggerUIChange(); } } @@ -903,7 +784,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter this.bolusDeliveryType = BolusDeliveryType.CancelDelivery; // if (isLoggingEnabled()) - LOG.warn("MedtronicPumpPlugin::deliverBolus - Stop Bolus Delivery."); + // LOG.warn("MedtronicPumpPlugin::deliverBolus - Stop Bolus Delivery."); } @@ -1183,6 +1064,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter gsonInstancePretty.toJson(lastPumpHistoryEntry)); medtronicHistoryData.setIsInInit(false); medtronicHistoryData.setLastHistoryRecordTime(null); + + // targetDate = lastPumpHistoryEntry.atechDateTime; } MedtronicUITask responseTask2 = medtronicUIComm.executeCommand(MedtronicCommandType.GetHistoryData, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/MedtronicCommunicationManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/MedtronicCommunicationManager.java index 7c4c2085b6..57dcd93262 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/MedtronicCommunicationManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/MedtronicCommunicationManager.java @@ -180,7 +180,11 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager pumpResponse.getRawContent()); MedtronicDeviceType pumpModel = (MedtronicDeviceType)dataResponse; - boolean valid = pumpModel != MedtronicDeviceType.Unknown_Device; + boolean valid = (pumpModel != MedtronicDeviceType.Unknown_Device); + + if (MedtronicUtil.getMedtronicPumpModel() == null && valid) { + MedtronicUtil.setMedtronicPumpModel(pumpModel); + } LOG.debug("isDeviceReachable. PumpModel is {} - Valid: {} (rssi={})", pumpModel.name(), valid, radioResponse.rssi); @@ -412,7 +416,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager public PumpHistoryResult getPumpHistory(PumpHistoryEntry lastEntry, LocalDateTime targetDate) { - PumpHistoryResult pumpTotalResult = new PumpHistoryResult(lastEntry, DateTimeUtil.toATechDate(targetDate)); + PumpHistoryResult pumpTotalResult = new PumpHistoryResult(lastEntry, targetDate == null ? null + : DateTimeUtil.toATechDate(targetDate)); if (doWakeUpBeforeCommand) wakeUp(receiverDeviceAwakeForMinutes, false); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/MedtronicHistoryEntry.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/MedtronicHistoryEntry.java index c1c3abfd7d..db54abb4b2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/MedtronicHistoryEntry.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/MedtronicHistoryEntry.java @@ -6,9 +6,12 @@ import java.util.Map; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.gson.annotations.Expose; +import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil; import info.nightscout.androidaps.plugins.PumpCommon.utils.DateTimeUtil; import info.nightscout.androidaps.plugins.PumpCommon.utils.HexDump; import info.nightscout.androidaps.plugins.PumpCommon.utils.StringUtil; @@ -39,6 +42,7 @@ public abstract class MedtronicHistoryEntry implements MedtronicHistoryEntryInte protected List rawData; protected static DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("dd.MM.yyyy HH:mm:ss"); + public static final Logger LOG = LoggerFactory.getLogger(MedtronicHistoryEntry.class); protected int[] sizes = new int[3]; @@ -142,8 +146,12 @@ public abstract class MedtronicHistoryEntry implements MedtronicHistoryEntryInte public String toString() { StringBuilder sb = new StringBuilder(); + if (this.DT == null) { + LOG.error("DT is null. RawData={}", ByteUtil.getHex(this.rawData)); + } + sb.append(getToStringStart()); - sb.append(", DT: " + StringUtil.getStringInLength(this.DT, 19)); + sb.append(", DT: " + (this.DT == null ? "null" : StringUtil.getStringInLength(this.DT, 19))); sb.append(", length="); sb.append(getHeadLength()); sb.append(","); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/ui/MedtronicUITask.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/ui/MedtronicUITask.java index 9987b270b3..82eb76cd2e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/ui/MedtronicUITask.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/ui/MedtronicUITask.java @@ -187,11 +187,6 @@ public class MedtronicUITask { } - public boolean haveData() { - return (returnData != null); - } - - public void postProcess(MedtronicUIPostprocessor postprocessor) { EventMedtronicDeviceStatusChange statusChange; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/util/MedtronicConst.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/util/MedtronicConst.java index 9be61ef036..88f758e702 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/util/MedtronicConst.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/util/MedtronicConst.java @@ -16,6 +16,7 @@ public class MedtronicConst { public static final String PumpFrequency = PrefPrefix + "frequency"; public static final String MaxBolus = PrefPrefix + "max_bolus"; public static final String MaxBasal = PrefPrefix + "max_basal"; + public static final String BolusDelay = PrefPrefix + "bolus_delay"; } public class Statistics { diff --git a/app/src/main/res/layout/overview_message_dialog.xml b/app/src/main/res/layout/overview_message_dialog.xml new file mode 100644 index 0000000000..dfade914a6 --- /dev/null +++ b/app/src/main/res/layout/overview_message_dialog.xml @@ -0,0 +1,29 @@ + + + + +