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