[Tinyos-beta-commits] CVS: tinyos-1.x/beta/TOSComm/comm Makefile, 1.1, 1.2 NativeSerial.h, 1.1, 1.2 NativeSerial_win32.cpp, 1.1, 1.2 TOSComm.i, 1.1, 1.2 TOSSerial.java, 1.1, 1.2

Cory Sharp cssharp at users.sourceforge.net
Wed Dec 22 11:51:49 PST 2004


Update of /cvsroot/tinyos/tinyos-1.x/beta/TOSComm/comm
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18610

Modified Files:
	Makefile NativeSerial.h NativeSerial_win32.cpp TOSComm.i 
	TOSSerial.java 
Log Message:
Added support for port name mapping via the environment variable TOSCOMMMAP.
It's like this:

    mapstr is of the form "from1=to1:from2=to2:..."

    If "from", "to", and "portname" all end port numbers, then the ports in
    "from" and "to" are used as a bias for the port in "portname", appended to
    the "to" string (without its original terminating digits).  If more than
    one port mapping matches, the one with the smallest non-negative port
    number wins.

    For instance, if
      mapstr="com1=COM1:com10=\\.\COM10"
    then
      com1 => COM1
      com3 => COM3
      com10 => \\.\COM10
      com12 => \\.\COM12
    or if
      mapstr="com1=/dev/ttyS0:usb1=/dev/ttyS100"
    then
      com1 => /dev/ttyS0
      com3 => /dev/ttyS2
      usb1 => /dev/ttyS100
      usb3 => /dev/ttyS102

The native interface has added getTOSCommMap to return the TOSCOMMMAP
environment variable, or some platform specific value if its undefined.

Index: Makefile
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/TOSComm/comm/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Makefile	22 Dec 2004 01:31:48 -0000	1.1
--- Makefile	22 Dec 2004 19:51:45 -0000	1.2
***************
*** 32,50 ****
    UnsupportedCommOperationException.java
  
! JAVAOBJS = \
!   build_$(PLATFORM)/NativeSerial.class \
!   build_$(PLATFORM)/TOSComm.class \
!   build_$(PLATFORM)/TOSCommJNI.class \
!   ByteQueue.class \
!   JavaxCommSerialPort.class \
!   SerialPort.class \
!   SerialPortEvent.class \
!   SerialPortListener.class \
!   TOSCommLibraryLoader.class \
!   TOSSerial$$EventDispatcher.class \
!   TOSSerial$$SerialInputStream.class \
!   TOSSerial$$SerialOutputStream.class \
!   TOSSerial.class \
!   UnsupportedCommOperationException.class
  
  SWIGDEPS = \
--- 32,36 ----
    UnsupportedCommOperationException.java
  
! JAVAOBJS = $(JAVADEPS:%.java=%.class)
  
  SWIGDEPS = \

Index: NativeSerial.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/TOSComm/comm/NativeSerial.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NativeSerial.h	22 Dec 2004 01:31:48 -0000	1.1
--- NativeSerial.h	22 Dec 2004 19:51:45 -0000	1.2
***************
*** 61,64 ****
--- 61,66 ----
    int write( int b );
    int write( const signed char buffer_in[], int off, int len );
+ 
+   static std::string getTOSCommMap();
  };
  

Index: NativeSerial_win32.cpp
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/TOSComm/comm/NativeSerial_win32.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NativeSerial_win32.cpp	22 Dec 2004 01:31:48 -0000	1.1
--- NativeSerial_win32.cpp	22 Dec 2004 19:51:45 -0000	1.2
***************
*** 403,406 ****
--- 403,412 ----
      SetEvent( oavail.o.hEvent );
    }
+ 
+   static std::string getTOSCommMap()
+   {
+     const char* env = getenv( "TOSCOMMMAP" );
+     return (env == NULL) ? "com1=COM1:com10=\\\\.\\COM10" : env;
+   }
  };
  

Index: TOSComm.i
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/TOSComm/comm/TOSComm.i,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TOSComm.i	22 Dec 2004 01:31:48 -0000	1.1
--- TOSComm.i	22 Dec 2004 19:51:45 -0000	1.2
***************
*** 29,32 ****
--- 29,33 ----
  
  %include "arrays_java.i";
