more work on service

This commit is contained in:
Milos Kozak 2017-09-18 12:57:07 +02:00
parent ee4d8b7748
commit e3ad396f65
10 changed files with 110 additions and 62 deletions

View file

@ -9,8 +9,10 @@ import org.slf4j.LoggerFactory;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -229,4 +231,17 @@ public class DanaRPump {
return PROFILE_PREFIX + (activeProfile + 1); return PROFILE_PREFIX + (activeProfile + 1);
} }
public static double[] buildDanaRProfileRecord(Profile nsProfile) {
double[] record = new double[24];
for (Integer hour = 0; hour < 24; hour++) {
//Some values get truncated to the next lower one.
// -> round them to two decimals and make sure we are a small delta larger (that will get truncated)
double value = Math.round(100d * nsProfile.getBasal((Integer) (hour * 60 * 60)))/100d + 0.00001;
if (Config.logDanaMessageDetail)
log.debug("NS basal value for " + hour + ":00 is " + value);
record[hour] = value;
}
return record;
}
} }

View file

@ -526,7 +526,7 @@ public class DanaRExecutionService extends Service {
connect("updateBasalsInPump"); connect("updateBasalsInPump");
if (!isConnected()) return false; if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
double[] basal = buildDanaRProfileRecord(profile); double[] basal = DanaRPump.buildDanaRProfileRecord(profile);
MsgSetBasalProfile msgSet = new MsgSetBasalProfile((byte) 0, basal); MsgSetBasalProfile msgSet = new MsgSetBasalProfile((byte) 0, basal);
mSerialIOThread.sendMessage(msgSet); mSerialIOThread.sendMessage(msgSet);
MsgSetActivateBasalProfile msgActivate = new MsgSetActivateBasalProfile((byte) 0); MsgSetActivateBasalProfile msgActivate = new MsgSetActivateBasalProfile((byte) 0);
@ -537,19 +537,6 @@ public class DanaRExecutionService extends Service {
return true; return true;
} }
private double[] buildDanaRProfileRecord(Profile nsProfile) {
double[] record = new double[24];
for (Integer hour = 0; hour < 24; hour++) {
//Some values get truncated to the next lower one.
// -> round them to two decimals and make sure we are a small delta larger (that will get truncated)
double value = Math.round(100d * nsProfile.getBasal((Integer) (hour * 60 * 60)))/100d + 0.00001;
if (Config.logDanaMessageDetail)
log.debug("NS basal value for " + hour + ":00 is " + value);
record[hour] = value;
}
return record;
}
private void waitMsec(long msecs) { private void waitMsec(long msecs) {
SystemClock.sleep(msecs); SystemClock.sleep(msecs);
} }

View file

@ -502,7 +502,7 @@ public class DanaRKoreanExecutionService extends Service {
connect("updateBasalsInPump"); connect("updateBasalsInPump");
if (!isConnected()) return false; if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
double[] basal = buildDanaRProfileRecord(profile); double[] basal = DanaRPump.buildDanaRProfileRecord(profile);
MsgSetSingleBasalProfile msgSet = new MsgSetSingleBasalProfile(basal); MsgSetSingleBasalProfile msgSet = new MsgSetSingleBasalProfile(basal);
mSerialIOThread.sendMessage(msgSet); mSerialIOThread.sendMessage(msgSet);
danaRPump.lastSettingsRead = new Date(0); // force read full settings danaRPump.lastSettingsRead = new Date(0); // force read full settings
@ -511,17 +511,6 @@ public class DanaRKoreanExecutionService extends Service {
return true; return true;
} }
private double[] buildDanaRProfileRecord(Profile nsProfile) {
double[] record = new double[24];
for (Integer hour = 0; hour < 24; hour++) {
double value = Math.round(100d * nsProfile.getBasal((Integer) (hour * 60 * 60)))/100d + 0.00001;
if (Config.logDanaMessageDetail)
log.debug("NS basal value for " + hour + ":00 is " + value);
record[hour] = value;
}
return record;
}
private void waitMsec(long msecs) { private void waitMsec(long msecs) {
SystemClock.sleep(msecs); SystemClock.sleep(msecs);
} }

View file

