auto-sync

This commit is contained in:
rusEfi 2014-08-29 17:06:31 -05:00
parent d6347a6b53
commit 6930487733
4 changed files with 47 additions and 32 deletions

View File

@ -62,6 +62,7 @@ class PortHolder {
}
try {
// todo: why is this delay here? add a comment
Thread.sleep(200);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
@ -71,6 +72,16 @@ class PortHolder {
this.serialPort = serialPort;
portLock.notifyAll();
}
try {
/**
* 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;
}
@ -106,13 +117,17 @@ class PortHolder {
}
// we are here only when serialPort!=null, that means we have a connection
try {
serialPort.writeString(command + "\r\n");
doWriteCommand(command);
} catch (SerialPortException e) {
throw new IllegalStateException(e);
}
}
}
private void doWriteCommand(String command) throws SerialPortException {
serialPort.writeString(command + "\r\n");
}
public static PortHolder getInstance() {
return instance;
}

View File

@ -3,6 +3,7 @@ package com.irnems.core;
import com.irnems.FileLog;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
@ -22,6 +23,10 @@ public class EngineState {
}
};
public static final String PACKING_DELIMITER = ":";
/**
* If we get this tag we have probably connected to the wrong port
*/
private static final CharSequence TS_PROTOCOL_TAG = "ts_p_al";
private final Object lock = new Object();
static class StringActionPair extends Pair<String, ValueCallback<String>> {
@ -209,6 +214,10 @@ public class EngineState {
*/
public static String unpackString(String message) {
String prefix = "line" + PACKING_DELIMITER;
if (message.contains(TS_PROTOCOL_TAG)) {
JOptionPane.showMessageDialog(null, "Are you sure you are not connected to TS port?");
return null;
}
if (!message.startsWith(prefix)) {
FileLog.MAIN.logLine("EngineState: unexpected header: " + message + " while looking for " + prefix);
return null;

View File

@ -19,7 +19,7 @@ import javax.swing.*;
* @see WavePanel
*/
public class Launcher extends FrameHelper {
public static final int CONSOLE_VERSION = 20140828;
public static final int CONSOLE_VERSION = 20140829;
public static final boolean SHOW_STIMULATOR = true;
public Launcher(String port) {
@ -40,10 +40,10 @@ public class Launcher extends FrameHelper {
// tabbedPane.addTab("ADC", new AdcPanel(new BooleanInputsModel()).createAdcPanel());
if (SHOW_STIMULATOR) {
EcuStimulator stimulator = EcuStimulator.getInstance();
tabbedPane.add("Emulation Map", stimulator.getPanel());
tabbedPane.add("ECU stimulation", stimulator.getPanel());
}
// tabbedPane.addTab("live map adjustment", new Live3DReport().getControl());
tabbedPane.add("MessagesCentral", new MsgPanel(true).getContent());
tabbedPane.add("Messages", new MsgPanel(true).getContent());
tabbedPane.add("Log Viewer", new LogViewer());

View File

@ -1,7 +1,5 @@
package com.rusefi.ui;
import com.rusefi.EcuStimulator;
import com.irnems.Launcher;
import com.irnems.core.EngineTimeListener;
import com.irnems.core.Sensor;
import com.rusefi.ui.widgets.*;
@ -20,7 +18,6 @@ import java.awt.event.ActionListener;
*/
public class RpmPanel {
private RpmControl rpmControl = new RpmControl();
// this label displays real RPM received from ECU
// that's for CKP signal emulation
public final WaveInfoPanel wave0 = new WaveInfoPanel(0);
public final WaveInfoPanel wave1 = new WaveInfoPanel(1);
@ -30,18 +27,6 @@ public class RpmPanel {
rpmControl.setSize(15);
}
private WaveInfoPanel findWavePanel(int index) {
WaveInfoPanel wave;
if (index == 0)
wave = wave0;
else if (index == 1)
wave = wave1;
else
throw new IllegalStateException("unexpected index " + index);
return wave;
}
public JComponent createRpmPanel() {
JPanel controls = createControls();
@ -60,6 +45,25 @@ public class RpmPanel {
// gauges.add(GaugesPanel.createGauge(Sensor.MAF));
startConnectionWatchDog();
JPanel msgPanel = new JPanel(new BorderLayout());
msgPanel.add(new AnyCommand(), BorderLayout.NORTH);
msgPanel.add(new MsgPanel(false).getContent(), BorderLayout.CENTER);
JComponent rpmPanel = new JPanel(new BorderLayout());
rpmPanel.setBorder(BorderFactory.createLineBorder(Color.white));
rpmPanel.add(rpmControl.getContent(), BorderLayout.NORTH);
rpmPanel.add(controls, BorderLayout.WEST);
rpmPanel.add(gauges, BorderLayout.CENTER);
rpmPanel.add(msgPanel, BorderLayout.EAST);
return rpmPanel;
}
private void startConnectionWatchDog() {
final Timer reconnectTimer = new Timer(10000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -75,20 +79,8 @@ public class RpmPanel {
* this timer will reconnect
*/
postponeReconnecting(reconnectTimer);
}
});
JComponent rpmPanel = new JPanel(new BorderLayout());
rpmPanel.setBorder(BorderFactory.createLineBorder(Color.white));
rpmPanel.add(rpmControl.getContent(), BorderLayout.NORTH);
rpmPanel.add(controls, BorderLayout.WEST);
rpmPanel.add(gauges, BorderLayout.CENTER);
MsgPanel msgPanel = new MsgPanel(false);
rpmPanel.add(msgPanel.getContent(), BorderLayout.EAST);
return rpmPanel;
}
private void postponeReconnecting(Timer timer2) {
@ -101,7 +93,6 @@ public class RpmPanel {
controls.add(new RpmCommand(), "grow, wrap");
// controls.add(new PotCommand(0).panel, "grow, wrap");
// controls.add(new PotCommand(1).panel, "grow, wrap");
controls.add(new AnyCommand(), "grow, wrap");
controls.add(new MafCommand(), "grow, wrap");