auto-sync

This commit is contained in:
rusEfi 2015-02-23 14:04:26 -06:00
parent cfda07d7ba
commit 35c1d7021d
3 changed files with 52 additions and 44 deletions

View File

@ -4,7 +4,7 @@ package com.rusefi;
import com.rusefi.waves.WaveChart;
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.sleep;
import static com.rusefi.TestingUtils.*;
@ -18,6 +18,8 @@ import static com.rusefi.TestingUtils.*;
* 3/5/14
*/
public class AutoTest {
static int currentEngineType;
static void mainTestBody() {
testCitroenBerlingo();
testMazda626();
@ -36,6 +38,7 @@ public class AutoTest {
}
private static void setEngineType(int type) {
currentEngineType = type;
sendCommand("set_engine_type " + type, 10000);
sleep(5);
sendCommand("enable self_stimulation");

View File

@ -52,7 +52,7 @@ public class IoUtil {
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 {
responseLatch.await(seconds, TimeUnit.SECONDS);
} 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) {
sendCommand("rpm " + rpm);
long time = System.currentTimeMillis();

View File

@ -1,11 +1,16 @@
package com.rusefi;
import com.rusefi.core.EngineState;
import com.rusefi.io.LinkManager;
import com.rusefi.waves.RevolutionLog;
import com.rusefi.waves.WaveChart;
import com.rusefi.waves.WaveChartParser;
import com.rusefi.waves.WaveReport;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
import static com.rusefi.waves.WaveReport.isCloseEnough;
@ -86,4 +91,46 @@ public class TestingUtils {
static void assertNull(String msg, Object value) {
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();
}
}