Skip to content

Commit 0c3b4ad

Browse files
committed
2 parents 87b81ee + 75e6741 commit 0c3b4ad

File tree

11 files changed

+61
-21
lines changed

11 files changed

+61
-21
lines changed

app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/CareLinkDataProcessor.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.SensorGlucose;
1919
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.TextMap;
2020

21+
import java.text.SimpleDateFormat;
2122
import java.util.ArrayList;
2223
import java.util.Collections;
2324
import java.util.Date;
@@ -41,6 +42,7 @@ public class CareLinkDataProcessor {
4142

4243
private static final String SOURCE_CARELINK_FOLLOW = "CareLink Follow";
4344

45+
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
4446

4547
static synchronized void processData(final RecentData recentData, final boolean live) {
4648

@@ -175,10 +177,10 @@ static synchronized void processData(final RecentData recentData, final boolean
175177
} else if ((marker.type.equals(Marker.MARKER_TYPE_INSULIN) && Pref.getBooleanDefaultFalse("clfollow_download_boluses"))
176178
|| (marker.type.equals(Marker.MARKER_TYPE_MEAL) && Pref.getBooleanDefaultFalse("clfollow_download_meals"))) {
177179

178-
//insulin, meal only for pumps (not value in case of GC)
179-
if (recentData.isNGP()) {
180+
//insulin, meal only for pumps and cgm (cgm = currently only Simplera, no value in case of Guardian CGM)
181+
if (recentData.isNGP() || recentData.isCGM()) {
180182

181-
final Treatments t;
183+
Treatments t;
182184
double carbs = 0;
183185
double insulin = 0;
184186

@@ -209,6 +211,7 @@ static synchronized void processData(final RecentData recentData, final boolean
209211
t.save();
210212
if (Home.get_show_wear_treatments())
211213
pushTreatmentSyncToWatch(t, true);
214+
UserError.Log.d(TAG, "NEW TREATMENT: " + treatmentToString(t));
212215
}
213216
}
214217
}
@@ -252,7 +255,8 @@ static synchronized void processData(final RecentData recentData, final boolean
252255
//Cleared Notifications
253256
if (recentData.notificationHistory.clearedNotifications != null) {
254257
for (ClearedNotification clearedNotification : recentData.notificationHistory.clearedNotifications) {
255-
addNotification(clearedNotification.triggeredDateTime, recentData.getDeviceFamily(), clearedNotification.getMessageId(), clearedNotification.faultId);
258+
Date notificationDate = clearedNotification.triggeredDateTime != null ? clearedNotification.triggeredDateTime : clearedNotification.dateTime;
259+
addNotification(notificationDate, recentData.getDeviceFamily(), clearedNotification.getMessageId(), clearedNotification.faultId);
256260
}
257261
}
258262
}
@@ -277,7 +281,7 @@ protected static boolean newTreatment(double carbs, double insulin, long timesta
277281

278282

279283
//Create notification from CareLink messageId
280-
protected static boolean addNotification(Date date, String deviceFamily, String messageId, int faultId) {
284+
protected static boolean addNotification(Date date, String deviceFamily, String messageId, String faultId) {
281285

282286
if (deviceFamily != null && messageId != null)
283287
return addNotification(date, TextMap.getNotificationMessage(deviceFamily, messageId, faultId));
@@ -339,4 +343,10 @@ protected static boolean newNote(String note, long timestamp) {
339343

340344
}
341345

346+
protected static String treatmentToString(Treatments treatments){
347+
return DateUtil.toISOString(treatments.timestamp) + " - "
348+
+ String.format("%.3f", treatments.insulin) + "U "
349+
+ String.format("%.0f", treatments.carbs) + "g ";
350+
}
351+
342352
}

app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public Boolean isRecentUploadBle(){
300300
return null;
301301

302302
for(DataUpload upload : this.sessionRecentUploads.recentUploads){
303-
if(upload.device.toUpperCase().contains("MINIMED"))
303+
if(upload.device.toUpperCase().contains("MINIMED") || upload.device.toUpperCase().contains("SIMPLERA"))
304304
return true;
305305
else if(upload.device.toUpperCase().contains("GUARDIAN"))
306306
return false;

app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Alarm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public String getMessageAlarmCode() {
1414
return null;
1515
}
1616

17-
public int code;
17+
public String code;
1818
//@JsonAdapter(CareLinkJsonAdapter.class)
1919
public String datetime;
2020
public Date datetimeAsDate;

app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Marker.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public boolean isBloodGlucose() {
3333
public Date dateTime;
3434
@JsonAdapter(CareLinkJsonAdapter.class)
3535
public Date timestamp = null;
36+
@JsonAdapter(CareLinkJsonAdapter.class)
37+
public Date displayTime = null;
3638
public Integer relativeOffset;
3739
public Boolean calibrationSuccess;
3840
public Double amount;
@@ -50,7 +52,9 @@ public boolean isBloodGlucose() {
5052
public MarkerData data;
5153

5254
public Date getDate(){
53-
if(timestamp != null)
55+
if(displayTime != null)
56+
return displayTime;
57+
else if(timestamp != null)
5458
return timestamp;
5559
else if(dateTime != null)
5660
return dateTime;
@@ -63,6 +67,12 @@ public Float getInsulinAmount(){
6367
return deliveredExtendedAmount + deliveredFastAmount;
6468
else if(data.dataValues != null && data.dataValues.deliveredFastAmount != null)
6569
return data.dataValues.deliveredFastAmount;
70+
else if(data != null && data.dataValues != null && data.dataValues.insulinUnits != null)
71+
try {
72+
return Float.parseFloat(data.dataValues.insulinUnits);
73+
} catch (Exception ex){
74+
return null;
75+
}
6676
else
6777
return null;
6878
}

app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/MarkerDataValues.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class MarkerDataValues {
88
public Float bolusAmount;
99
public Float maxAutoBasalRate;
1010
public String insulinType;
11+
public String insulinUnits;
1112
public Float programmedFastAmount;
1213
public Float deliveredFastAmount;
1314
public String activationType;

app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Notification.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class Notification {
1010
@JsonAdapter(CareLinkJsonAdapter.class)
1111
public Date dateTime;
1212
public String type;
13-
public int faultId;
13+
public String faultId;
1414
public int instanceId;
1515
public String messageId;
1616
public String pumpDeliverySuspendState;
@@ -20,8 +20,8 @@ public class Notification {
2020
public String getMessageId(){
2121
if(messageId != null)
2222
return messageId;
23-
else if(faultId > 0)
24-
return String.valueOf(faultId);
23+
else if(faultId != null)
24+
return faultId;
2525
else
2626
return null;
2727
}

app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Patient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class Patient {
1212
public boolean patientUsesConnect;
1313

1414
public boolean isBle() {
15-
return lastDeviceFamily.contains("BLE");
15+
return (lastDeviceFamily.contains("BLE") || lastDeviceFamily.contains("SIMPLERA"));
1616
}
1717

1818
}

app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/RecentData.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class RecentData {
1010

1111
public static final String DEVICE_FAMILY_GUARDIAN = "GUARDIAN";
1212
public static final String DEVICE_FAMILY_NGP = "NGP";
13+
public static final String DEVICE_FAMILY_CGM = "CGM";
1314

1415
//sensorState
1516
public static final String SENSOR_STATE_CALIBRATION_REQUIRED = "CALIBRATION_REQUIRED";
@@ -58,6 +59,10 @@ public boolean isNGP() {
5859
return getDeviceFamily().equals(DEVICE_FAMILY_NGP);
5960
}
6061

62+
public boolean isCGM() {
63+
return getDeviceFamily().equals(DEVICE_FAMILY_CGM);
64+
}
65+
6166
public int getDeviceBatteryLevel(){
6267
if(pumpBatteryLevelPercent == 0)
6368
return medicalDeviceBatteryLevelPercent;

app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/SensorGlucose.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message;
22

33
import com.eveningoutpost.dexdrip.cgm.carelinkfollow.message.util.CareLinkJsonAdapter;
4+
import com.eveningoutpost.dexdrip.models.DateUtil;
45
import com.google.gson.annotations.JsonAdapter;
56

7+
import java.text.SimpleDateFormat;
68
import java.util.Date;
79

810
/**
911
* CareLink SensorGlucose message with helper methods for processing
1012
*/
1113
public class SensorGlucose {
1214

15+
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
16+
1317
public Integer sg;
1418
public String datetime;
1519
public Date datetimeAsDate;
@@ -35,9 +39,9 @@ public String toS() {
3539
if (getDate() == null) {
3640
dt = "";
3741
} else {
38-
dt = getDate().toString();
42+
dt = DateUtil.toISOString(getDate());
3943
}
40-
return dt + " " + sg;
44+
return dt + " - " + sg;
4145
}
4246

4347
}

app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/TextMap.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.eveningoutpost.dexdrip.cgm.carelinkfollow.message;
22

3+
import com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer;
4+
35
import java.util.HashMap;
46

57
public class TextMap {
@@ -311,21 +313,27 @@ public static String getNotificationMessage(String deviceFamily, ClearedNotifica
311313
return getErrorMessage(deviceFamily, notification.messageId, notification.faultId);
312314
}
313315

314-
public static String getNotificationMessage(String deviceFamily, String messageId, int faultId) {
316+
public static String getNotificationMessage(String deviceFamily, String messageId, String faultId) {
315317
return getErrorMessage(deviceFamily, messageId, faultId);
316318
}
317319

318-
public static String getErrorMessage(String deviceFamily, String guardianErrorCode, int ngpErrorCode) {
320+
public static String getErrorMessage(String deviceFamily, String guardianErrorCode, String ngpErrorCode) {
319321
String errorTextId;
320322
String internalEC;
323+
String formattedEC;
321324

322325
if (deviceFamily.equals(RecentData.DEVICE_FAMILY_GUARDIAN)) {
323326
if (guardianErrorCode != null)
324327
errorTextId = ERROR_TEXT_PREFIX_GUARDIAN + guardianErrorCode;
325328
else
326329
errorTextId = null;
327-
} else if (deviceFamily.equals(RecentData.DEVICE_FAMILY_NGP)) {
328-
String formattedEC = String.format("%03d", ngpErrorCode);
330+
} else if (deviceFamily.equals(RecentData.DEVICE_FAMILY_NGP) || deviceFamily.equals(RecentData.DEVICE_FAMILY_CGM)) {
331+
if(ngpErrorCode.matches("\\d+"))
332+
{
333+
formattedEC = String.format("%03d", Integer.parseInt(ngpErrorCode));
334+
}
335+
else
336+
formattedEC = ngpErrorCode;
329337
if (errorCodeMap.containsKey(formattedEC))
330338
internalEC = errorCodeMap.get(formattedEC);
331339
else

0 commit comments

Comments
 (0)