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