Commit d6f10450 by tuomari

Lisätty esimerkkisofta javan sarjaportista (RemoteRfidReader) ja siirretty kaikk…

…i vanhat softat 'muutSoftat' hakemiston alle.

git-svn-id: https://dev.intra.insomnia.fi/svn/trunk@4 8cf89bec-f6a3-4178-919f-364fb3449fe5
1 parent 20a1ba4d
Showing with 518 additions and 0 deletions
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="/ZyxelRunner/lib/slf4j-api-1.5.8.jar"/>
<classpathentry exported="true" kind="lib" path="/ZyxelRunner/lib/slf4j-simple-1.5.8.jar"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.5.0 (MacOS X Default)"/>
<classpathentry exported="true" kind="lib" path="lib/RXTXcomm.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RemoteRfid</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>
#Thu Sep 10 11:52:05 EEST 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5
#Wed Sep 02 15:39:01 EEST 2009
eclipse.preferences.version=1
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="RemoteRfid">
<wb-resource deploy-path="/" source-path="/src"/>
</wb-module>
</project-modules>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="jst.java"/>
<fixed facet="jst.utility"/>
<installed facet="jst.utility" version="1.0"/>
<installed facet="jst.java" version="5.0"/>
</faceted-project>
grant {
permission java.security.AllPermission;
};
\ No newline at end of file
No preview for this file type
grant {
permission java.security.AllPermission;
};
\ No newline at end of file
package org.streamparty.remoterfid;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Cashier extends javax.swing.JPanel {
private static final Logger logger = LoggerFactory.getLogger(Cashier.class);
private String myName;
private RemoteRfidClient myRemote;
public Cashier() {
super();
JButton close = new JButton("Close");
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
JPanel paneeli = new JPanel(new GridLayout(0, 1));
paneeli.add(close);
paneeli.setVisible(true);
this.add(paneeli);
this.setVisible(true);
try {
logger.debug("Creating Port selector");
new SelectPort(this);
} catch (java.lang.UnsatisfiedLinkError e) {
logger.warn("RXTX library error", e);
throw e;
}
try {
while (true) {
RfidAction inst = RfidAction.getInstance();
if (inst != null) {
String tag = inst.listenPort();
RemoteRfidClient remoteClient;
try {
remoteClient = getRemoteClient();
logger.info("Found tag {}", tag);
if (remoteClient != null) {
remoteClient.foundTag(myName, tag);
}
} catch (Throwable t) {
logger.warn("Caught exception while executing remote command!", t);
myRemote = null;
}
}
Thread.sleep(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private RemoteRfidClient getRemoteClient() {
if (myRemote == null) {
try {
Registry registry = LocateRegistry.getRegistry("streamparty.lan", RemoteRfidClient.RMI_PORT);
myRemote = (RemoteRfidClient) registry.lookup(RemoteRfidClient.REMOTE_DESCRIPTOR);
logger.info("Created remote listener {}",myRemote);
} catch (RemoteException e1) {
myRemote = null;
e1.printStackTrace();
} catch (NotBoundException e) {
myRemote = null;
e.printStackTrace();
}
}
return myRemote;
}
public JMenuBar menuBar;
public JToolBar toolBar;
/**
*
*/
private static final long serialVersionUID = 1197345710866765672L;
public static void main(String[] vars) {
logger.debug("Libpath " + System.getProperty("java.library.path"));
JFrame frame = new JFrame("Stream cashier software");
frame.setSize(400, 400);
frame.setLocation(300, 200);
frame.setVisible(true);
Cashier cashier = new Cashier();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setJMenuBar(cashier.menuBar);
// frame.getContentPane().add(cashier.toolBar);
frame.getContentPane().add(cashier);
logger.debug("Frame set visible");
frame.validate();
return;
}
public void setReaderName(String text) {
myName = text;
}
}
package org.streamparty.remoterfid;
public abstract class PortListener {
public abstract void portIdentifier(RfidAction rfidParser);
}
package org.streamparty.remoterfid;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface RemoteRfidClient extends Remote{
static final int RMI_PORT = 54291;
static final String REMOTE_DESCRIPTOR = "StreampartyRfidReaderListener";
void foundTag(String name, String tag) throws RemoteException;
}
package org.streamparty.remoterfid;
import gnu.io.CommPortIdentifier;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import gnu.io.UnsupportedCommOperationException;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RfidAction {
private SerialPort opened;
private InputStream istream;
private OutputStream ostream;
private static final Logger logger = LoggerFactory.getLogger(RfidAction.class);
private static RfidAction thisElement = null;
public static RfidAction getInstance() {
return thisElement;
}
private RfidAction(CommPortIdentifier portId) {
try {
logger.debug("Opening port " + portId.getName());
opened = (SerialPort) portId.open("Stream cashier", 100);
opened.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
istream = opened.getInputStream();
ostream = opened.getOutputStream();
} catch (PortInUseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedCommOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String listenPort() {
// Tyhjennetn mahdollinen bufferi
logger.info("Tyhjennetn bufferi");
try {
while (istream.available() != 0) {
readChar();
}
} catch (IOException e) {
}
logger.info("Starting to read");
String tag = "";
// logger.debug((int)'\n');
try {
logger.info("Starting read loop");
JButton close = new JButton("Close");
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
JDialog readingDiag = new JDialog();
JPanel readingLabel = new JPanel(new GridLayout(1, 1));
readingLabel.add(new JLabel("Insert tag"));
readingDiag.add(readingLabel);
readingDiag.add(close);
// readingDiag.setAlwaysOnTop(true);
readingDiag.setSize(200, 200);
readingDiag.setVisible(true);
// JButton okLabelButton = new JButton("Ok");
/*
* okLabelButton.addActionListener(new ActionListener(){ public void
* actionPerformed(ActionEvent arg0) {
* ((JDialog)((JPanel)((JButton)arg0
* .getSource()).getParent()).getParent()).dispose(); }});
*/
while (true) {
if (opened.isCTS()) {
ostream.write('U');
logger.info("Wrote U to reader");
Thread.sleep(300);
if (istream.available() < 1) {
logger.info("istream size < 1");
continue;
}
String rresponse = Integer.toHexString(istream.read());
logger.info("rresponse: " + rresponse);
if (rresponse.equals("86") || rresponse.toUpperCase().equals("A6")) {
logger.info("Found valid code");
List<String> hexVals = new ArrayList<String>();
Collections.reverse(hexVals);
while (istream.available() > 0) {
String val = Integer.toHexString(istream.read());
if (val.length() < 2) {
val = "0" + val;
}
hexVals.add(val.toUpperCase());
}
hexVals.add("00");
Collections.reverse(hexVals);
Iterator<String> iter = hexVals.iterator();
tag = "";
while (iter.hasNext()) {
tag += iter.next();
}
readingDiag.dispose();
break;
}
} else {
// logger.info("CTS not open. waiting...");
// Thread.sleep(50);
}
}
} catch (IOException e) {
logger.warn("Tag reading error: ", e);
} catch (InterruptedException e) {
logger.info("Tag reading interrupted ", e);
}
logger.debug("Read tag " + tag);
return tag.trim();
}
private int readChar() {
int merkki = -1;
try {
if (istream.available() > 0) {
merkki = istream.read();
}
} catch (IOException e) {
logger.debug("Char reading error", e);
}
return merkki;
}
public static RfidAction init(CommPortIdentifier portId) {
logger.info("Initializing rfid reader for port: " + portId.getName());
thisElement = new RfidAction(portId);
return thisElement;
}
}
package org.streamparty.remoterfid;
import gnu.io.CommPortIdentifier;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SelectPort extends JDialog {
/**
*
*/
private static final long serialVersionUID = 433109152542158881L;
JList lista;
Set<PortListener> portListeners;
private JTextField readerName;
private Cashier cashier;
private static final Logger logger = LoggerFactory.getLogger(SelectPort.class);
public SelectPort(Cashier c) {
super();
cashier = c;
this.setSize(200, 400);
this.requestFocus(true);
setLocation(400, 300);
//setModalityType(Dialog.DEFAULT_MODALITY_TYPE);
portListeners = new HashSet<PortListener>();
try {
logger.debug("Getting serial port list");
Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier portId = null;
Vector<String> portit = new Vector<String>();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
portit.add(portId.getName());
}
}
lista = new JList(portit);
} catch (UnsatisfiedLinkError e) {
logger.debug(e.getMessage());
logger.debug("wtf: ", e);
throw e;
}
JPanel paneeli = new JPanel(new GridLayout(0, 1));
readerName = new javax.swing.JTextField();
this.getContentPane().add(paneeli);
paneeli.add(readerName);
paneeli.add(lista);
JButton nappi = new JButton("Select");
nappi.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String selectedValue = lista.getSelectedValue().toString();
logger.debug("Select port button pushed");
Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier portId = null;
boolean done = false;
while (portList.hasMoreElements() && !done) {
portId = (CommPortIdentifier) portList.nextElement();
logger.info("Looping through elements {}", portId.getName());
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL && portId.getName().equals(selectedValue)) {
RfidAction rfidParser = RfidAction.init(portId);
logger.info("Setting reader name to {}", readerName.getText());
cashier.setReaderName(readerName.getText());
Iterator<PortListener> loop = portListeners.iterator();
while (loop.hasNext()) {
logger.debug("Setting port to listeners");
loop.next().portIdentifier(rfidParser);
}
portListeners.clear();
dispose();
done = true;
}
}
}
});
paneeli.add(nappi);
JButton close = new JButton("Close");
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
paneeli.add(close);
paneeli.setVisible(true);
this.setVisible(true);
}
}
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!