Added initial support for map editing.

git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@521 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
Tgui 2007-02-19 05:34:28 +00:00
parent 637ce32419
commit 2e963a455f
4 changed files with 256 additions and 170 deletions

View File

@ -9,41 +9,39 @@ import enginuity.logger.utec.commEvent.*;
import enginuity.logger.utec.mapData.GetMapFromUtecListener; import enginuity.logger.utec.mapData.GetMapFromUtecListener;
import enginuity.logger.utec.mapData.UtecMapData; import enginuity.logger.utec.mapData.UtecMapData;
/** /**
* Class negotiates data to and from UTEC via the serial port * Class negotiates data to and from UTEC via the serial port
* *
* Please note that at this time ownership issues are not handled. * Please note that at this time ownership issues are not handled. See commented
* See commented out code pertaining to the parent entity * out code pertaining to the parent entity
* *
* @author botman * @author botman
* *
*/ */
//public class SerialConnection implements SerialPortEventListener, // public class SerialConnection implements SerialPortEventListener,
// CommPortOwnershipListener { // CommPortOwnershipListener {
import gnu.io.*; import gnu.io.*;
public class UtecSerialConnection implements SerialPortEventListener{ public class UtecSerialConnection implements SerialPortEventListener {
// Parent object organizing connections to and from UTEC // Parent object organizing connections to and from UTEC
//private JPanel parent; // private JPanel parent;
//Data to UTEC // Data to UTEC
//private JTextArea messageAreaOut; // private JTextArea messageAreaOut;
//Data from UTEC // Data from UTEC
//private JTextArea messageAreaIn; // private JTextArea messageAreaIn;
private GetMapFromUtecListener getMapFromUtecListener = null; private GetMapFromUtecListener getMapFromUtecListener = null;
// Parameters used to define serial connection // Parameters used to define serial connection
public SerialParameters parameters = new SerialParameters(); public SerialParameters parameters = new SerialParameters();
//Data from UTEC // Data from UTEC
private OutputStream outputToUtecStream; private OutputStream outputToUtecStream;
//Data to UTEC // Data to UTEC
private InputStream inputFromUtecStream; private InputStream inputFromUtecStream;
// Handler for keyboard input // Handler for keyboard input
@ -58,14 +56,16 @@ public class UtecSerialConnection implements SerialPortEventListener{
// Defin state of defined comport, open or closed. // Defin state of defined comport, open or closed.
private boolean open; private boolean open;
//Listeners // Listeners
private Vector portListeners = new Vector(); private Vector portListeners = new Vector();
//Define whether or not we are recieving a map from the UTEC // Define whether or not we are recieving a map from the UTEC
private boolean isMapFromUtecPrep = false; private boolean isMapFromUtecPrep = false;
private boolean isMapFromUtec = false; private boolean isMapFromUtec = false;
private UtecMapData currentMap = null; private UtecMapData currentMap = null;
/** /**
* Public constructor * Public constructor
* *
@ -74,112 +74,112 @@ public class UtecSerialConnection implements SerialPortEventListener{
* @param messageAreaOut * @param messageAreaOut
* @param messageAreaIn * @param messageAreaIn
*/ */
//public SerialConnection(JPanel parent, SerialParameters parameters, // public SerialConnection(JPanel parent, SerialParameters parameters,
// TextArea messageAreaOut, TextArea messageAreaIn) { // TextArea messageAreaOut, TextArea messageAreaIn) {
public UtecSerialConnection(SerialParameters parameters) { public UtecSerialConnection(SerialParameters parameters) {
//this.parent = parent; // this.parent = parent;
//this.messageAreaOut = messageAreaOut; // this.messageAreaOut = messageAreaOut;
//this.messageAreaIn = messageAreaIn; // this.messageAreaIn = messageAreaIn;
open = false; open = false;
} }
/** /**
* Get UTEC to send logger data data * Get UTEC to send logger data data
* *
*/ */
public void startLoggerDataFlow(){ public void startLoggerDataFlow() {
System.out.println("Starting data flow from UTEC"); System.out.println("Starting data flow from UTEC");
//OutPut a '!' to start basic data flow from UTEC // OutPut a '!' to start basic data flow from UTEC
this.sendDataToUtec(33); this.sendDataToUtec(33);
} }
/** /**
* Reset UTEC to main screen * Reset UTEC to main screen
* *
*/ */
public void resetUtec(){ public void resetUtec() {
//OutPut 2 ctrl-x to UTEC // OutPut 2 ctrl-x to UTEC
//this.sendDataToUtec('\u0018'); // this.sendDataToUtec('\u0018');
//this.sendDataToUtec('\u0018'); // this.sendDataToUtec('\u0018');
System.out.println("Utec reset called."); System.out.println("Utec reset called.");
this.sendDataToUtec(24); this.sendDataToUtec(24);
this.sendDataToUtec(24); this.sendDataToUtec(24);
this.sendDataToUtec(24); this.sendDataToUtec(24);
} }
/** /**
* Get map data from map number passed in * Get map data from map number passed in
* *
* @param mapNumber * @param mapNumber
*/ */
public void pullMapData(int mapNumber, GetMapFromUtecListener listener){ public void pullMapData(int mapNumber, GetMapFromUtecListener listener) {
System.out.println("UtecControl, getting map:"+mapNumber); System.out.println("UtecControl, getting map:" + mapNumber);
// Check bounds of map requested // Check bounds of map requested
if(mapNumber < 1 || mapNumber > 5){ if (mapNumber < 1 || mapNumber > 5) {
System.err.println("Map selection out of range.");
return; return;
} }
// Null out any previously loaded map // Null out any previously loaded map
this.currentMap = null; this.currentMap = null;
// Who will get this map in the end? // Who will get this map in the end?
this.getMapFromUtecListener = listener; this.getMapFromUtecListener = listener;
// Setup map transfer prep state // Setup map transfer prep state
this.isMapFromUtecPrep = true; this.isMapFromUtecPrep = true;
this.isMapFromUtec = false; this.isMapFromUtec = false;
// Reset the UTEC // Reset the UTEC
this.resetUtec(); this.resetUtec();
// Send an 'e' to enter map menu // Send an 'e' to enter map menu
//this.sendDataToUtec('\u0065'); // this.sendDataToUtec('\u0065');
this.sendDataToUtec('e'); this.sendDataToUtec(101);
System.out.println("Sent an e"); System.out.println("Sent an e");
// Point UTEC menu to the appropriate map // Point UTEC menu to the appropriate map
if(mapNumber == 1){ if (mapNumber == 1) {
//this.sendDataToUtec('\u0021'); // this.sendDataToUtec('\u0021');
this.sendDataToUtec(33); this.sendDataToUtec(33);
System.out.println("Requested Map 1"); System.out.println("Requested Map 1");
} }
if(mapNumber == 2){ if (mapNumber == 2) {
//this.sendDataToUtec('\u0040'); // this.sendDataToUtec('\u0040');
this.sendDataToUtec(64); this.sendDataToUtec(64);
System.out.println("Requested Map 2"); System.out.println("Requested Map 2");
} }
if(mapNumber == 3){ if (mapNumber == 3) {
//this.sendDataToUtec('\u0023'); // this.sendDataToUtec('\u0023');
this.sendDataToUtec(35); this.sendDataToUtec(35);
System.out.println("Requested Map 3"); System.out.println("Requested Map 3");
} }
if(mapNumber == 4){ if (mapNumber == 4) {
//this.sendDataToUtec('\u0024'); // this.sendDataToUtec('\u0024');
this.sendDataToUtec(36); this.sendDataToUtec(36);
System.out.println("Requested Map 4"); System.out.println("Requested Map 4");
} }
if(mapNumber == 5){ if (mapNumber == 5) {
//this.sendDataToUtec('\u0025'); // this.sendDataToUtec('\u0025');
this.sendDataToUtec(37); this.sendDataToUtec(37);
System.out.println("Requested Map 5"); System.out.println("Requested Map 5");
} }
// Write first ctrl-s to init save state // Write first ctrl-s to init save state
//this.sendDataToUtec('\u0013'); // this.sendDataToUtec('\u0013');
this.sendDataToUtec(19); this.sendDataToUtec(19);
System.out.println("Sent crtl-s"); System.out.println("Sent crtl-s");
// Make this class receptive to map transfer // Make this class receptive to map transfer
this.isMapFromUtec = true; this.isMapFromUtec = true;
// No longer map prep // No longer map prep
this.isMapFromUtecPrep = false; this.isMapFromUtecPrep = false;
// Write second ctrl-s to start map data flow // Write second ctrl-s to start map data flow
//this.sendDataToUtec('\u0013'); // this.sendDataToUtec('\u0013');
this.sendDataToUtec(19); this.sendDataToUtec(19);
System.out.println("Sent crtl-s"); System.out.println("Sent crtl-s");
} }
@ -189,25 +189,20 @@ public class UtecSerialConnection implements SerialPortEventListener{
* *
* @param charValue * @param charValue
*/ */
public void sendDataToUtec(int charValue){ public void sendDataToUtec(int charValue) {
/* /*
if(this.sPort == null){ * if(this.sPort == null){ System.err.println("No Port Selected.");
System.err.println("No Port Selected."); * return; }
return; */
}
*/ try {
try{
outputToUtecStream.write(charValue); outputToUtecStream.write(charValue);
} } catch (IOException e) {
catch(IOException e){ System.err.println("Can't send char data to UTEC: " + charValue);
System.err.println("Can't send char data to UTEC: "+charValue);
e.getMessage(); e.getMessage();
} }
} }
/** /**
* Opens a connection to the defined serial port If attempt fails, * Opens a connection to the defined serial port If attempt fails,
* SerialConnectionException is thrown * SerialConnectionException is thrown
@ -216,15 +211,12 @@ public class UtecSerialConnection implements SerialPortEventListener{
*/ */
public void openConnection() throws SerialConnectionException { public void openConnection() throws SerialConnectionException {
/* /*
if(sPort == null){ * if(sPort == null){ System.err.println("No port selected."); return; }
System.err.println("No port selected."); */
return;
}
*/
// Obtain a CommPortIdentifier object for the port you want to open. // Obtain a CommPortIdentifier object for the port you want to open.
try { try {
//System.out.println("PORT: "+parameters.getPortName()); // System.out.println("PORT: "+parameters.getPortName());
portId = CommPortIdentifier.getPortIdentifier(parameters portId = CommPortIdentifier.getPortIdentifier(parameters
.getPortName()); .getPortName());
} catch (NoSuchPortException e) { } catch (NoSuchPortException e) {
@ -240,7 +232,7 @@ public class UtecSerialConnection implements SerialPortEventListener{
sPort = (SerialPort) portId.open("SerialDemo", 30000); sPort = (SerialPort) portId.open("SerialDemo", 30000);
} catch (PortInUseException e) { } catch (PortInUseException e) {
System.err.println("Can't open serial port"); System.err.println("Can't open serial port");
//throw new SerialConnectionException(e.getMessage()); // throw new SerialConnectionException(e.getMessage());
} }
// Set the parameters of the connection. If they won't set, close the // Set the parameters of the connection. If they won't set, close the
@ -267,8 +259,8 @@ public class UtecSerialConnection implements SerialPortEventListener{
// Create a new KeyHandler to respond to key strokes in the // Create a new KeyHandler to respond to key strokes in the
// messageAreaOut. Add the KeyHandler as a keyListener to the // messageAreaOut. Add the KeyHandler as a keyListener to the
// messageAreaOut. // messageAreaOut.
//keyHandler = new KeyHandler(outputToUtecStream); // keyHandler = new KeyHandler(outputToUtecStream);
//messageAreaOut.addKeyListener(keyHandler); // messageAreaOut.addKeyListener(keyHandler);
// Add this object as an event listener for the serial port. // Add this object as an event listener for the serial port.
try { try {
@ -294,7 +286,7 @@ public class UtecSerialConnection implements SerialPortEventListener{
} }
// Add ownership listener to allow ownership event handling. // Add ownership listener to allow ownership event handling.
//portId.addPortOwnershipListener(this); // portId.addPortOwnershipListener(this);
open = true; open = true;
} }
@ -306,7 +298,7 @@ public class UtecSerialConnection implements SerialPortEventListener{
*/ */
public void setConnectionParameters() throws SerialConnectionException { public void setConnectionParameters() throws SerialConnectionException {
if(sPort == null){ if (sPort == null) {
System.err.println("No port selected."); System.err.println("No port selected.");
return; return;
} }
@ -349,12 +341,12 @@ public class UtecSerialConnection implements SerialPortEventListener{
return; return;
} }
System.out.println("Closing connection to the currently targeted port"); System.out.println("Closing connection to the currently targeted port");
//Reset the UTEC first // Reset the UTEC first
resetUtec(); resetUtec();
// Remove the key listener. // Remove the key listener.
//messageAreaOut.removeKeyListener(keyHandler); // messageAreaOut.removeKeyListener(keyHandler);
// Check to make sure sPort has reference to avoid a NPE. // Check to make sure sPort has reference to avoid a NPE.
if (sPort != null) { if (sPort != null) {
@ -370,7 +362,7 @@ public class UtecSerialConnection implements SerialPortEventListener{
sPort.close(); sPort.close();
// Remove the ownership listener. // Remove the ownership listener.
//portId.removePortOwnershipListener(this); // portId.removePortOwnershipListener(this);
} }
open = false; open = false;
@ -392,12 +384,12 @@ public class UtecSerialConnection implements SerialPortEventListener{
return open; return open;
} }
/** /**
* Method adds a class as a listener * Method adds a class as a listener
*
* @param o * @param o
*/ */
public void addListener(Object o){ public void addListener(Object o) {
portListeners.add(o); portListeners.add(o);
} }
@ -420,87 +412,89 @@ public class UtecSerialConnection implements SerialPortEventListener{
// Read data until -1 is returned. If \r is received substitute // Read data until -1 is returned. If \r is received substitute
// \n for correct newline handling. // \n for correct newline handling.
case SerialPortEvent.DATA_AVAILABLE: case SerialPortEvent.DATA_AVAILABLE:
// Output all utec noise to listeners // Append new output to buffer
while (newData != -1) { while (newData != -1) {
try { try {
newData = inputFromUtecStream.read(); newData = inputFromUtecStream.read();
if (newData == -1) { if (newData == -1) {
break; break;
} }
if ('\r' == (char) newData) { if ('\r' == (char) newData) {
inputBuffer.append('\n'); inputBuffer.append('\n');
} else { } else {
inputBuffer.append((char) newData); inputBuffer.append((char) newData);
} }
//inputBuffer.append((char) newData); // inputBuffer.append((char) newData);
} catch (IOException ex) { } catch (IOException ex) {
System.err.println(ex); System.err.println(ex);
return; return;
} }
} }
System.out.println(inputBuffer);
if (this.isMapFromUtecPrep == true) {
//Build new event with buffer data System.out.println("Map Prep State.");
CommEvent commEvent = null;
if(this.isMapFromUtec || this.isMapFromUtecPrep){
// See if we are finally recieving a map from the UTEC
if(this.isMapFromUtec){
System.out.println("Getting the map.");
// If this is the start of map data flow, then create a new map data object
if(this.currentMap == null){
currentMap = new UtecMapData();
}
// Append byte data from the UTEC
this.currentMap.addRawData(newData);
System.out.println("Added:"+(char)newData);
// Detect the end of the map recieving
if(inputBuffer.indexOf("[EOF]") != -1){
this.isMapFromUtecPrep = false;
this.currentMap.populateMapDataStructures();
// Notify listner if available
if(this.getMapFromUtecListener != null){
this.getMapFromUtecListener.mapRetrieved(this.currentMap);
}
}
}
}else{
} }
commEvent = new CommEvent(); else if (this.isMapFromUtec == true) {
commEvent.setLoggerData(new String(inputBuffer)); System.out.println("Map From Utec Data.");
commEvent.setLoggerData(true);
// If this is the start of map data flow, then create a new map
//Send received data to listeners // data object
//if(commEvent != null){ if (this.currentMap == null) {
currentMap = new UtecMapData();
}
// Append byte data from the UTEC
this.currentMap.addRawData(newData);
System.out.println("Added:" + (char) newData);
// Detect the end of the map recieving
if (inputBuffer.indexOf("[EOF]") != -1) {
System.out.println("End of file detected.");
this.isMapFromUtec = false;
this.currentMap.populateMapDataStructures();
// Notify listner if available
if (this.getMapFromUtecListener != null) {
this.getMapFromUtecListener.mapRetrieved(this.currentMap);
}
// Empty out map storage
this.currentMap = null;
}
}
// Logger data
else {
CommEvent commEvent = new CommEvent();
commEvent.setLoggerData(new String(inputBuffer));
commEvent.setLoggerData(true);
Iterator portIterator = portListeners.iterator(); Iterator portIterator = portListeners.iterator();
while(portIterator.hasNext()){ while (portIterator.hasNext()) {
CommListener theListener = (CommListener)portIterator.next(); CommListener theListener = (CommListener) portIterator
.next();
theListener.getCommEvent(commEvent); theListener.getCommEvent(commEvent);
} }
break; break;
//} }
// Ouput to console
System.out.println(inputBuffer);
// If break event append BREAK RECEIVED message. // If break event append BREAK RECEIVED message.
/*
case SerialPortEvent.BI: case SerialPortEvent.BI:
messageAreaIn.append("\n--- BREAK RECEIVED ---\n"); System.out.println("BREAK RECEIVED.");
*/
} }
} }
/** /**
@ -509,13 +503,11 @@ public class UtecSerialConnection implements SerialPortEventListener{
* the port. No action is taken on other types of ownership events. * the port. No action is taken on other types of ownership events.
*/ */
/* /*
public void ownershipChange(int type) { * public void ownershipChange(int type) { if (type ==
if (type == CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED) { * CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED) { PortRequestedDialog
PortRequestedDialog prd = new PortRequestedDialog(parent); * prd = new PortRequestedDialog(parent); } }
} */
}
*/
/** /**
* A class to handle <code>KeyEvent</code> s generated by the * A class to handle <code>KeyEvent</code> s generated by the
* messageAreaOut. When a <code>KeyEvent</code> occurs the * messageAreaOut. When a <code>KeyEvent</code> occurs the
@ -523,7 +515,7 @@ public class UtecSerialConnection implements SerialPortEventListener{
* an <code>int</code> and writen to the <code>OutputStream</code> for * an <code>int</code> and writen to the <code>OutputStream</code> for
* the port. * the port.
*/ */
class KeyHandler extends KeyAdapter { class KeyHandler extends KeyAdapter {
OutputStream toUtec; OutputStream toUtec;
@ -553,5 +545,5 @@ public class UtecSerialConnection implements SerialPortEventListener{
} }
} }
} }
} }

