auto-sync
This commit is contained in:
parent
ff24bf08b0
commit
e53811aaf4
|
@ -1,5 +1,5 @@
|
|||
// This file was generated by Version2Header
|
||||
// Mon Mar 09 22:03:41 EDT 2015
|
||||
// Mon Mar 09 23:25:52 EDT 2015
|
||||
#ifndef VCS_VERSION
|
||||
#define VCS_VERSION "7346"
|
||||
#endif
|
||||
|
|
|
@ -23,14 +23,18 @@ public class ConfigurationImage {
|
|||
return content.length;
|
||||
}
|
||||
|
||||
public byte[] getFileContent() throws IOException {
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
byte[] bytes = BIN_HEADER.getBytes();
|
||||
if (bytes.length != BIN_HEADER.length())
|
||||
throw new IllegalStateException("Encoding issue");
|
||||
baos.write(bytes);
|
||||
baos.write(content);
|
||||
return baos.toByteArray();
|
||||
public byte[] getFileContent() {
|
||||
try {
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
byte[] bytes = BIN_HEADER.getBytes();
|
||||
if (bytes.length != BIN_HEADER.length())
|
||||
throw new IllegalStateException("Encoding issue");
|
||||
baos.write(bytes);
|
||||
baos.write(content);
|
||||
return baos.toByteArray();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ public interface Logger {
|
|||
Logger STDOUT = new Logger() {
|
||||
@Override
|
||||
public void trace(String msg) {
|
||||
System.out.println(msg);
|
||||
// System.out.println(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.util.Arrays;
|
|||
* 3/6/2015
|
||||
*/
|
||||
public class BinaryProtocol {
|
||||
public static final int IMAGE_SIZE = 14008;
|
||||
private static final int BLOCKING_FACTOR = 256;
|
||||
private static final byte RESPONSE_OK = 0;
|
||||
private static final byte RESPONSE_BURN_OK = 0x04;
|
||||
|
@ -169,7 +170,7 @@ public class BinaryProtocol {
|
|||
}
|
||||
}
|
||||
|
||||
public void readImage(int size) throws SerialPortException, EOFException, InterruptedException {
|
||||
public void readImage(int size) {
|
||||
ConfigurationImage image = new ConfigurationImage(size);
|
||||
|
||||
int offset = 0;
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package com.rusefi.io.serial;
|
||||
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.core.EngineState;
|
||||
import com.rusefi.Logger;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.core.MessagesCentral;
|
||||
import com.rusefi.io.CommandQueue;
|
||||
import com.rusefi.io.DataListener;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import jssc.SerialPort;
|
||||
|
@ -9,6 +12,8 @@ import jssc.SerialPortException;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* This class holds the reference to the actual Serial port object
|
||||
* <p/>
|
||||
|
@ -24,7 +29,15 @@ 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() {
|
||||
}
|
||||
|
@ -42,7 +55,8 @@ public class PortHolder {
|
|||
return result;
|
||||
}
|
||||
|
||||
public boolean open(String port, DataListener listener) {
|
||||
public boolean open(String port, final DataListener listener) {
|
||||
this.listener = listener;
|
||||
SerialPort serialPort = new SerialPort(port);
|
||||
try {
|
||||
FileLog.MAIN.logLine("Opening " + port + " @ " + BAUD_RATE);
|
||||
|
@ -50,7 +64,7 @@ public class PortHolder {
|
|||
if (!opened)
|
||||
FileLog.MAIN.logLine("not opened!");
|
||||
setupPort(serialPort, BAUD_RATE);
|
||||
serialPort.addEventListener(new SerialPortReader(serialPort, listener));
|
||||
// serialPort.addEventListener(new SerialPortReader(serialPort, portHolderListener));
|
||||
} catch (SerialPortException e) {
|
||||
FileLog.rlog("ERROR " + e.getMessage());
|
||||
return false;
|
||||
|
@ -68,19 +82,54 @@ public class PortHolder {
|
|||
portLock.notifyAll();
|
||||
}
|
||||
|
||||
try {
|
||||
FileLog.rlog("PortHolder: test command");
|
||||
/**
|
||||
* Let's make sure we have not connected to Tuner Studio port?
|
||||
* @see EngineState#TS_PROTOCOL_TAG
|
||||
*/
|
||||
doWriteCommand("test");
|
||||
} catch (SerialPortException e) {
|
||||
return false;
|
||||
}
|
||||
bp = new BinaryProtocol(Logger.STDOUT, serialPort);
|
||||
|
||||
bp.switchToBinaryProtocol();
|
||||
// bp.readImage(BinaryProtocol.IMAGE_SIZE);
|
||||
|
||||
Runnable textPull = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
if (EXE_Q.isEmpty()) {
|
||||
PORT_QUEUE.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String text = bp.requestText();
|
||||
listener.onDataArrived((text + "\r\n").getBytes());
|
||||
}
|
||||
});
|
||||
}
|
||||
sleep();
|
||||
}
|
||||
}
|
||||
};
|
||||
Thread tr = new Thread(textPull);
|
||||
tr.setName("text pull");
|
||||
tr.start();
|
||||
|
||||
//
|
||||
// try {
|
||||
// FileLog.rlog("PortHolder: test command");
|
||||
// /**
|
||||
// * Let's make sure we have not connected to Tuner Studio port?
|
||||
// * @see EngineState#TS_PROTOCOL_TAG
|
||||
// */
|
||||
// doWriteCommand("test");
|
||||
// } catch (SerialPortException e) {
|
||||
// return false;
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sleep() {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupPort(SerialPort serialPort, int baudRate) throws SerialPortException {
|
||||
serialPort.setParams(baudRate, 8, 1, 0);//Set params.
|
||||
int mask = SerialPort.MASK_RXCHAR;
|
||||
|
@ -106,25 +155,45 @@ public class PortHolder {
|
|||
/**
|
||||
* this method blocks till a connection is available
|
||||
*/
|
||||
public void packAndSend(String command) throws InterruptedException {
|
||||
public void packAndSend(final String command) throws InterruptedException {
|
||||
FileLog.MAIN.logLine("Sending [" + command + "]");
|
||||
portHolderListener.onPortHolderMessage(PortHolder.class, "Sending [" + command + "]");
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
Future f = PORT_QUEUE.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
bp.sendTextCommand(command);
|
||||
}
|
||||
});
|
||||
|
||||
synchronized (portLock) {
|
||||
while (serialPort == null) {
|
||||
if (System.currentTimeMillis() - now > 3 * MINUTE)
|
||||
portHolderListener.onPortHolderMessage(PortHolder.class, "Looks like connection is gone :(");
|
||||
portLock.wait(MINUTE);
|
||||
}
|
||||
// we are here only when serialPort!=null, that means we have a connection
|
||||
try {
|
||||
doWriteCommand(command);
|
||||
} catch (SerialPortException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
try {
|
||||
f.get(30, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException e) {
|
||||
throw new IllegalStateException(e);
|
||||
} catch (TimeoutException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
/**
|
||||
* this here to make CommandQueue happy
|
||||
*/
|
||||
MessagesCentral.getInstance().postMessage(PortHolder.class, CommandQueue.CONFIRMATION_PREFIX + command);
|
||||
|
||||
|
||||
// long now = System.currentTimeMillis();
|
||||
//
|
||||
// synchronized (portLock) {
|
||||
// while (serialPort == null) {
|
||||
// if (System.currentTimeMillis() - now > 3 * MINUTE)
|
||||
// portHolderListener.onPortHolderMessage(PortHolder.class, "Looks like connection is gone :(");
|
||||
// portLock.wait(MINUTE);
|
||||
// }
|
||||
// // we are here only when serialPort!=null, that means we have a connection
|
||||
// try {
|
||||
// doWriteCommand(command);
|
||||
// } catch (SerialPortException e) {
|
||||
// throw new IllegalStateException(e);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private void doWriteCommand(@NotNull String command) throws SerialPortException {
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.rusefi.io.serial;
|
|||
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.core.EngineState;
|
||||
import com.rusefi.io.CommandQueue;
|
||||
import com.rusefi.io.LinkConnector;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.io.tcp.TcpConnector;
|
||||
|
@ -33,17 +34,16 @@ public class SerialConnector implements LinkConnector {
|
|||
|
||||
@Override
|
||||
public String unpack(String packet) {
|
||||
return EngineState.unpackString(packet);
|
||||
return packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(String text) throws InterruptedException {
|
||||
String command = LinkManager.encodeCommand(text);
|
||||
PortHolder.getInstance().packAndSend(command);
|
||||
PortHolder.getInstance().packAndSend(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String unpackConfirmation(String message) {
|
||||
return TcpConnector.doUnpackConfirmation(message);
|
||||
return message.substring(CommandQueue.CONFIRMATION_PREFIX.length());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public class Launcher extends FrameHelper {
|
|||
super.onWindowOpened();
|
||||
setTitle("N/A");
|
||||
|
||||
LinkManager.open();
|
||||
LinkManager.open(LinkManager.LinkStateListener.VOID);
|
||||
|
||||
LinkManager.engineState.registerStringValueAction(EngineState.RUS_EFI_VERSION_TAG, new EngineState.ValueCallback<String>() {
|
||||
@Override
|
||||
|
|
|
@ -18,7 +18,7 @@ import static com.romraider.editor.ecu.ECUEditorManager.getECUEditor;
|
|||
* 3/6/2015
|
||||
*/
|
||||
public class RomRaiderWrapper {
|
||||
private static final String DEFINITION_FILE = "..\\firmware\\integration\\rusefi.xml";
|
||||
private static final String DEFINITION_FILE = "rusefi.xml";
|
||||
|
||||
public static void main(String[] args) {
|
||||
startRomRaider();
|
||||
|
|
|
@ -85,8 +85,8 @@ public class UploadChanges {
|
|||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println(msg);
|
||||
wnd.appendMsg(msg);
|
||||
// System.out.println(msg);
|
||||
// wnd.appendMsg(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package com.rusefi.binaryprotocol;
|
||||
|
||||
import com.romraider.editor.ecu.ECUEditor;
|
||||
import com.romraider.util.SettingsManager;
|
||||
import com.rusefi.ConfigurationImage;
|
||||
import com.rusefi.Logger;
|
||||
import com.rusefi.RomRaiderWrapper;
|
||||
import com.rusefi.UploadChanges;
|
||||
import com.rusefi.io.serial.PortHolder;
|
||||
import jssc.SerialPort;
|
||||
|
@ -35,27 +38,14 @@ public class BinaryProtocolCmd {
|
|||
logger.info("Looks good");
|
||||
bp.switchToBinaryProtocol();
|
||||
|
||||
|
||||
// bp.exchange(new byte[]{'S'});
|
||||
|
||||
|
||||
// bp.sendTextCommand("hello");
|
||||
// bp.sendTextCommand("echo howareyou");
|
||||
|
||||
while (true) {
|
||||
bp.requestText();
|
||||
}
|
||||
|
||||
// bp.readImage(14008);
|
||||
// ConfigurationImage image = bp.getController();
|
||||
bp.readImage(BinaryProtocol.IMAGE_SIZE);
|
||||
ConfigurationImage image = bp.getController();
|
||||
//
|
||||
// image.saveToFile("rusefi_configuration.bin");
|
||||
//
|
||||
// RomRaiderWrapper.startRomRaider();
|
||||
//
|
||||
// ECUEditor.openImage(image.getFileContent(), SettingsManager.getSettings().getEcuDefinitionFiles().elementAt(0),
|
||||
// "rusEfi");
|
||||
|
||||
RomRaiderWrapper.startRomRaider();
|
||||
ECUEditor.openImage(image.getFileContent(), SettingsManager.getSettings().getEcuDefinitionFiles().elementAt(0),
|
||||
"rusEfi");
|
||||
}
|
||||
|
||||
public static void scheduleBurn(ConfigurationImage newVersion) {
|
||||
|
|
Loading…
Reference in New Issue