+ %include "std_string.i";
  
  %pragma(java) jniclasscode=%{

Index: TOSSerial.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/TOSComm/comm/TOSSerial.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TOSSerial.java	22 Dec 2004 01:31:48 -0000	1.1
--- TOSSerial.java	22 Dec 2004 19:51:45 -0000	1.2
***************
*** 27,30 ****
--- 27,31 ----
  import java.io.*;
  import java.util.*;
+ import java.util.regex.*;
  
  public class TOSSerial extends NativeSerial implements SerialPort
***************
*** 162,178 ****
    EventDispatcher m_dispatch;
  
!   static String map_portname( String name )
    {
!     String map = TOSComm.getenv("TOSCOMMMAP");
!     //System.err.println("TOSCOMMMAP="+map);
  
!     if( name.matches("(?i)com\\d+") )
!       return "\\\\.\\" + name;
!     return name;
    }
  
    public TOSSerial( String portname )
    {
!     super( map_portname(portname) );
      m_in = new SerialInputStream( this );
      m_out = new SerialOutputStream( this );
--- 163,236 ----
    EventDispatcher m_dispatch;
  
!   static String map_portname( String mapstr, String portname )
    {
!     // mapstr is of the form "from1=to1:from2=to2"
  
!     // If "from", "to", and "portname" all end port numbers, then the ports in
!     // "from" and "to" are used as a bias for the port in "portname", appended
!     // to the "to" string (without its original terminating digits).  If more
!     // than one port mapping matches, the one with the smallest non-negative
!     // port number wins.
! 
!     // For instance, if
!     //   mapstr="com1=COM1:com10=\\.\COM10"
!     // then
!     //   com1 => COM1
!     //   com3 => COM3
!     //   com10 => \\.\COM10
!     //   com12 => \\.\COM12
!     // or if
!     //   mapstr="com1=/dev/ttyS0:usb1=/dev/ttyS100"
!     // then
!     //   com1 => /dev/ttyS0
!     //   com3 => /dev/ttyS2
!     //   usb1 => /dev/ttyS100
!     //   usb3 => /dev/ttyS102
! 
!     String maps[] = mapstr.split(":");
!     Pattern pkv = Pattern.compile("(.*?)=(.*?)");
!     Pattern pnum = Pattern.compile("(.*\\D)(\\d+)");
! 
!     Matcher mport = pnum.matcher(portname);
!     int match_distance = -1;
!     String str_port_to = null;
! 
!     for( int i=0; i<maps.length; i++ )
!     {
!       Matcher mkv = pkv.matcher( maps[i] );
!       if( mkv.matches() )
!       {
! 	Matcher mfrom = pnum.matcher( mkv.group(1) );
! 	Matcher mto = pnum.matcher( mkv.group(2) );
! 	if( mfrom.matches() && mto.matches() && mport.matches()
! 	    && mfrom.group(1).equalsIgnoreCase( mport.group(1) )
! 	  )
! 	{
! 	  int nfrom = Integer.parseInt( mfrom.group(2) );
! 	  int nto = Integer.parseInt( mto.group(2) );
! 	  int nport_from = Integer.parseInt( mport.group(2) );
! 	  int nport_to = nport_from - nfrom + nto;
! 	  int ndist = nport_from - nfrom;
! 
! 	  if( (ndist >= 0) && ((ndist < match_distance) || (match_distance == -1)) )
! 	  {
! 	    match_distance = ndist;
! 	    str_port_to = mto.group(1) + nport_to;
! 	  }
! 	}
! 	else if( mkv.group(1).equalsIgnoreCase( portname ) )
! 	{
! 	  match_distance = 0;
! 	  str_port_to = mkv.group(2);
! 	}
!       }
!     }
! 
!     return (str_port_to == null) ? portname : str_port_to;
    }
  
    public TOSSerial( String portname )
    {
!     super( map_portname( NativeSerial.getTOSCommMap(), portname ) );
      m_in = new SerialInputStream( this );
      m_out = new SerialOutputStream( this );



More information about the Tinyos-beta-commits mailing list