From 135ca2ef80d8b7527d61a1f3ef08e9cdf2d856ff Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 8 Feb 2010 09:47:59 +0000 Subject: [PATCH] add a "probe" driver to support autodetection of cables git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1770 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/ChangeLog | 8 +++++++ urjtag/include/urjtag/cable.h | 2 ++ urjtag/src/cmd/cmd_cable.c | 15 +++++++++++++ urjtag/src/tap/cable/generic_usbconn.c | 30 ++++++++++++++++++++++++++ 4 files changed, 55 insertions(+) diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 613150ed..f0f469cb 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -1,3 +1,11 @@ +2010-02-08 Mike Frysinger + + * include/urjtag/cable.h (urj_tap_cable_usb_probe): New prototype. + * src/tap/cable/generic_usbconn.c (urj_tap_cable_usb_probe): New function + to autodetect USB cables. + * src/cmd/cmd_cable.c (cmd_cable_run): Add a new "probe" driver to call each + busses' autodetection routine. + 2010-02-08 Jie Zhang * include/urjtag/part.h (struct URJ_PART_PARAMS): Add wait_ready. diff --git a/urjtag/include/urjtag/cable.h b/urjtag/include/urjtag/cable.h index 0038551f..a536e807 100644 --- a/urjtag/include/urjtag/cable.h +++ b/urjtag/include/urjtag/cable.h @@ -227,6 +227,8 @@ urj_cable_t *urj_tap_cable_parport_connect (urj_chain_t *chain, urj_cable_t *urj_tap_cable_usb_connect (urj_chain_t *chain, const urj_cable_driver_t *driver, const urj_param_t *params[]); +int urj_tap_cable_usb_probe (char *params[]); + /** * API function to connect to a type-other cable * diff --git a/urjtag/src/cmd/cmd_cable.c b/urjtag/src/cmd/cmd_cable.c index 87ddc281..874ac7f1 100644 --- a/urjtag/src/cmd/cmd_cable.c +++ b/urjtag/src/cmd/cmd_cable.c @@ -39,6 +39,12 @@ #include "cmd.h" +static int +cable_probe (char *params[]) +{ + return urj_tap_cable_usb_probe (params); +} + static int cmd_cable_run (urj_chain_t *chain, char *params[]) { @@ -61,6 +67,14 @@ cmd_cable_run (urj_chain_t *chain, char *params[]) return URJ_STATUS_FAIL; } + if (strcasecmp (params[1], "probe") == 0 && cable_probe (params)) + { + urj_error_set (URJ_ERROR_NOTFOUND, + _("%s: automatic probe found nothing"), + params[0]); + return URJ_STATUS_FAIL; + } + /* maybe old syntax was used? search connection type driver */ for (i = 0; urj_tap_parport_drivers[i]; i++) if (strcasecmp (params[1], @@ -169,6 +183,7 @@ cmd_cable_help (void) "DRIVER_OPTS options for the selected cable\n" "\n" "Type \"cable DRIVER help\" for info about options for cable DRIVER.\n" + "You can also use the driver \"probe\" to attempt autodetection.\n" "\n" "List of supported cables:\n"), "cable"); diff --git a/urjtag/src/tap/cable/generic_usbconn.c b/urjtag/src/tap/cable/generic_usbconn.c index bb2135bc..d65ee298 100644 --- a/urjtag/src/tap/cable/generic_usbconn.c +++ b/urjtag/src/tap/cable/generic_usbconn.c @@ -173,3 +173,33 @@ urj_tap_cable_generic_usbconn_help (urj_log_level_t ll, const char *cablename) "DESC Some string to match in description or serial no.\n" "\n"), cablename); } + +int +urj_tap_cable_usb_probe (char *params[]) +{ + int i,j; + urj_usbconn_t *conn; + + urj_log_level_t old_level = urj_log_state.level; + urj_log_state.level = URJ_LOG_LEVEL_SILENT; + + for (i = 0; urj_tap_usbconn_drivers[i]; ++i) + { + for (j = 0; urj_tap_cable_usbconn_cables[j]; ++j) + { + urj_usbconn_cable_t cable_try = *(urj_tap_cable_usbconn_cables[j]); + conn = urj_tap_usbconn_drivers[i]->connect (&cable_try, NULL); + if (conn) + { + urj_log_state.level = old_level; + params[1] = (char *)urj_tap_cable_usbconn_cables[j]->name; + urj_log (URJ_LOG_LEVEL_NORMAL, + _("Found USB cable: %s\n"), params[1]); + return URJ_STATUS_OK; + } + } + } + + urj_log_state.level = old_level; + return URJ_STATUS_FAIL; +}