summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEnrico Granata2017-03-27 14:40:13 -0500
committerEnrico Granata2017-03-27 16:15:38 -0500
commit3a3850c37c5548373650f4b78e916da86d1a5266 (patch)
treecc5f2fc5c74807e4ba1a60a3e893258de3e7b694 /obd2-lib
parentefc36bc33992bc81901f119f3a31b4a4137ae949 (diff)
downloadplatform-packages-services-car-3a3850c37c5548373650f4b78e916da86d1a5266.tar.gz
platform-packages-services-car-3a3850c37c5548373650f4b78e916da86d1a5266.tar.xz
platform-packages-services-car-3a3850c37c5548373650f4b78e916da86d1a5266.zip
Rework the way diagnostic events are serialized to JSON, and deserialized:
- add a "type" field to distinguish between live and freeze frame data; - make a DiagnosticJson class to contain the deserialized JSON; - move logic to make a VehiclePropValue out of JSON into its own class (DiagnosticJsonReader / DiagnosticJson.Builder) This is useful/necessary because you need to know the number of vendor specific sensors if you're going to generate a valid VehiclePropValue for a real vehicle instead of a test case Test: runtest -x packages/services/Car/tests/obd2_test/src/com/android/car/obd2/test/Obd2LiveFrameGeneratorTest.java Change-Id: Ibc32fef65907137a36b33bf5ae983f27cff15e87
Diffstat (limited to 'obd2-lib')
-rw-r--r--obd2-lib/src/com/android/car/obd2/Obd2LiveFrameGenerator.java16
1 files changed, 12 insertions, 4 deletions
diff --git a/obd2-lib/src/com/android/car/obd2/Obd2LiveFrameGenerator.java b/obd2-lib/src/com/android/car/obd2/Obd2LiveFrameGenerator.java
index 5fb45391..121b54aa 100644
--- a/obd2-lib/src/com/android/car/obd2/Obd2LiveFrameGenerator.java
+++ b/obd2-lib/src/com/android/car/obd2/Obd2LiveFrameGenerator.java
@@ -27,6 +27,7 @@ import java.util.Optional;
27import java.util.Set; 27import java.util.Set;
28 28
29public class Obd2LiveFrameGenerator { 29public class Obd2LiveFrameGenerator {
30 public static final int FRAME_TYPE_LIVE = 1;
30 public static final String TAG = Obd2LiveFrameGenerator.class.getSimpleName(); 31 public static final String TAG = Obd2LiveFrameGenerator.class.getSimpleName();
31 32
32 private final Obd2Connection mConnection; 33 private final Obd2Connection mConnection;
@@ -63,6 +64,7 @@ public class Obd2LiveFrameGenerator {
63 64
64 public JsonWriter generate(JsonWriter jsonWriter, long timestamp) throws IOException { 65 public JsonWriter generate(JsonWriter jsonWriter, long timestamp) throws IOException {
65 jsonWriter.beginObject(); 66 jsonWriter.beginObject();
67 jsonWriter.name("type").value(FRAME_TYPE_LIVE);
66 jsonWriter.name("timestamp").value(timestamp); 68 jsonWriter.name("timestamp").value(timestamp);
67 jsonWriter.name("intValues").beginArray(); 69 jsonWriter.name("intValues").beginArray();
68 for (LiveFrameCommand<Integer> command : mIntegerCommands) { 70 for (LiveFrameCommand<Integer> command : mIntegerCommands) {
@@ -75,8 +77,11 @@ public class Obd2LiveFrameGenerator {
75 jsonWriter.endObject(); 77 jsonWriter.endObject();
76 } 78 }
77 } catch (IOException | InterruptedException e) { 79 } catch (IOException | InterruptedException e) {
78 Log.w(TAG, String.format("unable to retrieve OBD2 pid %d due to exception: %s", 80 Log.w(
79 command.getPid(), e)); 81 TAG,
82 String.format(
83 "unable to retrieve OBD2 pid %d due to exception: %s",
84 command.getPid(), e));
80 // skip this entry 85 // skip this entry
81 } 86 }
82 } 87 }
@@ -93,8 +98,11 @@ public class Obd2LiveFrameGenerator {
93 jsonWriter.endObject(); 98 jsonWriter.endObject();
94 } 99 }
95 } catch (IOException | InterruptedException e) { 100 } catch (IOException | InterruptedException e) {
96 Log.w(TAG, String.format("unable to retrieve OBD2 pid %d due to exception: %s", 101 Log.w(
97 command.getPid(), e)); 102 TAG,
103 String.format(
104 "unable to retrieve OBD2 pid %d due to exception: %s",
105 command.getPid(), e));
98 // skip this entry 106 // skip this entry
99 } 107 }
100 } 108 }