View File

@ -14,6 +14,7 @@ import javax.swing.*;
import java.awt.*; import java.awt.*;
import enginuity.Settings; import enginuity.Settings;
import enginuity.logger.utec.gui.mapTabs.FuelJPanel;
import enginuity.logger.utec.gui.realtimeData.*; import enginuity.logger.utec.gui.realtimeData.*;
import enginuity.logger.utec.gui.bottomControl.*; import enginuity.logger.utec.gui.bottomControl.*;
import enginuity.logger.utec.mapData.GetMapFromUtecListener; import enginuity.logger.utec.mapData.GetMapFromUtecListener;
@ -46,6 +47,12 @@ public class JutecGUI extends JFrame implements ActionListener,
private File selectedFile = null; private File selectedFile = null;
// Tabbed Panes
public JTabbedPane topTabbedPane = new JTabbedPane();
public JTabbedPane timingTabbedPane = new JTabbedPane();
public JTabbedPane fuelTabbedPane = new JTabbedPane();
public JTabbedPane boostTabbedPane = new JTabbedPane();
// FileMenu Items // FileMenu Items
public JMenuItem saveItem = new JMenuItem("Save Log"); public JMenuItem saveItem = new JMenuItem("Save Log");
@ -68,7 +75,6 @@ public class JutecGUI extends JFrame implements ActionListener,
private UtecMapData currentMap = null; private UtecMapData currentMap = null;
// Text input field for sending commands directly to the UTEC // Text input field for sending commands directly to the UTEC
//private JTextArea textInput = new JTextArea();
private JTextField textInput = new JTextField(); private JTextField textInput = new JTextField();
private JLabel utecInputLabel = new JLabel(" Send Commands to UTEC: "); private JLabel utecInputLabel = new JLabel(" Send Commands to UTEC: ");
@ -82,7 +88,7 @@ public class JutecGUI extends JFrame implements ActionListener,
// Main frame // Main frame
// Grid layout with a top and bottom, ie two rows // Grid layout with a top and bottom, ie two rows
super("UTEC Loggers"); super("UTEC Loggers");
this.setSize(800, 620); this.setSize(800, 640);
this.setResizable(false); this.setResizable(false);
this.setDefaultCloseOperation(setDefaultCloseOperation); this.setDefaultCloseOperation(setDefaultCloseOperation);
@ -90,8 +96,7 @@ public class JutecGUI extends JFrame implements ActionListener,
// Voice the welcome message // Voice the welcome message
// ************************* // *************************
VoiceThread vc = new VoiceThread( VoiceThread vc = new VoiceThread("Welcome to you teck logger! Use at your own risk.");
"Welcome to you teck logger! Use at your own risk.");
vc.start(); vc.start();
// Actions to take when window is closing // Actions to take when window is closing
@ -176,8 +181,11 @@ public class JutecGUI extends JFrame implements ActionListener,
bottomPanel = new BottomUtecControl(); bottomPanel = new BottomUtecControl();
JTabbedPane topTabbedPane = new JTabbedPane();
topTabbedPane.add("Graph Data", new RealTimeData()); this.topTabbedPane.add("Graph Data", new RealTimeData());
this.topTabbedPane.add("Timing Data", new JPanel());
this.topTabbedPane.add("Fuel Data", new FuelJPanel());
this.topTabbedPane.add("Boost Data", new JPanel());
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setDividerLocation(440); splitPane.setDividerLocation(440);

