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