Linux-DVB-DVBT

 view release on metacpan or  search on metacpan

clib/dvb_lib/dvb_tune.c  view on Meta::CPAN


    if ( (rc=dvb_frontend_open(h, /* write=1*/1)) < 0 )
    {
    	if (dvb_debug>1) fprintf(stderr,"unable to open rw frontend\n");
    	if (dvb_debug>1) _fn_end((char *)__FUNCTION__, rc) ;

    	RETURN_DVB_ERROR(rc);;
    }

    if (dvb_debug>1) _dump_state((char *)__FUNCTION__, "at start", h) ;
   	if (dvb_debug>1) {_prt_indent((char *)__FUNCTION__) ; fprintf(stderr, "OFDM\n") ; }

	params_to_frontend(
		frequency,
		inversion,
		bandwidth,
		code_rate_high,
		code_rate_low,
		modulation,
		transmission,
		guard_interval,
		hierarchy,
		&h->p) ;

    if (0 == memcmp(&h->p, &h->plast, sizeof(h->plast))) {
		if (dvb_frontend_is_locked(h)) {
		    /* same frequency and frontend still locked */
		    if (dvb_debug) fprintf(stderr,"dvb fe: skipped tuning\n");
		    rc = 0;
		    goto done;
		}
    }

if (dvb_debug>1) _dump_state((char *)__FUNCTION__, "before ioctl call", h) ;

    rc = ERR_GENERIC ;
if (dvb_debug>1) {_prt_indent((char *)__FUNCTION__) ; fprintf(stderr, "xiotcl(FE_SET_FRONTEND)\n") ; }
    if ( (rc=xioctl(h->fdwr,FE_SET_FRONTEND,&h->p)) < 0) {
    	// failed
	    if (dvb_debug) dump_fe_info(h);
		goto done;
    }

    if (dvb_debug)
    	dump_fe_info(h);

    memcpy(&h->plast, &h->p, sizeof(h->plast));
    rc = 0;

done:

	if (dvb_debug>1) _fn_end((char *)__FUNCTION__, rc) ;

    // Hmm, the driver seems not to like that :-/
    // dvb_frontend_release(h,1);
	RETURN_DVB_ERROR(rc);;
}

/* ----------------------------------------------------------------------- */
/* Returns true if any other process currently has this frontend in use */
int dvb_frontend_is_busy(struct dvb_state *h)
{
int rc;
int is_busy = 0 ;

    if ( (rc=dvb_frontend_open(h, /* write=1*/1)) < 0 )
    {
    	is_busy = 1 ;
    }
    else
    {
    	dvb_frontend_release(h, /* write */ 1) ;
    }

    return is_busy ;
}

/* ----------------------------------------------------------------------- */
/* print tuning settings */
void dvb_frontend_tune_info(struct dvb_state *h)
{
struct dvb_frontend_parameters info ;
	
    if (xioctl(h->fdro,FE_GET_FRONTEND,&info) != 0)
    {
//		dump_fe_info(h);
//		goto done;
        if (dvb_debug>=5)
        {
        	fprintf(stderr, "Error reading FE info\n") ;
        }
    }
    else
    {
		if (dvb_debug>=5)
		{
			fprintf(stderr, "readback tuning:\n") ;
			_dump_frontend_params(0, &info) ;
		}
    }

}


/* ----------------------------------------------------------------------- */
int dvb_frontend_is_locked(struct dvb_state *h)
{
    fe_status_t  status  = 0;

    if (ioctl(h->fdro, FE_READ_STATUS, &status) < 0) {
    	if (dvb_debug>1) perror("dvb fe: ioctl FE_READ_STATUS");
		return 0;
    }
if (dvb_debug>=10) fprintf(stderr, "frontend status=0x%04x\n", status) ;

    return (status & FE_HAS_LOCK);
}

/* ----------------------------------------------------------------------- */
int dvb_signal_quality(struct dvb_state *h, 
	unsigned 		*ber,
	unsigned		*snr,
	unsigned		*strength,
	unsigned		*uncorrected_blocks
)
{
uint32_t 		ber32 ;
int16_t			snr16 ;
int16_t			strength16 ;
uint32_t		uncorrected_blocks32 ;
int ok = 1 ;

	*ber = 0 ;
	*snr = 0 ;
	*strength = 0 ;



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