You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by do...@apache.org on 2007/04/30 14:50:33 UTC

svn commit: r533731 - in /incubator/felix/sandbox/donsez/rxtx.cmd: ./ doc/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/felix/ src/main/java/org/apache/felix/rxtx/ src/main/java/org/apache/felix/rx...

Author: donsez
Date: Mon Apr 30 05:50:32 2007
New Revision: 533731

URL: http://svn.apache.org/viewvc?view=rev&rev=533731
Log:
creation of bundle rxtx.cmd

Added:
    incubator/felix/sandbox/donsez/rxtx.cmd/
    incubator/felix/sandbox/donsez/rxtx.cmd/doc/
    incubator/felix/sandbox/donsez/rxtx.cmd/doc/readme.html   (with props)
    incubator/felix/sandbox/donsez/rxtx.cmd/pom.xml   (with props)
    incubator/felix/sandbox/donsez/rxtx.cmd/src/
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/IOWrapper.java   (with props)
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/Activator.java   (with props)
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/AsciiWrapper.java   (with props)
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/HexString.java   (with props)
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/HexWrapper.java   (with props)
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/RXTXCmdImpl.java   (with props)
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/nmea0183/
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/nmea0183/Nmea0183Wrapper.java   (with props)
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/rxtx/
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/rxtx/sample/
    incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/rxtx/sample/SerialParameters.java

Added: incubator/felix/sandbox/donsez/rxtx.cmd/doc/readme.html
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/donsez/rxtx.cmd/doc/readme.html?view=auto&rev=533731
==============================================================================
--- incubator/felix/sandbox/donsez/rxtx.cmd/doc/readme.html (added)
+++ incubator/felix/sandbox/donsez/rxtx.cmd/doc/readme.html Mon Apr 30 05:50:32 2007
@@ -0,0 +1,135 @@
+<html>
+<head>
+<title>RXTX Command</title>
+</head>
+<body>
+
+<!-- Start of Felix Bundle Documentation -->
+<hr width="100%" size="2">
+<h1><i><a name="rxtxcmd"></a><font color="#0000aa">rxtxcmd.jar</font></i></h1>
+
+<p>
+<b>Description</b><br>
+provides a command to send/receive bytes to/from a serial/parallel port
+<br>For more details on how to use this bundle, refer to the /doc/readme.html file embedded in the bundle jarfile.
+</p>
+
+<p>
+<b>Contributors</b><br>
+<ul>
+<li>Author:Apache Felix Team</a></li>
+</ul>
+</p>
+
+<p>
+<b>License</b><br>
+ASL 2.0<br>
+</p>
+
+<p>
+<b>Services</b><br>
+<ul>
+<li>org.apache.felix.shell.Command</li>
+</ul>
+</p>
+
+<p>
+<b>Properties</b><br>
+<ul>
+<li>None</li>
+</ul>
+</p>
+
+<p><b>Requirements</b><br>
+<li>gnu.io</li>
+</p>
+
+<!-- End of Felix Bundle Documentation -->
+
+<hr width="100%" size="2">
+
+<!-- Start of extra information  -->
+
+</ul>
+</p>
+
+<p id="build">
+<b>Build</b><br>
+<ol>
+<li>build with ant</li>
+</ol>
+</p>
+
+<p id="settings">
+<b>Settings</b><br>
+None
+</p>
+
+<p id="usage">
+<b>Usage</b><br>
+<pre>
+rxtx list                  : list the available ports
+rxtx open &lt;portname&gt; &lt;baudrate&gt; &lt;flowctrlin&gt; &lt;flowctrlout&gt; &lt;databits&gt; &lt;stopbits&gt; &lt;parity&gt;
+               flowctrl=None,Xon/XoffOut,Xon/XoffIn,RTS/CTSIn,RTS/CTSOut
+               databits=5,6,7,8
+               stopbits=1,1.5,2
+               parity=None,Odd,Even
+                           : open a serial port
+rxtx close                 : close the current opened port
+rxtx send &lt;bytes in hexa&gt;  : send message bytes
+rxtx binary                : switch IO in hex
+rxtx ascii                 : switch IO in ascii
+rxtx buffersize &lt;size&gt;     : set IO buffer size
+rxtx sendurl &lt;url&gt;         : send bytes contained at the url
+rxtx logfile &lt;filepath&gt;    : log received bytes in the file
+rxtx iowrapper &lt;classname&gt; : set a wrapper for IO parsing and printing. The class could be exported by a external bundle
+rxtx help                  : display this help</pre>
+</p>
+
+<p id="rundemo">
+<b>Run the demo</b><br>
+To run the demo of this bundle, enter the commands in the OSCAR shell for the script <a href="http://www-adele.imag.fr/users/Didier.Donsez/dev/osgi/script/rxtx.txt">http://www-adele.imag.fr/users/Didier.Donsez/dev/osgi/script/rxtx.txt</a><br>
+</p>
+
+
+<p id="typicalusage">
+<b>Typical Usages</b><br>
+<li>debugging programs using gnu.io</li>
+<li>dump serial port output (GPS, RFID reader, ...)</li>
+</p>
+
+<p id="gateways">
+<b>Tested gateways</b><br>
+<ul>
+<li><a href="http://oscar.objectweb.org">Oscar</a> (done)</li>
+<li>Felix (done)</li>
+<li><a href="http://www.knopflerfish.org">Knopflerfish OSGi</a> (to do)</li>
+</ul>
+</p>
+
+<p id="versions">
+<b>Versions history</b><br>
+<ul>
+<li>0.1.0, April 11, 2005</li>
+<li>0.2.0, February, 14 2006</li>
+</ul>
+</p>
+
+<p id="todo">
+<b>TODO (contributions are welcome)</b><br>
+<ul>
+<li>parameters for the wrapper instanciation</li>
+<li>BufferedCRLFAsciiWrapper (message contains a header with a length field) : parameter (the tail string)</li>
+<li>BufferedHexWrapper (message contains a header with a length field) : parameter size and position and coding (little/big endian) of the field length</li>
+</ul>
+</p>
+
+<p id="links">
+<b>Links</b><br>
+<ul>
+<li><a href="http://www.rxtx.org">RXTX Homepage</a></li>
+</ul>
+</p>
+
+</body>
+</html>

