Skip to content

Commit

Permalink
Merge pull request #974 from enviroCar/develop
Browse files Browse the repository at this point in the history
allow commands to recover from failures
  • Loading branch information
matthesrieke authored Feb 23, 2023
2 parents 7405e9a + bdaa62d commit 00ba858
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public void onReceiveSpeedUpdateEvent(SpeedUpdateEvent event) {

private void scheduleGpsConnection() {
if (isRunning) {
LOG.info("Received GPS Update. No stop required via OBD Connection Recognizer");
LOG.info("Received GPS Update. No stop required via GPS Connection Recognizer");
if (gpsPendingSubscription != null) {
gpsPendingSubscription.dispose();
gpsPendingSubscription = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public Observable<DataResponse> observe() {
response.getPid(),
response.getValue()));
subscriber.onNext(response);
clearFailureCount(latestCommand.getPid());
}
} catch (IOException e) {
if (!subscriber.isDisposed())
Expand Down Expand Up @@ -264,6 +265,7 @@ protected PIDCommand pollNextCommand() throws AdapterFailedException {
/**
* blacklisted: do not re-add it and return the next candidate
*/
LOGGER.info("Command is on the blocklist: " + cmd.getPid());
return pollNextCommand();
}
}
Expand All @@ -284,6 +286,18 @@ protected void increaseFailureCount(PID command) {
}
}

protected void clearFailureCount(PID command) {
if (command == null) {
return;
}

if (this.failureMap.containsKey(command)) {
if (this.failureMap.get(command).getAndSet(0) > 0) {
LOGGER.info("Command recovered from failures: " + command);
}
}
}

protected List<PIDCommand> defaultCycleCommands() {
if (requestCommands == null) {
requestCommands = new ArrayList<>();
Expand Down

0 comments on commit 00ba858

Please sign in to comment.