@ -380,6 +380,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
} else { } else {
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
} }
connectIfNotConnected("updateBasalsInPump");
if (!danaRSService.updateBasalsInPump(profile)) { if (!danaRSService.updateBasalsInPump(profile)) {
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT); Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification)); MainApp.bus().post(new EventNewNotification(notification));
@ -585,6 +586,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
return result; return result;
} }
int durationInHours = Math.max(durationInMinutes / 60, 1); int durationInHours = Math.max(durationInMinutes / 60, 1);
connectIfNotConnected("tempbasal");
boolean connectionOK = danaRSService.tempBasal(percent, durationInHours); boolean connectionOK = danaRSService.tempBasal(percent, durationInHours);
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) { if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
result.enacted = true; result.enacted = true;
@ -648,6 +650,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulin); log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulin);
return result; return result;
} }
connectIfNotConnected("extendedBolus");
boolean connectionOK = danaRSService.extendedBolus(insulin, durationInHalfHours); boolean connectionOK = danaRSService.extendedBolus(insulin, durationInHalfHours);
if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) { if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) {
result.enacted = true; result.enacted = true;
@ -673,6 +676,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
public PumpEnactResult cancelTempBasal(boolean force) { public PumpEnactResult cancelTempBasal(boolean force) {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
if (pump.isTempBasalInProgress) { if (pump.isTempBasalInProgress) {
connectIfNotConnected("tempBasalStop");
danaRSService.tempBasalStop(); danaRSService.tempBasalStop();
result.enacted = true; result.enacted = true;
result.isTempCancel = true; result.isTempCancel = true;
@ -697,6 +701,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
public PumpEnactResult cancelExtendedBolus() { public PumpEnactResult cancelExtendedBolus() {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
if (pump.isExtendedInProgress) { if (pump.isExtendedInProgress) {
connectIfNotConnected("extendedBolusStop");
danaRSService.extendedBolusStop(); danaRSService.extendedBolusStop();
result.enacted = true; result.enacted = true;
result.isTempCancel = true; result.isTempCancel = true;

View file

@ -31,7 +31,7 @@ public class DanaRSMessageHashTable {
put(new DanaRS_Packet_Basal_Set_Suspend_Off()); put(new DanaRS_Packet_Basal_Set_Suspend_Off());
put(new DanaRS_Packet_Basal_Set_Suspend_On()); put(new DanaRS_Packet_Basal_Set_Suspend_On());
put(new DanaRS_Packet_Basal_Set_Temporary_Basal()); put(new DanaRS_Packet_Basal_Set_Temporary_Basal());
put(new DanaRS_Packet_Basal_Temporary_Basal_State()); put(new DanaRS_Packet_Basal_Get_Temporary_Basal_State());
put(new DanaRS_Packet_Bolus_Get_Bolus_Option()); put(new DanaRS_Packet_Bolus_Get_Bolus_Option());
put(new DanaRS_Packet_Bolus_Get_Initial_Bolus()); put(new DanaRS_Packet_Bolus_Get_Initial_Bolus());
put(new DanaRS_Packet_Bolus_Get_Calculation_Information()); put(new DanaRS_Packet_Bolus_Get_Calculation_Information());

View file

@ -216,7 +216,7 @@ public class DanaRS_Packet {
ret = new DanaRS_Packet_Basal_Set_Temporary_Basal(); ret = new DanaRS_Packet_Basal_Set_Temporary_Basal();
break; break;
case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__TEMPORARY_BASAL_STATE: case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__TEMPORARY_BASAL_STATE:
ret = new DanaRS_Packet_Basal_Temporary_Basal_State(); ret = new DanaRS_Packet_Basal_Get_Temporary_Basal_State();
break; break;
case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__CANCEL_TEMPORARY_BASAL: case BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__CANCEL_TEMPORARY_BASAL:
ret = new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(); ret = new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal();

View file

@ -11,10 +11,10 @@ import info.nightscout.androidaps.Config;
import com.cozmo.danar.util.BleCommandUtil; import com.cozmo.danar.util.BleCommandUtil;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
public class DanaRS_Packet_Basal_Temporary_Basal_State extends DanaRS_Packet { public class DanaRS_Packet_Basal_Get_Temporary_Basal_State extends DanaRS_Packet {
private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Temporary_Basal_State.class); private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_Basal_Get_Temporary_Basal_State.class);
public DanaRS_Packet_Basal_Temporary_Basal_State() { public DanaRS_Packet_Basal_Get_Temporary_Basal_State() {
super(); super();
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__TEMPORARY_BASAL_STATE; opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__TEMPORARY_BASAL_STATE;
if (Config.logDanaMessageDetail) { if (Config.logDanaMessageDetail) {

View file

@ -34,13 +34,17 @@ public abstract class DanaRS_Packet_History_ extends DanaRS_Packet {
public DanaRS_Packet_History_(Date from) { public DanaRS_Packet_History_(Date from) {
this(); this();
GregorianCalendar cal = new GregorianCalendar(); GregorianCalendar cal = new GregorianCalendar();
if (from.getTime() != 0)
cal.setTime(from); cal.setTime(from);
else
cal.set(2000, 0, 1, 0, 0, 0);
year = cal.get(Calendar.YEAR) - 1900 - 100; year = cal.get(Calendar.YEAR) - 1900 - 100;
month = cal.get(Calendar.MONTH) + 1; month = cal.get(Calendar.MONTH) + 1;
day = cal.get(Calendar.DAY_OF_MONTH); day = cal.get(Calendar.DAY_OF_MONTH);
hour = cal.get(Calendar.HOUR_OF_DAY); hour = cal.get(Calendar.HOUR_OF_DAY);
min = cal.get(Calendar.MINUTE); min = cal.get(Calendar.MINUTE);
sec = cal.get(Calendar.SECOND); sec = cal.get(Calendar.SECOND);
log.debug("Loading event history from: " + new Date(cal.getTimeInMillis()).toLocaleString());
} }
@Override @Override

View file

@ -50,12 +50,18 @@ import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRSMessageHashTable
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Get_Basal_Rate; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Get_Basal_Rate;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Get_Profile_Number; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Get_Profile_Number;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Temporary_Basal_State; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Get_Temporary_Basal_State;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Set_Profile_Basal_Rate;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Set_Profile_Number;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Basal_Set_Temporary_Basal;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Bolus_Option; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Bolus_Option;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_CIR_CF_Array; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_CIR_CF_Array;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Calculation_Information; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Calculation_Information;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Extended_Bolus_State; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Extended_Bolus_State;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Step_Bolus_Information; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Get_Step_Bolus_Information;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Extended_Bolus;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Stop; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Stop;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_General_Get_Shipping_Information; import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_General_Get_Shipping_Information;
@ -131,7 +137,7 @@ public class DanaRSService extends Service {
sendMessage(new DanaRS_Packet_General_Initial_Screen_Information()); sendMessage(new DanaRS_Packet_General_Initial_Screen_Information());
sendMessage(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State()); sendMessage(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State());
sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // last bolus sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // last bolus
sendMessage(new DanaRS_Packet_Basal_Temporary_Basal_State()); sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State());
Date now = new Date(); Date now = new Date();
if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !MainApp.getSpecificPlugin(DanaRSPlugin.class).isInitialized()) { if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !MainApp.getSpecificPlugin(DanaRSPlugin.class).isInitialized()) {
@ -178,18 +184,12 @@ public class DanaRSService extends Service {
return false; return false;
SystemClock.sleep(300); SystemClock.sleep(300);
DanaRS_Packet_History_All_History msg; DanaRS_Packet_History_All_History msg;
if (lastHistoryFetched == 0) {
msg = new DanaRS_Packet_History_All_History(new Date(System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000)); // 2 days
log.debug("Loading complete event history");
} else {
msg = new DanaRS_Packet_History_All_History(new Date(lastHistoryFetched)); msg = new DanaRS_Packet_History_All_History(new Date(lastHistoryFetched));
log.debug("Loading event history from: " + new Date(lastHistoryFetched).toLocaleString());
}
sendMessage(msg); sendMessage(msg);
while (!msg.done && isConnected()) { while (!msg.done && isConnected()) {
SystemClock.sleep(100); SystemClock.sleep(100);
} }
SystemClock.sleep(200); SystemClock.sleep(200); // #### nefunguje
lastHistoryFetched = DanaRS_Packet_History_.lastEventTimeLoaded; lastHistoryFetched = DanaRS_Packet_History_.lastEventTimeLoaded;
return true; return true;
} }
@ -205,7 +205,7 @@ public class DanaRSService extends Service {
if (!isConnected()) return false; if (!isConnected()) return false;
if (carbs > 0) { if (carbs > 0) {
// MsgSetCarbsEntry msg = new MsgSetCarbsEntry(carbtime, carbs); // MsgSetCarbsEntry msg = new MsgSetCarbsEntry(carbtime, carbs); ####
// sendMessage(msg); // sendMessage(msg);
// MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(DanaRPump.CARBS, carbtime, carbs, 0); // MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(DanaRPump.CARBS, carbtime, carbs, 0);
// sendMessage(msgSetHistoryEntry_v2); // sendMessage(msgSetHistoryEntry_v2);
@ -236,28 +236,82 @@ public class DanaRSService extends Service {
} }
public void bolusStop() { public void bolusStop() {
if (Config.logDanaBTComm)
log.debug("bolusStop >>>>> @ " + (bolusingTreatment == null ? "" : bolusingTreatment.insulin));
DanaRS_Packet_Bolus_Set_Step_Bolus_Stop stop = new DanaRS_Packet_Bolus_Set_Step_Bolus_Stop();
stop.forced = true;
if (isConnected()) {
sendMessage(stop);
while (!stop.stopped) {
sendMessage(stop);
SystemClock.sleep(200);
}
} else {
stop.stopped = true;
}
} }
public boolean tempBasal(Integer percent, int durationInHours) { public boolean tempBasal(Integer percent, int durationInHours) {
return false; if (!isConnected()) return false;
if (danaRPump.isTempBasalInProgress) {
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
sendMessage(new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal());
SystemClock.sleep(500);
}
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal)));
sendMessage(new DanaRS_Packet_Basal_Set_Temporary_Basal(percent, durationInHours));
sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State());
loadEvents();
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
} }
public boolean highTempBasal(Integer percent) { public boolean highTempBasal(Integer percent) {
return false; return false;
} }
public void tempBasalStop() { public boolean tempBasalStop() {
if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
sendMessage(new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal());
sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State());
loadEvents();
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
} }
public boolean extendedBolus(Double insulin, int durationInHalfHours) { public boolean extendedBolus(Double insulin, int durationInHalfHours) {
return false; if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus)));
sendMessage(new DanaRS_Packet_Bolus_Set_Extended_Bolus(insulin, durationInHalfHours));
sendMessage(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State());
loadEvents();
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
} }
public void extendedBolusStop() { public boolean extendedBolusStop() {
if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus)));
sendMessage(new DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel());
sendMessage(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State());
loadEvents();
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
} }
public boolean updateBasalsInPump(Profile profile) { public boolean updateBasalsInPump(Profile profile) {
return false; if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
double[] basal = DanaRPump.buildDanaRProfileRecord(profile);
DanaRS_Packet_Basal_Set_Profile_Basal_Rate msgSet = new DanaRS_Packet_Basal_Set_Profile_Basal_Rate(0, basal);
sendMessage(msgSet);
DanaRS_Packet_Basal_Set_Profile_Number msgActivate = new DanaRS_Packet_Basal_Set_Profile_Number(0);
sendMessage(msgActivate);
danaRPump.lastSettingsRead = new Date(0); // force read full settings
getPumpStatus();
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
} }
public boolean loadHistory(byte type) { public boolean loadHistory(byte type) {
@ -609,7 +663,12 @@ public class DanaRSService extends Service {
// copy packet to input buffer // copy packet to input buffer
System.arraycopy(readBuffer, 0, inputBuffer, 0, length + 7); System.arraycopy(readBuffer, 0, inputBuffer, 0, length + 7);
// Cut off the message from readBuffer // Cut off the message from readBuffer
try {
System.arraycopy(readBuffer, length + 7, readBuffer, 0, bufferLength - (length + 7)); System.arraycopy(readBuffer, length + 7, readBuffer, 0, bufferLength - (length + 7));
} catch (Exception e) {
log.debug("length: " + length + "bufferLength: " + bufferLength);
throw e;
}
bufferLength -= (length + 7); bufferLength -= (length + 7);
} }
// now we have encrypted packet in inputBuffer // now we have encrypted packet in inputBuffer

View file

@ -530,7 +530,7 @@ public class DanaRv2ExecutionService extends Service {
connect("updateBasalsInPump"); connect("updateBasalsInPump");
if (!isConnected()) return false; if (!isConnected()) return false;
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates))); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
double[] basal = buildDanaRProfileRecord(profile); double[] basal = DanaRPump.buildDanaRProfileRecord(profile);
MsgSetBasalProfile msgSet = new MsgSetBasalProfile((byte) 0, basal); MsgSetBasalProfile msgSet = new MsgSetBasalProfile((byte) 0, basal);
mSerialIOThread.sendMessage(msgSet); mSerialIOThread.sendMessage(msgSet);
MsgSetActivateBasalProfile msgActivate = new MsgSetActivateBasalProfile((byte) 0); MsgSetActivateBasalProfile msgActivate = new MsgSetActivateBasalProfile((byte) 0);
@ -541,17 +541,6 @@ public class DanaRv2ExecutionService extends Service {
return true; return true;
} }
private double[] buildDanaRProfileRecord(Profile nsProfile) {
double[] record = new double[24];
for (Integer hour = 0; hour < 24; hour++) {
double value = Math.round(100d * nsProfile.getBasal((Integer) (hour * 60 * 60)))/100d + 0.00001;
if (Config.logDanaMessageDetail)
log.debug("NS basal value for " + hour + ":00 is " + value);
record[hour] = value;
}
return record;
}
private void waitMsec(long msecs) { private void waitMsec(long msecs) {
SystemClock.sleep(msecs); SystemClock.sleep(msecs);
} }