Skip to content

Conversation

thebookins
Copy link
Contributor

@thebookins thebookins commented Mar 30, 2018

I have observed occasionally that the state .needCalibration14 coincides with an unreliable glucose reading ('---'). Presumably, if an entered calibration is too far off the regression line, the logic is to stop supplying glucose readings until a new calibration has been provided. On these occasions (and also all states for which hasReliableGlucose is false the glucose bytes in the glucose Rx message are 0500 (a 'glucose' of 5 mg/dL).

With this PR, the glucose property in Glucose returns nil if glucoseMessage.glucose is less than 40 (the range of the Dex system is 40 - 400 mg/dL).

Incidentally, since the glucose bytes in the glucose Rx message are always 0500 when the glucose is unreliable, it may be unnecessary to compute the hasReliableGlucose property in CalibrationState and check for it here.

Update: for some reason the glucose bytes are 0100 in the .stopped state (a 'glucose' of 1 mg/dL). However, the logic here still holds.

@ps2
Copy link
Contributor

ps2 commented Mar 30, 2018

I'm not sure what problem this is fixing? The hasReliableGlucose property is the main property that should be checked to determine if the glucose value is reliable.

@thebookins
Copy link
Contributor Author

I believe it's needed because now error state 14 is included in the list of acceptable states here. Sometimes during error state 14 the receiver (or official app) displays glucose; at other times the glucose is '---'. The transmitter communicates 'unreliable glucose' simply by not supplying a glucose in the glucose Rx message, and this does not map cleanly to calibration states.
Without this change it's possible an unreliable glucose (a glucose of 5 mg/dL) could be dispatched to the client.

@ps2
Copy link
Contributor

ps2 commented Apr 1, 2018

Glucose values of 39 (“below range”) should not be considered unreliable, because if the user’s glucose is actually 40 or below the last thing we want to do is to make Loop stop running.

The quick fix is to adjust the condition to include 39. The better fix is to represent below-/in-/above-range as an enum in the Glucose model.

@thebookins
Copy link
Contributor Author

Agreed. I wasn't aware that the Tx communicates "below range" with a glucose value of 39. I guess the key thing is to distinguish a glucose of 5 (unreliable) from 39 (below range), 40 - 400 (in range) and > 400 (above range). I'll attempt to revise the code to include a glucose state enum.

@ps2
Copy link
Contributor

ps2 commented Apr 14, 2018

Fixed with #88. Thanks!

@ps2 ps2 closed this Apr 14, 2018
@thebookins thebookins deleted the glucose-level-guard branch August 25, 2018 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants