Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for G6v2 with adapted scaling factors #191

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/G5G6Model/BatteryInfoRxMessage.as
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ package G5G6Model
public var temperature:int;

public function BatteryInfoRxMessage(packet:ByteArray) {
if (packet.length >= 12) {
if (packet.length >= 10) {
byteSequence = new ByteArray();
byteSequence.endian = Endian.LITTLE_ENDIAN;
byteSequence.writeBytes(packet);
byteSequence.position = 0;
if (byteSequence.readByte() == opcode) {
//status = byteSequence.readByte();
status = byteSequence.readByte();
voltagea = byteSequence.readUnsignedShort();
voltageb = byteSequence.readUnsignedShort();
Expand All @@ -35,6 +34,9 @@ package G5G6Model
}
byteSequence.position = 0;
}
else {
myTrace("Invalid length for BatteryInfoMessage: " + packet.length);
}
}

private static function myTrace(log:String):void {
Expand Down
27 changes: 24 additions & 3 deletions src/G5G6Model/SensorRxMessage.as
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,34 @@ package G5G6Model

public class SensorRxMessage extends TransmitterMessage
{
private const G6_SCALING:int = 34;
private var opcode:int = 0x2f;
public var timestamp:Number;
public var unfiltered:Number;
public var filtered:Number;
public var transmitterStatus:TransmitterStatus;

private function scale(unscaled:int) {
myTrace("SensorRX dbg: unscaled = " + unscaled);

if (CGMBlueToothDevice.isDexcomG5())
{
return unscaled;
}
else
{
if (G5G6VersionInfo.getG5G6VersionInfo().firmware_version_string.indexOf("1") == 0)
{
// G6v1
return unscaled * 34;
}
else
{
// G6v2
return (unscaled - 1151395987) / 113432;
}
}
}

public function SensorRxMessage(packet:ByteArray) {
if (packet.length >= 14) {
byteSequence = new ByteArray();
Expand All @@ -26,8 +47,8 @@ package G5G6Model

transmitterStatus = TransmitterStatus.getBatteryLevel(byteSequence.readByte());
timestamp = byteSequence.readInt();
unfiltered = CGMBlueToothDevice.isDexcomG6() ? byteSequence.readInt() * G6_SCALING : byteSequence.readInt();
filtered = CGMBlueToothDevice.isDexcomG6() ? byteSequence.readInt() * G6_SCALING : byteSequence.readInt();
unfiltered = scale(byteSequence.readInt());
filtered = scale(byteSequence.readInt());
myTrace("SensorRX dbg: timestamp = " + timestamp + ", unfiltered = " + unfiltered + ", filtered = " + filtered + ", transmitterStatus = " + transmitterStatus.toString());
}
byteSequence.position = 0;
Expand Down