Skip to content

Commit

Permalink
NEW FEATURE: correct calculation of battery, more status details
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawel K committed Jan 4, 2021
1 parent c5d2a49 commit b4cd9d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Random Protocol Notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ KR = last bolus reference
SS = sensor status
SU = sensor control?
SC = sensor calibration minutes remaining
SB = sensor battery
SB = sensor battery (4 youngest bits)
SX = sensor rate of change (div 100)

SM = sensor mode active (incs each on and each off, if bit 0 is set then on)
Expand Down Expand Up @@ -303,7 +303,8 @@ Sensor/Transmitter:

[SU] 8bit = ?
[SC] 16bit = time remaining to next calibration in minutes (720 mins max count, FFFF = unknown)
[SB] 8bit = ? unconfirmed as transmitter battery (0x3F 100% ... 0x27 47% . 0x23 20%)
[SB] 8bit = 4 youngest bits represent the sensor battery 0x0f = 100%. (0x3F & 0x0F = 0x0F = 100%, 0x27 & 0x0F = 0x07 = 47%, 0x23 & 0x0F = 0x03 = 20%)
bit 5 seems always set. bit 4 is only set with 100%.
[SX] 16bit = isig rate of change? relates to use for trend arrows? (/100 for decimal value) (RATE_OF_CHANGE value in Carelink)

sensor warm-up noted:
Expand Down
18 changes: 17 additions & 1 deletion read_minimed_next24.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,22 @@ def trendArrow( self ):
@property
def sensorStatus(self):
status = int(struct.unpack('>B', self.responsePayload[0x41:0x42])[0])
if status == 0x00:
return "No sensor"
elif status & 0x01 == 0x01:
return "Calibrating 0x{:02X}".format(status)
elif status & 0x02 == 0x02:
return "Calibration complete 0x{:02X}".format(status)
elif status & 0x04 == 0x04:
return "SG value unavailable 0x{:02X}".format(status)
else:
return "Unknown sensor status: 0x{:02X}".format(status)
return status

@property
def sensorControl(self):
status = int(struct.unpack('>B', self.responsePayload[0x42:0x43])[0])
return "0x{0:02X} ({0:08b})".format(status)
return status

@property
Expand All @@ -592,7 +608,7 @@ def sensorCalibrationMinutesRemaining(self):

@property
def sensorBatteryPercent(self):
battery_percent = int(struct.unpack('>B', self.responsePayload[0x45:0x46])[0])
battery_percent = 100 * (0x0F & int(struct.unpack('>B', self.responsePayload[0x45:0x46])[0])) / 0x0F
return battery_percent

@property
Expand Down

0 comments on commit b4cd9d6

Please sign in to comment.