Linux-DVB-DVBT

 view release on metacpan or  search on metacpan

script/dvbt-strength  view on Meta::CPAN

			   'a|adap|dvb=i' => \$adapter,
			   'munin=s' => \$munin,
			   'hw|hwcheck' => \$hwcheck,
			   'mail=s' => \$mail,
			   ) or pod2usage(2) ;


    pod2usage(1) if $help;
    pod2usage(-verbose => 2) if $man;

    my $dvb_name = sprintf "DVB%d", $adapter ;

	info("===============================================================") if $VERBOSE ;
	info("$progname v$VERSION") if $VERBOSE ;
	info("Linux::DVB::DVBT v$Linux::DVB::DVBT::VERSION") if $VERBOSE ;

	Linux::DVB::DVBT->debug($DEBUG) ;
	Linux::DVB::DVBT->dvb_debug($DEBUG) ;

	## Create dvb
	## NOTE: With default object settings, the application will
	## die on *any* error, so there is no error checking in this script
	##
	my $dvb = Linux::DVB::DVBT->new(
		'adapter_num' => $adapter,
		'errmode' => 'message',
	) ;
	Linux::DVB::DVBT::prt_data("dvb=", $dvb) if $DEBUG ;

	my $errors_aref = $dvb->errors() ;
	if ( @$errors_aref )
	{
		my $error = join(', ', @$errors_aref) ;
		failed("Adapter $adapter not working : $error", $dvb_name, $hwcheck, $mail) ;
	}
	
	# use other config?
	$dvb->config_path($config) if $config ;

	info("== Locked $dvb_name ==") if $VERBOSE ;
	
	## get strength info
	my %info ;
	
	eval {
		%info = $dvb->tsid_signal_quality() ;
	} ;
	
	## Release DVB (for next recording)
	info("== Released $dvb_name ==") if $VERBOSE ;
	$dvb->dvb_close() ;
	
	if ($@)
	{
		## expected this to work
		failed($@, $dvb_name, $hwcheck, $mail) ;
	}
	
	Linux::DVB::DVBT::prt_data("Info=", \%info) if $DEBUG ;
	
	## Check for device busy
	foreach my $tsid (keys %info)
	{
		if ($info{$tsid}{'error'} && ($info{$tsid}{'error'} =~ /device busy/i)) 
		{
			if ($VERBOSE)
			{
				info("DVB IN USE") ;
			}
			else
			{
				if (!$munin)
				{
					print "DVB adapter is in use, please try again later.\n" ;
				}
			}
			exit 1 ;
		}
	}
	
	
	## output
	my $fh ;
	if ($munin)
	{
		open $fh, ">>$munin" or die "Error: unable to write to munin log file $munin : $!" ;
		my $timestamp = timestamp() ;
		printf $fh "[$timestamp DVB%d] ", $adapter ;
	}
	else
	{
		printf "%5s  : %8s %%\n", "TSID", "Strength" ;
	}
	foreach my $tsid (sort {$a <=> $b} keys %info)
	{
		$info{$tsid}{'strength'} ||= 0 ;
		my $err = "" ;
		my $percent = ($info{$tsid}{'strength'} * 100.0) / 65535.0 ;
		if (!$munin)
		{
			if ($info{$tsid}{'error'})
			{
				$err = "# $info{$tsid}{'error'}" ;
			}
			printf "%5d  : %8.2f %% $err\n", $tsid, $percent ;
		}
		else
		{
			if ($info{$tsid}{'error'})
			{
				$err = "($info{$tsid}{'error'}) " ;
			}
			printf $fh "%d=%.2f $err", $tsid, $percent ;
		}
		Linux::DVB::DVBT::prt_data("TSID $tsid = ", $info{$tsid}) if $DEBUG ;
	}

	if ($munin)
	{
		print $fh "\n" ;
		close $fh if $fh ;
	}

	## End



( run in 0.894 second using v1.01-cache-2.11-cpan-39bf76dae61 )