summaryrefslogtreecommitdiff
path: root/xpp/utils/xpp_blink
blob: 65be247d3c864cee5e904229b19d6fb0391fd6fd (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#! /usr/bin/perl -w
#
# Written by Oron Peled <oron@actcom.co.il>
# Copyright (C) 2007, Xorcom
# This program is free software; you can redistribute and/or
# modify it under the same terms as Perl itself.
#
# $Id$
#
use strict;
use File::Basename;
BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/zconf"); }

use Zaptel;
use Zaptel::Span;
use Zaptel::Xpp;
use Zaptel::Xpp::Xbus;

sub usage {
	die "Usage: $0 {on|off|bzzt} {span <number> | xpd <bus num> [<xpd num>]}\n";
}

my $state = shift;
my $selector = shift;
usage unless defined($state) and $state =~ /^(on|off|bzzt)$/;
usage unless defined($selector) and $selector =~ /^(span|xpd)$/i;

my $xpd;
my @xpds;
my @channels;

if($selector =~ /^span$/i) {
	my $number = shift;
	usage unless defined($number) and $number =~ /^\d+/;
	my $span = Zaptel::Span::by_number($number);
	die "Unkown Span $number\n" unless $span;
	$xpd = Zaptel::Xpp::xpd_of_span($span);
	die "Span $number is not an XPD\n" unless defined $xpd;
	my $xpdname = $xpd->fqn;
	my $connector = $xpd->xbus->connector;
	die "$xpdname is not connected\n" unless defined $connector;
	push(@xpds, $xpd);
	my @chans = $span->chans();
	@channels = join(' ', map { $_->num } @chans);
	printf "Using %s (connected via $connector): channels @channels\n", $xpd->fqn;
} elsif($selector =~ /^xpd$/i) {
	my $busnum = shift;
	my $xpdnum = shift;
	usage unless defined($busnum) and $busnum =~ /^\d+/;
	my $xbus = Zaptel::Xpp::Xbus::by_number($busnum);
	die "Unkown XBUS number $busnum\n" unless defined $xbus;
	if(defined $xpdnum) {
		usage unless $xpdnum =~ /^\d+/;
		$xpd = $xbus->get_xpd_by_number($xpdnum);
		die "Unkown XPD number $xpdnum on XBUS number $busnum\n" unless defined $xpd;
		push(@xpds, $xpd);
	} else {
		@xpds = $xbus->xpds;
		die "XBUS number $busnum has no XPDS!\n" unless @xpds;
	}
}

if($state eq 'on') {
	$_->blink(1) foreach (@xpds);
} elsif($state eq 'off') {
	$_->blink(0) foreach (@xpds);
} elsif($state eq 'bzzt') {
	$_->blink(1) foreach (@xpds);
	sleep 1;
	$_->blink(0) foreach (@xpds);
}

__END__

=head1 NAME

xpp_blink - Blink the leds of a specified XPD

=head1 SYNOPSIS

xpp_blink {on|off|bzzt} {span <number> | xpd <bus num> [<xpd num>]}\n";

=head1 DESCRIPTION

Blink all the leds of an XPD.

=head2 Blink mode:

=over 16

=item on	Turn on constant blink

=item off	Turn off blink

=item bzzt	Blink briefly for 1 second.

=back

=head2 Selector:

=over 16

=item span	Select by span number. This only work for XPD registered to zaptel.
		will also print the zaptel channels of the span and the
		xbus/xpd this span represents.

=item xpd	Select by xbus + xpd numbers. If only xbus number is given, all the
		XPDs of the selected xbus (Astribank) are blinked.

=back

=head1 EXAMPLES

  $ xpp_blink bzzt span 2
  Using XBUS-04/XPD-10 (connected via usb-0000:00:1d.7-1): channels 15 16 17 18 19 20 21 22

  $ xpp_blink xpd 0 1

  $ xpp_blink xpd 0