Initial intested support for pulling maps from the utec.

git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@516 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
Tgui 2007-02-14 03:26:08 +00:00
parent 4ac3ced77f
commit 4108c5a157
8 changed files with 188 additions and 37 deletions

View File

@ -6,6 +6,7 @@ import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import enginuity.logger.utec.commEvent.*;
import enginuity.logger.utec.mapData.GetMapFromUtecListener;
import enginuity.logger.utec.mapData.UtecMapData;
@ -34,6 +35,8 @@ public class UtecControl implements SerialPortEventListener{
//Data from UTEC
//private JTextArea messageAreaIn;
private GetMapFromUtecListener getMapFromUtecListener = null;
// Parameters used to define serial connection
public SerialParameters parameters = new SerialParameters();
@ -80,6 +83,7 @@ public class UtecControl implements SerialPortEventListener{
open = false;
}
/**
* Get UTEC to send logger data data
*
@ -112,17 +116,23 @@ public class UtecControl implements SerialPortEventListener{
*
* @param mapNumber
*/
public void pullMapData(int mapNumber){
// Put utec into a known state
this.resetUtec();
public void pullMapData(int mapNumber, GetMapFromUtecListener listener){
// Check bounds of map requested
if(mapNumber < 1 || mapNumber > 5){
return;
}
// Null out any previously loaded map
this.currentMap = null;
// Who will get this map in the end?
this.getMapFromUtecListener = listener;
// Setup map transfer prep state
this.isMapFromUtecPrep = true;
this.isMapFromUtec = false;
// Reset the UTEC
this.resetUtec();
@ -380,6 +390,7 @@ public class UtecControl implements SerialPortEventListener{
while (newData != -1) {
try {
newData = inputFromUtecStream.read();
if (newData == -1) {
break;
}
@ -388,6 +399,8 @@ public class UtecControl implements SerialPortEventListener{
} else {
inputBuffer.append((char) newData);
}
} catch (IOException ex) {
System.err.println(ex);
return;
@ -408,11 +421,17 @@ public class UtecControl implements SerialPortEventListener{
// 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);
}
}
}

View File

@ -12,13 +12,13 @@ import java.awt.event.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Enumeration;
import java.util.*;
//import javax.comm.CommPortIdentifier
import gnu.io.*;
import javax.swing.*;
import enginuity.logger.utec.gui.realtimeData.*;
import enginuity.logger.utec.mapData.GetMapFromUtecListener;
import enginuity.logger.utec.comm.*;
/**
* @author emorgan
@ -26,7 +26,7 @@ import enginuity.logger.utec.comm.*;
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class CommInterface{
public class UtecInterface{
//Store string vector of known system comm ports
private static Vector portChoices = listPortChoices();
@ -34,17 +34,21 @@ public class CommInterface{
private static SerialParameters parameters = new SerialParameters();
//Actual connection entity
private static UtecControl connection = new UtecControl(parameters);
private static UtecControl utecControl = new UtecControl(parameters);
public static boolean ISOPEN = connection.isOpen();
public static boolean ISOPEN = utecControl.isOpen();
public static Vector getPortsVector(){
return portChoices;
}
public static String getPortChoiceUsed(){
return connection.parameters.getPortName();
return utecControl.parameters.getPortName();
}
public static void getMap(int mapNumber, GetMapFromUtecListener listener){
utecControl.pullMapData(mapNumber, listener);
}
/**
@ -53,8 +57,13 @@ public class CommInterface{
* @param portName
*/
public static void openConnection(){
if(utecControl.isOpen()){
System.out.println("Port is already open.");
return;
}
//No port yet chosen
if(connection.parameters.getPortName().equalsIgnoreCase("")){
if(utecControl.parameters.getPortName().equalsIgnoreCase("")){
System.err.println("No Port Yet Chosen, nothing to open");
return;
}
@ -69,7 +78,7 @@ public class CommInterface{
//Attempt to make connection
try{
connection.openConnection();
utecControl.openConnection();
}catch(SerialConnectionException e){
System.err.println("Error opening serial port connection");
e.printStackTrace();
@ -81,11 +90,11 @@ public class CommInterface{
}
public static void closeConnection(){
connection.closeConnection();
utecControl.closeConnection();
}
public static void setPortChoice(String port){
connection.parameters.setPortName(port);
utecControl.parameters.setPortName(port);
}
/**
@ -93,7 +102,7 @@ public class CommInterface{
*
*/
public static void resetUtec(){
connection.resetUtec();
utecControl.resetUtec();
}
/**
@ -101,7 +110,7 @@ public class CommInterface{
*
*/
public static void startDataLogFromUtec(){
connection.startLoggerDataFlow();
utecControl.startLoggerDataFlow();
}
@ -110,12 +119,12 @@ public class CommInterface{
* @param o
*/
public static void addListener(Object o){
if(connection == null){
System.err.println("No Serial Connection defined yet.. DIZZoGG!");
if(utecControl == null){
System.err.println("No Serial Connection defined yet.");
return;
}
connection.addListener(o);
utecControl.addListener(o);
}
/**

View File

@ -16,13 +16,15 @@ import java.awt.*;
import enginuity.Settings;
import enginuity.logger.utec.gui.realtimeData.*;
import enginuity.logger.utec.gui.bottomControl.*;
import enginuity.logger.utec.mapData.GetMapFromUtecListener;
import enginuity.logger.utec.mapData.UtecMapData;
import enginuity.tts.VoiceThread;
import enginuity.logger.utec.commInterface.CommInterface;
import enginuity.logger.utec.commInterface.UtecInterface;
/**
* @author botman
*/
public class JutecGUI extends JFrame implements ActionListener{
public class JutecGUI extends JFrame implements ActionListener, GetMapFromUtecListener{
//Top level desktop pane
public JLayeredPane desktop = null;
@ -43,11 +45,20 @@ public class JutecGUI extends JFrame implements ActionListener{
//FileMenu Items
public JMenuItem saveItem = new JMenuItem("Save");
public JMenuItem saveItem = new JMenuItem("Save Log");
public JMenuItem saveMapItem = new JMenuItem("Save Map To File");
public JMenuItem exitItem = new JMenuItem("Exit");
public JMenuItem loadMapOne = new JMenuItem("Load Map #1");
public JMenuItem loadMapTwo = new JMenuItem("Load Map #2");
public JMenuItem loadMapThree = new JMenuItem("Load Map #3");
public JMenuItem loadMapFour = new JMenuItem("Load Map #4");
public JMenuItem loadMapFive = new JMenuItem("Load Map #5");
private static JutecGUI instance = null;
private UtecMapData currentMap = null;
public static JutecGUI getInstance(){
return instance;
}
@ -75,7 +86,7 @@ public class JutecGUI extends JFrame implements ActionListener{
System.out.println("JUTEC Exiting");
//Use interface to close the connecetion to the Utec
CommInterface.closeConnection();
UtecInterface.closeConnection();
}
});
@ -92,19 +103,34 @@ public class JutecGUI extends JFrame implements ActionListener{
// Define the menu system
JMenu fileMenu = new JMenu("File");
saveItem.addActionListener(this);
saveMapItem.addActionListener(this);
exitItem.addActionListener(this);
fileMenu.add(saveItem);
fileMenu.add(saveMapItem);
fileMenu.add(exitItem);
menuBar.add(fileMenu);
JMenu getMapsMenu = new JMenu("Load Map");
loadMapOne.addActionListener(this);
loadMapTwo.addActionListener(this);
loadMapThree.addActionListener(this);
loadMapFour.addActionListener(this);
loadMapFive.addActionListener(this);
getMapsMenu.add(loadMapOne);
getMapsMenu.add(loadMapTwo);
getMapsMenu.add(loadMapThree);
getMapsMenu.add(loadMapFour);
getMapsMenu.add(loadMapFive);
menuBar.add(getMapsMenu);
//----------------------------------
//Add a menu item for comm port selection
//----------------------------------
JMenu portsMenu =new JMenu("Ports");
//Gather list of ports from interface
Vector portsVector =CommInterface.getPortsVector();
Vector portsVector =UtecInterface.getPortsVector();
Iterator portsIterator = portsVector.iterator();
int counter = 0;
@ -118,7 +144,7 @@ public class JutecGUI extends JFrame implements ActionListener{
portsMenu.add(item);
if(counter == 1){
defaultPort = theName;
CommInterface.setPortChoice(defaultPort);
UtecInterface.setPortChoice(defaultPort);
}
}
menuBar.add(portsMenu);
@ -176,7 +202,7 @@ public class JutecGUI extends JFrame implements ActionListener{
}
//Start Capture
else if (cmd.equals("Save")) {
else if (cmd.equals("Save Log")) {
String saveFileName = null;
System.out.println("Save action occuring");
fileChosen = fileChooser.showSaveDialog(this);
@ -199,10 +225,58 @@ public class JutecGUI extends JFrame implements ActionListener{
}
else if (cmd.equals("Save Map To File")) {
System.out.println("Saving map to file.");
if(this.currentMap != null){
String saveFileName = null;
System.out.println("Save map now.");
fileChosen = fileChooser.showSaveDialog(this);
if(fileChosen == JFileChooser.APPROVE_OPTION)
{
saveFileName = fileChooser.getSelectedFile().getPath();
this.currentMap.writeMapToFile(saveFileName);
}
}else{
System.out.println("Map is null.");
}
}
else if (cmd.equals("Load Map #1")) {
System.out.println("Starting to get map 1");
UtecInterface.openConnection();
UtecInterface.getMap(1, this);
}
else if (cmd.equals("Load Map #2")) {
System.out.println("Starting to get map 2");
UtecInterface.openConnection();
UtecInterface.getMap(2, this);
}
else if (cmd.equals("Load Map #3")) {
System.out.println("Starting to get map 3");
UtecInterface.openConnection();
UtecInterface.getMap(3, this);
}
else if (cmd.equals("Load Map #4")) {
System.out.println("Starting to get map 4");
UtecInterface.openConnection();
UtecInterface.getMap(4, this);
}
else if (cmd.equals("Load Map #5")) {
System.out.println("Starting to get map 5");
UtecInterface.openConnection();
UtecInterface.getMap(5, this);
}
//Stop Capture
else if (cmd.equals("Exit")) {
//Use interface to finally close the connection to the Utec
CommInterface.closeConnection();
UtecInterface.closeConnection();
System.out.println("Exit action occuring");
//Close out the application
@ -218,7 +292,7 @@ public class JutecGUI extends JFrame implements ActionListener{
String portChoice = theItem.getName();
System.out.println("Port chosen: "+portChoice);
currentPort = portChoice;
CommInterface.setPortChoice(currentPort);
UtecInterface.setPortChoice(currentPort);
bottomPanel.setEnabled(true);
//Notify the infoPane of the current port choice
//infoPane.setPort(currentPort);
@ -244,4 +318,9 @@ public class JutecGUI extends JFrame implements ActionListener{
application.setVisible(true);
}
public void mapRetrieved(UtecMapData theMap) {
System.out.println("Got a map from the utec:"+theMap.getMapName());
this.currentMap = theMap;
}
}

View File

@ -8,7 +8,7 @@ package enginuity.logger.utec.gui.bottomControl;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import enginuity.logger.utec.commInterface.CommInterface;
import enginuity.logger.utec.commInterface.UtecInterface;
import enginuity.logger.utec.gui.JutecGUI;
import enginuity.logger.utec.commEvent.*;
@ -99,7 +99,7 @@ public class BottomUtecControl extends JPanel implements ActionListener, CommLis
this.add(utecOutTextScroll);
//Make this panel listen for comm events
CommInterface.addListener(this);
UtecInterface.addListener(this);
}
/**
@ -111,7 +111,7 @@ public class BottomUtecControl extends JPanel implements ActionListener, CommLis
//Open Port
if (cmd.equals("OPEN PORT")) {
System.out.println("Opening connection to defined port: "+CommInterface.getPortChoiceUsed());
System.out.println("Opening connection to defined port: "+UtecInterface.getPortChoiceUsed());
//Don't allow use after first press, and until after close port has been pressed
openButton.setEnabled(false);
@ -120,7 +120,7 @@ public class BottomUtecControl extends JPanel implements ActionListener, CommLis
stopButton.setEnabled(false);
//Use interface to open connection
CommInterface.openConnection();
UtecInterface.openConnection();
//VoiceThread vc = new VoiceThread("open port");
//vc.start();
@ -131,7 +131,7 @@ public class BottomUtecControl extends JPanel implements ActionListener, CommLis
System.out.println("Closing connection to defined port");
//Use interface to close the connection to the Utec
CommInterface.closeConnection();
UtecInterface.closeConnection();
//Set button states
openButton.setEnabled(true);
@ -148,7 +148,7 @@ public class BottomUtecControl extends JPanel implements ActionListener, CommLis
System.out.println("Starting data capture from the UTEC");
//Use interface to pull logging data from the Utec
CommInterface.startDataLogFromUtec();
UtecInterface.startDataLogFromUtec();
//Set button states
startButton.setEnabled(false);
@ -168,7 +168,7 @@ public class BottomUtecControl extends JPanel implements ActionListener, CommLis
System.out.println("Stopping data capture from the UTEC");
//Use interface to reset the state of the Utec
CommInterface.resetUtec();
UtecInterface.resetUtec();
//Set button states
startButton.setEnabled(true);

View File

@ -7,7 +7,7 @@ import javax.swing.*;
import enginuity.logger.utec.gui.bottomControl.*;
import enginuity.tts.VoiceThread;
import enginuity.logger.utec.commEvent.*;
import enginuity.logger.utec.commInterface.CommInterface;
import enginuity.logger.utec.commInterface.UtecInterface;
/**
* @author botman
@ -37,7 +37,7 @@ public class RealTimeData extends JComponent implements CommListener{
//Constructor
public RealTimeData() {
CommInterface.addListener(this);
UtecInterface.addListener(this);
}
/**
@ -45,7 +45,7 @@ public class RealTimeData extends JComponent implements CommListener{
* @param portChoice
*/
public void setPort(String portChoice) {
CommInterface.setPortChoice(portChoice);
UtecInterface.setPortChoice(portChoice);
}
public void paint(Graphics g) {

View File

@ -0,0 +1,5 @@
package enginuity.logger.utec.mapData;
public interface GetMapFromUtecListener {
public void mapRetrieved(UtecMapData theMap);
}

View File

@ -0,0 +1,5 @@
package enginuity.logger.utec.mapData;
public interface SaveMapToUtecListener {
public void mapSaved(boolean isSaved);
}

View File

@ -419,4 +419,38 @@ public class UtecMapData {
} catch (IOException e) {
}
}
// Misc getters and setters.
public double[][] getBoostMap() {
return boostMap;
}
public void setBoostMap(double[][] boostMap) {
this.boostMap = boostMap;
}
public double[][] getFuelMap() {
return fuelMap;
}
public void setFuelMap(double[][] fuelMap) {
this.fuelMap = fuelMap;
}
public double[][] getTimingMap() {
return timingMap;
}
public void setTimingMap(double[][] timingMap) {
this.timingMap = timingMap;
}
public String getMapComment() {
return mapComment;
}
public String getMapName() {
return mapName;
}
}