auto-sync
This commit is contained in:
parent
836188c674
commit
a2421c9f79
|
@ -9,6 +9,6 @@
|
|||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="io" />
|
||||
<orderEntry type="module" module-name="models" />
|
||||
<orderEntry type="library" name="jssc" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.rusefi.waves.WaveReport;
|
|||
|
||||
import static com.rusefi.IoUtil.nextChart;
|
||||
import static com.rusefi.IoUtil.sendCommand;
|
||||
import static com.rusefi.IoUtil.sleep;
|
||||
import static com.rusefi.TestingUtils.*;
|
||||
|
||||
/**
|
||||
|
@ -17,7 +18,7 @@ import static com.rusefi.TestingUtils.*;
|
|||
* 3/5/14
|
||||
*/
|
||||
public class AutoTest {
|
||||
private static void mainTestBody() {
|
||||
static void mainTestBody() {
|
||||
testCitroenBerlingo();
|
||||
testMazda626();
|
||||
test2003DodgeNeon();
|
||||
|
@ -29,15 +30,21 @@ public class AutoTest {
|
|||
}
|
||||
|
||||
private static void testCitroenBerlingo() {
|
||||
sendCommand("set_engine_type 15");
|
||||
setEngineType(15);
|
||||
// time to change engine type
|
||||
nextChart();
|
||||
String msg = "Citroen";
|
||||
// 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() {
|
||||
sendCommand("set_engine_type 28");
|
||||
setEngineType(28);
|
||||
WaveChart chart;
|
||||
// time to change engine type
|
||||
nextChart();
|
||||
|
@ -50,7 +57,7 @@ public class AutoTest {
|
|||
}
|
||||
|
||||
private static void test2003DodgeNeon() {
|
||||
sendCommand("set_engine_type 23");
|
||||
setEngineType(23);
|
||||
WaveChart chart;
|
||||
// time to change engine type
|
||||
nextChart();
|
||||
|
@ -90,7 +97,7 @@ public class AutoTest {
|
|||
}
|
||||
|
||||
private static void testMazdaProtege() {
|
||||
sendCommand("set_engine_type 14");
|
||||
setEngineType(14);
|
||||
WaveChart chart;
|
||||
nextChart(); // a bit of extra time to change engine type
|
||||
IoUtil.changeRpm(200);
|
||||
|
@ -113,7 +120,7 @@ public class AutoTest {
|
|||
}
|
||||
|
||||
private static void test1995DodgeNeon() {
|
||||
sendCommand("set_engine_type 2");
|
||||
setEngineType(2);
|
||||
WaveChart chart;
|
||||
sendCommand("set_whole_fuel_map 3");
|
||||
IoUtil.changeRpm(2000);
|
||||
|
@ -142,7 +149,7 @@ public class AutoTest {
|
|||
}
|
||||
|
||||
private static void testFordFiesta() {
|
||||
sendCommand("set_engine_type 4");
|
||||
setEngineType(4);
|
||||
WaveChart chart;
|
||||
IoUtil.changeRpm(2000);
|
||||
chart = nextChart();
|
||||
|
@ -156,7 +163,7 @@ public class AutoTest {
|
|||
}
|
||||
|
||||
private static void testFord6() {
|
||||
sendCommand("set_engine_type 7");
|
||||
setEngineType(7);
|
||||
WaveChart chart;
|
||||
IoUtil.changeRpm(2000);
|
||||
chart = nextChart();
|
||||
|
@ -173,7 +180,7 @@ public class AutoTest {
|
|||
}
|
||||
|
||||
private static void testFordAspire() {
|
||||
sendCommand("set_engine_type 3");
|
||||
setEngineType(3);
|
||||
String msg;
|
||||
WaveChart chart;
|
||||
// todo: interesting changeRpm(100);
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.rusefi.io.tcp.TcpConnector;
|
|||
import com.rusefi.waves.WaveChart;
|
||||
import com.rusefi.waves.WaveChartParser;
|
||||
import com.rusefi.waves.WaveReport;
|
||||
import jssc.SerialPortList;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -30,12 +31,16 @@ public class IoUtil {
|
|||
* @throws IllegalStateException if command was not confirmed
|
||||
*/
|
||||
static void sendCommand(String command) {
|
||||
sendCommand(command, CommandQueue.DEFAULT_TIMEOUT);
|
||||
}
|
||||
|
||||
static void sendCommand(String command, int timeoutMs) {
|
||||
final CountDownLatch responseLatch = new CountDownLatch(1);
|
||||
long time = System.currentTimeMillis();
|
||||
if (LinkManager.hasError())
|
||||
throw new IllegalStateException("IO error");
|
||||
FileLog.MAIN.logLine("Sending command [" + command + "]");
|
||||
CommandQueue.getInstance().write(command, CommandQueue.DEFAULT_TIMEOUT, new InvocationConfirmationListener() {
|
||||
CommandQueue.getInstance().write(command, timeoutMs, new InvocationConfirmationListener() {
|
||||
@Override
|
||||
public void onCommandConfirmation() {
|
||||
responseLatch.countDown();
|
||||
|
@ -77,7 +82,7 @@ public class IoUtil {
|
|||
final AtomicReference<String> result = new AtomicReference<>();
|
||||
|
||||
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
|
||||
public void onUpdate(String value) {
|
||||
waveChartLatch.countDown();
|
||||
|
@ -88,7 +93,7 @@ public class IoUtil {
|
|||
long waitStartTime = System.currentTimeMillis();
|
||||
wait(waveChartLatch, timeout);
|
||||
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)
|
||||
throw new IllegalStateException("Chart timeout: " + timeout);
|
||||
return result.get();
|
||||
|
@ -182,4 +187,26 @@ public class IoUtil {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.rusefi;
|
||||
|
||||
import static com.rusefi.AutoTest.*;
|
||||
|
||||
/**
|
||||
* this test connects to real hardware via serial port
|
||||
* (c) Andrey Belomutskiy 2013-2015
|
||||
|
@ -7,6 +9,24 @@ package com.rusefi;
|
|||
*/
|
||||
public class RealHwTest {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,9 @@ public class 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();
|
||||
mc.addListener(new MessagesCentral.MessageListener() {
|
||||
@Override
|
||||
|
@ -139,22 +141,22 @@ public class CommandQueue {
|
|||
/**
|
||||
* 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)
|
||||
cql.onCommand(command);
|
||||
|
||||
pendingCommands.add(new MethodInvocation(command, timeout, listener));
|
||||
pendingCommands.add(new MethodInvocation(command, timeoutMs, listener));
|
||||
}
|
||||
|
||||
static class MethodInvocation {
|
||||
private final String text;
|
||||
private final int timeout;
|
||||
private final int timeoutMs;
|
||||
private final InvocationConfirmationListener listener;
|
||||
|
||||
MethodInvocation(String text, int timeout, InvocationConfirmationListener listener) {
|
||||
MethodInvocation(String text, int timeoutMs, InvocationConfirmationListener listener) {
|
||||
this.text = text;
|
||||
this.timeout = timeout;
|
||||
this.timeoutMs = timeoutMs;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
|
@ -163,7 +165,7 @@ public class CommandQueue {
|
|||
}
|
||||
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
return timeoutMs;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@ import java.util.*;
|
|||
*/
|
||||
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;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.rusefi.core;
|
|||
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.SensorConversion;
|
||||
import com.rusefi.waves.WaveReport;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -30,6 +31,11 @@ public class EngineState {
|
|||
private static final CharSequence TS_PROTOCOL_TAG = "ts_p_al";
|
||||
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>> {
|
||||
public final String prefix;
|
||||
|
||||
|
|
|
@ -7,12 +7,11 @@ import java.util.List;
|
|||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class AnalogChartCentral {
|
||||
private static final String KEY = "analog_chart";
|
||||
|
||||
private static List<AnalogChartListener> listeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
static {
|
||||
LinkManager.engineState.registerStringValueAction(KEY, new EngineState.ValueCallback<String>() {
|
||||
LinkManager.engineState.registerStringValueAction(AverageAnglesUtil.KEY, new EngineState.ValueCallback<String>() {
|
||||
@Override
|
||||
public void onUpdate(String message) {
|
||||
for (AnalogChartListener listener : listeners)
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.core.EngineState;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import jssc.SerialPortList;
|
||||
|
||||
/**
|
||||
* (c) Andrey Belomutskiy 2013-2015
|
||||
* 2/22/2015
|
||||
|
@ -16,13 +12,9 @@ public class CmdLine {
|
|||
}
|
||||
String command = args[0];
|
||||
if (args.length == 1) {
|
||||
String[] ports = SerialPortList.getPortNames();
|
||||
if (ports.length == 0) {
|
||||
System.out.println("Port not specified and no ports found");
|
||||
String port = IoUtil.getDefaultPort();
|
||||
if (port == null)
|
||||
return;
|
||||
}
|
||||
String port = ports[ports.length - 1];
|
||||
System.out.println("Using last of " + ports.length + " port(s)");
|
||||
executeCommand(command, port);
|
||||
} else {
|
||||
executeCommand(command, args[1]);
|
||||
|
@ -32,13 +24,11 @@ public class CmdLine {
|
|||
private static void executeCommand(String command, String port) {
|
||||
System.out.println("Sending " + command);
|
||||
System.out.println("Sending to " + 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);
|
||||
IoUtil.realHardwareConnect(port);
|
||||
|
||||
IoUtil.sendCommand(command);
|
||||
System.out.println("Done!");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue