Skip to content

Commit

Permalink
-Bug fixes
Browse files Browse the repository at this point in the history
--G4 fixes for serial numbers that start with a null character?
-Added regular updates to android notification
-General code cleanup
-Switched dates to epoch in EGVRecord and DownloadObject rather than Date object.
  • Loading branch information
ktind committed Sep 7, 2014
1 parent 5859463 commit 8629045
Show file tree
Hide file tree
Showing 36 changed files with 517 additions and 198 deletions.
9 changes: 9 additions & 0 deletions .idea/libraries/acra_4_5_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/gson_2_3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/guava_14_0_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/mongo_java_driver_2_12_3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/org_eclipse_paho_client_mqttv3_1_0_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/libraries/play_services_wearable_5_0_77.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/protobuf_java_2_5_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/support_annotations_20_0_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/support_v13_20_0_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/support_v4_20_0_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/libraries/wearable_1_0_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
44 changes: 23 additions & 21 deletions mobile/src/main/java/com/ktind/cgm/bgscout/AbstractDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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();
}
Expand Down Expand Up @@ -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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -148,6 +149,7 @@ public void savelastSuccessDate(Date date){

@Override
public void stop(){
state=State.STOPPED;
Log.i(TAG,"Stopping monitor "+monitorType+" for "+name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ktind.cgm.bgscout;

import android.content.Context;
import android.os.Handler;

/**
Copyright (c) 2014, Kevin Lee ([email protected])
Expand Down Expand Up @@ -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() {
Expand Down
Loading

0 comments on commit 8629045

Please sign in to comment.