Ejemplo n.º 1
0
void
MyTagsTuner::onTagClicked( QListWidgetItem* i )
{
	QString tag = i->data( Qt::DisplayRole ).toString();
	emit tune( RadioStation::globalTag( tag ) );
	i->setSelected( false );
}
Ejemplo n.º 2
0
int sid_our_file (char *filename)
{
    int ret;

#ifdef DEBUG
    printf ("sid_our_file (%s) ", filename);
#endif
    // If an errors occured do not claim the file
    if (sidplayer.error)
        return 0;

    {
        SidTune tune(filename);
        if (!tune)
	{
#ifdef DEBUG
            printf ("[No]\n");
#endif
            return 0;
        }
    }
#ifdef DEBUG
    printf ("[Yes]\n");
#endif
    return 1;
}
Ejemplo n.º 3
0
    void sample(int iterations, int burn, int adapt, int thin) {
      double logp_value,old_logp_value;

      // tuning phase
      tune(adapt,static_cast<int>(adapt/100));

      logp_value  = -std::numeric_limits<double>::infinity();
      old_logp_value = -std::numeric_limits<double>::infinity();
      for(int i = 1; i <= (iterations + burn); i++) {
        old_logp_value = logp_value;
        preserve_all(mcmcObjects);
        jump_all(jumping_stochastics);
        update();
        logp_value = logp();
        if(reject(logp_value, old_logp_value)) {
          revert_all(mcmcObjects);
          logp_value = old_logp_value;
          rejected_ += 1;
        } else {
          accepted_ += 1;
        }
        if(i > burn && (i % thin == 0)) {
          tally_all(mcmcObjects);
        }
      }
    }
Ejemplo n.º 4
0
// Load sid file and setup default rule ids
bool Rule::load (const char *filename, int repeats, bool usage)
{
    SidTuneMod tune(0);
    if (!tune.load(filename))
    {
        m_status = false;
        return false;
    }

    strcpy (m_md5, tune.createMD5 ());
    if (md5_used ())
	    return false;

    for (int i = 0; i < 0x10000; i++)
        m_flags[i] = IGNORED;
    tune.placeSidTuneInC64mem (m_memory);
    { // Setup load image
        const SidTuneInfo &info = tune.getInfo ();
        _image (info.loadAddr, info.c64dataLen, repeats);
    }
    if (usage)
	    _usage (filename, m_md5);

    _eval  ();
    m_status   = true;
    strcpy (m_filename, filename);
    return true;
}
Ejemplo n.º 5
0
void sid_song_info (char *filename, char **title, int *length)
{ 
#ifdef DEBUG
    printf ("sid_song_info\n");
#endif
    SidTune tune(filename);
    if (!tune)
        return;
    tune.selectSong (0);
    *length = 1000 * 10 * 60;
    sid_create_title (tune.getInfo (), title);

    if (!*title)
    {   // Best Guess Title
        char *name;
        name = strrchr (filename, '/');
        if (!name)
	    name = filename;
        else
            name++;
        name   = strdup (name);
        *title = name;

        if (name)
        {   // Memory alloc can fail
            name = strrchr (name, '.');
            if (name)
                *name = '\0';
        }
    }

#ifdef DEBUG
    printf ("Title: %s\n", *title); 
#endif
}
static double tune_trx_phase_offset(struct iio_device *ldev, int *ret,
			long long cal_freq, long long cal_tone,
			double sign, double abort,
			void (*tune)(struct iio_device *, gdouble))
{
	int i;
	double offset, mag;
	double phase = 0.0, increment;

	for (i = 0; i < 10; i++) {

		get_markers(&offset, &mag);
		get_markers(&offset, &mag);

		increment = calc_phase_offset(cal_freq, cal_tone, offset, mag);
		increment *= sign;

		phase += increment;

		phase = scale_phase_0_360(phase);
		tune(ldev, phase);

		DBG("Step: %i increment %f Phase: %f\n", i, increment, phase);

		if (fabs(offset) < 0.001)
			break;
	}

	if (fabs(offset) > 0.1)
		*ret = -EFAULT;
	else
		*ret = 0;

	return phase * sign;
}
Ejemplo n.º 7
0
// Each semitone is tuned. As semitones are hopefully not far apart tuning wise,
// matrix pitch values are rounded off to the nearest semitone when looking up
// pitch correction before output to the DACs.
char TUNE_retune(){
  long correction;
  long newPitch;
  char vco;
  char semitone;
  
  TUNE_allAreTuneable = 1;

  // pause matrix calculations, restarted after updating global tuning
  MX_isSuspended = 1;
  
  for(vco=0; vco<3; vco++){
    for(semitone=CONF_SEMITONE_LOWEST; semitone<=CONF_SEMITONE_HIGHEST; semitone++){
      correction = tune(vco, semitone);
      if(correction >= -32768 && correction <= 32767){ // within range of an int
        newPitch = MX_keyToMatrixMapper[semitone] + correction;
        
        if(newPitch >= -32768 && newPitch <= 32767){
          TUNE_isTuneable[vco][semitone] = 1;
          TUNE_compuTuneCorrections[vco][semitone] = correction;
        } else {
          setUntunable(vco, semitone);
        }
      } else {
        setUntunable(vco, semitone);
      }
    }
  }
  return updateGlobalTuning(globalTuning);
}
Ejemplo n.º 8
0
void
Tomahawk::InfoSystem::XmppInfoPlugin::audioStopped()
{
    tDebug() << Q_FUNC_INFO << m_sipPlugin->m_client->jid().full();

    Jreen::Tune::Ptr tune( new Jreen::Tune() );
    m_pubSubManager->publishItems(QList<Jreen::Payload::Ptr>() << tune, Jreen::JID());
}
Ejemplo n.º 9
0
//	Scan methods
bool DVBProvider::scan( std::string &network ) {
	bool res=false;
	
	while (!res && _chan < DVB_CHANNELS) {
		res = tune();
		_chan++;
	}
	network = boost::lexical_cast<std::string>(_chan-1);
	return res;
}
Ejemplo n.º 10
0
void Move::autoTune( void ) {
    
    // only do something if tuning is turned on
    if ( autoTuning ) {
        // delegate to derived class
        tune();
        
        // reset counters
        resetCounters();
    }
}
Ejemplo n.º 11
0
void main(void) {
    HardwareInit();
    UartInit(STDIO,115200,DEFAULT_LINE_CTRL);
    heap_size=free_heap();
#if defined DEBUG
    test_pattern();
#endif
    UartPrint(STDOUT,"video initialization\r");
    VideoInit();
    delay_ms(500);
    UartPrint(STDOUT,"keyboard initialization: ");
    if (KeyboardInit()){
        UartPrint(STDOUT,"OK\r");
        comm_channel=LOCAL_CON;
    }else{
        UartPrint(STDOUT,"keyboard error\r");
        UartPrint(STDOUT,"Using uart2 channel.\r");
        comm_channel=SERIAL_CON;
    }
    text_coord_t cpos;
    UartPrint(STDOUT,"SD initialization: ");
    if (!mount(0)){
        UartPrint(STDOUT,"Failed\r");
        SDCardReady=FALSE;
    }else{
        UartPrint(STDOUT,"succeeded\r");
        SDCardReady=TRUE;
    }
    UartPrint(STDOUT,"SRAM initialization\r");
    sram_init();
    UartPrint(STDOUT,"sound initialization.\r");
    tune((unsigned int*)&e3k[0]);
    UartPrint(STDOUT,"initialization completed.\r");
    set_cursor(CR_BLOCK); // sauvegare video_buffer dans SRAM
    clear_screen();
#if defined _DEBUG_
    graphics_test();
    set_curpos(0,LINE_PER_SCREEN-1);
    print(comm_channel,"test");
    sram_write_block(100000,video_bmp,BMP_SIZE);
    delay_ms(1000);
    clear_screen();
    delay_ms(1000);
    sram_read_block(100000,video_bmp,BMP_SIZE);
    delay_ms(1000);
    clear_screen();
//    print(comm_channel,"heap_size: ");
//    print_int(comm_channel,heap_size,0);
//    crlf();
#endif
    shell();
} // main()
Ejemplo n.º 12
0
void HSVDetector::findObjectAndServePosition() {

    // If we are able to get a an image
    if (image_source.getSharedMat(hsv_image)) {

        addWorldReferenceFrame();
        cv::cvtColor(hsv_image, hsv_image, cv::COLOR_BGR2HSV);
        applyThreshold();
        clarifyBlobs();
        siftBlobs();
        tune();

        position_sink.pushObject(object_position);
    }
}
Ejemplo n.º 13
0
int main() {
    struct stat sb;
    
    if(stat(FN_PASSWD, &sb)) {
	perror("stat");
	return 1;
    }
    if(sb.st_size != sizeof(userec_t) * MAX_USERS) {
	printf("size and MAX_USERS do not match!\n");
	if(tune(sb.st_size / sizeof(userec_t)) == 0)
	    printf(FN_PASSWD " has been tuned successfully!\n");
    } else
	printf("Nothing to do.\n");
    return 0;
}
Ejemplo n.º 14
0
Archivo: recpt1.c Proyecto: k-pi/recdvb
/* will be ipc message receive thread */
void *
mq_recv(void *t)
{
    thread_data *tdata = (thread_data *)t;
    message_buf rbuf;
    char channel[16];
	char service_id[32] = {0};
    int recsec = 0, time_to_add = 0;
    unsigned int tsid = 0;

    while(1) {
        if(msgrcv(tdata->msqid, &rbuf, MSGSZ, 1, 0) < 0) {
            return NULL;
        }

		sscanf(rbuf.mtext, "ch=%s t=%d e=%d sid=%s tsid=%d", channel, &recsec, &time_to_add, service_id, &tsid);


            /* wait for remainder */
            while(tdata->queue->num_used > 0) {
                usleep(10000);
            }
//            if(close_tuner(tdata) != 0)
//                return NULL;

            tune(channel, tdata, 0, tsid);

        if(time_to_add) {
            tdata->recsec += time_to_add;
            fprintf(stderr, "Extended %d sec\n", time_to_add);
        }

        if(recsec) {
            time_t cur_time;
            time(&cur_time);
            if(cur_time - tdata->start_time > recsec) {
                f_exit = TRUE;
            }
            else {
                tdata->recsec = recsec;
                fprintf(stderr, "Total recording time = %d sec\n", recsec);
            }
        }

        if(f_exit)
            return NULL;
    }
}
Ejemplo n.º 15
0
SidTuneBase* prg::load(const char *fileName, buffer_t& dataBuf)
{
    const char *ext = SidTuneTools::fileExtOfPath(fileName);
    if ( (!stringutils::equal(ext, ".prg")) &&
         (!stringutils::equal(ext, ".c64")) )
    {
        return 0;
    }

    if (dataBuf.size() < 2)
    {
        throw loadError(ERR_TRUNCATED);
    }

    std::auto_ptr<prg> tune(new prg());
    tune->load();

    return tune.release();
}
Ejemplo n.º 16
0
static void set_params_safe(const std::string &method, const std::string &params, bool dipolar_ia) {
  if(scafacos && (scafacos->method != method)) {
    delete scafacos;
    scafacos = 0;
  }
  
  scafacos = new Scafacos(method, comm_cart, params);

  scafacos->parse_parameters(params);
  int per[3] = { PERIODIC(0) != 0, PERIODIC(1) != 0, PERIODIC(2) != 0 };
  scafacos->set_dipolar(dipolar_ia);
  scafacos->set_common_parameters(box_l, per, n_part);

  on_coulomb_change();
  
  tune();

  on_coulomb_change();
}
Ejemplo n.º 17
0
int
start_play (streams * sid, sockets * s)
{
	int a_id;

	if (sid->type == 0 && s->type == TYPE_HTTP)
		{
			sid->type = STREAM_HTTP;
			sid->rsock = s->sock;
		}

	if(sid->type == 0)
	{
//			LOG("Assuming RTSP over TCP for stream %d, most likely transport was not specified", sid->sid);
//			sid->type = STREAM_RTSP_TCP;
//			sid->rsock = s->sock;
			LOG_AND_RETURN(-454, "No Transport header was specified, for sid %d", sid->sid);
	}
	
	LOG ("Play for stream %d, type %d, rsock %d, adapter %d, sock_id %d handle %d", s->sid, sid->type, sid->rsock,
		sid->adapter, s->id, s->sock);

	if (sid->adapter == -1)		 // associate the adapter only at play (not at setup)
	{
		a_id =
			get_free_adapter (sid->tp.freq, sid->tp.pol, sid->tp.sys,
			sid->tp.fe);
		LOG ("Got adapter %d on socket %d", a_id, s->id);
		if (a_id < 0)
			return -404;
		sid->adapter = a_id;
		set_adapter_for_stream (sid->sid, a_id);

	}
	if (set_adapter_parameters (sid->adapter, s->sid, &sid->tp) < 0)
		return -404;
	sid->do_play = 1;
	sid->start_streaming = 0;
	sid->tp.apids = sid->tp.dpids = sid->tp.pids = sid->tp.x_pmt = NULL;
	return tune (sid->adapter, s->sid);
}
Ejemplo n.º 18
0
void
Tomahawk::InfoSystem::XmppInfoPlugin::audioStarted(const Tomahawk::InfoSystem::InfoStringHash& info)
{
    tDebug() << Q_FUNC_INFO << m_sipPlugin->m_client->jid().full() << info;

    Jreen::Tune::Ptr tune( new Jreen::Tune() );

    tune->setTitle( info.value( "title" ) );
    tune->setArtist( info.value( "artist" ) );
    tune->setLength( info.value("duration").toInt() );
    tune->setTrack( info.value("albumpos") );
    tune->setUri( GlobalActionManager::instance()->openLink( info.value( "title" ), info.value( "artist" ), info.value( "album" ) ) );

    //TODO: provide a rating once available in Tomahawk
    tune->setRating( 10 );

    //TODO: it would be nice to set Spotify, Dilandau etc here, but not the jabber ids of friends
    tune->setSource( "Tomahawk" );

    m_pubSubManager->publishItems( QList<Jreen::Payload::Ptr>() << tune, Jreen::JID() );
}
Ejemplo n.º 19
0
    void sample(int iterations, int burn, int adapt, int thin) {


      if(iterations % thin) {
        std::cout << "ERROR: interations not a multiple of thin." << std::endl;
        return;
      }

      // setup logp's etc.
      initChain();

      if(logp()==-std::numeric_limits<double>::infinity()) {
        throw std::logic_error("ERROR: cannot start from a logp of -Inf.");
      }

      // tuning phase
      tune(adapt,static_cast<int>(adapt/100));
      if(true) { tune_global(adapt,static_cast<int>(adapt/100)); }

      // sampling
      run(iterations, burn, thin);
    }
Ejemplo n.º 20
0
void dce_bayes_run_single(int* NRI, double* conc, double* tau_gamma, 
			  double* tau_theta, double* ab_vp,
			  double* ab_epsilon, double* aif_settings, 
			  int* settings, double* time, int* T,
			  double *ktrans_trace, double* kep_trace, 
			  double* vp_trace, double* tau_epsilon_trace,
			  double* deviance_trace, int* nsample) {
  GetRNGstate();
  int iter = 0, tu;
  double temp;
  double ktrans = 0.5;
  double kep = 1.0;
  double vp = 0.0;
  if (settings[0] == 1) {
    vp = ab_vp[0] / ab_vp[1];
  }
  double tau_epsilon = ab_epsilon[0] / ab_epsilon[1];
  int sample = -1;
  double sigmagamma = 1.0;
  double sigmatheta = 1.0;
  double sigmaeta = 1.0;
  int acc_gamma = 0;
  int acc_theta = 0;
  int acc_eta = 0;
  int dev;
  // iter = 0;

  while (iter < NRI[0]) { 
    iter++;
    temp = update_gamma2(log(ktrans), kep, vp,  tau_gamma[0], tau_gamma[1], 
			 tau_epsilon, conc, time, sigmagamma, T[0], 
			 aif_settings);
    if (temp != log(ktrans)) {
      acc_gamma++;
      ktrans = exp(temp);
    }
    temp = update_theta2(log(kep), ktrans, vp,  conc, time, tau_epsilon, 
			 tau_theta[0], tau_theta[1], sigmatheta, T[0], 
			 aif_settings);
    if (temp != log(kep)) {
      acc_theta++;
      kep = exp(temp);
    }
    
    if (settings[0] == 1) {
      temp = update_eta3(vp, kep, ktrans, ab_vp[0], ab_vp[1], tau_epsilon, 
			 conc, time, sigmaeta, T[0], aif_settings);
      if (temp != vp) {
	acc_eta++;
	vp = temp;
      }
    }
    tau_epsilon = update_tau_epsilon1(tau_epsilon, ab_epsilon[0], 
				      ab_epsilon[1], conc, vp, ktrans, kep,
				      time, T[0], aif_settings);
    if (iter == NRI[3])	{
      tu = 0;
      temp = tune(sigmagamma, acc_gamma, NRI[3]);
      if (sigmagamma != temp) {
	sigmagamma = temp;
	tu = 1;
      }
      temp = tune(sigmatheta, acc_theta, NRI[3]);
      if (sigmatheta != temp) {
	sigmatheta = temp;
	tu = 1;
      }
      if (settings[0] == 1) {
	temp = tune(sigmaeta, acc_eta, NRI[3]);
	if (sigmaeta != temp) {
	  sigmaeta = temp;
	  tu = 1;
	}
      }
      if (tu != 0) {
	iter = 0;
	acc_gamma = 0;
	acc_theta = 0;
	acc_eta = 0;
      } else {
	sample = 0;
      }
    }
    if (iter > NRI[2] && fmod(iter, NRI[1]) == 0 && sample >= 0) {
      ktrans_trace[sample] = ktrans;
      kep_trace[sample] = kep;
      vp_trace[sample] = vp;
      tau_epsilon_trace[sample] = tau_epsilon;
      deviance_trace[sample] = deviance(tau_epsilon, conc, time, ktrans, 
					kep, vp, T[0], aif_settings);
      sample++;
      if (sample>nsample[0]){sample=nsample[0];iter=iter+NRI[1];}
    }
  }
  PutRNGstate();
}
Ejemplo n.º 21
0
int main() {
  Wind flute;
  tune(flute); // Upcasting
} ///:~
Ejemplo n.º 22
0
Archivo: recpt1.c Proyecto: k-pi/recdvb
int
main(int argc, char **argv)
{
    time_t cur_time;
    pthread_t signal_thread;
    pthread_t reader_thread;
    pthread_t ipc_thread;
    QUEUE_T *p_queue = create_queue(MAX_QUEUE);
    BUFSZ   *bufptr;
    decoder *decoder = NULL;
    splitter *splitter = NULL;
    static thread_data tdata;
    decoder_options dopt = {
        4,  /* round */
        0,  /* strip */
        0   /* emm */
    };
    tdata.dopt = &dopt;
    tdata.lnb = 0;
    tdata.tfd = -1;

    int result;
    int option_index;
    struct option long_options[] = {
#ifdef HAVE_LIBARIB25
        { "b25",       0, NULL, 'b'},
        { "B25",       0, NULL, 'b'},
        { "round",     1, NULL, 'r'},
        { "strip",     0, NULL, 's'},
        { "emm",       0, NULL, 'm'},
        { "EMM",       0, NULL, 'm'},
#endif
        { "LNB",       1, NULL, 'n'},
        { "lnb",       1, NULL, 'n'},
        { "udp",       0, NULL, 'u'},
        { "addr",      1, NULL, 'a'},
        { "port",      1, NULL, 'p'},
        { "http",      1, NULL, 'H'},
        { "dev",       1, NULL, 'd'},
        { "help",      0, NULL, 'h'},
        { "version",   0, NULL, 'v'},
        { "sid",       1, NULL, 'i'},
        { "tsid",      1, NULL, 't'},
        { "lch",       0, NULL, 'c'},
        {0, 0, NULL, 0} /* terminate */
    };

    boolean use_b25 = FALSE;
    boolean use_udp = FALSE;
    boolean use_http = FALSE;
    boolean fileless = FALSE;
    boolean use_stdout = FALSE;
    boolean use_splitter = FALSE;
    boolean use_lch = FALSE;
    char *host_to = NULL;
    int port_to = 1234;
    int port_http = 12345;
    sock_data *sockdata = NULL;
    int dev_num = 0;
    int val;
    char *voltage[] = {"0V", "11V", "15V"};
    char *sid_list = NULL;
    unsigned int tsid = 0;
	int connected_socket, listening_socket;
	unsigned int len;
	char *channel, *pch = NULL;

    while((result = getopt_long(argc, argv, "br:smn:ua:H:p:d:hvitcl:",
                                long_options, &option_index)) != -1) {
        switch(result) {
        case 'b':
            use_b25 = TRUE;
            fprintf(stderr, "using B25...¥n");
            break;
        case 's':
            dopt.strip = TRUE;
            fprintf(stderr, "enable B25 strip¥n");
            break;
        case 'm':
            dopt.emm = TRUE;
            fprintf(stderr, "enable B25 emm processing¥n");
            break;
        case 'u':
            use_udp = TRUE;
            host_to = "localhost";
            fprintf(stderr, "enable UDP broadcasting¥n");
            break;
        case 'H':
            use_http = TRUE;
            port_http = atoi(optarg);
            fprintf(stderr, "creating a http daemon¥n");
            break;
        case 'h':
            fprintf(stderr, "¥n");
            show_usage(argv[0]);
            fprintf(stderr, "¥n");
            show_options();
            fprintf(stderr, "¥n");
            exit(0);
            break;
        case 'v':
            fprintf(stderr, "%s %s¥n", argv[0], version);
            fprintf(stderr, "recorder command for DVB tuner.¥n");
            exit(0);
            break;
        /* following options require argument */
        case 'n':
            val = atoi(optarg);
            switch(val) {
            case 11:
                tdata.lnb = 1;
                break;
            case 15:
                tdata.lnb = 2;
                break;
            default:
                tdata.lnb = 0;
                break;
            }
            fprintf(stderr, "LNB = %s¥n", voltage[tdata.lnb]);
            break;
        case 'r':
            dopt.round = atoi(optarg);
            fprintf(stderr, "set round %d¥n", dopt.round);
            break;
        case 'a':
            use_udp = TRUE;
            host_to = optarg;
            fprintf(stderr, "UDP destination address: %s¥n", host_to);
            break;
        case 'p':
            port_to = atoi(optarg);
            fprintf(stderr, "UDP port: %d¥n", port_to);
            break;
        case 'd':
            dev_num = atoi(optarg);
            fprintf(stderr, "using device: /dev/dvb/adapter%d¥n", dev_num);
            break;
        case 'i':
            use_splitter = TRUE;
            sid_list = optarg;
            break;
        case 't':
            tsid = atoi(optarg);
            if(strlen(optarg) > 2){
                if((optarg[0] == '0') && ((optarg[1] == 'X') ||(optarg[1] == 'x'))){
                    sscanf(optarg+2, "%x", &tsid);
                }
            }
            fprintf(stderr, "tsid = 0x%x¥n", tsid);
            break;
	case 'c':
	    use_lch = TRUE;
	    break;
        }
    }

if(use_http){	// http-server add-
	fprintf(stderr, "run as a daemon..¥n");
	if(daemon(1,1)){
		perror("failed to start");
		return 1;
	}
	fprintf(stderr, "pid = %d¥n", getpid());

	struct sockaddr_in sin;
	int ret;
	int sock_optval = 1;
		
	listening_socket = socket(AF_INET, SOCK_STREAM, 0);
	if ( listening_socket == -1 ){
		perror("socket");
		return 1;
	}
		
	if ( setsockopt(listening_socket, SOL_SOCKET, SO_REUSEADDR,
			&sock_optval, sizeof(sock_optval)) == -1 ){
		perror("setsockopt");
		return 1;
	}
		
	sin.sin_family = AF_INET;
	sin.sin_port = htons(port_http);
	sin.sin_addr.s_addr = htonl(INADDR_ANY);

		
	if ( bind(listening_socket, (struct sockaddr *)&sin, sizeof(sin)) < 0 ){
		perror("bind");
		return 1;
	}
		
	ret = listen(listening_socket, SOMAXCONN);
	if ( ret == -1 ){
		perror("listen");
		return 1;
	}
	fprintf(stderr,"listening at port %d¥n", port_http);
	//set rectime to the infinite
	if(parse_time("-",&tdata.recsec) != 0){
		return 1;
	}
	if(tdata.recsec == -1)
		tdata.indefinite = TRUE;
}else{	// -http-server add
    if(argc - optind < 3) {
        if(argc - optind == 2 && use_udp) {
            fprintf(stderr, "Fileless UDP broadcasting¥n");
            fileless = TRUE;
            tdata.wfd = -1;
        }
        else {
            fprintf(stderr, "Some required parameters are missing!¥n");
            fprintf(stderr, "Try '%s --help' for more information.¥n", argv[0]);
            return 1;
        }
    }

    fprintf(stderr, "pid = %d¥n", getpid());

    if(use_lch){
        set_lch(argv[optind], &pch, &sid_list, &tsid);
        if(sid_list) use_splitter = TRUE;
        fprintf(stderr, "tsid = 0x%x¥n", tsid);
    }
    if(pch == NULL) pch = argv[optind];

    /* tune */
    if(tune(pch, &tdata, dev_num, tsid) != 0)
        return 1;

    /* set recsec */
    if(parse_time(argv[optind + 1], &tdata.recsec) != 0) // no other thread --yaz
        return 1;

    if(tdata.recsec == -1)
        tdata.indefinite = TRUE;

    /* open output file */
    char *destfile = argv[optind + 2];
    if(destfile && !strcmp("-", destfile)) {
        use_stdout = TRUE;
        tdata.wfd = 1; /* stdout */
    }
    else {
        if(!fileless) {
            int status;
            char *path = strdup(argv[optind + 2]);
            char *dir = dirname(path);
            status = mkpath(dir, 0777);
            if(status == -1)
                perror("mkpath");
            free(path);

            tdata.wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666);
            if(tdata.wfd < 0) {
                fprintf(stderr, "Cannot open output file: %s¥n",
                        argv[optind + 2]);
                return 1;
            }
        }
    }
}	// http-server add

    /* initialize decoder */
    if(use_b25) {
        decoder = b25_startup(&dopt);
        if(!decoder) {
            fprintf(stderr, "Cannot start b25 decoder¥n");
            fprintf(stderr, "Fall back to encrypted recording¥n");
            use_b25 = FALSE;
        }
    }

