summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEnrico Granata2017-03-16 13:02:21 -0500
committerEnrico Granata2017-03-16 14:29:32 -0500
commit24475d0e9c67c758d05fa69bfe34013babfeb176 (patch)
treed35d414d4dac6b8c370ab29c51f55b6ca010aa40 /obd2-lib
parent185a2c831e365fb42f385b3280f27bfdc2ac0218 (diff)
downloadplatform-packages-services-car-24475d0e9c67c758d05fa69bfe34013babfeb176.tar.gz
platform-packages-services-car-24475d0e9c67c758d05fa69bfe34013babfeb176.tar.xz
platform-packages-services-car-24475d0e9c67c758d05fa69bfe34013babfeb176.zip
Add more sensor types to obd2_lib
Test: runtest -x packages/services/Car/tests/obd2_test/src/com/android/car/obd2/test/Obd2CommandTest.java Bug: 36098757 Change-Id: I18312a667ec781f8dc87c210972fe4606348d3fa
Diffstat (limited to 'obd2-lib')
-rw-r--r--obd2-lib/src/com/android/car/obd2/Obd2Command.java57
-rw-r--r--obd2-lib/src/com/android/car/obd2/commands/CalculatedEngineLoad.java34
-rw-r--r--obd2-lib/src/com/android/car/obd2/commands/EngineCoolantTemperature.java34
-rw-r--r--obd2-lib/src/com/android/car/obd2/commands/EngineRuntime.java36
-rw-r--r--obd2-lib/src/com/android/car/obd2/commands/FuelGaugePressure.java34
-rw-r--r--obd2-lib/src/com/android/car/obd2/commands/FuelSystemStatus.java34
-rw-r--r--obd2-lib/src/com/android/car/obd2/commands/FuelTankLevel.java36
-rw-r--r--obd2-lib/src/com/android/car/obd2/commands/FuelTrimCommand.java59
-rw-r--r--obd2-lib/src/com/android/car/obd2/commands/RPM.java36
-rw-r--r--obd2-lib/src/com/android/car/obd2/commands/Speed.java34
-rw-r--r--obd2-lib/src/com/android/car/obd2/commands/ThrottlePosition.java36
11 files changed, 419 insertions, 11 deletions
diff --git a/obd2-lib/src/com/android/car/obd2/Obd2Command.java b/obd2-lib/src/com/android/car/obd2/Obd2Command.java
index 3cbbf58e..e02c6af5 100644
--- a/obd2-lib/src/com/android/car/obd2/Obd2Command.java
+++ b/obd2-lib/src/com/android/car/obd2/Obd2Command.java
@@ -17,9 +17,23 @@
17package com.android.car.obd2; 17package com.android.car.obd2;
18 18
19import com.android.car.obd2.commands.AmbientAirTemperature; 19import com.android.car.obd2.commands.AmbientAirTemperature;
20import com.android.car.obd2.commands.CalculatedEngineLoad;
21import com.android.car.obd2.commands.EngineCoolantTemperature;
20import com.android.car.obd2.commands.EngineOilTemperature; 22import com.android.car.obd2.commands.EngineOilTemperature;
23import com.android.car.obd2.commands.EngineRuntime;
24import com.android.car.obd2.commands.FuelGaugePressure;
25import com.android.car.obd2.commands.FuelSystemStatus;
26import com.android.car.obd2.commands.FuelTankLevel;
27import com.android.car.obd2.commands.FuelTrimCommand.Bank1LongTermFuelTrimCommand;
28import com.android.car.obd2.commands.FuelTrimCommand.Bank1ShortTermFuelTrimCommand;
29import com.android.car.obd2.commands.FuelTrimCommand.Bank2LongTermFuelTrimCommand;
30import com.android.car.obd2.commands.FuelTrimCommand.Bank2ShortTermFuelTrimCommand;
31import com.android.car.obd2.commands.RPM;
32import com.android.car.obd2.commands.Speed;
33import com.android.car.obd2.commands.ThrottlePosition;
21import java.io.IOException; 34import java.io.IOException;
22import java.util.HashMap; 35import java.util.HashMap;
36import java.util.Objects;
23import java.util.Optional; 37import java.util.Optional;
24import java.util.Set; 38import java.util.Set;
25 39
@@ -51,16 +65,22 @@ public abstract class Obd2Command<ValueType> {
51 private static final HashMap<Integer, OutputSemanticHandler<Float>> SUPPORTED_FLOAT_COMMANDS = 65 private static final HashMap<Integer, OutputSemanticHandler<Float>> SUPPORTED_FLOAT_COMMANDS =
52 new HashMap<>(); 66 new HashMap<>();
53 67
54 private static void addSupportedIntegerCommand( 68 private static void addSupportedIntegerCommands(
55 OutputSemanticHandler<Integer> integerOutputSemanticHandler) { 69 OutputSemanticHandler<Integer>... integerOutputSemanticHandlers) {
56 SUPPORTED_INTEGER_COMMANDS.put( 70 for (OutputSemanticHandler<Integer> integerOutputSemanticHandler :
57 integerOutputSemanticHandler.getPid(), integerOutputSemanticHandler); 71 integerOutputSemanticHandlers) {
72 SUPPORTED_INTEGER_COMMANDS.put(
73 integerOutputSemanticHandler.getPid(), integerOutputSemanticHandler);
74 }
58 } 75 }
59 76
60 private static void addSupportedFloatCommand( 77 private static void addSupportedFloatCommands(
61 OutputSemanticHandler<Float> floatOutputSemanticHandler) { 78 OutputSemanticHandler<Float>... floatOutputSemanticHandlers) {
62 SUPPORTED_FLOAT_COMMANDS.put( 79 for (OutputSemanticHandler<Float> floatOutputSemanticHandler :
63 floatOutputSemanticHandler.getPid(), floatOutputSemanticHandler); 80 floatOutputSemanticHandlers) {
81 SUPPORTED_FLOAT_COMMANDS.put(
82 floatOutputSemanticHandler.getPid(), floatOutputSemanticHandler);
83 }
64 } 84 }
65 85
66 public static Set<Integer> getSupportedIntegerCommands() { 86 public static Set<Integer> getSupportedIntegerCommands() {
@@ -80,8 +100,23 @@ public abstract class Obd2Command<ValueType> {
80 } 100 }
81 101
82 static { 102 static {
83 addSupportedFloatCommand(new AmbientAirTemperature()); 103 addSupportedFloatCommands(
84 addSupportedIntegerCommand(new EngineOilTemperature()); 104 new AmbientAirTemperature(),
105 new CalculatedEngineLoad(),
106 new FuelTankLevel(),
107 new Bank2ShortTermFuelTrimCommand(),
108 new Bank2LongTermFuelTrimCommand(),
109 new Bank1LongTermFuelTrimCommand(),
110 new Bank1ShortTermFuelTrimCommand(),
111 new ThrottlePosition());
112 addSupportedIntegerCommands(
113 new EngineOilTemperature(),
114 new EngineCoolantTemperature(),
115 new FuelGaugePressure(),
116 new FuelSystemStatus(),
117 new RPM(),
118 new EngineRuntime(),
119 new Speed());
85 } 120 }
86 121
87 protected final int mMode; 122 protected final int mMode;
@@ -89,7 +124,7 @@ public abstract class Obd2Command<ValueType> {
89 124
90 Obd2Command(int mode, OutputSemanticHandler<ValueType> semanticHandler) { 125 Obd2Command(int mode, OutputSemanticHandler<ValueType> semanticHandler) {
91 mMode = mode; 126 mMode = mode;
92 mSemanticHandler = semanticHandler; 127 mSemanticHandler = Objects.requireNonNull(semanticHandler);
93 } 128 }
94 129
95 public abstract Optional<ValueType> run(Obd2Connection connection) throws Exception; 130 public abstract Optional<ValueType> run(Obd2Connection connection) throws Exception;
diff --git a/obd2-lib/src/com/android/car/obd2/commands/CalculatedEngineLoad.java b/obd2-lib/src/com/android/car/obd2/commands/CalculatedEngineLoad.java
new file mode 100644
index 00000000..ca06343b
--- /dev/null
+++ b/obd2-lib/src/com/android/car/obd2/commands/CalculatedEngineLoad.java
@@ -0,0 +1,34 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.car.obd2.commands;
18
19import com.android.car.obd2.IntegerArrayStream;
20import com.android.car.obd2.Obd2Command;
21import java.util.Optional;
22
23public class CalculatedEngineLoad implements Obd2Command.OutputSemanticHandler<Float> {
24 @Override
25 public int getPid() {
26 return 0x04;
27 }
28
29 @Override
30 public Optional<Float> consume(IntegerArrayStream data) {
31 return data.hasAtLeast(
32 1, theData -> Optional.of(theData.consume() / 2.25f), theData -> Optional.empty());
33 }
34}
diff --git a/obd2-lib/src/com/android/car/obd2/commands/EngineCoolantTemperature.java b/obd2-lib/src/com/android/car/obd2/commands/EngineCoolantTemperature.java
new file mode 100644
index 00000000..41ad73ce
--- /dev/null
+++ b/obd2-lib/src/com/android/car/obd2/commands/EngineCoolantTemperature.java
@@ -0,0 +1,34 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.car.obd2.commands;
18
19import com.android.car.obd2.IntegerArrayStream;
20import com.android.car.obd2.Obd2Command;
21import java.util.Optional;
22
23public class EngineCoolantTemperature implements Obd2Command.OutputSemanticHandler<Integer> {
24 @Override
25 public int getPid() {
26 return 0x05;
27 }
28
29 @Override
30 public Optional<Integer> consume(IntegerArrayStream data) {
31 return data.hasAtLeast(
32 1, theData -> Optional.of(theData.consume() - 40), theData -> Optional.empty());
33 }
34}
diff --git a/obd2-lib/src/com/android/car/obd2/commands/EngineRuntime.java b/obd2-lib/src/com/android/car/obd2/commands/EngineRuntime.java
new file mode 100644
index 00000000..13c886fc
--- /dev/null
+++ b/obd2-lib/src/com/android/car/obd2/commands/EngineRuntime.java
@@ -0,0 +1,36 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.car.obd2.commands;
18
19import com.android.car.obd2.IntegerArrayStream;
20import com.android.car.obd2.Obd2Command;
21import java.util.Optional;
22
23public class EngineRuntime implements Obd2Command.OutputSemanticHandler<Integer> {
24 @Override
25 public int getPid() {
26 return 0x1F;
27 }
28
29 @Override
30 public Optional<Integer> consume(IntegerArrayStream data) {
31 return data.hasAtLeast(
32 2,
33 theData -> Optional.of(theData.consume() * 256 + theData.consume()),
34 theData -> Optional.empty());
35 }
36}
diff --git a/obd2-lib/src/com/android/car/obd2/commands/FuelGaugePressure.java b/obd2-lib/src/com/android/car/obd2/commands/FuelGaugePressure.java
new file mode 100644
index 00000000..fc7aacea
--- /dev/null
+++ b/obd2-lib/src/com/android/car/obd2/commands/FuelGaugePressure.java
@@ -0,0 +1,34 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.car.obd2.commands;
18
19import com.android.car.obd2.IntegerArrayStream;
20import com.android.car.obd2.Obd2Command;
21import java.util.Optional;
22
23public class FuelGaugePressure implements Obd2Command.OutputSemanticHandler<Integer> {
24 @Override
25 public int getPid() {
26 return 0x0A;
27 }
28
29 @Override
30 public Optional<Integer> consume(IntegerArrayStream data) {
31 return data.hasAtLeast(
32 1, theData -> Optional.of(theData.consume() * 3), theData -> Optional.empty());
33 }
34}
diff --git a/obd2-lib/src/com/android/car/obd2/commands/FuelSystemStatus.java b/obd2-lib/src/com/android/car/obd2/commands/FuelSystemStatus.java
new file mode 100644
index 00000000..65001f8c
--- /dev/null
+++ b/obd2-lib/src/com/android/car/obd2/commands/FuelSystemStatus.java
@@ -0,0 +1,34 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.car.obd2.commands;
18
19import com.android.car.obd2.IntegerArrayStream;
20import com.android.car.obd2.Obd2Command;
21import java.util.Optional;
22
23public class FuelSystemStatus implements Obd2Command.OutputSemanticHandler<Integer> {
24 @Override
25 public int getPid() {
26 return 0x03;
27 }
28
29 @Override
30 public Optional<Integer> consume(IntegerArrayStream data) {
31 return data.hasAtLeast(
32 1, theData -> Optional.of(theData.consume()), theData -> Optional.empty());
33 }
34}
diff --git a/obd2-lib/src/com/android/car/obd2/commands/FuelTankLevel.java b/obd2-lib/src/com/android/car/obd2/commands/FuelTankLevel.java
new file mode 100644
index 00000000..190b5546
--- /dev/null
+++ b/obd2-lib/src/com/android/car/obd2/commands/FuelTankLevel.java
@@ -0,0 +1,36 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.car.obd2.commands;
18
19import com.android.car.obd2.IntegerArrayStream;
20import com.android.car.obd2.Obd2Command;
21import java.util.Optional;
22
23public class FuelTankLevel implements Obd2Command.OutputSemanticHandler<Float> {
24 @Override
25 public int getPid() {
26 return 0x2F;
27 }
28
29 @Override
30 public Optional<Float> consume(IntegerArrayStream data) {
31 return data.hasAtLeast(
32 1,
33 theData -> Optional.of(theData.consume() * (100.0f / 255.0f)),
34 theData -> Optional.empty());
35 }
36}
diff --git a/obd2-lib/src/com/android/car/obd2/commands/FuelTrimCommand.java b/obd2-lib/src/com/android/car/obd2/commands/FuelTrimCommand.java
new file mode 100644
index 00000000..5f22a6e5
--- /dev/null
+++ b/obd2-lib/src/com/android/car/obd2/commands/FuelTrimCommand.java
@@ -0,0 +1,59 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.car.obd2.commands;
18
19import com.android.car.obd2.IntegerArrayStream;
20import com.android.car.obd2.Obd2Command;
21import java.util.Optional;
22
23public abstract class FuelTrimCommand implements Obd2Command.OutputSemanticHandler<Float> {
24 @Override
25 public Optional<Float> consume(IntegerArrayStream data) {
26 return data.hasAtLeast(
27 1,
28 theData -> Optional.of(3 * theData.consume() / 1.28f - 100),
29 theData -> Optional.empty());
30 }
31
32 public static class Bank1ShortTermFuelTrimCommand extends FuelTrimCommand {
33 @Override
34 public int getPid() {
35 return 0x06;
36 }
37 }
38
39 public static class Bank1LongTermFuelTrimCommand extends FuelTrimCommand {
40 @Override
41 public int getPid() {
42 return 0x07;
43 }
44 }
45
46 public static class Bank2ShortTermFuelTrimCommand extends FuelTrimCommand {
47 @Override
48 public int getPid() {
49 return 0x08;
50 }
51 }
52
53 public static class Bank2LongTermFuelTrimCommand extends FuelTrimCommand {
54 @Override
55 public int getPid() {
56 return 0x09;
57 }
58 }
59}
diff --git a/obd2-lib/src/com/android/car/obd2/commands/RPM.java b/obd2-lib/src/com/android/car/obd2/commands/RPM.java
new file mode 100644
index 00000000..c4bb91fd
--- /dev/null
+++ b/obd2-lib/src/com/android/car/obd2/commands/RPM.java
@@ -0,0 +1,36 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.car.obd2.commands;
18
19import com.android.car.obd2.IntegerArrayStream;
20import com.android.car.obd2.Obd2Command;
21import java.util.Optional;
22
23public class RPM implements Obd2Command.OutputSemanticHandler<Integer> {
24 @Override
25 public int getPid() {
26 return 0x0C;
27 }
28
29 @Override
30 public Optional<Integer> consume(IntegerArrayStream data) {
31 return data.hasAtLeast(
32 2,
33 theData -> Optional.of(theData.consume() * 256 + theData.consume() / 4),
34 theData -> Optional.empty());
35 }
36}
diff --git a/obd2-lib/src/com/android/car/obd2/commands/Speed.java b/obd2-lib/src/com/android/car/obd2/commands/Speed.java
new file mode 100644
index 00000000..c797ce5c
--- /dev/null
+++ b/obd2-lib/src/com/android/car/obd2/commands/Speed.java
@@ -0,0 +1,34 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.car.obd2.commands;
18
19import com.android.car.obd2.IntegerArrayStream;
20import com.android.car.obd2.Obd2Command;
21import java.util.Optional;
22
23public class Speed implements Obd2Command.OutputSemanticHandler<Integer> {
24 @Override
25 public int getPid() {
26 return 0x0D;
27 }
28
29 @Override
30 public Optional<Integer> consume(IntegerArrayStream data) {
31 return data.hasAtLeast(
32 1, theData -> Optional.of(theData.consume()), theData -> Optional.empty());
33 }
34}
diff --git a/obd2-lib/src/com/android/car/obd2/commands/ThrottlePosition.java b/obd2-lib/src/com/android/car/obd2/commands/ThrottlePosition.java
new file mode 100644
index 00000000..71f4fee9
--- /dev/null
+++ b/obd2-lib/src/com/android/car/obd2/commands/ThrottlePosition.java
@@ -0,0 +1,36 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.car.obd2.commands;
18
19import com.android.car.obd2.IntegerArrayStream;
20import com.android.car.obd2.Obd2Command;
21import java.util.Optional;
22
23public class ThrottlePosition implements Obd2Command.OutputSemanticHandler<Float> {
24 @Override
25 public int getPid() {
26 return 0x11;
27 }
28
29 @Override
30 public Optional<Float> consume(IntegerArrayStream data) {
31 return data.hasAtLeast(
32 1,
33 theData -> Optional.of(theData.consume() * 0.392157f),
34 theData -> Optional.empty());
35 }
36}