From 6f469d7c3c4a31940658ee8e88faeb5c0c7dfaa6 Mon Sep 17 00:00:00 2001
From: Pogman <subaziro@gmail.com>
Date: Sat, 18 Feb 2017 16:29:27 +0000
Subject: [PATCH] Unexpected messages and timeouts during CNL-->Pump comms are
 usually a lost/dropped connection

If user has double polling set then poll sooner with this error type
---
 .../medtronic/service/MedtronicCnlIntentService.java   | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/app/src/main/java/info/nightscout/android/medtronic/service/MedtronicCnlIntentService.java b/app/src/main/java/info/nightscout/android/medtronic/service/MedtronicCnlIntentService.java
index ed91b04..9b95b9d 100644
--- a/app/src/main/java/info/nightscout/android/medtronic/service/MedtronicCnlIntentService.java
+++ b/app/src/main/java/info/nightscout/android/medtronic/service/MedtronicCnlIntentService.java
@@ -319,9 +319,19 @@ public class MedtronicCnlIntentService extends IntentService {
                     // Tell the Main Activity we have new data
                     sendMessage(Constants.ACTION_UPDATE_PUMP);
                 }
+
+                // TODO - consider handling comms during EHSM errors separately as these tend to be CNL<-->PUMP lost/bad/noisy communication errors rather then Uploader<-->CNL errors
             } catch (UnexpectedMessageException e) {
+                // unexpected messages during CNL-->Pump comms are usually a lost/dropped connection
+                // CNL 0x81 message response for lost/dropped connection: 0x55 "u" pump response "55 0D 00 04 00 00 00 00 03 00 01 ..." note: EHSM is auto closed by CNL
                 Log.e(TAG, "Unexpected Message", e);
                 sendStatus("Communication Error: " + e.getMessage());
+                pollInterval = MainActivity.pollInterval / (MainActivity.reducePollOnPumpAway?2L:1L);
+            } catch (TimeoutException e) {
+                // timeout during CNL-->Pump comms are usually a lost/dropped connection
+                Log.e(TAG, "Timeout communicating with the Contour Next Link.", e);
+                sendStatus("Timeout communicating with the Contour Next Link.");
+                pollInterval = MainActivity.pollInterval / (MainActivity.reducePollOnPumpAway?2L:1L);
             } catch (NoSuchAlgorithmException e) {
                 Log.e(TAG, "Could not determine CNL HMAC", e);
                 sendStatus("Error connecting to Contour Next Link: Hashing error.");
-- 
GitLab