]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tools/platforms/msp430/motelist/motelist-win32.cpp
Update motelist to support cp2103 detection.
[tinyos-2.x.git] / tools / platforms / msp430 / motelist / motelist-win32.cpp
index 8abbf087da9be5626522af6b4bad4f79917ea53a..803d97d9e0a56e534b1af63293245a15e2d3c218 100644 (file)
@@ -22,6 +22,9 @@
 
 // @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>
@@ -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;
 }