Debian Codegraph @

xpp/xpp_blink

raw
1 #! /usr/bin/perl -w
2 #
3 # Written by Oron Peled <[email protected]>
4 # Copyright (C) 2007, Xorcom
5 # This program is free software; you can redistribute and/or
6 # modify it under the same terms as Perl itself.
7 #
8 # $Id$
9 #
10 use strict;
11 use File::Basename;
12 BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); }
13
14 use Dahdi;
15 use Dahdi::Span;
16 use Dahdi::Xpp;
17 use Dahdi::Xpp::Xbus;
18
19 sub usage {
20 die "Usage: $0 {on|off|bzzt} {span <number> | chan <number> | xpd <bus num> [<xpd num>] | label <label>}\n";
21 }
22
23 my $state = shift;
24 my $selector = shift;
25 usage unless defined($state) and $state =~ /^(on|off|bzzt)$/;
26 usage unless defined($selector) and $selector =~ /^(span|chan|xpd|label)$/i;
27
28 my $xpd;
29 my @blinklist;
30 my @channels;
31
32 if($selector =~ /^span$/i) {
33 my $number = shift;
34 usage unless defined($number) and $number =~ /^\d+/;
35 my $span = Dahdi::Span::by_number($number);
36 die "Unkown Span $number\n" unless $span;
37 $xpd = Dahdi::Xpp::xpd_of_span($span);
38 die "Span $number is not an XPD\n" unless defined $xpd;
39 my $xpdname = $xpd->fqn;
40 my $connector = $xpd->xbus->connector;
41 die "$xpdname is not connected\n" unless defined $connector;
42 push(@blinklist, $xpd);
43 my @chans = $span->chans();
44 @channels = join(' ', map { $_->num } @chans);
45 printf "Using %s (connected via $connector): channels @channels\n", $xpd->fqn;
46 } elsif($selector =~ /^chan$/i) {
47 my $channo = shift;
48 usage unless defined($channo) and $channo =~ /^\d+/;
49 my @spans = Dahdi::spans();
50 my @chans = map { $_->chans() } @spans;
51 my ($chan) = grep { $_->num eq $channo } @chans;
52 die "Channel $channo was not found\n" unless defined $chan;
53 die "Cannot blink Input ports\n" if $chan->type eq 'IN';
54 die "Cannot blink Output ports\n" if $chan->type eq 'OUT';
55 push(@blinklist, $chan);
56 } elsif($selector =~ /^xpd$/i) {
57 my $busnum = shift;
58 my $xpdnum = shift;
59 my $linenum = shift;
60 usage unless defined($busnum) and $busnum =~ /^\d+/;
61 my $xbus = Dahdi::Xpp::Xbus::by_number($busnum);
62 die "Unkown XBUS number $busnum\n" unless defined $xbus;
63 if(defined $xpdnum) {
64 usage unless $xpdnum =~ /^\d+/;
65 $xpd = $xbus->get_xpd_by_number($xpdnum);
66 die "Unkown XPD number $xpdnum on XBUS number $busnum\n" unless defined $xpd;
67 if(defined $linenum) {
68 usage unless $linenum =~ /^\d+/;
69 my $lines = $xpd->lines;
70 my $l = @{$lines}[$linenum];
71 die "Bad line number $linenum on XPD $xpd->fqn\n" unless defined $l;
72 push(@blinklist, $l);
73 } else {
74 push(@blinklist, $xpd);
75 }
76 } else {
77 @blinklist = $xbus->xpds;
78 die "XBUS number $busnum has no XPDS!\n" unless @blinklist;
79 }
80 } elsif($selector =~ /^label$/i) {
81 my $label = shift;
82 usage unless defined($label);
83 my $xbus = Dahdi::Xpp::Xbus::by_label($label);
84 die "Unkown XBUS label $label\n" unless defined $xbus;
85 @blinklist = $xbus->xpds;
86 die "XBUS label '$label' has no XPDS!\n" unless @blinklist;
87 }
88
89 if($state eq 'on') {
90 $_->blink(1) foreach (@blinklist);
91 } elsif($state eq 'off') {
92 $_->blink(0) foreach (@blinklist);
93 } elsif($state eq 'bzzt') {
94 $_->blink(1) foreach (@blinklist);
95 sleep 1;
96 $_->blink(0) foreach (@blinklist);
97 }
98
99 __END__
100
101 =head1 NAME
102
103 xpp_blink - Blink the leds of a specified XPD
104
105 =head1 SYNOPSIS
106
107 xpp_blink {on|off|bzzt} {span <number> | chan <number> | xpd <bus num> [<xpd num> [<lineno>]]}
108
109 =head1 DESCRIPTION
110
111 Blink all the leds of an XPD.
112
113 =head2 Blink mode:
114
115 =over
116
117 =item on
118
119 Turn on constant blink
120
121 =item off
122
123 Turn off blink
124
125 =item bzzt
126
127 Blink briefly for 1 second.
128
129 =back
130
131 =head2 Selector:
132
133 =over
134
135 =item span
136
137 Select by span number. This only work for XPD registered to dahdi.
138
139 will also print the dahdi channels of the span and the xbus/xpd this
140 span represents.
141
142 =item chan
143
144 Select by channel number. This only work for XPD registered to dahdi.
145
146 =item xpd
147
148 Select by xbus + xpd numbers. If only xbus number is given, all the
149 XPDs of the selected xbus (Astribank) are blinked.
150
151 =item label
152
153 Select by xbus label. Affect the whole Astribank.
154
155 =back
156
157 =head1 EXAMPLES
158
159 $ xpp_blink bzzt span 2
160 Using XBUS-04/XPD-10 (connected via usb-0000:00:1d.7-1): channels 15 16 17 18 19 20 21 22
161
162 $ xpp_blink bzzt chan 18
163
164 $ xpp_blink on xpd 0 1 5
165
166 $ xpp_blink off xpd 0
167
168 $ xpp_blink bzzt label 'usb:00000238'