Skip to content

Commit

Permalink
handling of STOPPED - do NOT repeat request, (answer still pending)
Browse files Browse the repository at this point in the history
max timeout 1000ms
readability cleanup
  • Loading branch information
fr3ts0n committed Aug 29, 2015
1 parent 3b37c45 commit ed78700
Showing 1 changed file with 51 additions and 47 deletions.
98 changes: 51 additions & 47 deletions src/com/fr3ts0n/ecu/prot/ElmProt.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ public class ElmProt
/**
* ELM protocol ID's
*/
public static enum PROT
public enum PROT
{
ELM_PROT_AUTO("Automatic"),
ELM_PROT_J1850PWM("SAE J1850 PWM (41.6 KBaud)"),
ELM_PROT_J1850VPW("SAE J1850 VPW (10.4 KBaud)"),
ELM_PROT_9141_2("ISO 9141-2 (5 Baud Init)"),
ELM_PROT_14230_4("ISO 14230-4 KWP (5 Baud Init)"),
ELM_PROT_14230_4F("ISO 14230-4 KWP (fast Init)"),
ELM_PROT_15765_11_F("ISO 15765-4 CAN (11 Bit ID, 500 KBit)"),
ELM_PROT_15765_29_F("ISO 15765-4 CAN (29 Bit ID, 500 KBit)"),
ELM_PROT_15765_11_S("ISO 15765-4 CAN (11 Bit ID, 250 KBit)"),
ELM_PROT_15765_29_S("ISO 15765-4 CAN (29 Bit ID, 250 KBit)"),
ELM_PROT_J1939_29_S("SAE J1939 CAN (29 bit ID, 250* kbaud)"),
ELM_PROT_USER1_CAN_11_S("User1 CAN (11* bit ID, 125* kbaud)"),
ELM_PROT_USER2_CAN_11_S("User2 CAN (11* bit ID, 50* kbaud)"),;
ELM_PROT_AUTO ( "Automatic" ),
ELM_PROT_J1850PWM ( "SAE J1850 PWM (41.6 KBaud)" ),
ELM_PROT_J1850VPW ( "SAE J1850 VPW (10.4 KBaud)" ),
ELM_PROT_9141_2 ( "ISO 9141-2 (5 Baud Init)" ),
ELM_PROT_14230_4 ( "ISO 14230-4 KWP (5 Baud Init)" ),
ELM_PROT_14230_4F ( "ISO 14230-4 KWP (fast Init)" ),
ELM_PROT_15765_11_F ( "ISO 15765-4 CAN (11 Bit ID, 500 KBit)" ),
ELM_PROT_15765_29_F ( "ISO 15765-4 CAN (29 Bit ID, 500 KBit)" ),
ELM_PROT_15765_11_S ( "ISO 15765-4 CAN (11 Bit ID, 250 KBit)" ),
ELM_PROT_15765_29_S ( "ISO 15765-4 CAN (29 Bit ID, 250 KBit)" ),
ELM_PROT_J1939_29_S ( "SAE J1939 CAN (29 bit ID, 250* kbaud)" ),
ELM_PROT_USER1_CAN_11_S ( "User1 CAN (11* bit ID, 125* kbaud)" ),
ELM_PROT_USER2_CAN_11_S ( "User2 CAN (11* bit ID, 50* kbaud)" );
private String description;

PROT(String _description)
Expand All @@ -71,25 +71,25 @@ public String toString()
/**
* possible ELM responses and ID's
*/
static enum RSP_ID
enum RSP_ID
{
PROMPT(">"),
OK("OK"),
MODEL("ELM"),
NODATA("NODATA"),
SEARCH("SEARCHING"),
ERROR("ERROR"),
NOCONN("UNABLE"),
CANERROR("CANERROR"),
BUSBUSY("BUSBUSY"),
BUSERROR("BUSERROR"),
FBERROR("FBERROR"),
DATAERROR("DATAERROR"),
BUFFERFULL("BUFFERFULL"),
STOPPED("STOPPED"),
RXERROR("<"),
QMARK("?"),
UNKNOWN("");
PROMPT ( ">" ),
OK ( "OK" ),
MODEL ( "ELM" ),
NODATA ( "NODATA" ),
SEARCH ( "SEARCHING" ),
ERROR ( "ERROR" ),
NOCONN ( "UNABLE" ),
CANERROR ( "CANERROR" ),
BUSBUSY ( "BUSBUSY" ),
BUSERROR ( "BUSERROR" ),
FBERROR ( "FBERROR" ),
DATAERROR ( "DATAERROR" ),
BUFFERFULL( "BUFFERFULL" ),
STOPPED ( "STOPPED" ),
RXERROR ( "<" ),
QMARK ( "?" ),
UNKNOWN ( "" );
private String response;

RSP_ID(String response)
Expand All @@ -107,18 +107,19 @@ public String toString()
/**
* possible communication states
*/
public static enum STAT
public enum STAT
{
UNDEFINED("Undefined"),
INITIALIZING("Initializing"),
CONNECTING("Connecting"),
CONNECTED("Connected"),
NODATA("No data"),
DISCONNECTED("Disconnected"),
BUSERROR("BUS error"),
DATAERROR("DATA error"),
RXERROR("RX error"),
ERROR("Error");
UNDEFINED ( "Undefined" ),
INITIALIZING ( "Initializing" ),
CONNECTING ( "Connecting" ),
CONNECTED ( "Connected" ),
NODATA ( "No data" ),
STOPPED ( "Stopped" ),
DISCONNECTED ( "Disconnected" ),
BUSERROR ( "BUS error" ),
DATAERROR ( "DATA error" ),
RXERROR ( "RX error" ),
ERROR ( "Error" );
private String elmState;

STAT(String state)
Expand Down Expand Up @@ -187,7 +188,7 @@ public ElmProt()
/** min. ELM Message Timeout [ms] */
static final int ELM_TIMEOUT_MIN = 12;
/** max. ELM Message Timeout [ms] */
static final int ELM_TIMEOUT_MAX = 200;
static final int ELM_TIMEOUT_MAX = 1000;
/** 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 @@ -313,6 +314,8 @@ public int handleTelegram(char[] buffer)
// if ths is echo of last command
if (lastTxMsg.compareToIgnoreCase(bufferStr) == 0)
{
// immediate set echo off
queueCommand(CMD.ECHO, 0);
return result;
}

Expand Down Expand Up @@ -359,8 +362,6 @@ public int handleTelegram(char[] buffer)
// speed up protocol by removing spaces and line feeds from output
queueCommand(CMD.SETSPACES, 0);
queueCommand(CMD.SETLINEFEED, 0);
// immediate set echo off
sendCommand(CMD.ECHO, 0);
setStatus(STAT.INITIALIZING);
break;

Expand Down Expand Up @@ -404,8 +405,11 @@ public int handleTelegram(char[] buffer)
setStatus(STAT.CONNECTING);
break;

case NODATA:
case STOPPED:
setStatus(STAT.STOPPED);
break;

case NODATA:
char[] veryLastCmd = lastCommand;
setStatus(STAT.NODATA);
// re-queue last command
Expand Down

0 comments on commit ed78700

Please sign in to comment.