From 724af7f0963b43cc36df4ee7ea48404931efdc5b Mon Sep 17 00:00:00 2001 From: Matthes Rieke Date: Thu, 23 Feb 2023 09:48:09 +0100 Subject: [PATCH 1/2] allow commands to recover from failures --- .../recording/strategy/OBDRecordingStrategy.java | 2 +- .../org/envirocar/obd/adapter/SyncAdapter.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/org.envirocar.app/src/org/envirocar/app/recording/strategy/OBDRecordingStrategy.java b/org.envirocar.app/src/org/envirocar/app/recording/strategy/OBDRecordingStrategy.java index a4925d171..bc41920b9 100644 --- a/org.envirocar.app/src/org/envirocar/app/recording/strategy/OBDRecordingStrategy.java +++ b/org.envirocar.app/src/org/envirocar/app/recording/strategy/OBDRecordingStrategy.java @@ -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; diff --git a/org.envirocar.obd/src/main/java/org/envirocar/obd/adapter/SyncAdapter.java b/org.envirocar.obd/src/main/java/org/envirocar/obd/adapter/SyncAdapter.java index 81828a4e0..9ffeb90b5 100644 --- a/org.envirocar.obd/src/main/java/org/envirocar/obd/adapter/SyncAdapter.java +++ b/org.envirocar.obd/src/main/java/org/envirocar/obd/adapter/SyncAdapter.java @@ -217,6 +217,7 @@ public Observable observe() { response.getPid(), response.getValue())); subscriber.onNext(response); + clearFailureCount(latestCommand.getPid()); } } catch (IOException e) { if (!subscriber.isDisposed()) @@ -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(); } } @@ -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: " + cmd.getPid()); + } + } + } + protected List defaultCycleCommands() { if (requestCommands == null) { requestCommands = new ArrayList<>(); From bdaa62d6bf0d68a41b46b662270df8b3776a7ebb Mon Sep 17 00:00:00 2001 From: Matthes Rieke Date: Thu, 23 Feb 2023 09:56:23 +0100 Subject: [PATCH 2/2] fix wrong variable access --- .../src/main/java/org/envirocar/obd/adapter/SyncAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.envirocar.obd/src/main/java/org/envirocar/obd/adapter/SyncAdapter.java b/org.envirocar.obd/src/main/java/org/envirocar/obd/adapter/SyncAdapter.java index 9ffeb90b5..17ffdad8a 100644 --- a/org.envirocar.obd/src/main/java/org/envirocar/obd/adapter/SyncAdapter.java +++ b/org.envirocar.obd/src/main/java/org/envirocar/obd/adapter/SyncAdapter.java @@ -293,7 +293,7 @@ protected void clearFailureCount(PID command) { if (this.failureMap.containsKey(command)) { if (this.failureMap.get(command).getAndSet(0) > 0) { - LOGGER.info("Command recovered from failures: " + cmd.getPid()); + LOGGER.info("Command recovered from failures: " + command); } } }