auto-sync
This commit is contained in:
parent
9ddf6c4267
commit
9fb19ba92a
|
@ -6,10 +6,11 @@ package com.rusefi;
|
||||||
public interface Timeouts {
|
public interface Timeouts {
|
||||||
int SECOND = 1000;
|
int SECOND = 1000;
|
||||||
int COMMAND_TIMEOUT_SEC = 10; // seconds
|
int COMMAND_TIMEOUT_SEC = 10; // seconds
|
||||||
int CONNECTION_RESTART_DELAY = 20 * SECOND;
|
|
||||||
int BINARY_IO_TIMEOUT = 5 * SECOND;
|
int BINARY_IO_TIMEOUT = 5 * SECOND;
|
||||||
int CMD_TIMEOUT = 20;
|
int CMD_TIMEOUT = 20;
|
||||||
int READ_IMAGE_TIMEOUT = 60 * SECOND;
|
int READ_IMAGE_TIMEOUT = 60 * SECOND;
|
||||||
|
|
||||||
|
int CONNECTION_RESTART_DELAY = 20 * SECOND;
|
||||||
int CS_TIMEOUT = 3000;
|
int CS_TIMEOUT = 3000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,10 @@ package com.rusefi.binaryprotocol;
|
||||||
|
|
||||||
import com.rusefi.*;
|
import com.rusefi.*;
|
||||||
import com.rusefi.config.FieldType;
|
import com.rusefi.config.FieldType;
|
||||||
import com.rusefi.core.MessagesCentral;
|
|
||||||
import com.rusefi.core.Pair;
|
import com.rusefi.core.Pair;
|
||||||
import com.rusefi.core.Sensor;
|
import com.rusefi.core.Sensor;
|
||||||
import com.rusefi.core.SensorCentral;
|
import com.rusefi.core.SensorCentral;
|
||||||
import com.rusefi.io.*;
|
import com.rusefi.io.*;
|
||||||
import com.rusefi.io.serial.PortHolder;
|
|
||||||
import com.rusefi.io.serial.SerialIoStream;
|
import com.rusefi.io.serial.SerialIoStream;
|
||||||
import jssc.SerialPort;
|
import jssc.SerialPort;
|
||||||
import jssc.SerialPortException;
|
import jssc.SerialPortException;
|
||||||
|
@ -102,7 +100,7 @@ public class BinaryProtocol {
|
||||||
|
|
||||||
public void doSend(final String command, boolean fireEvent) throws InterruptedException {
|
public void doSend(final String command, boolean fireEvent) throws InterruptedException {
|
||||||
FileLog.MAIN.logLine("Sending [" + command + "]");
|
FileLog.MAIN.logLine("Sending [" + command + "]");
|
||||||
if (fireEvent) {
|
if (fireEvent && LinkManager.LOG_LEVEL.isDebugEnabled()) {
|
||||||
CommunicationLoggingHolder.communicationLoggingListener.onPortHolderMessage(BinaryProtocol.class, "Sending [" + command + "]");
|
CommunicationLoggingHolder.communicationLoggingListener.onPortHolderMessage(BinaryProtocol.class, "Sending [" + command + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +127,7 @@ public class BinaryProtocol {
|
||||||
/**
|
/**
|
||||||
* this here to make CommandQueue happy
|
* this here to make CommandQueue happy
|
||||||
*/
|
*/
|
||||||
MessagesCentral.getInstance().postMessage(PortHolder.class, CommandQueue.CONFIRMATION_PREFIX + command);
|
CommandQueue.getInstance().handleConfirmationMessage(CommandQueue.CONFIRMATION_PREFIX + command);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,7 +9,8 @@ import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class keeps re-sending a command till a proper confirmation is received
|
* This singleton keeps re-sending commands till a proper confirmation is received
|
||||||
|
*
|
||||||
* <p/>
|
* <p/>
|
||||||
* Date: 1/7/13
|
* Date: 1/7/13
|
||||||
* (c) Andrey Belomutskiy
|
* (c) Andrey Belomutskiy
|
||||||
|
@ -115,27 +116,23 @@ public class CommandQueue {
|
||||||
Thread thread = new Thread(runnable, "Commands Queue");
|
Thread thread = new Thread(runnable, "Commands Queue");
|
||||||
thread.setDaemon(true);
|
thread.setDaemon(true);
|
||||||
thread.start();
|
thread.start();
|
||||||
final MessagesCentral mc = MessagesCentral.getInstance();
|
|
||||||
mc.addListener(new MessagesCentral.MessageListener() {
|
|
||||||
@Override
|
|
||||||
public void onMessage(Class clazz, String message) {
|
|
||||||
if (message.startsWith(CONFIRMATION_PREFIX))
|
|
||||||
handleConfirmationMessage(message, mc);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this method handles command confirmations packed as
|
* this method handles command confirmations packed as
|
||||||
* TODO: add example, todo: refactor method and add unit test
|
* TODO: add example, todo: refactor method and add unit test
|
||||||
*/
|
*/
|
||||||
private void handleConfirmationMessage(final String message, MessagesCentral mc) {
|
public void handleConfirmationMessage(final String message) {
|
||||||
|
MessagesCentral mc = MessagesCentral.getInstance();
|
||||||
String confirmation = LinkManager.unpackConfirmation(message);
|
String confirmation = LinkManager.unpackConfirmation(message);
|
||||||
if (confirmation == null)
|
if (confirmation == null)
|
||||||
mc.postMessage(CommandQueue.class, "Broken confirmation length: " + message);
|
mc.postMessage(CommandQueue.class, "Broken confirmation length: " + message);
|
||||||
pendingConfirmations.add(confirmation);
|
pendingConfirmations.add(confirmation);
|
||||||
|
if (LinkManager.LOG_LEVEL.isDebugEnabled())
|
||||||
mc.postMessage(CommandQueue.class, "got valid conf! " + confirmation + ", still pending: " + pendingCommands.size());
|
mc.postMessage(CommandQueue.class, "got valid conf! " + confirmation + ", still pending: " + pendingCommands.size());
|
||||||
|
|
||||||
// FileLog.MAIN.logLine("templog got valid conf " + confirmation + " " + System.currentTimeMillis() + " " + new Date());
|
// FileLog.MAIN.logLine("templog got valid conf " + confirmation + " " + System.currentTimeMillis() + " " + new Date());
|
||||||
|
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
lock.notifyAll();
|
lock.notifyAll();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class ConnectionStatus {
|
||||||
private final Timer timer = new Timer(Timeouts.CS_TIMEOUT, new ActionListener() {
|
private final Timer timer = new Timer(Timeouts.CS_TIMEOUT, new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
setValue(Value.NOT_CONNECTED);
|
// setValue(Value.NOT_CONNECTED);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class ConnectionWatchdog {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
FileLog.MAIN.logLine("ConnectionWatchdog.reconnectTimer restarting");
|
FileLog.MAIN.logLine("ConnectionWatchdog.reconnectTimer restarting");
|
||||||
LinkManager.restart();
|
LinkManager.restart();
|
||||||
reconnectTimer.restart();
|
onDataArrived();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -23,20 +23,20 @@ public class ConnectionWatchdog {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void start() {
|
public static void start() {
|
||||||
reconnectTimer.restart();
|
onDataArrived();
|
||||||
|
|
||||||
LinkManager.engineState.timeListeners.add(new EngineTimeListener() {
|
LinkManager.engineState.timeListeners.add(new EngineTimeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onTime(double time) {
|
public void onTime(double time) {
|
||||||
/**
|
onDataArrived();
|
||||||
* this timer will reconnect
|
|
||||||
*/
|
|
||||||
reconnectTimer.restart();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onDataArrived() {
|
public static void onDataArrived() {
|
||||||
|
/**
|
||||||
|
* this timer will reconnect
|
||||||
|
*/
|
||||||
reconnectTimer.restart();
|
reconnectTimer.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -13,6 +13,19 @@ import java.util.concurrent.*;
|
||||||
* 3/3/14
|
* 3/3/14
|
||||||
*/
|
*/
|
||||||
public class LinkManager {
|
public class LinkManager {
|
||||||
|
public enum LogLevel {
|
||||||
|
INFO,
|
||||||
|
DEBUG,
|
||||||
|
TRACE;
|
||||||
|
|
||||||
|
public boolean isDebugEnabled() {
|
||||||
|
return this == DEBUG || this == TRACE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static LogLevel LOG_LEVEL = LogLevel.INFO;
|
||||||
|
|
||||||
public static LinkDecoder ENCODER = new LinkDecoder() {
|
public static LinkDecoder ENCODER = new LinkDecoder() {
|
||||||
@Override
|
@Override
|
||||||
public String unpack(String packedLine) {
|
public String unpack(String packedLine) {
|
||||||
|
@ -96,6 +109,7 @@ public class LinkManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void restart() {
|
public static void restart() {
|
||||||
|
ConnectionStatus.INSTANCE.setValue(ConnectionStatus.Value.NOT_CONNECTED);
|
||||||
connector.restart();
|
connector.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.rusefi.io.CommunicationLoggingHolder;
|
||||||
import com.rusefi.io.CommunicationLoggingListener;
|
import com.rusefi.io.CommunicationLoggingListener;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
|
||||||
* @see EngineSnifferPanel
|
* @see EngineSnifferPanel
|
||||||
*/
|
*/
|
||||||
public class Launcher {
|
public class Launcher {
|
||||||
public static final int CONSOLE_VERSION = 20160321;
|
public static final int CONSOLE_VERSION = 20160402;
|
||||||
public static final boolean SHOW_STIMULATOR = false;
|
public static final boolean SHOW_STIMULATOR = false;
|
||||||
private static final String TAB_INDEX = "main_tab";
|
private static final String TAB_INDEX = "main_tab";
|
||||||
protected static final String PORT_KEY = "port";
|
protected static final String PORT_KEY = "port";
|
||||||
|
@ -236,6 +236,9 @@ public class Launcher {
|
||||||
JustOneInstance.onStart();
|
JustOneInstance.onStart();
|
||||||
try {
|
try {
|
||||||
boolean isPortDefined = args.length > 0;
|
boolean isPortDefined = args.length > 0;
|
||||||
|
boolean isBaudRateDefined = args.length > 1;
|
||||||
|
if (isBaudRateDefined)
|
||||||
|
PortHolder.BAUD_RATE = Integer.parseInt(args[1]);
|
||||||
if (isPortDefined) {
|
if (isPortDefined) {
|
||||||
new Launcher(args[0]);
|
new Launcher(args[0]);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue