diff --git a/app/build.gradle b/app/build.gradle index 2b9ac10ac2..38c87ca8b1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,8 +63,8 @@ android { targetSdkVersion 25 multiDexEnabled true versionCode 1500 - // dev_version: 2.0 - version "medtronic-0.7.1-SNAPSHOT" + // dev_version: 2.0i + version "medtronic-0.7" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"' @@ -170,10 +170,10 @@ dependencies { wearApp project(':wear') implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation("com.crashlytics.sdk.android:crashlytics:2.6.7@aar") { + implementation("com.crashlytics.sdk.android:crashlytics:2.9.9@aar") { transitive = true; } - implementation("com.crashlytics.sdk.android:answers:1.3.12@aar") { + implementation("com.crashlytics.sdk.android:answers:1.4.7@aar") { transitive = true; } libs "MilosKozak:danars-support-lib:master@zip" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 39e8944b14..103376faa7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -51,6 +51,10 @@ + + diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 62b54af944..2bc06add25 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -44,6 +44,8 @@ import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin; import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin; import info.nightscout.androidaps.plugins.Insulin.InsulinOrefUltraRapidActingPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.Loop.LoopPlugin; +import info.nightscout.androidaps.plugins.Maintenance.LoggerUtils; import info.nightscout.androidaps.plugins.Maintenance.MaintenancePlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; @@ -68,6 +70,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin; import info.nightscout.androidaps.plugins.PumpInsightLocal.LocalInsightPlugin; import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin; +import info.nightscout.androidaps.plugins.PumpMedtronic.MedtronicPumpPlugin; import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicConst; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.Sensitivity.SensitivityAAPSPlugin; @@ -119,6 +122,7 @@ public class MainApp extends Application { public static boolean devBranch; public static boolean engineeringMode; + @Override public void onCreate() { super.onCreate(); @@ -160,7 +164,8 @@ public class MainApp extends Application { // Register all tabs in app here pluginsList.add(OverviewPlugin.getPlugin()); pluginsList.add(IobCobCalculatorPlugin.getPlugin()); - if (Config.ACTION) pluginsList.add(ActionsFragment.getPlugin()); + if (Config.ACTION) + pluginsList.add(ActionsFragment.getPlugin()); pluginsList.add(InsulinOrefRapidActingPlugin.getPlugin()); pluginsList.add(InsulinOrefUltraRapidActingPlugin.getPlugin()); pluginsList.add(InsulinOrefFreePeakPlugin.getPlugin()); @@ -174,21 +179,32 @@ public class MainApp extends Application { if (Config.PUMPDRIVERS) pluginsList.add(DanaRSPlugin.getPlugin()); if (Config.PUMPDRIVERS && engineeringMode) pluginsList.add(LocalInsightPlugin.getInstance()); pluginsList.add(CareportalPlugin.getPlugin()); - /*if (Config.PUMPDRIVERS && engineeringMode) - pluginsList.add(InsightPlugin.getPlugin());*/ - if (Config.PUMPDRIVERS) pluginsList.add(ComboPlugin.getPlugin()); - if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); + if (Config.PUMPDRIVERS && engineeringMode) { + pluginsList.add(MedtronicPumpPlugin.getPlugin()); + } + if (Config.PUMPDRIVERS) + pluginsList.add(ComboPlugin.getPlugin()); + if (Config.MDI) + pluginsList.add(MDIPlugin.getPlugin()); pluginsList.add(VirtualPumpPlugin.getPlugin()); - if (Config.APS) pluginsList.add(LoopPlugin.getPlugin()); - if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin()); - if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin()); - if (Config.APS) pluginsList.add(OpenAPSSMBPlugin.getPlugin()); + if (Config.APS) + pluginsList.add(LoopPlugin.getPlugin()); + if (Config.APS) + pluginsList.add(OpenAPSMAPlugin.getPlugin()); + if (Config.APS) + pluginsList.add(OpenAPSAMAPlugin.getPlugin()); + if (Config.APS) + pluginsList.add(OpenAPSSMBPlugin.getPlugin()); pluginsList.add(NSProfilePlugin.getPlugin()); - if (Config.OTHERPROFILES) pluginsList.add(SimpleProfilePlugin.getPlugin()); - if (Config.OTHERPROFILES) pluginsList.add(LocalProfilePlugin.getPlugin()); + if (Config.OTHERPROFILES) + pluginsList.add(SimpleProfilePlugin.getPlugin()); + if (Config.OTHERPROFILES) + pluginsList.add(LocalProfilePlugin.getPlugin()); pluginsList.add(TreatmentsPlugin.getPlugin()); - if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin()); - if (Config.APS) pluginsList.add(ObjectivesPlugin.getPlugin()); + if (Config.SAFETY) + pluginsList.add(SafetyPlugin.getPlugin()); + if (Config.APS) + pluginsList.add(ObjectivesPlugin.getPlugin()); pluginsList.add(SourceXdripPlugin.getPlugin()); pluginsList.add(SourceNSClientPlugin.getPlugin()); pluginsList.add(SourceMM640gPlugin.getPlugin()); @@ -298,11 +314,13 @@ public class MainApp extends Application { } } + public void stopKeepAliveService() { if (keepAliveReceiver != null) KeepAliveReceiver.cancelAlarm(this); } + public static void subscribe(Object subscriber) { try { bus().register(subscriber); @@ -311,6 +329,7 @@ public class MainApp extends Application { } } + public static void unsubscribe(Object subscriber) { try { bus().unregister(subscriber); @@ -319,34 +338,42 @@ public class MainApp extends Application { } } + public static Bus bus() { return sBus; } + public static String gs(int id) { return sResources.getString(id); } + public static String gs(int id, Object... args) { return sResources.getString(id, args); } + public static String gq(@PluralsRes int id, int quantity, Object... args) { return sResources.getQuantityString(id, quantity, args); } + public static int gc(int id) { return sResources.getColor(id); } + public static MainApp instance() { return sInstance; } + public static DatabaseHelper getDbHelper() { return sDatabaseHelper; } + public static void closeDbHelper() { if (sDatabaseHelper != null) { sDatabaseHelper.close(); @@ -354,14 +381,17 @@ public class MainApp extends Application { } } + public static ConstraintChecker getConstraintChecker() { return sConstraintsChecker; } + public static ArrayList getPluginsList() { return pluginsList; } + public static ArrayList getSpecificPluginsList(PluginType type) { ArrayList newList = new ArrayList<>(); @@ -376,6 +406,7 @@ public class MainApp extends Application { return newList; } + public static ArrayList getSpecificPluginsVisibleInList(PluginType type) { ArrayList newList = new ArrayList<>(); @@ -391,6 +422,7 @@ public class MainApp extends Application { return newList; } + public static ArrayList getSpecificPluginsListByInterface(Class interfaceClass) { ArrayList newList = new ArrayList<>(); @@ -405,6 +437,7 @@ public class MainApp extends Application { return newList; } + public static ArrayList getSpecificPluginsVisibleInListByInterface(Class interfaceClass, PluginType type) { ArrayList newList = new ArrayList<>(); @@ -420,12 +453,13 @@ public class MainApp extends Application { return newList; } + @Nullable public static T getSpecificPlugin(Class pluginClass) { if (pluginsList != null) { for (PluginBase p : pluginsList) { if (pluginClass.isAssignableFrom(p.getClass())) - return (T) p; + return (T)p; } } else { log.error("pluginsList=null"); @@ -433,6 +467,7 @@ public class MainApp extends Application { return null; } + public static boolean isEngineeringModeOrRelease() { if (!Config.APS) return true; @@ -449,6 +484,7 @@ public class MainApp extends Application { return devBranch; } + @Override public void onTerminate() { if (L.isEnabled(L.CORE)) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 7564801e33..091901c18a 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -70,6 +70,7 @@ import info.nightscout.utils.ToastUtils; * direct calls to the corresponding methods (eg. resetDatabases) should be done by a central service. */ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { + private static Logger log = LoggerFactory.getLogger(L.DATABASE); public static final String DATABASE_NAME = "AndroidAPSDb"; @@ -111,12 +112,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { private int oldVersion = 0; private int newVersion = 0; + public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); onCreate(getWritableDatabase(), getConnectionSource()); //onUpgrade(getWritableDatabase(), getConnectionSource(), 1,1); } + @Override public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) { try { @@ -140,6 +143,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + @Override public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) { try { @@ -172,20 +176,24 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + @Override public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { log.info("Do nothing for downgrading..."); log.debug("oldVersion: {}, newVersion: {}", oldVersion, newVersion); } + public int getOldVersion() { return oldVersion; } + public int getNewVersion() { return newVersion; } + /** * Close the database connections and clear any cached DAOs. */ @@ -199,6 +207,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return DatabaseUtils.queryNumEntries(getReadableDatabase(), database); } + // --------------------- DB resets --------------------- public void resetDatabases() { @@ -243,6 +252,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { ); } + public void resetTempTargets() { try { TableUtils.dropTable(connectionSource, TempTarget.class, true); @@ -253,6 +263,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleTemporaryTargetChange(); } + public void resetTemporaryBasals() { try { TableUtils.dropTable(connectionSource, TemporaryBasal.class, true); @@ -265,6 +276,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleTemporaryBasalChange(); } + public void resetExtededBoluses() { try { TableUtils.dropTable(connectionSource, ExtendedBolus.class, true); @@ -276,6 +288,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleExtendedBolusChange(); } + public void resetCareportalEvents() { try { TableUtils.dropTable(connectionSource, CareportalEvent.class, true); @@ -286,6 +299,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleCareportalEventChange(); } + public void resetProfileSwitch() { try { TableUtils.dropTable(connectionSource, ProfileSwitch.class, true); @@ -296,6 +310,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleProfileSwitchChange(); } + public void resetTDDs() { try { TableUtils.dropTable(connectionSource, TDD.class, true); @@ -305,40 +320,49 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + // ------------------ getDao ------------------------------------------- private Dao getDaoTempTargets() throws SQLException { return getDao(TempTarget.class); } + private Dao getDaoBgReadings() throws SQLException { return getDao(BgReading.class); } + private Dao getDaoDanaRHistory() throws SQLException { return getDao(DanaRHistoryRecord.class); } + private Dao getDaoTDD() throws SQLException { return getDao(TDD.class); } + private Dao getDaoDbRequest() throws SQLException { return getDao(DbRequest.class); } + private Dao getDaoTemporaryBasal() throws SQLException { return getDao(TemporaryBasal.class); } + private Dao getDaoExtendedBolus() throws SQLException { return getDao(ExtendedBolus.class); } + private Dao getDaoCareportalEvents() throws SQLException { return getDao(CareportalEvent.class); } + private Dao getDaoProfileSwitch() throws SQLException { return getDao(ProfileSwitch.class); } @@ -362,7 +386,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { log.debug("Rounding " + date + " to " + rounded); return rounded; } - // ------------------- BgReading handling ----------------------- + + + // ------------------- BgReading handling ----------------------- public boolean createIfNotExists(BgReading bgReading, String from) { try { @@ -391,6 +417,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return false; } + public void update(BgReading bgReading) { bgReading.date = roundDateToSec(bgReading.date); try { @@ -400,8 +427,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + private static void scheduleBgChange(@Nullable final BgReading bgReading) { class PostRunnable implements Runnable { + public void run() { if (L.isEnabled(L.DATABASE)) log.debug("Firing EventNewBg"); @@ -419,6 +448,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } + /* * Return last BgReading from database or null if db is empty */ @@ -444,6 +474,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } + /* * Return bg reading if not old ( <9 min ) * or null if older @@ -479,6 +510,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList(); } + public List getBgreadingsDataFromTime(long start, long end, boolean ascending) { try { Dao daoBgreadings = getDaoBgReadings(); @@ -496,6 +528,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList(); } + public List getAllBgreadingsDataFromTime(long mills, boolean ascending) { try { Dao daoBgreadings = getDaoBgReadings(); @@ -513,7 +546,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList(); } - // ------------------- TDD handling ----------------------- + + // ------------------- TDD handling ----------------------- public void createOrUpdateTDD(TDD tdd) { try { Dao dao = getDaoTDD(); @@ -524,6 +558,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + public List getTDDs() { List tddList; try { @@ -574,6 +609,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + public int delete(DbRequest dbr) { try { return getDaoDbRequest().delete(dbr); @@ -583,6 +619,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return 0; } + public int deleteDbRequest(String nsClientId) { try { return getDaoDbRequest().deleteById(nsClientId); @@ -592,6 +629,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return 0; } + public void deleteDbRequestbyMongoId(String action, String id) { try { QueryBuilder queryBuilder = getDaoDbRequest().queryBuilder(); @@ -608,6 +646,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + public void deleteAllDbRequests() { try { TableUtils.clearTable(connectionSource, DbRequest.class); @@ -616,6 +655,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + public CloseableIterator getDbRequestInterator() { try { return getDaoDbRequest().closeableIterator(); @@ -625,7 +665,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - // -------------------- TREATMENT HANDLING ------------------- + + // -------------------- TREATMENT HANDLING ------------------- public static void updateEarliestDataChange(long newDate) { if (earliestDataChange == null) { @@ -637,6 +678,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + // ---------------- TempTargets handling --------------- public List getTemptargetsDataFromTime(long mills, boolean ascending) { @@ -656,6 +698,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList(); } + public boolean createOrUpdate(TempTarget tempTarget) { try { TempTarget old; @@ -714,6 +757,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return false; } + public void delete(TempTarget tempTarget) { try { getDaoTempTargets().delete(tempTarget); @@ -723,8 +767,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + private static void scheduleTemporaryTargetChange() { class PostRunnable implements Runnable { + public void run() { if (L.isEnabled(L.DATABASE)) log.debug("Firing EventTempTargetChange"); @@ -742,20 +788,21 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } - /* - { - "_id": "58795998aa86647ba4d68ce7", - "enteredBy": "", - "eventType": "Temporary Target", - "reason": "Eating Soon", - "targetTop": 80, - "targetBottom": 80, - "duration": 120, - "created_at": "2017-01-13T22:50:00.782Z", - "carbs": null, - "insulin": null -} - */ + + /* + * { + * "_id": "58795998aa86647ba4d68ce7", + * "enteredBy": "", + * "eventType": "Temporary Target", + * "reason": "Eating Soon", + * "targetTop": 80, + * "targetBottom": 80, + * "duration": 120, + * "created_at": "2017-01-13T22:50:00.782Z", + * "carbs": null, + * "insulin": null + * } + */ public void createTemptargetFromJsonIfNotExists(JSONObject trJson) { try { @@ -774,6 +821,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + public void deleteTempTargetById(String _id) { TempTarget stored = findTempTargetById(_id); if (stored != null) { @@ -783,6 +831,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + public TempTarget findTempTargetById(String _id) { try { QueryBuilder queryBuilder = getDaoTempTargets().queryBuilder(); @@ -802,6 +851,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } + // ----------------- DanaRHistory handling -------------------- public void createOrUpdate(DanaRHistoryRecord record) { @@ -818,6 +868,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + public List getDanaRHistoryRecordsByType(byte type) { List historyList; try { @@ -835,6 +886,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return historyList; } + public void updateDanaRHistoryRecordId(JSONObject trJson) { try { QueryBuilder queryBuilder = getDaoDanaRHistory().queryBuilder(); @@ -860,6 +912,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + // ------------ TemporaryBasal handling --------------- //return true if new record was created @@ -953,6 +1006,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return false; } + public void delete(TemporaryBasal tempBasal) { try { getDaoTemporaryBasal().delete(tempBasal); @@ -963,6 +1017,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleTemporaryBasalChange(); } + public List getTemporaryBasalsDataFromTime(long mills, boolean ascending) { try { List tempbasals; @@ -979,8 +1034,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList(); } + private static void scheduleTemporaryBasalChange() { class PostRunnable implements Runnable { + public void run() { if (L.isEnabled(L.DATABASE)) log.debug("Firing EventTempBasalChange"); @@ -1002,6 +1059,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } + /* { "_id": "59232e1ddd032d04218dab00", @@ -1074,6 +1132,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + public void deleteTempBasalById(String _id) { TemporaryBasal stored = findTempBasalById(_id); if (stored != null) { @@ -1085,6 +1144,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + public TemporaryBasal findTempBasalById(String _id) { try { QueryBuilder queryBuilder = null; @@ -1105,6 +1165,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } + // ------------ ExtendedBolus handling --------------- public boolean createOrUpdate(ExtendedBolus extendedBolus) { @@ -1222,6 +1283,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleExtendedBolusChange(); } + public List getExtendedBolusDataFromTime(long mills, boolean ascending) { try { List extendedBoluses; @@ -1238,6 +1300,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList(); } + public void deleteExtendedBolusById(String _id) { ExtendedBolus stored = findExtendedBolusById(_id); if (stored != null) { @@ -1249,6 +1312,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + public ExtendedBolus findExtendedBolusById(String _id) { try { QueryBuilder queryBuilder = null; @@ -1269,6 +1333,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } + /* { "_id": "5924898d577eb0880e355337", @@ -1292,8 +1357,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { createOrUpdate(extendedBolus); } + private static void scheduleExtendedBolusChange() { class PostRunnable implements Runnable { + public void run() { if (L.isEnabled(L.DATABASE)) log.debug("Firing EventExtendedBolusChange"); @@ -1327,6 +1394,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleCareportalEventChange(); } + public void delete(CareportalEvent careportalEvent) { try { getDaoCareportalEvents().delete(careportalEvent); @@ -1336,6 +1404,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleCareportalEventChange(); } + public CareportalEvent getCareportalEventFromTimestamp(long timestamp) { try { return getDaoCareportalEvents().queryForId(timestamp); @@ -1345,6 +1414,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } + @Nullable public CareportalEvent getLastCareportalEvent(String event) { try { @@ -1366,6 +1436,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } + public List getCareportalEventsFromTime(long mills, boolean ascending) { try { List careportalEvents; @@ -1383,6 +1454,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList<>(); } + public void preprocessOpenAPSOfflineEvents(List list) { OverlappingIntervals offlineEvents = new OverlappingIntervals(); for (int i = 0; i < list.size(); i++) { @@ -1393,6 +1465,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } + public List getCareportalEventsFromTime(long mills, String type, boolean ascending) { try { List careportalEvents; @@ -1410,6 +1483,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList<>(); } + public List getCareportalEvents(boolean ascending) { try { List careportalEvents; @@ -1425,6 +1499,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList<>(); } + public void deleteCareportalEventById(String _id) { try { QueryBuilder queryBuilder; @@ -1448,6 +1523,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + public void createCareportalEventFromJsonIfNotExists(JSONObject trJson) { try { QueryBuilder queryBuilder; @@ -1481,8 +1557,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + private static void scheduleCareportalEventChange() { class PostRunnable implements Runnable { + public void run() { if (L.isEnabled(L.DATABASE)) log.debug("Firing scheduleCareportalEventChange"); @@ -1500,6 +1578,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } + // ---------------- ProfileSwitch handling --------------- public List getProfileSwitchData(boolean ascending) { @@ -1518,6 +1597,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList<>(); } + public List getProfileSwitchEventsFromTime(long mills, boolean ascending) { try { Dao daoProfileSwitch = getDaoProfileSwitch(); @@ -1536,6 +1616,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList<>(); } + public boolean createOrUpdate(ProfileSwitch profileSwitch) { try { ProfileSwitch old; @@ -1597,6 +1678,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return false; } + public void delete(ProfileSwitch profileSwitch) { try { getDaoProfileSwitch().delete(profileSwitch); @@ -1606,8 +1688,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + private static void scheduleProfileSwitchChange() { class PostRunnable implements Runnable { + public void run() { if (L.isEnabled(L.DATABASE)) log.debug("Firing EventProfileSwitchChange"); @@ -1690,6 +1774,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + public void deleteProfileSwitchById(String _id) { ProfileSwitch stored = findProfileSwitchById(_id); if (stored != null) { @@ -1700,6 +1785,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } + public ProfileSwitch findProfileSwitchById(String _id) { try { QueryBuilder queryBuilder = getDaoProfileSwitch().queryBuilder(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/RileyLinkUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/RileyLinkUtil.java index 987bd682f0..804ccd46c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/RileyLinkUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/RileyLinkUtil.java @@ -131,7 +131,8 @@ public class RileyLinkUtil { } else { - return RileyLinkUtil.rileyLinkServiceData.serviceState; + return RileyLinkUtil.rileyLinkServiceData.serviceState == null ? RileyLinkServiceState.NotStarted + : RileyLinkUtil.rileyLinkServiceData.serviceState; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SendAndListen.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SendAndListen.java index 4fa86e3884..30be3a0c27 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SendAndListen.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/ble/command/SendAndListen.java @@ -55,8 +55,10 @@ public class SendAndListen extends RileyLinkCommand { @Override public byte[] getRaw() { - boolean isPacketV2 = RileyLinkUtil.getFirmwareVersion().isSameVersion( - RileyLinkFirmwareVersion.Version2AndHigher); + // If firmware version is not set (error reading version from device, shouldn't happen), + // we will default to version 2 + boolean isPacketV2 = RileyLinkUtil.getFirmwareVersion() != null ? RileyLinkUtil.getFirmwareVersion() + .isSameVersion(RileyLinkFirmwareVersion.Version2AndHigher) : true; ArrayList bytes = new ArrayList(); bytes.add(this.getCommandType().code); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/dialog/RileyLinkStatusGeneral.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/dialog/RileyLinkStatusGeneral.java index 8d2afc6880..f0664827bc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/dialog/RileyLinkStatusGeneral.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/hw/rileylink/dialog/RileyLinkStatusGeneral.java @@ -91,7 +91,7 @@ public class RileyLinkStatusGeneral extends Fragment implements RefreshableInter RileyLinkTargetDevice targetDevice = RileyLinkUtil.getTargetDevice(); - this.connectionStatus.setText(MainApp.gs(rileyLinkServiceData.serviceState.getResourceId(targetDevice))); + this.connectionStatus.setText(MainApp.gs(RileyLinkUtil.getServiceState().getResourceId(targetDevice))); this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress); this.connectionError.setText(rileyLinkServiceData.errorCode == null ? // "-" diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/utils/ByteUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/utils/ByteUtil.java index bb1496e3db..f54701482f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/utils/ByteUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/utils/ByteUtil.java @@ -395,6 +395,15 @@ public class ByteUtil { } + public static byte[] createByteArrayFromHexString(String dataFull) { + + String data = dataFull.replace(" 0x", ""); + data = data.replace("0x", ""); + + return createByteArrayFromCompactString(data, 0, data.length()); + } + + public static byte[] createByteArrayFromCompactString(String dataFull, int startIndex) { return createByteArrayFromCompactString(dataFull, startIndex, dataFull.length()); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java index 00e91ef4c5..9e20907763 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicPumpPlugin.java @@ -36,6 +36,7 @@ import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.Actions.defs.CustomAction; import info.nightscout.androidaps.plugins.Actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; @@ -76,7 +77,7 @@ import info.nightscout.utils.SP; */ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInterface { - private static final Logger LOG = LoggerFactory.getLogger(MedtronicPumpPlugin.class); + private static final Logger LOG = LoggerFactory.getLogger(L.PUMP); protected static MedtronicPumpPlugin plugin = null; private RileyLinkMedtronicService medtronicService; @@ -96,18 +97,18 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter public static Gson gsonInstance = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); public static Gson gsonInstancePretty = new GsonBuilder().excludeFieldsWithoutExposeAnnotation() - .setPrettyPrinting().create(); + .setPrettyPrinting().create(); private MedtronicPumpPlugin() { super(new PluginDescription() // - .mainType(PluginType.PUMP) // - .fragmentClass(MedtronicFragment.class.getName()) // - .pluginName(R.string.medtronic_name) // - .shortName(R.string.medtronic_name_short) // - .preferencesId(R.xml.pref_medtronic).description(R.string.description_pump_medtronic), // - PumpType.Medtronic_522_722 // we default to most basic model, correct model from config is loaded later + .mainType(PluginType.PUMP) // + .fragmentClass(MedtronicFragment.class.getName()) // + .pluginName(R.string.medtronic_name) // + .shortName(R.string.medtronic_name_short) // + .preferencesId(R.xml.pref_medtronic).description(R.string.description_pump_medtronic), // + PumpType.Medtronic_522_722 // we default to most basic model, correct model from config is loaded later ); // TODO remove this later @@ -129,7 +130,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter public void onServiceConnected(ComponentName name, IBinder service) { if (isLoggingEnabled()) LOG.debug("RileyLinkMedtronicService is connected"); - RileyLinkMedtronicService.LocalBinder mLocalBinder = (RileyLinkMedtronicService.LocalBinder)service; + RileyLinkMedtronicService.LocalBinder mLocalBinder = (RileyLinkMedtronicService.LocalBinder) service; medtronicService = mLocalBinder.getServiceInstance(); new Thread(() -> { @@ -218,7 +219,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter if (this.isInitialized) { Map statusRefresh = workWithStatusRefresh( - StatusRefreshAction.GetData, null, null); + StatusRefreshAction.GetData, null, null); if (doWeHaveAnyStatusNeededRefereshing(statusRefresh)) { ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("Scheduled Status Refresh", null); @@ -324,8 +325,8 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter RileyLinkServiceState rileyLinkServiceState = MedtronicUtil.getServiceState(); if (rileyLinkServiceState != RileyLinkServiceState.PumpConnectorReady // - && rileyLinkServiceState != RileyLinkServiceState.RileyLinkReady // - && rileyLinkServiceState != RileyLinkServiceState.TuneUpDevice) { + && rileyLinkServiceState != RileyLinkServiceState.RileyLinkReady // + && rileyLinkServiceState != RileyLinkServiceState.TuneUpDevice) { if (isLoggingEnabled()) LOG.error("RileyLink unreachable."); return false; @@ -338,7 +339,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter private void refreshAnyStatusThatNeedsToBeRefreshed() { Map statusRefresh = workWithStatusRefresh(StatusRefreshAction.GetData, null, - null); + null); if (!doWeHaveAnyStatusNeededRefereshing(statusRefresh)) { return; @@ -367,7 +368,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter case PumpHistory: { readPumpHistory(); } - break; + break; case PumpTime: case BatteryStatus: @@ -376,13 +377,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter refreshTypesNeededToReschedule.add(refreshType.getKey()); resetTime = true; } - break; + break; case Configuration: { medtronicUIComm.executeCommand(refreshType.getKey().getCommandType()); resetTime = true; } - break; + break; } } } @@ -498,9 +499,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter } FabricPrivacy.getInstance().logCustom( // - new CustomEvent("MedtronicInitializePump") // - .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) // - .putCustomAttribute("version", BuildConfig.VERSION)); + new CustomEvent("MedtronicInitializePump") // + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) // + .putCustomAttribute("version", BuildConfig.VERSION)); isInitialized = true; // this.pumpState = PumpDriverState.Initialized; @@ -525,7 +526,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter // LOG.info("isThisProfileSet: check"); LOG.info("isThisProfileSet: check [basalProfileChanged={}, basalByHourSet={}, isBasalProfileInvalid={}", - basalProfileChanged, getMDTPumpStatus().basalsByHour != null, isBasalProfileInvalid); + basalProfileChanged, getMDTPumpStatus().basalsByHour != null, isBasalProfileInvalid); if (!basalProfileChanged && getMDTPumpStatus().basalsByHour != null && !isBasalProfileInvalid) { if (isLoggingEnabled()) @@ -601,7 +602,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter if (isLoggingEnabled()) LOG.debug("Current Basals (h): " - + (basalsByHour == null ? "null" : BasalProfile.getProfilesByHourToString(basalsByHour))); + + (basalsByHour == null ? "null" : BasalProfile.getProfilesByHourToString(basalsByHour))); int index = 0; @@ -733,9 +734,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter // LOG.debug("MedtronicPumpPlugin::deliverBolus - Start delivery"); MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetBolus, - detailedBolusInfo.insulin); + detailedBolusInfo.insulin); - Boolean response = (Boolean)responseTask.returnData; + Boolean response = (Boolean) responseTask.returnData; setRefreshButtonEnabled(true); @@ -769,18 +770,18 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter getMDTPumpStatus().reservoirRemainingUnits -= detailedBolusInfo.insulin; incrementStatistics(detailedBolusInfo.isSMB ? MedtronicConst.Statistics.SMBBoluses - : MedtronicConst.Statistics.StandardBoluses); + : MedtronicConst.Statistics.StandardBoluses); return new PumpEnactResult().success(response) // - .enacted(response) // - .bolusDelivered(detailedBolusInfo.insulin) // - .carbsDelivered(detailedBolusInfo.carbs); + .enacted(response) // + .bolusDelivered(detailedBolusInfo.insulin) // + .carbsDelivered(detailedBolusInfo.carbs); } else { return new PumpEnactResult() // - .success(bolusDeliveryType == BolusDeliveryType.CancelDelivery) // - .enacted(false) // - .comment(MainApp.gs(R.string.medtronic_cmd_bolus_could_not_be_delivered)); + .success(bolusDeliveryType == BolusDeliveryType.CancelDelivery) // + .enacted(false) // + .comment(MainApp.gs(R.string.medtronic_cmd_bolus_could_not_be_delivered)); } } finally { @@ -800,13 +801,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter if (success) { return new PumpEnactResult() // - .success(true) // - .enacted(false); + .success(true) // + .enacted(false); } else { return new PumpEnactResult() // - .success(false) // - .enacted(false) // - .comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable)); + .success(false) // + .enacted(false) // + .comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable)); } } @@ -831,7 +832,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter // if false and the same rate is requested enacted=false and success=true is returned and TBR is not changed @Override public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, - boolean enforceNew) { + boolean enforceNew) { setRefreshButtonEnabled(false); @@ -840,9 +841,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter setRefreshButtonEnabled(true); return new PumpEnactResult() // - .success(false) // - .enacted(false) // - .comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable)); + .success(false) // + .enacted(false) // + .comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable)); } MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable); @@ -860,11 +861,11 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter LOG.warn(getLogPrefix() + "setTempBasalAbsolute - Could not read current TBR, canceling operation."); finishAction("TBR"); return new PumpEnactResult().success(false).enacted(false) - .comment(MainApp.gs(R.string.medtronic_cmd_cant_read_tbr)); + .comment(MainApp.gs(R.string.medtronic_cmd_cant_read_tbr)); } else { if (isLoggingEnabled()) LOG.info(getLogPrefix() + "setTempBasalAbsolute: Current Basal: duration: {} min, rate={}", - tbrCurrent.getDurationMinutes(), tbrCurrent.getInsulinRate()); + tbrCurrent.getDurationMinutes(), tbrCurrent.getInsulinRate()); } if (!enforceNew) { @@ -896,7 +897,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter MedtronicUITask responseTask2 = medtronicUIComm.executeCommand(MedtronicCommandType.CancelTBR); - Boolean response = (Boolean)responseTask2.returnData; + Boolean response = (Boolean) responseTask2.returnData; if (response) { if (isLoggingEnabled()) @@ -908,15 +909,15 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter finishAction("TBR"); return new PumpEnactResult().success(false).enacted(false) - .comment(MainApp.gs(R.string.medtronic_cmd_cant_cancel_tbr_stop_op)); + .comment(MainApp.gs(R.string.medtronic_cmd_cant_cancel_tbr_stop_op)); } } // now start new TBR MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetTemporaryBasal, - absoluteRate, durationInMinutes); + absoluteRate, durationInMinutes); - Boolean response = (Boolean)responseTask.returnData; + Boolean response = (Boolean) responseTask.returnData; if (isLoggingEnabled()) LOG.info(getLogPrefix() + "setTempBasalAbsolute - setTBR. Response: " + response); @@ -928,10 +929,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter pumpStatusLocal.tempBasalLength = durationInMinutes; TemporaryBasal tempStart = new TemporaryBasal() // - .date(System.currentTimeMillis()) // - .duration(durationInMinutes) // - .absolute(absoluteRate) // - .source(Source.USER); + .date(System.currentTimeMillis()) // + .duration(durationInMinutes) // + .absolute(absoluteRate) // + .source(Source.USER); TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStart); @@ -940,13 +941,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter finishAction("TBR"); return new PumpEnactResult().success(response).enacted(response) // - .absolute(absoluteRate).duration(durationInMinutes); + .absolute(absoluteRate).duration(durationInMinutes); } else { finishAction("TBR"); return new PumpEnactResult().success(response).enacted(response) // - .comment(MainApp.gs(R.string.medtronic_cmd_tbr_could_not_be_delivered)); + .comment(MainApp.gs(R.string.medtronic_cmd_tbr_could_not_be_delivered)); } } @@ -981,7 +982,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter } if (this.getMDTPumpStatus().basalProfileStatus != BasalProfileStatus.NotInitialized - && medtronicHistoryData.hasBasalProfileChanged()) { + && medtronicHistoryData.hasBasalProfileChanged()) { medtronicHistoryData.processLastBasalProfileChange(getMDTPumpStatus()); // this.basalProfileChanged = true; } @@ -1007,10 +1008,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter processTDDs(tdds); } - List tdds2 = medtronicHistoryData.getTDDs2(); - - // FIXME - LOG.debug("TDDs2: {}", gsonInstancePretty.toJson(tdds2)); +// List tdds2 = medtronicHistoryData.getTDDs2(); +// +// // FIXME +// LOG.debug("TDDs2: {}", gsonInstancePretty.toJson(tdds2)); List treatments = medtronicHistoryData.getTreatments(); @@ -1066,21 +1067,21 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter if (lastPumpHistoryEntryTime == 0L) { if (isLoggingEnabled()) LOG.debug(getLogPrefix() + "readPumpHistoryLogic(): lastPumpHistoryEntryTime: 0L - targetDate: " - + targetDate); + + targetDate); targetDate = timeMinus36h; } else { // LocalDateTime lastHistoryRecordTime = DateTimeUtil.toLocalDateTime(lastPumpHistoryEntryTime); if (isLoggingEnabled()) LOG.debug(getLogPrefix() + "readPumpHistoryLogic(): lastPumpHistoryEntryTime: {} - targetDate: {}", - lastPumpHistoryEntryTime, targetDate); + lastPumpHistoryEntryTime, targetDate); medtronicHistoryData.setLastHistoryRecordTime(lastPumpHistoryEntryTime); LocalDateTime lastHistoryRecordTime = DateTimeUtil.toLocalDateTime(lastPumpHistoryEntryTime); lastHistoryRecordTime = lastHistoryRecordTime.minusHours(12); // we get last 12 hours of history to - // determine pump state + // determine pump state // (we don't process that data), we process only if (timeMinus36h.isAfter(lastHistoryRecordTime)) { @@ -1095,7 +1096,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter } else { if (isLoggingEnabled()) LOG.debug(getLogPrefix() + "readPumpHistoryLogic(): lastPumpHistoryEntry: not null - {}", - gsonInstancePretty.toJson(lastPumpHistoryEntry)); + gsonInstancePretty.toJson(lastPumpHistoryEntry)); medtronicHistoryData.setIsInInit(false); medtronicHistoryData.setLastHistoryRecordTime(null); @@ -1105,11 +1106,11 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter LOG.debug("HST: Target Date: {}", targetDate); MedtronicUITask responseTask2 = medtronicUIComm.executeCommand(MedtronicCommandType.GetHistoryData, - lastPumpHistoryEntry, targetDate); + lastPumpHistoryEntry, targetDate); LOG.debug("HST: After task"); - PumpHistoryResult historyResult = (PumpHistoryResult)responseTask2.returnData; + PumpHistoryResult historyResult = (PumpHistoryResult) responseTask2.returnData; LOG.debug("HST: History Result: {}", historyResult.toString()); @@ -1125,7 +1126,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter SP.putLong(MedtronicConst.Statistics.LastPumpHistoryEntry, latestEntry.atechDateTime); LOG.debug("HST: History: valid={}, unprocessed={}", historyResult.validEntries.size(), - historyResult.unprocessedEntries.size()); + historyResult.unprocessedEntries.size()); this.medtronicHistoryData.addNewHistory(historyResult); this.medtronicHistoryData.filterNewEntries(); @@ -1173,15 +1174,15 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter workWithStatusRefresh(StatusRefreshAction.Add, refreshType, getTimeInFutureFromMinutes(min)); } - break; + break; case PumpTime: case Configuration: case PumpHistory: { workWithStatusRefresh(StatusRefreshAction.Add, refreshType, - getTimeInFutureFromMinutes(refreshType.getRefreshTime() + additionalTimeInMinutes)); + getTimeInFutureFromMinutes(refreshType.getRefreshTime() + additionalTimeInMinutes)); } - break; + break; } } @@ -1192,7 +1193,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter private synchronized Map workWithStatusRefresh(StatusRefreshAction action, - MedtronicStatusRefreshType statusRefreshType, Long time) { + MedtronicStatusRefreshType statusRefreshType, Long time) { switch (action) { @@ -1230,7 +1231,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.ReadTemporaryBasal); if (responseTask.hasData()) { - TempBasalPair tbr = (TempBasalPair)responseTask.returnData; + TempBasalPair tbr = (TempBasalPair) responseTask.returnData; // we sometimes get rate returned even if TBR is no longer running if (tbr.getDurationMinutes() == 0) { @@ -1255,9 +1256,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter setRefreshButtonEnabled(true); return new PumpEnactResult() // - .success(false) // - .enacted(false) // - .comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable)); + .success(false) // + .enacted(false) // + .comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable)); } MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable); @@ -1277,12 +1278,12 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter LOG.warn(getLogPrefix() + "cancelTempBasal - Could not read currect TBR, canceling operation."); finishAction("TBR"); return new PumpEnactResult().success(false).enacted(false) - .comment(MainApp.gs(R.string.medtronic_cmd_cant_read_tbr)); + .comment(MainApp.gs(R.string.medtronic_cmd_cant_read_tbr)); } MedtronicUITask responseTask2 = medtronicUIComm.executeCommand(MedtronicCommandType.CancelTBR); - Boolean response = (Boolean)responseTask2.returnData; + Boolean response = (Boolean) responseTask2.returnData; finishAction("TBR"); @@ -1291,20 +1292,20 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter LOG.info(getLogPrefix() + "cancelTempBasal - Cancel TBR successful."); TemporaryBasal tempBasal = new TemporaryBasal() // - .date(System.currentTimeMillis()) // - .duration(0) // - .source(Source.USER); + .date(System.currentTimeMillis()) // + .duration(0) // + .source(Source.USER); TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal); return new PumpEnactResult().success(response).enacted(response) // - .isTempCancel(true); + .isTempCancel(true); } else { if (isLoggingEnabled()) LOG.info(getLogPrefix() + "cancelTempBasal - Cancel TBR failed."); return new PumpEnactResult().success(response).enacted(response) // - .comment(MainApp.gs(R.string.medtronic_cmd_cant_cancel_tbr)); + .comment(MainApp.gs(R.string.medtronic_cmd_cant_cancel_tbr)); } } @@ -1317,9 +1318,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter // this shouldn't be needed, but let's do check if profile setting we are setting is same as current one if (isProfileSame(profile)) { return new PumpEnactResult() // - .success(true) // - .enacted(false) // - .comment(MainApp.gs(R.string.medtronic_cmd_basal_profile_not_set_is_same)); + .success(true) // + .enacted(false) // + .comment(MainApp.gs(R.string.medtronic_cmd_basal_profile_not_set_is_same)); } setRefreshButtonEnabled(false); @@ -1329,9 +1330,9 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter setRefreshButtonEnabled(true); return new PumpEnactResult() // - .success(false) // - .enacted(false) // - .comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable)); + .success(false) // + .enacted(false) // + .comment(MainApp.gs(R.string.medtronic_pump_status_pump_unreachable)); } MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable); @@ -1342,15 +1343,15 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter if (profileInvalid != null) { return new PumpEnactResult() // - .success(false) // - .enacted(false) // - .comment(MainApp.gs(R.string.medtronic_cmd_set_profile_pattern_overflow, profileInvalid)); + .success(false) // + .enacted(false) // + .comment(MainApp.gs(R.string.medtronic_cmd_set_profile_pattern_overflow, profileInvalid)); } MedtronicUITask responseTask = medtronicUIComm.executeCommand(MedtronicCommandType.SetBasalProfileSTD, - basalProfile); + basalProfile); - Boolean response = (Boolean)responseTask.returnData; + Boolean response = (Boolean) responseTask.returnData; if (isLoggingEnabled()) LOG.info(getLogPrefix() + "Basal Profile was set: " + response); @@ -1360,7 +1361,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter return new PumpEnactResult().success(response).enacted(response); } else { return new PumpEnactResult().success(response).enacted(response) // - .comment(MainApp.gs(R.string.medtronic_cmd_basal_profile_could_not_be_set)); + .comment(MainApp.gs(R.string.medtronic_cmd_basal_profile_could_not_be_set)); } } @@ -1445,7 +1446,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter this.customActions = new ArrayList<>(); CustomAction ca = new CustomAction(R.string.medtronic_custom_action_wake_and_tune, - MedtronicCustomActionType.WakeUpAndTune); + MedtronicCustomActionType.WakeUpAndTune); this.customActions.add(ca); } @@ -1456,7 +1457,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter @Override public PumpEnactResult executeCustomAction(CustomActionType customActionType) { - MedtronicCustomActionType mcat = (MedtronicCustomActionType)customActionType; + MedtronicCustomActionType mcat = (MedtronicCustomActionType) customActionType; switch (mcat) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java index fc31e48a30..067531a94f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java @@ -465,7 +465,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder { // Bolus=1.7, Fodd, Corr, Manual=1.7, // Num bOlus=1, food/corr, Food+corr, manual bolus=1 - DailyTotalsDTO totals = new DailyTotalsDTO(entry.getEntryType(), entry.getBody()); + DailyTotalsDTO totals = new DailyTotalsDTO(entry); // System.out.println("Totals:" + totals); @@ -487,6 +487,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder { // } // // } + entry.addDecodedData("Object", totals); System.out.println("" + totals.toString()); @@ -563,7 +564,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder { } - private String getFormattedValue(float value, int decimals) { + public static String getFormattedValue(float value, int decimals) { return String.format(Locale.ENGLISH, "%." + decimals + "f", value); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntryType.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntryType.java index bf9de101aa..dd301ce0e8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntryType.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryEntryType.java @@ -144,17 +144,15 @@ public enum PumpHistoryEntryType // implements CodeEnum BolusReminder(0x69, "Bolus Reminder", PumpHistoryEntryGroup.Configuration, 2, 5, 0), // Ian69 DeleteAlarmClockTime(0x6a, "Delete Alarm Clock Time", PumpHistoryEntryGroup.Configuration, 2, 5, 7), // 14 - DailyTotals515(0x6c, "Daily Totals (515)", PumpHistoryEntryGroup.Statistic, 0, 0, 36), // - DailyTotals522(0x6d, "Daily Totals (522)", PumpHistoryEntryGroup.Statistic, 1, 2, 41), // // hack1(0x6d, "hack1", - // 46, - // 5, 0), // 1,2,41 + DailyTotals515(0x6c, "Daily Totals (515)", PumpHistoryEntryGroup.Statistic, 1, 2, 33), // v4: 0,0,36. v5: 1,2,33 + DailyTotals522(0x6d, "Daily Totals (522)", PumpHistoryEntryGroup.Statistic, 1, 2, 41), // DailyTotals523(0x6e, "Daily Totals (523)", PumpHistoryEntryGroup.Statistic, 1, 2, 49), // 1102014-03-17T00:00:00 - ChangeCarbUnits((byte)0x6f, "Change Carb Units", PumpHistoryEntryGroup.Configuration), // - /**/EventUnknown_MM522_0x70((byte)0x70, "Unknown Event 0x70", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // + ChangeCarbUnits((byte) 0x6f, "Change Carb Units", PumpHistoryEntryGroup.Configuration), // + /**/EventUnknown_MM522_0x70((byte) 0x70, "Unknown Event 0x70", PumpHistoryEntryGroup.Unknown, 2, 5, 1), // BasalProfileStart(0x7b, "Basal Profile Start", PumpHistoryEntryGroup.Basal, 2, 5, 3), // // 722 - ChangeWatchdogEnable((byte)0x7c, "Change Watchdog Enable", PumpHistoryEntryGroup.Configuration), // - ChangeOtherDeviceID((byte)0x7d, "Change Other Device ID", PumpHistoryEntryGroup.Configuration, 2, 5, 30), // + ChangeWatchdogEnable((byte) 0x7c, "Change Watchdog Enable", PumpHistoryEntryGroup.Configuration), // + ChangeOtherDeviceID((byte) 0x7d, "Change Other Device ID", PumpHistoryEntryGroup.Configuration, 2, 5, 30), // ChangeWatchdogMarriageProfile(0x81, "Change Watchdog Marriage Profile", PumpHistoryEntryGroup.Configuration, 2, 5, 5), // 12 DeleteOtherDeviceID(0x82, "Delete Other Device ID", PumpHistoryEntryGroup.Configuration, 2, 5, 5), // @@ -184,6 +182,7 @@ public enum PumpHistoryEntryType // implements CodeEnum UnknownBasePacket(0xff, "Unknown Base Packet", PumpHistoryEntryGroup.Unknown); private static Map opCodeMap = new HashMap(); + private static PumpHistoryEntryType tddType; static { for (PumpHistoryEntryType type : values()) { @@ -206,6 +205,7 @@ public enum PumpHistoryEntryType // implements CodeEnum private List specialRulesBody; private boolean hasSpecialRules = false; private PumpHistoryEntryGroup group = PumpHistoryEntryGroup.Unknown; + private static Object TDDType; PumpHistoryEntryType(int opCode, String name, PumpHistoryEntryGroup group) { @@ -239,10 +239,10 @@ public enum PumpHistoryEntryType // implements CodeEnum Bolus.addSpecialRuleHead(new SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 8)); // BolusWizardChange.addSpecialRuleBody(new SpecialRule(MedtronicDeviceType.Medtronic_522andHigher, 143)); BolusWizardChange.addSpecialRuleBody(new SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 143)); // V5: - // 522 - // has - // old - // form + // 522 + // has + // old + // form BolusWizardBolusEstimate.addSpecialRuleBody(new SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 15)); BolusReminder.addSpecialRuleBody(new SpecialRule(MedtronicDeviceType.Medtronic_523andHigher, 2)); } @@ -272,32 +272,32 @@ public enum PumpHistoryEntryType // implements CodeEnum public static boolean isAAPSRelevantEntry(PumpHistoryEntryType entryType) { return (entryType == PumpHistoryEntryType.Bolus || // Treatments - entryType == PumpHistoryEntryType.TempBasalRate || // - entryType == PumpHistoryEntryType.TempBasalDuration || // + entryType == PumpHistoryEntryType.TempBasalRate || // + entryType == PumpHistoryEntryType.TempBasalDuration || // - entryType == PumpHistoryEntryType.Prime || // Pump Status Change - entryType == PumpHistoryEntryType.PumpSuspend || // - entryType == PumpHistoryEntryType.PumpResume || // - entryType == PumpHistoryEntryType.Rewind || // - entryType == PumpHistoryEntryType.NoDeliveryAlarm || // no delivery - entryType == PumpHistoryEntryType.BasalProfileStart || // + entryType == PumpHistoryEntryType.Prime || // Pump Status Change + entryType == PumpHistoryEntryType.PumpSuspend || // + entryType == PumpHistoryEntryType.PumpResume || // + entryType == PumpHistoryEntryType.Rewind || // + entryType == PumpHistoryEntryType.NoDeliveryAlarm || // no delivery + entryType == PumpHistoryEntryType.BasalProfileStart || // - entryType == PumpHistoryEntryType.ChangeTime || // Time Change - entryType == PumpHistoryEntryType.NewTimeSet || // + entryType == PumpHistoryEntryType.ChangeTime || // Time Change + entryType == PumpHistoryEntryType.NewTimeSet || // - entryType == PumpHistoryEntryType.ChangeBasalPattern || // Configuration - entryType == PumpHistoryEntryType.ClearSettings || // - entryType == PumpHistoryEntryType.SaveSettings || // - entryType == PumpHistoryEntryType.ChangeMaxBolus || // - entryType == PumpHistoryEntryType.ChangeMaxBasal || // - entryType == PumpHistoryEntryType.ChangeTempBasalType || // + entryType == PumpHistoryEntryType.ChangeBasalPattern || // Configuration + entryType == PumpHistoryEntryType.ClearSettings || // + entryType == PumpHistoryEntryType.SaveSettings || // + entryType == PumpHistoryEntryType.ChangeMaxBolus || // + entryType == PumpHistoryEntryType.ChangeMaxBasal || // + entryType == PumpHistoryEntryType.ChangeTempBasalType || // - entryType == PumpHistoryEntryType.ChangeBasalProfile_NewProfile || // Basal profile + entryType == PumpHistoryEntryType.ChangeBasalProfile_NewProfile || // Basal profile - entryType == PumpHistoryEntryType.DailyTotals515 || // Daily Totals - entryType == PumpHistoryEntryType.DailyTotals522 || // - entryType == PumpHistoryEntryType.DailyTotals523 || // - entryType == PumpHistoryEntryType.EndResultTotals); + entryType == PumpHistoryEntryType.DailyTotals515 || // Daily Totals + entryType == PumpHistoryEntryType.DailyTotals522 || // + entryType == PumpHistoryEntryType.DailyTotals523 || // + entryType == PumpHistoryEntryType.EndResultTotals); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryResult.java index 409c45eec3..c1cbd05ace 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/PumpHistoryResult.java @@ -128,8 +128,8 @@ public class PumpHistoryResult { public String toString() { - return "PumpHistoryResult [unprocessed=" + unprocessedEntries.size() + // - ", valid=" + validEntries.size() + // + return "PumpHistoryResult [unprocessed=" + (unprocessedEntries != null ? "" + unprocessedEntries.size() : "0") + // + ", valid=" + (validEntries != null ? "" + validEntries.size() : "0") + // ", searchEntry=" + searchEntry + // ", searchDate=" + searchDate + // ", searchType=" + searchType + // diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/MedtronicHistoryData.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/MedtronicHistoryData.java index 34a6f3292f..6f867d4548 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/MedtronicHistoryData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/MedtronicHistoryData.java @@ -1,5 +1,10 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.data; +import com.google.common.base.Splitter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.ArrayList; import java.util.Collections; import java.util.GregorianCalendar; @@ -7,11 +12,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Splitter; - import info.nightscout.androidaps.plugins.PumpCommon.utils.DateTimeUtil; import info.nightscout.androidaps.plugins.PumpMedtronic.MedtronicPumpPlugin; import info.nightscout.androidaps.plugins.PumpMedtronic.comm.history.pump.MedtronicPumpHistoryDecoder; @@ -20,6 +20,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.comm.history.pump.PumpHi import info.nightscout.androidaps.plugins.PumpMedtronic.comm.history.pump.PumpHistoryResult; import info.nightscout.androidaps.plugins.PumpMedtronic.data.dto.BasalProfile; import info.nightscout.androidaps.plugins.PumpMedtronic.driver.MedtronicPumpStatus; +import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil; //import info.nightscout.androidaps.plugins.PumpMedtronic.MedtronicPumpPlugin; @@ -128,7 +129,7 @@ public class MedtronicHistoryData { // FIXME not just 50 records, last 24 hours public void finalizeNewHistoryRecords() { - List filteredListByLastRecord = getFilteredListByLastRecord((PumpHistoryEntryType)null); + List filteredListByLastRecord = getFilteredListByLastRecord((PumpHistoryEntryType) null); LOG.debug("New records: " + filteredListByLastRecord.size()); @@ -173,12 +174,12 @@ public class MedtronicHistoryData { public boolean hasRelevantConfigurationChanged() { return getStateFromFilteredList( // - PumpHistoryEntryType.ChangeBasalPattern, // - PumpHistoryEntryType.ClearSettings, // - PumpHistoryEntryType.SaveSettings, // - PumpHistoryEntryType.ChangeMaxBolus, // - PumpHistoryEntryType.ChangeMaxBasal, // - PumpHistoryEntryType.ChangeTempBasalType); + PumpHistoryEntryType.ChangeBasalPattern, // + PumpHistoryEntryType.ClearSettings, // + PumpHistoryEntryType.SaveSettings, // + PumpHistoryEntryType.ChangeMaxBolus, // + PumpHistoryEntryType.ChangeMaxBasal, // + PumpHistoryEntryType.ChangeTempBasalType); } @@ -198,13 +199,13 @@ public class MedtronicHistoryData { if (wasPumpSuspended == null) { // suspension status not known List items = getFilteredItems(PumpHistoryEntryType.Bolus, // - PumpHistoryEntryType.TempBasalCombined, // - PumpHistoryEntryType.Prime, // - PumpHistoryEntryType.PumpSuspend, // - PumpHistoryEntryType.PumpResume, // - PumpHistoryEntryType.Rewind, // - PumpHistoryEntryType.NoDeliveryAlarm, // - PumpHistoryEntryType.BasalProfileStart); + PumpHistoryEntryType.TempBasalCombined, // + PumpHistoryEntryType.Prime, // + PumpHistoryEntryType.PumpSuspend, // + PumpHistoryEntryType.PumpResume, // + PumpHistoryEntryType.Rewind, // + PumpHistoryEntryType.NoDeliveryAlarm, // + PumpHistoryEntryType.BasalProfileStart); if (items.size() == 0) return wasPumpSuspended == null ? false : wasPumpSuspended; @@ -212,20 +213,20 @@ public class MedtronicHistoryData { PumpHistoryEntry pumpHistoryEntry = items.get(0); return !(pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.TempBasalCombined || // - pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.BasalProfileStart || // - pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.Bolus || // - pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.PumpResume); + pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.BasalProfileStart || // + pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.Bolus || // + pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.PumpResume); } else { List items = getFilteredItems(PumpHistoryEntryType.Bolus, // - PumpHistoryEntryType.TempBasalCombined, // - PumpHistoryEntryType.Prime, // - PumpHistoryEntryType.PumpSuspend, // - PumpHistoryEntryType.PumpResume, // - PumpHistoryEntryType.Rewind, // - PumpHistoryEntryType.NoDeliveryAlarm, // - PumpHistoryEntryType.BasalProfileStart); + PumpHistoryEntryType.TempBasalCombined, // + PumpHistoryEntryType.Prime, // + PumpHistoryEntryType.PumpSuspend, // + PumpHistoryEntryType.PumpResume, // + PumpHistoryEntryType.Rewind, // + PumpHistoryEntryType.NoDeliveryAlarm, // + PumpHistoryEntryType.BasalProfileStart); if (wasPumpSuspended) { @@ -235,9 +236,9 @@ public class MedtronicHistoryData { PumpHistoryEntry pumpHistoryEntry = items.get(0); if (pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.TempBasalCombined || // - pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.BasalProfileStart || // - pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.Bolus || // - pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.PumpResume) + pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.BasalProfileStart || // + pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.Bolus || // + pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.PumpResume) return false; else return true; @@ -250,8 +251,8 @@ public class MedtronicHistoryData { PumpHistoryEntry pumpHistoryEntry = items.get(0); if (pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.NoDeliveryAlarm || // - pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.PumpSuspend || // - pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.Prime) + pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.PumpSuspend || // + pumpHistoryEntry.getEntryType() == PumpHistoryEntryType.Prime) return true; } @@ -266,16 +267,35 @@ public class MedtronicHistoryData { public List getTDDs() { - return getFilteredListByLastRecord(PumpHistoryEntryType.EndResultTotals); + return getFilteredListByLastRecord(getTDDType()); } - // FIXME remove - public List getTDDs2() { + private PumpHistoryEntryType getTDDType() { - return getFilteredListByLastRecord(PumpHistoryEntryType.DailyTotals515, PumpHistoryEntryType.DailyTotals522, - PumpHistoryEntryType.DailyTotals523); + + switch (MedtronicUtil.getMedtronicPumpModel()) { + + case Medtronic_515: + case Medtronic_715: + return PumpHistoryEntryType.DailyTotals515; + + + case Medtronic_522: + case Medtronic_722: + return PumpHistoryEntryType.DailyTotals522; + + case Medtronic_523_Revel: + case Medtronic_723_Revel: + case Medtronic_554_Veo: + case Medtronic_754_Veo: + return PumpHistoryEntryType.DailyTotals523; + + default: { + return PumpHistoryEntryType.EndResultTotals; + } + } } @@ -283,8 +303,8 @@ public class MedtronicHistoryData { public List getTreatments() { return getFilteredListByLastRecord( // - PumpHistoryEntryType.Bolus, // - PumpHistoryEntryType.TempBasalCombined); + PumpHistoryEntryType.Bolus, // + PumpHistoryEntryType.TempBasalCombined); } @@ -373,7 +393,7 @@ public class MedtronicHistoryData { if (newProfile != null) { LOG.debug("processLastBasalProfileChange. item found, setting new basalProfileLocally: " + newProfile); - BasalProfile basalProfile = (BasalProfile)newProfile.getDecodedData().get("Object"); + BasalProfile basalProfile = (BasalProfile) newProfile.getDecodedData().get("Object"); mdtPumpStatus.basalsByHour = basalProfile.getProfilesByHour(); } @@ -391,7 +411,7 @@ public class MedtronicHistoryData { public boolean hasPumpTimeChanged() { return getStateFromFilteredList(PumpHistoryEntryType.NewTimeSet, // - PumpHistoryEntryType.ChangeTime); + PumpHistoryEntryType.ChangeTime); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/DailyTotalsDTO.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/DailyTotalsDTO.java index d9efced0ee..e9b740677c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/DailyTotalsDTO.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/data/dto/DailyTotalsDTO.java @@ -6,12 +6,17 @@ import org.slf4j.LoggerFactory; import com.google.common.base.MoreObjects; import info.nightscout.androidaps.plugins.PumpCommon.utils.ByteUtil; -import info.nightscout.androidaps.plugins.PumpMedtronic.comm.history.pump.PumpHistoryEntryType; +import info.nightscout.androidaps.plugins.PumpCommon.utils.StringUtil; +import info.nightscout.androidaps.plugins.PumpMedtronic.comm.history.pump.PumpHistoryEntry; /** * Created by andy on 11/3/18. */ +/** + * NOTE: Decoding is only done for insulin part, everything else is pretty must left undecoded. + */ + public class DailyTotalsDTO { private static final Logger LOG = LoggerFactory.getLogger(DailyTotalsDTO.class); @@ -21,54 +26,87 @@ public class DailyTotalsDTO { // Insulin=19.8[8,9], Basal[10,11], Bolus[13,14], Carbs, // Bolus=1.7, Fodd, Corr, Manual=1.7, // Num bOlus=1, food/corr, Food+corr, manual bolus=1 - Double bgAvg; - Double bgLow; - Double bgHigh; - Integer bgCount; + private Double bgAvg; + private Double bgLow; + private Double bgHigh; + private Integer bgCount; - Double sensorAvg; - Double sensorMin; - Double sensorMax; - Integer sensorCalcCount; - Integer sensorDataCount; + private Double sensorAvg; + private Double sensorMin; + private Double sensorMax; + private Integer sensorCalcCount; + private Integer sensorDataCount; - Double insulinTotal; - Double insulinBasal; - Double insulinBolus; - Double insulinCarbs; + private Double insulinTotal; + private Double insulinBasal; + private Double insulinBolus; + private Double insulinCarbs; - Double bolusTotal; - Double bolusFood; - Double bolusFoodAndCorr; - Double bolusCorrection; - Double bolusManual; + private Double bolusTotal; + private Double bolusFood; + private Double bolusFoodAndCorr; + private Double bolusCorrection; + private Double bolusManual; - Integer bolusCount; - Integer bolusCountFoodOrCorr; + private Integer bolusCount; + private Integer bolusCountFoodOrCorr; // Integer bolusCountCorr; Integer bolusCountFoodAndCorr; Integer bolusCountManual; private Integer bolusCountFood; private Integer bolusCountCorr; + PumpHistoryEntry entry; - public DailyTotalsDTO(PumpHistoryEntryType entryType, byte[] data) { - switch (entryType) { + + public DailyTotalsDTO(PumpHistoryEntry entry) { + this.entry = entry; + + switch (entry.getEntryType()) { + case EndResultTotals: + decodeEndResultsTotals(entry); + break; case DailyTotals515: - decodeDailyTotals515(data); + decodeDailyTotals515(entry.getBody()); break; case DailyTotals522: - decodeDailyTotals522(data); + decodeDailyTotals522(entry.getBody()); break; case DailyTotals523: - decodeDailyTotals523(data); + decodeDailyTotals523(entry.getBody()); break; default: break; } + + // setDisplayable(); + } + + + private void setDisplayable() { + + if (this.insulinBasal == null) { + this.entry.setDisplayableValue("Total Insulin: " + StringUtil.getFormatedValueUS(this.insulinTotal, 2)); + } else { + this.entry.setDisplayableValue("Basal Insulin: " + StringUtil.getFormatedValueUS(this.insulinBasal, 2) + + ", Total Insulin: " + StringUtil.getFormatedValueUS(this.insulinTotal, 2)); + } + + } + + + private void decodeEndResultsTotals(PumpHistoryEntry entry) { + double totals = ByteUtil.toInt((int)entry.getHead()[0], (int)entry.getHead()[1], (int)entry.getHead()[2], + (int)entry.getHead()[3], ByteUtil.BitConversion.BIG_ENDIAN) * 0.025d; + + this.insulinTotal = totals; + + entry.addDecodedData("Totals", totals); + // entry.setDisplayableValue(getFormattedValue(totals, 3)); + } @@ -100,9 +138,18 @@ public class DailyTotalsDTO { private void decodeDailyTotals515(byte[] data) { - LOG.debug("Can't decode DailyTotals515: Body={}", ByteUtil.getHex(data)); + // LOG.debug("Can't decode DailyTotals515: Body={}", ByteUtil.getHex(data)); - testDecode(data); + this.insulinTotal = ByteUtil.toInt(data[8], data[9]) / 40.0d; + this.insulinBasal = ByteUtil.toInt(data[10], data[11]) / 40.0d; + this.insulinBolus = ByteUtil.toInt(data[13], data[14]) / 40.0d; + + // Delivery Stats: BG AVG: Bg Low/Hi=none,Number BGs=0 + // Delivery Stats: INSULIN: Basal 22.30, Bolus=4.20, Catbs = 0g (26.5) + // Delivery Stats: BOLUS: Food=0.00, Corr=0.00, Manual=4.20 + // Delivery Stats: NUM BOLUS: Food/Corr=0,Food+Corr=0, Manual=3 + + LOG.debug("515: {}", toString()); } diff --git a/app/src/main/res/values-ga/strings.xml b/app/src/main/res/values-ga/strings.xml index 70489fbc5e..fce0cc17b0 100644 --- a/app/src/main/res/values-ga/strings.xml +++ b/app/src/main/res/values-ga/strings.xml @@ -1,3 +1,323 @@ - - + + OAPS + MM640g + mmol/l + mg/dl + + Níl + Anois + Gaeilge + Bia + Dana + DanaRS + OAPS + Ard + Íseal + # Lá + xDrip + aláraim + Ceallraí + Bluetooth + Cnaipe 1 + Cnaipe 2 + Cnaipe 3 + Cuir ar ceal + Cuir ar ceal + Nasctha + Ag nascadh + DANA + DanaR + + Dáta + Gléas + Dínasctha + Dínasctha + In eagar + Bearla (English) + earráid + Scoir + BAILE + Íseal + Balbh + NSClient + NSClient + NSClient + OK + OK + OK + OpenAPS + OpenAPS AMA + OpenAPS MA + Eile + Eile + Athnuachan + Atosaigh + SAGE + Sábháil + Tosaigh + Stad + URL: + Suas + Toradh + Gréigis + Ginearálta + glúcóis + Glúcóis + Glúcóis + g + Fiasp + Saill + Cleachtadh + Folamh + Fad: + Fad + Fad + Fad [nóim.] + DanaRv2 + Dáta + Próifíl + Próifíl + Próifíl + Próifíl + PBAGE + Caidéil + Caidéil + CAIDÉIL + Ráta + Cóimheas + Cóimheas: + Cúis + Taiscumar + Atosú + Reáchtáil anois + Ag reáchtáil + Braiteoir + Braiteoir + Braiteoir aois + Rathúlacht + Aonaid + Aonaid: + A + Fionraí lúb do 10 u + Fionraí lúb do 1 u + Fionraí lúb do 2 u + Fionraí lúb do 3 u + Fionraí + Ceist + Teanga + Inslin + Ins: + INS + Inslin + Inslin + Inslin: + Inslin aois + IAGE + Gléas ainm + Páiste + Áireamhán + CAGE + Bluetooth stádas + APS + APS + AndroidAPS thosaigh + %dnóim ó shin + %d nóim ó shin + %.1fu ó shin + %.2f A/u + %1$d%% (%2$d nóim fágtha) + Gníomhartha + GNÍ + Cuir + Duine fásta + Calabrú + Calabrú + carbaihiodráit + Carbaihiodráití + Lúb dúnta + Cear + Cear + Seachadta + Seachadadh %.2fA + Seachadadh anois + Dhícheangal Caidéil do 10 u + Dhícheangal Caidéil do 1 u + Dhícheangal Caidéil do 2 u + Dhícheangal Caidéil do 3 u + Dhícheangal Caidéil do 30 nóim + Dícheangal + Ollainnis + Free-Peak Oref + " http://www.androidaps.org http://www.androidaps.de (de) facebook: http://facebook.androidaps.org http://facebook.androidaps.de (de)" + Iodáilis + Cóiréis + Lúb + Lúb + LÚB + Taiscumar folamh + Glúcóis stádas + Gearmáinis + Glimp + Stair + Lúb cumasaithe + ns_create_announcements_from_errors + NSCI + NS API secret + NS API secret + Lúb oscailte + Faoin gcéad + Faoin gcéad + Rapid-Acting Oref + athlán + Athlán + Athlódáil + Athlódáil próifíl + Rómáinis + Rúisis + Sensitivity Oref0 + Spainnis + Sualainnis + Déagóirí + Cóireálacha + Cóireálacha + Infheicthe + Bailí: + Fhíorú + Ar fionraí (%d n) + Ar fionraí ag úsáideoir + Tosaigh ag lúb oscailte + Stádas: + Stáit + Stopadh + Sraithuimhir + Athnuaigh + Athnuaigh caidéil stáit + Riamh + Tosaithe + Gnáth + Meán: %3.1f A + Uasmhéid: %3.1f A + Íosmhéid: %3.1f A + Ar fionraí ag earráid + Tosaithe ... + Léigh próifíl bunaidh + Léigh stair caidéil + Cumasaithe + Socrú BRS (%1$d%% / %2$d nóim) + Tosaithe + Cealú BRS + Is ceallraí Caidéil íseal + Is leibhéal cartús íseal + Ag bólas (%.1f A) + Carbí + Carbí + Carbí + Carbí + Carbí: + Carbí: + CARBÍ & BÓLAS + Ag nascadh le %d s + CPP + Tuairim + DanaR Bluetooth gléas + Seice + DanaR Cóiréis + DanaR staiti + Lúb atógáil + Is lúb cumasaithe + Is lúb cumasaithe + Is lúb díchumasaithe + Is lúb díchumasaithe + Lúb ar fionraí + Lúb ar fionraí + Lúb díchumasaithe + LÚB DÍCHUMASAITHE LE SRIANTA + Ceallraí Íseal + Nightscout URL + Nightscout + Novorapid, Novolog, Humalog + Nóta + Nótaí + Fast Acting Insulin Prolonged + DexcomG5 App (patched) + Díchumasaigh lúb + Cumasaigh lúb + Geata: + Glúcóis cineál + Athrú Cartús Inslin + Próifíl neamhbhailí !!! + Próifíl neamhbhailí: %s + Bólas deiridh + Reáchtáil deiridh + Achtaíodh deiridh + Nasc deiridh + GF deiridh: + Méar + Fast Acting Insulin + Earráidí + Inslin lá + Aonaid lá + Deilte + Deilte: + Socruithe Deilte + AndroidAPS + Bólas + Bólas stopadh + Ag stopadh bólas + Ag dul a sheachadadh %.2fA + Socrú próifíl bunaidh + Ag féachaint d\'athruithe stair + Níl nasc le haghaidh %d nóim + Is nuashonrú gá clog Caidéil + Cláir Caidéil bólas + Foláirimh + Gníomhaíocht + Gníom.: + Gníomhaíocht + Gníomhaíocht fad + Gníomhaíocht sprioc + Rabhadh + Stair le Caidéil + GLÉ + Feidhmiú + Firmware + MDI + Faoi + Iomlán + Iomlán + Próifíl gníomhach + Aláraim + APS mód + APS roghnaithe + Bunaidh + Bunaidh + Bunaidh + Bunaidh: + BUN + BUN + xds + Bólas: + Bólas + Bólas + Bólas E + Ag dul a sheachadadh %.2fA + Bólas DS + Bólas DE + Bólas S + SMS + Cúltaca + Bunaidh ráta + Bunaidh Céim + Bunaidh cineál + Bunaidh luach [%] + Bunaidh luach [A/u] + Bunaidh ráta bonn + Próifíl bonn + Seachadta %.2fA Bólas go rathúil + Seachadta %.2fA Bólas go rathúil + Bólas Céim + Bólasi + Cealú BRS + Cealú BRS teip + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5ef2e20e50..3c32523314 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1458,6 +1458,7 @@ No connection for %1$d hour(s) %2$d min No connection for %1$d day(s) %2$d hours + %1$d day %1$d days diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoderUTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoderUTest.java index 02c98d1224..2f98416c4d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoderUTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/PumpMedtronic/comm/history/pump/MedtronicPumpHistoryDecoderUTest.java @@ -93,20 +93,18 @@ public class MedtronicPumpHistoryDecoderUTest { @Test public void decodeDailyTotals515() { - byte[] data = new byte[] { - 0x6E, (byte)0xB1, (byte)0x92, 0x05, 0x00, (byte)0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, (byte)0x9A, 0x00, - 0x50, 0x34, 0x00, 0x4A, 0x30, 0x00, 0x0B, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x01, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0x80, (byte)0x80, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 }; + byte[] data = ByteUtil + .createByteArrayFromHexString("0x6C 0x17 0x93 0x06 0x08 0x00 0x2B 0x00 0x00 0x00 0x00 0x04 0x24 0x03 0x7C 0x54 0x00 0xA8 0x10 0x00 0x00 0x00 0xA8 0x10" + + " 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xA8 0x64 0x03 0x00 0x00"); - // Carbs=11, total=3.850,basal=2.000, bolus=1.850, basal 52%, blus=48%, Manual=0.95, #manual=5, - // Food only=0.9, #Food Only=1,Corr Only =0, #Corr only=0,Food+Corr=0 + // 0x6C 0x17 0x93 0x06 0x08 0x00 0x2B 0x00 0x00 0x00 0x00 0x04 0x24 0x03 0x7C 0x54 0x00 0xA8 0x10 0x00 0x00 0x00 + // 0xA8 0x10 + // 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xA8 0x64 0x03 0x00 0x00 - // Delivery Stats: Carbs=11, Total Insulin=3.850, Basal=2.000 - // Delivery Stats: Basal 52,Bolus 1.850, Bolus=48%o - // Delivery Stats: Food only=0.9, Food only#=1, Corr only = 0.0 - // Delivery Stats: #Corr_only=0,Food+Corr=0.000, #Food+Corr=0 - // Delivery Stats: Manual = 0.95, #Manual=5 + // Delivery Stats: BG AVG: Bg Low/Hi=none,Number BGs=0 + // Delivery Stats: INSULIN: Basal 22.30, Bolus=4.20, Catbs = 0g + // Delivery Stats: BOLUS: Food=0.00, Corr=0.00, Manual=4.20 + // Delivery Stats: NUM BOLUS: Food/Corr=0,Food+Corr=0, Manual=3 testRecord(data); @@ -145,6 +143,8 @@ public class MedtronicPumpHistoryDecoderUTest { phe.setEntryType(entryType); phe.setData(ByteUtil.getListFromByteArray(data), false); + System.out.println("EntryType: " + entryType); + decoder.decodeRecord(phe); System.out.println("Record: " + phe);