forked from dpenkler/linux-usbtmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis_usbtmc_parent
executable file
·42 lines (36 loc) · 1.17 KB
/
is_usbtmc_parent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl
# find if usb device is 'parent' to a usbtmc device
# returns 'true' (exit 0) if so
# Assumes that usb device is something like:
# (stuff)/usb1/1-3
# and that the child device is something like:
# (stuff)/usb1/1-3/1-3:2.4
# identified as a usbtmc device by having "DRIVER=usbtmc" in its uevent file.
#
# There might be a more elegant solution using udevadm, but didn't find it.
my $DEBUG = 0;
open(D,">>/var/log/usbtmc.log") if $DEBUG;
$devpath=$ENV{'DEVPATH'};
$devpath=shift if $DEBUG && !defined($devpath);
print D "devpath = $devpath\n" if $DEBUG;
exit 1 unless $devpath =~ /\/usb\d+\/(\d+\-\d+)$/;
my $tag = $1;
print D "got usb devpath tag $tag\n" if $DEBUG;
open(X,"find /sys${devpath} -maxdepth 2 -mindepth 2 -name uevent|") || die "find problem";
while (<X>) {
chomp;
next unless /$tag\/$tag:\d+\.\d+\/uevent/;
print D "uevent file $_\n" if $DEBUG;
$uev = $_;
open(Y,"<$uev") || die "error opening $uev";
while (<Y>) {
chomp;
next unless /^DRIVER=usbtmc\s*$/;
print D "got usbtmc child device\n" if $DEBUG;
exit 0;
}
close(Y);
}
close(X);
print D "not a usbtmc parent device\n" if $DEBUG;
exit 1;