Add option to access device by USB Bus:Device

Allow to select the device we want to talk to by providing
USB Bus:Device string.

Signed-off-by: Matthias Brugger <matthias.bgg@kernel.org>
Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
This commit is contained in:
Matthias Brugger 2020-03-31 21:23:05 +02:00 committed by Heinrich Schuchardt
parent ecf63a1367
commit bfda54e8ac
2 changed files with 30 additions and 1 deletions

View File

@ -68,6 +68,8 @@ Use not the first but the given device in the sequence of detected devices,
starting with "0" for the first device (see scan option)
.IP \-D
Same as \-d, but choose by serial number (see scan option)
.IP \-U
Same as \-d, but choose by USB Bus:Device the device is connected to (e.g. 001:003)
.IP \-n
do not print "ON" and "OFF", but "1" and "0" instead
.IP \-q

View File

@ -154,6 +154,7 @@ static void print_usage(char* name)
" 'm' - get power supply status outlet(s) on/off\n"
" 'd' - apply to device 'n'\n"
" 'D' - apply to device with given serial number\n"
" 'U' - apply to device connected to USB Bus:Device\n"
" 'n' - show result numerically\n"
" 'q' - quiet mode, no explanations - but errors\n"
" 'a' - get schedule for outlet\n"
@ -212,7 +213,7 @@ static void parse_command_line(int argc, char* argv[], int count,
bindaddr=BINDADDR;
#endif
while( (c=getopt(argc, argv,"i:o:f:t:a:A:b:g:m:lLqvh?nsd:D:u:p:")) != -1 ) {
while( (c=getopt(argc, argv,"i:o:f:t:a:A:b:g:m:lLqvh?nsd:D:u:p:U:")) != -1 ) {
if (count == 0) {
switch(c) {
case '?':
@ -360,6 +361,32 @@ static void parse_command_line(int argc, char* argv[], int count,
exit(-8);
}
break;
case 'U': // by USB Bus:Device
for (j=0; j < count; ++j) {
char tmp[8194];
sprintf(tmp, "%s:%s", dev[j]->bus->dirname, dev[j]->filename);
if (debug)
fprintf(stderr, "now comparing %s and %s\n", tmp, optarg);
if (strcasecmp(tmp, optarg) == 0) {
if (udev != NULL) {
usb_close(udev);
udev = NULL;
}
devnum = j;
break;
}
}
if (devnum != j) {
fprintf(stderr, "No device at USB Bus:Device %s found.\n"
"Terminating\n",optarg);
if (udev != NULL) {
usb_close(udev);
udev = NULL;
}
exit(-8);
}
break;
case 'o':
outlet=check_outlet_number(id, i);
sispm_switch_on(udev,id,outlet);