mirror of https://github.com/rusefi/RomRaider.git
ramtune test app update
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@683 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
6fbcb3f446
commit
fdd828c52e
|
@ -1,6 +1,7 @@
|
||||||
package enginuity.ramtune.test;
|
package enginuity.ramtune.test;
|
||||||
|
|
||||||
import enginuity.Settings;
|
import enginuity.Settings;
|
||||||
|
import enginuity.io.connection.ConnectionProperties;
|
||||||
import enginuity.io.port.SerialPortRefresher;
|
import enginuity.io.port.SerialPortRefresher;
|
||||||
import enginuity.io.protocol.Protocol;
|
import enginuity.io.protocol.Protocol;
|
||||||
import enginuity.io.protocol.SSMProtocol;
|
import enginuity.io.protocol.SSMProtocol;
|
||||||
|
@ -11,6 +12,7 @@ import enginuity.ramtune.test.command.generator.CommandGenerator;
|
||||||
import enginuity.ramtune.test.command.generator.EcuInitCommandGenerator;
|
import enginuity.ramtune.test.command.generator.EcuInitCommandGenerator;
|
||||||
import enginuity.ramtune.test.command.generator.ReadCommandGenerator;
|
import enginuity.ramtune.test.command.generator.ReadCommandGenerator;
|
||||||
import enginuity.ramtune.test.command.generator.WriteCommandGenerator;
|
import enginuity.ramtune.test.command.generator.WriteCommandGenerator;
|
||||||
|
import enginuity.ramtune.test.io.RamTuneTestAppConnectionProperties;
|
||||||
import enginuity.swing.LookAndFeelManager;
|
import enginuity.swing.LookAndFeelManager;
|
||||||
import static enginuity.util.HexUtil.asBytes;
|
import static enginuity.util.HexUtil.asBytes;
|
||||||
import static enginuity.util.HexUtil.asHex;
|
import static enginuity.util.HexUtil.asHex;
|
||||||
|
@ -40,9 +42,9 @@ import static javax.swing.border.BevelBorder.LOWERED;
|
||||||
import javax.swing.border.EtchedBorder;
|
import javax.swing.border.EtchedBorder;
|
||||||
import javax.swing.border.TitledBorder;
|
import javax.swing.border.TitledBorder;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import static java.awt.BorderLayout.WEST;
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.FlowLayout;
|
import java.awt.FlowLayout;
|
||||||
|
import static java.awt.FlowLayout.LEFT;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import static java.awt.Font.PLAIN;
|
import static java.awt.Font.PLAIN;
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
|
@ -71,6 +73,7 @@ public final class RamTuneTestApp extends JFrame implements WindowListener {
|
||||||
private final Settings settings = new Settings();
|
private final Settings settings = new Settings();
|
||||||
private final JTextField addressField = new JTextField(6);
|
private final JTextField addressField = new JTextField(6);
|
||||||
private final JTextField lengthField = new JTextField(4);
|
private final JTextField lengthField = new JTextField(4);
|
||||||
|
private final JTextField sendTimeoutField = new JTextField(4);
|
||||||
private final JTextArea dataField = new JTextArea(10, 80);
|
private final JTextArea dataField = new JTextArea(10, 80);
|
||||||
private final JTextArea responseField = new JTextArea(15, 80);
|
private final JTextArea responseField = new JTextArea(15, 80);
|
||||||
private final SerialPortComboBox portsComboBox = new SerialPortComboBox(settings);
|
private final SerialPortComboBox portsComboBox = new SerialPortComboBox(settings);
|
||||||
|
@ -112,10 +115,10 @@ public final class RamTuneTestApp extends JFrame implements WindowListener {
|
||||||
|
|
||||||
constraints.gridx = 0;
|
constraints.gridx = 0;
|
||||||
constraints.gridy = 0;
|
constraints.gridy = 0;
|
||||||
constraints.gridwidth = 1;
|
constraints.gridwidth = 2;
|
||||||
constraints.gridheight = 1;
|
constraints.gridheight = 1;
|
||||||
constraints.weightx = 1;
|
constraints.weightx = 1;
|
||||||
constraints.weighty = 1;
|
constraints.weighty = 0;
|
||||||
mainPanel.add(buildComPortPanel(), constraints);
|
mainPanel.add(buildComPortPanel(), constraints);
|
||||||
|
|
||||||
constraints.gridx = 0;
|
constraints.gridx = 0;
|
||||||
|
@ -153,13 +156,17 @@ public final class RamTuneTestApp extends JFrame implements WindowListener {
|
||||||
constraints.weighty = 1;
|
constraints.weighty = 1;
|
||||||
inputPanel.add(commandComboBox, constraints);
|
inputPanel.add(commandComboBox, constraints);
|
||||||
|
|
||||||
JPanel addressPanel = new JPanel(new FlowLayout());
|
JPanel addressFieldPanel = new JPanel(new FlowLayout());
|
||||||
addressPanel.add(new JLabel("Address (eg. 020000):"));
|
addressFieldPanel.add(new JLabel("Address (eg. 020000):"));
|
||||||
addressPanel.add(addressField);
|
addressFieldPanel.add(addressField);
|
||||||
addressPanel.add(new JLabel(" Read Length:"));
|
JPanel lengthPanel = new JPanel(new FlowLayout());
|
||||||
|
lengthPanel.add(new JLabel(" Read Length:"));
|
||||||
lengthField.setText("1");
|
lengthField.setText("1");
|
||||||
addressPanel.add(lengthField);
|
lengthPanel.add(lengthField);
|
||||||
addressPanel.add(new JLabel("byte(s)"));
|
lengthPanel.add(new JLabel("byte(s)"));
|
||||||
|
JPanel addressPanel = new JPanel(new FlowLayout(LEFT));
|
||||||
|
addressPanel.add(addressFieldPanel);
|
||||||
|
addressPanel.add(lengthPanel);
|
||||||
constraints.gridx = 3;
|
constraints.gridx = 3;
|
||||||
constraints.gridy = 0;
|
constraints.gridy = 0;
|
||||||
constraints.gridwidth = 2;
|
constraints.gridwidth = 2;
|
||||||
|
@ -208,7 +215,8 @@ public final class RamTuneTestApp extends JFrame implements WindowListener {
|
||||||
public void run() {
|
public void run() {
|
||||||
button.setEnabled(false);
|
button.setEnabled(false);
|
||||||
try {
|
try {
|
||||||
final CommandExecutor commandExecutor = new CommandExecutorImpl(protocol, (String) portsComboBox.getSelectedItem());
|
ConnectionProperties connectionProperties = new RamTuneTestAppConnectionProperties(protocol.getDefaultConnectionProperties(), getSendTimeout());
|
||||||
|
final CommandExecutor commandExecutor = new CommandExecutorImpl(connectionProperties, (String) portsComboBox.getSelectedItem());
|
||||||
final CommandGenerator commandGenerator = (CommandGenerator) commandComboBox.getSelectedItem();
|
final CommandGenerator commandGenerator = (CommandGenerator) commandComboBox.getSelectedItem();
|
||||||
if (validateInput(commandGenerator) && confirmCommandExecution(commandGenerator)) {
|
if (validateInput(commandGenerator) && confirmCommandExecution(commandGenerator)) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
@ -258,8 +266,16 @@ public final class RamTuneTestApp extends JFrame implements WindowListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getLength() {
|
private int getLength() {
|
||||||
|
return getIntFromField(lengthField);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getSendTimeout() {
|
||||||
|
return getIntFromField(sendTimeoutField);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getIntFromField(JTextField field) {
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(lengthField.getText().trim());
|
return Integer.parseInt(field.getText().trim());
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -314,11 +330,25 @@ public final class RamTuneTestApp extends JFrame implements WindowListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private JPanel buildComPortPanel() {
|
private JPanel buildComPortPanel() {
|
||||||
JPanel comboBoxPanel = new JPanel(new FlowLayout());
|
JPanel panel = new JPanel(new FlowLayout(LEFT));
|
||||||
comboBoxPanel.add(new JLabel("COM Port:"));
|
panel.add(buildComPorts());
|
||||||
comboBoxPanel.add(portsComboBox);
|
panel.add(buildSendTimeout());
|
||||||
JPanel panel = new JPanel(new BorderLayout());
|
return panel;
|
||||||
panel.add(comboBoxPanel, WEST);
|
}
|
||||||
|
|
||||||
|
private Component buildSendTimeout() {
|
||||||
|
sendTimeoutField.setText("55");
|
||||||
|
JPanel panel = new JPanel(new FlowLayout());
|
||||||
|
panel.add(new JLabel("Send Timeout:"));
|
||||||
|
panel.add(sendTimeoutField);
|
||||||
|
panel.add(new JLabel("ms"));
|
||||||
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel buildComPorts() {
|
||||||
|
JPanel panel = new JPanel(new FlowLayout());
|
||||||
|
panel.add(new JLabel("COM Port:"));
|
||||||
|
panel.add(portsComboBox);
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
package enginuity.ramtune.test.command.executor;
|
package enginuity.ramtune.test.command.executor;
|
||||||
|
|
||||||
|
import enginuity.io.connection.ConnectionProperties;
|
||||||
import enginuity.io.connection.EcuConnection;
|
import enginuity.io.connection.EcuConnection;
|
||||||
import enginuity.io.connection.EcuConnectionImpl;
|
import enginuity.io.connection.EcuConnectionImpl;
|
||||||
import enginuity.io.protocol.Protocol;
|
|
||||||
import static enginuity.util.ParamChecker.checkNotNull;
|
import static enginuity.util.ParamChecker.checkNotNull;
|
||||||
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
||||||
|
|
||||||
public final class CommandExecutorImpl implements CommandExecutor {
|
public final class CommandExecutorImpl implements CommandExecutor {
|
||||||
private final Protocol protocol;
|
private final ConnectionProperties connectionProperties;
|
||||||
private final String port;
|
private final String port;
|
||||||
|
|
||||||
public CommandExecutorImpl(Protocol protocol, String port) {
|
public CommandExecutorImpl(ConnectionProperties connectionProperties, String port) {
|
||||||
checkNotNull(protocol);
|
checkNotNull(connectionProperties);
|
||||||
checkNotNullOrEmpty(port, "port");
|
checkNotNullOrEmpty(port, "port");
|
||||||
this.protocol = protocol;
|
this.connectionProperties = connectionProperties;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] executeCommand(byte[] command) {
|
public byte[] executeCommand(byte[] command) {
|
||||||
EcuConnection ecuConnection = new EcuConnectionImpl(protocol.getDefaultConnectionProperties(), port);
|
EcuConnection ecuConnection = new EcuConnectionImpl(connectionProperties, port);
|
||||||
try {
|
try {
|
||||||
return ecuConnection.send(command);
|
return ecuConnection.send(command);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package enginuity.ramtune.test.io;
|
||||||
|
|
||||||
|
import enginuity.io.connection.ConnectionProperties;
|
||||||
|
|
||||||
|
public final class RamTuneTestAppConnectionProperties implements ConnectionProperties {
|
||||||
|
private final ConnectionProperties defaultConnectionProperties;
|
||||||
|
private final int sendTimeout;
|
||||||
|
|
||||||
|
public RamTuneTestAppConnectionProperties(ConnectionProperties defaultConnectionProperties, int sendTimeout) {
|
||||||
|
this.defaultConnectionProperties = defaultConnectionProperties;
|
||||||
|
this.sendTimeout = sendTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBaudRate() {
|
||||||
|
return defaultConnectionProperties.getBaudRate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDataBits() {
|
||||||
|
return defaultConnectionProperties.getDataBits();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStopBits() {
|
||||||
|
return defaultConnectionProperties.getStopBits();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getParity() {
|
||||||
|
return defaultConnectionProperties.getParity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getConnectTimeout() {
|
||||||
|
return defaultConnectionProperties.getConnectTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSendTimeout() {
|
||||||
|
return sendTimeout > 0 ? sendTimeout : defaultConnectionProperties.getSendTimeout();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue