auto-sync
This commit is contained in:
parent
cfda07d7ba
commit
35c1d7021d
|
@ -4,7 +4,7 @@ package com.rusefi;
|
||||||
import com.rusefi.waves.WaveChart;
|
import com.rusefi.waves.WaveChart;
|
||||||
import com.rusefi.waves.WaveReport;
|
import com.rusefi.waves.WaveReport;
|
||||||
|
|
||||||
import static com.rusefi.IoUtil.nextChart;
|
import static com.rusefi.TestingUtils.nextChart;
|
||||||
import static com.rusefi.IoUtil.sendCommand;
|
import static com.rusefi.IoUtil.sendCommand;
|
||||||
import static com.rusefi.IoUtil.sleep;
|
import static com.rusefi.IoUtil.sleep;
|
||||||
import static com.rusefi.TestingUtils.*;
|
import static com.rusefi.TestingUtils.*;
|
||||||
|
@ -18,6 +18,8 @@ import static com.rusefi.TestingUtils.*;
|
||||||
* 3/5/14
|
* 3/5/14
|
||||||
*/
|
*/
|
||||||
public class AutoTest {
|
public class AutoTest {
|
||||||
|
static int currentEngineType;
|
||||||
|
|
||||||
static void mainTestBody() {
|
static void mainTestBody() {
|
||||||
testCitroenBerlingo();
|
testCitroenBerlingo();
|
||||||
testMazda626();
|
testMazda626();
|
||||||
|
@ -36,6 +38,7 @@ public class AutoTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setEngineType(int type) {
|
private static void setEngineType(int type) {
|
||||||
|
currentEngineType = type;
|
||||||
sendCommand("set_engine_type " + type, 10000);
|
sendCommand("set_engine_type " + type, 10000);
|
||||||
sleep(5);
|
sleep(5);
|
||||||
sendCommand("enable self_stimulation");
|
sendCommand("enable self_stimulation");
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class IoUtil {
|
||||||
FileLog.MAIN.logLine("Command [" + command + "] executed in " + (System.currentTimeMillis() - time));
|
FileLog.MAIN.logLine("Command [" + command + "] executed in " + (System.currentTimeMillis() - time));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void wait(CountDownLatch responseLatch, int seconds) {
|
static void wait(CountDownLatch responseLatch, int seconds) {
|
||||||
try {
|
try {
|
||||||
responseLatch.await(seconds, TimeUnit.SECONDS);
|
responseLatch.await(seconds, TimeUnit.SECONDS);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -60,48 +60,6 @@ public class IoUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getNextWaveChart() {
|
|
||||||
// we need to skip TWO because spark could have been scheduled a while ago and happen now
|
|
||||||
// todo: improve this logic, compare times
|
|
||||||
getWaveChart();
|
|
||||||
// we want to wait for the 2nd chart to see same same RPM across the whole chart
|
|
||||||
String result = getWaveChart();
|
|
||||||
FileLog.MAIN.logLine("current chart: " + result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is blocking and waits for the next wave chart to arrive
|
|
||||||
*
|
|
||||||
* @return next wave chart in the I/O pipeline
|
|
||||||
*/
|
|
||||||
private static String getWaveChart() {
|
|
||||||
final CountDownLatch waveChartLatch = new CountDownLatch(1);
|
|
||||||
|
|
||||||
final AtomicReference<String> result = new AtomicReference<>();
|
|
||||||
|
|
||||||
FileLog.MAIN.logLine("waiting for next chart");
|
|
||||||
LinkManager.engineState.replaceStringValueAction(WaveReport.WAVE_CHART, new EngineState.ValueCallback<String>() {
|
|
||||||
@Override
|
|
||||||
public void onUpdate(String value) {
|
|
||||||
waveChartLatch.countDown();
|
|
||||||
result.set(value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
int timeout = 60;
|
|
||||||
long waitStartTime = System.currentTimeMillis();
|
|
||||||
wait(waveChartLatch, timeout);
|
|
||||||
FileLog.MAIN.logLine("got next chart in " + (System.currentTimeMillis() - waitStartTime) + "ms");
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
static WaveChart nextChart() {
|
|
||||||
return WaveChartParser.unpackToMap(getNextWaveChart());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void changeRpm(final int rpm) {
|
static void changeRpm(final int rpm) {
|
||||||
sendCommand("rpm " + rpm);
|
sendCommand("rpm " + rpm);
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package com.rusefi;
|
package com.rusefi;
|
||||||
|
|
||||||
|
import com.rusefi.core.EngineState;
|
||||||
|
import com.rusefi.io.LinkManager;
|
||||||
import com.rusefi.waves.RevolutionLog;
|
import com.rusefi.waves.RevolutionLog;
|
||||||
import com.rusefi.waves.WaveChart;
|
import com.rusefi.waves.WaveChart;
|
||||||
|
import com.rusefi.waves.WaveChartParser;
|
||||||
import com.rusefi.waves.WaveReport;
|
import com.rusefi.waves.WaveReport;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static com.rusefi.waves.WaveReport.isCloseEnough;
|
import static com.rusefi.waves.WaveReport.isCloseEnough;
|
||||||
|
|
||||||
|
@ -86,4 +91,46 @@ public class TestingUtils {
|
||||||
static void assertNull(String msg, Object value) {
|
static void assertNull(String msg, Object value) {
|
||||||
assertTrue(msg, value == null);
|
assertTrue(msg, value == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static WaveChart nextChart() {
|
||||||
|
return WaveChartParser.unpackToMap(getNextWaveChart());
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getNextWaveChart() {
|
||||||
|
// we need to skip TWO because spark could have been scheduled a while ago and happen now
|
||||||
|
// todo: improve this logic, compare times
|
||||||
|
getWaveChart();
|
||||||
|
// we want to wait for the 2nd chart to see same same RPM across the whole chart
|
||||||
|
String result = getWaveChart();
|
||||||
|
FileLog.MAIN.logLine("current chart: " + result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is blocking and waits for the next wave chart to arrive
|
||||||
|
*
|
||||||
|
* @return next wave chart in the I/O pipeline
|
||||||
|
*/
|
||||||
|
private static String getWaveChart() {
|
||||||
|
final CountDownLatch waveChartLatch = new CountDownLatch(1);
|
||||||
|
|
||||||
|
final AtomicReference<String> result = new AtomicReference<>();
|
||||||
|
|
||||||
|
FileLog.MAIN.logLine("waiting for next chart");
|
||||||
|
LinkManager.engineState.replaceStringValueAction(WaveReport.WAVE_CHART, new EngineState.ValueCallback<String>() {
|
||||||
|
@Override
|
||||||
|
public void onUpdate(String value) {
|
||||||
|
waveChartLatch.countDown();
|
||||||
|
result.set(value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
int timeout = 60;
|
||||||
|
long waitStartTime = System.currentTimeMillis();
|
||||||
|
IoUtil.wait(waveChartLatch, timeout);
|
||||||
|
FileLog.MAIN.logLine("got next chart in " + (System.currentTimeMillis() - waitStartTime) + "ms for engine_type " + AutoTest.currentEngineType);
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue