Skip to content

Commit

Permalink
Try to increase timeout dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Fisch authored and Robert Fisch committed Nov 21, 2015
1 parent 742482b commit 5e69159
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="CMCanZE" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="CanZE" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/lu/fisch/canze/devices/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

public abstract class Device {

protected int frequencyMultiplicator = 1;

/* ----------------------------------------------------------------
* Attributes
\ -------------------------------------------------------------- */
Expand Down Expand Up @@ -685,8 +687,12 @@ public Message requestField(Field field)
if (field.isIsoTp()) msg = requestIsoTpFrame(field);
else msg = requestFreeFrame(field);

if (msg == null || msg.getData().isEmpty())
if (msg == null || msg.getData().isEmpty()) {
MainActivity.debug("Device: request for " + field.getSID() + " is empty ...");
// theory: when the answer is empty, the timeout is to low --> increase it!
frequencyMultiplicator+=0.1;
MainActivity.debug("Device: frequencyMultiplicator = "+frequencyMultiplicator);
}
}
else
MainActivity.debug("Device: ignoring virtual field " + field.getSID());
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/lu/fisch/canze/devices/ELM327.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ELM327 extends Device {

// define the timeout we may wait to get an answer
private static int DEFAULT_TIMEOUT = 500;
private static int MINIMUM_TIMEOUT = 100;
private int TIMEOUT = 500;
// define End Of Message for this type of reader
private static final char EOM1 = '\r';
Expand Down Expand Up @@ -552,8 +553,8 @@ public Message requestFreeFrame(Field field) {
if (!someThingWrong) {
//sendAndWaitForAnswer("atcra" + emlFilter, 400);
// atma (wait for one answer line)
TIMEOUT = field.getFrequency() + 50;
if (TIMEOUT < 70) TIMEOUT = 70;
TIMEOUT = (int) (field.getFrequency()*frequencyMultiplicator + 50);
if (TIMEOUT < MINIMUM_TIMEOUT) TIMEOUT = MINIMUM_TIMEOUT;
MainActivity.debug("ELM327: requestFreeFrame > TIMEOUT = "+TIMEOUT);

hexData = sendAndWaitForAnswer("atma", 20);
Expand Down

0 comments on commit 5e69159

Please sign in to comment.