Skip to content

Commit

Permalink
Fix issue #8
Browse files Browse the repository at this point in the history
changed handling of bus- and connection error:
-> set default imeout (instead of fastest)
-> set auto protocol
-> re-issue last command
  • Loading branch information
fr3ts0n committed Sep 22, 2015
1 parent f60f77b commit f966d30
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/com/fr3ts0n/ecu/prot/ElmProt.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ public ElmProt()
static final int ELM_TIMEOUT_MIN = 12;
/** max. ELM Message Timeout [ms] */
static final int ELM_TIMEOUT_MAX = 1000;
/** default ELM message timeout */
static final int ELM_TIMEOUT_DEFAULT = 200;
/** Learning resolution of ELM Message Timeout [ms] */
static final int ELM_TIMEOUT_RES = 4;
/** ELM message timeout: defaults to approx 200 [ms] */
Expand Down Expand Up @@ -365,17 +367,17 @@ public int handleTelegram(char[] buffer)
break;

case NOCONN:
// no immediate response
setStatus(STAT.DISCONNECTED);
sendCommand(CMD.RESET, 0);
break;

case CANERROR:
case BUSERROR:
case BUSBUSY:
case FBERROR:
setStatus(STAT.BUSERROR);
sendCommand(CMD.SETPROTAUTO, PROT.ELM_PROT_AUTO.ordinal());
setStatus(STAT.DISCONNECTED);
// re-queue last command
if(service != OBD_SVC_NONE) cmdQueue.add(String.valueOf(lastCommand));
// set default timeout
setElmMsgTimeout(ELM_TIMEOUT_DEFAULT);
// set to automatic protocol
sendCommand(CMD.SETPROT, PROT.ELM_PROT_AUTO.ordinal());
break;

case DATAERROR:
Expand Down Expand Up @@ -409,10 +411,9 @@ public int handleTelegram(char[] buffer)
break;

case NODATA:
char[] veryLastCmd = lastCommand;
setStatus(STAT.NODATA);
// re-queue last command
if(service != OBD_SVC_NONE) cmdQueue.add(String.valueOf(veryLastCmd));
if(service != OBD_SVC_NONE) cmdQueue.add(String.valueOf(lastCommand));
// increase OBD timeout since we may expect answers too fast
if ((elmMsgTimeout + ELM_TIMEOUT_RES) < ELM_TIMEOUT_MAX)
{
Expand Down

0 comments on commit f966d30

Please sign in to comment.