Skip to content

Commit

Permalink
-Experimental protobuf support
Browse files Browse the repository at this point in the history
-Support messages from standard uploader
-Cleanup EGVRecord
-Cleanup of the notification code
  • Loading branch information
ktind committed Sep 21, 2014
1 parent 158ca44 commit fcb5f2b
Show file tree
Hide file tree
Showing 21 changed files with 1,451 additions and 10,970 deletions.
9 changes: 0 additions & 9 deletions .idea/libraries/acra_4_5_0.xml

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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 10
versionName "0.1.1"
versionCode 12
versionName "0.1.2"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public class AndroidNotificationMonitor extends AbstractMonitor {
protected boolean isTickCounterSyncd=false;
protected boolean isScreenOn=true;
protected WearableExtender wearableExtender;
protected boolean runInit =true;
// protected boolean firstReading = true;
// protected NotificationCompat.WearableExtender wearableExtender;


Expand Down Expand Up @@ -133,6 +135,7 @@ public void init(){
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));
runInit =false;
}

public String getPhoneNum() {
Expand Down Expand Up @@ -209,7 +212,7 @@ private void syncTickCounter(){
}

private Notification buildNotification(AnalyzedDownload dl){
setDefaults();
setDefaults(dl);
setSound(dl);
setTicker(dl);
setActions(dl);
Expand All @@ -223,6 +226,13 @@ protected void setSound(AnalyzedDownload dl){
if (isSilenced)
return;
ArrayList<Conditions> conditions=dl.getConditions();
if ( !conditions.contains(Conditions.CRITICALHIGH)
&& !conditions.contains(Conditions.WARNHIGH)
&& !conditions.contains(Conditions.WARNLOW)
&& !conditions.contains(Conditions.CRITICALLOW)) {
return;
}

Uri uri = Uri.EMPTY;
// allows us to give some sounds higher precedence than others
// I'm thinking I'll need to set a priority to the enums to break ties but this should work for now
Expand Down Expand Up @@ -365,8 +375,21 @@ public void setTicker(AnalyzedDownload dl){

}

private void setDefaults(){
this.notifBuilder=new NotificationCompat.Builder(context)
private void setDefaults(AnalyzedDownload dl){
// this.notifBuilder=new NotificationCompat.Builder(context)
ArrayList<Conditions> conditions=dl.getConditions();
notifBuilder = new NotificationCompat.Builder(context);
if ( conditions.contains(Conditions.CRITICALHIGH)
|| conditions.contains(Conditions.WARNHIGH)
|| conditions.contains(Conditions.WARNLOW)
|| conditions.contains(Conditions.CRITICALLOW)) {

notifBuilder.setPriority(Notification.PRIORITY_MAX);
// firstReading=false;
} else {
notifBuilder.setPriority(Notification.PRIORITY_DEFAULT);
}
notifBuilder
.setContentTitle(name)
.setContentText("Default text")
.setContentIntent(contentIntent)
Expand Down Expand Up @@ -687,7 +710,7 @@ public void updateNotification(){
if (previousDownloads.size() > 0) {
AbstractDownloadAnalyzer downloadAnalyzer = new G4DownloadAnalyzer(previousDownloads.get(previousDownloads.size() - 1), context);
analyzedDownload = downloadAnalyzer.analyze();
setDefaults();
setDefaults(analyzedDownload);
setActions(analyzedDownload);
setContent(analyzedDownload);
setIcon(analyzedDownload);
Expand Down Expand Up @@ -715,6 +738,8 @@ public class tickReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context mContext, Intent intent) {
if (intent.getAction().equals("android.intent.action.TIME_TICK")) {
if (analyzedDownload==null)
return;
try {
Log.d(TAG, "Comparing "+(new Date().getTime()-analyzedDownload.getLastRecordReadingDate().getTime()));
if (new Date().getTime()-analyzedDownload.getLastRecordReadingDate().getTime()< 310000 && ! isScreenOn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
for (final AbstractDevice cgm : cgms) {
cgm.start();
}
startForeground(24, notification);
startForeground(0, notification);
super.onStartCommand(intent, flags, startId);
state = ServiceState.STARTED;
}
Expand Down
26 changes: 1 addition & 25 deletions mobile/src/main/java/com/ktind/cgm/bgscout/EGVRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,19 @@ public class EGVRecord implements Parcelable {
protected Long date;
protected Trend trend=Trend.NONE;
protected GlucoseUnit unit=GlucoseUnit.MGDL;
// protected boolean isNew=true;

EGVRecord(int egv,long date,Trend trend,boolean isNew){
EGVRecord(int egv,long date,Trend trend){
super();
this.setEgv(egv);
this.setDate(date);
this.setTrend(trend);
// 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(){
Expand Down Expand Up @@ -98,14 +95,6 @@ public void setTrend(Trend trend) {
this.trend = trend;
}

// public boolean isNew() {
// return isNew;
// }

// public void setNew(boolean isNew) {
// this.isNew = isNew;
// }

@Override
public int describeContents() {
return 0;
Expand All @@ -117,7 +106,6 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(date);
dest.writeInt(trend.getVal());
dest.writeInt(unit.getValue());
// dest.writeByte((byte) (isNew ? 1 : 0));
}

public static final Parcelable.Creator<EGVRecord> CREATOR
Expand All @@ -136,7 +124,6 @@ private EGVRecord(Parcel in) {
date=in.readLong();
trend=Trend.values()[in.readInt()];
unit=GlucoseUnit.values()[in.readInt()];
// isNew = in.readByte() != 0;
}

@Override
Expand All @@ -150,14 +137,6 @@ public boolean equals(Object o) {
Log.d(TAG, "EGV Record failed on comparison egv");
return false;
}
// if (isNew != record.isNew){
// Log.d(TAG, "EGV Record failed on comparison isNew");
// return false;
// }
// 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;
Expand All @@ -171,8 +150,6 @@ public boolean equals(Object o) {
Log.d(TAG, "EGV Record failed on comparison unit");
return false;
}
// return (unit != record.unit);

return true;
}

Expand All @@ -182,7 +159,6 @@ public int hashCode() {
result = 31 * result + date.hashCode();
result = 31 * result + trend.hashCode();
result = 31 * result + unit.hashCode();
// result = 31 * result + (isNew ? 1 : 0);
return result;
}
}
2 changes: 1 addition & 1 deletion mobile/src/main/java/com/ktind/cgm/bgscout/MockDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private DownloadObject generateDownloadObject(){
DownloadStatus downloadStatus=generateStatus();
ArrayList<EGVRecord> egvArray=new ArrayList<EGVRecord>();
Random rand=new Random();
EGVRecord egvRecord=new EGVRecord(rand.nextInt(362)+39,new Date().getTime(),Trend.values()[rand.nextInt(Trend.values().length)],true);
EGVRecord egvRecord=new EGVRecord(rand.nextInt(362)+39,new Date().getTime(),Trend.values()[rand.nextInt(Trend.values().length)]);
egvArray.add(egvRecord);
egvHistory.add(egvRecord);

Expand Down
37 changes: 36 additions & 1 deletion mobile/src/main/java/com/ktind/cgm/bgscout/RemoteMQTTDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.protobuf.InvalidProtocolBufferException;
import com.ktind.cgm.bgscout.mqtt.MQTTMgr;
import com.ktind.cgm.bgscout.mqtt.MQTTMgrObserverInterface;

import org.eclipse.paho.client.mqttv3.MqttMessage;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;

/**
Copyright (c) 2014, Kevin Lee ([email protected])
Expand Down Expand Up @@ -82,7 +85,7 @@ public void run() {
mqttMgr.initConnect(url);
Log.d(TAG, "Subscribe start");
// mqttMgr.subscribe("/entries/sgv", "/uploader");
mqttMgr.subscribe("/entries/sgv");
mqttMgr.subscribe("/entries/sgv","/protobuf/test2");
Log.d(TAG,"Connect ended");
}
}).start();
Expand Down Expand Up @@ -124,6 +127,38 @@ public void onMessage(String topic, MqttMessage msg) {
setLastDownloadObject(ddo);
onDownload(ddo);
}
if (topic.equals("/protobuf/test2")){
try {
SGV.ProposedCookieMonsterG4Download protoBufDownload=SGV.ProposedCookieMonsterG4Download.parseFrom(msg.getPayload());
Log.d("XXX", "SGV Download status: "+protoBufDownload.getDownloadStatus().name());
Log.d("XXX", "SGV Units: " + protoBufDownload.getUnits().name());
Log.d("XXX", "SGV Download timestamp: "+new Date(protoBufDownload.getDownloadTimestamp()));
Log.d("XXX", "SGV Uploader battery: " + protoBufDownload.getUploaderBattery());
Log.d("XXX", "SGV BG: "+protoBufDownload.getSgv(0).getSgv());
Log.d("XXX", "SGV direction: "+protoBufDownload.getSgv(0).getDirection().name());
Log.d("XXX", "SGV timestamp: "+new Date(protoBufDownload.getSgv(0).getTimestamp()));

ArrayList<EGVRecord> egvRecords = new ArrayList<EGVRecord>();
for (SGV.ProposeCookieMonsterSGVG4 sgv: protoBufDownload.getSgvList()){
egvRecords.add(new EGVRecord(sgv.getSgv(),sgv.getTimestamp(),Trend.values()[sgv.getDirection().getNumber()]));
}
DownloadObject downloadObject=new DownloadObject();
// TODO: once more CGMS are decoded we should consider adding some of these to the Protobuf definition.
downloadObject.setUploaderBattery(protoBufDownload.getUploaderBattery())
.setDownloadDate(new Date(protoBufDownload.getDownloadTimestamp()))
.setEgvRecords(egvRecords)
.setRemoteDevice(false)
.setDeviceName("dexcom")
.setUnit(GlucoseUnit.values()[protoBufDownload.getUnits().getNumber()])
.setDeviceID("device_1")
.setLastReadingDate(egvRecords.get(egvRecords.size()-1).getDate())
.setDriver("DexcomG4");
setLastDownloadObject(downloadObject);
onDownload(downloadObject);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}

@Override
Expand Down
Loading

0 comments on commit fcb5f2b

Please sign in to comment.