Propchange: incubator/felix/sandbox/donsez/rxtx.cmd/doc/readme.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/donsez/rxtx.cmd/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/donsez/rxtx.cmd/pom.xml?view=auto&rev=533731
==============================================================================
--- incubator/felix/sandbox/donsez/rxtx.cmd/pom.xml (added)
+++ incubator/felix/sandbox/donsez/rxtx.cmd/pom.xml Mon Apr 30 05:50:32 2007
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project>
+	<properties>
+		<repositoryLocation>http://www-adele.imag.fr/users/Didier.Donsez/dev/felix/sandbox/</repositoryLocation>
+		<description>shell command to use the RXTX library./</description>
+	</properties>  
+
+  <parent>
+    <groupId>org.apache.felix</groupId>
+    <artifactId>felix</artifactId>
+    <version>0.9.0-incubator-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>bundle</packaging>
+  <name>Apache Felix RXTX Command</name>
+  <artifactId>org.apache.felix.rxtx.cmd</artifactId>
+  <description>${description}</description>
+  
+  <dependencies>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+    <!--
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.rxtx</artifactId>
+      <version>${pom.version}</version>
+    </dependency> 
+    -->
+    <dependency>
+      <groupId>org.rxtx</groupId>
+      <artifactId>rxtx</artifactId>
+      <version>2.1.7</version>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.shell</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+	  	<!--
+			docs in http://cwiki.apache.org/FELIX/bundle-plugin-for-maven-bnd.html
+			and http://cwiki.apache.org/FELIX/osgi-plugin-for-maven-2.html
+		-->
+		
+            <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+            <Bundle-Description>${description}</Bundle-Description>
+ 
+	    
+            <Export-Package>${pom.artifactId}</Export-Package>
+            <Private-Package>${pom.artifactId}.impl.*,rxtx.*</Private-Package>
+            <Import-Package>*</Import-Package>
+	    
+	    <Bundle-Activator>${pom.artifactId}.impl.Activator</Bundle-Activator>
+	    
+            <Export-Service>org.apache.felix.shell.Command</Export-Service>
+	    
+            <Bundle-DocURL>${repositoryLocation}${pom.artifactId}/index.html</Bundle-DocURL>
+            <Bundle-Url>${repositoryLocation}${pom.artifactId}/${pom.artifactId}-${pom.version}.jar</Bundle-Url>
+            <Bundle-Source>${repositoryLocation}${pom.artifactId}/${pom.artifactId}-${pom.version}-src.jar</Bundle-Source>
+	    
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <!--
+  <repositories>
+    <repository>
+      <id>apache.m2.incubator</id>
+      <name>Apache M2 Incubator Repository</name>
+      <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+    </repository>
+
+  </repositories>
+  <pluginRepositories>
+    <pluginRepository>
+      <id>apache.m2.incubator</id>
+      <name>Apache M2 Incubator Repository</name>
+      <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+    </pluginRepository>
+  </pluginRepositories>
+  -->
+</project>
+

Propchange: incubator/felix/sandbox/donsez/rxtx.cmd/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/IOWrapper.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/IOWrapper.java?view=auto&rev=533731
==============================================================================
--- incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/IOWrapper.java (added)
+++ incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/IOWrapper.java Mon Apr 30 05:50:32 2007
@@ -0,0 +1,34 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * RXTX Command.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+package org.apache.felix.rxtx.cmd;
+
+import java.text.ParseException;
+import java.util.StringTokenizer;
+
+public interface IOWrapper {
+	byte[] parse(String string) throws ParseException;
+	byte[] parse(StringTokenizer st) throws ParseException;
+	String format(byte[] bytes) throws ParseException;
+	String format(byte[] bytes, int offset, int length) throws ParseException;
+}

Propchange: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/IOWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/Activator.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/Activator.java?view=auto&rev=533731
==============================================================================
--- incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/Activator.java (added)
+++ incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/Activator.java Mon Apr 30 05:50:32 2007
@@ -0,0 +1,83 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * RXTX Command.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+
+package org.apache.felix.rxtx.cmd.impl;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.felix.shell.Command;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceRegistration;
+
+
+public class Activator implements BundleActivator {
+	private transient BundleContext m_context = null;
+	private transient Map m_commandServiceRegistration = null;
+
+	public void start(BundleContext context) throws BundleException {
+		m_context = context;
+		m_commandServiceRegistration = new HashMap();
+
+		Dictionary properties=new Hashtable();
+		properties.put("categories",
+			new String[]{ "script" }
+		);
+		
+		Command command=new RXTXCmdImpl(m_context);
+		if(command instanceof BundleActivator)
+			try {
+				((BundleActivator) command).start(m_context);
+			} catch (Exception e) {
+				throw new BundleException("Can not start command \""+command.getName()+"\": ",e);
+			}
+		m_commandServiceRegistration.put(
+			m_context.registerService(
+				Command.class.getName(),
+				command,
+				properties),
+			command
+		);
+	}
+
+	public void stop(BundleContext context) throws BundleException {
+		Iterator iterator=m_commandServiceRegistration.keySet().iterator();
+		while(iterator.hasNext()){
+			ServiceRegistration sr=(ServiceRegistration)iterator.next();
+			sr.unregister();	
+			Command command=(Command)m_commandServiceRegistration.remove(sr);
+			if(command instanceof BundleActivator)
+				try {
+					((BundleActivator) command).stop(m_context);
+				} catch (Exception e) {
+					System.err.println("Can not stop command \""+command.getName()+"\": "+e);
+				}
+		}
+	}
+}

