auto-sync
This commit is contained in:
parent
e53811aaf4
commit
f36bb2560c
|
@ -169,6 +169,10 @@ public class IoUtil {
|
||||||
System.out.println("CONNECTION FAILED, did you specify the right port name?");
|
System.out.println("CONNECTION FAILED, did you specify the right port name?");
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConnectionEstablished() {
|
||||||
|
}
|
||||||
});
|
});
|
||||||
LinkManager.engineState.registerStringValueAction(EngineState.RUS_EFI_VERSION_TAG, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
|
LinkManager.engineState.registerStringValueAction(EngineState.RUS_EFI_VERSION_TAG, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
|
||||||
LinkManager.engineState.registerStringValueAction(EngineState.OUTPIN_TAG, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
|
LinkManager.engineState.registerStringValueAction(EngineState.OUTPIN_TAG, (EngineState.ValueCallback<String>) EngineState.ValueCallback.VOID);
|
||||||
|
|
|
@ -35,10 +35,16 @@ public class BinaryProtocol {
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
private ConfigurationImage controller;
|
private ConfigurationImage controller;
|
||||||
|
|
||||||
|
// todo: fix this, this is HORRIBLE!
|
||||||
|
@Deprecated
|
||||||
|
public static BinaryProtocol instance;
|
||||||
|
|
||||||
public BinaryProtocol(final Logger logger, SerialPort serialPort) {
|
public BinaryProtocol(final Logger logger, SerialPort serialPort) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.serialPort = serialPort;
|
this.serialPort = serialPort;
|
||||||
|
|
||||||
|
instance = this;
|
||||||
|
|
||||||
cbb = new CircularByteBuffer(BUFFER_SIZE);
|
cbb = new CircularByteBuffer(BUFFER_SIZE);
|
||||||
DataListener listener = new DataListener() {
|
DataListener listener = new DataListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -108,7 +114,7 @@ public class BinaryProtocol {
|
||||||
|
|
||||||
offset = range.second;
|
offset = range.second;
|
||||||
}
|
}
|
||||||
burn();
|
burn(logger);
|
||||||
setController(newVersion);
|
setController(newVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,9 +244,10 @@ public class BinaryProtocol {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void burn() throws InterruptedException, EOFException, SerialPortException {
|
private void burn(Logger logger) throws InterruptedException, EOFException, SerialPortException {
|
||||||
if (!isBurnPending)
|
if (!isBurnPending)
|
||||||
return;
|
return;
|
||||||
|
logger.info("Need to burn");
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
byte[] response = exchange(new byte[]{'B'});
|
byte[] response = exchange(new byte[]{'B'});
|
||||||
|
@ -249,6 +256,7 @@ public class BinaryProtocol {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
logger.info("DONE");
|
||||||
isBurnPending = false;
|
isBurnPending = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,7 @@ import com.rusefi.io.serial.SerialConnector;
|
||||||
import com.rusefi.io.tcp.TcpConnector;
|
import com.rusefi.io.tcp.TcpConnector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ThreadFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrey Belomutskiy
|
* @author Andrey Belomutskiy
|
||||||
|
@ -53,6 +51,10 @@ public class LinkManager {
|
||||||
return TcpConnector.doUnpackConfirmation(message);
|
return TcpConnector.doUnpackConfirmation(message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
public static final LinkedBlockingQueue<Runnable> COMMUNICATION_QUEUE = new LinkedBlockingQueue<>();
|
||||||
|
public static final ExecutorService COMMUNICATION_EXECUTOR = new ThreadPoolExecutor(1, 1,
|
||||||
|
0L, TimeUnit.MILLISECONDS,
|
||||||
|
COMMUNICATION_QUEUE);
|
||||||
public static EngineState engineState = new EngineState(new EngineState.EngineStateListenerImpl() {
|
public static EngineState engineState = new EngineState(new EngineState.EngineStateListenerImpl() {
|
||||||
@Override
|
@Override
|
||||||
public void beforeLine(String fullLine) {
|
public void beforeLine(String fullLine) {
|
||||||
|
@ -131,8 +133,15 @@ public class LinkManager {
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionFailed() {
|
public void onConnectionFailed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConnectionEstablished() {
|
||||||
|
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void onConnectionFailed();
|
void onConnectionFailed();
|
||||||
|
|
||||||
|
void onConnectionEstablished();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,14 +29,7 @@ public class PortHolder {
|
||||||
private static PortHolder instance = new PortHolder();
|
private static PortHolder instance = new PortHolder();
|
||||||
private final Object portLock = new Object();
|
private final Object portLock = new Object();
|
||||||
|
|
||||||
private final LinkedBlockingQueue<Runnable> EXE_Q = new LinkedBlockingQueue<>();
|
|
||||||
|
|
||||||
private final ExecutorService PORT_QUEUE = new ThreadPoolExecutor(1, 1,
|
|
||||||
0L, TimeUnit.MILLISECONDS,
|
|
||||||
EXE_Q);
|
|
||||||
|
|
||||||
public PortHolderListener portHolderListener = PortHolderListener.VOID;
|
public PortHolderListener portHolderListener = PortHolderListener.VOID;
|
||||||
private DataListener listener;
|
|
||||||
private BinaryProtocol bp;
|
private BinaryProtocol bp;
|
||||||
|
|
||||||
private PortHolder() {
|
private PortHolder() {
|
||||||
|
@ -50,13 +43,15 @@ public class PortHolder {
|
||||||
if (port == null)
|
if (port == null)
|
||||||
return false;
|
return false;
|
||||||
boolean result = open(port, dataListener);
|
boolean result = open(port, dataListener);
|
||||||
if (!result)
|
if (result) {
|
||||||
|
listener.onConnectionEstablished();
|
||||||
|
} else {
|
||||||
listener.onConnectionFailed();
|
listener.onConnectionFailed();
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean open(String port, final DataListener listener) {
|
public boolean open(String port, final DataListener listener) {
|
||||||
this.listener = listener;
|
|
||||||
SerialPort serialPort = new SerialPort(port);
|
SerialPort serialPort = new SerialPort(port);
|
||||||
try {
|
try {
|
||||||
FileLog.MAIN.logLine("Opening " + port + " @ " + BAUD_RATE);
|
FileLog.MAIN.logLine("Opening " + port + " @ " + BAUD_RATE);
|
||||||
|
@ -85,14 +80,14 @@ public class PortHolder {
|
||||||
bp = new BinaryProtocol(Logger.STDOUT, serialPort);
|
bp = new BinaryProtocol(Logger.STDOUT, serialPort);
|
||||||
|
|
||||||
bp.switchToBinaryProtocol();
|
bp.switchToBinaryProtocol();
|
||||||
// bp.readImage(BinaryProtocol.IMAGE_SIZE);
|
bp.readImage(BinaryProtocol.IMAGE_SIZE);
|
||||||
|
|
||||||
Runnable textPull = new Runnable() {
|
Runnable textPull = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (EXE_Q.isEmpty()) {
|
if (LinkManager.COMMUNICATION_QUEUE.isEmpty()) {
|
||||||
PORT_QUEUE.submit(new Runnable() {
|
LinkManager.COMMUNICATION_EXECUTOR.submit(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String text = bp.requestText();
|
String text = bp.requestText();
|
||||||
|
@ -159,7 +154,7 @@ public class PortHolder {
|
||||||
FileLog.MAIN.logLine("Sending [" + command + "]");
|
FileLog.MAIN.logLine("Sending [" + command + "]");
|
||||||
portHolderListener.onPortHolderMessage(PortHolder.class, "Sending [" + command + "]");
|
portHolderListener.onPortHolderMessage(PortHolder.class, "Sending [" + command + "]");
|
||||||
|
|
||||||
Future f = PORT_QUEUE.submit(new Runnable() {
|
Future f = LinkManager.COMMUNICATION_EXECUTOR.submit(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
bp.sendTextCommand(command);
|
bp.sendTextCommand(command);
|
||||||
|
@ -168,9 +163,7 @@ public class PortHolder {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
f.get(30, TimeUnit.SECONDS);
|
f.get(30, TimeUnit.SECONDS);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException | TimeoutException e) {
|
||||||
throw new IllegalStateException(e);
|
|
||||||
} catch (TimeoutException e) {
|
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.rusefi;
|
package com.rusefi;
|
||||||
|
|
||||||
|
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||||
|
import com.rusefi.binaryprotocol.BinaryProtocolCmd;
|
||||||
import com.rusefi.core.EngineState;
|
import com.rusefi.core.EngineState;
|
||||||
import com.rusefi.core.MessagesCentral;
|
import com.rusefi.core.MessagesCentral;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
|
@ -83,7 +85,20 @@ public class Launcher extends FrameHelper {
|
||||||
super.onWindowOpened();
|
super.onWindowOpened();
|
||||||
setTitle("N/A");
|
setTitle("N/A");
|
||||||
|
|
||||||
LinkManager.open(LinkManager.LinkStateListener.VOID);
|
LinkManager.open(new LinkManager.LinkStateListener() {
|
||||||
|
@Override
|
||||||
|
public void onConnectionFailed() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConnectionEstablished() {
|
||||||
|
try {
|
||||||
|
BinaryProtocolCmd.doShowImage(BinaryProtocol.instance.getController());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
LinkManager.engineState.registerStringValueAction(EngineState.RUS_EFI_VERSION_TAG, new EngineState.ValueCallback<String>() {
|
LinkManager.engineState.registerStringValueAction(EngineState.RUS_EFI_VERSION_TAG, new EngineState.ValueCallback<String>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.rusefi;
|
package com.rusefi;
|
||||||
|
|
||||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||||
|
import com.rusefi.io.LinkManager;
|
||||||
import com.rusefi.io.serial.PortHolder;
|
import com.rusefi.io.serial.PortHolder;
|
||||||
import com.rusefi.ui.StatusWindow;
|
import com.rusefi.ui.StatusWindow;
|
||||||
import jssc.SerialPort;
|
import jssc.SerialPort;
|
||||||
|
@ -10,8 +11,6 @@ import javax.swing.*;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (c) Andrey Belomutskiy 2013-2015
|
* (c) Andrey Belomutskiy 2013-2015
|
||||||
|
@ -19,8 +18,6 @@ import java.util.concurrent.Executors;
|
||||||
*/
|
*/
|
||||||
public class UploadChanges {
|
public class UploadChanges {
|
||||||
public static final Logger logger = createUiLogger();
|
public static final Logger logger = createUiLogger();
|
||||||
private static final Executor EXEC = Executors.newSingleThreadExecutor();
|
|
||||||
|
|
||||||
public static void main(String[] args) throws SerialPortException, InvocationTargetException, InterruptedException {
|
public static void main(String[] args) throws SerialPortException, InvocationTargetException, InterruptedException {
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
System.out.println("Exactly one parameter expected");
|
System.out.println("Exactly one parameter expected");
|
||||||
|
@ -62,11 +59,11 @@ public class UploadChanges {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void scheduleBurn(final ConfigurationImage newVersion, final BinaryProtocol bp) {
|
public static void scheduleBurn(final ConfigurationImage newVersion, final BinaryProtocol bp) {
|
||||||
EXEC.execute(new Runnable() {
|
LinkManager.COMMUNICATION_EXECUTOR.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
bp.burnChanges(newVersion, logger);
|
BinaryProtocol.instance.burnChanges(newVersion, logger);
|
||||||
} catch (InterruptedException | EOFException | SerialPortException e) {
|
} catch (InterruptedException | EOFException | SerialPortException e) {
|
||||||
logger.error("Error: " + e);
|
logger.error("Error: " + e);
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
|
|
|
@ -39,10 +39,13 @@ public class BinaryProtocolCmd {
|
||||||
bp.switchToBinaryProtocol();
|
bp.switchToBinaryProtocol();
|
||||||
|
|
||||||
bp.readImage(BinaryProtocol.IMAGE_SIZE);
|
bp.readImage(BinaryProtocol.IMAGE_SIZE);
|
||||||
ConfigurationImage image = bp.getController();
|
//
|
||||||
//
|
|
||||||
// image.saveToFile("rusefi_configuration.bin");
|
// image.saveToFile("rusefi_configuration.bin");
|
||||||
//
|
//
|
||||||
|
doShowImage(bp.getController());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void doShowImage(ConfigurationImage image) throws Exception {
|
||||||
RomRaiderWrapper.startRomRaider();
|
RomRaiderWrapper.startRomRaider();
|
||||||
ECUEditor.openImage(image.getFileContent(), SettingsManager.getSettings().getEcuDefinitionFiles().elementAt(0),
|
ECUEditor.openImage(image.getFileContent(), SettingsManager.getSettings().getEcuDefinitionFiles().elementAt(0),
|
||||||
"rusEfi");
|
"rusEfi");
|
||||||
|
|
Loading…
Reference in New Issue