Merge branch 'nsclient' of https://github.com/MilosKozak/AndroidAPS into nsclient

This commit is contained in:
Milos Kozak 2017-02-20 08:32:25 +01:00
commit 352902438c
4 changed files with 21 additions and 9 deletions

View file

@ -341,7 +341,7 @@ public class ExecutionService extends Service {
danaRPump.lastConnection = now;
MainApp.bus().post(new EventDanaRNewStatus());
MainApp.bus().post(new EventInitializationChanged());
MainApp.getConfigBuilder().uploadDeviceStatus(60);
MainApp.getConfigBuilder().uploadDeviceStatus(15);
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning ) {
log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.sResources.getString(R.string.approachingdailylimit), Notification.URGENT);

View file

@ -332,7 +332,7 @@ public class ExecutionService extends Service {
danaRKoreanPump.lastConnection = now;
MainApp.bus().post(new EventDanaRNewStatus());
MainApp.bus().post(new EventInitializationChanged());
MainApp.getConfigBuilder().uploadDeviceStatus(60);
MainApp.getConfigBuilder().uploadDeviceStatus(15);
if (danaRKoreanPump.dailyTotalUnits > danaRKoreanPump.maxDailyTotalUnits * Constants.dailyLimitWarning ) {
log.debug("Approaching daily limit: " + danaRKoreanPump.dailyTotalUnits + "/" + danaRKoreanPump.maxDailyTotalUnits);
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.sResources.getString(R.string.approachingdailylimit), Notification.URGENT);

View file

@ -228,7 +228,7 @@ public class LoopPlugin implements PluginBase {
}
MainApp.bus().post(new EventLoopUpdateGui());
MainApp.getConfigBuilder().uploadDeviceStatus(120);
MainApp.getConfigBuilder().uploadDeviceStatus(60);
} finally {
if (Config.logFunctionCalls)
log.debug("invoke end");

View file

@ -10,7 +10,6 @@ import android.os.HandlerThread;
import android.os.IBinder;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.widget.Toast;
import com.google.common.base.Charsets;
import com.google.common.hash.Hashing;
@ -59,8 +58,8 @@ import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientS
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
import io.socket.client.IO;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
@ -95,6 +94,8 @@ public class NSClientService extends Service {
private boolean uploading = false;
public Date lastReception = new Date();
public long latestDateInReceivedData = 0;
private String nsAPIhashCode = "";
public static UploadQueue uploadQueue = new UploadQueue();
@ -252,6 +253,7 @@ public class NSClientService extends Service {
authMessage.put("history", nsHours);
authMessage.put("status", true); // receive status
authMessage.put("pingme", true); // send mi pings to keep alive
authMessage.put("from", latestDateInReceivedData); // send data newer than
authMessage.put("secret", nsAPIhashCode);
} catch (JSONException e) {
e.printStackTrace();
@ -411,6 +413,11 @@ public class NSClientService extends Service {
// remove from upload queue if Ack is failing
UploadQueue.removeID(jsonTreatment);
//Find latest date in treatment
if (treatment.getMills() != null && treatment.getMills() < new Date().getTime())
if (treatment.getMills() > latestDateInReceivedData)
latestDateInReceivedData = treatment.getMills();
if (treatment.getAction() == null) {
if (!isCurrent(treatment)) continue;
addedTreatments.put(jsonTreatment);
@ -485,9 +492,14 @@ public class NSClientService extends Service {
// Handle new sgv here
// remove from upload queue if Ack is failing
UploadQueue.removeID(jsonSgv);
//Find latest date in sgv
if (sgv.getMills() != null && sgv.getMills() < new Date().getTime())
if (sgv.getMills() > latestDateInReceivedData)
latestDateInReceivedData = sgv.getMills();
}
bs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta);
}
MainApp.bus().post(new EventNSClientNewLog("LAST", DateUtil.dateAndTimeString(latestDateInReceivedData)));
} catch (JSONException e) {
e.printStackTrace();
}
@ -509,7 +521,7 @@ public class NSClientService extends Service {
message.put("_id", dbr._id);
message.put("data", dbr.data);
mSocket.emit("dbUpdate", message, ack);
MainApp.bus().post(new EventNSClientNewLog("DBUPDATE", "Sent " + dbr._id));
MainApp.bus().post(new EventNSClientNewLog("DBUPDATE " + dbr.collection, "Sent " + dbr._id));
} catch (JSONException e) {
e.printStackTrace();
}
@ -523,7 +535,7 @@ public class NSClientService extends Service {
message.put("_id", dbr._id);
message.put("data", dbr.data);
mSocket.emit("dbUpdateUnset", message, ack);
MainApp.bus().post(new EventNSClientNewLog("DBUPDATEUNSET", "Sent " + dbr._id));
MainApp.bus().post(new EventNSClientNewLog("DBUPDATEUNSET " + dbr.collection, "Sent " + dbr._id));
} catch (JSONException e) {
e.printStackTrace();
}
@ -536,7 +548,7 @@ public class NSClientService extends Service {
message.put("collection", dbr.collection);
message.put("_id", dbr._id);
mSocket.emit("dbRemove", message, ack);
MainApp.bus().post(new EventNSClientNewLog("DBREMOVE", "Sent " + dbr._id));
MainApp.bus().post(new EventNSClientNewLog("DBREMOVE " + dbr.collection, "Sent " + dbr._id));
} catch (JSONException e) {
e.printStackTrace();
}
@ -559,7 +571,7 @@ public class NSClientService extends Service {
message.put("collection", dbr.collection);
message.put("data", dbr.data);
mSocket.emit("dbAdd", message, ack);
MainApp.bus().post(new EventNSClientNewLog("DBADD", "Sent " + dbr.nsClientID));
MainApp.bus().post(new EventNSClientNewLog("DBADD " + dbr.collection, "Sent " + dbr.nsClientID));
} catch (JSONException e) {
e.printStackTrace();
}