diff --git a/pom.xml b/pom.xml index 4e371375..e17d3079 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ obd-metrics - 11.0.0-SNAPSHOT + 11.1.0-SNAPSHOT jar diff --git a/src/main/java/org/obd/metrics/api/CommandBufferInitHandler.java b/src/main/java/org/obd/metrics/api/CommandBufferInitHandler.java index c41f0fc7..38e3a0d9 100644 --- a/src/main/java/org/obd/metrics/api/CommandBufferInitHandler.java +++ b/src/main/java/org/obd/metrics/api/CommandBufferInitHandler.java @@ -29,6 +29,7 @@ import org.obd.metrics.buffer.CommandsBuffer; import org.obd.metrics.command.ATCommand; import org.obd.metrics.command.Command; +import org.obd.metrics.command.obd.ObdCommand; import org.obd.metrics.command.process.DelayCommand; import org.obd.metrics.command.process.InitCompletedCommand; import org.obd.metrics.context.Context; @@ -92,16 +93,20 @@ private void appendPIDsGroups(Init init, LinkedList groups) { @SuppressWarnings("unchecked") private Optional mapToCommand(Class defaultClass, PidDefinition pid) { + + log.debug("Instantiating the PID: {} for the group: {}",pid.getPid(),pid.getGroup()); + try { final Class commandClass = (pid.getCommandClass() == null) ? defaultClass : Class.forName(pid.getCommandClass()); if (commandClass == null) { - return Optional.empty(); + return Optional.of(new ObdCommand(pid)); + }else { + final Constructor constructor = (Constructor) commandClass + .getConstructor(PidDefinition.class); + return Optional.of(constructor.newInstance(pid)); } - final Constructor constructor = (Constructor) commandClass - .getConstructor(PidDefinition.class); - return Optional.of(constructor.newInstance(pid)); } catch (Throwable e) { log.error("Failed to initiate command class: {}", pid.getCommandClass(), e); } diff --git a/src/main/java/org/obd/metrics/command/meta/HexCommand.java b/src/main/java/org/obd/metrics/command/meta/HexCodec.java similarity index 68% rename from src/main/java/org/obd/metrics/command/meta/HexCommand.java rename to src/main/java/org/obd/metrics/command/meta/HexCodec.java index 2c6189a8..dc079545 100644 --- a/src/main/java/org/obd/metrics/command/meta/HexCommand.java +++ b/src/main/java/org/obd/metrics/command/meta/HexCodec.java @@ -18,33 +18,35 @@ **/ package org.obd.metrics.command.meta; -import java.util.Optional; - import org.obd.metrics.codec.Codec; import org.obd.metrics.pid.PidDefinition; +import org.obd.metrics.transport.Characters; import org.obd.metrics.transport.message.ConnectorResponse; import lombok.extern.slf4j.Slf4j; @Slf4j -public final class HexCommand extends MetadataCommand implements Codec { - - public HexCommand(PidDefinition pid) { - super(pid); - } +public final class HexCodec implements Codec { @Override public String decode(PidDefinition pid, ConnectorResponse connectorResponse) { - log.info("Decoding the message: {}", connectorResponse.getMessage()); - final Optional answer = decodeRawMessage(getQuery(),connectorResponse); - - if (answer.isPresent()) { - final String decoded = Hex.decode(answer.get()); + if (log.isTraceEnabled()) { + log.trace("PID: {}, received message: {}",pid.getPid(), connectorResponse.getMessage()); + } + + final String rawValue = connectorResponse.getRawValue(pid); + if (rawValue == null) { + return null; + }else { + final String answer = Characters.normalize(rawValue); + final String decoded = Hex.decode(answer); final String result = (decoded == null) ? null : decoded.trim(); - log.info("Decoded message: {} for: {}", result, connectorResponse.getMessage()); + + if (log.isTraceEnabled()) { + log.trace("Decoded message: {} for: {}", result, connectorResponse.getMessage()); + } return result; } - return null; } } diff --git a/src/main/java/org/obd/metrics/command/meta/MetadataCommand.java b/src/main/java/org/obd/metrics/command/meta/MetadataCommand.java index 71234926..cb24a8d1 100644 --- a/src/main/java/org/obd/metrics/command/meta/MetadataCommand.java +++ b/src/main/java/org/obd/metrics/command/meta/MetadataCommand.java @@ -20,7 +20,6 @@ import java.util.Optional; -import org.obd.metrics.command.Command; import org.obd.metrics.pid.PidDefinition; import org.obd.metrics.transport.Characters; import org.obd.metrics.transport.message.ConnectorResponse; @@ -28,13 +27,11 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -public abstract class MetadataCommand extends Command { +public abstract class MetadataCommand { protected final PidDefinition pid; protected MetadataCommand(PidDefinition pid) { - super(pid.getQuery(), pid.getMode(), - pid.getDescription(), pid.getOverrides().getCanMode() != null ? pid.getOverrides().getCanMode() : ""); this.pid = pid; } diff --git a/src/main/java/org/obd/metrics/command/meta/NotEncodedCommand.java b/src/main/java/org/obd/metrics/command/meta/NotEncodedCodec.java similarity index 70% rename from src/main/java/org/obd/metrics/command/meta/NotEncodedCommand.java rename to src/main/java/org/obd/metrics/command/meta/NotEncodedCodec.java index 3820a14a..e7eafb4b 100644 --- a/src/main/java/org/obd/metrics/command/meta/NotEncodedCommand.java +++ b/src/main/java/org/obd/metrics/command/meta/NotEncodedCodec.java @@ -18,30 +18,23 @@ **/ package org.obd.metrics.command.meta; -import java.util.Optional; - import org.obd.metrics.codec.Codec; import org.obd.metrics.pid.PidDefinition; +import org.obd.metrics.transport.Characters; import org.obd.metrics.transport.message.ConnectorResponse; import lombok.extern.slf4j.Slf4j; @Slf4j -public final class NotEncodedCommand extends MetadataCommand implements Codec { +public final class NotEncodedCodec implements Codec { - public NotEncodedCommand(PidDefinition pid) { - super(pid); - } @Override public String decode(PidDefinition pid, ConnectorResponse connectorResponse) { - - log.info("Decoding the message: {}", connectorResponse.getMessage()); - final Optional answer = decodeRawMessage(getQuery(), connectorResponse); - if (answer.isPresent()) { - log.info("Decoded message: {} for: {}", answer.get(), connectorResponse.getMessage()); - return answer.get(); + if (log.isTraceEnabled()) { + log.trace("Decoding the message: {}", connectorResponse.getMessage()); } - return null; + final String rawValue = connectorResponse.getRawValue(pid); + return rawValue == null ? null : Characters.normalize(rawValue); } } diff --git a/src/main/java/org/obd/metrics/command/meta/TimeCommand.java b/src/main/java/org/obd/metrics/command/meta/TimeCommand.java index 792f1100..916bbf39 100644 --- a/src/main/java/org/obd/metrics/command/meta/TimeCommand.java +++ b/src/main/java/org/obd/metrics/command/meta/TimeCommand.java @@ -18,8 +18,6 @@ **/ package org.obd.metrics.command.meta; -import java.util.Optional; - import org.obd.metrics.codec.Codec; import org.obd.metrics.pid.PidDefinition; import org.obd.metrics.transport.message.ConnectorResponse; @@ -27,23 +25,16 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -public final class TimeCommand extends MetadataCommand implements Codec { - - public TimeCommand(PidDefinition pid) { - super(pid); - } +public final class TimeCommand implements Codec { @Override - public Integer decode(PidDefinition pid, ConnectorResponse connectorResponse) { - - log.info("Decoding the message: {}", connectorResponse.getMessage()); - - final Optional answer = decodeRawMessage(getQuery(), connectorResponse); - if (answer.isPresent()) { - final Integer result = Integer.parseInt(answer.get(), 16); - log.info("Decoded message: {} for: {}", result, connectorResponse.getMessage()); - return result; + public String decode(PidDefinition pid, ConnectorResponse connectorResponse) { + if (log.isDebugEnabled()) { + log.debug("Decoding the message: {}", connectorResponse.getMessage()); } - return null; + + final String answer = connectorResponse.getRawValue(pid); + final Integer result = Integer.parseInt(answer, 16); + return result.toString(); } } diff --git a/src/main/java/org/obd/metrics/executor/MetadataReader.java b/src/main/java/org/obd/metrics/executor/MetadataReader.java index c3ab9e07..6dc4d12a 100644 --- a/src/main/java/org/obd/metrics/executor/MetadataReader.java +++ b/src/main/java/org/obd/metrics/executor/MetadataReader.java @@ -21,39 +21,26 @@ import java.util.HashMap; import java.util.Map; -import org.obd.metrics.api.model.Reply; -import org.obd.metrics.codec.Codec; +import org.obd.metrics.api.model.ObdMetric; +import org.obd.metrics.api.model.ReplyObserver; import org.obd.metrics.command.Command; import org.obd.metrics.pid.PIDsGroup; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; @Slf4j -final class MetadataReader extends PIDsGroupReader> { - - MetadataReader() { - super(PIDsGroup.METADATA); - value = new HashMap(); - } +final class MetadataReader extends ReplyObserver { + @Getter + private final Map value = new HashMap(); @Override - public void onNext(Reply reply) { - final Command command = (Command) reply.getCommand(); - log.debug("Recieved vehicle metadata: {}", reply); - - if (command instanceof Codec) { - final Object decode = ((Codec) command).decode(reply.getRaw()); - if (decode == null) { - value.put(command.getLabel(), reply.getRaw().getMessage()); - } else { - if (decode instanceof Map) { - value.putAll((Map) decode); - } else { - value.put(command.getLabel(), decode.toString()); - } - } - } else { - value.put(command.getLabel(), reply.getRaw().getMessage()); - } + public void onNext(ObdMetric reply) { + + if (reply.getCommand().getPid().getGroup() == PIDsGroup.METADATA) { + final Command command = (Command) reply.getCommand(); + log.debug("Recieved vehicle metadata: {}", reply); + value.put(command.getLabel(), reply.getValue().toString()); + } } } diff --git a/src/main/java/org/obd/metrics/executor/PIDsGroupReader.java b/src/main/java/org/obd/metrics/executor/PIDsGroupReader.java index 90f0cb7f..485c6ba9 100644 --- a/src/main/java/org/obd/metrics/executor/PIDsGroupReader.java +++ b/src/main/java/org/obd/metrics/executor/PIDsGroupReader.java @@ -56,8 +56,10 @@ public List> subscribeFor() { }) .filter(p -> p != null) .collect(Collectors.toSet()); - - collect.add(group.getDefaultCommandClass()); + + if (group.getDefaultCommandClass() != null) { + collect.add(group.getDefaultCommandClass()); + } return new ArrayList<>(collect); } } diff --git a/src/main/java/org/obd/metrics/pid/PIDsGroup.java b/src/main/java/org/obd/metrics/pid/PIDsGroup.java index 702976f7..cbd61944 100644 --- a/src/main/java/org/obd/metrics/pid/PIDsGroup.java +++ b/src/main/java/org/obd/metrics/pid/PIDsGroup.java @@ -22,7 +22,6 @@ import org.obd.metrics.command.SupportedPIDsCommand; import org.obd.metrics.command.dtc.DiagnosticTroubleCodeClearCommand; import org.obd.metrics.command.dtc.DiagnosticTroubleCodeCommand; -import org.obd.metrics.command.meta.HexCommand; import lombok.Getter; @@ -30,7 +29,7 @@ public enum PIDsGroup { LIVEDATA(null), ROUTINE(null), - METADATA(HexCommand.class), + METADATA(null), DTC_READ(DiagnosticTroubleCodeCommand.class), DTC_CLEAR(DiagnosticTroubleCodeClearCommand.class), CAPABILITES(SupportedPIDsCommand.class); diff --git a/src/main/java/org/obd/metrics/transport/message/ConnectorResponse.java b/src/main/java/org/obd/metrics/transport/message/ConnectorResponse.java index 36d7a8d4..c61b6ab8 100644 --- a/src/main/java/org/obd/metrics/transport/message/ConnectorResponse.java +++ b/src/main/java/org/obd/metrics/transport/message/ConnectorResponse.java @@ -58,7 +58,11 @@ default int[] getColonPositions() { } default String getRawValue(final PidDefinition pid) { - return getMessage().subSequence(pid.getSuccessCode().length(), remaining()).toString(); + final String message = getMessage(); + final int indexOf = message.indexOf(pid.getSuccessCode()); + return indexOf >= 0 ? + message.subSequence(indexOf + pid.getSuccessCode().length(), remaining()).toString() + : null; } default boolean isResponseCodeSuccess(PidDefinition pidDefinition) { diff --git a/src/main/resources/alfa.json b/src/main/resources/alfa.json index baa91ed6..67c3cddc 100644 --- a/src/main/resources/alfa.json +++ b/src/main/resources/alfa.json @@ -30,7 +30,7 @@ "mode": "22", "pid": "F1A5", "description": "ECU ISO Code", - "commandClass": "org.obd.metrics.command.meta.NotEncodedCommand" + "codecClass": "org.obd.metrics.command.meta.NotEncodedCodec" }, { @@ -64,14 +64,14 @@ "mode": "22", "pid": "F195", "description": "Software version", - "commandClass": "org.obd.metrics.command.meta.NotEncodedCommand" + "codecClass": "org.obd.metrics.command.meta.NotEncodedCodec" }, { "id": "16009", "mode": "22", "pid": "F193", "description": "Hardware version", - "commandClass": "org.obd.metrics.command.meta.NotEncodedCommand" + "codecClass": "org.obd.metrics.command.meta.NotEncodedCodec" }, { "id": "16011", @@ -79,7 +79,7 @@ "pid": "2008", "units": "min", "description": "Functioning time (EEPROM)", - "commandClass": "org.obd.metrics.command.meta.TimeCommand" + "codecClass": "org.obd.metrics.command.meta.TimeCommand" }, { "id": "16012", @@ -87,7 +87,7 @@ "pid": "1008", "units": "min", "description": "Operating time", - "commandClass": "org.obd.metrics.command.meta.TimeCommand" + "codecClass": "org.obd.metrics.command.meta.TimeCommand" } ], diff --git a/src/main/resources/giulia_2.0_gme.json b/src/main/resources/giulia_2.0_gme.json index ab7014f8..89da860b 100644 --- a/src/main/resources/giulia_2.0_gme.json +++ b/src/main/resources/giulia_2.0_gme.json @@ -62,28 +62,32 @@ "id": "17001", "mode": "22", "pid": "F190", - "description": "Vehicle Identification Number" + "description": "Vehicle Identification Number", + "codecClass": "org.obd.metrics.command.meta.HexCodec" }, { "id": "17002", "mode": "22", "pid": "F18C", - "description": "ECU serial number" + "description": "ECU serial number", + "codecClass": "org.obd.metrics.command.meta.HexCodec" }, { "id": "17003", "mode": "22", "pid": "F194", - "description": "Software number" + "description": "Software number", + "codecClass": "org.obd.metrics.command.meta.HexCodec" }, { "id": "17004", "mode": "22", "pid": "F191", - "description": "FIAT drawing number" + "description": "FIAT drawing number", + "codecClass": "org.obd.metrics.command.meta.HexCodec" }, { @@ -91,7 +95,9 @@ "id": "17005", "mode": "22", "pid": "F192", - "description": "Hardware number" + "length": 10, + "description": "Hardware number", + "codecClass": "org.obd.metrics.command.meta.HexCodec" }, { @@ -99,20 +105,22 @@ "id": "17006", "mode": "22", "pid": "F187", - "description": "Spare part number" + "description": "Spare part number", + "codecClass": "org.obd.metrics.command.meta.HexCodec" }, { "id": "17007", "mode": "22", "pid": "F196", - "description": "Homologation number" + "description": "Homologation number", + "codecClass": "org.obd.metrics.command.meta.HexCodec" }, { "id": "17008", "mode": "22", "pid": "F195", "description": "Software version", - "commandClass": "org.obd.metrics.command.meta.NotEncodedCommand" + "codecClass": "org.obd.metrics.command.meta.NotEncodedCodec" }, { @@ -120,14 +128,14 @@ "mode": "22", "pid": "F193", "description": "Hardware version", - "commandClass": "org.obd.metrics.command.meta.NotEncodedCommand" + "codecClass": "org.obd.metrics.command.meta.NotEncodedCodec" }, { "id": "17010", "mode": "22", "pid": "F1A5", "description": "ECU ISO Code", - "commandClass": "org.obd.metrics.command.meta.NotEncodedCommand" + "codecClass": "org.obd.metrics.command.meta.NotEncodedCodec" }, { "id": "17011", @@ -135,7 +143,7 @@ "pid": "2008", "units": "min", "description": "Functioning time (EEPROM)", - "commandClass": "org.obd.metrics.command.meta.TimeCommand" + "codecClass": "org.obd.metrics.command.meta.TimeCommand" }, { "id": "17012", @@ -144,7 +152,7 @@ "length": 4, "units": "min", "description": "Operating time", - "commandClass": "org.obd.metrics.command.meta.TimeCommand" + "codecClass": "org.obd.metrics.command.meta.TimeCommand" } ], diff --git a/src/main/resources/mode01.json b/src/main/resources/mode01.json index 09573420..7d51d911 100644 --- a/src/main/resources/mode01.json +++ b/src/main/resources/mode01.json @@ -50,7 +50,8 @@ "id": "11000", "mode": "09", "pid": "02", - "description": "VIN" + "description": "VIN", + "codecClass": "org.obd.metrics.command.meta.HexCodec" } ], "livedata": [ diff --git a/src/test/java/org/obd/metrics/api/RoutinesTest.java b/src/test/java/org/obd/metrics/api/RoutinesTest.java index 8812513a..f403d3ce 100644 --- a/src/test/java/org/obd/metrics/api/RoutinesTest.java +++ b/src/test/java/org/obd/metrics/api/RoutinesTest.java @@ -35,6 +35,7 @@ import org.obd.metrics.api.model.Query; import org.obd.metrics.command.group.DefaultCommandGroup; import org.obd.metrics.command.routine.RoutineExecutionStatus; +import org.obd.metrics.pid.PidDefinitionRegistry; import org.obd.metrics.test.DataCollector; import org.obd.metrics.test.MockAdapterConnection; import org.obd.metrics.test.SimpleLifecycle; @@ -62,7 +63,7 @@ public void parameterizedTest(String canRequestIDKey,String canRequestIDValue, S SimpleLifecycle lifecycle = new SimpleLifecycle(); - Workflow workflow = SimpleWorkflowFactory.getWorkflow(lifecycle, collector, "giulia_2.0_gme.json"); + Workflow workflow = SimpleWorkflowFactory.getWorkflow(lifecycle, collector, "giulia_2.0_gme.json", "alfa.json"); // Query for specified PID's like: Engine coolant temperature Query query = Query.builder() @@ -70,6 +71,13 @@ public void parameterizedTest(String canRequestIDKey,String canRequestIDValue, S .pid(6008l) // Coolant .pid(6007l) // IAT .build(); + + PidDefinitionRegistry pidRegistry = workflow.getPidRegistry(); + + Assertions.assertThat(pidRegistry.findBy(6015L)).isNotNull(); + Assertions.assertThat(pidRegistry.findBy(6008l)).isNotNull(); + Assertions.assertThat(pidRegistry.findBy(6007l)).isNotNull(); + // Create an instance of mock connection with additional commands and replies MockAdapterConnection connection = MockAdapterConnection.builder() .requestResponse("22 194F 1003 1935 2", "00B0:62194F2E65101:0348193548") @@ -91,7 +99,7 @@ public void parameterizedTest(String canRequestIDKey,String canRequestIDValue, S status = workflow.executeRoutine(routineID, init); Assertions.assertThat(status).isEqualTo(WorkflowExecutionStatus.ROUTINE_QUEUED); - +// // Starting the workflow completion job, it will end workflow after some period // of time (helper method) WorkflowFinalizer.finalize(workflow); @@ -99,6 +107,7 @@ public void parameterizedTest(String canRequestIDKey,String canRequestIDValue, S final String expectedQueries = "ATD, ATZ, ATL0, ATH0, ATE0, ATPP 2CSV 01, ATPP 2C ON, ATPP 2DSV 01, ATPP 2D ON, ATAT2, ATSP0, ATSH" + canRequestIDValue + ", 10 03, 3E00, " + routine; + for (final String q : expectedQueries.split(",")) { Assertions.assertThat(connection.recordedQueries().pop()).isEqualTo(q.trim()); } @@ -155,10 +164,10 @@ public void noIDsProvidedTest() throws IOException, InterruptedException { status = workflow.executeRoutine(123456L, init); Assertions.assertThat(status).isEqualTo(WorkflowExecutionStatus.REJECTED); - WorkflowFinalizer.finalize(workflow); + WorkflowFinalizer.finalizeAfter(workflow,1000l); // Ensure we receive AT commands - Assertions.assertThat(collector.findATResetCommand()).isNotNull(); + Assertions.assertThat(collector.findATResetCommand()).isNotNull(); // Workflow is not running Assertions.assertThat(workflow.isRunning()).isFalse(); diff --git a/src/test/java/org/obd/metrics/api/VinTest.java b/src/test/java/org/obd/metrics/api/VinTest.java index eeb9549f..327169a6 100644 --- a/src/test/java/org/obd/metrics/api/VinTest.java +++ b/src/test/java/org/obd/metrics/api/VinTest.java @@ -163,6 +163,6 @@ public void incorrectTest() throws IOException, InterruptedException { Assertions.assertThat(collector.findATResetCommand()).isNotNull(); // failed decoding VIN - Assertions.assertThat(lifecycle.getMetadata()).containsEntry("VIN", vinMessage); + Assertions.assertThat(lifecycle.getMetadata()).doesNotContainKey("VIN"); } } diff --git a/src/test/java/org/obd/metrics/codec/VinCommandTest.java b/src/test/java/org/obd/metrics/codec/VinCommandTest.java index 5eabd1d6..6d0a621c 100644 --- a/src/test/java/org/obd/metrics/codec/VinCommandTest.java +++ b/src/test/java/org/obd/metrics/codec/VinCommandTest.java @@ -21,7 +21,7 @@ import org.assertj.core.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; -import org.obd.metrics.command.meta.HexCommand; +import org.obd.metrics.command.meta.HexCodec; import org.obd.metrics.pid.PidDefinitionRegistry; import org.obd.metrics.test.PIDsRegistryFactory; import org.obd.metrics.transport.message.ConnectorResponseFactory; @@ -36,9 +36,10 @@ public class VinCommandTest { "0140:4902015756571:5A5A5A314B5A412:4D363930333;", // incorrect hex }, delimiter = ';') public void hexCommandTest(String raw,String expected) { - PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("mode01.json"); - HexCommand metadataDecoder = new HexCommand(pidDefinitionRegistry.findBy(11000l)); - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(raw.getBytes())); - Assertions.assertThat(decode).isEqualTo(expected); + final PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("mode01.json"); + final HexCodec metadataDecoder = new HexCodec(); + final String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(11000l), + ConnectorResponseFactory.wrap(raw.getBytes())); + Assertions.assertThat(expected).isEqualTo(decode); } } diff --git a/src/test/java/org/obd/metrics/codec/giulia_2_0_gme/MetadataDecoderTest.java b/src/test/java/org/obd/metrics/codec/giulia_2_0_gme/MetadataDecoderTest.java index a0313bf8..b5dd02c7 100644 --- a/src/test/java/org/obd/metrics/codec/giulia_2_0_gme/MetadataDecoderTest.java +++ b/src/test/java/org/obd/metrics/codec/giulia_2_0_gme/MetadataDecoderTest.java @@ -20,8 +20,8 @@ import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import org.obd.metrics.command.meta.HexCommand; -import org.obd.metrics.command.meta.NotEncodedCommand; +import org.obd.metrics.command.meta.HexCodec; +import org.obd.metrics.command.meta.NotEncodedCodec; import org.obd.metrics.command.meta.TimeCommand; import org.obd.metrics.pid.PidDefinitionRegistry; import org.obd.metrics.test.PIDsRegistryFactory; @@ -31,10 +31,11 @@ public class MetadataDecoderTest { @Test public void vin_1_Test() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("mode01.json"); - HexCommand metadataDecoder = new HexCommand(pidDefinitionRegistry.findBy(11000l)); + HexCodec metadataDecoder = new HexCodec(); String answer = "0140:4902015756571:5A5A5A314B5A412:4D363930333932"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(11000l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("WVWZZZ1KZAM690392"); } @@ -42,30 +43,33 @@ public void vin_1_Test() { public void vin_2_Test() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("giulia_2.0_gme.json"); - HexCommand metadataDecoder = new HexCommand(pidDefinitionRegistry.findBy(17001l)); + HexCodec metadataDecoder = new HexCodec(); String answer = "0140:62F1905A41521:454145424E394B2:37363137323839"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(17001l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("ZAREAEBN9K7617289"); } @Test public void ecuSerialNumberTest() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("giulia_2.0_gme.json"); - HexCommand metadataDecoder = new HexCommand(pidDefinitionRegistry.findBy(17002l)); + HexCodec metadataDecoder = new HexCodec(); String answer = "0120:62F18C5444341:313930393539452:3031343430"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(17002l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("TD4190959E01440"); } @Test public void ecuSofwareNumberTest() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("giulia_2.0_gme.json"); - HexCommand metadataDecoder = new HexCommand(pidDefinitionRegistry.findBy(17003l)); + HexCodec metadataDecoder = new HexCodec(); String answer = "00E0:62F1945031341:315641304520202:20"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(17003l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("P141VA0E"); } @@ -73,30 +77,33 @@ public void ecuSofwareNumberTest() { @Test public void fiatDrawingNumberTest() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("giulia_2.0_gme.json"); - HexCommand metadataDecoder = new HexCommand(pidDefinitionRegistry.findBy(17004l)); + HexCodec metadataDecoder = new HexCodec(); String answer = "00E0:62F1913532301:353533323020202:20"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(17004l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("52055320"); } @Test public void ecuTypeTest() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("giulia_2.0_gme.json"); - HexCommand metadataDecoder = new HexCommand(pidDefinitionRegistry.findBy(17005l)); + HexCodec metadataDecoder = new HexCodec(); String answer = "00E0:62F1924D4D311:304A41485732332:32"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(17005l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("MM10JAHW232"); } @Test public void sparePartNumberTest() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("giulia_2.0_gme.json"); - HexCommand metadataDecoder = new HexCommand(pidDefinitionRegistry.findBy(17006l)); + HexCodec metadataDecoder = new HexCodec(); String answer = "00E0:62F1873530351:353938353220202:20"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(17006l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("50559852"); } @@ -104,40 +111,44 @@ public void sparePartNumberTest() { @Test public void homologationNumberTest() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("giulia_2.0_gme.json"); - HexCommand metadataDecoder = new HexCommand(pidDefinitionRegistry.findBy(17007l)); + HexCodec metadataDecoder = new HexCodec(); String answer = "0090:62F1964548411:423030"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(17007l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("EHAB00"); } @Test public void softwareVersion() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("giulia_2.0_gme.json"); - NotEncodedCommand metadataDecoder = new NotEncodedCommand(pidDefinitionRegistry.findBy(17008l)); + NotEncodedCodec metadataDecoder = new NotEncodedCodec(); String answer = "62F1950000"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(17008l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("0000"); } @Test public void hardwareVersion() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("giulia_2.0_gme.json"); - NotEncodedCommand metadataDecoder = new NotEncodedCommand(pidDefinitionRegistry.findBy(17009l)); + NotEncodedCodec metadataDecoder = new NotEncodedCodec(); String answer = "62F19300"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(17009l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("00"); } @Test public void ecuIsoCodeTest() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("giulia_2.0_gme.json"); - NotEncodedCommand metadataDecoder = new NotEncodedCommand(pidDefinitionRegistry.findBy(17010l)); + NotEncodedCodec metadataDecoder = new NotEncodedCodec(); String answer = "0080:62F1A50001501:7517"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(17010l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("0001507517"); } @@ -145,20 +156,22 @@ public void ecuIsoCodeTest() { @Test public void operatingTimeTest() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("giulia_2.0_gme.json"); - TimeCommand metadataDecoder = new TimeCommand(pidDefinitionRegistry.findBy(17012l)); + TimeCommand metadataDecoder = new TimeCommand(); String answer = "6210080000BFC8"; - Integer decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); - Assertions.assertThat(decode).isNotNull().isEqualTo(49096); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(17012l), + ConnectorResponseFactory.wrap(answer.getBytes())); + Assertions.assertThat(decode).isNotNull().isEqualTo("49096"); } @Test public void functioningTimeTest() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("giulia_2.0_gme.json"); - TimeCommand metadataDecoder = new TimeCommand(pidDefinitionRegistry.findBy(17011l)); + TimeCommand metadataDecoder = new TimeCommand(); String answer = "6220080000BFC7"; - Integer decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); - Assertions.assertThat(decode).isNotNull().isEqualTo(49095); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(17011l), + ConnectorResponseFactory.wrap(answer.getBytes())); + Assertions.assertThat(decode).isNotNull().isEqualTo("49095"); } } diff --git a/src/test/java/org/obd/metrics/codec/giulietta_qv_med17_3_1/MetadataDecoderTest.java b/src/test/java/org/obd/metrics/codec/giulietta_qv_med17_3_1/MetadataDecoderTest.java index 6768e487..8d2da4c6 100644 --- a/src/test/java/org/obd/metrics/codec/giulietta_qv_med17_3_1/MetadataDecoderTest.java +++ b/src/test/java/org/obd/metrics/codec/giulietta_qv_med17_3_1/MetadataDecoderTest.java @@ -20,8 +20,8 @@ import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import org.obd.metrics.command.meta.HexCommand; -import org.obd.metrics.command.meta.NotEncodedCommand; +import org.obd.metrics.command.meta.HexCodec; +import org.obd.metrics.command.meta.NotEncodedCodec; import org.obd.metrics.pid.PidDefinitionRegistry; import org.obd.metrics.test.PIDsRegistryFactory; import org.obd.metrics.transport.message.ConnectorResponseFactory; @@ -31,20 +31,22 @@ public class MetadataDecoderTest { @Test public void ecuIsoCodeTest() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("alfa.json"); - NotEncodedCommand metadataDecoder = new NotEncodedCommand(pidDefinitionRegistry.findBy(16002l)); + NotEncodedCodec metadataDecoder = new NotEncodedCodec(); String answer = "0080:62F1A50807191:8986"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(16002l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("0807198986"); } @Test public void ecuSofwareNumberTest() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("alfa.json"); - HexCommand metadataDecoder = new HexCommand(pidDefinitionRegistry.findBy(16003l)); + HexCodec metadataDecoder = new HexCodec(); String answer = "00E0:62F1943130331:373532393935312:20"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(16003l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("1037529951"); } @@ -52,20 +54,22 @@ public void ecuSofwareNumberTest() { @Test public void ecuTypeTest() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("alfa.json"); - HexCommand metadataDecoder = new HexCommand(pidDefinitionRegistry.findBy(16005l)); + HexCodec metadataDecoder = new HexCodec(); String answer = "00E0:62F1923032361:315330353631382:20"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(16005l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("0261S05618"); } @Test public void sparePartNumberTest() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("alfa.json"); - HexCommand metadataDecoder = new HexCommand(pidDefinitionRegistry.findBy(16006l)); + HexCodec metadataDecoder = new HexCodec(); String answer = "00E0:62F1873535321:353030373220202:20"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(16006l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("55250072"); } @@ -73,20 +77,22 @@ public void sparePartNumberTest() { @Test public void homologationNumberTest() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("alfa.json"); - HexCommand metadataDecoder = new HexCommand(pidDefinitionRegistry.findBy(16007l)); + HexCodec metadataDecoder = new HexCodec(); String answer = "0090:62F1964431371:334530"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(16007l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("D173E0"); } @Test public void softwareVersion() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("alfa.json"); - NotEncodedCommand metadataDecoder = new NotEncodedCommand(pidDefinitionRegistry.findBy(16008l)); + NotEncodedCodec metadataDecoder = new NotEncodedCodec(); String answer = "62F1950406"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(16008l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("0406"); } @@ -94,10 +100,11 @@ public void softwareVersion() { @Test public void hardwareVersion() { PidDefinitionRegistry pidDefinitionRegistry = PIDsRegistryFactory.get("alfa.json"); - NotEncodedCommand metadataDecoder = new NotEncodedCommand(pidDefinitionRegistry.findBy(16009l)); + NotEncodedCodec metadataDecoder = new NotEncodedCodec(); String answer = "62F19300"; - String decode = metadataDecoder.decode(ConnectorResponseFactory.wrap(answer.getBytes())); + String decode = metadataDecoder.decode(pidDefinitionRegistry.findBy(16009l), + ConnectorResponseFactory.wrap(answer.getBytes())); Assertions.assertThat(decode).isNotNull().isEqualTo("00"); } }