From 17038ffb242a1eadb265896a8c669edf74d3c1c7 Mon Sep 17 00:00:00 2001 From: yoh-there Date: Sat, 21 Nov 2015 12:24:44 +0100 Subject: [PATCH] Implemented some overflow detection, trying to catch the ELM going bezerks. --- app/app.iml | 11 ++--------- app/src/main/java/lu/fisch/canze/devices/ELM327.java | 9 +++++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/app.iml b/app/app.iml index 039cbc1a..852a1345 100644 --- a/app/app.iml +++ b/app/app.iml @@ -65,26 +65,19 @@ - - - - - - - - - + + diff --git a/app/src/main/java/lu/fisch/canze/devices/ELM327.java b/app/src/main/java/lu/fisch/canze/devices/ELM327.java index 06d9d576..077a1d5f 100644 --- a/app/src/main/java/lu/fisch/canze/devices/ELM327.java +++ b/app/src/main/java/lu/fisch/canze/devices/ELM327.java @@ -389,6 +389,10 @@ private String sendAndWaitForAnswer(String command, int waitMillis, boolean unti // send a command and wait for an answer private String sendAndWaitForAnswer(String command, int waitMillis, boolean untilEmpty, int answerLinesCount, boolean addReturn) { + + int maxUntilEmptyCounter = 10; + int maxLengthCounter = 500; // char = nibble, so 2000 bits + if(!BluetoothManager.getInstance().isConnected()) return ""; if(command!=null) { @@ -457,9 +461,14 @@ private String sendAndWaitForAnswer(String command, int waitMillis, boolean unti // do nothing } stop=(BluetoothManager.getInstance().available()==0); + } else { + if (--maxUntilEmptyCounter <= 0) timedOut = true; // well, this is a timed"In", as in, too many lines } } + } else { + if (--maxLengthCounter <= 0) timedOut = true; // well, this is a timed"In", as in, too many lines } + } } else