-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
G5: debug version for new collection method
- Loading branch information
Showing
5 changed files
with
226 additions
and
130 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
app/src/main/java/com/eveningoutpost/dexdrip/G5Model/GlucoseRxMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.eveningoutpost.dexdrip.G5Model; | ||
|
||
import com.eveningoutpost.dexdrip.Models.JoH; | ||
import com.eveningoutpost.dexdrip.Models.UserError; | ||
import com.eveningoutpost.dexdrip.Services.G5CollectionService; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
|
||
/** | ||
* Created by jamorham on 25/11/2016. | ||
* | ||
* Alternate mechanism for reading data cribbed from LoopKit | ||
* totally experimental and untested | ||
*/ | ||
|
||
public class GlucoseRxMessage extends TransmitterMessage { | ||
|
||
private final static String TAG = G5CollectionService.class.getSimpleName(); // meh | ||
|
||
public static final byte opcode = 0x31; | ||
public TransmitterStatus status; | ||
public int status_raw; | ||
public int timestamp; | ||
public int unfiltered; | ||
public int filtered; | ||
public int sequence; // : UInt32 | ||
public boolean glucoseIsDisplayOnly; // : Bool | ||
public int glucose; // : UInt16 | ||
public int state; //: UInt8 | ||
public int trend; // : Int8 | ||
|
||
|
||
public GlucoseRxMessage(byte[] packet) { | ||
UserError.Log.e(TAG, "GlucoseRX dbg: " + JoH.bytesToHex(packet)); | ||
if (packet.length >= 14) { | ||
// TODO check CRC?? | ||
if (packet[0] == opcode) { | ||
data = ByteBuffer.wrap(packet).order(ByteOrder.LITTLE_ENDIAN); | ||
|
||
status_raw = data.get(1); | ||
status = TransmitterStatus.getBatteryLevel(data.get(1)); | ||
sequence = data.getInt(2); | ||
timestamp = data.getInt(6); | ||
|
||
|
||
int glucoseBytes = data.getShort(10); // check signed vs unsigned!! | ||
glucoseIsDisplayOnly = (glucoseBytes & 0xf000) > 0; | ||
glucose = glucoseBytes & 0xfff; | ||
|
||
state = data.get(12); | ||
trend = data.get(13); | ||
|
||
unfiltered = glucose * 1000; | ||
filtered = glucose * 1000; | ||
|
||
UserError.Log.e(TAG, "GlucoseRX: " + sequence + " ts:" + timestamp + " sg:" + glucose + " do:" + glucoseIsDisplayOnly + " ss:" + status + " sr:" + status_raw + " st:" + state + " tr:" + trend); | ||
|
||
} | ||
} else { | ||
UserError.Log.e(TAG, "GlucoseRxMessage packet length received wrong: " + packet.length); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/eveningoutpost/dexdrip/G5Model/GlucoseTxMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.eveningoutpost.dexdrip.G5Model; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
* Created by jamorham on 25/11/2016. | ||
*/ | ||
|
||
public class GlucoseTxMessage extends TransmitterMessage { | ||
|
||
byte opcode = 0x30; | ||
byte[] crc = CRC.calculate(opcode); | ||
|
||
public GlucoseTxMessage() { | ||
data = ByteBuffer.allocate(3); | ||
data.put(opcode); | ||
data.put(crc); | ||
byteSequence = data.array(); | ||
} | ||
} | ||
|
Oops, something went wrong.