- Changes made in CGMS
- Finished support for Bolus history mapping - fixed 20 crashalytics errors
This commit is contained in:
parent
674ec84a9c
commit
8bf284f86d
|
@ -64,7 +64,7 @@ android {
|
|||
multiDexEnabled true
|
||||
versionCode 1500
|
||||
// dev_version: 2.2.1-dev
|
||||
version "medtronic-0.8.2-SNAPSHOT"
|
||||
version "medtronic-0.8.3-SNAPSHOT"
|
||||
buildConfigField "String", "VERSION", '"' + version + '"'
|
||||
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
|
||||
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'
|
||||
|
|
|
@ -229,11 +229,6 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
|||
else
|
||||
tempTarget.setVisibility(View.VISIBLE);
|
||||
|
||||
if (!Config.APS)
|
||||
tempTarget.setVisibility(View.GONE);
|
||||
else
|
||||
tempTarget.setVisibility(View.VISIBLE);
|
||||
|
||||
if (!pump.getPumpDescription().supportsTDDs)
|
||||
tddStats.setVisibility(View.GONE);
|
||||
else
|
||||
|
|
|
@ -367,7 +367,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
int agoMin = (int)(agoMsec / 60d / 1000d);
|
||||
ret += "LastConn: " + agoMin + " min ago\n";
|
||||
}
|
||||
if (pumpStatus.lastBolusTime.getTime() != 0) {
|
||||
if (pumpStatus.lastBolusTime != null && pumpStatus.lastBolusTime.getTime() != 0) {
|
||||
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pumpStatus.lastBolusAmount) + "U @" + //
|
||||
android.text.format.DateFormat.format("HH:mm", pumpStatus.lastBolusTime) + "\n";
|
||||
}
|
||||
|
@ -381,10 +381,10 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
if (activeExtendedBolus != null) {
|
||||
ret += "Extended: " + activeExtendedBolus.toString() + "\n";
|
||||
}
|
||||
if (!veryShort) {
|
||||
ret += "TDD: " + DecimalFormatter.to0Decimal(pumpStatus.dailyTotalUnits) + " / "
|
||||
+ pumpStatus.maxDailyTotalUnits + " U\n";
|
||||
}
|
||||
// if (!veryShort) {
|
||||
// ret += "TDD: " + DecimalFormatter.to0Decimal(pumpStatus.dailyTotalUnits) + " / "
|
||||
// + pumpStatus.maxDailyTotalUnits + " U\n";
|
||||
// }
|
||||
ret += "IOB: " + pumpStatus.iob + "U\n";
|
||||
ret += "Reserv: " + DecimalFormatter.to0Decimal(pumpStatus.reservoirRemainingUnits) + "U\n";
|
||||
ret += "Batt: " + pumpStatus.batteryRemaining + "\n";
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data;
|
||||
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.CommandValueDefinitionType;
|
||||
|
||||
/**
|
||||
* Created by andy on 4/5/19.
|
||||
*/
|
||||
|
||||
public class CommandValueDefinition {
|
||||
|
||||
public CommandValueDefinitionType definitionType;
|
||||
public String value;
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs;
|
||||
|
||||
/**
|
||||
* Created by andy on 4/5/19.
|
||||
*/
|
||||
|
||||
public enum CommandValueDefinitionRLType implements CommandValueDefinitionType {
|
||||
Name, //
|
||||
Firmware, //
|
||||
SignalStrength, //
|
||||
ConnectionState, //
|
||||
Frequency, //
|
||||
;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String commandAction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs;
|
||||
|
||||
/**
|
||||
* Created by andy on 4/5/19.
|
||||
*/
|
||||
|
||||
public interface CommandValueDefinitionType {
|
||||
|
||||
String getName();
|
||||
|
||||
|
||||
String getDescription();
|
||||
|
||||
|
||||
String commandAction();
|
||||
|
||||
}
|
|
@ -128,7 +128,7 @@ public class RileyLinkStatusActivity extends AppCompatActivity {
|
|||
|
||||
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");
|
||||
//mSectionsPagerAdapter.addFragment(new RileyLinkStatusDevice(), "Medtronic");
|
||||
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
@ -9,23 +10,27 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
|
||||
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.CommandValueDefinition;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.CommandValueDefinitionType;
|
||||
//import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.CommandValueDefinition;
|
||||
//import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
|
||||
//import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.CommandValueDefinitionType;
|
||||
//import info.nightscout.androidaps.plugins.pump.common.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;
|
||||
|
@ -45,11 +50,16 @@ public class RileyLinkStatusDevice extends Fragment implements RefreshableInterf
|
|||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
this.listView = (ListView)getActivity().findViewById(R.id.rileylink_history_list);
|
||||
this.listView = (ListView)getActivity().findViewById(R.id.rileyLinkDeviceList);
|
||||
|
||||
listView.setAdapter(adapter);
|
||||
|
||||
refreshData();
|
||||
setElements();
|
||||
}
|
||||
|
||||
|
||||
private void setElements() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -60,66 +70,55 @@ public class RileyLinkStatusDevice extends Fragment implements RefreshableInterf
|
|||
|
||||
static class ViewHolder {
|
||||
|
||||
TextView itemTime;
|
||||
TextView itemSource;
|
||||
TextView itemDescription;
|
||||
Button itemValue;
|
||||
}
|
||||
|
||||
private class RileyLinkCommandListAdapter extends BaseAdapter {
|
||||
|
||||
private List<RLHistoryItem> historyItemList;
|
||||
private List<CommandValueDefinition> commandValueList;
|
||||
private Map<CommandValueDefinitionType, CommandValueDefinition> commandValueMap;
|
||||
private LayoutInflater mInflator;
|
||||
|
||||
|
||||
public RileyLinkCommandListAdapter() {
|
||||
super();
|
||||
historyItemList = new ArrayList<>();
|
||||
commandValueList = new ArrayList<>();
|
||||
mInflator = RileyLinkStatusDevice.this.getLayoutInflater();
|
||||
}
|
||||
|
||||
|
||||
public void addItem(RLHistoryItem item) {
|
||||
if (!historyItemList.contains(item)) {
|
||||
historyItemList.add(item);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
public void addItems(List<CommandValueDefinition> list) {
|
||||
commandValueList.addAll(list);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
for (CommandValueDefinition commandValueDefinition : list) {
|
||||
commandValueMap.put(commandValueDefinition.definitionType, commandValueDefinition);
|
||||
}
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
public CommandValueDefinition getCommandValueItem(int position) {
|
||||
return commandValueList.get(position);
|
||||
}
|
||||
|
||||
|
||||
public void clear() {
|
||||
historyItemList.clear();
|
||||
commandValueList.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return historyItemList.size();
|
||||
return commandValueList.size();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getItem(int i) {
|
||||
return historyItemList.get(i);
|
||||
return commandValueList.get(i);
|
||||
}
|
||||
|
||||
|
||||
|
@ -136,18 +135,17 @@ public class RileyLinkStatusDevice extends Fragment implements RefreshableInterf
|
|||
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);
|
||||
viewHolder.itemDescription = (TextView)view.findViewById(R.id.rileylink_device_label);
|
||||
viewHolder.itemValue = (Button)view.findViewById(R.id.rileylink_device_action);
|
||||
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());
|
||||
// Z
|
||||
// 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;
|
||||
}
|
||||
|
|
|
@ -94,13 +94,18 @@ public class RileyLinkStatusGeneral extends Fragment implements RefreshableInter
|
|||
RileyLinkTargetDevice targetDevice = RileyLinkUtil.getTargetDevice();
|
||||
|
||||
this.connectionStatus.setText(MainApp.gs(RileyLinkUtil.getServiceState().getResourceId(targetDevice)));
|
||||
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
|
||||
this.connectionError.setText(rileyLinkServiceData.errorCode == null ? //
|
||||
"-"
|
||||
: MainApp.gs(rileyLinkServiceData.errorCode.getResourceId(targetDevice)));
|
||||
|
||||
this.firmwareVersion.setText("BLE113: " + rileyLinkServiceData.versionBLE113 + "\nCC110: "
|
||||
+ rileyLinkServiceData.versionCC110.toString());
|
||||
if (rileyLinkServiceData != null) {
|
||||
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
|
||||
this.connectionError.setText(rileyLinkServiceData.errorCode == null ? //
|
||||
"-"
|
||||
: MainApp.gs(rileyLinkServiceData.errorCode.getResourceId(targetDevice)));
|
||||
|
||||
this.firmwareVersion.setText("BLE113: " + //
|
||||
rileyLinkServiceData.versionBLE113 == null ? "-" : rileyLinkServiceData.versionBLE113 + //
|
||||
"\nCC110: " + rileyLinkServiceData.versionCC110 == null ? "-" : rileyLinkServiceData.versionCC110
|
||||
.toString());
|
||||
}
|
||||
|
||||
// TODO add handling for Omnipod pump status
|
||||
this.medtronicPumpStatus = MedtronicUtil.getPumpStatus();
|
||||
|
|
|
@ -180,6 +180,11 @@ public abstract class RileyLinkService extends Service {
|
|||
// returns true if our Rileylink configuration changed
|
||||
public boolean reconfigureRileyLink(String deviceAddress) {
|
||||
|
||||
if (rileyLinkBLE == null) {
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothInitializing);
|
||||
return false;
|
||||
}
|
||||
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.RileyLinkInitializing);
|
||||
|
||||
if (rileyLinkBLE.isConnected()) {
|
||||
|
|
|
@ -185,7 +185,7 @@ public class DateTimeUtil {
|
|||
Date d = new Date();
|
||||
d.setDate(dayOfMonth);
|
||||
d.setMonth(month - 1);
|
||||
d.setYear(year);
|
||||
d.setYear(year - 1900);
|
||||
d.setHours(hourOfDay);
|
||||
d.setMinutes(minute);
|
||||
d.setSeconds(second);
|
||||
|
|
|
@ -408,6 +408,9 @@ public class MedtronicFragment extends SubscriberFragment {
|
|||
if (activity != null && basaBasalRateView != null)
|
||||
activity.runOnUiThread(() -> {
|
||||
|
||||
if (lastConnectionView == null) // ui not yet initialized
|
||||
return;
|
||||
|
||||
localActivity = activity;
|
||||
MedtronicPumpPlugin plugin = (MedtronicPumpPlugin)MedtronicPumpPlugin.getPlugin();
|
||||
MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -274,7 +275,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
@Override
|
||||
public boolean isInitialized() {
|
||||
// TODO remove
|
||||
if (isLoggingEnabled())
|
||||
if (isLoggingEnabled() && displayConnectionMessages)
|
||||
LOG.debug("MedtronicPumpPlugin::isInitialized");
|
||||
return isServiceSet() && isInitialized;
|
||||
}
|
||||
|
@ -337,8 +338,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
// TODO remove
|
||||
if (isLoggingEnabled())
|
||||
if (isLoggingEnabled() && displayConnectionMessages)
|
||||
LOG.debug("MedtronicPumpPlugin::isConnected");
|
||||
return isServiceSet() && medtronicService.isInitialized();
|
||||
}
|
||||
|
@ -346,8 +346,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
@Override
|
||||
public boolean isConnecting() {
|
||||
// TODO remove
|
||||
if (isLoggingEnabled())
|
||||
if (isLoggingEnabled() && displayConnectionMessages)
|
||||
LOG.debug("MedtronicPumpPlugin::isConnecting");
|
||||
return !isServiceSet() || !medtronicService.isInitialized();
|
||||
}
|
||||
|
@ -368,7 +367,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
}
|
||||
|
||||
|
||||
public void resetStatusState() {
|
||||
void resetStatusState() {
|
||||
firstRun = true;
|
||||
isRefresh = true;
|
||||
}
|
||||
|
@ -411,40 +410,44 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
|
||||
|
||||
Set<MedtronicStatusRefreshType> refreshTypesNeededToReschedule = new HashSet<>();
|
||||
|
||||
// execute
|
||||
for (Map.Entry<MedtronicStatusRefreshType, Long> refreshType : statusRefresh.entrySet()) {
|
||||
if (statusRefresh != null) {
|
||||
|
||||
if (refreshType.getValue() > 0 && System.currentTimeMillis() > refreshType.getValue()) {
|
||||
Set<MedtronicStatusRefreshType> refreshTypesNeededToReschedule = new HashSet<>();
|
||||
|
||||
switch (refreshType.getKey()) {
|
||||
case PumpHistory: {
|
||||
readPumpHistory();
|
||||
for (Map.Entry<MedtronicStatusRefreshType, Long> refreshType : statusRefresh.entrySet()) {
|
||||
|
||||
if (refreshType.getValue() > 0 && System.currentTimeMillis() > refreshType.getValue()) {
|
||||
|
||||
switch (refreshType.getKey()) {
|
||||
case PumpHistory: {
|
||||
readPumpHistory();
|
||||
}
|
||||
break;
|
||||
|
||||
case PumpTime:
|
||||
case BatteryStatus:
|
||||
case RemainingInsulin: {
|
||||
medtronicUIComm.executeCommand(refreshType.getKey().getCommandType());
|
||||
refreshTypesNeededToReschedule.add(refreshType.getKey());
|
||||
resetTime = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case Configuration: {
|
||||
medtronicUIComm.executeCommand(refreshType.getKey().getCommandType());
|
||||
resetTime = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case PumpTime:
|
||||
case BatteryStatus:
|
||||
case RemainingInsulin: {
|
||||
medtronicUIComm.executeCommand(refreshType.getKey().getCommandType());
|
||||
refreshTypesNeededToReschedule.add(refreshType.getKey());
|
||||
resetTime = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case Configuration: {
|
||||
medtronicUIComm.executeCommand(refreshType.getKey().getCommandType());
|
||||
resetTime = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reschedule
|
||||
for (MedtronicStatusRefreshType refreshType : refreshTypesNeededToReschedule) {
|
||||
scheduleNextRefresh(refreshType);
|
||||
// reschedule
|
||||
for (MedtronicStatusRefreshType refreshType : refreshTypesNeededToReschedule) {
|
||||
scheduleNextRefresh(refreshType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (resetTime)
|
||||
|
@ -568,10 +571,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
public boolean isThisProfileSet(Profile profile) {
|
||||
LOG.debug("isThisProfileSet: basalInitalized={}", getMDTPumpStatus().basalProfileStatus);
|
||||
|
||||
if (getMDTPumpStatus().basalProfileStatus != BasalProfileStatus.ProfileOK)
|
||||
return true;
|
||||
|
||||
return isProfileSame(profile);
|
||||
return (getMDTPumpStatus().basalProfileStatus != BasalProfileStatus.ProfileOK) || isProfileSame(profile);
|
||||
}
|
||||
|
||||
|
||||
|
@ -584,7 +584,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
LOG.debug("Current Basals (h): "
|
||||
+ (basalsByHour == null ? "null" : BasalProfile.getProfilesByHourToString(basalsByHour)));
|
||||
|
||||
int index = 0;
|
||||
// int index = 0;
|
||||
|
||||
if (basalsByHour == null)
|
||||
return true; // we don't want to set profile again, unless we are sure
|
||||
|
@ -599,7 +599,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
invalid = true;
|
||||
}
|
||||
|
||||
stringBuilder.append(String.format("%.3f", basalValue.value));
|
||||
stringBuilder.append(String.format(Locale.ENGLISH, "%.3f", basalValue.value));
|
||||
stringBuilder.append(" ");
|
||||
}
|
||||
|
||||
|
@ -745,7 +745,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
}).start();
|
||||
}
|
||||
|
||||
boolean treatmentCreated = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
|
||||
|
||||
// we subtract insulin, exact amount will be visible with next remainingInsulin update.
|
||||
getMDTPumpStatus().reservoirRemainingUnits -= detailedBolusInfo.insulin;
|
||||
|
@ -753,7 +753,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
incrementStatistics(detailedBolusInfo.isSMB ? MedtronicConst.Statistics.SMBBoluses
|
||||
: MedtronicConst.Statistics.StandardBoluses);
|
||||
|
||||
if (response) {
|
||||
// if (response)
|
||||
{
|
||||
int bolusTime = (int)(detailedBolusInfo.insulin * 42.0d);
|
||||
long time = System.currentTimeMillis() + (bolusTime * 1000);
|
||||
|
||||
|
@ -762,8 +763,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
refreshCustomActionsList();
|
||||
}
|
||||
|
||||
return new PumpEnactResult().success(response) //
|
||||
.enacted(response) //
|
||||
return new PumpEnactResult().success(true) //
|
||||
.enacted(true) //
|
||||
.bolusDelivered(detailedBolusInfo.insulin) //
|
||||
.carbsDelivered(detailedBolusInfo.carbs);
|
||||
|
||||
|
@ -930,13 +931,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
finishAction("TBR");
|
||||
|
||||
return new PumpEnactResult().success(response).enacted(response) //
|
||||
return new PumpEnactResult().success(true).enacted(true) //
|
||||
.absolute(absoluteRate).duration(durationInMinutes);
|
||||
|
||||
} else {
|
||||
finishAction("TBR");
|
||||
|
||||
return new PumpEnactResult().success(response).enacted(response) //
|
||||
return new PumpEnactResult().success(false).enacted(false) //
|
||||
.comment(MainApp.gs(R.string.medtronic_cmd_tbr_could_not_be_delivered));
|
||||
}
|
||||
|
||||
|
@ -993,6 +994,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
medtronicHistoryData.processNewHistoryData();
|
||||
|
||||
this.medtronicHistoryData.finalizeNewHistoryRecords();
|
||||
// this.medtronicHistoryData.setLastHistoryRecordTime(this.lastPumpHistoryEntry.atechDateTime);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1046,7 +1048,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
LOG.debug(getLogPrefix() + "readPumpHistoryLogic(): lastPumpHistoryEntry: not null - {}",
|
||||
gsonInstancePretty.toJson(lastPumpHistoryEntry));
|
||||
medtronicHistoryData.setIsInInit(false);
|
||||
medtronicHistoryData.setLastHistoryRecordTime(null);
|
||||
// medtronicHistoryData.setLastHistoryRecordTime(lastPumpHistoryEntry.atechDateTime);
|
||||
|
||||
// targetDate = lastPumpHistoryEntry.atechDateTime;
|
||||
}
|
||||
|
@ -1136,7 +1138,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
private enum StatusRefreshAction {
|
||||
Add, //
|
||||
GetData;
|
||||
GetData
|
||||
}
|
||||
|
||||
|
||||
|
@ -1246,7 +1248,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
|
||||
|
||||
return new PumpEnactResult().success(response).enacted(response) //
|
||||
return new PumpEnactResult().success(true).enacted(true) //
|
||||
.isTempCancel(true);
|
||||
} else {
|
||||
if (isLoggingEnabled())
|
||||
|
@ -1305,8 +1307,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
LOG.info(getLogPrefix() + "Basal Profile was set: " + response);
|
||||
|
||||
if (response) {
|
||||
medtronicHistoryData.setBasalProfileChanged();
|
||||
return new PumpEnactResult().success(response).enacted(response);
|
||||
// medtronicHistoryData.setBasalProfileChanged();
|
||||
return new PumpEnactResult().success(true).enacted(true);
|
||||
} else {
|
||||
return new PumpEnactResult().success(response).enacted(response) //
|
||||
.comment(MainApp.gs(R.string.medtronic_cmd_basal_profile_could_not_be_set));
|
||||
|
@ -1326,9 +1328,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
for (BasalProfileEntry profileEntry : basalProfile.getEntries()) {
|
||||
|
||||
if (profileEntry.rate > pumpStatus.maxBasal) {
|
||||
|
||||
stringBuilder.append(profileEntry.startTime.toString("HH:mm") + "=" + profileEntry.rate);
|
||||
|
||||
stringBuilder.append(profileEntry.startTime.toString("HH:mm"));
|
||||
stringBuilder.append("=");
|
||||
stringBuilder.append(profileEntry.rate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1362,27 +1364,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
// OPERATIONS not supported by Pump or Plugin
|
||||
|
||||
// public void connect(String reason) {
|
||||
// // we don't use this.
|
||||
// // we connect to RileyLink on startup and keep connection opened, then connection to pump
|
||||
// // is established when needed.
|
||||
//
|
||||
// // TODO remove
|
||||
// LOG.debug("MedtronicPumpPlugin::connect (reason: {})", reason);
|
||||
// }
|
||||
|
||||
// public void disconnect(String reason) {
|
||||
// // see comment in connect
|
||||
// // TO DO remove
|
||||
// LOG.debug("MedtronicPumpPlugin::disconnect (reason: {})", reason);
|
||||
// }
|
||||
|
||||
// public void stopConnecting() {
|
||||
// // see comment in connect
|
||||
// // TO DO remove
|
||||
// LOG.debug("MedtronicPumpPlugin::stopConnecting");
|
||||
// }
|
||||
|
||||
private List<CustomAction> customActions = null;
|
||||
|
||||
private CustomAction customActionWakeUpAndTune = new CustomAction(R.string.medtronic_custom_action_wake_and_tune,
|
||||
|
|
|
@ -63,7 +63,7 @@ public abstract class MedtronicHistoryEntry implements MedtronicHistoryEntryInte
|
|||
/**
|
||||
* Pump id that will be used with AAPS object (time * 1000 + historyType (max is FF = 255)
|
||||
*/
|
||||
public long pumpId;
|
||||
protected Long pumpId;
|
||||
|
||||
/**
|
||||
* if history object is already linked to AAPS object (either Treatment, TempBasal or TDD (tdd's are not actually
|
||||
|
@ -238,6 +238,16 @@ public abstract class MedtronicHistoryEntry implements MedtronicHistoryEntryInte
|
|||
}
|
||||
|
||||
|
||||
public byte getRawDataByIndex(int index) {
|
||||
return rawData.get(index);
|
||||
}
|
||||
|
||||
|
||||
public int getUnsignedRawDataByIndex(int index) {
|
||||
return ByteUtil.convertUnsignedByteToInt(rawData.get(index));
|
||||
}
|
||||
|
||||
|
||||
public void setRawData(List<Byte> rawData) {
|
||||
this.rawData = rawData;
|
||||
}
|
||||
|
|
|
@ -2,12 +2,19 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.cgms;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.joda.time.LocalDateTime;
|
||||
|
||||
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
||||
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.MedtronicHistoryEntry;
|
||||
|
||||
/**
|
||||
* Created by andy on 27.03.15.
|
||||
* This file was taken from GGC - GNU Gluco Control and modified/extended for AAPS.
|
||||
*
|
||||
* Author: Andy {andy.rozman@gmail.com}
|
||||
*/
|
||||
|
||||
public class CGMSHistoryEntry extends MedtronicHistoryEntry {
|
||||
|
||||
private CGMSHistoryEntryType entryType;
|
||||
|
@ -63,10 +70,22 @@ public class CGMSHistoryEntry extends MedtronicHistoryEntry {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getToStringStart() {
|
||||
return "CGMSHistoryEntry [type=" + entryType.name() + " [" + getOpCode() + ", 0x"
|
||||
+ ByteUtil.getCorrectHexValue(getOpCode()) + "]";
|
||||
public boolean hasTimeStamp() {
|
||||
return (this.entryType.hasDate());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getToStringStart() {
|
||||
|
||||
return "CGMSHistoryEntry [type=" + StringUtils.rightPad(entryType.name(), 18) + " ["
|
||||
+ StringUtils.leftPad("" + getOpCode(), 3) + ", 0x" + ByteUtil.getCorrectHexValue(getOpCode()) + "]";
|
||||
}
|
||||
|
||||
|
||||
public void setDateTime(LocalDateTime timeStamp, int getIndex) {
|
||||
|
||||
setAtechDateTime(DateTimeUtil.toATechDate(timeStamp.plusMinutes(getIndex * 5)));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,62 +4,31 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Application: GGC - GNU Gluco Control
|
||||
* Plug-in: GGC PlugIn Base (base class for all plugins)
|
||||
* <p>
|
||||
* See AUTHORS for copyright information.
|
||||
* <p>
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
|
||||
* version.
|
||||
* <p>
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
|
||||
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
* <p>
|
||||
* Filename: PumpHistoryEntryType Description: Pump History Entry Type.
|
||||
* <p>
|
||||
* Data is from several sources, so in comments there are "versions". Version: v1 - default doc fromc decoding-carelink
|
||||
* v2 - Andy testing (?)
|
||||
* <p>
|
||||
* Author: Andy {andy@atech-software.com}
|
||||
* This file was taken from GGC - GNU Gluco Control and modified/extended for AAPS.
|
||||
*
|
||||
* Author: Andy {andy.rozman@gmail.com}
|
||||
*/
|
||||
|
||||
public enum CGMSHistoryEntryType {
|
||||
|
||||
None(0, "None", 1, 0, 0, DateType.None), //
|
||||
|
||||
DataEnd(0x01, "DataEnd", 1, 0, 0, DateType.None), //
|
||||
|
||||
DataEnd(0x01, "DataEnd", 1, 0, 0, DateType.PreviousTimeStamp), //
|
||||
SensorWeakSignal(0x02, "SensorWeakSignal", 1, 0, 0, DateType.PreviousTimeStamp), //
|
||||
|
||||
SensorCal(0x03, "SensorCal", 1, 0, 1, DateType.PreviousTimeStamp), //
|
||||
|
||||
SensorPacket(0x04, "SensorPacket", 1, 0, 1, DateType.PreviousTimeStamp),
|
||||
SensorError(0x05, "SensorError", 1, 0, 1, DateType.PreviousTimeStamp),
|
||||
SensorDataLow(0x06, "SensorDataLow", 1, 0, 1, DateType.PreviousTimeStamp),
|
||||
SensorDataHigh(0x07, "SensorDataHigh", 1, 0, 1, DateType.PreviousTimeStamp),
|
||||
SensorTimestamp(0x08, "SensorTimestamp", 1, 4, 0, DateType.MinuteSpecific), //
|
||||
|
||||
BatteryChange(0x0a, "BatteryChange',packet_size=4", 1, 4, 0, DateType.MinuteSpecific), //
|
||||
|
||||
BatteryChange(0x0a, "BatteryChange", 1, 4, 0, DateType.MinuteSpecific), //
|
||||
SensorStatus(0x0b, "SensorStatus", 1, 4, 0, DateType.MinuteSpecific), //
|
||||
|
||||
DateTimeChange(0x0c, "DateTimeChange", 1, 4, 0, DateType.SecondSpecific), //
|
||||
|
||||
SensorSync(0x0d, "SensorSync',packet_size=4", 1, 4, 0, DateType.MinuteSpecific), //
|
||||
|
||||
CalBGForGH(0x0e, "CalBGForGH',packet_size=5", 1, 4, 1, DateType.MinuteSpecific), //
|
||||
|
||||
SensorCalFactor(0x0f, "SensorCalFactor", 1, 4, 2, DateType.MinuteSpecific), //
|
||||
|
||||
// # 0x10: '10-Something',packet_size=7,date_type='minSpecific',op='0x10'),
|
||||
|
||||
Something10(0x10, "10-Something", 1, 4, 0, DateType.MinuteSpecific), //
|
||||
|
||||
Something19(0x13, "19-Something", 1, 0, 0, DateType.PreviousTimeStamp),
|
||||
|
||||
// V2
|
||||
Something05(0x05, "05-Something", 1, 0, 0, DateType.PreviousTimeStamp),
|
||||
|
||||
GlucoseSensorData(0xFF, "GlucoseSensorData", 1, 0, 0, DateType.PreviousTimeStamp);
|
||||
;
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -13,25 +14,9 @@ import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.MedtronicH
|
|||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RecordDecodeStatus;
|
||||
|
||||
/**
|
||||
* Application: GGC - GNU Gluco Control
|
||||
* Plug-in: GGC PlugIn Base (base class for all plugins)
|
||||
* <p>
|
||||
* See AUTHORS for copyright information.
|
||||
* <p>
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
|
||||
* version.
|
||||
* <p>
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
|
||||
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
* <p>
|
||||
* Filename: MinimedCGMSHistoryDecoder Description: Decoder for CGMS history data. For now we support just data from
|
||||
* GlucoseHistory command. ISIGHistory and VCntrHistory are IGNORED for now.
|
||||
* <p>
|
||||
* Author: Andy {andy@atech-software.com}
|
||||
* This file was taken from GGC - GNU Gluco Control and modified/extended for AAPS.
|
||||
*
|
||||
* Author: Andy {andy.rozman@gmail.com}
|
||||
*/
|
||||
|
||||
public class MedtronicCGMSHistoryDecoder extends MedtronicHistoryDecoder<CGMSHistoryEntry> {
|
||||
|
@ -45,68 +30,83 @@ public class MedtronicCGMSHistoryDecoder extends MedtronicHistoryDecoder<CGMSHis
|
|||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public Class<CGMSHistoryEntry> getHistoryEntryClass() {
|
||||
// return CGMSHistoryEntry.class;
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public Class getHistoryEntryClass() {
|
||||
// return CGMSHistoryEntry.class;
|
||||
// }
|
||||
|
||||
public RecordDecodeStatus decodeRecord(CGMSHistoryEntry entryIn) {
|
||||
CGMSHistoryEntry precord = (CGMSHistoryEntry)entryIn;
|
||||
public RecordDecodeStatus decodeRecord(CGMSHistoryEntry record) {
|
||||
try {
|
||||
return decodeRecord(precord, false);
|
||||
return decodeRecord(record, false);
|
||||
} catch (Exception ex) {
|
||||
LOG.error(" Error decoding: type={}, ex={}", precord.getEntryType().name(), ex.getMessage(), ex);
|
||||
LOG.error(" Error decoding: type={}, ex={}", record.getEntryType().name(), ex.getMessage(), ex);
|
||||
return RecordDecodeStatus.Error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public RecordDecodeStatus decodeRecord(CGMSHistoryEntry entry, boolean x) {
|
||||
// FIXME
|
||||
// TODO
|
||||
// CGMSHistoryEntry entry = (CGMSHistoryEntry) entryIn;
|
||||
|
||||
if (entry.getDateTimeLength() > 0) {
|
||||
Long dt = parseDate(entry);
|
||||
System.out.println("DT: " + dt);
|
||||
parseDate(entry);
|
||||
}
|
||||
|
||||
// LOG.debug("decodeRecord: type={}", entry.getEntryType());
|
||||
switch (entry.getEntryType()) {
|
||||
|
||||
switch ((CGMSHistoryEntryType)entry.getEntryType()) {
|
||||
case SensorPacket:
|
||||
decodeSensorPacket(entry);
|
||||
break;
|
||||
|
||||
case SensorWeakSignal:
|
||||
case SensorError:
|
||||
decodeSensorError(entry);
|
||||
break;
|
||||
case SensorCal:
|
||||
|
||||
case SensorDataLow:
|
||||
decodeDataHighLow(entry, 40);
|
||||
break;
|
||||
|
||||
case SensorDataHigh:
|
||||
decodeDataHighLow(entry, 400);
|
||||
break;
|
||||
|
||||
case SensorTimestamp:
|
||||
decodeSensorTimestamp(entry);
|
||||
break;
|
||||
case BatteryChange:
|
||||
|
||||
case SensorCal:
|
||||
decodeSensorCal(entry);
|
||||
break;
|
||||
|
||||
case SensorCalFactor:
|
||||
decodeSensorCalFactor(entry);
|
||||
break;
|
||||
|
||||
case SensorSync:
|
||||
decodeSensorSync(entry);
|
||||
break;
|
||||
|
||||
case SensorStatus:
|
||||
decodeSensorStatus(entry);
|
||||
break;
|
||||
|
||||
case CalBGForGH:
|
||||
decodeCalBGForGH(entry);
|
||||
break;
|
||||
|
||||
case GlucoseSensorData:
|
||||
decodeGlucoseSensorData(entry);
|
||||
break;
|
||||
|
||||
// just timestamp
|
||||
case BatteryChange:
|
||||
case Something10:
|
||||
case DateTimeChange:
|
||||
break;
|
||||
case SensorSync:
|
||||
break;
|
||||
case CalBGForGH:
|
||||
break;
|
||||
case SensorCalFactor:
|
||||
LOG.debug("{}", entry.toString());
|
||||
break;
|
||||
case Something10:
|
||||
break;
|
||||
|
||||
// just relative timestamp
|
||||
case Something19:
|
||||
case DataEnd:
|
||||
case SensorWeakSignal:
|
||||
break;
|
||||
|
||||
case None:
|
||||
case DataEnd:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return RecordDecodeStatus.NotSupported;
|
||||
|
@ -126,14 +126,14 @@ public class MedtronicCGMSHistoryDecoder extends MedtronicHistoryDecoder<CGMSHis
|
|||
LOG.debug("createRecords not implemented... WIP");
|
||||
// return listRecords;
|
||||
|
||||
List<Byte> dataClear = reverseList(dataClearInput);
|
||||
List<Byte> dataClear = reverseList(dataClearInput, Byte.class);
|
||||
|
||||
System.out.println("Reversed:" + ByteUtil.getHex(ByteUtil.getByteArrayFromList(dataClear)));
|
||||
|
||||
prepareStatistics();
|
||||
|
||||
int counter = 0;
|
||||
int record = 0;
|
||||
// int record = 0;
|
||||
|
||||
List<CGMSHistoryEntry> outList = new ArrayList<CGMSHistoryEntry>();
|
||||
|
||||
|
@ -151,22 +151,18 @@ public class MedtronicCGMSHistoryDecoder extends MedtronicHistoryDecoder<CGMSHis
|
|||
|
||||
if (entryType == CGMSHistoryEntryType.None) {
|
||||
this.unknownOpCodes.put(opCode, opCode);
|
||||
// System.out.println("Unknown code: " + opCode);
|
||||
LOG.warn("GlucoseHistoryEntry with unknown code: " + opCode);
|
||||
|
||||
CGMSHistoryEntry pe = new CGMSHistoryEntry();
|
||||
pe.setEntryType(CGMSHistoryEntryType.None);
|
||||
pe.setOpCode(opCode);
|
||||
|
||||
// List<Byte> listRawData = new ArrayList<Byte>();
|
||||
// listRawData.add((byte) opCode);
|
||||
|
||||
// pe.setOpCode(opCode);
|
||||
pe.setData(Arrays.asList((byte)opCode), false);
|
||||
|
||||
// System.out.println("Record: " + pe);
|
||||
|
||||
outList.add(pe);
|
||||
} else {
|
||||
// System.out.println("OpCode: " + opCode);
|
||||
|
||||
List<Byte> listRawData = new ArrayList<Byte>();
|
||||
listRawData.add((byte)opCode);
|
||||
|
||||
|
@ -189,59 +185,47 @@ public class MedtronicCGMSHistoryDecoder extends MedtronicHistoryDecoder<CGMSHis
|
|||
CGMSHistoryEntry pe = new CGMSHistoryEntry();
|
||||
pe.setEntryType(CGMSHistoryEntryType.GlucoseSensorData);
|
||||
|
||||
// List<Byte> listRawData = new ArrayList<Byte>();
|
||||
// listRawData.add((byte) opCode);
|
||||
|
||||
// pe.setOpCode(opCode);
|
||||
pe.setData(Arrays.asList((byte)opCode), false);
|
||||
|
||||
// System.out.println("Record: " + pe);
|
||||
|
||||
outList.add(pe);
|
||||
}
|
||||
|
||||
} while (counter < dataClear.size());
|
||||
|
||||
int i = outList.size() - 1;
|
||||
List<CGMSHistoryEntry> reversedOutList = reverseList(outList, CGMSHistoryEntry.class);
|
||||
|
||||
for (; i >= 0; i--) {
|
||||
// CGMSHistoryEntryType type = (CGMSHistoryEntryType) outList.get(i).getDateLength();
|
||||
Long timeStamp = null;
|
||||
LocalDateTime dateTime = null;
|
||||
int getIndex = 0;
|
||||
|
||||
if (outList.get(i).getDateLength() > 0) {
|
||||
System.out.println("Recordccc2: " + outList.get(i));
|
||||
for (CGMSHistoryEntry entry : reversedOutList) {
|
||||
|
||||
decodeRecord(outList.get(i));
|
||||
// 2015-04-11T14:02:00
|
||||
decodeRecord(entry);
|
||||
|
||||
break;
|
||||
if (entry.hasTimeStamp()) {
|
||||
timeStamp = entry.atechDateTime;
|
||||
dateTime = DateTimeUtil.toLocalDateTime(timeStamp);
|
||||
getIndex = 0;
|
||||
} else if (entry.getEntryType() == CGMSHistoryEntryType.GlucoseSensorData) {
|
||||
getIndex++;
|
||||
if (dateTime != null)
|
||||
entry.setDateTime(dateTime, getIndex);
|
||||
} else {
|
||||
if (dateTime != null)
|
||||
entry.setDateTime(dateTime, getIndex);
|
||||
}
|
||||
|
||||
// System.out.println("Record2: " + outList.get(i));
|
||||
|
||||
LOG.debug("Record: {}", entry);
|
||||
}
|
||||
|
||||
// System.exit(1);
|
||||
|
||||
// FIXME
|
||||
for (; i >= 0; i--) {
|
||||
// System.out.println("Record2: " + outList.get(i));
|
||||
|
||||
CGMSHistoryEntry che = (CGMSHistoryEntry)outList.get(i);
|
||||
|
||||
parseDate(che);
|
||||
|
||||
System.out.println("Record2: " + outList.get(i));
|
||||
|
||||
}
|
||||
|
||||
return outList;
|
||||
return reversedOutList;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private List<Byte> reverseList(List<Byte> dataClearInput) {
|
||||
private <E extends Object> List<E> reverseList(List<E> dataClearInput, Class<E> clazz) {
|
||||
|
||||
List<Byte> outList = new ArrayList<Byte>();
|
||||
List<E> outList = new ArrayList<E>();
|
||||
|
||||
for (int i = dataClearInput.size() - 1; i > 0; i--) {
|
||||
outList.add(dataClearInput.get(i));
|
||||
|
@ -302,11 +286,17 @@ public class MedtronicCGMSHistoryDecoder extends MedtronicHistoryDecoder<CGMSHis
|
|||
|
||||
|
||||
private Long parseDate(CGMSHistoryEntry entry) {
|
||||
if (entry.getEntryType().hasDate())
|
||||
|
||||
// System.out.println("parseDate [entryType=" + entry.getEntryType() + ",hasDate="
|
||||
// + entry.getEntryType().hasDate() + "]");
|
||||
|
||||
if (!entry.getEntryType().hasDate())
|
||||
return null;
|
||||
|
||||
byte data[] = entry.getDatetime();
|
||||
|
||||
// System.out.println("parseDate: " + data);
|
||||
|
||||
// def parse_date (data, unmask=False, strict=False,
|
||||
// minute_specific=False):
|
||||
// """
|
||||
|
@ -340,10 +330,14 @@ public class MedtronicCGMSHistoryDecoder extends MedtronicHistoryDecoder<CGMSHis
|
|||
// parseHours(data[2]), parseMinutes(data[1]), 0,
|
||||
// ATechDateType.DateAndTimeSec);
|
||||
|
||||
entry.atechDateTime = DateTimeUtil.toATechDate(parseYear(data[3]), parseMonths(data[0], data[1]),
|
||||
Long atechDateTime = DateTimeUtil.toATechDate(parseYear(data[3]), parseMonths(data[0], data[1]),
|
||||
parseDay(data[2]), parseHours(data[0]), parseMinutes(data[1]), 0);
|
||||
|
||||
return entry.atechDateTime;
|
||||
// System.out.println("atechDateTime: " + atechDateTime);
|
||||
|
||||
entry.setAtechDateTime(atechDateTime);
|
||||
|
||||
return atechDateTime;
|
||||
|
||||
} else if (entry.getEntryType().getDateType() == CGMSHistoryEntryType.DateType.SecondSpecific) {
|
||||
LOG.warn("parseDate for SecondSpecific type is not implemented.");
|
||||
|
@ -355,6 +349,184 @@ public class MedtronicCGMSHistoryDecoder extends MedtronicHistoryDecoder<CGMSHis
|
|||
}
|
||||
|
||||
|
||||
private void decodeGlucoseSensorData(CGMSHistoryEntry entry) {
|
||||
int sgv = entry.getUnsignedRawDataByIndex(0) * 2;
|
||||
entry.addDecodedData("sgv", sgv);
|
||||
}
|
||||
|
||||
|
||||
private void decodeCalBGForGH(CGMSHistoryEntry entry) {
|
||||
|
||||
int amount = ((entry.getRawDataByIndex(3) & 0b00100000) << 3) | entry.getRawDataByIndex(5);
|
||||
//
|
||||
String originType;
|
||||
|
||||
switch (entry.getRawDataByIndex(3) >> 5 & 0b00000011) {
|
||||
case 0x00:
|
||||
originType = "rf";
|
||||
break;
|
||||
|
||||
default:
|
||||
originType = "unknown";
|
||||
|
||||
}
|
||||
|
||||
entry.addDecodedData("amount", amount);
|
||||
entry.addDecodedData("originType", originType);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void decodeSensorSync(CGMSHistoryEntry entry) {
|
||||
|
||||
String syncType;
|
||||
|
||||
switch (entry.getRawDataByIndex(3) >> 5 & 0b00000011) {
|
||||
case 0x01:
|
||||
syncType = "new";
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
syncType = "old";
|
||||
break;
|
||||
|
||||
default:
|
||||
syncType = "find";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
entry.addDecodedData("syncType", syncType);
|
||||
}
|
||||
|
||||
|
||||
private void decodeSensorStatus(CGMSHistoryEntry entry) {
|
||||
|
||||
String statusType;
|
||||
|
||||
switch (entry.getRawDataByIndex(3) >> 5 & 0b00000011) {
|
||||
case 0x00:
|
||||
statusType = "off";
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
statusType = "on";
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
statusType = "lost";
|
||||
break;
|
||||
|
||||
default:
|
||||
statusType = "unknown";
|
||||
}
|
||||
|
||||
entry.addDecodedData("statusType", statusType);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void decodeSensorCalFactor(CGMSHistoryEntry entry) {
|
||||
|
||||
double factor = (entry.getRawDataByIndex(5) << 8 | entry.getRawDataByIndex(6)) / 1000.0d;
|
||||
|
||||
entry.addDecodedData("factor", factor);
|
||||
}
|
||||
|
||||
|
||||
private void decodeSensorCal(CGMSHistoryEntry entry) {
|
||||
|
||||
String calibrationType;
|
||||
|
||||
switch (entry.getRawDataByIndex(1)) {
|
||||
case 0x00:
|
||||
calibrationType = "meter_bg_now";
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
calibrationType = "waiting";
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
calibrationType = "cal_error";
|
||||
break;
|
||||
|
||||
default:
|
||||
calibrationType = "unknown";
|
||||
}
|
||||
|
||||
entry.addDecodedData("calibrationType", calibrationType);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void decodeSensorTimestamp(CGMSHistoryEntry entry) {
|
||||
|
||||
String sensorTimestampType;
|
||||
|
||||
switch (entry.getRawDataByIndex(3) >> 5 & 0b00000011) {
|
||||
|
||||
case 0x00:
|
||||
sensorTimestampType = "LastRf";
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
sensorTimestampType = "PageEnd";
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
sensorTimestampType = "Gap";
|
||||
break;
|
||||
|
||||
default:
|
||||
sensorTimestampType = "Unknown";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
entry.addDecodedData("sensorTimestampType", sensorTimestampType);
|
||||
}
|
||||
|
||||
|
||||
private void decodeSensorPacket(CGMSHistoryEntry entry) {
|
||||
|
||||
String packetType;
|
||||
|
||||
switch (entry.getRawDataByIndex(1)) {
|
||||
case 0x02:
|
||||
packetType = "init";
|
||||
break;
|
||||
|
||||
default:
|
||||
packetType = "unknown";
|
||||
}
|
||||
|
||||
entry.addDecodedData("packetType", packetType);
|
||||
}
|
||||
|
||||
|
||||
private void decodeSensorError(CGMSHistoryEntry entry) {
|
||||
|
||||
String errorType;
|
||||
|
||||
switch (entry.getRawDataByIndex(1)) {
|
||||
case 0x01:
|
||||
errorType = "end";
|
||||
break;
|
||||
|
||||
default:
|
||||
errorType = "unknown";
|
||||
}
|
||||
|
||||
entry.addDecodedData("errorType", errorType);
|
||||
}
|
||||
|
||||
|
||||
private void decodeDataHighLow(CGMSHistoryEntry entry, int sgv) {
|
||||
entry.addDecodedData("sgv", sgv);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void runPostDecodeTasks() {
|
||||
this.showStatistics();
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -13,7 +11,6 @@ import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
|
|||
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
||||
import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.MedtronicHistoryDecoder;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.MedtronicHistoryEntry;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RecordDecodeStatus;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BolusDTO;
|
||||
|
@ -25,24 +22,9 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpBolusType;
|
|||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||
|
||||
/**
|
||||
* Application: GGC - GNU Gluco Control
|
||||
* Plug-in: GGC PlugIn Base (base class for all plugins)
|
||||
* <p>
|
||||
* See AUTHORS for copyright information.
|
||||
* <p>
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
|
||||
* version.
|
||||
* <p>
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
|
||||
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
* <p>
|
||||
* Filename: MedtronicPumpHistoryDecoder Description: Decoder for history data.
|
||||
* <p>
|
||||
* Author: Andy {andy@atech-software.com}
|
||||
* This file was taken from GGC - GNU Gluco Control and modified/extended for AAPS.
|
||||
*
|
||||
* Author: Andy {andy.rozman@gmail.com}
|
||||
*/
|
||||
|
||||
public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHistoryEntry> {
|
||||
|
@ -52,7 +34,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
|
|||
// PumpValuesWriter pumpValuesWriter = null;
|
||||
|
||||
// DataAccessPlugInBase dataAccess = DataAccessPump.getInstance();
|
||||
Map<String, BolusDTO> bolusHistory = new HashMap<>();
|
||||
// Map<String, BolusDTO> bolusHistory = new HashMap<>();
|
||||
// Temporary records for processing
|
||||
private PumpHistoryEntry tbrPreviousRecord;
|
||||
private PumpHistoryEntry changeTimeRecord;
|
||||
|
@ -63,11 +45,6 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
|
|||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public Class<PumpHistoryEntry> getHistoryEntryClass() {
|
||||
// return PumpHistoryEntry.class;
|
||||
// }
|
||||
|
||||
public List<PumpHistoryEntry> createRecords(List<Byte> dataClear) {
|
||||
prepareStatistics();
|
||||
|
||||
|
@ -207,67 +184,27 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
|
|||
}
|
||||
|
||||
|
||||
public RecordDecodeStatus decodeRecord(PumpHistoryEntry entryIn) {
|
||||
PumpHistoryEntry precord = (PumpHistoryEntry)entryIn;
|
||||
public RecordDecodeStatus decodeRecord(PumpHistoryEntry record) {
|
||||
try {
|
||||
return decodeRecord(entryIn, false);
|
||||
return decodeRecord(record, false);
|
||||
} catch (Exception ex) {
|
||||
LOG.error(" Error decoding: type={}, ex={}", precord.getEntryType().name(), ex.getMessage(), ex);
|
||||
LOG.error(" Error decoding: type={}, ex={}", record.getEntryType().name(), ex.getMessage(), ex);
|
||||
return RecordDecodeStatus.Error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public RecordDecodeStatus decodeRecord(MedtronicHistoryEntry entryIn, boolean x) {
|
||||
// FIXME
|
||||
// TODO
|
||||
PumpHistoryEntry entry = (PumpHistoryEntry)entryIn;
|
||||
public RecordDecodeStatus decodeRecord(PumpHistoryEntry entry, boolean x) {
|
||||
|
||||
if (entry.getDateTimeLength() > 0) {
|
||||
decodeDateTime(entry);
|
||||
}
|
||||
|
||||
// LOG.debug("decodeRecord: type={}", entry.getEntryType());
|
||||
// decodeDateTime(entry);
|
||||
|
||||
switch (entry.getEntryType()) {
|
||||
// not implemented
|
||||
|
||||
case DailyTotals522:
|
||||
case DailyTotals523:
|
||||
case DailyTotals515:
|
||||
case EndResultTotals:
|
||||
return decodeDailyTotals(entry); // Not supported at the moment
|
||||
|
||||
case ChangeBasalPattern:
|
||||
return RecordDecodeStatus.OK; // Not supported at the moment
|
||||
|
||||
// WORK IN PROGRESS
|
||||
|
||||
// POSSIBLY READY
|
||||
|
||||
case ChangeBasalProfile_OldProfile:
|
||||
case ChangeBasalProfile_NewProfile:
|
||||
return decodeBasalProfile(entry);
|
||||
|
||||
case BasalProfileStart:
|
||||
return decodeBasalProfileStart(entry);
|
||||
|
||||
// AAPS Implementation - Not yet done
|
||||
|
||||
// AAPS Implementation - OK entries
|
||||
case ChangeTempBasalType:
|
||||
case ChangeMaxBolus:
|
||||
case ChangeMaxBasal:
|
||||
case ClearSettings:
|
||||
case SaveSettings:
|
||||
return RecordDecodeStatus.OK;
|
||||
// AAPS events (Tbr, Bolus)
|
||||
|
||||
// AAPS alerts
|
||||
|
||||
// AAPS TDDs
|
||||
|
||||
// AAPS Implementation - Ignored entries
|
||||
case CalBGForPH:
|
||||
case ChangeRemoteId:
|
||||
|
@ -352,6 +289,19 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
|
|||
|
||||
// **** Implemented records ****
|
||||
|
||||
case DailyTotals522:
|
||||
case DailyTotals523:
|
||||
case DailyTotals515:
|
||||
case EndResultTotals:
|
||||
return decodeDailyTotals(entry);
|
||||
|
||||
case ChangeBasalProfile_OldProfile:
|
||||
case ChangeBasalProfile_NewProfile:
|
||||
return decodeBasalProfile(entry);
|
||||
|
||||
case BasalProfileStart:
|
||||
return decodeBasalProfileStart(entry);
|
||||
|
||||
case ChangeTime:
|
||||
changeTimeRecord = entry;
|
||||
return RecordDecodeStatus.OK;
|
||||
|
@ -372,10 +322,6 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
|
|||
decodeBolus(entry);
|
||||
return RecordDecodeStatus.OK;
|
||||
|
||||
// case EndResultTotals:
|
||||
// decodeEndResultTotals(entry);
|
||||
// return RecordDecodeStatus.OK;
|
||||
|
||||
case BatteryChange:
|
||||
decodeBatteryActivity(entry);
|
||||
return RecordDecodeStatus.OK;
|
||||
|
@ -385,23 +331,15 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
|
|||
return RecordDecodeStatus.OK;
|
||||
|
||||
case LowBattery:
|
||||
// this.writeData(PumpBaseType.Event, PumpEventType.BatteryLow, entry.getATechDate());
|
||||
return RecordDecodeStatus.OK;
|
||||
|
||||
case PumpSuspend:
|
||||
// this.writeData(PumpBaseType.Event, PumpEventType.BasalStop, entry.getATechDate());
|
||||
return RecordDecodeStatus.OK;
|
||||
|
||||
case PumpResume:
|
||||
// this.writeData(PumpBaseType.Event, PumpEventType.BasalRun, entry.getATechDate());
|
||||
return RecordDecodeStatus.OK;
|
||||
|
||||
case Rewind:
|
||||
// this.writeData(PumpBaseType.Event, PumpEventType.CartridgeRewind, entry.getATechDate());
|
||||
return RecordDecodeStatus.OK;
|
||||
|
||||
case NoDeliveryAlarm:
|
||||
// this.writeData(PumpBaseType.Alarm, PumpAlarms.NoDelivery, entry.getATechDate());
|
||||
case ChangeTempBasalType:
|
||||
case ChangeMaxBolus:
|
||||
case ChangeMaxBasal:
|
||||
case ClearSettings:
|
||||
case SaveSettings:
|
||||
return RecordDecodeStatus.OK;
|
||||
|
||||
case BolusWizardBolusEstimate:
|
||||
|
|
|
@ -12,24 +12,9 @@ import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
|||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.MedtronicHistoryEntry;
|
||||
|
||||
/**
|
||||
* Application: GGC - GNU Gluco Control
|
||||
* Plug-in: GGC PlugIn Base (base class for all plugins)
|
||||
* <p>
|
||||
* See AUTHORS for copyright information.
|
||||
* <p>
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
|
||||
* version.
|
||||
* <p>
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
|
||||
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
* <p>
|
||||
* Filename: PumpHistoryEntry Description: Pump History Entry.
|
||||
* <p>
|
||||
* Author: Andy {andy@atech-software.com}
|
||||
* This file was taken from GGC - GNU Gluco Control and modified/extended for AAPS.
|
||||
*
|
||||
* Author: Andy {andy.rozman@gmail.com}
|
||||
*/
|
||||
|
||||
public class PumpHistoryEntry extends MedtronicHistoryEntry {
|
||||
|
@ -165,4 +150,11 @@ public class PumpHistoryEntry extends MedtronicHistoryEntry {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public Long getPumpId() {
|
||||
setPumpId();
|
||||
|
||||
return pumpId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
|
||||
/**
|
||||
* Created by andy on 12/23/18.
|
||||
* This file was taken from GGC - GNU Gluco Control and modified/extended for AAPS.
|
||||
*
|
||||
* Author: Andy {andy.rozman@gmail.com}
|
||||
*/
|
||||
|
||||
public enum PumpHistoryEntryGroup {
|
||||
|
|
|
@ -9,27 +9,9 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceTyp
|
|||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||
|
||||
/**
|
||||
* Application: GGC - GNU Gluco Control
|
||||
* Plug-in: GGC PlugIn Base (base class for all plugins)
|
||||
* <p>
|
||||
* See AUTHORS for copyright information.
|
||||
* <p>
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
|
||||
* version.
|
||||
* <p>
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
|
||||
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
* <p>
|
||||
* Filename: PumpHistoryEntryType Description: Pump History Entry Type.
|
||||
* <p>
|
||||
* Data is from several sources, so in comments there are "versions". Version: v1 - default doc from decoding-carelink
|
||||
* v2 - nightscout code v3 - testing v4 - Andy testing (?) v5 - Loop code and another batch of testing with 512
|
||||
* <p>
|
||||
* Author: Andy {andy@atech-software.com}
|
||||
* This file was taken from GGC - GNU Gluco Control and modified/extended for AAPS.
|
||||
*
|
||||
* Author: Andy {andy.rozman@gmail.com}
|
||||
*/
|
||||
|
||||
public enum PumpHistoryEntryType // implements CodeEnum
|
||||
|
|
|
@ -33,10 +33,15 @@ public class PumpHistoryResult {
|
|||
|
||||
public PumpHistoryResult(PumpHistoryEntry searchEntry, Long targetDate) {
|
||||
if (searchEntry != null) {
|
||||
this.searchEntry = searchEntry;
|
||||
this.searchType = SearchType.LastEntry;
|
||||
LOG.debug("PumpHistoryResult. Search parameters: Last Entry: " + searchEntry.atechDateTime + " type="
|
||||
+ searchEntry.getEntryType().name());
|
||||
/*
|
||||
* this.searchEntry = searchEntry;
|
||||
* this.searchType = SearchType.LastEntry;
|
||||
* LOG.debug("PumpHistoryResult. Search parameters: Last Entry: " + searchEntry.atechDateTime + " type="
|
||||
* + searchEntry.getEntryType().name());
|
||||
*/
|
||||
this.searchDate = searchEntry.atechDateTime;
|
||||
this.searchType = SearchType.Date;
|
||||
LOG.debug("PumpHistoryResult. Search parameters: Date(with searchEntry): " + targetDate);
|
||||
} else if (targetDate != null) {
|
||||
this.searchDate = targetDate;
|
||||
this.searchType = SearchType.Date;
|
||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.medtronic.data;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -21,6 +22,9 @@ import info.nightscout.androidaps.db.DatabaseHelper;
|
|||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
import info.nightscout.androidaps.db.Source;
|
||||
import info.nightscout.androidaps.db.TDD;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.DetailedBolusInfoStorage;
|
||||
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder;
|
||||
|
@ -53,10 +57,6 @@ public class MedtronicHistoryData {
|
|||
private Long lastHistoryRecordTime;
|
||||
private boolean isInit = false;
|
||||
|
||||
private static final int OLD_HISTORY_SIZE = 50;
|
||||
|
||||
private int basalProfileChangedInternally = 0;
|
||||
|
||||
private Gson gsonPretty;
|
||||
private List<PumpHistoryEntry> fakeTBRs;
|
||||
|
||||
|
@ -76,7 +76,18 @@ public class MedtronicHistoryData {
|
|||
*/
|
||||
public void addNewHistory(PumpHistoryResult result) {
|
||||
|
||||
this.newHistory = result.getValidEntries();
|
||||
List<PumpHistoryEntry> validEntries = result.getValidEntries();
|
||||
|
||||
List<PumpHistoryEntry> newEntries = new ArrayList<>();
|
||||
|
||||
for (PumpHistoryEntry validEntry : validEntries) {
|
||||
|
||||
if (!this.allHistory.contains(validEntry)) {
|
||||
newEntries.add(validEntry);
|
||||
}
|
||||
}
|
||||
|
||||
this.newHistory = newEntries;
|
||||
|
||||
showLogs("List of history (before filtering): ", MedtronicPumpPlugin.gsonInstance.toJson(this.newHistory));
|
||||
}
|
||||
|
@ -103,7 +114,6 @@ public class MedtronicHistoryData {
|
|||
|
||||
List<PumpHistoryEntry> newHistory2 = new ArrayList<>();
|
||||
List<PumpHistoryEntry> TBRs = new ArrayList<>();
|
||||
// LocalDateTime localDateTime = new LocalDateTime();
|
||||
long atechDate = DateTimeUtil.toATechDate(new GregorianCalendar());
|
||||
|
||||
for (PumpHistoryEntry pumpHistoryEntry : newHistory) {
|
||||
|
@ -112,8 +122,6 @@ public class MedtronicHistoryData {
|
|||
|
||||
PumpHistoryEntryType type = pumpHistoryEntry.getEntryType();
|
||||
|
||||
// if (PumpHistoryEntryType.isAAPSRelevantEntry(type)) {
|
||||
|
||||
if (type == PumpHistoryEntryType.TempBasalRate || type == PumpHistoryEntryType.TempBasalDuration) {
|
||||
TBRs.add(pumpHistoryEntry);
|
||||
} else {
|
||||
|
@ -146,47 +154,49 @@ public class MedtronicHistoryData {
|
|||
}
|
||||
|
||||
|
||||
// FIXME not just 50 records, last 24 hours
|
||||
public void finalizeNewHistoryRecords() {
|
||||
|
||||
List<PumpHistoryEntry> filteredListByLastRecord = getFilteredListByLastRecord((PumpHistoryEntryType)null);
|
||||
|
||||
LOG.debug("New records: " + filteredListByLastRecord.size());
|
||||
|
||||
if (filteredListByLastRecord.size() == 0)
|
||||
if ((newHistory == null) || (newHistory.size() == 0))
|
||||
return;
|
||||
|
||||
// List<PumpHistoryEntry> outList = new ArrayList<>();
|
||||
PumpHistoryEntry pheLast = newHistory.get(0);
|
||||
|
||||
// if (allHistory.size() > OLD_HISTORY_SIZE) {
|
||||
// for (int i = 0; i < OLD_HISTORY_SIZE; i++) {
|
||||
// outList.add(allHistory.get(i));
|
||||
// }
|
||||
// } else {
|
||||
//
|
||||
// }
|
||||
|
||||
// FIXME keep 24h only
|
||||
|
||||
LOG.debug("All History records (before): " + allHistory.size());
|
||||
|
||||
for (PumpHistoryEntry pumpHistoryEntry : filteredListByLastRecord) {
|
||||
for (PumpHistoryEntry pumpHistoryEntry : newHistory) {
|
||||
|
||||
if (!this.allHistory.contains(pumpHistoryEntry)) {
|
||||
this.allHistory.add(pumpHistoryEntry);
|
||||
}
|
||||
|
||||
if (pumpHistoryEntry.isAfter(pheLast.atechDateTime)) {
|
||||
pheLast = pumpHistoryEntry;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// outList.addAll(this.allHistory);
|
||||
// outList.addAll(filteredListByLastRecord);
|
||||
//
|
||||
// this.allHistory.clear();
|
||||
//
|
||||
// this.allHistory.addAll(outList);
|
||||
//
|
||||
// this.sort(this.allHistory);
|
||||
this.setLastHistoryRecordTime(pheLast.atechDateTime);
|
||||
|
||||
LOG.debug("All History records (after): " + allHistory.size());
|
||||
LocalDateTime dt = DateTimeUtil.toLocalDateTime(pheLast.atechDateTime);
|
||||
dt = dt.minusDays(1); // we keep 24 hours
|
||||
|
||||
long dtRemove = DateTimeUtil.toATechDate(dt);
|
||||
|
||||
List<PumpHistoryEntry> removeList = new ArrayList<>();
|
||||
|
||||
for (PumpHistoryEntry pumpHistoryEntry : allHistory) {
|
||||
|
||||
if (!pumpHistoryEntry.isAfter(dtRemove)) {
|
||||
removeList.add(pumpHistoryEntry);
|
||||
}
|
||||
}
|
||||
|
||||
this.allHistory.removeAll(removeList);
|
||||
|
||||
this.sort(this.allHistory);
|
||||
|
||||
LOG.debug("All History records [afterFilterCount={}, removedItemsCount={}, newItemsCount={}]",
|
||||
allHistory.size(), removeList.size(), newHistory.size());
|
||||
|
||||
this.newHistory.clear();
|
||||
|
||||
}
|
||||
|
||||
|
@ -205,32 +215,29 @@ public class MedtronicHistoryData {
|
|||
|
||||
|
||||
private boolean isCollectionEmpty(List col) {
|
||||
|
||||
if (col == null)
|
||||
return true;
|
||||
|
||||
return col.isEmpty();
|
||||
return (col == null || col.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
// TODO This logic might not be working correctly
|
||||
public boolean isPumpSuspended() {
|
||||
|
||||
List<PumpHistoryEntry> items = getDataForSuspends(false);
|
||||
|
||||
showLogs("isPumpSuspendCheck: ", MedtronicPumpPlugin.gsonInstancePretty.toJson(items));
|
||||
showLogs("isPumpSuspended: ", MedtronicPumpPlugin.gsonInstancePretty.toJson(items));
|
||||
|
||||
if (!items.isEmpty()) {
|
||||
|
||||
PumpHistoryEntryType pumpHistoryEntryType = items.get(0).getEntryType();
|
||||
|
||||
LOG.debug("Last entry type: {}", pumpHistoryEntryType);
|
||||
|
||||
return !(pumpHistoryEntryType == PumpHistoryEntryType.TempBasalCombined || //
|
||||
boolean isSuspended = !(pumpHistoryEntryType == PumpHistoryEntryType.TempBasalCombined || //
|
||||
pumpHistoryEntryType == PumpHistoryEntryType.BasalProfileStart || //
|
||||
pumpHistoryEntryType == PumpHistoryEntryType.Bolus || //
|
||||
pumpHistoryEntryType == PumpHistoryEntryType.PumpResume || //
|
||||
pumpHistoryEntryType == PumpHistoryEntryType.Prime);
|
||||
|
||||
LOG.debug("isPumpSuspended. Last entry type={}, isSuspended={}", pumpHistoryEntryType, isSuspended);
|
||||
|
||||
return isSuspended;
|
||||
} else
|
||||
return false;
|
||||
|
||||
|
@ -306,27 +313,27 @@ public class MedtronicHistoryData {
|
|||
public void processNewHistoryData() {
|
||||
|
||||
// TDD
|
||||
List<PumpHistoryEntry> tdds = getFilteredListByLastRecord(PumpHistoryEntryType.EndResultTotals, getTDDType());
|
||||
List<PumpHistoryEntry> tdds = getFilteredItems(PumpHistoryEntryType.EndResultTotals, getTDDType());
|
||||
|
||||
LOG.debug("ProcessHistoryData: TDD [count={}, items={}]", tdds.size(), gsonPretty.toJson(tdds));
|
||||
|
||||
if (!isCollectionEmpty(tdds)) {
|
||||
//processTDDs(tdds);
|
||||
processTDDs(tdds);
|
||||
}
|
||||
|
||||
pumpTime = MedtronicUtil.getPumpTime();
|
||||
|
||||
// Bolus
|
||||
List<PumpHistoryEntry> treatments = getFilteredListByLastRecord(PumpHistoryEntryType.Bolus);
|
||||
List<PumpHistoryEntry> treatments = getFilteredItems(PumpHistoryEntryType.Bolus);
|
||||
|
||||
LOG.debug("ProcessHistoryData: Bolus [count={}, items={}]", treatments.size(), gsonPretty.toJson(treatments));
|
||||
|
||||
if (treatments.size() > 0) {
|
||||
//processBoluses(treatments);
|
||||
processBoluses(treatments);
|
||||
}
|
||||
|
||||
// TBR
|
||||
List<PumpHistoryEntry> tbrs = getFilteredListByLastRecord(PumpHistoryEntryType.TempBasalCombined);
|
||||
List<PumpHistoryEntry> tbrs = getFilteredItems(PumpHistoryEntryType.TempBasalCombined);
|
||||
|
||||
LOG.debug("ProcessHistoryData: TBRs [count={}, items={}]", tbrs.size(), gsonPretty.toJson(tbrs));
|
||||
|
||||
|
@ -403,6 +410,9 @@ public class MedtronicHistoryData {
|
|||
|
||||
filterOutAlreadyAddedEntries(boluses, treatmentsFromHistory);
|
||||
|
||||
if (boluses.isEmpty())
|
||||
return;
|
||||
|
||||
LOG.debug("Boluses (after filter): {}, FromDb={}", gsonPretty.toJson(boluses),
|
||||
gsonPretty.toJson(treatmentsFromHistory));
|
||||
|
||||
|
@ -413,7 +423,8 @@ public class MedtronicHistoryData {
|
|||
}
|
||||
} else {
|
||||
for (PumpHistoryEntry treatment : boluses) {
|
||||
Treatment treatmentDb = findTreatment2(treatment, treatmentsFromHistory);
|
||||
tryToGetByLocalTime(treatment.atechDateTime);
|
||||
Treatment treatmentDb = findTreatment(treatment, treatmentsFromHistory, dateDifference);
|
||||
LOG.debug("Add Bolus {} - (treatmentFromDb={}) ", treatment, treatmentDb);
|
||||
|
||||
addBolus(treatment, treatmentDb);
|
||||
|
@ -433,8 +444,7 @@ public class MedtronicHistoryData {
|
|||
PumpHistoryEntry selectedBolus = null;
|
||||
|
||||
for (PumpHistoryEntry bolus : boluses) {
|
||||
if (bolus.pumpId == treatment.pumpId) {
|
||||
|
||||
if (bolus.getPumpId() == treatment.pumpId) {
|
||||
selectedBolus = bolus;
|
||||
break;
|
||||
}
|
||||
|
@ -447,14 +457,12 @@ public class MedtronicHistoryData {
|
|||
}
|
||||
}
|
||||
|
||||
for (Treatment treatment : removeTreatmentsFromHistory) {
|
||||
treatmentsFromHistory.remove(treatment);
|
||||
}
|
||||
treatmentsFromHistory.removeAll(removeTreatmentsFromHistory);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Treatment findTreatment(PumpHistoryEntry treatment, List<Treatment> treatmentsFromHistory) {
|
||||
private Treatment findTreatmentOld(PumpHistoryEntry treatment, List<Treatment> treatmentsFromHistory) {
|
||||
|
||||
long proposedTime = DateTimeUtil.toMillisFromATD(treatment.atechDateTime);
|
||||
|
||||
|
@ -535,15 +543,25 @@ public class MedtronicHistoryData {
|
|||
}
|
||||
|
||||
|
||||
private Treatment findTreatment2(PumpHistoryEntry treatment, List<Treatment> treatmentsFromHistory) {
|
||||
private Treatment findTreatment(PumpHistoryEntry treatment, List<Treatment> treatmentsFromHistory,
|
||||
int dateDifference) {
|
||||
|
||||
long proposedTime = DateTimeUtil.toMillisFromATD(treatment.atechDateTime);
|
||||
|
||||
proposedTime += (this.pumpTime.timeDifference * 1000);
|
||||
|
||||
treatment.phoneDateTime = proposedTime;
|
||||
// treatment.phoneDateTime = proposedTime;
|
||||
Date proposedTimeDD = new Date(proposedTime);
|
||||
|
||||
for (int min = 0; min < 6; min++) {
|
||||
if (treatmentsFromHistory.size() == 0) {
|
||||
return null;
|
||||
} else if (treatmentsFromHistory.size() == 1) {
|
||||
Treatment treatment1 = treatmentsFromHistory.get(0);
|
||||
LocalDateTime ldt = new LocalDateTime(treatment1.date);
|
||||
return treatmentsFromHistory.get(0);
|
||||
}
|
||||
|
||||
for (int min = 0; min < 5; min++) {
|
||||
for (int sec = 0; sec < 60; sec += 10) {
|
||||
|
||||
int diff = (min * 60 * 1000) + (sec * 1000);
|
||||
|
@ -587,20 +605,30 @@ public class MedtronicHistoryData {
|
|||
|
||||
switch (bolusDTO.getBolusType()) {
|
||||
case Normal: {
|
||||
DetailedBolusInfo normalBolus = new DetailedBolusInfo();
|
||||
normalBolus.date = tryToGetByLocalTime(bolus.atechDateTime);
|
||||
normalBolus.source = Source.PUMP;
|
||||
normalBolus.insulin = bolusDTO.getDeliveredAmount();
|
||||
normalBolus.pumpId = bolus.pumpId;
|
||||
normalBolus.isValid = true;
|
||||
normalBolus.isSMB = false;
|
||||
// DetailedBolusInfo normalBolus = new DetailedBolusInfo();
|
||||
|
||||
bolus.setLinkedObject(normalBolus);
|
||||
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage
|
||||
.findDetailedBolusInfo(tryToGetByLocalTime(bolus.atechDateTime));
|
||||
if (detailedBolusInfo == null) {
|
||||
detailedBolusInfo = new DetailedBolusInfo();
|
||||
}
|
||||
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(normalBolus, true);
|
||||
detailedBolusInfo.date = tryToGetByLocalTime(bolus.atechDateTime);
|
||||
detailedBolusInfo.source = Source.PUMP;
|
||||
detailedBolusInfo.pumpId = bolus.getPumpId();
|
||||
detailedBolusInfo.insulin = bolusDTO.getDeliveredAmount();
|
||||
|
||||
LOG.debug("addBolus - Normal [date={},pumpId={}, insulin={}]", normalBolus.date,
|
||||
normalBolus.pumpId, normalBolus.insulin);
|
||||
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
|
||||
|
||||
bolus.setLinkedObject(detailedBolusInfo);
|
||||
|
||||
// bolus.setLinkedObject(normalBolus);
|
||||
|
||||
// TreatmentsPlugin.getPlugin().addToHistoryTreatment(normalBolus, false);
|
||||
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
LOG.debug("addBolus - [date={},pumpId={}, insulin={}, newRecord={}]", detailedBolusInfo.date,
|
||||
detailedBolusInfo.pumpId, detailedBolusInfo.insulin, newRecord);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -610,7 +638,7 @@ public class MedtronicHistoryData {
|
|||
extendedBolus.date = tryToGetByLocalTime(bolus.atechDateTime);
|
||||
extendedBolus.source = Source.PUMP;
|
||||
extendedBolus.insulin = bolusDTO.getDeliveredAmount();
|
||||
extendedBolus.pumpId = bolus.pumpId;
|
||||
extendedBolus.pumpId = bolus.getPumpId();
|
||||
extendedBolus.isValid = true;
|
||||
extendedBolus.durationInMinutes = bolusDTO.getDuration();
|
||||
|
||||
|
@ -624,53 +652,69 @@ public class MedtronicHistoryData {
|
|||
}
|
||||
break;
|
||||
|
||||
case Multiwave: {
|
||||
DetailedBolusInfo normalBolus = new DetailedBolusInfo();
|
||||
normalBolus.date = tryToGetByLocalTime(bolus.atechDateTime);
|
||||
normalBolus.source = Source.PUMP;
|
||||
normalBolus.insulin = bolusDTO.getImmediateAmount();
|
||||
normalBolus.pumpId = bolus.pumpId;
|
||||
normalBolus.isValid = true;
|
||||
normalBolus.isSMB = false;
|
||||
|
||||
bolus.setLinkedObject(normalBolus);
|
||||
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(normalBolus, true);
|
||||
|
||||
LOG.debug("addBolus - Multiwave-Normal [date={},pumpId={}, insulin={}]", normalBolus.date,
|
||||
normalBolus.pumpId, normalBolus.insulin);
|
||||
|
||||
ExtendedBolus extendedBolus = new ExtendedBolus();
|
||||
extendedBolus.date = tryToGetByLocalTime(bolus.atechDateTime);
|
||||
extendedBolus.source = Source.PUMP;
|
||||
extendedBolus.insulin = bolusDTO.getDeliveredAmount();
|
||||
extendedBolus.pumpId = bolus.pumpId;
|
||||
extendedBolus.isValid = true;
|
||||
extendedBolus.durationInMinutes = bolusDTO.getDuration();
|
||||
|
||||
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
|
||||
|
||||
LOG.debug("addBolus - Multiwave-Extended [date={},pumpId={}, insulin={}, duration={}]",
|
||||
extendedBolus.date, extendedBolus.pumpId, extendedBolus.insulin,
|
||||
extendedBolus.durationInMinutes);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
treatment.insulin = bolusDTO.getDeliveredAmount();
|
||||
treatment.pumpId = bolus.pumpId;
|
||||
|
||||
bolus.setLinkedObject(treatment);
|
||||
boolean old = false;
|
||||
|
||||
TreatmentsPlugin.getPlugin().getService().createOrUpdate(treatment);
|
||||
if (old) {
|
||||
treatment.insulin = bolusDTO.getDeliveredAmount();
|
||||
treatment.pumpId = bolus.getPumpId();
|
||||
treatment.source = Source.PUMP;
|
||||
|
||||
bolus.setLinkedObject(treatment);
|
||||
|
||||
TreatmentsPlugin.getPlugin().getService().createOrUpdate(treatment);
|
||||
|
||||
LOG.debug("editBolus - [date={},pumpId={}, insulin={}]", treatment.date, treatment.pumpId,
|
||||
treatment.insulin);
|
||||
|
||||
MainApp.bus().post(new EventTreatmentChange(treatment));
|
||||
} else {
|
||||
|
||||
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(treatment.date);
|
||||
if (detailedBolusInfo == null) {
|
||||
detailedBolusInfo = new DetailedBolusInfo();
|
||||
}
|
||||
|
||||
detailedBolusInfo.date = treatment.date;
|
||||
detailedBolusInfo.source = Source.PUMP;
|
||||
detailedBolusInfo.pumpId = bolus.getPumpId();
|
||||
detailedBolusInfo.insulin = bolusDTO.getDeliveredAmount();
|
||||
|
||||
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
|
||||
|
||||
bolus.setLinkedObject(detailedBolusInfo);
|
||||
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
LOG.debug("editBolus - [date={},pumpId={}, insulin={}, newRecord={}]", detailedBolusInfo.date,
|
||||
detailedBolusInfo.pumpId, detailedBolusInfo.insulin, newRecord);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private DetailedBolusInfo createTreatment(long date, double amount, long pumpId, Boolean isSmb, Treatment treatment) {
|
||||
DetailedBolusInfo normalBolus = new DetailedBolusInfo();
|
||||
normalBolus.date = date;
|
||||
|
||||
if (treatment != null) {
|
||||
normalBolus.carbs = treatment.carbs;
|
||||
normalBolus.date = treatment.date;
|
||||
}
|
||||
|
||||
normalBolus.source = Source.PUMP;
|
||||
normalBolus.insulin = amount;
|
||||
normalBolus.pumpId = pumpId;
|
||||
normalBolus.isValid = true;
|
||||
normalBolus.isSMB = isSmb == null ? false : isSmb;
|
||||
|
||||
return normalBolus;
|
||||
}
|
||||
|
||||
|
||||
// TODO needs to be implemented
|
||||
public void processTBRs(List<PumpHistoryEntry> treatments) {
|
||||
|
||||
|
@ -736,10 +780,12 @@ public class MedtronicHistoryData {
|
|||
LOG.debug("TOE. LocalTime: " + pumpTime.localDeviceTime.toString("HH:mm:ss"));
|
||||
LOG.debug("TOE. Difference(s): " + pumpTime.timeDifference);
|
||||
|
||||
ldt.plusSeconds(pumpTime.timeDifference);
|
||||
ldt = ldt.plusSeconds(pumpTime.timeDifference);
|
||||
|
||||
LOG.debug("TOE. New Time Of Entry: " + ldt.toString("HH:mm:ss"));
|
||||
|
||||
ldt.millisOfSecond().setCopy(000);
|
||||
|
||||
return ldt.toDate().getTime();
|
||||
|
||||
// return 0;
|
||||
|
@ -758,13 +804,19 @@ public class MedtronicHistoryData {
|
|||
}
|
||||
|
||||
LocalDateTime d = DateTimeUtil.toLocalDateTime(dt);
|
||||
d.minusMinutes(2);
|
||||
d.minusMinutes(5);
|
||||
|
||||
if (this.pumpTime.timeDifference < 0) {
|
||||
d.plusSeconds(this.pumpTime.timeDifference);
|
||||
}
|
||||
// } else {
|
||||
// d.minusSeconds(this.pumpTime.timeDifference);
|
||||
// }
|
||||
|
||||
Minutes minutes = Minutes.minutesBetween(d, new LocalDateTime());
|
||||
|
||||
// returns oldest time in history, with calculated time difference between pump and phone, minus 2 minutes
|
||||
|
||||
return minutes.getMinutes();
|
||||
|
||||
}
|
||||
|
@ -784,6 +836,10 @@ public class MedtronicHistoryData {
|
|||
|
||||
private PumpHistoryEntryType getTDDType() {
|
||||
|
||||
if (MedtronicUtil.getMedtronicPumpModel() == null) {
|
||||
return PumpHistoryEntryType.EndResultTotals;
|
||||
}
|
||||
|
||||
switch (MedtronicUtil.getMedtronicPumpModel()) {
|
||||
|
||||
case Medtronic_515:
|
||||
|
@ -837,23 +893,6 @@ public class MedtronicHistoryData {
|
|||
* entryType == PumpHistoryEntryType.DailyTotals523 || //
|
||||
* entryType == PumpHistoryEntryType.EndResultTotals
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean hasBasalProfileChanged_Old() {
|
||||
|
||||
List<PumpHistoryEntry> filteredItems = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile);
|
||||
|
||||
LOG.debug("Items: " + filteredItems);
|
||||
|
||||
boolean profileChanged = ((filteredItems.size() - basalProfileChangedInternally) > 0);
|
||||
|
||||
LOG.error("Profile changed:" + profileChanged);
|
||||
|
||||
this.basalProfileChangedInternally = 0;
|
||||
|
||||
return profileChanged;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean hasBasalProfileChanged() {
|
||||
|
||||
|
@ -1034,15 +1073,13 @@ public class MedtronicHistoryData {
|
|||
}
|
||||
|
||||
|
||||
public List<PumpHistoryEntry> getNewHistoryEntries() {
|
||||
return this.newHistory;
|
||||
}
|
||||
|
||||
|
||||
public void setBasalProfileChanged() {
|
||||
this.basalProfileChangedInternally++;
|
||||
}
|
||||
// public List<PumpHistoryEntry> getNewHistoryEntries() {
|
||||
// return this.newHistory;
|
||||
// }
|
||||
|
||||
// public void setBasalProfileChanged() {
|
||||
// this.basalProfileChangedInternally++;
|
||||
// }
|
||||
|
||||
private String getLogPrefix() {
|
||||
return "MedtronicHistoryData::";
|
||||
|
|
|
@ -39,7 +39,7 @@ public class DailyTotalsDTO {
|
|||
private Integer sensorCalcCount;
|
||||
private Integer sensorDataCount;
|
||||
|
||||
private Double insulinTotal;
|
||||
private Double insulinTotal = 0.0d;
|
||||
private Double insulinBasal = 0.0d;
|
||||
private Double insulinBolus = 0.0d;
|
||||
private Double insulinCarbs;
|
||||
|
@ -84,7 +84,7 @@ public class DailyTotalsDTO {
|
|||
break;
|
||||
}
|
||||
|
||||
// setDisplayable();
|
||||
setDisplayable();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package info.nightscout.androidaps.plugins.pump.medtronic.defs;
|
||||
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.CommandValueDefinitionType;
|
||||
|
||||
/**
|
||||
* Created by andy on 4/5/19.
|
||||
*/
|
||||
|
||||
public enum CommandValueDefinitionMDTType implements CommandValueDefinitionType {
|
||||
GetModel, //
|
||||
TuneUp, //
|
||||
GetProfile, //
|
||||
GetTBR, //
|
||||
;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String commandAction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
package info.nightscout.androidaps.plugins.pump.medtronic.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.pump.common.dialog.RefreshableInterface;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
|
||||
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
|
||||
|
||||
/**
|
||||
* Created by andy on 5/19/18.
|
||||
*/
|
||||
|
||||
// FIXME needs to be implemented
|
||||
@Deprecated
|
||||
public class RileyLinkStatusDeviceMedtronic 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 = RileyLinkStatusDeviceMedtronic.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) {
|
||||
RileyLinkStatusDeviceMedtronic.ViewHolder viewHolder;
|
||||
// General ListView optimization code.
|
||||
if (view == null) {
|
||||
view = mInflator.inflate(R.layout.rileylink_status_device_item, null);
|
||||
viewHolder = new RileyLinkStatusDeviceMedtronic.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 = (RileyLinkStatusDeviceMedtronic.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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -228,13 +228,21 @@ public class MedtronicPumpStatus extends PumpStatus {
|
|||
}
|
||||
}
|
||||
|
||||
maxBolus = checkParameterValue(MedtronicConst.Prefs.MaxBolus, "25.0", 25.0d);
|
||||
double maxBolusLcl = checkParameterValue(MedtronicConst.Prefs.MaxBolus, "25.0", 25.0d);
|
||||
|
||||
LOG.debug("Max Bolus from AAPS settings is " + maxBolus);
|
||||
if (maxBolus == null || !maxBolus.equals(maxBolusLcl)) {
|
||||
maxBolus = maxBolusLcl;
|
||||
|
||||
maxBasal = checkParameterValue(MedtronicConst.Prefs.MaxBasal, "35.0", 35.0d);
|
||||
LOG.debug("Max Bolus from AAPS settings is " + maxBolus);
|
||||
}
|
||||
|
||||
LOG.debug("Max Basal from AAPS settings is " + maxBasal);
|
||||
double maxBasalLcl = checkParameterValue(MedtronicConst.Prefs.MaxBasal, "35.0", 35.0d);
|
||||
|
||||
if (maxBasal == null || !maxBasal.equals(maxBasalLcl)) {
|
||||
maxBasal = maxBasalLcl;
|
||||
|
||||
LOG.debug("Max Basal from AAPS settings is " + maxBasal);
|
||||
}
|
||||
|
||||
startService();
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package info.nightscout.androidaps.plugins.treatments;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
|
@ -28,6 +28,7 @@ import info.nightscout.androidaps.utils.JsonHelper;
|
|||
|
||||
@DatabaseTable(tableName = Treatment.TABLE_TREATMENTS)
|
||||
public class Treatment implements DataPointWithLabelInterface {
|
||||
|
||||
public static final String TABLE_TREATMENTS = "Treatments";
|
||||
|
||||
@DatabaseField(id = true)
|
||||
|
@ -60,20 +61,22 @@ public class Treatment implements DataPointWithLabelInterface {
|
|||
@DatabaseField
|
||||
public String boluscalc;
|
||||
|
||||
|
||||
public Treatment() {
|
||||
}
|
||||
|
||||
|
||||
public static Treatment createFromJson(JSONObject json) throws JSONException {
|
||||
Treatment treatment = new Treatment();
|
||||
treatment.source = Source.NIGHTSCOUT;
|
||||
treatment.date = DateUtil.roundDateToSec(JsonHelper.safeGetLong(json, "mills"));
|
||||
if (treatment.date == 0L)
|
||||
return null;
|
||||
treatment.carbs = JsonHelper.safeGetDouble(json,"carbs");
|
||||
treatment.insulin = JsonHelper.safeGetDouble(json,"insulin");
|
||||
treatment.carbs = JsonHelper.safeGetDouble(json, "carbs");
|
||||
treatment.insulin = JsonHelper.safeGetDouble(json, "insulin");
|
||||
treatment.pumpId = JsonHelper.safeGetLong(json, "pumpId");
|
||||
treatment._id = json.getString("_id");
|
||||
treatment.isSMB = JsonHelper.safeGetBoolean(json,"isSMB");
|
||||
treatment.isSMB = JsonHelper.safeGetBoolean(json, "isSMB");
|
||||
if (json.has("eventType")) {
|
||||
treatment.mealBolus = !json.get("eventType").equals("Correction Bolus");
|
||||
double carbs = treatment.carbs;
|
||||
|
@ -90,20 +93,14 @@ public class Treatment implements DataPointWithLabelInterface {
|
|||
return treatment;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "Treatment{" +
|
||||
"date= " + date +
|
||||
", date= " + new Date(date).toLocaleString() +
|
||||
", isValid= " + isValid +
|
||||
", isSMB= " + isSMB +
|
||||
", _id= " + _id +
|
||||
", pumpId= " + pumpId +
|
||||
", insulin= " + insulin +
|
||||
", carbs= " + carbs +
|
||||
", mealBolus= " + mealBolus +
|
||||
"}";
|
||||
return "Treatment{" + "date= " + date + ", date= " + new Date(date).toLocaleString() + ", isValid= " + isValid
|
||||
+ ", isSMB= " + isSMB + ", _id= " + _id + ", pumpId= " + pumpId + ", insulin= " + insulin + ", carbs= "
|
||||
+ carbs + ", mealBolus= " + mealBolus + "}";
|
||||
}
|
||||
|
||||
|
||||
public boolean isDataChanging(Treatment other) {
|
||||
if (date != other.date)
|
||||
return true;
|
||||
|
@ -114,6 +111,7 @@ public class Treatment implements DataPointWithLabelInterface {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean isEqual(Treatment other) {
|
||||
if (date != other.date)
|
||||
return false;
|
||||
|
@ -132,16 +130,18 @@ public class Treatment implements DataPointWithLabelInterface {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public JSONObject getBoluscalc() {
|
||||
try {
|
||||
if (boluscalc != null)
|
||||
return new JSONObject(boluscalc);
|
||||
return new JSONObject(boluscalc);
|
||||
} catch (JSONException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* mealBolus, _id and isSMB cannot be known coming from pump. Only compare rest
|
||||
* TODO: remove debug toasts
|
||||
|
@ -159,6 +159,7 @@ public class Treatment implements DataPointWithLabelInterface {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void copyFrom(Treatment t) {
|
||||
date = t.date;
|
||||
_id = t._id;
|
||||
|
@ -167,8 +168,10 @@ public class Treatment implements DataPointWithLabelInterface {
|
|||
mealBolus = t.mealBolus;
|
||||
pumpId = t.pumpId;
|
||||
isSMB = t.isSMB;
|
||||
source = t.source;
|
||||
}
|
||||
|
||||
|
||||
public void copyBasics(Treatment t) {
|
||||
date = t.date;
|
||||
insulin = t.insulin;
|
||||
|
@ -177,7 +180,8 @@ public class Treatment implements DataPointWithLabelInterface {
|
|||
source = t.source;
|
||||
}
|
||||
|
||||
// ----------------- DataPointInterface --------------------
|
||||
|
||||
// ----------------- DataPointInterface --------------------
|
||||
@Override
|
||||
public double getX() {
|
||||
return date;
|
||||
|
@ -186,25 +190,30 @@ public class Treatment implements DataPointWithLabelInterface {
|
|||
// default when no sgv around available
|
||||
private double yValue = 0;
|
||||
|
||||
|
||||
@Override
|
||||
public double getY() {
|
||||
return isSMB ? OverviewPlugin.getPlugin().determineLowLine() : yValue;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
String label = "";
|
||||
if (insulin > 0) label += DecimalFormatter.toPumpSupportedBolus(insulin) + "U";
|
||||
if (insulin > 0)
|
||||
label += DecimalFormatter.toPumpSupportedBolus(insulin) + "U";
|
||||
if (carbs > 0)
|
||||
label += "~" + DecimalFormatter.to0Decimal(carbs) + "g";
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getDuration() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PointsWithLabelGraphSeries.Shape getShape() {
|
||||
if (isSMB)
|
||||
|
@ -213,11 +222,13 @@ public class Treatment implements DataPointWithLabelInterface {
|
|||
return PointsWithLabelGraphSeries.Shape.BOLUS;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getSize() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
if (isSMB)
|
||||
|
@ -228,12 +239,14 @@ public class Treatment implements DataPointWithLabelInterface {
|
|||
return MainApp.instance().getResources().getColor(android.R.color.holo_red_light);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setY(double y) {
|
||||
yValue = y;
|
||||
}
|
||||
|
||||
// ----------------- DataPointInterface end --------------------
|
||||
|
||||
// ----------------- DataPointInterface end --------------------
|
||||
|
||||
public Iob iobCalc(long time, double dia) {
|
||||
if (!isValid)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
android:id="@+id/constraintLayout"
|
||||
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.RileyLinkStatusDevice">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -13,7 +13,7 @@
|
|||
<ListView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/rileyLinkHistoryList"
|
||||
android:id="@+id/rileyLinkDeviceList"
|
||||
tools:layout_editor_absoluteX="8dp"
|
||||
tools:layout_editor_absoluteY="8dp" />
|
||||
</LinearLayout>
|
||||
|
|
|
@ -8,14 +8,14 @@
|
|||
|
||||
<TextView
|
||||
android:id="@+id/rileylink_device_label"
|
||||
android:layout_width="150dp"
|
||||
android:layout_width="184dp"
|
||||
android:layout_height="match_parent"
|
||||
android:text="Command"
|
||||
android:gravity="center_vertical"
|
||||
android:text="Command"
|
||||
android:textSize="12dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/rileylink_history_description"
|
||||
<Button
|
||||
android:id="@+id/rileylink_device_action"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="Description"
|
||||
|
|
Loading…
Reference in a new issue