mirror of https://github.com/rusefi/RomRaider.git
auto-refresh added to serial port list
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@264 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
32f4d12059
commit
081a2373b9
|
@ -5,11 +5,13 @@ import enginuity.logger.definition.EcuDataLoader;
|
|||
import enginuity.logger.definition.EcuDataLoaderImpl;
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuSwitch;
|
||||
import enginuity.logger.io.serial.SerialPortRefresher;
|
||||
import enginuity.logger.ui.LoggerDataTableModel;
|
||||
import enginuity.logger.ui.MessageListener;
|
||||
import enginuity.logger.ui.ParameterListTableModel;
|
||||
import enginuity.logger.ui.ParameterRegistrationBroker;
|
||||
import enginuity.logger.ui.ParameterRegistrationBrokerImpl;
|
||||
import enginuity.logger.ui.SerialPortComboBox;
|
||||
import enginuity.logger.ui.handler.DashboardUpdateHandler;
|
||||
import enginuity.logger.ui.handler.DataUpdateHandlerManager;
|
||||
import enginuity.logger.ui.handler.DataUpdateHandlerManagerImpl;
|
||||
|
@ -44,7 +46,6 @@ TODO: finish dashboard tab
|
|||
TODO: add configuration screen (log file destination, etc)
|
||||
TODO: add user definable addresses
|
||||
TODO: Clean up this class!
|
||||
TODO: Periodically refresh com port list
|
||||
*/
|
||||
|
||||
public final class EcuLogger extends JFrame implements WindowListener, PropertyChangeListener, MessageListener {
|
||||
|
@ -54,7 +55,7 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
private final LoggerController controller = new LoggerControllerImpl(settings, this);
|
||||
private final JLabel statusBarLabel = new JLabel("Enginuity ECU Logger");
|
||||
private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM);
|
||||
private final JComboBox portsComboBox = new JComboBox();
|
||||
private final SerialPortComboBox portsComboBox = new SerialPortComboBox(settings);
|
||||
private final LoggerDataTableModel dataTableModel = new LoggerDataTableModel();
|
||||
private final JPanel graphPanel = new JPanel();
|
||||
private final DataUpdateHandlerManager dataHandlerManager = new DataUpdateHandlerManagerImpl();
|
||||
|
@ -73,6 +74,9 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
public EcuLogger(String title) {
|
||||
super(title);
|
||||
|
||||
// start port list refresher thread
|
||||
startPortRefresherThread();
|
||||
|
||||
// setup the user interface
|
||||
initUserInterface();
|
||||
|
||||
|
@ -84,6 +88,12 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
|
||||
}
|
||||
|
||||
private void startPortRefresherThread() {
|
||||
Thread portRefresherThread = new Thread(new SerialPortRefresher(portsComboBox, controller));
|
||||
portRefresherThread.setDaemon(true);
|
||||
portRefresherThread.start();
|
||||
}
|
||||
|
||||
private void initUserInterface() {
|
||||
// setup main panel
|
||||
JPanel mainPanel = new JPanel();
|
||||
|
@ -170,7 +180,6 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
}
|
||||
|
||||
private JComboBox buildPortsComboBox() {
|
||||
refreshPortsComboBox();
|
||||
portsComboBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
settings.setLoggerPort((String) portsComboBox.getSelectedItem());
|
||||
|
@ -182,14 +191,6 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
return portsComboBox;
|
||||
}
|
||||
|
||||
private void refreshPortsComboBox() {
|
||||
List<String> ports = controller.listSerialPorts();
|
||||
for (String port : ports) {
|
||||
portsComboBox.addItem(port);
|
||||
}
|
||||
settings.setLoggerPort((String) portsComboBox.getSelectedItem());
|
||||
}
|
||||
|
||||
private JButton buildStartButton() {
|
||||
JButton startButton = new JButton("Start");
|
||||
startButton.addActionListener(new ActionListener() {
|
||||
|
|
|
@ -3,11 +3,11 @@ package enginuity.logger;
|
|||
import enginuity.logger.definition.EcuData;
|
||||
import enginuity.logger.query.LoggerCallback;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface LoggerController {
|
||||
|
||||
List<String> listSerialPorts();
|
||||
Set<String> listSerialPorts();
|
||||
|
||||
void addLogger(EcuData ecuData, LoggerCallback callback);
|
||||
|
||||
|
|
|
@ -13,8 +13,9 @@ import enginuity.logger.ui.MessageListener;
|
|||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
import gnu.io.CommPortIdentifier;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public final class LoggerControllerImpl implements LoggerController {
|
||||
private final QueryManager queryManager;
|
||||
|
@ -24,12 +25,15 @@ public final class LoggerControllerImpl implements LoggerController {
|
|||
queryManager = new QueryManagerImpl(txManager, messageListener);
|
||||
}
|
||||
|
||||
public List<String> listSerialPorts() {
|
||||
public Set<String> listSerialPorts() {
|
||||
SerialPortDiscoverer serialPortDiscoverer = new SerialPortDiscovererImpl();
|
||||
List<CommPortIdentifier> portIdentifiers = serialPortDiscoverer.listPorts();
|
||||
List<String> portNames = new ArrayList<String>(portIdentifiers.size());
|
||||
Set<String> portNames = new TreeSet<String>();
|
||||
for (CommPortIdentifier portIdentifier : portIdentifiers) {
|
||||
portNames.add(portIdentifier.getName());
|
||||
String portName = portIdentifier.getName();
|
||||
if (!portNames.contains(portName)) {
|
||||
portNames.add(portName);
|
||||
}
|
||||
}
|
||||
return portNames;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package enginuity.logger.io.serial;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface SerialPortRefreshListener {
|
||||
|
||||
void refreshPortList(Set<String> ports);
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package enginuity.logger.io.serial;
|
||||
|
||||
import enginuity.logger.LoggerController;
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
|
||||
public final class SerialPortRefresher implements Runnable {
|
||||
private SerialPortRefreshListener listener;
|
||||
private LoggerController controller;
|
||||
|
||||
public SerialPortRefresher(SerialPortRefreshListener listener, LoggerController controller) {
|
||||
checkNotNull(listener, controller);
|
||||
this.listener = listener;
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (true) {
|
||||
listener.refreshPortList(controller.listSerialPorts());
|
||||
try {
|
||||
Thread.sleep(15000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,16 +2,12 @@ package enginuity.logger.ui;
|
|||
|
||||
import enginuity.logger.definition.EcuData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ParameterRegistrationBroker {
|
||||
|
||||
void registerEcuParameterForLogging(EcuData ecuData);
|
||||
|
||||
void deregisterEcuParameterFromLogging(EcuData ecuData);
|
||||
|
||||
List<String> listSerialPorts();
|
||||
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
|
|
|
@ -54,11 +54,6 @@ public final class ParameterRegistrationBrokerImpl implements ParameterRegistrat
|
|||
|
||||
}
|
||||
|
||||
public List<String> listSerialPorts() {
|
||||
return controller.listSerialPorts();
|
||||
}
|
||||
|
||||
|
||||
public synchronized void start() {
|
||||
loggerStartTime = System.currentTimeMillis();
|
||||
controller.start();
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import enginuity.Settings;
|
||||
import enginuity.logger.io.serial.SerialPortRefreshListener;
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public final class SerialPortComboBox extends JComboBox implements SerialPortRefreshListener {
|
||||
private final Settings settings;
|
||||
|
||||
public SerialPortComboBox(Settings settings) {
|
||||
checkNotNull(settings);
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public void refreshPortList(Set<String> ports) {
|
||||
checkNotNull(ports);
|
||||
boolean changeDetected = ports.isEmpty() || ports.size() != getItemCount();
|
||||
if (!changeDetected) {
|
||||
for (int i = 0; i < getItemCount(); i++) {
|
||||
String port = (String) getItemAt(i);
|
||||
if (!ports.contains(port)) {
|
||||
changeDetected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!changeDetected) {
|
||||
Set<String> comboPorts = new TreeSet<String>();
|
||||
for (int i = 0; i < getItemCount(); i++) {
|
||||
comboPorts.add((String) getItemAt(i));
|
||||
}
|
||||
for (String port : ports) {
|
||||
if (!comboPorts.contains(port)) {
|
||||
changeDetected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changeDetected) {
|
||||
String selectedPort = (String) getSelectedItem();
|
||||
removeAllItems();
|
||||
if (!ports.isEmpty()) {
|
||||
for (String port : ports) {
|
||||
addItem(port);
|
||||
}
|
||||
if (selectedPort != null) {
|
||||
if (ports.contains(selectedPort)) {
|
||||
setSelectedItem(selectedPort);
|
||||
}
|
||||
settings.setLoggerPort(selectedPort);
|
||||
} else {
|
||||
setSelectedIndex(0);
|
||||
settings.setLoggerPort((String) getItemAt(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue