Skip to content

Commit 76762ed

Browse files
authored
Log g5 errors, non-ok calibration states, and unknown data (#487)
* Log g5 errors, non-ok calibration states, and unknown data * Update to new DiagnosticLogger
1 parent c7d3f37 commit 76762ed

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Loop/Managers/CGM/DexCGMManager.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ final class ShareClientManager: CGMManager {
109109

110110
final class G5CGMManager: DexCGMManager, TransmitterDelegate {
111111
private let transmitter: Transmitter?
112+
let logger = DiagnosticLogger.shared!.forCategory("G5CGMManager")
112113

113114
init(transmitterID: String?) {
114115
if let transmitterID = transmitterID {
@@ -161,10 +162,15 @@ final class G5CGMManager: DexCGMManager, TransmitterDelegate {
161162
// MARK: - TransmitterDelegate
162163

163164
func transmitter(_ transmitter: Transmitter, didError error: Error) {
165+
logger.error(error)
164166
delegate?.cgmManager(self, didUpdateWith: .error(error))
165167
}
166168

167169
func transmitter(_ transmitter: Transmitter, didRead glucose: Glucose) {
170+
if !glucose.state.hasReliableGlucose {
171+
logger.error(String(describing: glucose.state))
172+
}
173+
168174
guard glucose != latestReading, let quantity = glucose.glucose else {
169175
delegate?.cgmManager(self, didUpdateWith: .noData)
170176
return
@@ -177,6 +183,7 @@ final class G5CGMManager: DexCGMManager, TransmitterDelegate {
177183
}
178184

179185
func transmitter(_ transmitter: Transmitter, didReadUnknownData data: Data) {
186+
logger.error("Unknown sensor data: " + data.hexadecimalString)
180187
// This can be used for protocol discovery, but isn't necessary for normal operation
181188
}
182189
}
@@ -255,3 +262,20 @@ final class G4CGMManager: DexCGMManager, ReceiverDelegate {
255262
// NSLog(["event": "\(event)", "collectedAt": NSDateFormatter.ISO8601StrictDateFormatter().stringFromDate(NSDate())])
256263
}
257264
}
265+
266+
extension CalibrationState: CustomStringConvertible {
267+
public var description: String {
268+
switch self {
269+
case .needCalibration, .needFirstInitialCalibration, .needSecondInitialCalibration:
270+
return NSLocalizedString("Sensor needs calibration", comment: "The description of sensor calibration state when sensor needs calibration.")
271+
case .ok:
272+
return NSLocalizedString("Sensor calibration is OK", comment: "The description of sensor calibration state when sensor calibration is ok.")
273+
case .stopped:
274+
return NSLocalizedString("Sensor is stopped", comment: "The description of sensor calibration state when sensor sensor is stopped.")
275+
case .warmup:
276+
return NSLocalizedString("Sensor is warming up", comment: "The description of sensor calibration state when sensor sensor is warming up.")
277+
case .unknown(let rawValue):
278+
return String(format: NSLocalizedString("Sensor is in unknown state %1$d", comment: "The description of sensor calibration state when raw value is unknown. (1: missing data details)"), rawValue)
279+
}
280+
}
281+
}

0 commit comments

Comments
 (0)