예제 #1
0
int main (int argc, const char * argv[]){
    // handle remote addr
    if (argc > 1){
        if (sscan_bd_addr((uint8_t *)argv[1], addr)){
            serverMode = 0;
            prepare_packet();
        }
    }

	run_loop_init(RUN_LOOP_POSIX);
	int err = bt_open();
	if (err) {
		printf("Failed to open connection to BTdaemon\n");
		return err;
	}
	bt_register_packet_handler(packet_handler);
	bt_send_cmd(&l2cap_register_service, PSM_TEST, PACKET_SIZE);
	bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
	
	// banner
	printf("L2CAP Throughput Test (compatible with Apple's Bluetooth Explorer)\n");
	if (serverMode) {
	   printf(" * Running in Server mode. For client mode, specify remote addr 11:22:33:44:55:66\n");
    }
    printf(" * MTU: 1000 bytes\n");
	
	run_loop_execute();
	bt_close();
	return 0;
}
예제 #2
0
파일: mitm.c 프로젝트: darkfall/ArduinoBot
int main (int argc, const char * argv[]){
	// parse addr of Bob
	uint8_t ok = 0;
	if (argc >= 2) {
		ok = sscan_bd_addr((uint8_t *) argv[1], bob_addr);
	} 
	if (!ok) {
		printf("Usage: mitm 12:34:56:78:9A:BC\n");
		exit(0);
	}
	
	// start stack
	run_loop_init(RUN_LOOP_POSIX);
	int err = bt_open();
	if (err) {
		printf("Failed to open connection to BTdaemon\n");
		return err;
	}
	
	printf("BTstack-in-the-Middle started, will pretend to be BOB (");
	print_bd_addr(bob_addr);
	printf(")\n");
	
	bt_register_packet_handler(packet_handler);
	bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
	run_loop_execute();
	bt_close();
}
예제 #3
0
파일: test.c 프로젝트: darkfall/ArduinoBot
int main (int argc, const char * argv[]){
	run_loop_init(RUN_LOOP_POSIX);
	int err = bt_open();
	if (err) {
		printf("Failed to open connection to BTdaemon\n");
		return err;
	}
	bt_register_packet_handler(packet_handler);
	bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
	run_loop_execute();
	bt_close();
}
예제 #4
0
static int
bt_rec_open(struct voss_backend *pbe, const char *devname, int samplerate,
    int bufsize, int *pchannels, int *pformat)
{
	struct bt_config *cfg = pbe->arg;
	int retval;

	bt_init_cfg(cfg);

	retval = bt_open(pbe, devname, samplerate, bufsize, pchannels, pformat,
	    cfg, SDP_SERVICE_CLASS_AUDIO_SOURCE, 0);
	if (retval != 0)
		return (retval);
	return (0);
}
예제 #5
0
파일: bt617.c 프로젝트: wuchen1106/DAQ
int mvme_open(MVME_INTERFACE **vme, int index)
{
   BT617_TABLE *ptab;
   bt_devdata_t flag;
   int status;

   *vme = (MVME_INTERFACE *)malloc(sizeof(MVME_INTERFACE));
   if (*vme == NULL)
      return MVME_NO_MEM;

   (*vme)->am       = MVME_AM_DEFAULT;
   (*vme)->dmode    = MVME_DMODE_DEFAULT;
   (*vme)->blt_mode = MVME_BLT_NONE;

   (*vme)->handle = 0; /* use first entry in BT617_TABLE by default */

   (*vme)->table = (void *)malloc(sizeof(BT617_TABLE)*MAX_BT617_TABLES);
   if ((*vme)->table == NULL)
      return MVME_NO_MEM;

   memset((*vme)->table, 0, sizeof(BT617_TABLE)*MAX_BT617_TABLES);   
   ptab = (BT617_TABLE *) (*vme)->table;

   ptab->am = MVME_AM_DEFAULT;
   
   bt_gen_name(index, BT_DEV_A32, ptab->devname, BT_MAX_DEV_NAME);
   status = bt_open(&ptab->btd, ptab->devname, BT_RDWR);
   if (status != BT_SUCCESS) {
      bt_perror(ptab->btd, status, "bt_open error");
      return MVME_NO_INTERFACE;
   }
   bt_init(ptab->btd);
   bt_clrerr(ptab->btd);

   /* select swapping mode */
   flag = BT_SWAP_NONE;
   bt_set_info(ptab->btd, BT_INFO_SWAP, flag);

   /* set data mode */
   flag = BT_WIDTH_D32;
   bt_set_info(ptab->btd, BT_INFO_DATAWIDTH, flag);

   /* switch off block transfer */
   flag = FALSE;
   bt_set_info(ptab->btd, BT_INFO_BLOCK, flag);

   return MVME_SUCCESS;
}
예제 #6
0
/**************************************************************************//**
* \fn      CAENComm_ErrorCode STDCALL CAENComm_OpenDevice(CAENComm_DeviceDescr dd, int *handle);
* \brief   Open the device
*
* \param	[IN] LinkType: the link used by the device(CAENComm_USB|CAENComm_PCI_OpticalLink|CAENComm_PCIE_OpticalLink|CAENComm_PCIE)
* \param	[IN] LinkNum: The link number
* \param	[IN] ConetNode: The board number in the link.
* \param	[IN] VMEBaseAddress: The VME base address of the board
* \param	[OUT] handle: device handler
* \return  0 = Success; negative numbers are error codes
* \note  We ignore the link type -- it's always going to be SBS
* \note  The LinkNum will be the SBS interface board.
* \note  The ConetNode will be ignored,.
* \note  We are always going to open BT_DEV_A32
* \note  SBS errors are converted to a generic error.
*
******************************************************************************/
CAENComm_ErrorCode STDCALL CAENComm_OpenDevice(CAENComm_ConnectionType LinkType,
					       int LinkNum, int ConetNode, 
					       uint32_t VMEBaseAddress, 
					       int *handle)
{
  CAENComm_ErrorCode status =CAENComm_Success;	// optimistic completion code.

  try {
    char deviceName[PATH_MAX+1];
    bt_desc_t*  btHandle = new bt_desc_t;;
    void*      pMap;
    
    // Generate our device name and attempt to open it:
    

    const char*  pName = bt_gen_name(LinkNum, BT_DEV_A32, deviceName, sizeof(deviceName));
    
    if (pName != deviceName) throw CAENComm_GenericError;

    bt_error_t ok = bt_open(btHandle, pName, BT_RDWR);
    if (ok != BT_SUCCESS) throw CAENComm_GenericError;

    // Attempt to map the address space:

    ok = bt_mmap(*btHandle, &pMap, 
		 VMEBaseAddress, gWindowSize, 
		 BT_RDWR, BT_SWAP_NONE);

    if(ok != BT_SUCCESS) throw CAENComm_GenericError;

    // Create the handle, fill it in, validate it and return its index to the caller.

    int iHandle              = newHandle();
    pNSCLHandle pHandle      = &(gHandles[iHandle]);
    pHandle->s_pSbsHandle    = btHandle;
    pHandle->s_nBaseAddress  = VMEBaseAddress;
    pHandle->s_pMappedMemory = pMap;
    pHandle->s_fValid        = true;
    *handle                  = iHandle;

  }
  catch(CAENComm_ErrorCode code) {
    status = code;
  }
  return status;
    

}
예제 #7
0
FtkApp* ftk_app_bluetooth_create(void)
{
	FtkApp* thiz = FTK_ZALLOC(sizeof(FtkApp) + sizeof(PrivInfo));

	if(thiz != NULL)
	{
		thiz->run  = ftk_app_bluetooth_run;
		thiz->get_icon = ftk_app_bluetooth_get_icon;
		thiz->get_name = ftk_app_bluetooth_get_name;
		thiz->destroy = ftk_app_bluetooth_destroy;

		_bt = bt_open();
	}

	return thiz;
}
예제 #8
0
파일: inquiry.c 프로젝트: sristi194/uubt
int main (int argc, const char * argv[]){
	// start stack
	run_loop_init(RUN_LOOP_POSIX);
	int err = bt_open();
	if (err) {
		printf("Failed to open connection to BTdaemon\n");
		return err;
	}
	// init table
	int i; for (i=0;i<MAX_DEVICES;i++) devices[i].state = 0;
	
	bt_register_packet_handler(packet_handler);
	bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
	run_loop_execute();
	bt_close();
	return 0;
}
예제 #9
0
int main (int argc, const char * argv[]){
	
    create_test_data();
    
	run_loop_init(RUN_LOOP_POSIX);
	int err = bt_open();
	if (err) {
		//fpritf(stderr,"Failed to open connection to BTdaemon, err %d\n",err);
		return 1;
	}
	bt_register_packet_handler(packet_handler);
	
	bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
	run_loop_execute();
	bt_close();
    return 0;
}
예제 #10
0
int main (int argc, const char * argv[]) {
    printf("le_scan started\n");
    printf("- connecting to BTstack Daemon\n");
    // start stack
    btstack_run_loop_init(btstack_run_loop_posix_get_instance());
    int err = bt_open();
    if (err) {
        printf("-> Failed to open connection to BTstack Daemon\n");
        return err;
    }

    printf("- connected\n");
    printf("- send power on\n");

    bt_register_packet_handler(packet_handler);
    bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );
    btstack_run_loop_execute();
    bt_close();
    return 0;
}
예제 #11
0
int vme_open()
{
   /*  Open SBS VME-PCI  */
    status = bt_open(&btd, bt_gen_name(unit, type, &devname[0], BT_MAX_DEV_NAME), BT_RD | BT_WR);
    if (BT_SUCCESS != status) {
        bt_perror(btd, status, "Engine ERROR: Could not open SBS VME-PCI");
		remove("/Applications/sirius/system/engine.lock");
        return -1;
    }
	
    /* Clear any outstanding errors */
    status = bt_clrerr(btd);
    if (BT_SUCCESS != status) {
        bt_perror(btd, status, "Engine ERROR: Could not clear errors from SBS VME-PCI");
		remove("/Applications/sirius/system/engine.lock");
        (void) bt_close(btd);
        return -1;
    }
	return 0;
}
/*
 * Open a dataset
 */
