auto-sync

This commit is contained in:
rusEfi 2016-04-03 00:02:46 -04:00
parent 9ddf6c4267
commit 9fb19ba92a
8 changed files with 38 additions and 24 deletions

View File

@ -6,10 +6,11 @@ package com.rusefi;
public interface Timeouts {
int SECOND = 1000;
int COMMAND_TIMEOUT_SEC = 10; // seconds
int CONNECTION_RESTART_DELAY = 20 * SECOND;
int BINARY_IO_TIMEOUT = 5 * SECOND;
int CMD_TIMEOUT = 20;
int READ_IMAGE_TIMEOUT = 60 * SECOND;
int CONNECTION_RESTART_DELAY = 20 * SECOND;
int CS_TIMEOUT = 3000;
}

View File

@ -2,12 +2,10 @@ package com.rusefi.binaryprotocol;
import com.rusefi.*;
import com.rusefi.config.FieldType;
import com.rusefi.core.MessagesCentral;
import com.rusefi.core.Pair;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCentral;
import com.rusefi.io.*;
import com.rusefi.io.serial.PortHolder;
import com.rusefi.io.serial.SerialIoStream;
import jssc.SerialPort;
import jssc.SerialPortException;
@ -102,7 +100,7 @@ public class BinaryProtocol {
public void doSend(final String command, boolean fireEvent) throws InterruptedException {
FileLog.MAIN.logLine("Sending [" + command + "]");
if (fireEvent) {
if (fireEvent && LinkManager.LOG_LEVEL.isDebugEnabled()) {
CommunicationLoggingHolder.communicationLoggingListener.onPortHolderMessage(BinaryProtocol.class, "Sending [" + command + "]");
}
@ -129,7 +127,7 @@ public class BinaryProtocol {
/**
* this here to make CommandQueue happy
*/
MessagesCentral.getInstance().postMessage(PortHolder.class, CommandQueue.CONFIRMATION_PREFIX + command);
CommandQueue.getInstance().handleConfirmationMessage(CommandQueue.CONFIRMATION_PREFIX + command);
}
/**

View File

@ -9,7 +9,8 @@ import java.util.concurrent.BlockingQueue;
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/>
* Date: 1/7/13
* (c) Andrey Belomutskiy
@ -115,27 +116,23 @@ public class CommandQueue {
Thread thread = new Thread(runnable, "Commands Queue");
thread.setDaemon(true);
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
* 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);
if (confirmation == null)
mc.postMessage(CommandQueue.class, "Broken confirmation length: " + message);
pendingConfirmations.add(confirmation);
mc.postMessage(CommandQueue.class, "got valid conf! " + confirmation + ", still pending: " + pendingCommands.size());
if (LinkManager.LOG_LEVEL.isDebugEnabled())
mc.postMessage(CommandQueue.class, "got valid conf! " + confirmation + ", still pending: " + pendingCommands.size());
// FileLog.MAIN.logLine("templog got valid conf " + confirmation + " " + System.currentTimeMillis() + " " + new Date());
synchronized (lock) {
lock.notifyAll();
}

View File

@ -34,7 +34,7 @@ public class ConnectionStatus {
private final Timer timer = new Timer(Timeouts.CS_TIMEOUT, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setValue(Value.NOT_CONNECTED);
// setValue(Value.NOT_CONNECTED);
}
});

View File

@ -15,7 +15,7 @@ public class ConnectionWatchdog {
public void actionPerformed(ActionEvent e) {
FileLog.MAIN.logLine("ConnectionWatchdog.reconnectTimer restarting");
LinkManager.restart();
reconnectTimer.restart();
onDataArrived();
}
});
@ -23,20 +23,20 @@ public class ConnectionWatchdog {
}
public static void start() {
reconnectTimer.restart();
onDataArrived();
LinkManager.engineState.timeListeners.add(new EngineTimeListener() {
@Override
public void onTime(double time) {
/**
* this timer will reconnect
*/
reconnectTimer.restart();
onDataArrived();
}
});
}
public static void onDataArrived() {
/**
* this timer will reconnect
*/
reconnectTimer.restart();
}
}

View File

@ -13,6 +13,19 @@ import java.util.concurrent.*;
* 3/3/14
*/
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() {
@Override
public String unpack(String packedLine) {
@ -96,6 +109,7 @@ public class LinkManager {
}
public static void restart() {
ConnectionStatus.INSTANCE.setValue(ConnectionStatus.Value.NOT_CONNECTED);
connector.restart();
}

View File

@ -5,6 +5,7 @@ import com.rusefi.io.CommunicationLoggingHolder;
import com.rusefi.io.CommunicationLoggingListener;
import javax.swing.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

View File

@ -36,7 +36,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
* @see EngineSnifferPanel
*/
public class Launcher {
public static final int CONSOLE_VERSION = 20160321;
public static final int CONSOLE_VERSION = 20160402;
public static final boolean SHOW_STIMULATOR = false;
private static final String TAB_INDEX = "main_tab";
protected static final String PORT_KEY = "port";
@ -236,6 +236,9 @@ public class Launcher {
JustOneInstance.onStart();
try {
boolean isPortDefined = args.length > 0;
boolean isBaudRateDefined = args.length > 1;
if (isBaudRateDefined)
PortHolder.BAUD_RATE = Integer.parseInt(args[1]);
if (isPortDefined) {
new Launcher(args[0]);
} else {