Propchange: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/Activator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/AsciiWrapper.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/AsciiWrapper.java?view=auto&rev=533731
==============================================================================
--- incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/AsciiWrapper.java (added)
+++ incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/AsciiWrapper.java Mon Apr 30 05:50:32 2007
@@ -0,0 +1,96 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * RXTX Command.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+package org.apache.felix.rxtx.cmd.impl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.StringTokenizer;
+
+import org.apache.felix.rxtx.cmd.IOWrapper;
+
+
+public class AsciiWrapper implements IOWrapper {
+
+	private int linesize=16;
+
+	private String separator=" ";
+
+	/**
+	 * @see org.apache.felix.rxtx.cmd.IOWrapper#parse(java.lang.String)
+	 */
+	public byte[] parse(String string) throws ParseException {
+		return string.getBytes();
+	}
+
+	/**
+	 * @see org.apache.felix.rxtx.cmd.IOWrapper#parse(java.util.StringTokenizer)
+	 */
+	
+	public byte[] parse(StringTokenizer st) throws ParseException {
+		int c=0;
+		try {
+			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+			while (st.hasMoreTokens()) {
+				if(c!=0) byteArrayOutputStream.write(separator.getBytes());
+				byteArrayOutputStream.write(st.nextToken().getBytes());
+				c++;
+			}
+			return byteArrayOutputStream.toByteArray();
+		} catch (IOException e) {
+			throw new ParseException(e.toString(),c); 
+		}
+	}
+
+	/**
+	 * @see org.apache.felix.rxtx.cmd.IOWrapper#format(byte[])
+	 */
+	public String format(byte[] bytes) throws ParseException {
+		return new String(bytes);
+	}
+
+	/**
+	 * @see org.apache.felix.rxtx.cmd.IOWrapper#format(byte[], int, int)
+	 */
+	public String format(byte[] bytes, int offset, int length)
+			throws ParseException {
+		return new String(bytes, offset, length);
+	}
+
+	public int getLineSize() {
+		return linesize;
+	}
+
+	public void setLineSize(int linesize) {
+		this.linesize = linesize;
+	}
+
+	public String getSeparator() {
+		return separator;
+	}
+
+	public void setSeparator(String separator) {
+		this.separator = separator;
+	}
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/AsciiWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/HexString.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/HexString.java?view=auto&rev=533731
==============================================================================
--- incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/HexString.java (added)
+++ incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/HexString.java Mon Apr 30 05:50:32 2007
@@ -0,0 +1,117 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * RXTX Command.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+
+package org.apache.felix.rxtx.cmd.impl;
+
+import java.util.StringTokenizer;
+
+public class HexString {
+
+	protected final static String[] hexChars = { "0", "1", "2", "3", "4", "5",
+			"6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };
+
+	/**
+	 * Parse a Hex string
+	 * 
+	 * @param hexString a sequence of 2-symbol hexadecimal numbers
+	 * @return a byte array
+	 * @exception java.lang.NumberFormatException if a number is not a hexadecimal number
+	 * @note : java.lang.Integer.parseInt(String s, int radix) do not verify if
+	 *       symbol is correct !!
+	 * @note : opencard.core.util.HexString.parseHexString(String s) requires
+	 *       fixed space in string
+	 */
+	public static byte[] parseHexString(String hexString)
+			throws java.lang.NumberFormatException {
+
+		StringTokenizer st = new StringTokenizer(hexString);
+		byte[] result = new byte[st.countTokens()];
+		for (int i = 0; st.hasMoreTokens(); i++) {
+			//result[i]=(byte)Integer.parseInt(st.nextToken(),16);
+			char[] ca = (st.nextToken()).toCharArray();
+			if (ca.length != 2) {
+				throw new java.lang.NumberFormatException();
+			}
+			result[i] = (byte) (parseHexChar(ca[0]) * 16 + parseHexChar(ca[1]));
+		}
+		return result;
+	}
+
+	/**
+	 * Parse a radix 16 symbol
+	 * 
+	 * @param c a symbol
+	 * @return a byte
+	 * @exception java.lang.NumberFormatException if c is not a hexadecimal symbol 
+	 * @note : java.lang.Integer.parseInt(String s, int radix) do not verify if
+	 *       symbol is correct !!
+	 */
+	public static byte parseHexChar(char c)
+			throws java.lang.NumberFormatException {
+		if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')
+				|| (c >= 'A' && c <= 'F')) {
+			return (byte) (Character.digit(c, 16));
+		}
+		throw new java.lang.NumberFormatException();
+	}
+
+	/**
+	 * Hexify (ie represents in hexadecimal) a byte array
+	 * 
+	 * @param data the byte array to hexify
+	 * @param offset the offset in the byte array
+	 * @param length the number of bytes to represent
+	 * @param linesize the number of byte per line in the string
+	 * @return a String with Hexadecimal representation of bytes
+	 */
+	public static String hexify(byte[] data, int offset, int length, int linesize) {
+		return hexify(data,offset,length,linesize," ");
+		
+	}
+	
+	public static String hexify(byte[] data, int offset, int length, int linesize, String separator) {
+		if (data == null)
+			return "null";
+
+		StringBuffer out = new StringBuffer(256);
+		int n = 0;
+		int c = 0;
+
+		for (int i = offset; i < data.length && c < length; i++, c++) {
+			if (n > 0)
+				out.append(separator);
+
+			out.append(hexChars[(data[i] >> 4) & 0x0f]);
+			out.append(hexChars[data[i] & 0x0f]);
+
+			if (++n == linesize) {
+				out.append('\n');
+				n = 0;
+			}
+		}
+
+		return out.toString();
+	}
+
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/HexString.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/HexWrapper.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/HexWrapper.java?view=auto&rev=533731
==============================================================================
--- incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/HexWrapper.java (added)
+++ incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/HexWrapper.java Mon Apr 30 05:50:32 2007
@@ -0,0 +1,83 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * RXTX Command.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+
+package org.apache.felix.rxtx.cmd.impl;
+
+import java.text.ParseException;
+import java.util.StringTokenizer;
+
+import org.apache.felix.rxtx.cmd.IOWrapper;
+
+
+public class HexWrapper implements IOWrapper {
+
+	private int linesize=16;
+
+	/**
+	 * @see org.apache.felix.rxtx.cmd.IOWrapper#parse(java.lang.String)
+	 */
+	public byte[] parse(String string) throws ParseException {
+		return parse(new StringTokenizer(string));
+	}
+
+	/**
+	 * @see org.apache.felix.rxtx.cmd.IOWrapper#parse(java.util.StringTokenizer)
+	 */
+	public byte[] parse(StringTokenizer st) throws ParseException {
+		byte[] msg = new byte[st.countTokens()];
+		for (int i = 0; st.hasMoreTokens(); i++) {
+			//msg[i]=(byte)Integer.parseInt(st.nextToken(),16);
+			char[] ca = (st.nextToken()).toCharArray();
+			if (ca.length != 2) {
+				throw new ParseException("Bad number format",i);
+			}
+			msg[i] = (byte) (
+						HexString.parseHexChar(ca[0]) * 16
+					+ HexString.parseHexChar(ca[1])
+					);
+		}
+		return msg;
+	}
+
+	/**
+	 * @see org.apache.felix.rxtx.cmd.IOWrapper#format(byte[])
+	 */
+	public String format(byte[] bytes) throws ParseException {
+		return HexString.hexify(bytes,0,bytes.length,linesize=16);
+	}
+
+	/**
+	 * @see org.apache.felix.rxtx.cmd.IOWrapper#format(byte[], int, int)
+	 */
+	public String format(byte[] bytes, int offset, int length) throws ParseException {
+		return HexString.hexify(bytes,offset,length,linesize);
+	}
+
+	public int getLineSize() {
+		return linesize;
+	}
+	public void setLineSize(int linesize) {
+		this.linesize = linesize;
+	}
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/HexWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/RXTXCmdImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/RXTXCmdImpl.java?view=auto&rev=533731
==============================================================================
--- incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/RXTXCmdImpl.java (added)
+++ incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/RXTXCmdImpl.java Mon Apr 30 05:50:32 2007
@@ -0,0 +1,484 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * RXTX Command.
+ * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+ */
+package org.apache.felix.rxtx.cmd.impl;
+
+import gnu.io.CommPortIdentifier;
+import gnu.io.NoSuchPortException;
+import gnu.io.PortInUseException;
+import gnu.io.SerialPort;
+import gnu.io.SerialPortEvent;
+import gnu.io.SerialPortEventListener;
+import gnu.io.UnsupportedCommOperationException;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.text.ParseException;
+import java.util.Enumeration;
+import java.util.StringTokenizer;
+import java.util.TooManyListenersException;
+
+
+import org.apache.felix.rxtx.cmd.IOWrapper;
+import org.apache.felix.shell.Command;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+import rxtx.sample.SerialParameters;
+
+/**
+ * This class creates a shell command
+ */
+public class RXTXCmdImpl implements Command, SerialPortEventListener,
+		BundleActivator {
+
+	SerialPort serialPort = null;
+
+	OutputStream outputStream = null;
+
+	InputStream inputStream = null;
+
+	String logFileName = null;
+	OutputStream logOutputStream = null;
+
+	IOWrapper currentWrapper = new HexWrapper();
+
+	// TODO resizable buffer
+	byte[] readBuffer = new byte[256];
+
+	public RXTXCmdImpl(BundleContext context) {
+	}
+
+	public String getName() {
+		return "rxtx";
+	}
+
+	public String getUsage() {
+		return "rxtx help";
+	}
+
+	public String getShortDescription() {
+		return "send/receive bytes to/from a serial port";
+	}
+
+	private void printUsage(PrintStream out) {
+		out
+				.println(getName()
+						+ " list                  : list the available ports\n"
+						+ getName()
+						+ " open <portname> <baudrate> <flowctrlin> <flowctrlout> <databits> <stopbits> <parity>\n"
+						+ "               flowctrl=None,Xon/XoffOut,Xon/XoffIn,RTS/CTSIn,RTS/CTSOut\n"
+						+ "                            : open a serial port\n"
+						+ "               databits=5,6,7,8\n"
+						+ "               stopbits=1,1.5,2\n"
+						+ "               parity=None,Odd,Even\n"
+						+ "                            : open a serial port\n"
+						+ getName()
+						+ " close                 : close the current opened port\n"
+						+ getName()
+						+ " send <bytes in hexa>  : send message bytes\n"
+						+ getName()
+						+ " binary                : switch IO in hex\n"
+						+ getName()
+						+ " ascii                 : switch IO in ascii\n"
+						+ getName()
+						+ " buffersize <size>     : set IO buffer size\n"
+						+ getName()
+						+ " sendurl <url>         : send bytes contained at the url\n"
+						+ getName()
+						+ " logfile <filepath>    : log received bytes in the file\n"
+						+ getName()
+						+ " logfile               : stop to log bytes\n"
+						+ getName()
+						+ " iowrapper <classname> : set a wrapper for IO parsing and printing. The class must be provided by a external bundle\n"
+						+ getName()
+						+ " help                  : display this help\n");
+		return;
+	}
+
+	public void execute(String commandLine, PrintStream out, PrintStream err) {
+
+		StringTokenizer st = new StringTokenizer(commandLine, " ");
+
+		// Ignore the command name.
+		st.nextToken();
+		if (st.countTokens() < 1) {
+			printUsage(err);
+			return;
+		}
+
+		String option = st.nextToken();
+
+		if (option.equals("list")) {
+			listPorts(null, out, err);
+		} else if (option.equals("binary")) {
+			currentWrapper = new HexWrapper();
+		} else if (option.equals("ascii")) {
+			currentWrapper = new AsciiWrapper();
+		} else if (option.equals("buffersize")) {
+			if (st.countTokens() != 1) {
+				printUsage(err);
+				return;
+			}
+			// TODO synchronization
+			int newsize = 0;
+			try {
+				newsize = Integer.parseInt(st.nextToken());
+			} catch (NumberFormatException e) {
+				err.println(e);
+				return;
+			}
+			synchronized (this) {
+				readBuffer = new byte[newsize];
+			}
+			return;
+		} else if (option.equals("iowrapper")) {
+			String classname = st.nextToken();
+			Class clazz = null;
+			try {
+				clazz = this.getClass().getClassLoader().loadClass(classname);
+			} catch (ClassNotFoundException e) {
+				err.println(e);
+				return;
+			}
+			IOWrapper wrapper = null;
+			try {
+				wrapper = (IOWrapper) clazz.newInstance();
+			} catch (InstantiationException e) {
+				err.println(e);
+				return;
+			} catch (IllegalAccessException e) {
+				err.println(e);
+				return;
+			}
+			if (wrapper != null)
+				currentWrapper = wrapper;
+			return;
+		} else if (option.equals("sendurl")) {
+			err.println("Not implemented");
+			return;
+		} else if (option.equals("logfile")) {
+
+			if(logOutputStream!=null) {
+				try {
+					logOutputStream.close();
+				} catch (IOException e) {
+					err.println(e);
+					return;
+				}
+				logOutputStream=null;
+				out.println("Close the current log file : "+logFileName); 
+			}
+
+			if (st.countTokens() != 1) {
+				if(logOutputStream!=null) {
+					try {
+						logOutputStream.close();
+					} catch (IOException e) {
+						err.println(e);
+						return;
+					}
+					logOutputStream=null;
+					out.println("Close the current log file: "+logFileName); 
+				} else {
+					err.println("No current log file");
+				}
+				return;
+			}
+
+			logFileName = st.nextToken();
+			File file = new File(logFileName);
+			try {
+				logOutputStream = new FileOutputStream(file);
+			} catch (FileNotFoundException e) {
+				err.println(e);
+				logFileName=null;
+				return;
+			}
+			return;
+		} else if (option.equals("open")) {
+			if (st.countTokens() != 7) {
+				printUsage(err);
+				return;
+			}
+			SerialParameters serialParameters = new SerialParameters();
+			serialParameters.setPortName(st.nextToken());
+			serialParameters.setBaudRate(st.nextToken());
+			serialParameters.setFlowControlIn(st.nextToken());
+			serialParameters.setFlowControlOut(st.nextToken());
+			serialParameters.setDatabits(st.nextToken());
+			serialParameters.setStopbits(st.nextToken());
+			serialParameters.setParity(st.nextToken());
+
+			CommPortIdentifier portId = null;
+			try {
+				portId = CommPortIdentifier.getPortIdentifier(serialParameters
+						.getPortName());
+			} catch (NoSuchPortException e1) {
+				err.println("No Such Port:" + serialParameters.getPortName());
+				return;
+			}
+			if (portId.getPortType() != CommPortIdentifier.PORT_SERIAL) {
+				err.println(serialParameters.getPortName()
+						+ " is not a serial port");
+				return;
+			}
+			try {
+				serialPort = (SerialPort) portId.open("RXTXCmd", 2000);
+			} catch (PortInUseException e) {
+				err.println(serialParameters.getPortName() + " already used");
+				return;
+			}
+
+			try {
+				outputStream = serialPort.getOutputStream();
+			} catch (IOException e) {
+				err.println(e);
+				return;
+			}
+
+			try {
+				inputStream = serialPort.getInputStream();
+			} catch (IOException e) {
+				err.println(e);
+				return;
+			}
+
+			try {
+				serialPort.addEventListener(this);
+				serialPort.notifyOnDataAvailable(true);
+			} catch (TooManyListenersException e) {
+				err.println(e);
+				return;
+			}
+
+			try {
+				serialPort.setSerialPortParams(serialParameters.getBaudRate(),
+						serialParameters.getDatabits(), serialParameters
+								.getStopbits(), serialParameters.getParity());
+			} catch (UnsupportedCommOperationException e) {
+				err.println(e);
+				return;
+			}
+
+		} else if (option.equals("close")) {
+			if (serialPort == null) {
+				err.println("No opened port");
+				return;
+			}
+			close(commandLine, out, err);
+		} else if (option.equals("send")) {
+			if (serialPort == null) {
+				err.println("No opened port");
+				return;
+			}
+			if (st.countTokens() < 1) {
+				printUsage(err);
+				return;
+			}
+
+			byte[] msg = null;
+			int start = commandLine.indexOf("\"");
+			int last = commandLine.lastIndexOf("\"");
+			try {
+				if (start >= 0 && start < last) {
+					String str = commandLine.substring(start + 1, last);
+					msg = currentWrapper.parse(str);
+				} else {
+					msg = currentWrapper.parse(st);
+				}
+			} catch (ParseException e) {
+				err.println(e);
+				return;
+			}
+
+			try {
+				outputStream.write(msg);
+				outputStream.flush();
+			} catch (IOException e) {
+				err.println(e);
+				return;
+			}
+
+		} else {
+			printUsage(out);
+		}
+
+	}
+
+	public void close(String commandLine, PrintStream out, PrintStream err) {
+		if (outputStream != null) {
+			try {
+				outputStream.close();
+			} catch (IOException e) {
+				err.println(e);
+				return;
+			}
+			outputStream = null;
+		}
+
+		if (inputStream != null) {
+			try {
+				inputStream.close();
+			} catch (IOException e) {
+				err.println(e);
+				return;
+			}
+			inputStream = null;
+		}
+
+		if (serialPort != null) {
+			serialPort.removeEventListener();
+			serialPort.close();
+			serialPort = null;
+		}
+
+	}
+
+	public void listPorts(String commandLine, PrintStream out, PrintStream err) {
+		out.println("List of ports from RXTX");
+		Enumeration ports = CommPortIdentifier.getPortIdentifiers();
+		while (ports.hasMoreElements()) {
+			CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
+			String type;
+			switch (port.getPortType()) {
+			case CommPortIdentifier.PORT_PARALLEL:
+				type = "Parallel";
+				break;
+			case CommPortIdentifier.PORT_SERIAL:
+				type = "Serial";
+				break;
+			default: /// Shouldn't happen
+				type = "Unknown";
+				break;
+			}
+			out.println(port.getName() + ": " + type);
+		}
+	}
+
+	/**
+	 * @see gnu.io.SerialPortEventListener#serialEvent(gnu.io.SerialPortEvent)
+	 */
+	public void serialEvent(SerialPortEvent event) {
+		switch (event.getEventType()) {
+		case SerialPortEvent.BI:
+		case SerialPortEvent.OE:
+		case SerialPortEvent.FE:
+		case SerialPortEvent.PE:
+		case SerialPortEvent.CD:
+		case SerialPortEvent.CTS:
+		case SerialPortEvent.DSR:
+		case SerialPortEvent.RI:
+		case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
+			break;
+		case SerialPortEvent.DATA_AVAILABLE:
+
+			try {
+				int numBytes = 0;
+				int numBytesAvailables = 0;
+				synchronized (this) {
+
+					while ((numBytesAvailables=inputStream.available()) > 0) {
+						numBytes = inputStream.read(readBuffer);
+
+						System.out.print(getName() + " (" + numBytes + " bytes received):\n");
+
+						try {
+							System.out.println(currentWrapper.format(readBuffer, 0, numBytes));
+
+							if(logOutputStream!=null){								
+								logOutputStream.write(readBuffer, 0, numBytes);
+								logOutputStream.flush();
+							}
+						} catch (ParseException e) {
+							System.err.println(e);
+							return;
+						}
+					}
+				}
+			} catch (IOException e) {
+				System.err.print(getName() + ":" + e);
+			}
+			break;
+			
+			/*
+			try {
+				int numBytes = 0;
+				synchronized (this) {
+					//System.out.print("received:");
+					while ((numBytes = inputStream.available()) > 0) {
+						numBytes = inputStream.read(readBuffer, currentPos, numBytes);
+						currentPos=currentPos+numBytes;							
+						//System.out.println(HexString.hexify(readBuffer, 0, currentPos, 16, " "));
+						int len;
+						if(currentPos>2 && currentPos>=(len=readBuffer[1])){
+							
+							byte[] b=new byte[len];
+							System.arraycopy(readBuffer,0,b,0,len);
+							currentPos=0;
+							
+							readTRPDetailsResponseFrame = new ReadTRPDetailsResponseFrame(b);
+							
+							if (readTRPDetailsResponseFrame.noErrorReturned()) {
+								tagId = Long.toString(readTRPDetailsResponseFrame.getTagId());
+								tagItListener.process(readerId, tagId);
+							}
+						}
+					}
+				}
+			} catch (IOException e) {
+				System.err.print(readerId + ":" + e);
+			}
+			 */
+			
+			
+			
+			
+		}
+	}
+
+	/**
+	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+	 */
+	public void start(BundleContext arg0) throws Exception {
+	}
+
+	/**
+	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+	 */
+	public void stop(BundleContext arg0) throws Exception {
+		if (logOutputStream != null) {
+			try {
+				logOutputStream.close();
+			} catch (IOException e) {
+				// do nothing
+			}
+		}
+		close(null,System.out,System.err);
+	}
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/RXTXCmdImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/nmea0183/Nmea0183Wrapper.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/nmea0183/Nmea0183Wrapper.java?view=auto&rev=533731
==============================================================================
--- incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/nmea0183/Nmea0183Wrapper.java (added)
+++ incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/nmea0183/Nmea0183Wrapper.java Mon Apr 30 05:50:32 2007
@@ -0,0 +1,50 @@
+/*
+ *  RXTX Command
+ *
+ * Copyright (C) 2005-2006  Didier Donsez (didier.donsez@ieee.org)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * Contact: Didier Donsez (didier.donsez@ieee.org)
+ * Contributor(s):
+ *
+ **/
+
+package org.apache.felix.rxtx.cmd.impl.nmea0183;
+
+import java.text.ParseException;
+import java.util.StringTokenizer;
+
+import org.apache.felix.rxtx.cmd.IOWrapper;
+import org.apache.felix.rxtx.cmd.impl.AsciiWrapper;
+
+
+public class Nmea0183Wrapper extends AsciiWrapper implements IOWrapper {
+
+	/**
+	 * @see org.apache.felix.rxtx.cmd.IOWrapper#parse(java.lang.String)
+	 */
+	public byte[] parse(String string) throws ParseException {
+		throw new ParseException("NMEA0183 have not commands",0);
+	}
+
+	/**
+	 * @see org.apache.felix.rxtx.cmd.IOWrapper#parse(java.util.StringTokenizer)
+	 */
+	public byte[] parse(StringTokenizer st) throws ParseException {
+		throw new ParseException("NMEA0183 have not commands",0);
+	}
+
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/org/apache/felix/rxtx/cmd/impl/nmea0183/Nmea0183Wrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/rxtx/sample/SerialParameters.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/rxtx/sample/SerialParameters.java?view=auto&rev=533731
==============================================================================
--- incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/rxtx/sample/SerialParameters.java (added)
+++ incubator/felix/sandbox/donsez/rxtx.cmd/src/main/java/rxtx/sample/SerialParameters.java Mon Apr 30 05:50:32 2007
@@ -0,0 +1,414 @@
+/* @(#)SerialParameters.java	1.5 98/07/17 SMI
+ *
+ * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Sun grants you ("Licensee") a non-exclusive, royalty free, license
+ * to use, modify and redistribute this software in source and binary
+ * code form, provided that i) this copyright notice and license appear
+ * on all copies of the software; and ii) Licensee does not utilize the
+ * software in a manner which is disparaging to Sun.
+ *
+ * This software is provided "AS IS," without a warranty of any kind.
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND
+ * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
+ * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE
+ * SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS
+ * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
+ * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,
+ * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING
+ * OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * This software is not designed or intended for use in on-line control
+ * of aircraft, air traffic, aircraft navigation or aircraft
+ * communications; or in the design, construction, operation or
+ * maintenance of any nuclear facility. Licensee represents and
+ * warrants that it will not use or redistribute the Software for such
+ * purposes.
+ */
+
+package rxtx.sample;
+import gnu.io.*;
+
+/**
+A class that stores parameters for serial ports. 
+*/
+public class SerialParameters {
+
+    private String portName;
+    private int baudRate;
+    private int flowControlIn;
+    private int flowControlOut;
+    private int databits;
+    private int stopbits;
+    private int parity;
+
+    /**
+    Default constructer. Sets parameters to no port, 9600 baud, no flow 
+    control, 8 data bits, 1 stop bit, no parity.
+    */
+    public SerialParameters () {
+	this("", 
+	     9600, 
+	     SerialPort.FLOWCONTROL_NONE,
+	     SerialPort.FLOWCONTROL_NONE,
+	     SerialPort.DATABITS_8,
+	     SerialPort.STOPBITS_1,
+	     SerialPort.PARITY_NONE );
+			   
+    }		
+
+    /**
+    Paramaterized constructer.
+
+    @param portName The name of the port.
+    @param baudRate The baud rate.
+    @param flowControlIn Type of flow control for receiving.
+    @param flowControlOut Type of flow control for sending.
+    @param databits The number of data bits.
+    @param stopbits The number of stop bits.
+    @param parity The type of parity.
+    */
+    public SerialParameters(String portName, 
+			    int baudRate,
+			    int flowControlIn,
+			    int flowControlOut,
+			    int databits,
+			    int stopbits,
+			    int parity) {
+
+    	this.portName = portName;
+    	this.baudRate = baudRate;
+    	this.flowControlIn = flowControlIn;
+    	this.flowControlOut = flowControlOut;
+    	this.databits = databits;
+    	this.stopbits = stopbits;
+    	this.parity = parity;
+    }
+
+    /**
+    Sets port name.
+    @param portName New port name.
+    */
+    public void setPortName(String portName) {
+	this.portName = portName;
+    }
+
+    /**
+    Gets port name.
+    @return Current port name.
+    */
+    public String getPortName() {
+	return portName;
+    }
+
+    /**
+    Sets baud rate.
+    @param baudRate New baud rate.
+    */
+    public void setBaudRate(int baudRate) {
+	this.baudRate = baudRate;
+    }
+
+    /**
+    Sets baud rate.
+    @param baudRate New baud rate.
+    */
+    public void setBaudRate(String baudRate) {
+	this.baudRate = Integer.parseInt(baudRate);
+    }
+
+    /**
+    Gets baud rate as an <code>int</code>.
+    @return Current baud rate.
+    */
+    public int getBaudRate() {
+	return baudRate;
+    }
+
+    /**
+    Gets baud rate as a <code>String</code>.
+    @return Current baud rate.
+    */
+    public String getBaudRateString() {
+	return Integer.toString(baudRate);
+    }
+
+    /**
+    Sets flow control for reading.
+    @param flowControlIn New flow control for reading type.
+    */
+    public void setFlowControlIn(int flowControlIn) {
+	this.flowControlIn = flowControlIn;
+    }
+
+    /**
+    Sets flow control for reading.
+    @param flowControlIn New flow control for reading type.
+    */
+    public void setFlowControlIn(String flowControlIn) {
+	this.flowControlIn = stringToFlow(flowControlIn);
+    }
+
+    /** 
+    Gets flow control for reading as an <code>int</code>.
+    @return Current flow control type.
+    */
+    public int getFlowControlIn() {
+	return flowControlIn;
+    }
+
+    /** 
+    Gets flow control for reading as a <code>String</code>.
+    @return Current flow control type.
+    */
+    public String getFlowControlInString() {
+	return flowToString(flowControlIn);
+    }
+
+    /**
+    Sets flow control for writing.
+    @param flowControlIn New flow control for writing type.
+    */
+    public void setFlowControlOut(int flowControlOut) {
+	this.flowControlOut = flowControlOut;
+    }
+
+    /**
+    Sets flow control for writing.
+    @param flowControlIn New flow control for writing type.
+    */
+    public void setFlowControlOut(String flowControlOut) {
+	this.flowControlOut = stringToFlow(flowControlOut);
+    }
+
+    /** 
+    Gets flow control for writing as an <code>int</code>.
+    @return Current flow control type.
+    */
+    public int getFlowControlOut() {
+	return flowControlOut;
+    }
+
+    /** 
+    Gets flow control for writing as a <code>String</code>.
+    @return Current flow control type.
+    */
+    public String getFlowControlOutString() {
+	return flowToString(flowControlOut);
+    }
+
+    /** 
+    Sets data bits.
+    @param databits New data bits setting.
+    */
+    public void setDatabits(int databits) {
+	this.databits = databits;
+    }
+
+    /** 
+    Sets data bits.
+    @param databits New data bits setting.
+    */
+    public void setDatabits(String databits) {
+	if (databits.equals("5")) {
+	    this.databits = SerialPort.DATABITS_5;
+	}
+	if (databits.equals("6")) {
+	    this.databits = SerialPort.DATABITS_6;
+	}
+	if (databits.equals("7")) {
+	    this.databits = SerialPort.DATABITS_7;
+	}
+	if (databits.equals("8")) {
+	    this.databits = SerialPort.DATABITS_8;
+	}
+    }
+
+    /**
+    Gets data bits as an <code>int</code>.
+    @return Current data bits setting.
+    */
+    public int getDatabits() {
+	return databits;
+    }
+
+    /**
+    Gets data bits as a <code>String</code>.
+    @return Current data bits setting.
+    */
+    public String getDatabitsString() {
+	switch(databits) {
+	    case SerialPort.DATABITS_5:
+		return "5";
+	    case SerialPort.DATABITS_6:
+		return "6";
+	    case SerialPort.DATABITS_7:
+		return "7";
+	    case SerialPort.DATABITS_8:
+		return "8";
+	    default:
+		return "8";
+	}
+    }
+
+    /**
+    Sets stop bits.
+    @param stopbits New stop bits setting.
+    */
+    public void setStopbits(int stopbits) {
+	this.stopbits = stopbits;
+    }
+
+    /**
+    Sets stop bits.
+    @param stopbits New stop bits setting.
+    */
+    public void setStopbits(String stopbits) {
+	if (stopbits.equals("1")) {
+	    this.stopbits = SerialPort.STOPBITS_1;
+	}
+	if (stopbits.equals("1.5")) {
+	    this.stopbits = SerialPort.STOPBITS_1_5;
+	}
+	if (stopbits.equals("2")) {
+	    this.stopbits = SerialPort.STOPBITS_2;
+	}
+    }
+
+    /**
+    Gets stop bits setting as an <code>int</code>.
+    @return Current stop bits setting.
+    */
+    public int getStopbits() {
+	return stopbits;
+    }
+
+    /**
+    Gets stop bits setting as a <code>String</code>.
+    @return Current stop bits setting.
+    */
+    public String getStopbitsString() {
+	switch(stopbits) {
+	    case SerialPort.STOPBITS_1:
+		return "1";
+	    case SerialPort.STOPBITS_1_5:
+		return "1.5";
+	    case SerialPort.STOPBITS_2:
+		return "2";
+	    default:
+		return "1";
+	}
+    }
+
+    /**
+    Sets parity setting.
+    @param parity New parity setting.
+    */
+    public void setParity(int parity) {
+	this.parity = parity;
+    }
+
+    /**
+    Sets parity setting.
+    @param parity New parity setting.
+    */
+    public void setParity(String parity) {
+	if (parity.equals("None")) {
+	    this.parity = SerialPort.PARITY_NONE;
+	}
+	if (parity.equals("Even")) {
+	    this.parity = SerialPort.PARITY_EVEN;
+	}
+	if (parity.equals("Odd")) {
+	    this.parity = SerialPort.PARITY_ODD;
+	}
+    }
+
+    /**
+    Gets parity setting as an <code>int</code>.
+    @return Current parity setting.
+    */
+    public int getParity() {
+	return parity;
+    }
+
+    /**
+    Gets parity setting as a <code>String</code>.
+    @return Current parity setting.
+    */
+    public String getParityString() {
+	switch(parity) {
+	    case SerialPort.PARITY_NONE:
+		return "None";
+ 	    case SerialPort.PARITY_EVEN:
+		return "Even";
+	    case SerialPort.PARITY_ODD:
+		return "Odd";
+	    default:
+		return "None";
+	}
+    }
+
+    /**
+    Converts a <code>String</code> describing a flow control type to an
+    <code>int</code> type defined in <code>SerialPort</code>.
+    @param flowControl A <code>string</code> describing a flow control type.
+    @return An <code>int</code> describing a flow control type.
+    */
+    private int stringToFlow(String flowControl) {
+	if (flowControl.equals("None")) {
+	    return SerialPort.FLOWCONTROL_NONE;
+	}
+	if (flowControl.equals("Xon/Xoff Out")) {
+	    return SerialPort.FLOWCONTROL_XONXOFF_OUT;
+	}
+	if (flowControl.equals("Xon/Xoff In")) {
+	    return SerialPort.FLOWCONTROL_XONXOFF_IN;
+	}
+	if (flowControl.equals("RTS/CTS In")) {
+	    return SerialPort.FLOWCONTROL_RTSCTS_IN;
+	}
+	if (flowControl.equals("RTS/CTS Out")) {
+	    return SerialPort.FLOWCONTROL_RTSCTS_OUT;
+	}
+	if (flowControl.equals("Xon/XoffOut")) {
+	    return SerialPort.FLOWCONTROL_XONXOFF_OUT;
+	}
+	if (flowControl.equals("Xon/XoffIn")) {
+	    return SerialPort.FLOWCONTROL_XONXOFF_IN;
+	}
+	if (flowControl.equals("RTS/CTSIn")) {
+	    return SerialPort.FLOWCONTROL_RTSCTS_IN;
+	}
+	if (flowControl.equals("RTS/CTSOut")) {
+	    return SerialPort.FLOWCONTROL_RTSCTS_OUT;
+	}
+	return SerialPort.FLOWCONTROL_NONE;
+    }
+
+    /**
+    Converts an <code>int</code> describing a flow control type to a 
+    <code>String</code> describing a flow control type.
+    @param flowControl An <code>int</code> describing a flow control type.
+    @return A <code>String</code> describing a flow control type.
+    */
+    String flowToString(int flowControl) {
+	switch(flowControl) {
+	    case SerialPort.FLOWCONTROL_NONE:
+		return "None";
+	    case SerialPort.FLOWCONTROL_XONXOFF_OUT:
+		return "Xon/Xoff Out";
+	    case SerialPort.FLOWCONTROL_XONXOFF_IN:
+		return "Xon/Xoff In";
+	    case SerialPort.FLOWCONTROL_RTSCTS_IN:
+		return "RTS/CTS In";
+	    case SerialPort.FLOWCONTROL_RTSCTS_OUT:
+		return "RTS/CTS Out";
+	    default:
+		return "None";
+	}
+    }
+}