De-initialize Rv2 if time is off by more than 1.5h
This commit is contained in:
parent
78949a34ab
commit
02eceef134
1 changed files with 30 additions and 23 deletions
|
@ -189,6 +189,36 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
mSerialIOThread.sendMessage(tempStatusMsg);
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingextendedbolusstatus)));
|
||||
mSerialIOThread.sendMessage(exStatusMsg);
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
|
||||
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
|
||||
long timeDiff = (mDanaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L;
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds");
|
||||
if (Math.abs(timeDiff) > 3) {
|
||||
if (Math.abs(timeDiff) > 60*60*1.5) {
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds - large difference");
|
||||
//If time-diff is very large, warn user until we can synchronize history readings properly
|
||||
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||
i.putExtra("soundid", R.raw.error);
|
||||
i.putExtra("status", MainApp.gs(R.string.largetimediff));
|
||||
i.putExtra("title", MainApp.gs(R.string.largetimedifftitle));
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
MainApp.instance().startActivity(i);
|
||||
|
||||
//deinitialize pump
|
||||
DanaRPump.reset();
|
||||
mDanaRPump = DanaRPump.getInstance();
|
||||
MainApp.bus().post(new EventDanaRNewStatus());
|
||||
MainApp.bus().post(new EventInitializationChanged());
|
||||
return;
|
||||
} else {
|
||||
waitForWholeMinute(); // Dana can set only whole minute
|
||||
// add 10sec to be sure we are over minute (will be cutted off anyway)
|
||||
mSerialIOThread.sendMessage(new MsgSetTime(new Date(DateUtil.now() + T.secs(10).msecs())));
|
||||
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
|
||||
timeDiff = (mDanaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L;
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds");
|
||||
}
|
||||
}
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
if (mDanaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !MainApp.getSpecificPlugin(DanaRv2Plugin.class).isInitialized()) {
|
||||
|
@ -204,29 +234,6 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
mSerialIOThread.sendMessage(new MsgSettingProfileRatios());
|
||||
mSerialIOThread.sendMessage(new MsgSettingUserOptions());
|
||||
mSerialIOThread.sendMessage(new MsgSettingProfileRatiosAll());
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
|
||||
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
|
||||
long timeDiff = (mDanaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L;
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds");
|
||||
if (Math.abs(timeDiff) > 3) {
|
||||
if (Math.abs(timeDiff) > 60*60*1.5) {
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds - large difference");
|
||||
//If time-diff is very large, warn user until we can synchronize history readings properly
|
||||
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||
i.putExtra("soundid", R.raw.error);
|
||||
i.putExtra("status", MainApp.gs(R.string.largetimediff));
|
||||
i.putExtra("title", MainApp.gs(R.string.largetimedifftitle));
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
MainApp.instance().startActivity(i);
|
||||
} else {
|
||||
waitForWholeMinute(); // Dana can set only whole minute
|
||||
// add 10sec to be sure we are over minute (will be cutted off anyway)
|
||||
mSerialIOThread.sendMessage(new MsgSetTime(new Date(DateUtil.now() + T.secs(10).msecs())));
|
||||
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
|
||||
timeDiff = (mDanaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L;
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds");
|
||||
}
|
||||
}
|
||||
mDanaRPump.lastSettingsRead = now;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue