some work on history
This commit is contained in:
parent
6662c9dd6c
commit
ee4d8b7748
|
@ -12,12 +12,14 @@ import com.cozmo.danar.util.BleCommandUtil;
|
|||
public abstract class DanaRS_Packet_History_ extends DanaRS_Packet {
|
||||
private static Logger log = LoggerFactory.getLogger(DanaRS_Packet_History_.class);
|
||||
|
||||
private int year;
|
||||
private int month;
|
||||
private int day;
|
||||
private int hour;
|
||||
private int min;
|
||||
private int sec;
|
||||
private int year = 0;
|
||||
private int month = 0;
|
||||
private int day = 0;
|
||||
private int hour = 0;
|
||||
private int min = 0;
|
||||
private int sec = 0;
|
||||
|
||||
public static long lastEventTimeLoaded = 0;
|
||||
|
||||
public boolean done;
|
||||
public int totalCount;
|
||||
|
@ -41,16 +43,6 @@ public abstract class DanaRS_Packet_History_ extends DanaRS_Packet {
|
|||
sec = cal.get(Calendar.SECOND);
|
||||
}
|
||||
|
||||
public DanaRS_Packet_History_(int year, int month, int day, int hour, int min, int sec) {
|
||||
this();
|
||||
this.year = year;
|
||||
this.month = month;
|
||||
this.day = day;
|
||||
this.hour = hour;
|
||||
this.min = min;
|
||||
this.sec = sec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getRequestParams() {
|
||||
byte[] request = new byte[6];
|
||||
|
@ -65,22 +57,24 @@ public abstract class DanaRS_Packet_History_ extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
int error = 0x00;
|
||||
int error;
|
||||
totalCount = 0;
|
||||
if (data.length == 3) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
done = error == 0x00;
|
||||
done = true;
|
||||
log.debug("History end. Code: " + error + " Success: " + (error == 0x00));
|
||||
} else if (data.length == 5) {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
error = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
done = error == 0x00;
|
||||
done = true;
|
||||
|
||||
dataIndex += dataSize;
|
||||
dataSize = 2;
|
||||
totalCount = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
log.debug("History end. Code: " + error + " Success: " + (error == 0x00) + " Toatal count: " + totalCount);
|
||||
} else {
|
||||
int dataIndex = DATA_START;
|
||||
int dataSize = 1;
|
||||
|
@ -111,6 +105,7 @@ public abstract class DanaRS_Packet_History_ extends DanaRS_Packet {
|
|||
int historySecond = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
Date date = new Date(100 + historyYear, historyMonth - 1, historyDay, historyHour, historyMinute, historySecond);
|
||||
lastEventTimeLoaded = date.getTime();
|
||||
|
||||
dataIndex += dataSize;
|
||||
dataSize = 1;
|
||||
|
@ -119,6 +114,8 @@ public abstract class DanaRS_Packet_History_ extends DanaRS_Packet {
|
|||
dataIndex += dataSize;
|
||||
dataSize = 2;
|
||||
int historyValue = byteArrayToInt(getBytes(data, dataIndex, dataSize));
|
||||
|
||||
log.debug("History packet: " + historyType + " Date: " + date.toLocaleString() + " Code: " + historyCode + " Value: " + historyValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,8 @@ import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Se
|
|||
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_Initial_Screen_Information;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_History_All_History;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_Delivery_Complete;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_Delivery_Rate_Display;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Get_Pump_Time;
|
||||
|
@ -107,6 +109,7 @@ public class DanaRSService extends Service {
|
|||
private DanaRS_Packet processsedMessage = null;
|
||||
private ArrayList<byte[]> mSendQueue = new ArrayList<>();
|
||||
|
||||
private long lastHistoryFetched = 0;
|
||||
|
||||
public DanaRSService() {
|
||||
try {
|
||||
|
@ -170,15 +173,34 @@ public class DanaRSService extends Service {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void loadEvents() {
|
||||
public boolean loadEvents() {
|
||||
if (!isConnected())
|
||||
return false;
|
||||
SystemClock.sleep(300);
|
||||
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));
|
||||
log.debug("Loading event history from: " + new Date(lastHistoryFetched).toLocaleString());
|
||||
}
|
||||
sendMessage(msg);
|
||||
while (!msg.done && isConnected()) {
|
||||
SystemClock.sleep(100);
|
||||
}
|
||||
SystemClock.sleep(200);
|
||||
lastHistoryFetched = DanaRS_Packet_History_.lastEventTimeLoaded;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean bolus(double insulin, int carbs, long l, Treatment t) {
|
||||
bolusingTreatment = t;
|
||||
int speed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||
DanaRS_Packet_Bolus_Set_Step_Bolus_Start start = new DanaRS_Packet_Bolus_Set_Step_Bolus_Start(insulin, speed);
|
||||
DanaRS_Packet_Bolus_Set_Step_Bolus_Stop stop = new DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(insulin, t);
|
||||
DanaRS_Packet_Notify_Delivery_Complete complete = new DanaRS_Packet_Notify_Delivery_Complete(insulin, t);
|
||||
DanaRS_Packet_Bolus_Set_Step_Bolus_Stop stop = new DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(insulin, t); // initialize static variables
|
||||
DanaRS_Packet_Notify_Delivery_Complete complete = new DanaRS_Packet_Notify_Delivery_Complete(insulin, t); // initialize static variables
|
||||
|
||||
if (!isConnected()) return false;
|
||||
|
||||
|
@ -669,11 +691,11 @@ public class DanaRSService extends Service {
|
|||
log.debug("Pump user password: " + Integer.toHexString(pass));
|
||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED));
|
||||
|
||||
getPumpStatus();
|
||||
scheduleDisconnection();
|
||||
isConnected = true;
|
||||
isConnecting = false;
|
||||
if (mConfirmConnect != null) {
|
||||
getPumpStatus();
|
||||
scheduleDisconnection();
|
||||
if (mConfirmConnect != null) {
|
||||
synchronized (mConfirmConnect) {
|
||||
mConfirmConnect.notify();
|
||||
mConfirmConnect = null;
|
||||
|
|
Loading…
Reference in a new issue