Add "cable list" command. This is more or less a draft to be reviewed.
I'm not really sure what types shall be selected for parameters of FT_*() functions. Signed-off-by: Márton Németh <[email protected]> --- diff --git a/urjtag/include/urjtag/cable.h b/urjtag/include/urjtag/cable.h index f9ef14d..c83b09f 100644 --- a/urjtag/include/urjtag/cable.h +++ b/urjtag/include/urjtag/cable.h @@ -243,6 +243,13 @@ urj_cable_t *urj_tap_cable_usb_connect (urj_chain_t *chain, int urj_tap_cable_usb_probe (char *params[]); /** + * API function to list connected USB cables + * + * @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on failure + */ +int urj_tap_cable_usb_list (char *params[]); + +/** * API function to connect to a type-other cable * * @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on failure diff --git a/urjtag/include/urjtag/usbconn.h b/urjtag/include/urjtag/usbconn.h index e232db2..da3e6e7 100644 --- a/urjtag/include/urjtag/usbconn.h +++ b/urjtag/include/urjtag/usbconn.h @@ -56,6 +56,7 @@ typedef struct int (*read) (urj_usbconn_t *, uint8_t *, int); /** @return bytes written on success; -1 on error */ int (*write) (urj_usbconn_t *, uint8_t *, int, int); + int (*list) (void); } urj_usbconn_driver_t; diff --git a/urjtag/src/cmd/cmd_cable.c b/urjtag/src/cmd/cmd_cable.c index a666b1f..e34665f 100644 --- a/urjtag/src/cmd/cmd_cable.c +++ b/urjtag/src/cmd/cmd_cable.c @@ -46,6 +46,12 @@ cable_probe (char *params[]) } static int +cable_list (char *params[]) +{ + return urj_tap_cable_usb_list (params); +} + +static int cmd_cable_run (urj_chain_t *chain, char *params[]) { int i; @@ -68,6 +74,19 @@ cmd_cable_run (urj_chain_t *chain, char *params[]) return URJ_STATUS_FAIL; } + if (strcasecmp (params[1], "list") == 0) + { + if (cable_list (params)) + { + urj_error_set (URJ_ERROR_NOTFOUND, + _("%s: no connected cables found to list"), + params[0]); + return URJ_STATUS_FAIL; + } else { + return URJ_STATUS_OK; + } + } + /* maybe old syntax was used? search connection type driver */ for (i = 0; urj_tap_parport_drivers[i]; i++) if (strcasecmp (params[1], diff --git a/urjtag/src/tap/cable/generic_usbconn.c b/urjtag/src/tap/cable/generic_usbconn.c index 775c029..c64511b 100644 --- a/urjtag/src/tap/cable/generic_usbconn.c +++ b/urjtag/src/tap/cable/generic_usbconn.c @@ -241,3 +241,19 @@ urj_tap_cable_usb_probe (char *params[]) urj_log_state.level = old_level; return URJ_STATUS_FAIL; } + +int +urj_tap_cable_usb_list (char *params[]) +{ + int i; + int count = 0; + + for (i = 0; urj_tap_usbconn_drivers[i]; ++i) + { + if (urj_tap_usbconn_drivers[i]->list) { + count += urj_tap_usbconn_drivers[i]->list (); + } + } + + return count ? URJ_STATUS_OK : URJ_STATUS_FAIL; +} diff --git a/urjtag/src/tap/usbconn/libftd2xx.c b/urjtag/src/tap/usbconn/libftd2xx.c index dad17e1..465bcb3 100644 --- a/urjtag/src/tap/usbconn/libftd2xx.c +++ b/urjtag/src/tap/usbconn/libftd2xx.c @@ -590,6 +590,146 @@ usbconn_ftd2xx_free (urj_usbconn_t *conn) /* ---------------------------------------------------------------------- */ +static int +usbconn_ftd2xx_list () +{ + FT_STATUS status; + uint32_t library_ver; + uint32_t driver_ver; + FT_HANDLE fc; + FT_HANDLE fc_temp; + uint32_t num_devs; + uint32_t i; + uint32_t flags; + uint32_t id; + uint32_t dev_type; + uint32_t loc_id; + char serial_number[16]; + char description[64]; + uint32_t com_port_number; + + // create the device information list + status = FT_CreateDeviceInfoList(&num_devs); + if (status == FT_OK) { + urj_log (URJ_LOG_LEVEL_NORMAL, + _("There are %d devices currently connected.\n"), num_devs); + } + + library_ver = 0; + status = FT_GetLibraryVersion(&library_ver); + if (status == FT_OK) { + urj_log (URJ_LOG_LEVEL_NORMAL, + _("Library version %u.%u.%u.\n"), + (library_ver >> 16) & 0xFF, + (library_ver >> 8) & 0xFF, + library_ver & 0xFF); + } + + for (i=0; i < num_devs; i++) { + // get information for device + flags = 0; + dev_type = 0; + id = 0; + loc_id = 0; + memset(serial_number, 0, sizeof(serial_number)); + memset(description, 0, sizeof(description)); + fc = NULL; + fc_temp = NULL; + status = FT_GetDeviceInfoDetail(i, &flags, &dev_type, &id, &loc_id, serial_number, description, &fc); + if (status == FT_OK) { + urj_log (URJ_LOG_LEVEL_NORMAL, _(" Device #%i:\n"), i); + urj_log (URJ_LOG_LEVEL_NORMAL, _(" flags: %s, %s (0x%x)\n"), + flags & FT_FLAGS_OPENED ? _("Open") : _("Closed"), + flags & FT_FLAGS_HISPEED ? _("Hi-Speed") : _("Full speed"), + flags); + if (dev_type != FT_DEVICE_UNKNOWN) { + urj_log (URJ_LOG_LEVEL_NORMAL, _(" Type: ")); + switch (dev_type) { + case FT_DEVICE_BM: + urj_log (URJ_LOG_LEVEL_NORMAL, "232BM"); + break; + case FT_DEVICE_AM: + urj_log (URJ_LOG_LEVEL_NORMAL, "232AM"); + break; + case FT_DEVICE_100AX: + urj_log (URJ_LOG_LEVEL_NORMAL, "100AX"); + break; + case FT_DEVICE_2232C: + urj_log (URJ_LOG_LEVEL_NORMAL, "2232C"); + break; + case FT_DEVICE_232R: + urj_log (URJ_LOG_LEVEL_NORMAL, "232R"); + break; + case FT_DEVICE_2232H: + urj_log (URJ_LOG_LEVEL_NORMAL, "2232H"); + break; + case FT_DEVICE_4232H: + urj_log (URJ_LOG_LEVEL_NORMAL, "4232H"); + break; + case FT_DEVICE_232H: + urj_log (URJ_LOG_LEVEL_NORMAL, "232H"); + break; + case FT_DEVICE_UNKNOWN: + default: + urj_log (URJ_LOG_LEVEL_NORMAL, _("unknown")); + } + urj_log (URJ_LOG_LEVEL_NORMAL, _(" (0x%x)\n"), dev_type); + } + if (id) { + urj_log (URJ_LOG_LEVEL_NORMAL, _(" ID: 0x%x\n"), id); + } + + if (0 < strlen(serial_number)) { + urj_log (URJ_LOG_LEVEL_NORMAL, _(" Serial Number: %s\n"), serial_number); + } + + if (0 < strlen(description)) { + urj_log (URJ_LOG_LEVEL_NORMAL, _(" Description: \"%s\"\n"), description); + } + + if (loc_id) { + urj_log (URJ_LOG_LEVEL_NORMAL, _(" Location ID: 0x%x\n"), loc_id); + } + + if (!fc) { + status = FT_Open(i, &fc_temp); + } else { + fc_temp = fc; + status = FT_OK; + } + if (status == FT_OK) { + status = FT_GetDriverVersion(fc_temp, &driver_ver); + if (status == FT_OK) { + urj_log (URJ_LOG_LEVEL_NORMAL, _(" Driver version: %u.%u.%u\n"), + (driver_ver >> 16) & 0xFF, + (driver_ver >> 8) & 0xFF, + driver_ver & 0xFF); + } + + status = FT_GetComPortNumber(fc_temp, &com_port_number); + if (status == FT_OK) { + if (com_port_number == -1) { + // No COM port assigned + } else { + // COM port assigned with number held in com_port_number + urj_log (URJ_LOG_LEVEL_NORMAL, _(" COM%u\n"), com_port_number); + } + } else { + // FT_GetComPortNumber FAILED! + } + + if (!fc) { + FT_Close(fc_temp); + fc_temp = NULL; + } + } + } + } + return num_devs; +} + +/* ---------------------------------------------------------------------- */ + const urj_usbconn_driver_t urj_tap_usbconn_ftd2xx_driver = { "ftd2xx", usbconn_ftd2xx_connect, @@ -597,7 +737,8 @@ const urj_usbconn_driver_t urj_tap_usbconn_ftd2xx_driver = { usbconn_ftd2xx_open, usbconn_ftd2xx_close, usbconn_ftd2xx_read, - usbconn_ftd2xx_write + usbconn_ftd2xx_write, + usbconn_ftd2xx_list }; const urj_usbconn_driver_t urj_tap_usbconn_ftd2xx_mpsse_driver = { ------------------------------------------------------------------------------ Learn Windows Azure Live! Tuesday, Dec 13, 2011 Microsoft is holding a special Learn Windows Azure training event for developers. It will provide a great way to learn Windows Azure and what it provides. You can attend the event by watching it streamed LIVE online. Learn more at http://p.sf.net/sfu/ms-windowsazure _______________________________________________ UrJTAG-development mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/urjtag-development
