Skip to content

Commit

Permalink
Improve robustness on inconsistent adapter responses
Browse files Browse the repository at this point in the history
Debounce disable of data item processing
- disable on >3 consecutive conversion failures
  • Loading branch information
fr3ts0n committed Nov 27, 2017
1 parent ae57477 commit a4b6b9e
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/com/fr3ts0n/ecu/EcuDataItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class EcuDataItem
};
// current conversion system
public static int cnvSystem = SYSTEM_METRIC;
// maximum number of conversion errors before disabling data item
public static int MAX_ERROR_COUNT = 3;

public int pid; ///< pid
public int ofs; ///< Offset within message
Expand All @@ -54,15 +56,15 @@ public class EcuDataItem
String fmt; ///< Format for text output
public String label; ///< text label
public EcuDataPv pv; ///< the process variable for displaying
boolean enabled = true; ///< if not enabled, do not process
int currErrorCount = 0; ///< current number of consecutive conversion errors

// Logger object
public static final Logger log = Logger.getLogger("data.ecu");

public static int[] byteValues =
{
0xFFFF, // fake default max value for length 0
0xFF,
0xFF,
0xFFFF,
0xFFFFFF,
0xFFFFFFFF
Expand Down Expand Up @@ -171,11 +173,15 @@ Object physFromBuffer(char[] buffer)
{
result = String.copyValueOf(buffer, ofs, bytes);
}
// decrement error counter
currErrorCount = Math.max(0, currErrorCount -1);
} catch(Exception ex)
{
result = "n/a";
log.warning(String.format("%s: %s - [%s]", toString(), ex.getMessage(), ProtUtils.hexDumpBuffer(buffer)));
enabled = false;

// increment error counter
currErrorCount = Math.min(MAX_ERROR_COUNT, currErrorCount +1);
}
return (result);
}
Expand All @@ -187,8 +193,10 @@ Object physFromBuffer(char[] buffer)
*/
public void updatePvFomBuffer(char[] buffer)
{
if(enabled)
// if consecutive conversion error counter not exceeded
if(currErrorCount < MAX_ERROR_COUNT)
{
// process data item
try
{
// get physical value
Expand All @@ -202,9 +210,16 @@ public void updatePvFomBuffer(char[] buffer)
}
catch(Exception ex)
{
log.severe(ex.toString());
log.warning(ex.toString());
}
}
else
{
log.warning(String.format("Item disabled: %s (%d/%d)",
toString(),
currErrorCount,
MAX_ERROR_COUNT));
}
}

@Override
Expand Down

0 comments on commit a4b6b9e

Please sign in to comment.