View File

@ -0,0 +1,34 @@
package enginuity.logger.utec.gui.mapTabs;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class FuelJPanel extends JPanel{
public FuelJPanel(){
super(new BorderLayout());
init();
}
public void init(){
JTable table = new JTable(new UtecTableModel());
//table.setPreferredScrollableViewportSize(new Dimension(500, 70));
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
//Add the scroll pane to this panel.
this.add(scrollPane, BorderLayout.CENTER);
}
}

View File

@ -0,0 +1,52 @@
package enginuity.logger.utec.gui.mapTabs;
import javax.swing.table.AbstractTableModel;
public class UtecTableModel extends AbstractTableModel {
private String[] columnNames = new String[11];
private double[][] data = new double[11][40];
public UtecTableModel() {
for (int i = 0; i < columnNames.length; i++) {
System.out.println("count: " + i);
columnNames[i] = i + "";
}
}
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return 40;
}
public Object getValueAt(int row, int col) {
return data[col][row];
}
public String getColumnName(int col) {
return columnNames[col];
}
public boolean isCellEditable(int row, int col) {
return true;
}
public void setValueAt(Object value, int row, int col) {
// Set new data in table
double temp = data[col][row];
try{
temp = Double.parseDouble((String)value);
}catch (NumberFormatException e) {
}
data[col][row] = temp;
fireTableCellUpdated(row, col);
}
}