auto-sync
This commit is contained in:
parent
45d4ed1b9f
commit
ee5957ddbe
|
@ -22,6 +22,13 @@ import static com.rusefi.waves.WaveReport.isCloseEnough;
|
|||
* 3/19/14.
|
||||
*/
|
||||
public class IoUtil {
|
||||
private static final int CMD_TIMEOUT = 20;
|
||||
|
||||
/**
|
||||
* Send a command and wait for the confirmation
|
||||
*
|
||||
* @throws IllegalStateException if command was not confirmed
|
||||
*/
|
||||
static void sendCommand(String command) {
|
||||
final CountDownLatch responseLatch = new CountDownLatch(1);
|
||||
long time = System.currentTimeMillis();
|
||||
|
@ -34,7 +41,7 @@ public class IoUtil {
|
|||
responseLatch.countDown();
|
||||
}
|
||||
});
|
||||
wait(responseLatch, 20);
|
||||
wait(responseLatch, CMD_TIMEOUT);
|
||||
if (LinkManager.hasError())
|
||||
throw new IllegalStateException("IO error");
|
||||
FileLog.MAIN.logLine("Command [" + command + "] executed in " + (System.currentTimeMillis() - time));
|
||||
|
@ -163,10 +170,11 @@ public class IoUtil {
|
|||
* TCP connector is blocking
|
||||
*/
|
||||
LinkManager.open();
|
||||
|
||||
LinkManager.engineState.registerStringValueAction(EngineState.RUS_EFI_VERSION_TAG, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
|
||||
waitForFirstResponse();
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
static void sleep(int seconds) {
|
||||
try {
|
||||
Thread.sleep(seconds * 1000L);
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.rusefi.FileLog;
|
|||
import com.rusefi.core.EngineState;
|
||||
import com.rusefi.io.serial.SerialConnector;
|
||||
import com.rusefi.io.tcp.TcpConnector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
@ -16,7 +17,7 @@ import java.util.concurrent.ThreadFactory;
|
|||
public class LinkManager {
|
||||
public final static Executor IO_EXECUTOR = Executors.newSingleThreadExecutor(new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
public Thread newThread(@NotNull Runnable r) {
|
||||
Thread t = new Thread(r);
|
||||
t.setName("IO executor thread");
|
||||
t.setDaemon(true); // need daemon thread so that COM thread is also daemon
|
||||
|
@ -57,6 +58,7 @@ public class LinkManager {
|
|||
public static boolean isStimulationMode;
|
||||
|
||||
public static void start(String port) {
|
||||
FileLog.MAIN.logLine("Starting " + port);
|
||||
if (isLogViewerMode(port)) {
|
||||
connector = LinkManager.VOID;
|
||||
} else if (TcpConnector.isTcpPort(port)) {
|
||||
|
@ -75,6 +77,9 @@ public class LinkManager {
|
|||
return connector == LinkManager.VOID;
|
||||
}
|
||||
|
||||
/**
|
||||
* todo: should this be merged into {@link #start(String)} ?
|
||||
*/
|
||||
public static void open() {
|
||||
if (connector == null)
|
||||
throw new NullPointerException("connector");
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.rusefi.core.EngineState;
|
|||
import com.rusefi.io.DataListener;
|
||||
import jssc.SerialPort;
|
||||
import jssc.SerialPortException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
|
@ -22,8 +23,6 @@ public class PortHolder {
|
|||
private static PortHolder instance = new PortHolder();
|
||||
private final Object portLock = new Object();
|
||||
|
||||
public static long startedAt = System.currentTimeMillis();
|
||||
|
||||
public PortHolderListener listener = PortHolderListener.VOID;
|
||||
|
||||
private PortHolder() {
|
||||
|
@ -45,7 +44,7 @@ public class PortHolder {
|
|||
FileLog.MAIN.logLine("Opening " + port + " @ " + BAUD_RATE);
|
||||
boolean opened = serialPort.openPort();//Open serial port
|
||||
if (!opened)
|
||||
FileLog.MAIN.logLine("opened: " + opened);
|
||||
FileLog.MAIN.logLine("not opened!");
|
||||
serialPort.setParams(BAUD_RATE, 8, 1, 0);//Set params.
|
||||
int mask = SerialPort.MASK_RXCHAR;
|
||||
//Set the prepared mask
|
||||
|
@ -55,7 +54,7 @@ public class PortHolder {
|
|||
FileLog.rlog("ERROR " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
FileLog.rlog("PortHolder: Sleeping a bit");
|
||||
try {
|
||||
// todo: why is this delay here? add a comment
|
||||
Thread.sleep(200);
|
||||
|
@ -69,6 +68,7 @@ public class PortHolder {
|
|||
}
|
||||
|
||||
try {
|
||||
FileLog.rlog("PortHolder: test command");
|
||||
/**
|
||||
* Let's make sure we have not connected to Tuner Studio port?
|
||||
* @see EngineState#TS_PROTOCOL_TAG
|
||||
|
@ -119,7 +119,9 @@ public class PortHolder {
|
|||
}
|
||||
}
|
||||
|
||||
private void doWriteCommand(String command) throws SerialPortException {
|
||||
private void doWriteCommand(@NotNull String command) throws SerialPortException {
|
||||
if (serialPort == null)
|
||||
throw new NullPointerException("serialPort");
|
||||
serialPort.writeString(command + "\r\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.io.serial;
|
||||
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.io.LinkConnector;
|
||||
|
||||
/**
|
||||
|
@ -13,6 +14,7 @@ public class SerialConnector implements LinkConnector {
|
|||
|
||||
@Override
|
||||
public void connect() {
|
||||
FileLog.MAIN.logLine("SerialConnector: connecting");
|
||||
SerialManager.scheduleOpening();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,13 +16,13 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||
*/
|
||||
public class EngineState {
|
||||
public static final String SEPARATOR = ",";
|
||||
public static final int SNIFFED_ADC_COUNT = 16;
|
||||
public static final ValueCallback<String> NOTHING = new ValueCallback<String>() {
|
||||
@Override
|
||||
public void onUpdate(String value) {
|
||||
}
|
||||
};
|
||||
public static final String PACKING_DELIMITER = ":";
|
||||
public static final String RUS_EFI_VERSION_TAG = "rusEfiVersion";
|
||||
/**
|
||||
* If we get this tag we have probably connected to the wrong port
|
||||
*/
|
||||
|
@ -43,11 +43,11 @@ public class EngineState {
|
|||
}
|
||||
}
|
||||
|
||||
public final List<EngineTimeListener> timeListeners = new CopyOnWriteArrayList<EngineTimeListener>();
|
||||
public final List<EngineTimeListener> timeListeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
private final ResponseBuffer buffer;
|
||||
private final List<StringActionPair> actions = new ArrayList<StringActionPair>();
|
||||
private final Set<String> keys = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||
private final List<StringActionPair> actions = new ArrayList<>();
|
||||
private final Set<String> keys = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
public EngineState(@NotNull final EngineStateListener listener) {
|
||||
buffer = new ResponseBuffer(new ResponseBuffer.ResponseListener() {
|
||||
|
@ -285,6 +285,13 @@ public class EngineState {
|
|||
}
|
||||
|
||||
public interface ValueCallback<V> {
|
||||
static final ValueCallback<?> VOID = new ValueCallback() {
|
||||
@Override
|
||||
public void onUpdate(Object value) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void onUpdate(V value);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,43 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.core.EngineState;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import jssc.SerialPortList;
|
||||
|
||||
/**
|
||||
* (c) Andrey Belomutskiy 2013-2015
|
||||
* 2/22/2015
|
||||
*/
|
||||
public class CmdLine {
|
||||
public static void main(String[] args) {
|
||||
if (args.length == 0 || args.length > 2) {
|
||||
System.out.println("CmdLine COMMAND [PORT]");
|
||||
return;
|
||||
}
|
||||
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");
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
IoUtil.sendCommand(command);
|
||||
System.out.println("Done!");
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
|
|||
* @see com.rusefi.ui.engine.EngineSnifferPanel
|
||||
*/
|
||||
public class Launcher extends FrameHelper {
|
||||
public static final int CONSOLE_VERSION = 20150216;
|
||||
public static final int CONSOLE_VERSION = 20150222;
|
||||
public static final boolean SHOW_STIMULATOR = true;
|
||||
public static final String TAB_INDEX = "main_tab";
|
||||
private final String port;
|
||||
|
@ -84,7 +84,7 @@ public class Launcher extends FrameHelper {
|
|||
|
||||
LinkManager.open();
|
||||
|
||||
LinkManager.engineState.registerStringValueAction("rusEfiVersion", new EngineState.ValueCallback<String>() {
|
||||
LinkManager.engineState.registerStringValueAction(EngineState.RUS_EFI_VERSION_TAG, new EngineState.ValueCallback<String>() {
|
||||
@Override
|
||||
public void onUpdate(String firmwareVersion) {
|
||||
setTitle(firmwareVersion);
|
||||
|
|
|
@ -17,6 +17,6 @@
|
|||
<orderEntry type="library" name="batik" level="project" />
|
||||
<orderEntry type="module" module-name="models" />
|
||||
<orderEntry type="library" name="SteelSeries" level="project" />
|
||||
<orderEntry type="module" module-name="autotest" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
</module>
|
Loading…
Reference in New Issue