diff --git a/src/enginuity/ramtune/test/RamTuneTestApp.java b/src/enginuity/ramtune/test/RamTuneTestApp.java index 361e8498..f1c87765 100644 --- a/src/enginuity/ramtune/test/RamTuneTestApp.java +++ b/src/enginuity/ramtune/test/RamTuneTestApp.java @@ -2,11 +2,13 @@ package enginuity.ramtune.test; import enginuity.Settings; import enginuity.io.port.SerialPortRefresher; +import enginuity.io.protocol.Protocol; +import enginuity.io.protocol.SSMProtocol; import enginuity.logger.ecu.ui.SerialPortComboBox; -import enginuity.ramtune.test.command.Command; -import enginuity.ramtune.test.command.EcuInitCommand; -import enginuity.ramtune.test.command.ReadCommand; -import enginuity.ramtune.test.command.WriteCommand; +import enginuity.ramtune.test.command.generator.CommandGenerator; +import enginuity.ramtune.test.command.generator.EcuInitCommandGenerator; +import enginuity.ramtune.test.command.generator.ReadCommandGenerator; +import enginuity.ramtune.test.command.generator.WriteCommandGenerator; import enginuity.swing.LookAndFeelManager; import static enginuity.util.ThreadUtil.runAsDaemon; import static enginuity.util.ThreadUtil.sleep; @@ -52,10 +54,11 @@ import java.io.Writer; * It borrows some functionality from the logger which should be rewritten/removed before being released!! */ public final class RamTuneTestApp extends JFrame implements WindowListener { - private Settings settings = new Settings(); - private SerialPortComboBox portsComboBox = new SerialPortComboBox(settings); - private JLabel messageLabel = new JLabel(); - private JLabel connectionStatusLabel = new JLabel(); + private final Protocol protocol = new SSMProtocol(); + private final Settings settings = new Settings(); + private final SerialPortComboBox portsComboBox = new SerialPortComboBox(settings); + private final JLabel messageLabel = new JLabel(); + private final JLabel connectionStatusLabel = new JLabel(); public RamTuneTestApp(String title) { super(title); @@ -168,7 +171,8 @@ public final class RamTuneTestApp extends JFrame implements WindowListener { } private JComboBox buildCommandComboBox() { - return new JComboBox(new Command[] {new EcuInitCommand(), new ReadCommand(), new WriteCommand()}); + return new JComboBox(new CommandGenerator[] {new EcuInitCommandGenerator(protocol), + new ReadCommandGenerator(protocol), new WriteCommandGenerator(protocol)}); } private Component buildOutputPanel() { diff --git a/src/enginuity/ramtune/test/command/Command.java b/src/enginuity/ramtune/test/command/Command.java index 4fcef6db..e17f36ad 100644 --- a/src/enginuity/ramtune/test/command/Command.java +++ b/src/enginuity/ramtune/test/command/Command.java @@ -2,5 +2,5 @@ package enginuity.ramtune.test.command; public interface Command { - byte[] constructCommandRequest(byte[] address, byte[] data); + byte[] getBytes(); } diff --git a/src/enginuity/ramtune/test/command/CommandImpl.java b/src/enginuity/ramtune/test/command/CommandImpl.java new file mode 100644 index 00000000..8f28ca15 --- /dev/null +++ b/src/enginuity/ramtune/test/command/CommandImpl.java @@ -0,0 +1,16 @@ +package enginuity.ramtune.test.command; + +import static enginuity.util.ParamChecker.checkNotNull; + +public final class CommandImpl implements Command { + private final byte[] bytes; + + public CommandImpl(byte[] bytes) { + checkNotNull(bytes, "bytes"); + this.bytes = bytes; + } + + public byte[] getBytes() { + return bytes; + } +} diff --git a/src/enginuity/ramtune/test/command/CommandResult.java b/src/enginuity/ramtune/test/command/CommandResult.java new file mode 100644 index 00000000..9bafb05c --- /dev/null +++ b/src/enginuity/ramtune/test/command/CommandResult.java @@ -0,0 +1,6 @@ +package enginuity.ramtune.test.command; + +public interface CommandResult { + + byte[] getResult(); +} diff --git a/src/enginuity/ramtune/test/command/CommandResultImpl.java b/src/enginuity/ramtune/test/command/CommandResultImpl.java new file mode 100644 index 00000000..f1081163 --- /dev/null +++ b/src/enginuity/ramtune/test/command/CommandResultImpl.java @@ -0,0 +1,16 @@ +package enginuity.ramtune.test.command; + +import static enginuity.util.ParamChecker.checkNotNull; + +public final class CommandResultImpl implements CommandResult { + private final byte[] result; + + public CommandResultImpl(byte[] result) { + checkNotNull(result, "result"); + this.result = result; + } + + public byte[] getResult() { + return result; + } +} diff --git a/src/enginuity/ramtune/test/command/EcuInitCommand.java b/src/enginuity/ramtune/test/command/EcuInitCommand.java deleted file mode 100644 index 3629e6b5..00000000 --- a/src/enginuity/ramtune/test/command/EcuInitCommand.java +++ /dev/null @@ -1,16 +0,0 @@ -package enginuity.ramtune.test.command; - -import enginuity.io.protocol.Protocol; -import enginuity.io.protocol.SSMProtocol; - -public final class EcuInitCommand implements Command { - private final Protocol protocol = new SSMProtocol(); - - public byte[] constructCommandRequest(byte[] address, byte[] data) { - return protocol.constructEcuInitRequest(); - } - - public String toString() { - return "ECU Init"; - } -} diff --git a/src/enginuity/ramtune/test/command/ReadCommand.java b/src/enginuity/ramtune/test/command/ReadCommand.java deleted file mode 100644 index 98843b44..00000000 --- a/src/enginuity/ramtune/test/command/ReadCommand.java +++ /dev/null @@ -1,16 +0,0 @@ -package enginuity.ramtune.test.command; - -import enginuity.io.protocol.Protocol; -import enginuity.io.protocol.SSMProtocol; - -public final class ReadCommand implements Command { - private final Protocol protocol = new SSMProtocol(); - - public byte[] constructCommandRequest(byte[] address, byte[] data) { - return protocol.constructReadAddressRequest(new byte[][] {address}); - } - - public String toString() { - return "Read"; - } -} diff --git a/src/enginuity/ramtune/test/command/WriteCommand.java b/src/enginuity/ramtune/test/command/WriteCommand.java deleted file mode 100644 index fef7d151..00000000 --- a/src/enginuity/ramtune/test/command/WriteCommand.java +++ /dev/null @@ -1,16 +0,0 @@ -package enginuity.ramtune.test.command; - -import enginuity.io.protocol.Protocol; -import enginuity.io.protocol.SSMProtocol; - -public final class WriteCommand implements Command { - private final Protocol protocol = new SSMProtocol(); - - public byte[] constructCommandRequest(byte[] address, byte[] data) { - return protocol.constructWriteMemoryRequest(address, data); - } - - public String toString() { - return "Write"; - } -} diff --git a/src/enginuity/ramtune/test/command/executor/CommandExecutor.java b/src/enginuity/ramtune/test/command/executor/CommandExecutor.java new file mode 100644 index 00000000..10729663 --- /dev/null +++ b/src/enginuity/ramtune/test/command/executor/CommandExecutor.java @@ -0,0 +1,9 @@ +package enginuity.ramtune.test.command.executor; + +import enginuity.ramtune.test.command.Command; +import enginuity.ramtune.test.command.CommandResult; + +public interface CommandExecutor { + + CommandResult executeCommand(Command command); +} diff --git a/src/enginuity/ramtune/test/command/executor/CommandExecutorImpl.java b/src/enginuity/ramtune/test/command/executor/CommandExecutorImpl.java new file mode 100644 index 00000000..d74d38bd --- /dev/null +++ b/src/enginuity/ramtune/test/command/executor/CommandExecutorImpl.java @@ -0,0 +1,24 @@ +package enginuity.ramtune.test.command.executor; + +import enginuity.io.connection.ConnectionProperties; +import enginuity.io.connection.EcuConnection; +import enginuity.io.connection.EcuConnectionImpl; +import enginuity.ramtune.test.command.Command; +import enginuity.ramtune.test.command.CommandResult; +import static enginuity.util.ParamChecker.checkNotNull; +import static enginuity.util.ParamChecker.checkNotNullOrEmpty; + +public final class CommandExecutorImpl implements CommandExecutor { + private final EcuConnection ecuConnection; + + public CommandExecutorImpl(ConnectionProperties connectionProperties, String port) { + checkNotNull(connectionProperties); + checkNotNullOrEmpty(port, "port"); + this.ecuConnection = new EcuConnectionImpl(connectionProperties, port); + } + + public CommandResult executeCommand(Command command) { + ecuConnection.send(command.getBytes()); + return null; + } +} diff --git a/src/enginuity/ramtune/test/command/generator/CommandGenerator.java b/src/enginuity/ramtune/test/command/generator/CommandGenerator.java new file mode 100644 index 00000000..86c2eeb9 --- /dev/null +++ b/src/enginuity/ramtune/test/command/generator/CommandGenerator.java @@ -0,0 +1,8 @@ +package enginuity.ramtune.test.command.generator; + +import enginuity.ramtune.test.command.Command; + +public interface CommandGenerator { + + Command createCommand(byte[] address, byte[] data); +} diff --git a/src/enginuity/ramtune/test/command/generator/EcuInitCommandGenerator.java b/src/enginuity/ramtune/test/command/generator/EcuInitCommandGenerator.java new file mode 100644 index 00000000..09bba144 --- /dev/null +++ b/src/enginuity/ramtune/test/command/generator/EcuInitCommandGenerator.java @@ -0,0 +1,23 @@ +package enginuity.ramtune.test.command.generator; + +import enginuity.io.protocol.Protocol; +import enginuity.ramtune.test.command.Command; +import enginuity.ramtune.test.command.CommandImpl; +import static enginuity.util.ParamChecker.checkNotNull; + +public final class EcuInitCommandGenerator implements CommandGenerator { + private final Protocol protocol; + + public EcuInitCommandGenerator(Protocol protocol) { + checkNotNull(protocol, "protocol"); + this.protocol = protocol; + } + + public Command createCommand(byte[] address, byte[] data) { + return new CommandImpl(protocol.constructEcuInitRequest()); + } + + public String toString() { + return "ECU Init"; + } +} diff --git a/src/enginuity/ramtune/test/command/generator/ReadCommandGenerator.java b/src/enginuity/ramtune/test/command/generator/ReadCommandGenerator.java new file mode 100644 index 00000000..3d97d70a --- /dev/null +++ b/src/enginuity/ramtune/test/command/generator/ReadCommandGenerator.java @@ -0,0 +1,25 @@ +package enginuity.ramtune.test.command.generator; + +import enginuity.io.protocol.Protocol; +import enginuity.ramtune.test.command.Command; +import enginuity.ramtune.test.command.CommandImpl; +import static enginuity.util.ParamChecker.checkNotNull; +import static enginuity.util.ParamChecker.checkNotNullOrEmpty; + +public final class ReadCommandGenerator implements CommandGenerator { + private final Protocol protocol; + + public ReadCommandGenerator(Protocol protocol) { + checkNotNull(protocol, "protocol"); + this.protocol = protocol; + } + + public Command createCommand(byte[] address, byte[] data) { + checkNotNullOrEmpty(address, "address"); + return new CommandImpl(protocol.constructReadAddressRequest(new byte[][] {address})); + } + + public String toString() { + return "Read"; + } +} diff --git a/src/enginuity/ramtune/test/command/generator/WriteCommandGenerator.java b/src/enginuity/ramtune/test/command/generator/WriteCommandGenerator.java new file mode 100644 index 00000000..b987acb2 --- /dev/null +++ b/src/enginuity/ramtune/test/command/generator/WriteCommandGenerator.java @@ -0,0 +1,26 @@ +package enginuity.ramtune.test.command.generator; + +import enginuity.io.protocol.Protocol; +import enginuity.ramtune.test.command.Command; +import enginuity.ramtune.test.command.CommandImpl; +import static enginuity.util.ParamChecker.checkNotNull; +import static enginuity.util.ParamChecker.checkNotNullOrEmpty; + +public final class WriteCommandGenerator implements CommandGenerator { + private final Protocol protocol; + + public WriteCommandGenerator(Protocol protocol) { + checkNotNull(protocol, "protocol"); + this.protocol = protocol; + } + + public Command createCommand(byte[] address, byte[] data) { + checkNotNullOrEmpty(address, "address"); + checkNotNullOrEmpty(data, "data"); + return new CommandImpl(protocol.constructWriteMemoryRequest(address, data)); + } + + public String toString() { + return "Write"; + } +}