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
master
Mike Frysinger 15 years ago
parent dd77752ee7
commit 135ca2ef80

@ -1,3 +1,11 @@
2010-02-08 Mike Frysinger <vapier@gentoo.org>
* 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 <jie.zhang@analog.com>
* include/urjtag/part.h (struct URJ_PART_PARAMS): Add wait_ready.

@ -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
*

@ -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");

@ -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;
}

Loading…
Cancel
Save