[dahdi-commits] tzafrir: branch tools/tzafrir/sysfs r5935 - in /tools/team/tzafrir/sysfs/xpp/...
SVN commits to the DAHDI project
dahdi-commits at lists.digium.com
Sat Jan 31 06:00:14 CST 2009
Author: tzafrir
Date: Sat Jan 31 06:00:14 2009
New Revision: 5935
URL: http://svn.digium.com/svn-view/dahdi?view=rev&rev=5935
Log:
Half-working sysfs support in dahdi-perl .
Modified:
tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi.pm
tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Chans.pm
tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm
Modified: tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi.pm
URL: http://svn.digium.com/svn-view/dahdi/tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi.pm?view=diff&rev=5935&r1=5934&r2=5935
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi.pm (original)
+++ tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi.pm Sat Jan 31 06:00:14 2009
@@ -33,6 +33,7 @@
=cut
my $proc_base = "/proc/dahdi";
+my $sysfs_base = '/sys/bus/spans/devices';
=head1 spans()
@@ -43,11 +44,19 @@
sub spans() {
my @spans;
- -d $proc_base or return ();
- foreach my $zfile (glob "$proc_base/*") {
- $zfile =~ s:$proc_base/::;
- my $span = Dahdi::Span->new($zfile);
- push(@spans, $span);
+ if ( -d $sysfs_base) {
+ foreach my $zfile (glob "$sysfs_base/span-*") {
+ my $span = Dahdi::Span->new($zfile);
+ push(@spans, $span);
+ }
+ } elsif ( -d $proc_base ) {
+ foreach my $zfile (glob "$proc_base/*") {
+ $zfile =~ s:$proc_base/::;
+ my $span = Dahdi::Span->new_procfs($zfile);
+ push(@spans, $span);
+ }
+ } else {
+ return ();
}
@spans = sort { $a->num <=> $b->num } @spans;
return @spans;
Modified: tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Chans.pm
URL: http://svn.digium.com/svn-view/dahdi/tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Chans.pm?view=diff&rev=5935&r1=5934&r2=5935
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Chans.pm (original)
+++ tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Chans.pm Sat Jan 31 06:00:14 2009
@@ -86,7 +86,62 @@
"Unconfigured"
);
-sub new($$$$$$) {
+sub _get_dev_attr($$) {
+ my $self = shift;
+ my $attr = shift;
+
+ my $attr_file = $self->{DEV_DIR}."/$attr";
+
+ open(ATTR, $attr_file) or die "Failed to read SysFS attribute $attr_file\n";
+ my $value = <ATTR>;
+ close(ATTR);
+ chomp $value;
+ return $value;
+}
+
+sub new($$$) {
+ my $pack = shift or die "Wasn't called as a class method\n";
+ my $span = shift or die "Missing a span parameter\n";
+ my $dev_dir = shift or die "Missing SysFS path parameter\n";
+ my $index = $1;
+ if ($dev_dir !~ /:(\d)+$/) {
+ die "Malformed SysFS device name $dev_dir\n";
+ }
+ my $self = {
+ 'SPAN' => $span,
+ 'DEV_DIR' => $dev_dir,
+ 'INDEX' => $index,
+ };
+ bless $self, $pack;
+ $self->{NUM} = $self->_get_dev_attr('channo');
+ $self->{FQN} = $self->_get_dev_attr('name'); # TODO: correct?
+
+ # FIXME: resolve numbers to string
+ $self->{ALARMS} = [];
+ my $alarms = $self->_get_dev_attr('chan_alarms');
+ if ($alarms) {$self->{ALARMS} = [$alarms]}
+
+ $self->{SIGNALLING} = hex($self->_get_dev_attr('sig'));
+ $self->{SIGCAP} = hex($self->_get_dev_attr('sigcap'));
+ # INFO?
+ # BATTERY
+
+ # TODO: Where do I get __DAHDI_SIG_FXS and __DAHDI_SIG_FXO from?
+ my $maybe_fxs = $self->{SIGCAP} & (1 << 12);
+ my $maybe_fxo = $self->{SIGCAP} & (1 << 13);
+ if ( $maybe_fxs && (not $maybe_fxo) ) {
+ $self->{TYPE} = 'FXS';
+ } elsif ( (not $maybe_fxs) && $maybe_fxo) {
+ $self->{TYPE} = 'FXO';
+ } else {
+ }
+
+ $self->{INFO} = 'FIXME INFO';
+
+ return $self;
+}
+
+sub new_procfs($$$$$$) {
my $pack = shift or die "Wasn't called as a class method\n";
my $span = shift or die "Missing a span parameter\n";
my $index = shift;
Modified: tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm
URL: http://svn.digium.com/svn-view/dahdi/tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm?view=diff&rev=5935&r1=5934&r2=5935
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm (original)
+++ tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm Sat Jan 31 06:00:14 2009
@@ -49,7 +49,7 @@
=head2 chans()
-The list of the channels (L<Dahdi::Chan> objects) of this span.
+The list of the channels (L<Dahdi::Chans> objects) of this span.
In a scalar context returns the number of channels this span has.
=head2 bchans()
@@ -170,18 +170,69 @@
$self->{TYPE} = "${proto}_$self->{TERMTYPE}";
}
+sub _get_span_xpdinfo($) {
+ my $self = shift;
+ $self->{TYPE} = "UNKNOWN";
+ my @xpds = Dahdi::Xpp::Xpd::xpds_by_spanno;
+ my $num = $self->{NUM};
+ my $xpd = $xpds[$num];
+ if(defined $xpd) {
+ die "Spanno mismatch: $xpd->spanno, $num" unless $xpd->spanno == $num;
+ $self->{XPD} = $xpd;
+ }
+}
+
+sub _get_dev_attr($$) {
+ my $self = shift;
+ my $attr = shift;
+
+ my $attr_file = $self->{DEV_DIR}."/$attr";
+
+ open(ATTR, $attr_file) or die "Failed to read SysFS attribute $attr_file\n";
+ my $value = <ATTR>;
+ chomp $value;
+ return $value;
+}
+
+
+# TYPE
+# IS_BRI
+# IS_PRI
sub new($$) {
+ my $pack = shift or die "Wasn't called as a class method\n";
+ my $dev_dir = shift or die "Missing sysfs path parameter\n";
+ $dev_dir =~ m{.*/span-(\d+)$};
+ my $num = $1;
+ my $num_str = sprintf "%03d", $num;
+ defined($num) or die "can't figure span number from $dev_dir\n";
+ my $self = { NUM => $num, DEV_DIR => $dev_dir };
+ bless $self, $pack;
+
+ $self->_get_span_xpdinfo();
+ $self->{IS_DIGITAL} = $self->_get_dev_attr('is_digital');
+ $self->{IS_DAHDI_SYNC_MASTER} = $self->_get_dev_attr('is_sync_master');
+ $self->{NAME} = $self->_get_dev_attr('name');
+ $self->{DESCRIPTION} = $self->_get_dev_attr('desc');
+ # TODO: span alarms?
+
+ $self->{CHANS} = [];
+ my @channels;
+ foreach my $chan_dev_dir (glob("$dev_dir/$num_str:[0-9][0-9]")) {
+ my $chan = Dahdi::Chans->new($self, $chan_dev_dir);
+ push(@channels, $chan);
+ }
+ @channels = sort { $a->num <=> $b->num } @channels;
+ $self->{CHANS} = \@channels;
+
+
+ return $self;
+}
+
+sub new_procfs($$) {
my $pack = shift or die "Wasn't called as a class method\n";
my $num = shift or die "Missing a span number parameter\n";
my $self = { NUM => $num };
bless $self, $pack;
- $self->{TYPE} = "UNKNOWN";
- my @xpds = Dahdi::Xpp::Xpd::xpds_by_spanno;
- my $xpd = $xpds[$num];
- if(defined $xpd) {
- die "Spanno mismatch: $xpd->spanno, $num" unless $xpd->spanno == $num;
- $self->{XPD} = $xpd;
- }
open(F, "$proc_base/$num") or die "Failed to open '$proc_base/$num\n";
my $head = <F>;
chomp $head;
@@ -231,7 +282,7 @@
s/\s*$//;
next unless /\S/;
next unless /^\s*\d+/; # must be a real channel string.
- my $c = Dahdi::Chans->new($self, $index, $_);
+ my $c = Dahdi::Chans->new_procfs($self, $index, $_);
push(@channels, $c);
$index++;
}
More information about the dahdi-commits
mailing list