Skip to content
Snippets Groups Projects
Commit 3d6b6667 authored by Pogman's avatar Pogman
Browse files

Merge remote-tracking branch 'remotes/origin/feature/PR104' into develop_invincible

# Conflicts:
#	app/src/main/java/info/nightscout/android/medtronic/MainActivity.java
parents 8f8ef8f9 1aeca0a4
Branches
Tags
No related merge requests found
......@@ -82,11 +82,7 @@
<receiver android:name=".medtronic.service.MedtronicCnlAlarmReceiver" />
<receiver android:name=".upload.nightscout.NightscoutUploadReceiver" />
<receiver android:name=".xdrip_plus.XDripPlusUploadReceiver" /><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<receiver android:name=".xdrip_plus.XDripPlusUploadReceiver" />
</application>
......
......@@ -114,10 +114,23 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc
private StatusMessageReceiver statusMessageReceiver = new StatusMessageReceiver();
private MedtronicCnlAlarmReceiver medtronicCnlAlarmReceiver = new MedtronicCnlAlarmReceiver();
/**
* calculate the next poll timestamp based on last svg event
*
* @param pumpStatusData
* @return timestamp
*/
public static long getNextPoll(PumpStatusEvent pumpStatusData) {
long nextPoll = pumpStatusData.getEventDate().getTime() + pumpStatusData.getPumpTimeOffset()
+ MedtronicCnlIntentService.POLL_GRACE_PERIOD_MS;
long nextPoll = pumpStatusData.getEventDate().getTime() + pumpStatusData.getPumpTimeOffset(),
now = System.currentTimeMillis();
// align to next poll slot
if (nextPoll + 2 * 60 * 60 * 1000 < now) { // last event more than 2h old -> could be a calibration
nextPoll = System.currentTimeMillis() + 1000;
} else {
// align to poll interval
nextPoll += (((now - nextPoll) / MainActivity.pollInterval)) * MainActivity.pollInterval
+ MedtronicCnlIntentService.POLL_GRACE_PERIOD_MS;
if (pumpStatusData.getBatteryPercentage() > 25) {
// poll every 5 min
nextPoll += MainActivity.pollInterval;
......@@ -126,6 +139,7 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc
//TODO add message & document it
nextPoll += MainActivity.lowBatteryPollInterval;
}
}
return nextPoll;
}
......@@ -288,7 +302,8 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc
stopCgmService();
finish();
} else if (drawerItem.equals(itemGetNow)) {
startCgmService();
// It was triggered by user so start reading of data now and not based on last poll.
startCgmService(0);
} else if (drawerItem.equals(itemClearLog)) {
clearLogText();
}
......@@ -426,7 +441,18 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc
}
private void startCgmService() {
startCgmService(System.currentTimeMillis() + 1000);
startCgmServiceDelayed(0);
}
private void startCgmServiceDelayed(long delay) {
RealmResults<PumpStatusEvent> results = mRealm.where(PumpStatusEvent.class)
.findAllSorted("eventDate", Sort.DESCENDING);
if (results.size() > 0) {
startCgmService(getNextPoll(results.first()) + delay);
} else {
startCgmService(System.currentTimeMillis() + (delay==0?1000:delay));
}
}
private void startCgmService(long initialPoll) {
......@@ -930,7 +956,7 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc
if (hasUsbPermission()) {
// Give the USB a little time to warm up first
startCgmService(System.currentTimeMillis() + MedtronicCnlIntentService.USB_WARMUP_TIME_MS);
startCgmServiceDelayed(MedtronicCnlIntentService.USB_WARMUP_TIME_MS);
} else {
Log.d(TAG, "No permission for USB. Waiting.");
waitForUsbPermission();
......
......@@ -23,15 +23,14 @@ import java.util.concurrent.TimeoutException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import info.nightscout.android.BuildConfig;
import info.nightscout.android.R;
import info.nightscout.android.USB.UsbHidDriver;
import info.nightscout.android.medtronic.MainActivity;
import info.nightscout.android.medtronic.MedtronicCnlReader;
import info.nightscout.android.medtronic.exception.ChecksumException;
import info.nightscout.android.medtronic.exception.EncryptionException;
import info.nightscout.android.medtronic.message.MessageUtils;
import info.nightscout.android.medtronic.exception.UnexpectedMessageException;
import info.nightscout.android.medtronic.message.MessageUtils;
import info.nightscout.android.model.medtronicNg.ContourNextLinkInfo;
import info.nightscout.android.model.medtronicNg.PumpInfo;
import info.nightscout.android.model.medtronicNg.PumpStatusEvent;
......@@ -40,8 +39,6 @@ import info.nightscout.android.xdrip_plus.XDripPlusUploadReceiver;
import io.realm.Realm;
import io.realm.RealmResults;
import static info.nightscout.android.medtronic.MainActivity.setActivePumpMac;
public class MedtronicCnlIntentService extends IntentService {
public final static int USB_VID = 0x1a79;
public final static int USB_PID = 0x6210;
......@@ -178,12 +175,7 @@ public class MedtronicCnlIntentService extends IntentService {
.findFirst();
if (info == null) {
// TODO - use realm.createObject()?
info = realm.createObject(ContourNextLinkInfo.class, cnlReader.getStickSerial());
//info = new ContourNextLinkInfo();
///info.setSerialNumber(cnlReader.getStickSerial());
//info = realm.copyToRealm(info);
}
cnlReader.getPumpSession().setStickSerial(info.getSerialNumber());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment