From 3b4245ea23aa60842f9dbf5a152ee389d559dbf3 Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Mon, 27 Oct 2008 16:07:50 +0000 Subject: perl xpp: Support for FXO batter attribute from sysfs (from r5133). Still falls back to reading the battery status from procfs. Also fixes error message. git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@5134 a0bf4364-ded3-4de4-8d8a-66a801d63aff --- xpp/perl_modules/Dahdi/Xpp.pm | 2 +- xpp/perl_modules/Dahdi/Xpp/Line.pm | 48 ++++++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 16 deletions(-) (limited to 'xpp/perl_modules') diff --git a/xpp/perl_modules/Dahdi/Xpp.pm b/xpp/perl_modules/Dahdi/Xpp.pm index f2811aa..eeb7bcb 100644 --- a/xpp/perl_modules/Dahdi/Xpp.pm +++ b/xpp/perl_modules/Dahdi/Xpp.pm @@ -40,7 +40,7 @@ sub xpd_attr_path($$$@) { unless(-f $file) { my $procfile = sprintf "/proc/xpp/XBUS-%02d/XPD-%1d%1d/$attr", $busnum, $unitnum, $subunitnum; - warn "$0: OLD DRIVER: missing '$file'. Fall back to '$procfile'\n"; + warn "$0: OLD DRIVER: missing '$file'. Fall back to /proc\n"; $file = $procfile; } next unless -f $file; diff --git a/xpp/perl_modules/Dahdi/Xpp/Line.pm b/xpp/perl_modules/Dahdi/Xpp/Line.pm index 2320bc7..507b2e2 100644 --- a/xpp/perl_modules/Dahdi/Xpp/Line.pm +++ b/xpp/perl_modules/Dahdi/Xpp/Line.pm @@ -69,23 +69,41 @@ sub create_all($$) { } $xpd->{LINES} = \@lines; if($xpd->type eq 'FXO') { - my ($infofile) = glob "$procdir/*_info"; - die "Failed globbing '$procdir/*_info'" unless defined $infofile; - open(F, "$infofile") || die "Failed opening '$infofile': $!"; - my $battery_info = 0; - while () { - chomp; - $battery_info = 1 if /^Battery:/; - if($battery_info && s/^\s*on\s*:\s*//) { - my @batt = split; - foreach my $l (@lines) { - die unless @batt; - my $state = shift @batt; - $l->{BATTERY} = ($state eq '+') ? 1 : 0; + my $file = Dahdi::Xpp::xpd_attr_path( + $xpd->xbus->num, + $xpd->unit, + $xpd->subunit, "fxo_battery"); + if(defined $file) { + open(F, "$file") || die "Failed opening '$file': $!"; + my $battery_line = ; + close F; + my @batt = split(/\s+/, $battery_line); + foreach my $l (@lines) { + die unless @batt; + my $state = shift @batt; + $l->{BATTERY} = ($state eq '+') ? 1 : 0; + } + } else { + # Fallback to old interface + my ($infofile) = glob "$procdir/*_info"; + die "Failed globbing '$procdir/*_info'" unless defined $infofile; + open(F, "$infofile") || die "Failed opening '$infofile': $!"; + my $battery_info = 0; + while () { + chomp; + $battery_info = 1 if /^Battery:/; + if($battery_info && s/^\s*on\s*:\s*//) { + my @batt = split; + foreach my $l (@lines) { + die unless @batt; + my $state = shift @batt; + $l->{BATTERY} = ($state eq '+') ? 1 : 0; + } + $battery_info = 0; + die if @batt; } - $battery_info = 0; - die if @batt; } + close F; } } close F; -- cgit v1.2.3