Skip to content
Snippets Groups Projects
Commit 4c42c646 authored by Lennart Goedhart's avatar Lennart Goedhart
Browse files

Try to handle comms errors more reliably.

parent 8790877c
No related branches found
No related tags found
No related merge requests found
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
......
This diff is collapsed.
...@@ -7,7 +7,6 @@ import android.app.PendingIntent; ...@@ -7,7 +7,6 @@ import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.hardware.usb.UsbManager; import android.hardware.usb.UsbManager;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
...@@ -22,7 +21,6 @@ import android.util.Log; ...@@ -22,7 +21,6 @@ import android.util.Log;
import com.nightscout.android.R; import com.nightscout.android.R;
import com.nightscout.android.USB.UsbHidDriver; import com.nightscout.android.USB.UsbHidDriver;
import com.nightscout.android.dexcom.DexcomG4Activity; import com.nightscout.android.dexcom.DexcomG4Activity;
import com.nightscout.android.dexcom.LoginActivity;
import com.nightscout.android.medtronic.MedtronicCNLReader; import com.nightscout.android.medtronic.MedtronicCNLReader;
import com.nightscout.android.medtronic.data.CNLConfigDbHelper; import com.nightscout.android.medtronic.data.CNLConfigDbHelper;
import com.nightscout.android.medtronic.message.ChecksumException; import com.nightscout.android.medtronic.message.ChecksumException;
...@@ -124,6 +122,7 @@ public class MedtronicCNLService extends AbstractService { ...@@ -124,6 +122,7 @@ public class MedtronicCNLService extends AbstractService {
mHidDevice.open(); mHidDevice.open();
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Unable to open serial device", e); Log.e(TAG, "Unable to open serial device", e);
return;
} }
// Go get the data // Go get the data
...@@ -150,27 +149,33 @@ public class MedtronicCNLService extends AbstractService { ...@@ -150,27 +149,33 @@ public class MedtronicCNLService extends AbstractService {
cnlReader.getPumpSession().setKey( MessageUtils.hexStringToByteArray( key ) ); cnlReader.getPumpSession().setKey( MessageUtils.hexStringToByteArray( key ) );
cnlReader.enterControlMode(); cnlReader.enterControlMode();
cnlReader.enterPassthroughMode(); try {
cnlReader.openConnection(); cnlReader.enterPassthroughMode();
cnlReader.requestReadInfo(); cnlReader.openConnection();
byte radioChannel = cnlReader.negotiateChannel(); cnlReader.requestReadInfo();
if (radioChannel == 0) { byte radioChannel = cnlReader.negotiateChannel();
send(Message.obtain(null, DexcomG4Activity.DexcomG4ActivityHandler.MSG_ERROR, "Could not communicate with the 640g. Are you near the pump?")); if (radioChannel == 0) {
Log.e(TAG, "Could not communicate with the 640g. Are you near the pump?"); send(Message.obtain(null, DexcomG4Activity.DexcomG4ActivityHandler.MSG_ERROR, "Could not communicate with the 640g. Are you near the pump?"));
} else { Log.i(TAG, "Could not communicate with the 640g. Are you near the pump?");
send(Message.obtain(null, DexcomG4Activity.DexcomG4ActivityHandler.MSG_STATUS, String.format("Connected to Contour Next Link on channel %d.", (int) radioChannel))); } else {
Log.d(TAG, String.format("Connected to Contour Next Link on channel %d.", (int) radioChannel)); send(Message.obtain(null, DexcomG4Activity.DexcomG4ActivityHandler.MSG_STATUS, String.format("Connected to Contour Next Link on channel %d.", (int) radioChannel)));
cnlReader.beginEHSMSession(); Log.d(TAG, String.format("Connected to Contour Next Link on channel %d.", (int) radioChannel));
cnlReader.beginEHSMSession();
cnlReader.getPumpTime(pumpRecord);
cnlReader.getPumpStatus(pumpRecord); cnlReader.getPumpTime(pumpRecord);
writeData(pumpRecord); cnlReader.getPumpStatus(pumpRecord);
send(Message.obtain(null, DexcomG4Activity.DexcomG4ActivityHandler.MSG_DATA, pumpRecord)); writeData(pumpRecord);
cnlReader.endEHSMSession(); send(Message.obtain(null, DexcomG4Activity.DexcomG4ActivityHandler.MSG_DATA, pumpRecord));
cnlReader.endEHSMSession();
}
cnlReader.closeConnection();
} catch (UnexpectedMessageException e) {
Log.e(TAG, "Unexpected Message", e);
send(Message.obtain(null, DexcomG4Activity.DexcomG4ActivityHandler.MSG_ERROR, "Communication Error: " + e.getMessage()));
} finally {
cnlReader.endPassthroughMode();
cnlReader.endControlMode();
} }
cnlReader.closeConnection();
cnlReader.endPassthroughMode();
cnlReader.endControlMode();
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error getting BGLs", e); Log.e(TAG, "Error getting BGLs", e);
send(Message.obtain(null, DexcomG4Activity.DexcomG4ActivityHandler.MSG_ERROR, "Error connecting to Contour Next Link.")); send(Message.obtain(null, DexcomG4Activity.DexcomG4ActivityHandler.MSG_ERROR, "Error connecting to Contour Next Link."));
...@@ -185,7 +190,7 @@ public class MedtronicCNLService extends AbstractService { ...@@ -185,7 +190,7 @@ public class MedtronicCNLService extends AbstractService {
send(Message.obtain(null, DexcomG4Activity.DexcomG4ActivityHandler.MSG_ERROR, "Timeout communicating with the Contour Next Link.")); send(Message.obtain(null, DexcomG4Activity.DexcomG4ActivityHandler.MSG_ERROR, "Timeout communicating with the Contour Next Link."));
} catch (UnexpectedMessageException e) { } catch (UnexpectedMessageException e) {
Log.e(TAG, "Unexpected Message", e); Log.e(TAG, "Unexpected Message", e);
send(Message.obtain(null, DexcomG4Activity.DexcomG4ActivityHandler.MSG_ERROR, "Communication Error: " + e.getMessage())); send(Message.obtain(null, DexcomG4Activity.DexcomG4ActivityHandler.MSG_ERROR, "Could not close connection: " + e.getMessage()));
} }
mUploader.execute(pumpRecord); mUploader.execute(pumpRecord);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment