Add the list subcommand for cable command. This subcommand will list
all the connected cables and helps to find out the description and serial
number when it is more than one device is connected with the same driver.

See the following example when an FT232R based USB-to-serial converer and
an Amontec JTAGkey-2 is connected to the same computer. The "cable JTAGkey"
command would open the wrong device: the FT232R based USB-to-serial converter
instead of the JTAGkey-2. The "cable JTAGkey list" command helps to find
out which device is to be actually used:

jtag> cable JTAGkey help
Usage: cable JTAGkey [vid=VID] [pid=PID] [desc=DESC] [driver=DRIVER]

VID        vendor ID (hex), defaults to 0403
PID        product ID (hex), defaults to CFF8
DESC       Some string to match in description or serial no.
DRIVER     usbconn driver, either ftdi-mpsse or ftd2xx-mpsse
           defaults to ftd2xx-mpsse if not specified

Usage: cable JTAGkey list

List the currently connected JTAGkey cables.

jtag> cable JTAGkey list
There are 3 devices currently connected and handled by ftd2xx driver.
Library version 3.1.25.
 Device #0:
  Flags: Closed, Full speed (0x0)
  Type: 232R (0x5)
  ID: 0x4036001
  SerialNumber: A10096S3
  Description: "FT232R USB UART"
  Location ID: 0x213
  Driver version: 2.4.34
  COM30
 Device #1:
  Flags: Closed, Hi-Speed (0x2)
  Type: 2232H (0x6)
  ID: 0x403cff8
  SerialNumber: 53U2ENL4A
  Description: "Amontec JTAGkey-2 A"
  Location ID: 0x2141
  Driver version: 2.4.34
 Device #2:
  Flags: Closed, Hi-Speed (0x2)
  Type: 2232H (0x6)
  ID: 0x403cff8
  SerialNumber: 53U2ENL4B
  Description: "Amontec JTAGkey-2 B"
  Location ID: 0x2142
  Driver version: 2.4.34
List is not implemented for ftd2xx-mpsse
jtag> cable JTAGkey
Connected to libftd2xx driver.
jtag> cable JTAGkey list
There are 3 devices currently connected and handled by ftd2xx driver.
Library version 3.1.25.
 Device #0:
  Flags: Open, Full speed (0x1)
  Type: 232R (0x5)
  ID: 0x4036001
  SerialNumber: A10096S3
  Description: "FT232R USB UART"
  Driver version: 2.4.34
  COM30
 Device #1:
  Flags: Closed, Hi-Speed (0x2)
  Type: 2232H (0x6)
  ID: 0x403cff8
  SerialNumber: 53U2ENL4A
  Description: "Amontec JTAGkey-2 A"
  Location ID: 0x2141
  Driver version: 2.4.34
 Device #2:
  Flags: Closed, Hi-Speed (0x2)
  Type: 2232H (0x6)
  ID: 0x403cff8
  SerialNumber: 53U2ENL4B
  Description: "Amontec JTAGkey-2 B"
  Location ID: 0x2142
  Driver version: 2.4.34
List is not implemented for ftd2xx-mpsse
jtag> cable JTAGkey desc=53U2ENL4A
Connected to libftd2xx driver.
jtag> cable JTAGkey list
There are 3 devices currently connected and handled by ftd2xx driver.
Library version 3.1.25.
 Device #0:
  Flags: Closed, Full speed (0x0)
  Type: 232R (0x5)
  ID: 0x4036001
  SerialNumber: A10096S3
  Description: "FT232R USB UART"
  Location ID: 0x213
  Driver version: 2.4.34
  COM30
 Device #1:
  Flags: Open, Hi-Speed (0x3)
  Type: 2232H (0x6)
  ID: 0x403cff8
  SerialNumber: 53U2ENL4A
  Description: "Amontec JTAGkey-2 A"
  Driver version: 2.4.34
 Device #2:
  Flags: Closed, Hi-Speed (0x2)
  Type: 2232H (0x6)
  ID: 0x403cff8
  SerialNumber: 53U2ENL4B
  Description: "Amontec JTAGkey-2 B"
  Location ID: 0x2142
  Driver version: 2.4.34
List is not implemented for ftd2xx-mpsse
jtag> quit


Signed-off-by: Márton Németh <[email protected]>
---
diff -upr urjtag-0.10.orig//include/cable.h urjtag-0.10/include/cable.h
--- urjtag-0.10.orig//include/cable.h   2009-04-17 22:24:09.000000000 +0200
+++ urjtag-0.10/include/cable.h 2011-12-04 13:58:56.231600000 +0100
@@ -61,6 +61,7 @@ struct cable_driver_t {
        int (*get_signal)( cable_t *, pod_sigsel_t );
        void (*flush)( cable_t *, cable_flush_amount_t );
        void (*help)( const char * );
+       void (*list)( cable_t * );
 };

 typedef struct cable_queue_t cable_queue_t;
diff -upr urjtag-0.10.orig//include/usbconn.h urjtag-0.10/include/usbconn.h
--- urjtag-0.10.orig//include/usbconn.h 2009-04-17 22:24:09.000000000 +0200
+++ urjtag-0.10/include/usbconn.h       2011-12-04 15:21:09.419600000 +0100
@@ -50,6 +50,7 @@ typedef struct {
        int (*close)( usbconn_t * );
        int (*read)( usbconn_t *, uint8_t *, int );
        int (*write)( usbconn_t *, uint8_t *, int, int );
+       void (*list)( usbconn_cable_t *);
 } usbconn_driver_t;

 struct usbconn_t {
diff -upr urjtag-0.10.orig//src/cmd/cable.c urjtag-0.10/src/cmd/cable.c
--- urjtag-0.10.orig//src/cmd/cable.c   2009-04-17 22:24:09.000000000 +0200
+++ urjtag-0.10/src/cmd/cable.c 2011-12-04 14:01:07.973600000 +0100
@@ -84,6 +84,23 @@ cmd_cable_run( chain_t *chain, char *par
                        cable_drivers[i]->help(cable_drivers[i]->name);
                        return 1;
                }
+               if (strcasecmp( params[2], "list" ) == 0)
+               {
+                       if (cable_drivers[i]->list) {
+                               cable = calloc(1, sizeof(cable_t) );
+                               if (!cable) {
+                                 printf( _("%s(%d) malloc failed!\n"), 
__FILE__, __LINE__);
+                                 return 1;
+                               }
+                               cable->driver = cable_drivers[i];
+                               cable_drivers[i]->list(cable);
+                               free( cable );
+
+                       } else {
+                               printf( _("Error: list is not implemented for 
%s!\n"), cable_drivers[i]->name);
+                       }
+                       return 1;
+               }
        }

        if (bus) {
diff -upr urjtag-0.10.orig//src/tap/cable/ft2232.c 
urjtag-0.10/src/tap/cable/ft2232.c
--- urjtag-0.10.orig//src/tap/cable/ft2232.c    2009-04-17 22:24:10.000000000 
+0200
+++ urjtag-0.10/src/tap/cable/ft2232.c  2011-12-05 20:58:25.790363100 +0100
@@ -1672,6 +1672,16 @@ found:
           conn->vid, conn->pid,
           DEFAULT_DRIVER
           );
+  printf( _(
+            "Usage: cable %s list\n"
+            "\n"
+            "List the currently connected %s cables.\n"
+            "\n"
+            ),
+          cablename,
+          cablename
+          );
+
 }


@@ -1800,7 +1810,8 @@ cable_driver_t ft2232_jtagkey_cable_driv
   ft2232_set_signal,
   generic_get_signal,
   ft2232_flush,
-  ft2232_usbcable_help
+  ft2232_usbcable_help,
+  generic_usbconn_list
 };
 usbconn_cable_t usbconn_cable_jtagkey_ftdi = {
   "JTAGkey",          /* cable name */
diff -upr urjtag-0.10.orig//src/tap/cable/generic_usbconn.c 
urjtag-0.10/src/tap/cable/generic_usbconn.c
--- urjtag-0.10.orig//src/tap/cable/generic_usbconn.c   2009-04-17 
22:24:10.000000000 +0200
+++ urjtag-0.10/src/tap/cable/generic_usbconn.c 2011-12-04 15:33:26.622400000 
+0100
@@ -261,3 +261,32 @@ generic_usbconn_help( const char *cablen
     );
 }

