Skip to content

Commit

Permalink
MGB data support added.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Jan 20, 2015
1 parent 5939ee3 commit 7f5684b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 29 deletions.
84 changes: 59 additions & 25 deletions src/com/nightscout/android/medtronic/MedtronicReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ public String processBufferedMessages(ArrayList<byte[]> bufferedMessages) {
readData.length);
}
sResponse
.append(processGlucometerDataMessage(readData))
.append(processGlucometerDataMessage(readData, true))
.append("\n");
if (lastGlucometerValue > 0) {
isCalibrating = true;
Expand Down Expand Up @@ -617,14 +617,45 @@ public String processBufferedMessages(ArrayList<byte[]> bufferedMessages) {
.copyOfRange(readData, 0,
readData.length);
}
sResponse.append("Glucomenter Deteted!! \n");
sResponse.append("Glucomenter Deteted!! \n").append(processGlucometerDataMessage(readData, false));
sendMessageToUI("Glucometer Detected!!..Waiting 15 min. to retrieve calibration factor...", false);
log.debug("Glucometer Detected!!..Waiting 15 min. to retrieve calibration factor...");
if (mHandlerSensorCalibration != null && getCalibrationFromSensor != null){
mHandlerSensorCalibration.removeCallbacks(getCalibrationFromSensor);
mHandlerSensorCalibration.postDelayed(getCalibrationFromSensor, MedtronicConstants.TIME_15_MIN_IN_MS + 120000);
}else
log.debug("glucometer handler or glucometer runnable is null");
}else{
if (lastGlucometerMessage == null
|| lastGlucometerMessage.length == 0) {
lastGlucometerMessage = Arrays
.copyOfRange(readData, 0,
readData.length);
lastGlucometerMessageDate = System
.currentTimeMillis();
SharedPreferences.Editor editor = settings
.edit();
editor.putString(
"lastGlucometerMessage",
HexDump.toHexString(lastGlucometerMessage));

editor.commit();
} else {
boolean isEqual = Arrays
.equals(lastGlucometerMessage,
readData);
if (isEqual
&& (System.currentTimeMillis()
- lastGlucometerMessageDate < MedtronicConstants.TIME_15_MIN_IN_MS)) {
continue;
}
lastGlucometerMessageDate = System
.currentTimeMillis();
lastGlucometerMessage = Arrays
.copyOfRange(readData, 0,
readData.length);
}
sResponse.append("Glucomenter Deteted!! \n").append(processGlucometerDataMessage(readData, false));
}
break;
}
Expand Down Expand Up @@ -1620,7 +1651,7 @@ record = new MedtronicSensorRecord();
* @param readData
* @return String, for debug or notification purposes
*/
public String processGlucometerDataMessage(byte[] readData) {
public String processGlucometerDataMessage(byte[] readData, boolean calibrate) {
int firstMeasureByte = firstByteAfterDeviceId(readData);
if (firstMeasureByte < 0)
return "Error, I can not identify the initial byte of the glucometer measure";
Expand Down Expand Up @@ -1651,30 +1682,33 @@ public String processGlucometerDataMessage(byte[] readData) {
lastGlucometerRecord.lastDate = d.getTime();
lastGlucometerDate = d.getTime();
calculateDate(lastGlucometerRecord, d, 0);
if (HexDump.unsignedByte(expectedSensorSortNumber) == HexDump
.unsignedByte((byte) 0xff)) {
expectedSensorSortNumberForCalibration[0] = (byte) 0x00;
expectedSensorSortNumberForCalibration[1] = (byte) 0x71;
} else {
synchronized (expectedSensorSortNumberLock) {
byte expectedAux = expectedSensorSortNumber;
if (HexDump
.unsignedByte((byte) (expectedSensorSortNumber & (byte) 0x01)) > 0)
expectedAux = (byte) (expectedSensorSortNumber & (byte) 0xFE);
expectedSensorSortNumberForCalibration[0] = calculateNextSensorSortNameFrom(
6, expectedAux);
expectedSensorSortNumberForCalibration[1] = calculateNextSensorSortNameFrom(
10, expectedAux);
if (calibrate){
if (HexDump.unsignedByte(expectedSensorSortNumber) == HexDump
.unsignedByte((byte) 0xff)) {
expectedSensorSortNumberForCalibration[0] = (byte) 0x00;
expectedSensorSortNumberForCalibration[1] = (byte) 0x71;
} else {
synchronized (expectedSensorSortNumberLock) {
byte expectedAux = expectedSensorSortNumber;
if (HexDump
.unsignedByte((byte) (expectedSensorSortNumber & (byte) 0x01)) > 0)
expectedAux = (byte) (expectedSensorSortNumber & (byte) 0xFE);
expectedSensorSortNumberForCalibration[0] = calculateNextSensorSortNameFrom(
6, expectedAux);
expectedSensorSortNumberForCalibration[1] = calculateNextSensorSortNameFrom(
10, expectedAux);
}
}

SharedPreferences.Editor editor = settings.edit();
editor.putFloat("lastGlucometerValue", (float) num);
editor.putLong("glucometerLastDate", d.getTime());
editor.putString("expectedSensorSortNumberForCalibration0",
HexDump.toHexString(expectedSensorSortNumberForCalibration[0]));
editor.putString("expectedSensorSortNumberForCalibration1",
HexDump.toHexString(expectedSensorSortNumberForCalibration[1]));
editor.commit();
}
SharedPreferences.Editor editor = settings.edit();
editor.putFloat("lastGlucometerValue", (float) num);
editor.putLong("glucometerLastDate", d.getTime());
editor.putString("expectedSensorSortNumberForCalibration0",
HexDump.toHexString(expectedSensorSortNumberForCalibration[0]));
editor.putString("expectedSensorSortNumberForCalibration1",
HexDump.toHexString(expectedSensorSortNumberForCalibration[1]));
editor.commit();
return "Measure received " + num + " mg/dl";
}

Expand Down
18 changes: 14 additions & 4 deletions src/com/nightscout/android/upload/UploadHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ private void doMongoUpload(SharedPreferences prefs, Record... records) {
// make db object
testData.put("device", getSelectedDeviceName());
testData.put("sgv", record.bGValue);
testData.put("type", "sgv");
testData.put("direction", record.trend);
typeSaved = 0;
if (cgmSelected == DexcomG4Activity.MEDTRONIC_CGM && (oRecord instanceof MedtronicSensorRecord)){
Expand All @@ -667,12 +668,21 @@ private void doMongoUpload(SharedPreferences prefs, Record... records) {
}
log.info("Uploading a EGVRecord");
dexcomData.save(testData, WriteConcern.UNACKNOWLEDGED);
}else if (oRecord instanceof GlucometerRecord && glucomData != null){
}else if (oRecord instanceof GlucometerRecord && (glucomData != null || dexcomData != null)){
typeSaved = 2;
GlucometerRecord gdRecord = (GlucometerRecord) oRecord;
testData.put("gdValue", gdRecord.numGlucometerValue);
log.info("Uploading a GlucometerRecord");
glucomData.save(testData, WriteConcern.UNACKNOWLEDGED);
if (glucomData != null){//To be deprecated
testData.put("gdValue", gdRecord.numGlucometerValue);
log.info("Uploading a GlucometerRecord");
glucomData.save(testData, WriteConcern.UNACKNOWLEDGED);
}
if (dexcomData != null){
testData.put("device", getSelectedDeviceName());
testData.put("type", "mbg");
testData.put("mbg", gdRecord.numGlucometerValue);
log.info("Uploading a Glucometer Record!");
dexcomData.save(testData, WriteConcern.UNACKNOWLEDGED);
}
}else if (oRecord instanceof MedtronicPumpRecord && deviceData != null){
typeSaved = 3;
MedtronicPumpRecord pumpRecord = (MedtronicPumpRecord) oRecord;
Expand Down

0 comments on commit 7f5684b

Please sign in to comment.