Btree *open_dataset(char *name)
{
	Btree *bt;

	bt = malloc(sizeof(Btree));
	if (!bt)
		return NULL;

	strcpy(bt->fdata[NDX].filename, name);
	strcat(bt->fdata[NDX].filename, ".ndx");
	bt->fdata[NDX].bufferlist = NULL;

	strcpy(bt->fdata[DAT].filename, name);
	strcat(bt->fdata[DAT].filename, ".dat");
	bt->fdata[DAT].bufferlist = NULL;

    bt->getkeysize     = UserGetKeySize; /* user.c */
    bt->getkeyNrecsize = UserGetKeyNRecSize;
    bt->getrecsize     = UserGetRecSize;
    bt->key2keycmp     = UserKey2KeyCmp;
    bt->key2reccmp     = UserKey2RecCmp;
    bt->rec2keycpy     = UserRec2KeyCpy;

	bt->error_code = 0;
	bt->duplicatesOK = 1;

	if (bt_open(bt)) {
        printf("Open failed: %s.\n",
				ErrorText[bt->error_code]);
		free(bt);
		bt = NULL;
	}
    else
        fprintf(stdout, "Opened\n");
	return bt;
}
예제 #13
0
파일: bt617.c 프로젝트: wuchen1106/DAQ
int bt617_set_am(MVME_INTERFACE *vme, int am)
{
   int i;
   BT617_TABLE *ptab;
   bt_error_t status;
   bt_devdata_t flag;

   for (i=0 ; i<MAX_BT617_TABLES ; i++)
      if (((BT617_TABLE *)vme->table)[i].am == am)
         break;

   if (((BT617_TABLE *)vme->table)[i].am == am) {

      vme->handle = i;
      ptab = ((BT617_TABLE *)vme->table)+i;
      bt_set_info(ptab->btd, BT_INFO_DMA_AMOD, am);
      bt_set_info(ptab->btd, BT_INFO_PIO_AMOD, am);
      bt_set_info(ptab->btd, BT_INFO_MMAP_AMOD, am);
      return MVME_SUCCESS;
   }

   /* search free slot */
   for (i=0 ; i<MAX_BT617_TABLES ; i++)
      if (((BT617_TABLE *)vme->table)[i].am == 0)
         break;
   if (i==MAX_BT617_TABLES)
      return MVME_NO_MEM;

   /* mode not yet open, open it */
   vme->handle = i;
   ptab = ((BT617_TABLE *)vme->table)+i;

   ptab->am = am;
   if (am == MVME_AM_A16_SD || am == MVME_AM_A16_ND)
      bt_gen_name(vme->index, BT_DEV_A16, ptab->devname, BT_MAX_DEV_NAME);
   else if (am == MVME_AM_A24_SB     ||
            am == MVME_AM_A24_SP     ||
            am == MVME_AM_A24_SD     ||
            am == MVME_AM_A24_NB     ||
            am == MVME_AM_A24_NP     ||
            am == MVME_AM_A24_ND     ||
            am == MVME_AM_A24_SMBLT  ||
            am == MVME_AM_A24_NMBLT  ||
            am == MVME_AM_A24        ||
            am == MVME_AM_A24_D64)
      bt_gen_name(vme->index, BT_DEV_A24, ptab->devname, BT_MAX_DEV_NAME);
   else
      bt_gen_name(vme->index, BT_DEV_A32, ptab->devname, BT_MAX_DEV_NAME);

   status = bt_open(&ptab->btd, ptab->devname, BT_RDWR);
   if (status != BT_SUCCESS) {
      bt_perror(ptab->btd, status, "bt_open error");
      return MVME_NO_INTERFACE;
   }
   bt_init(ptab->btd);
   bt_clrerr(ptab->btd);

   /* select swapping mode */
   flag = BT_SWAP_NONE;
   bt_set_info(ptab->btd, BT_INFO_SWAP, flag);

   /* set data mode */
   flag = BT_WIDTH_D16;
   bt_set_info(ptab->btd, BT_INFO_DATAWIDTH, flag);

   /* switch off block transfer */
   flag = FALSE;
   bt_set_info(ptab->btd, BT_INFO_BLOCK, flag);

   /* set amod */
   bt_set_info(ptab->btd, BT_INFO_DMA_AMOD, am);
   bt_set_info(ptab->btd, BT_INFO_PIO_AMOD, am);
   bt_set_info(ptab->btd, BT_INFO_MMAP_AMOD, am);

   return MVME_SUCCESS;
}
예제 #14
0
파일: rtkgps.c 프로젝트: DuQiFa/rtkgps-1
/*****************************************************************************
 Open communications with GPS device.
 *****************************************************************************/
