auto-sync

This commit is contained in:
rusEfi 2015-02-23 08:05:15 -06:00
parent 836188c674
commit a2421c9f79
9 changed files with 90 additions and 38 deletions

View File

@ -9,6 +9,6 @@
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="io" /> <orderEntry type="module" module-name="io" />
<orderEntry type="module" module-name="models" /> <orderEntry type="module" module-name="models" />
<orderEntry type="library" name="jssc" level="project" />
</component> </component>
</module> </module>

View File

@ -6,6 +6,7 @@ import com.rusefi.waves.WaveReport;
import static com.rusefi.IoUtil.nextChart; import static com.rusefi.IoUtil.nextChart;
import static com.rusefi.IoUtil.sendCommand; import static com.rusefi.IoUtil.sendCommand;
import static com.rusefi.IoUtil.sleep;
import static com.rusefi.TestingUtils.*; import static com.rusefi.TestingUtils.*;
/** /**
@ -17,7 +18,7 @@ import static com.rusefi.TestingUtils.*;
* 3/5/14 * 3/5/14
*/ */
public class AutoTest { public class AutoTest {
private static void mainTestBody() { static void mainTestBody() {
testCitroenBerlingo(); testCitroenBerlingo();
testMazda626(); testMazda626();
test2003DodgeNeon(); test2003DodgeNeon();
@ -29,15 +30,21 @@ public class AutoTest {
} }
private static void testCitroenBerlingo() { private static void testCitroenBerlingo() {
sendCommand("set_engine_type 15"); setEngineType(15);
// time to change engine type // time to change engine type
nextChart(); nextChart();
String msg = "Citroen"; String msg = "Citroen";
// todo: add more content // todo: add more content
} }
private static void setEngineType(int type) {
sendCommand("set_engine_type " + type, 10000);
sleep(5);
sendCommand("enable self_stimulation");
}
private static void testMazda626() { private static void testMazda626() {
sendCommand("set_engine_type 28"); setEngineType(28);
WaveChart chart; WaveChart chart;
// time to change engine type // time to change engine type
nextChart(); nextChart();
@ -50,7 +57,7 @@ public class AutoTest {
} }
private static void test2003DodgeNeon() { private static void test2003DodgeNeon() {
sendCommand("set_engine_type 23"); setEngineType(23);
WaveChart chart; WaveChart chart;
// time to change engine type // time to change engine type
nextChart(); nextChart();
@ -90,7 +97,7 @@ public class AutoTest {
} }
private static void testMazdaProtege() { private static void testMazdaProtege() {
sendCommand("set_engine_type 14"); setEngineType(14);
WaveChart chart; WaveChart chart;
nextChart(); // a bit of extra time to change engine type nextChart(); // a bit of extra time to change engine type
IoUtil.changeRpm(200); IoUtil.changeRpm(200);
@ -113,7 +120,7 @@ public class AutoTest {
} }
private static void test1995DodgeNeon() { private static void test1995DodgeNeon() {
sendCommand("set_engine_type 2"); setEngineType(2);
WaveChart chart; WaveChart chart;
sendCommand("set_whole_fuel_map 3"); sendCommand("set_whole_fuel_map 3");
IoUtil.changeRpm(2000); IoUtil.changeRpm(2000);
@ -142,7 +149,7 @@ public class AutoTest {
} }
private static void testFordFiesta() { private static void testFordFiesta() {
sendCommand("set_engine_type 4"); setEngineType(4);
WaveChart chart; WaveChart chart;
IoUtil.changeRpm(2000); IoUtil.changeRpm(2000);
chart = nextChart(); chart = nextChart();
@ -156,7 +163,7 @@ public class AutoTest {
} }
private static void testFord6() { private static void testFord6() {
sendCommand("set_engine_type 7"); setEngineType(7);
WaveChart chart; WaveChart chart;
IoUtil.changeRpm(2000); IoUtil.changeRpm(2000);
chart = nextChart(); chart = nextChart();
@ -173,7 +180,7 @@ public class AutoTest {
} }
private static void testFordAspire() { private static void testFordAspire() {
sendCommand("set_engine_type 3"); setEngineType(3);
String msg; String msg;
WaveChart chart; WaveChart chart;
// todo: interesting changeRpm(100); // todo: interesting changeRpm(100);

View File

@ -10,6 +10,7 @@ import com.rusefi.io.tcp.TcpConnector;
import com.rusefi.waves.WaveChart; import com.rusefi.waves.WaveChart;
import com.rusefi.waves.WaveChartParser; import com.rusefi.waves.WaveChartParser;
import com.rusefi.waves.WaveReport; import com.rusefi.waves.WaveReport;
import jssc.SerialPortList;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -30,12 +31,16 @@ public class IoUtil {
* @throws IllegalStateException if command was not confirmed * @throws IllegalStateException if command was not confirmed
*/ */
static void sendCommand(String command) { static void sendCommand(String command) {
sendCommand(command, CommandQueue.DEFAULT_TIMEOUT);
}
static void sendCommand(String command, int timeoutMs) {
final CountDownLatch responseLatch = new CountDownLatch(1); final CountDownLatch responseLatch = new CountDownLatch(1);
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
if (LinkManager.hasError()) if (LinkManager.hasError())
throw new IllegalStateException("IO error"); throw new IllegalStateException("IO error");
FileLog.MAIN.logLine("Sending command [" + command + "]"); FileLog.MAIN.logLine("Sending command [" + command + "]");
CommandQueue.getInstance().write(command, CommandQueue.DEFAULT_TIMEOUT, new InvocationConfirmationListener() { CommandQueue.getInstance().write(command, timeoutMs, new InvocationConfirmationListener() {
@Override @Override
public void onCommandConfirmation() { public void onCommandConfirmation() {
responseLatch.countDown(); responseLatch.countDown();
@ -77,7 +82,7 @@ public class IoUtil {
final AtomicReference<String> result = new AtomicReference<>(); final AtomicReference<String> result = new AtomicReference<>();
FileLog.MAIN.logLine("waiting for next chart"); FileLog.MAIN.logLine("waiting for next chart");
LinkManager.engineState.registerStringValueAction(WaveReport.WAVE_CHART, new EngineState.ValueCallback<String>() { LinkManager.engineState.replaceStringValueAction(WaveReport.WAVE_CHART, new EngineState.ValueCallback<String>() {
@Override @Override
public void onUpdate(String value) { public void onUpdate(String value) {
waveChartLatch.countDown(); waveChartLatch.countDown();
@ -88,7 +93,7 @@ public class IoUtil {
long waitStartTime = System.currentTimeMillis(); long waitStartTime = System.currentTimeMillis();
wait(waveChartLatch, timeout); wait(waveChartLatch, timeout);
FileLog.MAIN.logLine("got next chart in " + (System.currentTimeMillis() - waitStartTime) + "ms"); FileLog.MAIN.logLine("got next chart in " + (System.currentTimeMillis() - waitStartTime) + "ms");
LinkManager.engineState.removeAction(WaveReport.WAVE_CHART); LinkManager.engineState.replaceStringValueAction(WaveReport.WAVE_CHART, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
if (result.get() == null) if (result.get() == null)
throw new IllegalStateException("Chart timeout: " + timeout); throw new IllegalStateException("Chart timeout: " + timeout);
return result.get(); return result.get();
@ -182,4 +187,26 @@ public class IoUtil {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
} }
/**
* @return null if no port located
*/
static String getDefaultPort() {
String[] ports = SerialPortList.getPortNames();
if (ports.length == 0) {
System.out.println("Port not specified and no ports found");
return null;
}
String port = ports[ports.length - 1];
System.out.println("Using last of " + ports.length + " port(s)");
return port;
}
static void realHardwareConnect(String port) {
LinkManager.start(port);
LinkManager.open();
LinkManager.engineState.registerStringValueAction(EngineState.RUS_EFI_VERSION_TAG, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
LinkManager.engineState.registerStringValueAction(EngineState.OUTPIN_TAG, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
LinkManager.engineState.registerStringValueAction(AverageAnglesUtil.KEY, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
}
} }

View File

@ -1,5 +1,7 @@
package com.rusefi; package com.rusefi;
import static com.rusefi.AutoTest.*;
/** /**
* this test connects to real hardware via serial port * this test connects to real hardware via serial port
* (c) Andrey Belomutskiy 2013-2015 * (c) Andrey Belomutskiy 2013-2015
@ -7,6 +9,24 @@ package com.rusefi;
*/ */
public class RealHwTest { public class RealHwTest {
public static void main(String[] args) { public static void main(String[] args) {
FileLog.MAIN.start();
String port;
if (args.length == 1) {
port = args[0];
} else if (args.length == 0) {
port = IoUtil.getDefaultPort();
if (port == null)
return;
} else {
System.out.println("Only one optional argument expected: port number");
return;
}
runRealHardwareTest(port);
}
private static void runRealHardwareTest(String port) {
IoUtil.realHardwareConnect(port);
mainTestBody();
} }
} }

View File

@ -83,7 +83,9 @@ public class CommandQueue {
} }
private CommandQueue() { private CommandQueue() {
new Thread(runnable, "Commands Queue").start(); Thread thread = new Thread(runnable, "Commands Queue");
thread.setDaemon(true);
thread.start();
final MessagesCentral mc = MessagesCentral.getInstance(); final MessagesCentral mc = MessagesCentral.getInstance();
mc.addListener(new MessagesCentral.MessageListener() { mc.addListener(new MessagesCentral.MessageListener() {
@Override @Override
@ -139,22 +141,22 @@ public class CommandQueue {
/** /**
* Non-blocking command request * Non-blocking command request
*/ */
public void write(String command, int timeout, InvocationConfirmationListener listener) { public void write(String command, int timeoutMs, InvocationConfirmationListener listener) {
for (CommandQueueListener cql : commandListeners) for (CommandQueueListener cql : commandListeners)
cql.onCommand(command); cql.onCommand(command);
pendingCommands.add(new MethodInvocation(command, timeout, listener)); pendingCommands.add(new MethodInvocation(command, timeoutMs, listener));
} }
static class MethodInvocation { static class MethodInvocation {
private final String text; private final String text;
private final int timeout; private final int timeoutMs;
private final InvocationConfirmationListener listener; private final InvocationConfirmationListener listener;
MethodInvocation(String text, int timeout, InvocationConfirmationListener listener) { MethodInvocation(String text, int timeoutMs, InvocationConfirmationListener listener) {
this.text = text; this.text = text;
this.timeout = timeout; this.timeoutMs = timeoutMs;
this.listener = listener; this.listener = listener;
} }
@ -163,7 +165,7 @@ public class CommandQueue {
} }
public int getTimeout() { public int getTimeout() {
return timeout; return timeoutMs;
} }
} }

View File

@ -15,7 +15,8 @@ import java.util.*;
*/ */
public class AverageAnglesUtil { public class AverageAnglesUtil {
public static final String ANALOG_CHART = "analog_chart,"; public static final String KEY = "analog_chart";
public static final String ANALOG_CHART = KEY + ",";
private static int currentRpm = -1; private static int currentRpm = -1;

View File

@ -2,6 +2,7 @@ package com.rusefi.core;
import com.rusefi.FileLog; import com.rusefi.FileLog;
import com.rusefi.SensorConversion; import com.rusefi.SensorConversion;
import com.rusefi.waves.WaveReport;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import javax.swing.*; import javax.swing.*;
@ -30,6 +31,11 @@ public class EngineState {
private static final CharSequence TS_PROTOCOL_TAG = "ts_p_al"; private static final CharSequence TS_PROTOCOL_TAG = "ts_p_al";
private final Object lock = new Object(); private final Object lock = new Object();
public void replaceStringValueAction(String key, ValueCallback<String> callback) {
removeAction(key);
registerStringValueAction(key, callback);
}
private static class StringActionPair extends Pair<String, ValueCallback<String>> { private static class StringActionPair extends Pair<String, ValueCallback<String>> {
public final String prefix; public final String prefix;

View File

@ -7,12 +7,11 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
public class AnalogChartCentral { public class AnalogChartCentral {
private static final String KEY = "analog_chart";
private static List<AnalogChartListener> listeners = new CopyOnWriteArrayList<>(); private static List<AnalogChartListener> listeners = new CopyOnWriteArrayList<>();
static { static {
LinkManager.engineState.registerStringValueAction(KEY, new EngineState.ValueCallback<String>() { LinkManager.engineState.registerStringValueAction(AverageAnglesUtil.KEY, new EngineState.ValueCallback<String>() {
@Override @Override
public void onUpdate(String message) { public void onUpdate(String message) {
for (AnalogChartListener listener : listeners) for (AnalogChartListener listener : listeners)

View File

@ -1,9 +1,5 @@
package com.rusefi; package com.rusefi;
import com.rusefi.core.EngineState;
import com.rusefi.io.LinkManager;
import jssc.SerialPortList;
/** /**
* (c) Andrey Belomutskiy 2013-2015 * (c) Andrey Belomutskiy 2013-2015
* 2/22/2015 * 2/22/2015
@ -16,13 +12,9 @@ public class CmdLine {
} }
String command = args[0]; String command = args[0];
if (args.length == 1) { if (args.length == 1) {
String[] ports = SerialPortList.getPortNames(); String port = IoUtil.getDefaultPort();
if (ports.length == 0) { if (port == null)
System.out.println("Port not specified and no ports found");
return; return;
}
String port = ports[ports.length - 1];
System.out.println("Using last of " + ports.length + " port(s)");
executeCommand(command, port); executeCommand(command, port);
} else { } else {
executeCommand(command, args[1]); executeCommand(command, args[1]);
@ -32,13 +24,11 @@ public class CmdLine {
private static void executeCommand(String command, String port) { private static void executeCommand(String command, String port) {
System.out.println("Sending " + command); System.out.println("Sending " + command);
System.out.println("Sending to " + port); System.out.println("Sending to " + port);
LinkManager.start(port); IoUtil.realHardwareConnect(port);
LinkManager.open();
LinkManager.engineState.registerStringValueAction(EngineState.RUS_EFI_VERSION_TAG, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
LinkManager.engineState.registerStringValueAction(EngineState.OUTPIN_TAG, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
IoUtil.sendCommand(command); IoUtil.sendCommand(command);
System.out.println("Done!"); System.out.println("Done!");
System.exit(-1); System.exit(-1);
} }
} }