From: smckown Date: Thu, 4 Sep 2008 16:13:21 +0000 (+0000) Subject: Update motelist to support cp2103 detection. X-Git-Tag: patchset/2.1.1-4.4~21 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=da0fc4a07b170b5c2c4b1ead622701be794a4de6 Update motelist to support cp2103 detection. --- diff --git a/tools/platforms/msp430/motelist/motelist-linux b/tools/platforms/msp430/motelist/motelist-linux index b6f1c407..9f989231 100755 --- a/tools/platforms/msp430/motelist/motelist-linux +++ b/tools/platforms/msp430/motelist/motelist-linux @@ -3,6 +3,8 @@ use strict; # $Id$ # @author Cory Sharp # @author Joe Polastre +# +# Changes to support CP2103 by R. Steve Mckown my $help = <<'EOF'; usage: motelist [options] @@ -59,9 +61,9 @@ print_motelist( sort { cmp_usbdev($a,$b) } @devs ); # sub scan_sysfs { - # Scan /sys/bus/usb/drivers/usb for FTDI devices + # Scan /sys/bus/usb/drivers/usb for FTDI and CP2103 devices my @ftdidevs = - grep { ($_->{UsbVendor}||"") eq "0403" && ($_->{UsbProduct}||"") eq "6001" } + grep { (($_->{UsbVendor}||"") eq "0403" && ($_->{UsbProduct}||"") eq "6001") || (($_->{UsbVendor}||"") eq "10c4" && ($_->{UsbProduct}||"") eq "ea60") } map { { SysPath => $_, UsbVendor => snarf("$_/idVendor",1), @@ -69,7 +71,7 @@ sub scan_sysfs { } } glob("/sys/bus/usb/drivers/usb/*"); - # Gather information about each FTDI device + # Gather information about each FTDI and CP2103 device for my $f (@ftdidevs) { my $syspath = $f->{SysPath}; diff --git a/tools/platforms/msp430/motelist/motelist-win32.cpp b/tools/platforms/msp430/motelist/motelist-win32.cpp index 8abbf087..803d97d9 100644 --- a/tools/platforms/msp430/motelist/motelist-win32.cpp +++ b/tools/platforms/msp430/motelist/motelist-win32.cpp @@ -22,6 +22,9 @@ // @author Cory Sharp +// Support for CP2103 by Sporian Microsystems, Inc. and R. Steve McKown +// + #include #include #include @@ -86,7 +89,7 @@ struct RegValue case REG_DWORD: data_int = *(DWORD*)_data; - nbuf = sprintf( buf, "%d", *(DWORD*)_data ); + nbuf = sprintf( buf, "%lu", *(DWORD*)_data ); data = String( buf, buf+nbuf ); break; @@ -319,10 +322,8 @@ int getRefCount( const RegKey& dclass, const RegKey& key ) return refcnt; } -ListDevice getDevices() +void getFTDIDevices(ListDevice& devs) { - ListDevice devs; - String ccs = "SYSTEM\\CurrentControlSet\\"; RegKey dclass( HKEY_LOCAL_MACHINE, ccs+"Control\\DeviceClasses" ); RegKey ftdibus( HKEY_LOCAL_MACHINE, ccs+"Enum\\FTDIBUS" ); @@ -360,6 +361,55 @@ ListDevice getDevices() devs.push_back(d); } } +} + +void getCP210xDevices(ListDevice& devs) +{ + String ccs = "SYSTEM\\CurrentControlSet\\"; + String enums = "Enum\\USB\\Vid_10c4&Pid_ea60"; + RegKey dclass(HKEY_LOCAL_MACHINE, ccs+"Control\\DeviceClasses"); + RegKey usb10c4(HKEY_LOCAL_MACHINE, ccs+enums); + RegKey usb10c4tty(HKEY_LOCAL_MACHINE, ccs+enums+"&Mi_00"); + + VecString cdev = usb10c4.getSubkeyNames(); + for( VecString::const_iterator i=cdev.begin(); i!=cdev.end(); i++ ) + { + Device d; + d.id = i->substr(0, 8); + + try + { + RegKey devkey = usb10c4tty[*i+"_00"]; + d.comm = devkey["Device Parameters"]("PortName").data; + } + catch( std::runtime_error e ) + { + d.comm = "no_comm"; + } + + try { d.info = usb10c4[*i]("LocationInformation").data; } + catch( std::runtime_error e ) { } + + try { + d.refcount = getRefCount( dclass, usb10c4[*i] ); + } + catch( std::runtime_error e ) { } + + String::size_type ncomm = d.comm.find_first_of("0123456789"); + if( ncomm != String::npos ) + d.sortnum = atoi( d.comm.substr(ncomm).c_str() ); + + devs.push_back(d); + } +} + + +ListDevice getDevices() +{ + ListDevice devs; + + getFTDIDevices(devs); + getCP210xDevices(devs); return devs; }