# $Id$
# @author Cory Sharp <cory@moteiv.com>
# @author Joe Polastre
+#
+# Changes to support CP2103 by R. Steve Mckown <rsmckown@gmail.com>
my $help = <<'EOF';
usage: motelist [options]
#
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),
} }
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};
// @author Cory Sharp <cssharp@eecs.berkeley.edu>
+// Support for CP2103 by Sporian Microsystems, Inc. and R. Steve McKown
+// <rsmckown@gmail.com>
+
#include <iostream>
#include <string>
#include <vector>
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;
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" );
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;
}