+void
+generic_usbconn_list( cable_t *cable )
+{
+       usbconn_t *conn = NULL;
+       int i;
+
+       /* search usbconn driver list */
+       for (i = 0; usbconn_drivers[i] && !conn; i++)
+       {
+               int j;
+
+               /* search cable list */
+               for (j = 0; usbconn_cables[j] && !conn; j++)
+               {
+                       if (strcasecmp(usbconn_cables[j]->driver, 
usbconn_drivers[i]->type) == 0)
+                       {
+                               usbconn_cable_t cable_try = 
*(usbconn_cables[j]);
+                               if (usbconn_drivers[i]->list) {
+                                       usbconn_drivers[i]->list( &cable_try );
+                               } else {
+                                       printf( _("List is not implemented for 
%s\n"), usbconn_drivers[i]->type);
+                               }
+                               
+                               /* Step to the next usbconn_cable after the 
first match */
+                               break;
+                       }
+               }
+       }
+}
diff -upr urjtag-0.10.orig//src/tap/cable/generic_usbconn.h 
urjtag-0.10/src/tap/cable/generic_usbconn.h
--- urjtag-0.10.orig//src/tap/cable/generic_usbconn.h   2009-04-17 
22:24:10.000000000 +0200
+++ urjtag-0.10/src/tap/cable/generic_usbconn.h 2011-12-04 15:25:32.591600000 
+0100
@@ -32,5 +32,6 @@ int generic_usbconn_connect( char *param
 void generic_usbconn_done( cable_t *cable );
 void generic_usbconn_help( const char *name );
 void generic_usbconn_free( cable_t *cable );
+void generic_usbconn_list( cable_t *cable );

 #endif /* GENERIC_H */
diff -upr urjtag-0.10.orig//src/tap/usbconn/libftd2xx.c 
urjtag-0.10/src/tap/usbconn/libftd2xx.c
--- urjtag-0.10.orig//src/tap/usbconn/libftd2xx.c       2009-04-17 
22:24:10.000000000 +0200
+++ urjtag-0.10/src/tap/usbconn/libftd2xx.c     2011-12-05 21:44:38.826163100 
+0100
@@ -518,6 +518,141 @@ usbconn_ftd2xx_free( usbconn_t *conn )

 /* ---------------------------------------------------------------------- */

+static void
+usbconn_ftd2xx_list(usbconn_cable_t *conn)
+{
+  FT_STATUS ftStatus;
+  DWORD dwLibraryVer;
+  DWORD dwDriverVer;
+  FT_HANDLE ftHandle;
+  FT_HANDLE ftHandleTemp;
+  DWORD numDevs;
+  DWORD i;
+  DWORD Flags;
+  DWORD ID;
+  DWORD Type;
+  DWORD LocId;
+  char SerialNumber[16];
+  char Description[64];
+  LONG lComPortNumber;
+
+  // create the device information list
+  ftStatus = FT_CreateDeviceInfoList(&numDevs);
+  if (ftStatus == FT_OK) {
+       printf( _("There are %d devices currently connected and handled by %s 
driver.\n"), numDevs, conn->driver);
+  }
+
+  dwLibraryVer = 0;
+  ftStatus = FT_GetLibraryVersion(&dwLibraryVer);
+  if (ftStatus == FT_OK) {
+       printf( _("Library version %u.%u.%u.\n"),
+               (dwLibraryVer >> 16) & 0xFF,
+               (dwLibraryVer >> 8) & 0xFF,
+               dwLibraryVer & 0xFF);
+  }
+
+  for (i=0; i < numDevs; i++) {
+               // get information for device
+               Flags = 0;
+               Type = 0;
+               ID = 0;
+               LocId = 0;
+               memset(SerialNumber, 0, sizeof(SerialNumber));
+               memset(Description, 0, sizeof(Description));
+               ftHandle = NULL;
+               ftHandleTemp = NULL;
+               ftStatus = FT_GetDeviceInfoDetail(i, &Flags, &Type, &ID, 
&LocId, SerialNumber, Description, &ftHandle);
+               if (ftStatus == FT_OK) {
+                       printf( _(" Device #%i:\n"), i);
+                       printf( _("  Flags: %s, %s (0x%x)\n"),
+                                               Flags & FT_FLAGS_OPENED ? 
_("Open") : _("Closed"),
+                                               Flags & FT_FLAGS_HISPEED ? 
_("Hi-Speed") : _("Full speed"),
+                                               Flags);
+                       if (Type != FT_DEVICE_UNKNOWN) {
+                               printf( _("  Type: "));
+                               switch (Type) {
+                                       case FT_DEVICE_BM:
+                                               printf("232BM");
+                                               break;
+                                       case FT_DEVICE_AM:
+                                               printf("232AM");
+                                               break;
+                                       case FT_DEVICE_100AX:
+                                               printf("100AX");
+                                               break;
+                                       case FT_DEVICE_2232C:
+                                               printf("2232C");
+                                               break;
+                                       case FT_DEVICE_232R:
+                                               printf("232R");
+                                               break;
+                                       case FT_DEVICE_2232H:
+                                               printf("2232H");
+                                               break;
+                                       case FT_DEVICE_4232H:
+                                               printf("4232H");
+                                               break;
+                                       case FT_DEVICE_232H:
+                                               printf("232H");
+                                               break;
+                                       case FT_DEVICE_UNKNOWN:
+                                       default:
+                                               printf( _("unknown"));
+                               }
+                               printf( _(" (0x%x)\n"), Type);
+                       }
+                       if (ID) {
+                               printf( _("  ID: 0x%x\n"), ID);
+                       }
+
+                       if (0 < strlen(SerialNumber)) {
+                               printf( _("  SerialNumber: %s\n"), 
SerialNumber);
+                       }
+
+                       if (0 < strlen(Description)) {
+                               printf( _("  Description: \"%s\"\n"), 
Description);
+                       }
+
+                       if (LocId) {
+                               printf( _("  Location ID: 0x%x\n"), LocId);
+                       }
+
+                       if (!ftHandle) {
+                               ftStatus = FT_Open(i, &ftHandleTemp);
+                       } else {
+                               ftHandleTemp = ftHandle;
+                               ftStatus = FT_OK;
+                       }
+                       if (ftStatus == FT_OK) {
+                               ftStatus = FT_GetDriverVersion(ftHandleTemp, 
&dwDriverVer);
+                               if (ftStatus == FT_OK) {
+                                       printf( _("  Driver version: 
%u.%u.%u\n"),
+                                               (dwDriverVer >> 16) & 0xFF,
+                                               (dwDriverVer >> 8) & 0xFF,
+                                               dwDriverVer & 0xFF);
+                               }
+
+                               ftStatus = FT_GetComPortNumber(ftHandleTemp, 
&lComPortNumber);
+                               if (ftStatus == FT_OK) {
+                                       if (lComPortNumber == -1) {
+                                               // No COM port assigned
+                                       } else {
+                                               // COM port assigned with 
number held in lComPortNumber
+                                               printf( _("  COM%u\n"), 
lComPortNumber);
+                                       }
+                               } else {
+                                       // FT_GetComPortNumber FAILED!
+                               }
+                               
+                               if (!ftHandle) {
+                                       FT_Close(ftHandleTemp);
+                                       ftHandleTemp = NULL;
+                               }
+                       }
+               }
+  }
+}
+
 usbconn_driver_t usbconn_ftd2xx_driver = {
   "ftd2xx",
   usbconn_ftd2xx_connect,
@@ -525,7 +660,8 @@ usbconn_driver_t usbconn_ftd2xx_driver =
   usbconn_ftd2xx_open,
   usbconn_ftd2xx_close,
   usbconn_ftd2xx_read,
-  usbconn_ftd2xx_write
+  usbconn_ftd2xx_write,
+  usbconn_ftd2xx_list
 };

 usbconn_driver_t usbconn_ftd2xx_mpsse_driver = {

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
UrJTAG-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/urjtag-development

Reply via email to