From 920a43d034eb94863b5d043f4606a49ffc2f68b6 Mon Sep 17 00:00:00 2001 From: Sascha Scandella Date: Tue, 16 Apr 2019 23:13:14 +0200 Subject: [PATCH] Support for G6v2 with adapted scaling values --- src/G5G6Model/BatteryInfoRxMessage.as | 6 ++++-- src/G5G6Model/SensorRxMessage.as | 27 ++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/G5G6Model/BatteryInfoRxMessage.as b/src/G5G6Model/BatteryInfoRxMessage.as index b73010fc71..f045d18449 100644 --- a/src/G5G6Model/BatteryInfoRxMessage.as +++ b/src/G5G6Model/BatteryInfoRxMessage.as @@ -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(); @@ -35,6 +34,9 @@ package G5G6Model } byteSequence.position = 0; } + else { + myTrace("Invalid length for BatteryInfoMessage: " + packet.length); + } } private static function myTrace(log:String):void { diff --git a/src/G5G6Model/SensorRxMessage.as b/src/G5G6Model/SensorRxMessage.as index c0993ed612..b1b55baf96 100644 --- a/src/G5G6Model/SensorRxMessage.as +++ b/src/G5G6Model/SensorRxMessage.as @@ -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(); @@ -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;