while(1){	// http-server add-
	if(use_http){
		struct hostent *peer_host;
		struct sockaddr_in peer_sin;
		pch = NULL;
		sid_list = NULL;

		len = sizeof(peer_sin);

		connected_socket = accept(listening_socket, (struct sockaddr *)&peer_sin, &len);
		if ( connected_socket == -1 ){
			perror("accept");
			return 1;
		}

		peer_host = gethostbyaddr((char *)&peer_sin.sin_addr.s_addr,
				  sizeof(peer_sin.sin_addr), AF_INET);
		if ( peer_host == NULL ){
			fprintf(stderr, "gethostbyname failed¥n");
			return 1;
		}

		fprintf(stderr,"connect from: %s [%s] port %d¥n", peer_host->h_name, inet_ntoa(peer_sin.sin_addr), ntohs(peer_sin.sin_port));

		char buf[256];
		read_line(connected_socket, buf);
		fprintf(stderr,"request command is %s¥n",buf);
		char s0[256],s1[256],s2[256];
		sscanf(buf,"%s%s%s",s0,s1,s2);
		char delim[] = "/";
		channel = strtok(s1,delim);
		char *sidflg = strtok(NULL,delim);
		if(sidflg)
			sid_list = sidflg;
		if(use_lch)
			set_lch(channel, &pch, &sid_list, &tsid);
		if(pch == NULL) pch = channel;
		fprintf(stderr,"channel is %s¥n",channel);

		if(sid_list == NULL){
			use_splitter = FALSE;
			splitter = NULL;
		}else if(!strcmp(sid_list,"all")){
			use_splitter = FALSE;
			splitter = NULL;
		}else{
			use_splitter = TRUE;
		}
	}	// -http-server add

    /* initialize splitter */
    if(use_splitter) {
        splitter = split_startup(sid_list);
        if(splitter->sid_list == NULL) {
            fprintf(stderr, "Cannot start TS splitter¥n");
            return 1;
        }
    }

	if(use_http){	// http-server add-
		char header[100];
		if(use_b25) {
			strcpy(header, "HTTP/1.1 200 OK¥r¥nContent-Type: video/mpeg¥r¥nCache-Control: no-cache¥r¥n¥r¥n");
		}else if(!strcmp(sid_list,"1seg")){
			strcpy(header, "HTTP/1.1 200 OK¥r¥nContent-Type: video/mpeg¥r¥nCache-Control: no-cache¥r¥n¥r¥n");
		}else{
			strcpy(header, "HTTP/1.1 200 OK¥r¥nContent-Type: application/octet-stream¥r¥nCache-Control: no-cache¥r¥n¥r¥n");
		}
		write(connected_socket, header, strlen(header));

		//set write target to http
		tdata.wfd = connected_socket;

		//tune
		if(tune(pch, &tdata, dev_num, tsid) != 0){
			fprintf(stderr, "Tuner cannot start recording¥n");
			continue;
		}
	}else{	// -http-server add
    /* initialize udp connection */
    if(use_udp) {
      sockdata = calloc(1, sizeof(sock_data));
      struct in_addr ia;
      ia.s_addr = inet_addr(host_to);
      if(ia.s_addr == INADDR_NONE) {
            struct hostent *hoste = gethostbyname(host_to);
            if(!hoste) {
                perror("gethostbyname");
                return 1;
            }
            ia.s_addr = *(in_addr_t*) (hoste->h_addr_list[0]);
        }
        if((sockdata->sfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
            perror("socket");
            return 1;
        }

        sockdata->addr.sin_family = AF_INET;
        sockdata->addr.sin_port = htons (port_to);
        sockdata->addr.sin_addr.s_addr = ia.s_addr;

        if(connect(sockdata->sfd, (struct sockaddr *)&sockdata->addr,
                   sizeof(sockdata->addr)) < 0) {
            perror("connect");
            return 1;
        }
    }
	}	// http-server add
    /* prepare thread data */
    tdata.queue = p_queue;
    tdata.decoder = decoder;
    tdata.splitter = splitter;
    tdata.sock_data = sockdata;
    tdata.tune_persistent = FALSE;

    /* spawn signal handler thread */
    init_signal_handlers(&signal_thread, &tdata);

    /* spawn reader thread */
    tdata.signal_thread = signal_thread;
    pthread_create(&reader_thread, NULL, reader_func, &tdata);

    /* spawn ipc thread */
    key_t key;
    key = (key_t)getpid();

    if ((tdata.msqid = msgget(key, IPC_CREAT | 0666)) < 0) {
        perror("msgget");
    }
    pthread_create(&ipc_thread, NULL, mq_recv, &tdata);
    fprintf(stderr, "¥nRecording...¥n");

    time(&tdata.start_time);

    /* read from tuner */
    while(1) {
        if(f_exit)
            break;

        time(&cur_time);
        bufptr = malloc(sizeof(BUFSZ));
        if(!bufptr) {
            f_exit = TRUE;
            break;
        }
        bufptr->size = read(tdata.tfd, bufptr->buffer, MAX_READ_SIZE);
        if(bufptr->size <= 0) {
            if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) {
                f_exit = TRUE;
                enqueue(p_queue, NULL);
                break;
            }
            else {
                free(bufptr);
                continue;
            }
        }
        enqueue(p_queue, bufptr);

        /* stop recording */
        time(&cur_time);
        if((cur_time - tdata.start_time) >= tdata.recsec && !tdata.indefinite) {
            break;
        }
    }

    /* delete message queue*/
    msgctl(tdata.msqid, IPC_RMID, NULL);

    pthread_kill(signal_thread, SIGUSR1);

    /* wait for threads */
    pthread_join(reader_thread, NULL);
    pthread_join(signal_thread, NULL);
    pthread_join(ipc_thread, NULL);

    /* close tuner */
    if(close_tuner(&tdata) != 0)
        return 1;

    /* release queue */
    destroy_queue(p_queue);
	if(use_http){	// http-server add-
		//reset queue
		p_queue = create_queue(MAX_QUEUE);

		/* close http socket */
		close(tdata.wfd);

		fprintf(stderr,"connection closed. still listening at port %d¥n",port_http);
		f_exit = FALSE;
	}else{	// -http-server add
    /* close output file */
	if(!use_stdout){
		fsync(tdata.wfd);
        close(tdata.wfd);
	}

    /* free socket data */
    if(use_udp) {
        close(sockdata->sfd);
        free(sockdata);
    }

    /* release decoder */
    if(!use_http)
    if(use_b25) {
        b25_shutdown(decoder);
    }
	}	// http-server add
    if(use_splitter) {
        split_shutdown(splitter);
    }

	if(!use_http)	// http-server add
    return 0;
}	// http-server add
}
Ejemplo n.º 23
0
int main(int argc, char const *argv[]) {

    int page = 0, pages = 0, slide = 0;
    int overlap, rotate;

    char *start;
    long bufsize = 0;

    // pdf=1 djvu=2
    int type = 0;

    if (argc<5 || argc>6) {
        printf("\nUsage: tyebook filename width height overlap rotate(R|L|0)\n");
        printf("   or: tyebook tune width height steps\n");
        return 0;
    } else {
        width = atoi(argv[2]);
        height = atoi(argv[3]);
        frame = width*height;
        if (argc == 5 && !strcmp(argv[1], "tune")) {
            tune(atoi(argv[4]));
            return 0;
        }
    }

    // starting
    overlap = atoi(argv[4])*width;

    if (argv[5][0]=='R')
        rotate = 90;
    else if (argv[5][0]=='L')
        rotate = -90;
    else
        rotate = 0;

    // getting file type
    if  (!strcmp(getfilextension(argv[1]), ".pdf") ||
         !strcmp(getfilextension(argv[1]), ".PDF"))
            type = 1;
    else if (!strcmp(getfilextension(argv[1]), ".djvu") ||
             !strcmp(getfilextension(argv[1]), ".DJVU"))
            type = 2;
    else {
        printf("Error: only PDF and DJVU files are supported\n");
        return 0;
    }

    // getting number of pages
    if (type == 1) {
        sprintf(string, "%spdfinfo \"%s\"", PREFIX, argv[1]);
        outbuf = popen(string, "r");
        while (fgets(string, sizeof string, outbuf))
            if (start = strstr(string, "Pages:"))
                pages = atoi(start+16);
    } else if (type == 2) {
        sprintf(string, "%sdjvm -l \"%s\"", PREFIX, argv[1]);
        outbuf = popen(string, "r");
        while (fgets(string, sizeof string, outbuf))
            if (strstr(string, "PAGE"))
                pages+=1;
    }
    pclose(outbuf);

    // main processing
    printf("\npages = %d\n", pages);
    printf("starting...\n");

    start = buffer = malloc(frame+1);
    buffer[frame] = 0;

    for (page=1; page<=pages; page++) {

        printf("page: %4d\n", page);

        if (type == 1)
            sprintf(string, STAGE1P, page, page, argv[1], width);
        else if (type == 2)
            sprintf(string, STAGE1D, page, argv[1], width);

        outbuf = popen(string, RB);

        while (fread(start, width, 1, outbuf) > 0) {

            if (bufsize == frame) {

                sprintf(string, STAGE2, width, height, rotate, ++slide);
                inbuf = popen(string, WB);
                setbuf(inbuf, NULL);
                fwrite(buffer, 1, frame+1, inbuf);
                pclose(inbuf);

                // move overlapping data from buffer end
                memmove(buffer, buffer+frame-overlap, overlap);
                bufsize=overlap;

            }
            start = buffer+bufsize;
            bufsize+=width;
        }

        pclose(outbuf);

    }

    // last frame
    sprintf(string, STAGE2, width, height, rotate, ++slide);
    inbuf = popen(string, WB);
    setbuf(inbuf, NULL);
    buffer[bufsize-width] = 0;
    fwrite(buffer, 1, bufsize-width+1, inbuf);
    pclose(inbuf);

    printf("finishing...\n");

    // exporting result
    sprintf(string, STAGE3, argv[1]);
    system(string);

    printf("done!\n");

    return 0;
}
Ejemplo n.º 24
0
void GDClass::begin(uint8_t options) {
  GDTR.begin();

#if VERBOSE
  Serial.println("ID REGISTER:");
  Serial.println(GDTR.rd(REG_ID), HEX);
#endif

  // Generate a blank screen
  cmd_dlstart();
  Clear();
  swap();
  finish();

  GDTR.wr(REG_PCLK_POL, 1);
  GDTR.wr(REG_PCLK, 5);
#if PROTO == 1
  GDTR.wr(REG_ROTATE, 1);
  GDTR.wr(REG_SWIZZLE, 3);
#endif
  GDTR.wr(REG_GPIO_DIR, 0x83);
  GDTR.wr(REG_GPIO, 0x80);

  if (options & GD_CALIBRATE) {
#if CALIBRATION && defined(ARDUINO)
    if (EEPROM.read(0) != 0x7c) {
      self_calibrate();
      // for (int i = 0; i < 24; i++) Serial.println(GDTR.rd(REG_TOUCH_TRANSFORM_A + i), HEX);
      for (int i = 0; i < 24; i++)
        EEPROM.write(1 + i, GDTR.rd(REG_TOUCH_TRANSFORM_A + i));
      EEPROM.write(0, 0x7c);  // is written!
    } else {
      for (int i = 0; i < 24; i++)
        GDTR.wr(REG_TOUCH_TRANSFORM_A + i, EEPROM.read(1 + i));
    }
#endif


#if CALIBRATION && defined(RASPBERRY_PI)
    {
      uint8_t cal[24];
      FILE *calfile = fopen(".calibration", "r");
      if (calfile == NULL) {
        calfile = fopen(".calibration", "w");
        if (calfile != NULL) {
          self_calibrate();
          for (int i = 0; i < 24; i++)
            cal[i] = GDTR.rd(REG_TOUCH_TRANSFORM_A + i);
          fwrite(cal, 1, sizeof(cal), calfile);
          fclose(calfile);
        }
      } else {
        fread(cal, 1, sizeof(cal), calfile);
        for (int i = 0; i < 24; i++)
          GDTR.wr(REG_TOUCH_TRANSFORM_A + i, cal[i]);
        fclose(calfile);
      }
    }
#endif
  }

  GDTR.wr16(REG_TOUCH_RZTHRESH, 1200);

  lfsr = 0x5555;
  lcg = 0;

#if STORAGE && defined(ARDUINO)
  if (options & GD_STORAGE) {
    storage();
  }
#endif

  if (options & GD_TRIM) {
    tune();
  }
}
Ejemplo n.º 25
0
//	Start/stop network
bool DVBProvider::startNetwork( const std::string &net ) {
	_chan = boost::lexical_cast<int>( net );
	return tune();
}
Ejemplo n.º 26
0
void channels::setPerspective(int number)
{
	//std::cout << "Switching to perspective number " << number << std::endl;
	if (linkage_perspectives.size() > 0)
	{
		if ((unsigned int) number >= linkage_perspectives.size())
			return;	
		current_mode = LINKAGE;
	}
	else if (getCurrentNVODcount() > 0)
	{
		if (number >= getCurrentNVODcount())
		return;
		current_mode = NVOD;
	}
	
	pmt_data pmt_entry;

	zap_obj->stop();
	curr_perspective = number;
	if (current_mode == LINKAGE)
	{
		tmp_link = linkage_perspectives[number];

		////printf("----------------------\n");
		////printf("APID: %d\n", apid);
		////printf("Current perspective: %d\n", curr_perspective);
		if (old_TS != tmp_link.TS || old_ONID != tmp_link.ONID)
		{
			//std::cout << "New TS selected" << std::endl;
			//std::cout << "The new TS is: " << tmp_link.TS << std::endl;
			tune(tmp_link.TS, tmp_link.ONID);
		}
		old_ONID = tmp_link.ONID;
		old_TS = tmp_link.TS;
	
		zap_obj->close_dev();
		pat_obj->readPAT();
		ECM = 0;
	
		memset (&pmt_entry, 0, sizeof (struct pmt_data));
		tmp_link.PMT = pat_obj->getPMT(tmp_link.SID);
		pmt_entry = pmt_obj->readPMT(tmp_link.PMT);
		linkage_pmt = pmt_entry;
		//channels.deleteCurrentAPIDs();
		tmp_link.APIDcount = 0;
		tmp_link.PCR = pmt_entry.PCR;
		for (int i = 0; i < pmt_entry.pid_counter; i++)
		{
			if (pmt_entry.type[i] == 0x02)
				tmp_link.VPID = pmt_entry.PID[i];
			else if (pmt_entry.type[i] == 0x04 || pmt_entry.type[i] == 0x03 || pmt_entry.type[i] == 0x06)
			{
				//printf("an APID: %04x\n", pmt_entry.PID[i]);
				tmp_link.APID[tmp_link.APIDcount++] = pmt_entry.PID[i];
			}
			//printf("type: %d - PID: %04x\n", pmt_entry.type[i], pmt_entry.PID[i]);
		}
	
		//printf("ECMs: %d\n", pmt_entry.ecm_counter);
	
		for (int i = 0; i < pmt_entry.ecm_counter; i++)
		{
			if (setting->getCAID() == pmt_entry.CAID[i])
				ECM = pmt_entry.ECM[i];
			//printf("CAID: %04x - ECM: %04x\n", pmt_entry.CAID[i], pmt_entry.ECM[i]);
		}
		/*	osd_obj->addCommand("HIDE perspective");
			osd_obj->createPerspective();
			osd_obj->setPerspectiveName(tmp_link.name);
			osd_obj->addCommand("SHOW perspective");*/
		//printf("%s\n", tmp_link.name);
		if (tmp_link.APIDcount == 1)
			zap_obj->zap_to(pmt_entry, tmp_link.VPID, tmp_link.APID[apid], tmp_link.PCR, ECM, tmp_link.SID, tmp_link.ONID, tmp_link.TS);
		else
			zap_obj->zap_to(pmt_entry, tmp_link.VPID, tmp_link.APID[0], tmp_link.PCR, ECM, tmp_link.SID, tmp_link.ONID, tmp_link.TS, tmp_link.APID[1]);
	}
	else if (current_mode == NVOD)	
	{
		int TS = getCurrentNVOD_TS(number);
		int ONID = getCurrentNVOD_ONID(number);
		int SID = getCurrentNVOD_SID(number);
		if (old_TS != TS || old_ONID != ONID)
		{
			//std::cout << "New TS selected" << std::endl;
			//std::cout << "The new TS is: " << tmp_link.TS << std::endl;
			tune(TS, ONID);
		}
		old_ONID = ONID;
		old_TS = TS;
	
		zap_obj->close_dev();
		pat_obj->readPAT();
		ECM = 0;
	
		memset (&NVOD_pmt, 0, sizeof (struct pmt_data));

		int PMT = pat_obj->getPMT(SID);
		if (PMT < 1)
			return;
		NVOD_pmt = pmt_obj->readPMT(PMT);

		//channels.deleteCurrentAPIDs();
		int APIDcount = 0;
		int PCR = NVOD_pmt.PCR;
		int VPID = 0;
		std::vector<int> APID;

		for (int i = 0; i < NVOD_pmt.pid_counter; i++)
		{
			if (NVOD_pmt.type[i] == 0x02)
				VPID = NVOD_pmt.PID[i];
			else if (NVOD_pmt.type[i] == 0x04 || NVOD_pmt.type[i] == 0x03 || NVOD_pmt.type[i] == 0x06)
			{
				//printf("an APID: %04x\n", pmt_entry.PID[i]);
				APID.insert(APID.end(), NVOD_pmt.PID[i]);
				APIDcount++;
			}
			//printf("type: %d - PID: %04x\n", pmt_entry.type[i], pmt_entry.PID[i]);
		}
	
		//printf("ECMs: %d\n", pmt_entry.ecm_counter);
		for (int i = 0; i < NVOD_pmt.ecm_counter; i++)
		{
			if (setting->getCAID() == NVOD_pmt.CAID[i])
				ECM = NVOD_pmt.ECM[i];
			//printf("CAID: %04x - ECM: %04x\n", pmt_entry.CAID[i], pmt_entry.ECM[i]);
		}
		/*	osd_obj->addCommand("HIDE perspective");
			osd_obj->createPerspective();
			osd_obj->setPerspectiveName(tmp_link.name);
			osd_obj->addCommand("SHOW perspective");*/
		//printf("%s\n", tmp_link.name);
		apid = 0;
		if (APIDcount == 1)
			zap_obj->zap_to(NVOD_pmt, VPID, APID[apid], PCR, ECM, SID, ONID, TS);
		else
			zap_obj->zap_to(NVOD_pmt, VPID, APID[0], PCR, ECM, SID, ONID, TS, APID[1]);
	}

}
Ejemplo n.º 27
0
void Infogrames::getNextSample(Channel &chn) {
	byte *data;
	byte cmdBlock = 0;
	uint16 cmd;
	bool cont = false;

	if (chn.flags & 64)
		return;

	if (chn.flags & 1) {
		chn.flags &= ~1;
		chn.cmdBlocks = chn.cmdBlockIndices;
	} else {
		chn.flags &= ~1;
		if (_speedCounter == 0)
			chn.ticks--;
		if (chn.ticks != 0) {
			_volume = MAX((int16) 0, tune(chn.volSlide, 0));
			_period = tune(chn.periodSlide, chn.period);
			return;
		} else {
			chn.ticks = chn.tickCount;
			cont = true;
		}
	}

	while (1) {
		while (cont || ((cmdBlock = *chn.cmdBlocks) != 0xFF)) {
			if (!cont) {
				chn.cmdBlocks++;
				chn.cmds = _subSong +
					READ_BE_UINT16(_cmdBlocks + (cmdBlock * 2));
			} else
				cont = false;
			while ((cmd = *chn.cmds) != 0xFF) {
				chn.cmds++;
				if (cmd & 128)
				{
					switch (cmd & 0xE0) {
					case 0x80: // 100xxxxx - Set ticks
						chn.ticks = tickCount[cmd & 0xF];
						chn.tickCount = tickCount[cmd & 0xF];
						break;
					case 0xA0: // 101xxxxx - Set sample
						_sample = cmd & 0x1F;
						break;
					case 0xC0: // 110xxxxx - Set volume slide/finetune
						data = _volSlideBlocks + (cmd & 0x1F) * 13;
						chn.volSlide.flags = (*data & 0x80) | 1;
						chn.volSlide.amount = *data++ & 0x7F;
						chn.volSlide.data = data;
						chn.volSlide.dataOffset = 0;
						chn.volSlide.finetunePos = 0;
						chn.volSlide.finetuneNeg = 0;
						chn.volSlide.curDelay1 = 0;
						chn.volSlide.curDelay2 = 0;
						break;
					case 0xE0: // 111xxxxx - Extended
						switch (cmd & 0x1F) {
						case 0: // Set period modifier
							chn.periodMod = (int8) *chn.cmds++;
							break;
						case 1: // Set continuous period slide
							chn.periodSlide.data =
								_periodSlideBlocks + *chn.cmds++ * 13 + 1;
							chn.periodSlide.amount = 0;
							chn.periodSlide.dataOffset = 0;
							chn.periodSlide.finetunePos = 0;
							chn.periodSlide.finetuneNeg = 0;
							chn.periodSlide.curDelay1 = 0;
							chn.periodSlide.curDelay2 = 0;
							chn.periodSlide.flags = 0x81;
							break;
						case 2: // Set non-continuous period slide
							chn.periodSlide.data =
								_periodSlideBlocks + *chn.cmds++ * 13 + 1;
							chn.periodSlide.amount = 0;
							chn.periodSlide.dataOffset = 0;
							chn.periodSlide.finetunePos = 0;
							chn.periodSlide.finetuneNeg = 0;
							chn.periodSlide.curDelay1 = 0;
							chn.periodSlide.curDelay2 = 0;
							chn.periodSlide.flags = 1;
							break;
						case 3: // NOP
							break;
						default:
							warning("Unknown Infogrames command: %X", cmd);
						}
						break;
					}
				} else { // 0xxxxxxx - Set period
					if (cmd != 0)
						cmd += chn.periodMod;
					chn.period = periods[cmd];
					chn.volSlide.dataOffset = 0;
					chn.volSlide.finetunePos = 0;
					chn.volSlide.finetuneNeg = 0;
					chn.volSlide.curDelay1 = 0;
					chn.volSlide.curDelay2 = 0;
					chn.volSlide.flags |= 1;
					chn.volSlide.flags &= ~4;
					chn.periodSlide.dataOffset = 0;
					chn.periodSlide.finetunePos = 0;
					chn.periodSlide.finetuneNeg = 0;
					chn.periodSlide.curDelay1 = 0;
					chn.periodSlide.curDelay2 = 0;
					chn.periodSlide.flags |= 1;
					chn.periodSlide.flags &= ~4;
					_volume = MAX((int16) 0, tune(chn.volSlide, 0));
					_period = tune(chn.periodSlide, chn.period);
					return;
				}
			}
		}
		if (!(chn.flags & 32)) {
			chn.flags |= 0x40;
			_volume = 0;
			return;
		} else
			chn.cmdBlocks = chn.cmdBlockIndices;
	}
}
Ejemplo n.º 28
0
void channels::zapCurrentChannel()
{
	//zap_obj->zap_allstop();

	linkage_perspectives.clear();

	current_mode = CHANNEL;

	zap_obj->stop();

	if (tune(getCurrentTS(), getCurrentONID()))
	{

		fprintf(stderr, "Getting pat\n");
		pat_obj->readPAT();
		fprintf(stderr, "Got it\n");
	
		ECM = 0;
	
		apid = 0;
	
		int tmp_pmt = pat_obj->getPMT(getCurrentSID());
	
		if (tmp_pmt != 0)
		{
			setCurrentPMT(pat_obj->getPMT(getCurrentSID()));
			
			fprintf(stderr, "Getting pmt\n");
			pmt_data pmt_entry = (pmt_obj->readPMT(getCurrentPMT()));
			fprintf(stderr, "Got it\n");
			
			setCurrentPMTdata(pmt_entry);
			deleteCurrentAPIDs();
			number_components = 0;
			video_component = 0;
			for (int i = 0; i < pmt_entry.pid_counter; i++)
			{
				if (pmt_entry.type[i] == 0x02)
				{
					setCurrentVPID(pmt_entry.PID[i]);
					video_component = pmt_entry.component[i];
				}
				else if (pmt_entry.type[i] == 0x04 || pmt_entry.type[i] == 0x03)
				{
					addCurrentAPID(pmt_entry.PID[i]);
					component[number_components++] = pmt_entry.component[i];
				}
				else if (pmt_entry.type[i] == 0x06 && pmt_entry.subtype[i] == 1)
				{
					setCurrentTXT(pmt_entry.PID[i]);
				}
				else if (pmt_entry.type[i] == 0x06 && pmt_entry.subtype[i] != 1)
				{
					addCurrentAPID(pmt_entry.PID[i], (bool) true);
					component[number_components++] = pmt_entry.component[i];
				}
			
				//printf("type: %d - PID: %04x\n", pmt_entry.type[i], pmt_entry.PID[i]);
			}
		
				for (int i = 0; i < pmt_entry.ecm_counter; i++)
			{
				if (setting->getCAID() == pmt_entry.CAID[i])
					ECM = pmt_entry.ECM[i];
				//printf("CAID: %04x - ECM: %04x\n", pmt_entry.CAID[i], pmt_entry.ECM[i]);
			}
			basic_channellist[cur_pos].PCR = pmt_entry.PCR;
		
			hardware_obj->useDD(getCurrentDD(0));
			if (getCurrentAPIDcount() == 1)
				(*zap_obj).zap_to(pmt_entry, getCurrentVPID(), getCurrentAPID(0), getCurrentPCR(), ECM, getCurrentSID(), getCurrentONID(), getCurrentTS());
			else
				(*zap_obj).zap_to(pmt_entry, getCurrentVPID(), getCurrentAPID(0), getCurrentPCR(), ECM, getCurrentSID(), getCurrentONID(), getCurrentTS(), getCurrentAPID(1));
			
			
			if (getCurrentAPIDcount() > 1)
				(*eit_obj).setAudioComponent(component[apid]);
			else
				(*eit_obj).setAudioComponent(-1);
			}
	
		if (getCurrentType() == 4)
		{
			vars->setvalue("%IS_NVOD", "true");
			osd_obj->setNVODAvailable(true);
		}
		else 
		{
			vars->setvalue("%IS_NVOD", "false");
			osd_obj->setNVODAvailable(false);
		}

		last_channels.push(cur_pos);
		int number_last_chans = 2;
		if (vars->isavailable("%NUMBERLASTCHANNELS"))
		{
			number_last_chans = atoi(vars->getvalue("%NUMBERLASTCHANNELS").c_str());
		}
		if (last_channels.size() > (unsigned int) number_last_chans)
		{
			last_channels.pop();
		}
	}
}
Ejemplo n.º 29
0
static double tune_trx_phase_offset(struct iio_device *ldev, int *ret,
			long long cal_freq, long long cal_tone,
			double sign, double abort,
			void (*tune)(struct iio_device *, gdouble))
{
	long long y, y1, y2, delta = LLONG_MAX,
		min_delta = LLONG_MAX, x1;
	int i, offset, pos = 0, neg = 0;
	double min_phase, phase = 0.0, step = 1.0;

	for (i = 0; i < 30; i++) {

		get_markers(&offset, &y, &y1, &y2, &x1);
		get_markers(&offset, &y, &y1, &y2, &x1);

		if (i == 0) {
			phase = calc_phase_offset(cal_freq, cal_tone, offset, y);
			tune(ldev, phase * sign);
			continue;
		}


		if (offset != 0) {
			phase += (360.0 / ((cal_freq / cal_tone) / offset) / 2);
			tune(ldev, phase * sign);
			continue;
		}

		delta = abs(y1) - abs(y2);

		if (delta < min_delta) {
			min_delta = delta;
			min_phase = phase;
		}

		if (x1 > 0) {
			if (pos == 1) {
				step /= 2;
				pos = 0;
			}
			phase -= step;
			neg = 1;
		} else {
			if (neg == 1) {
				step /= 2;
				neg = 0;
			}
			phase += step;
			pos = 1;
		}

		if (step < abort)
			break;

		DBG("Step: %f Phase: %f, min_Phase: %f\ndelta %d, pdelta %d, min_delta %d\n",
		    step, phase, min_phase, (int)delta, (int)min_delta);

		tune(ldev, phase * sign);
	}

	if (offset)
		*ret = -EFAULT;
	else
		*ret = 0;

	return phase * sign;
}
Ejemplo n.º 30
0
int
main(int argc, char **argv)
{
	pthread_t signal_thread;
	static thread_data tdata;
	int result;
	int option_index;
	struct option long_options[] = {
		{ "bell",	   0, NULL, 'b'},
		{ "help",	   0, NULL, 'h'},
		{ "version",   0, NULL, 'v'},
		{ "list",	   0, NULL, 'l'},
		{ "driver",    1, NULL, 'd'},
		{0, 0, NULL, 0} /* terminate */
	};

	tdata.hModule = NULL;
	tdata.dwSpace = 0;
	tdata.table = NULL;
	char *driver = NULL;
	boolean use_bell = FALSE;

	while((result = getopt_long(argc, argv, "bhvln:d:",
								long_options, &option_index)) != -1) {
		switch(result) {
		case 'b':
			use_bell = TRUE;
			break;
		case 'h':
			fprintf(stderr, "\n");
			show_usage(argv[0]);
			fprintf(stderr, "\n");
			show_options();
			fprintf(stderr, "\n");
			show_channels();
			fprintf(stderr, "\n");
			exit(0);
			break;
		case 'v':
			fprintf(stderr, "%s %s\n", argv[0], version);
			fprintf(stderr, "signal check utility for BonDriver based tuners.\n");
			exit(0);
			break;
		case 'l':
			show_channels();
			exit(0);
			break;
		case 'd':
			driver = optarg;
			break;
		}
	}

	if(argc - optind < 1) {
		fprintf(stderr, "channel must be specified!\n");
		fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
		return 1;
	}

	/* set tune_persistent flag */
	tdata.tune_persistent = TRUE;

	/* spawn signal handler thread */
	init_signal_handlers(&signal_thread, &tdata);

	/* tune */
	if(tune(argv[optind], &tdata, driver) != 0)
		return 1;

	while(1) {
		if(f_exit)
			break;
		tdata.pIBon->PurgeTsStream();	// 凡ドラはCh設定時からストリームデータをバッファに溜め込むため追加
		/* show signal strength */
		calc_cn(&tdata, use_bell);
		sleep(1);
	}

	/* wait for signal thread */
	pthread_kill(signal_thread, SIGUSR1);
	pthread_join(signal_thread, NULL);

	/* close tuner */
	if(close_tuner(&tdata) != 0)
		return 1;

	return 0;
}