summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>2008-10-27 16:07:50 +0000
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>2008-10-27 16:07:50 +0000
commit3b4245ea23aa60842f9dbf5a152ee389d559dbf3 (patch)
treebb95489766707c7ee1e13d9d40c549d4105d1f43
parentf48e3505473b9be26fa6d71c8437a87abde608f1 (diff)
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
-rw-r--r--xpp/perl_modules/Dahdi/Xpp.pm2
-rw-r--r--xpp/perl_modules/Dahdi/Xpp/Line.pm48
2 files changed, 34 insertions, 16 deletions
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 (<F>) {
- 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 = <F>;
+ 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 (<F>) {
+ 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;