Skip to content

Commit

Permalink
fixed #15
Browse files Browse the repository at this point in the history
changed ELM reset on NRC to immediate protocol reaction rather than application reaction since too much delay time
  • Loading branch information
fr3ts0n committed Feb 5, 2016
1 parent 591cbe7 commit ee2a15a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/com/fr3ts0n/ecu/gui/androbd/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,6 @@ public void handleMessage(Message msg)
case MESSAGE_OBD_NRC:
// reset OBD mode to prevent infinite error loop
setObdService(ObdProt.OBD_SVC_NONE, getText(R.string.obd_error));
// if elm should be reset on NRC, then do it now
if(prefs.getBoolean(ELM_RESET_ON_NRC, false))
{
mCommService.elm.reset();
}
// show error dialog ...
evt = (PropertyChangeEvent) msg.obj;
String nrcMessage = (String)evt.getNewValue();
Expand Down Expand Up @@ -718,6 +713,10 @@ public void onSharedPreferenceChanged(SharedPreferences prefs, String key)
if(key==null || ELM_ADAPTIVE_TIMING.equals(key))
CommService.elm.mAdaptiveTiming.setEnabled(prefs.getBoolean(ELM_ADAPTIVE_TIMING, true));

// set protocol flag to initiate immediate reset on NRC reception
if(key==null || ELM_RESET_ON_NRC.equals(key))
CommService.elm.setResetOnNrc(prefs.getBoolean(ELM_RESET_ON_NRC, false));

// set custom ELM init commands
if(key==null || ELM_CUSTOM_INIT_CMDS.equals(key))
{
Expand Down
30 changes: 28 additions & 2 deletions src/com/fr3ts0n/ecu/prot/obd/ObdProt.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ public class ObdProt extends ProtoHeader

/** negative response ID */
public static final int OBD_ID_NRC = 0x7F;

/** perform immediate reset on NRC reception? */
public boolean isResetOnNrc()
{
return resetOnNrc;
}

/** Set protocol parameter
* @param resetOnNrc perform immediate reset on NRC reception?
*/
public void setResetOnNrc(boolean resetOnNrc)
{
log.info(String.format("Reset on NRC = %b", resetOnNrc));
this.resetOnNrc = resetOnNrc;
}

/** negative response codes */
public enum NRC
{
Expand Down Expand Up @@ -229,6 +245,8 @@ public String toString(int service)
static Vector<String> cmdQueue = new Vector<String>();
/** freeze frame ID to request */
private int freezeFrame_Id = 0;
/** perform reset on NRC reception */
private boolean resetOnNrc = false;

/** Creates a new instance of ObdProt */
public ObdProt()
Expand Down Expand Up @@ -504,8 +522,16 @@ public synchronized int handleTelegram(char[] buffer)
String error = String.format(nrc.toString(svc));
// log error
log.error(error);
// switch off any active service
setService(OBD_SVC_NONE, true);
if(isResetOnNrc())
{
// perform immediate reset because NRC reception
reset();
}
else
{
// otherwise just switch off any active service
setService(OBD_SVC_NONE, true);
}
// notify change listeners
firePropertyChange(new PropertyChangeEvent(this, PROP_NRC, null, error));
// handling finished
Expand Down

0 comments on commit ee2a15a

Please sign in to comment.