From c77259fc9f485415e98f6180015d8314fbe89d38 Mon Sep 17 00:00:00 2001 From: matthesrieke Date: Tue, 12 Jan 2016 15:00:51 +0100 Subject: [PATCH 1/3] implement lambda switch workaround --- org.envirocar.app/AndroidManifest.xml | 2 +- .../commands/response/ResponseParserTest.java | 11 ++++ .../envirocar/obd/adapter/DataCollector.java | 14 ----- .../adapter/async/DriveDeckSportAdapter.java | 2 +- .../obd/commands/response/ResponseParser.java | 58 ++++++++++++++++++- 5 files changed, 68 insertions(+), 19 deletions(-) delete mode 100644 org.envirocar.obd/src/main/java/org/envirocar/obd/adapter/DataCollector.java diff --git a/org.envirocar.app/AndroidManifest.xml b/org.envirocar.app/AndroidManifest.xml index 9113429c2..88528d057 100644 --- a/org.envirocar.app/AndroidManifest.xml +++ b/org.envirocar.app/AndroidManifest.xml @@ -4,7 +4,7 @@ package="org.envirocar.app" android:installLocation="internalOnly" android:versionCode="28" - android:versionName="0.21.0"> + android:versionName="0.21.0-SNAPSHOT"> getSupportedPIDs() { private DataResponse parsePIDResponse(String pid, byte[] rawBytes) throws InvalidCommandResponseException, NoDataReceivedException, UnmatchedResponseException, AdapterSearchingException { - logger.verbose(String.format("Processing PID Response: %s; %s", pid, Base64.encodeToString(rawBytes, Base64.DEFAULT)).trim()); + logger.verbose(String.format("PID Response: %s; %s", pid, Base64.encodeToString(rawBytes, Base64.DEFAULT)).trim()); /* * resulting HEX values are 0x0d additive to the diff --git a/org.envirocar.obd/src/main/java/org/envirocar/obd/commands/response/ResponseParser.java b/org.envirocar.obd/src/main/java/org/envirocar/obd/commands/response/ResponseParser.java index e75f8e027..8c7e0f71d 100644 --- a/org.envirocar.obd/src/main/java/org/envirocar/obd/commands/response/ResponseParser.java +++ b/org.envirocar.obd/src/main/java/org/envirocar/obd/commands/response/ResponseParser.java @@ -1,5 +1,6 @@ package org.envirocar.obd.commands.response; +import org.envirocar.core.logging.Logger; import org.envirocar.obd.commands.PID; import org.envirocar.obd.commands.PIDUtil; import org.envirocar.obd.commands.response.entity.GenericDataResponse; @@ -21,12 +22,19 @@ import org.envirocar.obd.commands.response.entity.ThrottlePositionResponse; import org.envirocar.obd.exception.InvalidCommandResponseException; +import java.util.concurrent.atomic.AtomicBoolean; + public class ResponseParser { + private static final Logger LOGGER = Logger.getLogger(ResponseParser.class); + private static final CharSequence SEARCHING = "SEARCHING"; private static final CharSequence STOPPED = "STOPPED"; private static final CharSequence NO_DATA = "NODATA"; public static final String STATUS_OK = "41"; + private AtomicBoolean lambdaVoltageSwitched; + private int lambdaSwitchCandidates; + private int totalLambdas; public ResponseParser() { @@ -125,9 +133,10 @@ private DataResponse createDataResponse(PID pid, int[] processedData, byte[] raw case O2_LAMBDA_PROBE_6_VOLTAGE: case O2_LAMBDA_PROBE_7_VOLTAGE: case O2_LAMBDA_PROBE_8_VOLTAGE: - return new LambdaProbeVoltageResponse( - ((processedData[4]*256d) + processedData[5] )/ 8192d, - ((processedData[2]*256d) + processedData[3]) / 32768d); + LambdaProbeVoltageResponse lambda = new LambdaProbeVoltageResponse( + ((processedData[4] * 256d) + processedData[5]) / 8192d, + ((processedData[2] * 256d) + processedData[3]) / 32768d); + return checkForPossibleSwitchedValues(lambda, processedData); case O2_LAMBDA_PROBE_1_CURRENT: case O2_LAMBDA_PROBE_2_CURRENT: case O2_LAMBDA_PROBE_3_CURRENT: @@ -144,6 +153,49 @@ private DataResponse createDataResponse(PID pid, int[] processedData, byte[] raw return new GenericDataResponse(pid, processedData, rawData); } + private LambdaProbeVoltageResponse checkForPossibleSwitchedValues(LambdaProbeVoltageResponse lambda, int[] processedData) { + if (lambdaVoltageSwitched != null) { + if (lambdaVoltageSwitched.get()) { + /** + * there are two ways of switching lambda response values: + * + * 1. just switch the calculated results (this does not consider the different formulas for ER and V) + * 2. switch the byte position 2,3 and 4,5 and recalculate with the formulas + * + * for the moment, we just switch + */ + return new LambdaProbeVoltageResponse(lambda.getEquivalenceRatio(), lambda.getVoltage()); + } + else { + return lambda; + } + } + else { + totalLambdas++; + /** + * we are in determination mode + */ + double ratio = lambda.getEquivalenceRatio() == 0.0d ? 1.0d : (lambda.getVoltage() / lambda.getEquivalenceRatio()); + + if (ratio >= 1.0d) { + lambdaSwitchCandidates++; + } + + if (totalLambdas > 100) { + if (lambdaSwitchCandidates > 20) { + lambdaVoltageSwitched = new AtomicBoolean(true); + } + else { + lambdaVoltageSwitched = new AtomicBoolean(false); + } + + LOGGER.info("Lambda Switch analysis completed: switching? "+lambdaVoltageSwitched.get()); + } + + return lambda; + } + } + private boolean isSearching(String dataString) { return dataString.contains(SEARCHING) || dataString.contains(STOPPED); From 6c542684a868876b2d33d7c27d3ae21a1a3ed98c Mon Sep 17 00:00:00 2001 From: matthesrieke Date: Thu, 14 Jan 2016 10:22:06 +0100 Subject: [PATCH 2/3] change logger name --- org.envirocar.app/src/org/envirocar/app/BaseMainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.envirocar.app/src/org/envirocar/app/BaseMainActivity.java b/org.envirocar.app/src/org/envirocar/app/BaseMainActivity.java index 62dede68b..ea9e11b79 100644 --- a/org.envirocar.app/src/org/envirocar/app/BaseMainActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/BaseMainActivity.java @@ -100,7 +100,7 @@ * @author dewall */ public class BaseMainActivity extends BaseInjectorActivity { - private static final Logger LOGGER = Logger.getLogger(BaseApplication.class); + private static final Logger LOGGER = Logger.getLogger(BaseMainActivity.class); public static final int TRACK_MODE_SINGLE = 0; public static final int TRACK_MODE_AUTO = 1; From cfaead9bffa85fd4be0e22cddc8011cca0459cae Mon Sep 17 00:00:00 2001 From: matthesrieke Date: Thu, 14 Jan 2016 10:24:23 +0100 Subject: [PATCH 3/3] remove lambda switching for the moment --- .../obd/commands/response/ResponseParser.java | 59 ++----------------- 1 file changed, 5 insertions(+), 54 deletions(-) diff --git a/org.envirocar.obd/src/main/java/org/envirocar/obd/commands/response/ResponseParser.java b/org.envirocar.obd/src/main/java/org/envirocar/obd/commands/response/ResponseParser.java index 8c7e0f71d..c92cadfa5 100644 --- a/org.envirocar.obd/src/main/java/org/envirocar/obd/commands/response/ResponseParser.java +++ b/org.envirocar.obd/src/main/java/org/envirocar/obd/commands/response/ResponseParser.java @@ -3,14 +3,11 @@ import org.envirocar.core.logging.Logger; import org.envirocar.obd.commands.PID; import org.envirocar.obd.commands.PIDUtil; -import org.envirocar.obd.commands.response.entity.GenericDataResponse; -import org.envirocar.obd.exception.AdapterSearchingException; -import org.envirocar.obd.exception.NoDataReceivedException; -import org.envirocar.obd.exception.UnmatchedResponseException; import org.envirocar.obd.commands.response.entity.EngineLoadResponse; import org.envirocar.obd.commands.response.entity.EngineRPMResponse; import org.envirocar.obd.commands.response.entity.FuelPressureResponse; import org.envirocar.obd.commands.response.entity.FuelSystemStatusResponse; +import org.envirocar.obd.commands.response.entity.GenericDataResponse; import org.envirocar.obd.commands.response.entity.IntakeAirTemperatureResponse; import org.envirocar.obd.commands.response.entity.IntakeManifoldAbsolutePressureResponse; import org.envirocar.obd.commands.response.entity.LambdaProbeCurrentResponse; @@ -20,9 +17,10 @@ import org.envirocar.obd.commands.response.entity.ShortTermFuelTrimResponse; import org.envirocar.obd.commands.response.entity.SpeedResponse; import org.envirocar.obd.commands.response.entity.ThrottlePositionResponse; +import org.envirocar.obd.exception.AdapterSearchingException; import org.envirocar.obd.exception.InvalidCommandResponseException; - -import java.util.concurrent.atomic.AtomicBoolean; +import org.envirocar.obd.exception.NoDataReceivedException; +import org.envirocar.obd.exception.UnmatchedResponseException; public class ResponseParser { @@ -32,9 +30,6 @@ public class ResponseParser { private static final CharSequence STOPPED = "STOPPED"; private static final CharSequence NO_DATA = "NODATA"; public static final String STATUS_OK = "41"; - private AtomicBoolean lambdaVoltageSwitched; - private int lambdaSwitchCandidates; - private int totalLambdas; public ResponseParser() { @@ -136,7 +131,7 @@ private DataResponse createDataResponse(PID pid, int[] processedData, byte[] raw LambdaProbeVoltageResponse lambda = new LambdaProbeVoltageResponse( ((processedData[4] * 256d) + processedData[5]) / 8192d, ((processedData[2] * 256d) + processedData[3]) / 32768d); - return checkForPossibleSwitchedValues(lambda, processedData); + return lambda; case O2_LAMBDA_PROBE_1_CURRENT: case O2_LAMBDA_PROBE_2_CURRENT: case O2_LAMBDA_PROBE_3_CURRENT: @@ -153,50 +148,6 @@ private DataResponse createDataResponse(PID pid, int[] processedData, byte[] raw return new GenericDataResponse(pid, processedData, rawData); } - private LambdaProbeVoltageResponse checkForPossibleSwitchedValues(LambdaProbeVoltageResponse lambda, int[] processedData) { - if (lambdaVoltageSwitched != null) { - if (lambdaVoltageSwitched.get()) { - /** - * there are two ways of switching lambda response values: - * - * 1. just switch the calculated results (this does not consider the different formulas for ER and V) - * 2. switch the byte position 2,3 and 4,5 and recalculate with the formulas - * - * for the moment, we just switch - */ - return new LambdaProbeVoltageResponse(lambda.getEquivalenceRatio(), lambda.getVoltage()); - } - else { - return lambda; - } - } - else { - totalLambdas++; - /** - * we are in determination mode - */ - double ratio = lambda.getEquivalenceRatio() == 0.0d ? 1.0d : (lambda.getVoltage() / lambda.getEquivalenceRatio()); - - if (ratio >= 1.0d) { - lambdaSwitchCandidates++; - } - - if (totalLambdas > 100) { - if (lambdaSwitchCandidates > 20) { - lambdaVoltageSwitched = new AtomicBoolean(true); - } - else { - lambdaVoltageSwitched = new AtomicBoolean(false); - } - - LOGGER.info("Lambda Switch analysis completed: switching? "+lambdaVoltageSwitched.get()); - } - - return lambda; - } - } - - private boolean isSearching(String dataString) { return dataString.contains(SEARCHING) || dataString.contains(STOPPED); }