int coms_open(cmdlnopts_t *cmdopt) {
  int fd = -1;

  /* Open communication with device */
  if (cmdopt->devs != NULL) {
    /* Serial device name is provided */
    fd = dev_open(cmdopt->devs);
    if (fd < 0) {
      fprintf(stderr, "rtkgps: Error opening device %s [%s]\n", cmdopt->devs,
	      strerror(errno));
      exit(4);
    }
    if (dev_config_serial(fd, cmdopt->sspd) < 0) {
      fprintf(stderr, "rtkgps: Error setting device speed to %u [%s]\n",
      		cmdopt->sspd, strerror(errno));
      exit(4);
    }

    /* Display connection message in verbose mode */
    if (cmdopt->vflg) {
      printf("Opened device %s at %u baud\n", cmdopt->devs, cmdopt->sspd);
    }
  } else {
#if ENABLE_LINUX_BT-0
    static char btscs[24];
    /* Serial device name not provide: scan or use provide bluetooth address */
    if (cmdopt->btas == NULL) {
      /* Bluetooth address not specified: do a scan for a matching device */
      bt_device_t btd[32];
      int nbtd, nbgp = -1, n;

      /* Perform scan */
      nbtd = bt_scan(btd, 32);
      if (nbtd < 0) {
	fprintf(stderr, "rtkgps: Error perfoming bluetooth scan [%s]\n",
		strerror(errno));
	exit(4);
      }
      /* Report error if no devices found */
      if (nbtd == 0) {
	fprintf(stderr, "rtkgps: No bluetooth devices found during scan\n");
	exit(4);
      }
      /* Display scan result in verbose mode */
      if (cmdopt->vflg) {
	printf("Bluetooth scan:\n");
	bt_scan_print(stdout,  btd, nbtd);
      }
      /* Look for single bluetooth device named BlueGPS */
      for (n = 0; n < nbtd; n++) {
	if (strncmp(btd[n].name, "BlueGPS ", 8) == 0) {
	  if (nbgp == -1)
	    nbgp = n;
	  else {
	    /* Report error if multiple matching devices found */
	    fprintf(stderr, "rtkgps: Multiple BlueGPS devices found during"
		    " scan\n");
	    exit(4);
	  }
	}
      }
      if (nbgp == -1) {
	/* Report error if no matching devices found */
	fprintf(stderr, "rtkgps: No BlueGPS devices found during scan\n");
	exit(4);
      }
      /* Set selected device address from matching device address */
      ba2str(&btd[nbgp].bdaddr, btscs);

      cmdopt->btas = btscs;
      /* Display matching device details in verbose mode */
      if (cmdopt->vflg) {
	printf("Found appropriate device: ");
	bt_scan_print(stdout,  &btd[nbgp], 1);
      }
      /* This delay avoids "Operation already in progress" errors on
	 trying to open the bluetooth connection */
      sleep(1);
    }
    /* Open a connection to the selected bluetooth device */
    fd = bt_open(cmdopt->btas, 1);
    if (fd < 0) {
      fprintf(stderr, "rtkgps: Error connecting to %s [%s]\n", cmdopt->btas,
	      strerror(errno));
      exit(4);
    }
    /* Display connection message in verbose mode */
    if (cmdopt->vflg) {
      printf("Connected to %s\n", cmdopt->btas);
    }
#endif /* ENABLE_LINUX_BT */
  }

  return fd;
}
예제 #15
0
int main()
{
	//atddtree_key min = 1;
	//atddtree_key max;// = 1000;
	//atddtree_key keys[10] = {2,3,5,8,16,23,26,35,48,50};
	long max;
	int i;
	//atddtree* t;

	int nuser = 32*1024-1;	//1024*1024*64-1;
	double mean_ia = 205;

	
	gsl_rng *r;
		const gsl_rng_type *T;
		int n=5;
		double u;
			
		T=gsl_rng_ranlxs0;		//设随机数生成器类型是 ranlxs0
		
		
		//gen arrival
		gsl_rng_default_seed = ((unsigned long)(time(NULL))); 	 //设seed值为当前时间
		r=gsl_rng_alloc(T); 	 //生成实例
		
		double* exp_sample_ir = MALLOC(nuser, double);
		double abstemp = 0;
		for(i=0;i<nuser;i++)	{
				exp_sample_ir[i] = gsl_ran_exponential(r, mean_ia);
				//exp_sample_ir[i] =  2+(i%10000)*0.3;
#ifdef LOGISTIC				
				abstemp = gsl_ran_logistic(r, 1);
				if(abstemp<0)	{
					abstemp=0-abstemp;
				}
				exp_sample_ir[i] = abstemp;				
#endif	
				//exp_sample_ir[i] = 5*gsl_ran_beta(r, 5, 1);
				//exp_sample_ir[i] = 5*gsl_ran_lognormal(r, 5, 0.25);
				//printf("exp: %f\n", exp_sample_ir[i]);
		}
		
		
		double* arrival_real	= MALLOC(nuser, double);
		arrival_real[0] = 1.0;
		for(i=1;i<nuser;i++)	{
			arrival_real[i] = arrival_real[i-1]+exp_sample_ir[i-1];
			//printf("arrival_real: %f\n", arrival_real[i]);
		}

		long* arrival	= MALLOC(nuser, long);
		for(i=0;i<nuser;i++)	{
					arrival[i] = (long)arrival_real[i];
					//printf("arrival: %ld\n", arrival[i]);
		}


		max = 0;
	for(i=0;i<nuser;i++)	{
		
		if(arrival[i]>max)	{
			max = arrival[i];
		}
		
	}

	printf("---max=%ld, sizeoflong=%d\n", max, sizeof(long));
	

	BtDb* t = bt_open("btree.dat", BT_rw, 12, 65535);
	BTERR e;
	for(i=0;i<nuser;i++)	{
//		atddtree_insert(t, arrival+i);
		e = bt_insertkey (t, arrival+i, 4, 0, i+1, i+1);
		//printf("insert %ld, height=%d\n", arrival[i], t->h);
		//printf("level=%d, e=%d\n", t->page->lvl, e);
	}
//	(char *name, uint mode, uint bits, uint cacheblk);
//	printf("level=%d\n", t->page->lvl);
}
예제 #16
0
static int
bt_play_open(struct voss_backend *pbe, const char *devname, int samplerate,
    int bufsize, int *pchannels, int *pformat)
{
	struct bt_config *cfg = pbe->arg;
	int retval;

	bt_init_cfg(cfg);

	retval = bt_open(pbe, devname, samplerate, bufsize, pchannels, pformat,
	    cfg, SDP_SERVICE_CLASS_AUDIO_SINK, 1);
	if (retval != 0)
		return (retval);

	/* setup codec */
	switch (cfg->codec) {
	case CODEC_SBC:
		cfg->handle.sbc_enc =
		    malloc(sizeof(*cfg->handle.sbc_enc));
		if (cfg->handle.sbc_enc == NULL)
			return (-1);
		memset(cfg->handle.sbc_enc, 0, sizeof(*cfg->handle.sbc_enc));
		break;
#ifdef HAVE_FFMPEG
	case CODEC_AAC:
		av_register_all();

		cfg->handle.av.codec = avcodec_find_encoder_by_name("aac");
		if (cfg->handle.av.codec == NULL) {
			DPRINTF("Codec AAC encoder not found\n");
			goto av_error_0;
		}
		cfg->handle.av.format = avformat_alloc_context();
		if (cfg->handle.av.format == NULL) {
			DPRINTF("Could not allocate format context\n");
			goto av_error_0;
		}
		cfg->handle.av.format->oformat =
		    av_guess_format("latm", NULL, NULL);
		if (cfg->handle.av.format->oformat == NULL) {
			DPRINTF("Could not guess output format\n");
			goto av_error_1;
		}
		cfg->handle.av.stream = avformat_new_stream(
		    cfg->handle.av.format, cfg->handle.av.codec);

		if (cfg->handle.av.stream == NULL) {
			DPRINTF("Could not create new stream\n");
			goto av_error_1;
		}
		cfg->handle.av.context = cfg->handle.av.stream->codec;
		if (cfg->handle.av.context == NULL) {
			DPRINTF("Could not allocate audio context\n");
			goto av_error_1;
		}
		avcodec_get_context_defaults3(cfg->handle.av.context,
		    cfg->handle.av.codec);

		cfg->handle.av.context->bit_rate = 128000;
		cfg->handle.av.context->sample_fmt = AV_SAMPLE_FMT_FLTP;
		cfg->handle.av.context->sample_rate = samplerate;
		switch (*pchannels) {
		case 1:
			cfg->handle.av.context->channel_layout = AV_CH_LAYOUT_MONO;
			cfg->handle.av.context->channels = 1;
			break;
		default:
			cfg->handle.av.context->channel_layout = AV_CH_LAYOUT_STEREO;
			cfg->handle.av.context->channels = 2;
			break;
		}

		cfg->handle.av.context->profile = FF_PROFILE_AAC_LOW;
		if (1) {
			AVDictionary *opts = NULL;

			av_dict_set(&opts, "strict", "-2", 0);
			av_dict_set_int(&opts, "latm", 1, 0);

			if (avcodec_open2(cfg->handle.av.context,
			    cfg->handle.av.codec, &opts) < 0) {
				av_dict_free(&opts);

				DPRINTF("Could not open codec\n");
				goto av_error_1;
			}
			av_dict_free(&opts);
		}
		cfg->handle.av.frame = av_frame_alloc();
		if (cfg->handle.av.frame == NULL) {
			DPRINTF("Could not allocate audio frame\n");
			goto av_error_2;
		}
		cfg->handle.av.frame->nb_samples = cfg->handle.av.context->frame_size;
		cfg->handle.av.frame->format = cfg->handle.av.context->sample_fmt;
		cfg->handle.av.frame->channel_layout = cfg->handle.av.context->channel_layout;
		cfg->rem_in_size = av_samples_get_buffer_size(NULL,
		    cfg->handle.av.context->channels,
		    cfg->handle.av.context->frame_size,
		    cfg->handle.av.context->sample_fmt, 0);

		cfg->rem_in_data = av_malloc(cfg->rem_in_size);
		if (cfg->rem_in_data == NULL) {
			DPRINTF("Could not allocate %u bytes sample buffer\n",
			    (unsigned)cfg->rem_in_size);
			goto av_error_3;
		}
		retval = avcodec_fill_audio_frame(cfg->handle.av.frame,
		    cfg->handle.av.context->channels,
		    cfg->handle.av.context->sample_fmt,
		    cfg->rem_in_data, cfg->rem_in_size, 0);
		if (retval < 0) {
			DPRINTF("Could not setup audio frame\n");
			goto av_error_4;
		}
		break;
av_error_4:
		av_free(cfg->rem_in_data);
av_error_3:
		av_frame_free(&cfg->handle.av.frame);
av_error_2:
		avcodec_close(cfg->handle.av.context);
av_error_1:
		avformat_free_context(cfg->handle.av.format);
		cfg->handle.av.context = NULL;
av_error_0:
		bt_close(pbe);
		return (-1);
#endif
	default:
		bt_close(pbe);
		return (-1);
	}
	return (0);
}
예제 #17
0
파일: str340.c 프로젝트: alcap-org/AlcapDAQ
int fb_init()
{
   bt_error_t status;           /* Bit 3 library error return type */
   char devname[BT_MAX_DEV_NAME];       /* Device to open */
   bt_devdata_t flag;

   /* Open the device in A24 space */
   bt_gen_name(0, BT_DEV_A24, devname, BT_MAX_DEV_NAME);
   status = bt_open(&btd, devname, BT_RDWR);
   if (status != BT_SUCCESS) {
      cm_msg(MERROR, "fb_init", "Cannot open Bit3 device driver");
      return FALSE;
   }
   bt_init(btd);
   bt_clrerr(btd);

   /* map SFI memory */
   status = bt_mmap(btd, &_sfi, SFI_ADDRESS, SFI_SIZE, BT_RDWR, BT_SWAP_DEFAULT);
   if (status != BT_SUCCESS) {
      cm_msg(MERROR, "fb_init", "Cannot map VME memory");
      bt_close(btd);
      return FALSE;
   }

   /* Open the device in local memory */
   bt_gen_name(0, BT_DEV_LM, devname, BT_MAX_DEV_NAME);
   status = bt_open(&btd_lm, devname, BT_RDWR);
   if (status != BT_SUCCESS) {
      cm_msg(MERROR, "fb_init", "Cannot open Bit3 device for local memory");
      return FALSE;
   }
   bt_clrerr(btd_lm);

   /* map local memory */
   status =
       bt_mmap(btd_lm, &remote_ram_buffer, 0, REMOTE_RAM_SIZE, BT_RDWR, BT_SWAP_DEFAULT);
   if (status != BT_SUCCESS) {
      cm_msg(MERROR, "fb_init", "Cannot map local memory");
      bt_close(btd);
      return FALSE;
   }

   /* clear local memory */
   memset(remote_ram_buffer, 0, REMOTE_RAM_SIZE);

   /* force D32 mode */
   bt_get_info(btd, BT_INFO_MMAP_AMOD, &flag);
   flag = BT_AMOD_A24_SD;
   bt_set_info(btd, BT_INFO_MMAP_AMOD, flag);

   /* sequencer reset */
   SFI_OUT(SFI_SEQUENCER_RESET, 0);

   /* arbitration level */
//  SFI_OUT(SFI_FASTBUS_ARBITRATION_LEVEL_REGISTER, 0x15);
   SFI_OUT(SFI_FASTBUS_ARBITRATION_LEVEL_REGISTER, 0xBF);

   /* timeout */
   SFI_OUT(SFI_FASTBUS_TIMEOUT_REGISTER, 0x73);

   /* sequencer enable */
   SFI_OUT(SFI_SEQUENCER_ENABLE, 0);

   /* switch off all output */
   SFI_OUT(SFI_CLEAR_BOTH_LCA1_TEST_REGISTER, 0);

   /* clear registers */
   SFI_OUT(SFI_RESET_REGISTER_GROUP_LCA2, 0);

   return SUCCESS;
}