diff --git a/.idea/libraries/acra_4_5_0.xml b/.idea/libraries/acra_4_5_0.xml
new file mode 100644
index 0000000..c54996c
--- /dev/null
+++ b/.idea/libraries/acra_4_5_0.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/gson_2_3.xml b/.idea/libraries/gson_2_3.xml
new file mode 100644
index 0000000..f7974c7
--- /dev/null
+++ b/.idea/libraries/gson_2_3.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/guava_14_0_1.xml b/.idea/libraries/guava_14_0_1.xml
new file mode 100644
index 0000000..5275114
--- /dev/null
+++ b/.idea/libraries/guava_14_0_1.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/mongo_java_driver_2_12_3.xml b/.idea/libraries/mongo_java_driver_2_12_3.xml
new file mode 100644
index 0000000..bca31c8
--- /dev/null
+++ b/.idea/libraries/mongo_java_driver_2_12_3.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/org_eclipse_paho_client_mqttv3_1_0_0.xml b/.idea/libraries/org_eclipse_paho_client_mqttv3_1_0_0.xml
new file mode 100644
index 0000000..ad5926d
--- /dev/null
+++ b/.idea/libraries/org_eclipse_paho_client_mqttv3_1_0_0.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/play_services_wearable_5_0_77.xml b/.idea/libraries/play_services_wearable_5_0_77.xml
new file mode 100644
index 0000000..cd236ac
--- /dev/null
+++ b/.idea/libraries/play_services_wearable_5_0_77.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/protobuf_java_2_5_0.xml b/.idea/libraries/protobuf_java_2_5_0.xml
new file mode 100644
index 0000000..b049cb7
--- /dev/null
+++ b/.idea/libraries/protobuf_java_2_5_0.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/support_annotations_20_0_0.xml b/.idea/libraries/support_annotations_20_0_0.xml
new file mode 100644
index 0000000..ce41c6b
--- /dev/null
+++ b/.idea/libraries/support_annotations_20_0_0.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/support_v13_20_0_0.xml b/.idea/libraries/support_v13_20_0_0.xml
new file mode 100644
index 0000000..2d52151
--- /dev/null
+++ b/.idea/libraries/support_v13_20_0_0.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/support_v4_20_0_0.xml b/.idea/libraries/support_v4_20_0_0.xml
new file mode 100644
index 0000000..347fa3e
--- /dev/null
+++ b/.idea/libraries/support_v4_20_0_0.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/wearable_1_0_0.xml b/.idea/libraries/wearable_1_0_0.xml
new file mode 100644
index 0000000..58144b3
--- /dev/null
+++ b/.idea/libraries/wearable_1_0_0.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mobile/build.gradle b/mobile/build.gradle
index d0a31df..e180926 100644
--- a/mobile/build.gradle
+++ b/mobile/build.gradle
@@ -8,8 +8,8 @@ android {
applicationId "com.ktind.cgm.bgscout"
minSdkVersion 16
targetSdkVersion 20
- versionCode 3
- versionName "1.0.3"
+ versionCode 6
+ versionName "1.0.6"
}
buildTypes {
release {
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractDevice.java b/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractDevice.java
index e9ad3b0..9ce6933 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractDevice.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractDevice.java
@@ -190,12 +190,14 @@ public GlucoseUnit getUnit() {
}
public void stopMonitors(){
-// state=State.STOPPING;
+ if (monitors==null) {
+ Log.w(TAG, "monitors is null. A stop was previously issued. How did I get here?");
+ return;
+ }
Log.d(TAG,"stopMonitors called");
for (AbstractMonitor monitor:monitors){
monitor.stop();
}
-// state=State.STOPPED;
monitors=null;
}
@@ -204,18 +206,19 @@ public void setUnit(GlucoseUnit unit) {
}
@Override
- public void fireMonitors() {
+ public void fireMonitors(DownloadObject dl) {
stats.startMonitorTimer();
Log.d(TAG,"Firing monitors");
// FIXME why is monitors set to null here sometimes?
if (monitors==null)
return;
for (AbstractMonitor monitor:monitors){
- try {
- monitor.process(getLastDownloadObject());
- } catch (DeviceException e) {
- Log.w(TAG,e.getMessage());
- }
+// try {
+// monitor.process(getLastDownloadObject());
+ monitor.process(dl);
+// } catch (DeviceException e) {
+// Log.w(TAG,e.getMessage());
+// }
}
stats.stopMonitorTimer();
}
@@ -289,37 +292,36 @@ public Date getNextReadingTime() {
public int getLastBG() throws NoDataException {
int lastIndex= 0;
- lastIndex = getLastDownloadObject().getEgvRecords().length-1;
+ lastIndex = getLastDownloadObject().getEgvArrayListRecords().size()-1;
if (lastIndex<0)
throw new NoDataException("No previous download available");
- return getLastDownloadObject().getEgvRecords()[lastIndex].getEgv();
+ return getLastDownloadObject().getEgvArrayListRecords().get(lastIndex).getEgv();
}
public Trend getLastTrend() throws NoDataException {
int lastIndex = 0;
- lastIndex = getLastDownloadObject().getEgvRecords().length - 1;
+ lastIndex = getLastDownloadObject().getEgvArrayListRecords().size() - 1;
if (lastIndex<0)
throw new NoDataException("No previous download available");
- return getLastDownloadObject().getEgvRecords()[lastIndex].getTrend();
+ return getLastDownloadObject().getEgvArrayListRecords().get(lastIndex).getTrend();
}
- protected void onDownload(){
+ protected void onDownload(DownloadObject dl){
sendToUI();
- try {
+// try {
if (Looper.getMainLooper().getThread()==Thread.currentThread())
Log.d(TAG,"ON THE MAIN Thread!!!");
else
Log.d(TAG, "Not on the MAIN Thread ("+Thread.currentThread().getName()+"/"+Thread.currentThread().getState()+")");
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sharedPref.edit();
- // FIXME should this really be "last_g4_download"? Perhaps it should be "driver"
- editor.putLong(deviceIDStr +"_last_"+driver, getLastDownloadObject().getLastReadingDate().getTime());
+ editor.putLong(deviceIDStr +"_last_"+driver, dl.getLastReadingDate().getTime());
editor.apply();
- } catch (NoDataException e) {
- Log.i(TAG,"No data on download");
-// e.printStackTrace();
- }
- fireMonitors();
+// } catch (NoDataException e) {
+// Log.i(TAG,"No data on download");
+//// e.printStackTrace();
+// }
+ fireMonitors(dl);
}
public void sendToUI(){
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractMonitor.java b/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractMonitor.java
index 33a4d09..9c9e506 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractMonitor.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractMonitor.java
@@ -50,6 +50,7 @@ abstract public class AbstractMonitor implements MonitorInterface {
protected Context context;
protected SharedPreferences sharedPref;
protected long lastSuccessDate;
+ protected State state;
// protected EGVLimits egvLimits;
public AbstractMonitor(String n,int devID,Context context, String monitorName){
@@ -148,6 +149,7 @@ public void savelastSuccessDate(Date date){
@Override
public void stop(){
+ state=State.STOPPED;
Log.i(TAG,"Stopping monitor "+monitorType+" for "+name);
}
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractPollDevice.java b/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractPollDevice.java
index bf78cc3..18aa8f5 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractPollDevice.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractPollDevice.java
@@ -121,17 +121,18 @@ public void run() {
stats.startDownloadTimer();
Tracker tracker=((BGScout) context.getApplicationContext()).getTracker();
long downloadTimeStart=System.currentTimeMillis();
- doDownload();
+ DownloadObject dl=doDownload();
tracker.send(new HitBuilders.TimingBuilder()
- .setCategory("Download")
+ .setCategory("Device Download")
.setLabel(driver)
.setValue(System.currentTimeMillis() - downloadTimeStart)
+ .setVariable(driver)
.build()
);
Log.d(TAG,"Sent timing to GA: "+(System.currentTimeMillis()-downloadTimeStart));
stats.stopDownloadTimer();
Log.i(TAG,"Download complete in download thread");
- onDownload();
+ onDownload(dl);
}
},"Download_"+deviceIDStr).start();
Log.i(TAG,"After download thread creation");
@@ -164,7 +165,8 @@ public long nextFire(){
public long nextFire(long millis){
try {
// FIXME consider using system time to determine the offset for the next reading rather than the display time to get rid of the time sync problems.
- long lastDLlong=getLastDownloadObject().getEgvRecords()[getLastDownloadObject().getEgvRecords().length-1].getDate().getTime();
+// long lastDLlong=getLastDownloadObject().getEgvRecords()[getLastDownloadObject().getEgvRecords().length-1].getDate().getTime();
+ long lastDLlong=getLastDownloadObject().getLastRecordReadingDate().getTime();
Log.d(TAG,"nextFire calculated last dl to be: "+lastDLlong + " currentMillis: "+System.currentTimeMillis());
long diff=(millis-(System.currentTimeMillis() - lastDLlong));
Log.d(TAG,"nextFire calculated to be: "+diff+" for "+getName()+" using a poll interval of "+millis);
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractPushDevice.java b/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractPushDevice.java
index d66ce7f..6701ae8 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractPushDevice.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/AbstractPushDevice.java
@@ -1,7 +1,6 @@
package com.ktind.cgm.bgscout;
import android.content.Context;
-import android.os.Handler;
/**
Copyright (c) 2014, Kevin Lee (klee24@gmail.com)
@@ -36,9 +35,9 @@ public AbstractPushDevice(String n, int deviceID, Context appContext, String dri
// abstract void onDataReady(DownloadObject ddo);
@Override
- public void onDownload(){
+ public void onDownload(DownloadObject dl){
stats.addDownload();
- super.onDownload();
+ super.onDownload(dl);
}
@Override
public void start() {
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/AndroidNotificationMonitor.java b/mobile/src/main/java/com/ktind/cgm/bgscout/AndroidNotificationMonitor.java
index 3eb5550..184657c 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/AndroidNotificationMonitor.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/AndroidNotificationMonitor.java
@@ -61,6 +61,8 @@ public class AndroidNotificationMonitor extends AbstractMonitor {
protected boolean isSilenced=false;
protected Date timeSilenced;
protected SnoozeReceiver snoozeReceiver;
+ protected tickReceiver tickReceiver;
+ protected screenStateReceiver screenStateReceiver;
protected DownloadObject lastDownload;
protected ArrayList previousDownloads=new ArrayList();
protected final int MAXPREVIOUS=3;
@@ -73,6 +75,9 @@ public class AndroidNotificationMonitor extends AbstractMonitor {
private DownloadObject lastKnownGood;
protected String phoneNum=null;
protected AnalyzedDownload analyzedDownload;
+ protected int tickCounter=0;
+ protected boolean isTickCounterSyncd=false;
+ protected boolean isScreenOn=true;
public void setNotifBuilder(Notification.Builder notifBuilder) {
@@ -111,7 +116,12 @@ public void init(){
sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
this.setAllowVirtual(true);
snoozeReceiver = new SnoozeReceiver();
+ screenStateReceiver= new screenStateReceiver();
+ tickReceiver = new tickReceiver();
context.registerReceiver(snoozeReceiver, new IntentFilter(Constants.SNOOZE_INTENT));
+ context.registerReceiver(screenStateReceiver,new IntentFilter(Intent.ACTION_SCREEN_ON));
+ context.registerReceiver(screenStateReceiver,new IntentFilter(Intent.ACTION_SCREEN_OFF));
+ context.registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
}
public String getPhoneNum() {
@@ -138,9 +148,8 @@ public void doProcess(DownloadObject dl) {
} else {
Log.w(TAG, "No previous downloads?");
}
- if (dl.getEgvRecords().length>0)
+ if (dl.getEgvArrayListRecords().size()>0)
lastKnownGood = dl;
-
// TODO add devicetype to the download object so that we can instantiate the proper analyzer
AbstractDownloadAnalyzer downloadAnalyzer=new G4DownloadAnalyzer(dl, context);
analyzedDownload=downloadAnalyzer.analyze();
@@ -159,6 +168,11 @@ public void doProcess(DownloadObject dl) {
}
mNotifyMgr.notify(deviceID, buildNotification(analyzedDownload));
+ if (! isTickCounterSyncd) {
+ syncTickCounter();
+ // Not sure this is what we want to do but I don't want to spend valuable CPU time/battery recalc'ing the sync when it will rarely if ever change.
+ isTickCounterSyncd=true;
+ }
try {
savelastSuccessDate(dl.getLastRecordReadingDate().getTime());
} catch (NoDataException e) {
@@ -166,6 +180,19 @@ public void doProcess(DownloadObject dl) {
}
}
+ private void syncTickCounter(){
+ try {
+ // tickCounter represents the number of minutes since the previous analyzed download
+ if (previousDownloads != null && previousDownloads.size() > 0) {
+ int timeSinceDownload = (int) (new Date().getTime() - previousDownloads.get(previousDownloads.size() - 1).getLastRecordReadingDate().getTime());
+ tickCounter = (timeSinceDownload / 1000) / 60;
+ Log.d(TAG, "Setting tickCounter to " + tickCounter);
+ }
+ } catch (NoDataException e) {
+ e.printStackTrace();
+ }
+ }
+
private Notification buildNotification(AnalyzedDownload dl){
setDefaults();
setSound(dl);
@@ -360,7 +387,7 @@ protected void setActions(AnalyzedDownload dl){
notifBuilder.addAction(android.R.drawable.sym_action_call, "Call", callPendingIntent);
Intent smsIntent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms",phoneNum,null));
- PendingIntent smsPendingIntent = PendingIntent.getActivity(context,40+deviceID,smsIntent,0);
+ PendingIntent smsPendingIntent = PendingIntent.getActivity(context, 40 + deviceID, smsIntent, 0);
notifBuilder.addAction(android.R.drawable.sym_action_chat,"Text",smsPendingIntent);
}
@@ -408,7 +435,6 @@ protected void setIcon(AnalyzedDownload dl){
iconLevel = trend.getVal() + (state * 10) + (range * 20);
} catch (NoDataException e) {
iconLevel=60;
-// e.printStackTrace();
}
notifBuilder.setSmallIcon(R.drawable.smicons, iconLevel);
}
@@ -423,29 +449,106 @@ public void start() {
public void stop() {
Log.i(TAG, "Stopping monitor " + monitorType + " for " + name);
mNotifyMgr.cancel(deviceID);
- if (context != null && snoozeReceiver != null)
- context.unregisterReceiver(snoozeReceiver);
+ if (context !=null) {
+ if (snoozeReceiver != null)
+ context.unregisterReceiver(snoozeReceiver);
+ if (screenStateReceiver !=null)
+ context.unregisterReceiver(screenStateReceiver);
+ if (tickReceiver != null)
+ context.unregisterReceiver(tickReceiver);
+ }
}
public class SnoozeReceiver extends BroadcastReceiver {
@Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction().equals(Constants.SNOOZE_INTENT)){
+ public void onReceive(Context mContext, Intent intent) {
+ if (intent.getAction().equals(Constants.SNOOZE_INTENT)) {
if (intent.getExtras().get("device").equals(deviceIDStr)) {
- Tracker tracker=((BGScout) context.getApplicationContext()).getTracker();
- tracker.send(new HitBuilders.EventBuilder("Snooze","pressed").build());
+ Tracker tracker = ((BGScout) context.getApplicationContext()).getTracker();
+ tracker.send(new HitBuilders.EventBuilder("Snooze", "pressed").build());
Log.d(TAG, deviceIDStr + ": Received a request to snooze alarm on " + intent.getExtras().get("device"));
// Only capture the first snooze operation.. ignore others until it is reset
if (!isSilenced) {
isSilenced = true;
timeSilenced = new Date();
}
- if (analyzedDownload!=null)
+ if (analyzedDownload != null)
mNotifyMgr.notify(deviceID, buildNotification(analyzedDownload));
- }else{
- Log.d(TAG,deviceIDStr+": Ignored a request to snooze alarm on "+intent.getExtras().get("device"));
+ } else {
+ Log.d(TAG, deviceIDStr + ": Ignored a request to snooze alarm on " + intent.getExtras().get("device"));
+ }
+ }
+ }
+ }
+
+ public void updateNotification(){
+ Log.d(TAG, "Reanalyzing the download");
+ if (previousDownloads.size() > 0) {
+ AbstractDownloadAnalyzer downloadAnalyzer = new G4DownloadAnalyzer(previousDownloads.get(previousDownloads.size() - 1), context);
+ analyzedDownload = downloadAnalyzer.analyze();
+ setDefaults();
+ setActions(analyzedDownload);
+ setContent(analyzedDownload);
+ setIcon(analyzedDownload);
+ notifBuilder.setPriority(Notification.PRIORITY_LOW);
+ Notification notification=notifBuilder.build();
+ mNotifyMgr.notify(deviceID, notification);
+ }
+ }
+
+ public class screenStateReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context mContext, Intent intent) {
+ Log.d(TAG,"Intent=>"+intent.getAction()+" received");
+ if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
+ updateNotification();
+ isScreenOn=true;
+// tickReceiver=new tickReceiver();
+// IntentFilter intentFilter = new IntentFilter("android.intent.action.TIME_TICK");
+// context.registerReceiver(tickReceiver, intentFilter);
+ Log.d(TAG, "Kicking off tick timer");
+ } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
+// IntentFilter intentFilter = new IntentFilter("android.intent.action.TIME_TICK");
+// context.unregisterReceiver(tickReceiver);
+// tickReceiver=null;
+ isScreenOn=false;
+// Log.d(TAG, "Canceling tick timer");
+ }
+ }
+ }
+
+ public class tickReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context mContext, Intent intent) {
+ if (intent.getAction().equals("android.intent.action.TIME_TICK")) {
+ try {
+ Log.d(TAG, "Comparing "+(new Date().getTime()-analyzedDownload.getLastRecordReadingDate().getTime()));
+ if (new Date().getTime()-analyzedDownload.getLastRecordReadingDate().getTime()< 310000 && ! isScreenOn) {
+ Log.d(TAG,"tickReceiver is returning because screen is off and the last reading is less than 5 minutes and 10 seconds old");
+ return;
+ }
+ if (isScreenOn)
+ updateNotification();
+ // On every 5th tick lets only do an update to avoid double notifications when there is a timing mismatch
+ if (tickCounter==5) {
+ updateNotification();
+ return;
+ }
+ if (tickCounter>6) {
+ Log.d(TAG, "Reanalyzing the download");
+ if (previousDownloads.size() > 0) {
+ AbstractDownloadAnalyzer downloadAnalyzer = new G4DownloadAnalyzer(previousDownloads.get(previousDownloads.size() - 1), context);
+ analyzedDownload = downloadAnalyzer.analyze();
+ mNotifyMgr.notify(deviceID, buildNotification(analyzedDownload));
+ }
+ tickCounter=0;
+ }
+ tickCounter+=1;
+ } catch (NoDataException e) {
+ e.printStackTrace();
}
+
}
}
}
@@ -475,6 +578,7 @@ private Bitmap getThumbnailByPhoneDataUri(Uri phoneDataUri){
thumbnail= BitmapFactory.decodeByteArray(thumbnailBytes,0,thumbnailBytes.length);
}
}
+ cursor.close();
// InputStream photoDataStream = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(),uri);
// Bitmap photo=BitmapFactory.decodeStream(photoDataStream);
return thumbnail;
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/CGMDownloadAnalyzer.java b/mobile/src/main/java/com/ktind/cgm/bgscout/CGMDownloadAnalyzer.java
index 918c926..ecf8667 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/CGMDownloadAnalyzer.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/CGMDownloadAnalyzer.java
@@ -43,7 +43,7 @@ public abstract class CGMDownloadAnalyzer extends AbstractDownloadAnalyzer {
protected final int UPLOADERBATTERYCRITICAL =20;
protected final int DEVICEBATTERYWARN =30;
protected final int DEVICEBATTERYCRITICAL =20;
- protected final int MAXRECORDAGE=300000;
+ protected final int MAXRECORDAGE=310000;
protected EGVLimits egvLimits=new EGVLimits();
// protected EGVThresholdsEnum conditions=EGVThresholdsEnum.INRANGE;
@@ -107,6 +107,9 @@ protected void checkRecordAge() throws NoDataException {
Long recordAge=new Date().getTime() - downloadObject.getLastRecordReadingDate().getTime();
if (recordAge > MAXRECORDAGE)
downloadObject.addMessage(new AlertMessage(AlertLevels.CRITICAL,"Last record is greater than "+((recordAge/1000)/60)+" minutes old"),Conditions.STALEDATA);
+ Long downloadAge=new Date().getTime() - downloadObject.getDownloadDate().getTime();
+ if (downloadAge > MAXRECORDAGE)
+ downloadObject.addMessage(new AlertMessage(AlertLevels.CRITICAL,"Have not heard from remote CGM for more than "+((downloadAge/1000)/60)+" minutes"),Conditions.STALEDATA);
}
protected void checkDownloadStatus(){
@@ -157,7 +160,43 @@ protected void checkThresholdholds() throws NoDataException {
}
protected void checkLastRecordTime() throws NoDataException {
- String msg=new SimpleDateFormat("HH:mm:ss MM/dd").format(downloadObject.getLastRecordReadingDate());
+// String msg=new SimpleDateFormat("HH:mm:ss MM/dd").format(downloadObject.getLastRecordReadingDate());
+ String msg="~";
+ int timeDiff=(int) (new Date().getTime()-downloadObject.getLastRecordReadingDate().getTime());
+ Log.d("XXX","Time difference: "+timeDiff);
+ if (timeDiff<60000) {
+ msg += "Now";
+ }else if (timeDiff>60000 && timeDiff<3600000){
+ msg += String.valueOf((timeDiff/1000)/60);
+ msg += "m";
+ }else if (timeDiff>3600000 && timeDiff<86400000){
+ msg += String.valueOf(((timeDiff/1000)/60)/24);
+ msg += "h";
+ }else if (timeDiff>86400000 && timeDiff<604800000){
+ msg += String.valueOf((((timeDiff/1000)/60)/24)/7);
+ msg += "w";
+ }else {
+ msg=new SimpleDateFormat("HH:mm:ss MM/dd").format(downloadObject.getLastRecordReadingDate());
+ }
+ msg+="\n"+new SimpleDateFormat("HH:mm:ss MM/dd").format(downloadObject.getLastRecordReadingDate());
downloadObject.addMessage(new AlertMessage(AlertLevels.CRITICAL,msg),Conditions.NONE);
+// msg="Download: ~";
+// timeDiff=(int) (new Date().getTime()-downloadObject.getDownloadDate().getTime());
+// Log.d("XXX","Time difference: "+timeDiff);
+// if (timeDiff<60000) {
+// msg += "Now";
+// }else if (timeDiff>60000 && timeDiff<3600000){
+// msg += String.valueOf((timeDiff/1000)/60);
+// msg += "m";
+// }else if (timeDiff>3600000 && timeDiff<86400000){
+// msg += String.valueOf(((timeDiff/1000)/60)/24);
+// msg += "h";
+// }else if (timeDiff>86400000 && timeDiff<604800000){
+// msg += String.valueOf((((timeDiff/1000)/60)/24)/7);
+// msg += "w";
+// }else {
+// msg=new SimpleDateFormat("HH:mm:ss MM/dd").format(downloadObject.getLastRecordReadingDate());
+// }
+// downloadObject.addMessage(new AlertMessage(AlertLevels.CRITICAL,msg),Conditions.NONE);
}
}
\ No newline at end of file
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/CGMDownloadObject.java b/mobile/src/main/java/com/ktind/cgm/bgscout/CGMDownloadObject.java
index 1b5ecca..6a764a5 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/CGMDownloadObject.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/CGMDownloadObject.java
@@ -28,7 +28,6 @@
import android.util.Log;
-import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
@@ -86,7 +85,7 @@ public Date getLastReadingDate() {
// Then check to see if there are any records
// finally set to now - 2.5 hours.
if (this.lastReadingDate!=null)
- return this.lastReadingDate;
+ return new Date(this.lastReadingDate);
if (this.egvRecords != null && this.egvRecords.size() > 0)
return egvRecords.get(egvRecords.size()-1).getDate();
// return egvRecords[egvRecords.length-1].getDate();
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/Conditions.java b/mobile/src/main/java/com/ktind/cgm/bgscout/Conditions.java
index edc85f1..a9d36b5 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/Conditions.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/Conditions.java
@@ -46,5 +46,7 @@ public enum Conditions {
DEVICEMSGS,
UNKNOWN,
NONE,
- REMOTEDISCONNECTED
+ REMOTEDISCONNECTED,
+ MISSEDREADING,
+ SPECIALVALUE
}
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/DeviceActivity.java b/mobile/src/main/java/com/ktind/cgm/bgscout/DeviceActivity.java
index 3e5cecb..7280cdd 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/DeviceActivity.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/DeviceActivity.java
@@ -1,11 +1,5 @@
package com.ktind.cgm.bgscout;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Locale;
-
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Fragment;
@@ -21,10 +15,10 @@
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build;
+import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.support.v13.app.FragmentPagerAdapter;
-import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
@@ -45,6 +39,12 @@
import com.ktind.cgm.bgscout.model.DownloadDataSource;
import com.ktind.cgm.bgscout.model.EGV;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Locale;
+
public class DeviceActivity extends Activity {
private static final String TAG = DeviceActivity.class.getSimpleName();
@@ -144,12 +144,12 @@ public void onDrawerOpened(View drawerView) {
if (ui.containsKey(ld.getDeviceID())){
ui.get(ld.getDeviceID()).update(ld);
} else {
- Log.w("XXX","UI does not contain "+ld.getDeviceID());
+// Log.w("XXX","UI does not contain "+ld.getDeviceID());
}
}
// UIDeviceList.get(0).update((DownloadObject) savedInstanceState.getSerializable("lastDownload"));
} else {
- Log.w("XXX", "Saved instance does not contain anything");
+// Log.w("XXX", "Saved instance does not contain anything");
}
}
@@ -164,7 +164,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) {
public void buildUI(){
// Build the UI objects
- Log.d("XXX","Number of fragments here: "+PlaceholderFragment.fragments.size());
+// Log.d("XXX","Number of fragments here: "+PlaceholderFragment.fragments.size());
for (String key:PlaceholderFragment.fragments.keySet()) {
TextView egvValue = (TextView) PlaceholderFragment.fragments.get(key).getView().findViewById(R.id.reading_text);
TextView uploaderBatteryLabel = (TextView) PlaceholderFragment.fragments.get(key).getView().findViewById(R.id.uploader_battery_label);
@@ -175,7 +175,7 @@ public void buildUI(){
ImageView uploaderBat = (ImageView) PlaceholderFragment.fragments.get(key).getView().findViewById(R.id.uploader_battery_indicator);
ImageView deviceBat = (ImageView) PlaceholderFragment.fragments.get(key).getView().findViewById(R.id.device_battery_indicator);
UIDevice uid=new UIDevice(main,direction,egvValue,name,uploaderBat,uploaderBatteryLabel,deviceBat,deviceBatteryLabel);
- Log.d("XXX", "Adding "+key+" to ui elements map");
+// Log.d("XXX", "Adding "+key+" to ui elements map");
ui.put(key, uid);
}
@@ -369,13 +369,13 @@ public void updateView(DownloadObject dl){
@Override
public void onDestroyView() {
- Log.d("XXX","onDestoryView called");
+// Log.d("XXX","onDestoryView called");
super.onDestroyView();
}
@Override
public void onDestroy() {
- Log.d("XXX","onDestory called");
+// Log.d("XXX","onDestory called");
super.onDestroy();
}
@@ -395,7 +395,7 @@ public void onViewStateRestored(Bundle savedInstanceState) {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
- Log.d("XXX","onCreateView called");
+// Log.d("XXX","onCreateView called");
if (savedInstanceState!=null){
ld=savedInstanceState.getParcelable("lastDownload");
if (ld==null){
@@ -404,12 +404,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
if (ui.containsKey(ld.getDeviceID())){
ui.get(ld.getDeviceID()).update(ld);
} else {
- Log.w("XXX","UI does not contain "+ld.getDeviceID());
+// Log.w("XXX","UI does not contain "+ld.getDeviceID());
}
}
// UIDeviceList.get(0).update((DownloadObject) savedInstanceState.getSerializable("lastDownload"));
} else {
- Log.w("XXX", "Saved instance does not contain anything");
+// Log.w("XXX", "Saved instance does not contain anything");
}
View rootView = inflater.inflate(R.layout.fragment_device, container, false);
return rootView;
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/DeviceDownloadService.java b/mobile/src/main/java/com/ktind/cgm/bgscout/DeviceDownloadService.java
index 8efaec5..fd8c518 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/DeviceDownloadService.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/DeviceDownloadService.java
@@ -6,15 +6,12 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Binder;
-import android.os.Handler;
import android.os.IBinder;
-
import android.preference.PreferenceManager;
import android.util.Log;
@@ -49,7 +46,6 @@ public class DeviceDownloadService extends Service {
private static final String TAG = DeviceDownloadService.class.getSimpleName();
private ArrayList cgms=new ArrayList();
private Notification.Builder notificationBuilder;
- private Handler mHandler=new Handler();
IBinder mBinder=new LocalBinder();
private commandReceiver cr;
private ServiceState state=ServiceState.STOPPED;
@@ -59,6 +55,9 @@ public class DeviceDownloadService extends Service {
public void onCreate() {
super.onCreate();
+ // autostart
+// Intent mIntent = new Intent(DeviceDownloadService.this, DeviceDownloadService.class);
+// startService(mIntent);
// Intent uiIntent = new Intent("com.ktind.cgm.SERVICE_READY");
// sendBroadcast(uiIntent);
}
@@ -213,6 +212,8 @@ public DeviceDownloadService getServerInstance() {
}
}
+
+
private class commandReceiver extends BroadcastReceiver{
@Override
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/DeviceInterface.java b/mobile/src/main/java/com/ktind/cgm/bgscout/DeviceInterface.java
index da0546d..520ca4d 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/DeviceInterface.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/DeviceInterface.java
@@ -29,7 +29,7 @@
public interface DeviceInterface {
public void start();
public void stop();
- public void fireMonitors();
+ public void fireMonitors(DownloadObject dl);
public void stopMonitors();
// public void download();
}
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/DexcomG4/G4.java b/mobile/src/main/java/com/ktind/cgm/bgscout/DexcomG4/G4.java
index 1330428..9b8c664 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/DexcomG4/G4.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/DexcomG4/G4.java
@@ -3,9 +3,14 @@
import android.content.Context;
import android.util.Log;
-import com.google.android.gms.analytics.HitBuilders;
-import com.google.android.gms.analytics.Tracker;
-import com.ktind.cgm.bgscout.*;
+import com.ktind.cgm.bgscout.BitTools;
+import com.ktind.cgm.bgscout.CGMTransportAbstract;
+import com.ktind.cgm.bgscout.Constants;
+import com.ktind.cgm.bgscout.DeviceException;
+import com.ktind.cgm.bgscout.DeviceIOException;
+import com.ktind.cgm.bgscout.GlucoseUnit;
+import com.ktind.cgm.bgscout.NoDeviceFoundException;
+import com.ktind.cgm.bgscout.OperationNotSupportedException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -60,10 +65,17 @@ public class G4 {
CGMTransportAbstract cgmTransport;
protected GlucoseUnit unit;
protected Context context;
+// TimeZone tz;
+// long timeZoneOffset;
public G4(Context context){
this.context=context;
cgmTransport=new G4USBSerialTransport(context);
+// Calendar cal = Calendar.getInstance();
+// tz = cal.getTimeZone();
+// timeZoneOffset=tz.getRawOffset()/1000;
+// if (tz.inDaylightTime(new Date()))
+// timeZoneOffset+=3600; // 1 hour for daylight time if it is observed
}
public int getDeviceBattery() throws OperationNotSupportedException, NoDeviceFoundException, DeviceIOException {
@@ -84,7 +96,7 @@ public boolean isConnected(){
public void setup() throws OperationNotSupportedException, NoDeviceFoundException, DeviceIOException {
if (cgmTransport.isOpen()) {
unit = getUnit();
- serialNum = getRcvrSerial();
+// serialNum = getRcvrSerial();
cgmBattery=getBatteryLevel();
}else{
Log.e(TAG,"Unable to setup device that I am not connected to");
@@ -252,11 +264,11 @@ public void syncTimeToDevice() throws OperationNotSupportedException, NoDeviceFo
}
public long getDisplayTimeLong() throws OperationNotSupportedException, NoDeviceFoundException, DeviceIOException {
- Calendar mCalendar = new GregorianCalendar();
- TimeZone mTimeZone = mCalendar.getTimeZone();
+// Calendar mCalendar = new GregorianCalendar();
+// TimeZone mTimeZone = mCalendar.getTimeZone();
long dispTime=G4Constants.RECEIVERBASEDATE+getDisplayTimeOffsetLong()*1000L+getSystemTimeLong()*1000L;
- if (mTimeZone.inDaylightTime(new Date()))
- dispTime-=3600000L;
+// if (mTimeZone.inDaylightTime(new Date()))
+// dispTime-=3600000L;
Log.v(TAG,"getDisplayTimeLong: "+dispTime);
return dispTime;
}
@@ -591,7 +603,7 @@ private String getParam(G4RecType recType,String param) throws DeviceIOException
for (G4DBPage page:pages){
int i;
// Ugly code to capture the null terminated string
- for (i = 0; i < page.PageData.length && page.PageData[i] != 0x00; i++) { }
+ for (i = 1; i < page.PageData.length && page.PageData[i] != 0x00; i++) { }
if (i<8)
throw new DeviceIOException("Expected larger page data in getParam for " + recType.toString() + " parameter: " + param);
// Strip the header and reduce the size of the string by the header length
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/DownloadObject.java b/mobile/src/main/java/com/ktind/cgm/bgscout/DownloadObject.java
index 59f6c05..3ce2632 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/DownloadObject.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/DownloadObject.java
@@ -4,13 +4,10 @@
import android.os.Parcelable;
import android.util.Log;
-import com.ktind.cgm.bgscout.DexcomG4.G4EGVSpecialValue;
-
-
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Calendar;
import java.util.Date;
-
+import java.util.TimeZone;
/**
Copyright (c) 2014, Kevin Lee (klee24@gmail.com)
@@ -47,29 +44,65 @@ public class DownloadObject implements Parcelable {
protected ArrayList egvRecords=new ArrayList();
protected DownloadStatus status;
- protected String specialValueMessage=null;
+// protected String specialValueMessage=null;
protected int deviceBattery;
protected float uploaderBattery;
- protected GlucoseUnit unit;
-// protected ArrayList> alertMessages=new ArrayList>();
-// protected HashMap downloadMessage=new HashMap();
+ // FIXME - default to MGDL for now.
+ protected GlucoseUnit unit=GlucoseUnit.MGDL;
protected String deviceID;
- protected Date lastReadingDate;
+ protected Long lastReadingDate;
protected String driver;
- private Date downloadDate;
+ protected Long downloadDate;
+
+ public Date getDownloadDate(){
+ return new Date(downloadDate);
+ }
- public Date getDownloadDate() {
- return downloadDate;
+// private Date adjustForLocal(Date date){
+// }
+
+ private long adjustForLocal(long date){
+ Calendar cal = Calendar.getInstance();
+ TimeZone tz = cal.getTimeZone();
+ if (tz.inDaylightTime(new Date(date)))
+ date+=3600000;
+ return date;
}
- public DownloadObject setDownloadDate(Date downloadDate) {
- this.downloadDate = downloadDate;
+ private long adjustForUTC(long date){
+ Calendar cal = Calendar.getInstance();
+ TimeZone tz = cal.getTimeZone();
+ if (tz.inDaylightTime(new Date(date)))
+ date-=3600000;
+ return date;
+ }
+
+ public void adjustDataToLocalTime(){
+ lastReadingDate=adjustForLocal(lastReadingDate);
+// downloadDate=adjustForLocal(downloadDate);
+ for (int index=0;index(Arrays.asList(egvRecords)));
+// setStatus(downloadStatus);
// }
- public DownloadObject(AbstractDevice device, EGVRecord[] egvRecords, DownloadStatus downloadStatus){
+ public DownloadObject(AbstractDevice device, ArrayList egvRecords, DownloadStatus downloadStatus){
super();
setDeviceID(device.getDeviceIDStr());
- setEgvRecords(new ArrayList(Arrays.asList(egvRecords)));
+ setEgvRecords(egvRecords);
setStatus(downloadStatus);
}
@@ -167,18 +195,18 @@ public DownloadObject setUploaderBattery(float uploaderBattery) {
return this;
}
- public String getSpecialValueMessage() {
- return specialValueMessage;
- }
-
- public DownloadObject setSpecialValueMessage(String specialValueMessage) {
- this.specialValueMessage = specialValueMessage;
- return this;
- }
+// public String getSpecialValueMessage() {
+// return specialValueMessage;
+// }
+//
+// public DownloadObject setSpecialValueMessage(String specialValueMessage) {
+// this.specialValueMessage = specialValueMessage;
+// return this;
+// }
- public EGVRecord[] getEgvRecords() {
- return egvRecords.toArray(new EGVRecord[egvRecords.size()]);
- }
+// public EGVRecord[] getEgvRecords() {
+// return egvRecords.toArray(new EGVRecord[egvRecords.size()]);
+// }
public ArrayList getEgvArrayListRecords() {
return egvRecords;
@@ -190,10 +218,10 @@ public DownloadObject setEgvRecords(ArrayList records) {
return this;
}
- public DownloadObject setEgvRecords(EGVRecord[] records){
- this.egvRecords=new ArrayList(Arrays.asList(records));
- return this;
- }
+// public DownloadObject setEgvRecords(EGVRecord[] records){
+// this.egvRecords=new ArrayList(Arrays.asList(records));
+// return this;
+// }
public DownloadStatus getStatus() {
return status;
@@ -227,7 +255,7 @@ public Date getLastReadingDate() {
// Then check to see if there are any records
// finally set to now - 2.5 hours.
if (this.lastReadingDate!=null)
- return this.lastReadingDate;
+ return new Date(this.lastReadingDate);
// Log.e(TAG,"length=>"+egvRecords.length);
// Log.e(TAG,"Date=>"+egvRecords[egvRecords.length-1].date);
if (this.egvRecords != null && this.egvRecords.size() > 0)
@@ -237,26 +265,10 @@ public Date getLastReadingDate() {
}
public DownloadObject setLastReadingDate(Date date){
- this.lastReadingDate=date;
+ this.lastReadingDate=date.getTime();
return this;
}
-// public void trimReadingsAfter(Long afterDateLong){
-// ArrayList recs=egvRecords;
-// Log.d(TAG,"Size before trim: "+recs.size());
-// Date afterDate=new Date(afterDateLong);
-// for (Iterator iterator = recs.iterator(); iterator.hasNext(); ) {
-// EGVRecord record = iterator.next();
-// // trim anything after the date UNLESS that means we trim everything. Let's keep
-// // the last record in there just in case. Need to find a better solution to this
-// // the method doesn't reflect its purpose
-// if (! record.getDate().after(afterDate) && recs.size()>1)
-// iterator.remove();
-// }
-// Log.d(TAG,"Size after trim: "+recs.size()+" vs original "+egvRecords.size());
-// }
-
-
public int getLastReading() throws NoDataException {
return getLastRecord().getEgv();
}
@@ -289,12 +301,13 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeByte((byte) (isRemoteDevice ? 1 : 0));
dest.writeTypedList(egvRecords);
dest.writeInt(status.getVal());
- dest.writeString(specialValueMessage);
+// dest.writeString(specialValueMessage);
dest.writeInt(deviceBattery);
dest.writeFloat(uploaderBattery);
dest.writeInt(unit.getValue());
dest.writeString(deviceID);
- dest.writeLong(lastReadingDate.getTime());
+ dest.writeLong(lastReadingDate);
+ dest.writeLong(downloadDate);
}
public static final Parcelable.Creator CREATOR
@@ -313,12 +326,13 @@ protected DownloadObject(Parcel in) {
isRemoteDevice=in.readByte() != 0;
in.readTypedList(egvRecords,EGVRecord.CREATOR);
status=DownloadStatus.values()[in.readInt()];
- specialValueMessage=in.readString();
+// specialValueMessage=in.readString();
deviceBattery=in.readInt();
uploaderBattery=in.readFloat();
unit=GlucoseUnit.values()[in.readInt()];
deviceID=in.readString();
- lastReadingDate=new Date(in.readLong());
+ lastReadingDate=in.readLong();
+ downloadDate=in.readLong();
}
@Override
@@ -364,10 +378,15 @@ public boolean equals(Object o) {
Log.d(TAG, "Failed comparison on lastReadingDate");
return false;
}
- if (specialValueMessage != null ? !specialValueMessage.equals(that.specialValueMessage) : that.specialValueMessage != null) {
- Log.d(TAG, "Failed comparison on specialValueMessage");
+ if (downloadDate != null ? !downloadDate.equals(that.downloadDate) : that.downloadDate != null) {
+ Log.d(TAG, "Failed comparison on downloadDate");
return false;
}
+
+// if (specialValueMessage != null ? !specialValueMessage.equals(that.specialValueMessage) : that.specialValueMessage != null) {
+// Log.d(TAG, "Failed comparison on specialValueMessage");
+// return false;
+// }
if (status != that.status){
Log.d(TAG, "Failed comparison on status");
return false;
@@ -386,7 +405,7 @@ public int hashCode() {
result = 31 * result + (isRemoteDevice ? 1 : 0);
result = 31 * result + (egvRecords != null ? egvRecords.hashCode() : 0);
result = 31 * result + status.hashCode();
- result = 31 * result + (specialValueMessage != null ? specialValueMessage.hashCode() : 0);
+// result = 31 * result + (specialValueMessage != null ? specialValueMessage.hashCode() : 0);
result = 31 * result + deviceBattery;
result = 31 * result + (uploaderBattery != +0.0f ? Float.floatToIntBits(uploaderBattery) : 0);
result = 31 * result + unit.hashCode();
@@ -394,6 +413,7 @@ public int hashCode() {
// result = 31 * result + (downloadMessage != null ? downloadMessage.hashCode() : 0);
result = 31 * result + deviceID.hashCode();
result = 31 * result + (lastReadingDate != null ? lastReadingDate.hashCode() : 0);
+ result = 31 * result + (downloadDate != null ? downloadDate.hashCode() : 0);
return result;
}
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/EGVRecord.java b/mobile/src/main/java/com/ktind/cgm/bgscout/EGVRecord.java
index 51a2fcb..32d6c14 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/EGVRecord.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/EGVRecord.java
@@ -37,12 +37,12 @@
public class EGVRecord implements Parcelable {
private static final String TAG = EGVRecord.class.getSimpleName();
protected int egv;
- protected Date date;
+ protected Long date;
protected Trend trend=Trend.NONE;
protected GlucoseUnit unit=GlucoseUnit.MGDL;
protected boolean isNew=true;
- EGVRecord(int egv,Date date,Trend trend,boolean isNew){
+ EGVRecord(int egv,long date,Trend trend,boolean isNew){
super();
this.setEgv(egv);
this.setDate(date);
@@ -50,7 +50,13 @@ public class EGVRecord implements Parcelable {
this.setNew(isNew);
}
-
+ EGVRecord(EGVRecord record){
+ this.egv=record.getEgv();
+ this.date=record.date;
+ this.trend=record.getTrend();
+ this.unit=record.getUnit();
+ this.isNew=record.isNew;
+ }
public EGVRecord(){
super();
@@ -73,13 +79,17 @@ public void setEgv(int egv) {
}
public Date getDate() {
- return date;
+ return new Date(date);
}
- public void setDate(Date date) {
+ public void setDate(long date) {
this.date = date;
}
+ public void setDate(Date date){
+ setDate(date.getTime());
+ }
+
public Trend getTrend() {
return trend;
}
@@ -104,7 +114,7 @@ public int describeContents() {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(egv);
- dest.writeLong(date.getTime());
+ dest.writeLong(date);
dest.writeInt(trend.getVal());
dest.writeInt(unit.getValue());
dest.writeByte((byte) (isNew ? 1 : 0));
@@ -123,7 +133,7 @@ public EGVRecord[] newArray(int size) {
private EGVRecord(Parcel in) {
egv=in.readInt();
- date=new Date(in.readLong());
+ date=in.readLong();
trend=Trend.values()[in.readInt()];
unit=GlucoseUnit.values()[in.readInt()];
isNew = in.readByte() != 0;
@@ -144,11 +154,16 @@ public boolean equals(Object o) {
Log.d(TAG, "EGV Record failed on comparison isNew");
return false;
}
- if (!date.equals(record.date)){
+// if (!date.equals(record.date)){
+// Log.d(TAG, "EGV Record failed on comparison date");
+// return false;
+// }
+ if (date==record.date){
Log.d(TAG, "EGV Record failed on comparison date");
return false;
}
- if (trend != record.trend){
+
+ if (trend != record.trend){
Log.d(TAG, "EGV Record failed on comparison trend");
return false;
}
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/G4CGMDevice.java b/mobile/src/main/java/com/ktind/cgm/bgscout/G4CGMDevice.java
index 0fd9d7f..61455fa 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/G4CGMDevice.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/G4CGMDevice.java
@@ -2,7 +2,6 @@
import android.content.Context;
import android.content.SharedPreferences;
-import android.os.Handler;
import android.util.Log;
import com.google.android.gms.analytics.HitBuilders;
@@ -11,11 +10,9 @@
import com.ktind.cgm.bgscout.DexcomG4.G4EGVRecord;
import com.ktind.cgm.bgscout.DexcomG4.G4EGVSpecialValue;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
-import java.util.Iterator;
/**
@@ -80,7 +77,7 @@ public void start() {
@Override
protected DownloadObject doDownload() {
- String specialMessage="";
+// String specialMessage="";
int deviceBattery=-1;
float uploaderBattery=getUploaderBattery()*100.0f;
@@ -112,7 +109,7 @@ protected DownloadObject doDownload() {
for (G4EGVSpecialValue specialValue : G4EGVSpecialValue.values()) {
if (lastBG == specialValue.getValue()) {
status = DownloadStatus.SPECIALVALUE;
- specialMessage=G4EGVSpecialValue.getEGVSpecialValue(lastBG).toString();
+// specialMessage=G4EGVSpecialValue.getEGVSpecialValue(lastBG).toString();
break;
}
}
@@ -159,11 +156,12 @@ protected DownloadObject doDownload() {
.setStatus(status)
.setEgvRecords(egvList)
.setDriver(driver)
- .setDownloadDate(new Date())
- .setSpecialValueMessage(specialMessage);
+ .setDownloadDate(new Date());
+// .setSpecialValueMessage(specialMessage);
// .addAlertMessages(alerts);
editor.putLong(deviceIDStr+"_lastG4Download",lastReadingDateRecord);
editor.apply();
+// Log.d("XXX","downloadDate=>"+ddo.getDownloadDate());
setLastDownloadObject(ddo);
return ddo;
}
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/G4DownloadAnalyzer.java b/mobile/src/main/java/com/ktind/cgm/bgscout/G4DownloadAnalyzer.java
index ba0b668..837bb7c 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/G4DownloadAnalyzer.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/G4DownloadAnalyzer.java
@@ -66,7 +66,7 @@ protected void checkSpecialValues() {
}else{
alertMessage=new AlertMessage(AlertLevels.WARN,"Unknown special value received from G4");
}
- downloadObject.addMessage(alertMessage,Conditions.DEVICEMSGS);
+ downloadObject.addMessage(alertMessage,Conditions.SPECIALVALUE);
}
}
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/MockDevice.java b/mobile/src/main/java/com/ktind/cgm/bgscout/MockDevice.java
index bcb0349..89f9cad 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/MockDevice.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/MockDevice.java
@@ -1,7 +1,6 @@
package com.ktind.cgm.bgscout;
import android.content.Context;
-import android.os.Handler;
import android.util.Log;
import java.io.IOException;
@@ -72,10 +71,11 @@ public void disconnect() {
private DownloadObject generateDownloadObject(){
Log.d(TAG,"Generating start object");
DownloadStatus downloadStatus=generateStatus();
- EGVRecord[] egvArray=new EGVRecord[1];
+ ArrayList egvArray=new ArrayList();
Random rand=new Random();
- egvArray[0]=new EGVRecord(rand.nextInt(362)+39,new Date(),Trend.values()[rand.nextInt(Trend.values().length)],true);
- egvHistory.add(egvArray[0]);
+ EGVRecord egvRecord=new EGVRecord(rand.nextInt(362)+39,new Date().getTime(),Trend.values()[rand.nextInt(Trend.values().length)],true);
+ egvArray.add(egvRecord);
+ egvHistory.add(egvRecord);
DownloadObject ddo=new DownloadObject(this,egvArray,downloadStatus);
ddo.setUnit(GlucoseUnit.MGDL).setLastReadingDate(new Date()).setUploaderBattery(rand.nextFloat()*100).setDeviceBattery(rand.nextInt(101));
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/MongoUploadMonitor.java b/mobile/src/main/java/com/ktind/cgm/bgscout/MongoUploadMonitor.java
index 6d2a9cc..44dfab8 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/MongoUploadMonitor.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/MongoUploadMonitor.java
@@ -3,10 +3,18 @@
import android.content.Context;
import android.util.Log;
-import com.mongodb.*;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.MongoClient;
+import com.mongodb.MongoClientURI;
+import com.mongodb.MongoException;
+import com.mongodb.MongoTimeoutException;
+import com.mongodb.WriteConcern;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Date;
/**
@@ -72,11 +80,11 @@ protected void doProcess(DownloadObject d) {
MongoClient mongoClient = new MongoClient(uri);
db = mongoClient.getDB(uri.getDatabase());
deviceData = db.getCollection(collectionName);
- EGVRecord[] r=d.getEgvRecords();
+ ArrayList r=d.getEgvArrayListRecords();
int uploadCount=0;
for (EGVRecord sr:r) {
BasicDBObject data = new BasicDBObject();
- if (sr.isNew()) {
+// if (sr.isNew()) {
data.put("name", d.getDeviceName());
data.put("trend", sr.getTrend().getVal());
@@ -90,9 +98,9 @@ protected void doProcess(DownloadObject d) {
deviceData.update(data, data, true, false, WriteConcern.UNACKNOWLEDGED);
uploadCount+=1;
Log.v(TAG, "Added Record - EGV: " + sr.getEgv() + " Trend: " + sr.getTrend().getNsString() + " Date: " + new SimpleDateFormat("MM/dd/yyy hh:mm:ss aa").format(sr.getDate()));
- }
+// }
}
- Log.i(TAG,"Records processed: "+r.length+" Records Uploaded: "+uploadCount);
+ Log.i(TAG,"Records processed: "+r.size()+" Records Uploaded: "+uploadCount);
if (!d.isRemoteDevice()) {
BasicDBObject data = new BasicDBObject();
data.put("name", d.getDeviceName());
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/MqttUploader.java b/mobile/src/main/java/com/ktind/cgm/bgscout/MqttUploader.java
index f4a25bb..5c30e4d 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/MqttUploader.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/MqttUploader.java
@@ -57,6 +57,7 @@ public MqttUploader(String n, int devID ,Context context) {
@Override
protected void doProcess(DownloadObject d) {
+// Log.d("XXX","monitor downloadDate=>"+d.getDownloadDate());
Gson gson=new Gson();
if (initialUpload || (lastDownload!=null && ! lastDownload.equals(d))) {
mqttMgr.publish(gson.toJson(d), "/entries/sgv");
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/NightScoutUpload.java b/mobile/src/main/java/com/ktind/cgm/bgscout/NightScoutUpload.java
index 0daf823..fbf4652 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/NightScoutUpload.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/NightScoutUpload.java
@@ -75,9 +75,9 @@ protected void doProcess(DownloadObject d) {
Log.w(TAG,"Nightscout base API url is not set for "+getName()+"("+deviceIDStr+")");
return;
}
- int numRecs=d.getEgvRecords().length;
+ int numRecs=d.getEgvArrayListRecords().size();
int index=0;
- for (EGVRecord record : d.getEgvRecords()) {
+ for (EGVRecord record : d.getEgvArrayListRecords()) {
if (!record.isNew())
continue;
// hack to only send the last record for now...
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/PushOverMonitor.java b/mobile/src/main/java/com/ktind/cgm/bgscout/PushOverMonitor.java
index 79c4b65..2201a86 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/PushOverMonitor.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/PushOverMonitor.java
@@ -71,8 +71,8 @@ protected void doProcess(DownloadObject d) {
String apiSecret="a6As5oZJhxLayHPKM2AGJSWG6VLMDk";
String postURL="https://api.pushover.net/1/messages.json";
Log.i(TAG, "Posting to: " + postURL);
- Log.d(TAG,"Number of records: "+d.getEgvRecords().length);
- for (EGVRecord record : d.getEgvRecords()) {
+ Log.d(TAG,"Number of records: "+d.getEgvArrayListRecords().size());
+ for (EGVRecord record : d.getEgvArrayListRecords()) {
try {
HttpPost post = new HttpPost(postURL);
final List nvps = new ArrayList();
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/RemoteMQTTDevice.java b/mobile/src/main/java/com/ktind/cgm/bgscout/RemoteMQTTDevice.java
index df4ee71..045138b 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/RemoteMQTTDevice.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/RemoteMQTTDevice.java
@@ -2,8 +2,6 @@
import android.content.Context;
import android.content.SharedPreferences;
-import android.os.Handler;
-import android.os.Looper;
import android.preference.PreferenceManager;
import android.util.Log;
@@ -12,10 +10,10 @@
import com.ktind.cgm.bgscout.mqtt.MQTTMgr;
import com.ktind.cgm.bgscout.mqtt.MQTTMgrObserverInterface;
-import java.io.IOException;
-
import org.eclipse.paho.client.mqttv3.MqttMessage;
+import java.io.IOException;
+
/**
Copyright (c) 2014, Kevin Lee (klee24@gmail.com)
All rights reserved.
@@ -123,13 +121,13 @@ public void onMessage(String topic, MqttMessage msg) {
DownloadObject ddo=gson.fromJson(new String(msg.getPayload()),DownloadObject.class);
Log.d(TAG,"Message from device: "+ddo.getDeviceName());
setLastDownloadObject(ddo);
- onDownload();
+ onDownload(ddo);
}
}
@Override
public void onDisconnect() {
lastDownloadObject.setStatus(DownloadStatus.REMOTEDISCONNECTED);
- fireMonitors();
+// fireMonitors(lastDownloadObject);
}
}
diff --git a/mobile/src/main/java/com/ktind/cgm/bgscout/RemoteMongoDevice.java b/mobile/src/main/java/com/ktind/cgm/bgscout/RemoteMongoDevice.java
index ba2dda8..711b769 100644
--- a/mobile/src/main/java/com/ktind/cgm/bgscout/RemoteMongoDevice.java
+++ b/mobile/src/main/java/com/ktind/cgm/bgscout/RemoteMongoDevice.java
@@ -2,11 +2,16 @@
import android.content.Context;
import android.content.SharedPreferences;
-import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
-import com.mongodb.*;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+import com.mongodb.DBCollection;
+import com.mongodb.DBCursor;
+import com.mongodb.DBObject;
+import com.mongodb.MongoClient;
+import com.mongodb.MongoClientURI;
import java.net.UnknownHostException;
import java.util.ArrayList;
@@ -50,7 +55,7 @@ public class RemoteMongoDevice extends AbstractPollDevice {
DB db;
MongoClient mongoClient = null;
long lastQueryDate;
- EGVRecord[] lastRecord=new EGVRecord[1];
+ EGVRecord lastRecord;
public RemoteMongoDevice(String n,int deviceID,Context appContext){
super(n,deviceID,appContext,"RemoteMongo");
@@ -87,7 +92,7 @@ protected DownloadObject doDownload() {
// ddo.setDevice(this);
ddo.setStatus(DownloadStatus.APPLICATIONERROR);
ArrayList egvRecords=new ArrayList();
- ddo.setEgvRecords(new EGVRecord[0]);
+// ddo.setEgvRecords(egvRecords);
try {
mongoClient = new MongoClient(uri);
db = mongoClient.getDB(uri.getDatabase());
@@ -106,19 +111,20 @@ protected DownloadObject doDownload() {
EGVRecord record;
if (recQueryDate>lastQueryDate){
lastQueryDate=recQueryDate;
- record=new EGVRecord(bgValue,recDate,trend,true);
- lastRecord[0]=record;
+ record=new EGVRecord(bgValue,recQueryDate,trend,true);
+ lastRecord=record;
}else{
- record=new EGVRecord(bgValue,recDate,trend,false);
+ record=new EGVRecord(bgValue,recQueryDate,trend,false);
}
egvRecords.add(record);
- ddo.setEgvRecords(egvRecords.toArray(new EGVRecord[egvRecords.size()]));
+ ddo.setEgvRecords(egvRecords);
}
ddo.setStatus(DownloadStatus.SUCCESS);
- //FIXME there has to be a more efficient way
- if (lastRecord!=null && ddo.getEgvRecords().length==0){
+ if (lastRecord!=null && ddo.getEgvArrayListRecords().size()==0){
ddo.setStatus(DownloadStatus.NODATA);
- ddo.setEgvRecords(lastRecord);
+ ArrayList lastDL = new ArrayList();
+ lastDL.add(lastRecord);
+ ddo.setEgvRecords(lastDL);
}
} finally {
@@ -129,7 +135,7 @@ protected DownloadObject doDownload() {
}catch(UnknownHostException e){
Log.e(TAG,"Unable to connect to MongoDB URI",e);
ddo.setStatus(DownloadStatus.DEVICENOTFOUND);
- ddo.setEgvRecords(new EGVRecord[0]);
+// ddo.setEgvRecords(new ArrayList());
}
lastDownloadObject=ddo;
return ddo;
diff --git a/mobile/src/main/res/xml/analytics_global_config.xml b/mobile/src/main/res/xml/analytics_global_config.xml
index 0142bb4..8bed3aa 100644
--- a/mobile/src/main/res/xml/analytics_global_config.xml
+++ b/mobile/src/main/res/xml/analytics_global_config.xml
@@ -1,6 +1,6 @@
- verbose
+ warning
1000
false
\ No newline at end of file