-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Full Protobuf support using SGV.proto
- Loading branch information
Showing
5 changed files
with
307 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,13 @@ | |
import android.content.Context; | ||
import android.util.Log; | ||
|
||
import com.google.gson.Gson; | ||
import com.ktind.cgm.bgscout.mqtt.MQTTMgr; | ||
import com.ktind.cgm.bgscout.mqtt.MQTTMgrObserverInterface; | ||
|
||
import org.eclipse.paho.client.mqttv3.MqttMessage; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
Copyright (c) 2014, Kevin Lee ([email protected]) | ||
All rights reserved. | ||
|
@@ -39,6 +40,7 @@ public class MqttUploader extends AbstractMonitor implements MQTTMgrObserverInte | |
private static final String TAG = MqttUploader.class.getSimpleName(); | ||
protected DownloadObject lastDownload=null; | ||
protected boolean initialUpload=true; | ||
public static final String PROTOBUF_DOWNLOAD_TOPIC="/downloads/protobuf"; | ||
|
||
protected MQTTMgr mqttMgr; | ||
|
||
|
@@ -58,10 +60,30 @@ 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(); | ||
// Gson gson=new Gson(); | ||
if (initialUpload || (lastDownload!=null && ! lastDownload.equals(d))) { | ||
mqttMgr.publish(gson.toJson(d), "/entries/sgv"); | ||
initialUpload=false; | ||
try { | ||
SGV.CookieMonsterG4Download.Builder recordBuilder = SGV.CookieMonsterG4Download.newBuilder() | ||
.setDownloadStatus(SGV.CookieMonsterG4Download.DownloadStatus.SUCCESS) | ||
.setDownloadTimestamp(new Date().getTime()) | ||
.setUploaderBattery((int) d.getUploaderBattery()) | ||
.setReceiverBattery(d.getDeviceBattery()) | ||
.setUnits(SGV.CookieMonsterG4Download.Unit.MGDL); | ||
SGV.CookieMonsterSGVG4 sgv = SGV.CookieMonsterSGVG4.newBuilder() | ||
.setSgv(d.getLastRecord().getEgv()) | ||
.setTimestamp(d.getLastRecordReadingDate().getTime()) | ||
.setDirection(SGV.CookieMonsterSGVG4.Direction.values()[d.getLastTrend().getVal()]) | ||
.build(); | ||
recordBuilder.addSgv(sgv); | ||
SGV.CookieMonsterG4Download download = recordBuilder.build(); | ||
mqttMgr.publish(download.toByteArray(),PROTOBUF_DOWNLOAD_TOPIC); | ||
initialUpload=false; | ||
} catch (NoDataException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
// mqttMgr.publish(gson.toJson(d), "/entries/sgv"); | ||
|
||
try { | ||
savelastSuccessDate(d.getLastRecordReadingDate().getTime()); | ||
} catch (NoDataException e) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.