Exemple #1
0
static void
init_netifs(void)
{
#if PPP_SUPPORT
  pppInit();
#if PPP_PTY_TEST
  ppp_sio = sio_open(2);
#else
  ppp_sio = sio_open(0);
#endif
  if(!ppp_sio)
  {
      perror("Error opening device: ");
      exit(1);
  }

#ifdef LWIP_PPP_CHAP_TEST
  pppSetAuth(PPPAUTHTYPE_CHAP, "lwip", "mysecret");
#endif

  pppOpen(ppp_sio, pppLinkStatusCallback, NULL);
#endif /* PPP_SUPPORT */
  
#if LWIP_DHCP
  {
    IP4_ADDR(&gw, 0,0,0,0);
    IP4_ADDR(&ipaddr, 0,0,0,0);
    IP4_ADDR(&netmask, 0,0,0,0);

    netif_add(&netif, &ipaddr, &netmask, &gw, NULL, tapif_init,
              tcpip_input);
    netif_set_default(&netif);
    dhcp_start(&netif);
  }
#else
  
  netif_set_default(netif_add(&netif,&ipaddr, &netmask, &gw, NULL, tapif_init,
                  tcpip_input));
  netif_set_up(&netif);

#endif

#if 0
  /* Only used for testing purposes: */
  netif_add(&ipaddr, &netmask, &gw, NULL, pcapif_init, tcpip_input);
#endif
  
#if LWIP_TCP  
  //tcpecho_init();
  //shell_init();
  httpd_init();
#endif
#if LWIP_UDP  
  //udpecho_init();
#endif  
  /*  sys_timeout(5000, tcp_debug_timeout, NULL);*/
}
Exemple #2
0
unsigned long open_audio(unsigned long f, int s)
   {
	struct sio_par par;
	int buf_max;

	hdl = sio_open(NULL, SIO_PLAY, 0);
	if (hdl == NULL)
		end_all("Error opening audio device");

	realpos = 0;
	sio_onmove(hdl, movecb, NULL);

	sio_initpar(&par);
	if (f)
		par.rate = f;
	par.pchan = 2;
	if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par) || !sio_start(hdl) ||
	    (par.bits != 8 && par.bits != 16) || par.pchan > 2)
		end_all("Sorry, no audio format supported by this binary is available");

	buf_max = par.appbufsz * par.bps * par.pchan;
	current_freq = par.rate;
	stereo = par.pchan == 2 ? 1 : 0;

	dsp_samplesize = par.bits;
	dsize = par.bps;
	buffer = malloc(buf_max);
	buffer16 = (short *)buffer;

	idx = 0;
	samples_max = buf_max / dsize / par.pchan;
	set_watched_scalar(FREQUENCY, current_freq);
	total = 0;
	return current_freq;
   }
Exemple #3
0
bool CAESinkSNDIO::Initialize(AEAudioFormat &format, std::string &device)
{
  if ((m_hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0)) == nullptr)
  {
    CLog::Log(LOGERROR, "CAESinkSNDIO::Initialize - Failed to open device");
    return false;
  }

  AudioFormatToPar(format);
  if (!sio_setpar(m_hdl, &m_par) ||
      !sio_getpar(m_hdl, &m_par) ||
      !ParToAudioFormat(format))
  {
    CLog::Log(LOGERROR, "CAESinkSNDIO::Initialize - could not negotiate parameters");
    return false;
  }

  m_played = m_written = 0;

  sio_onmove(m_hdl, CAESinkSNDIO::OnmoveCb, this);

  if (!sio_start(m_hdl))
  {
    CLog::Log(LOGERROR, "CAESinkSNDIO::Initialize - sio_start failed");
    return false;
  }

  return true;
}
Exemple #4
0
/**
 * SLIP netif initialization
 *
 * Call the arch specific sio_open and remember
 * the opened device in the state field of the netif.
 *
 * @param netif the lwip network interface structure for this slipif
 * @return ERR_OK if serial line could be opened,
 *         ERR_MEM if no memory could be allocated,
 *         ERR_IF is serial line couldn't be opened
 *
 * @note netif->num must contain the number of the serial port to open
 *       (0 by default). If netif->state is != NULL, it is interpreted as an
 *       u8_t pointer pointing to the serial port number instead of netif->num.
 *
 */
err_t
slipif_init(struct netif *netif)
{
  struct slipif_priv *priv;
  u8_t sio_num;

  LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%"U16_F"\n", (u16_t)netif->num));

  /* Allocate private data */
  priv = (struct slipif_priv *)mem_malloc(sizeof(struct slipif_priv));
  if (!priv) {
    return ERR_MEM;
  }

  netif->name[0] = 's';
  netif->name[1] = 'l';
#if LWIP_IPV4
  netif->output = slipif_output_v4;
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
  netif->output_ip6 = slipif_output_v6;
#endif /* LWIP_IPV6 */
  netif->mtu = SLIP_MAX_SIZE;

  /* netif->state or netif->num contain the port number */
  if (netif->state != NULL) {
    sio_num = *(u8_t*)netif->state;
  } else {
    sio_num = netif->num;
  }
  /* Try to open the serial port. */
  priv->sd = sio_open(sio_num);
  if (!priv->sd) {
    /* Opening the serial port failed. */
    mem_free(priv);
    return ERR_IF;
  }

  /* Initialize private data */
  priv->p = NULL;
  priv->q = NULL;
  priv->state = SLIP_RECV_NORMAL;
  priv->i = 0;
  priv->recved = 0;
#if SLIP_RX_FROM_ISR
  priv->rxpackets = NULL;
#endif

  netif->state = priv;

  /* initialize the snmp variables and counters inside the struct netif */
  MIB2_INIT_NETIF(netif, snmp_ifType_slip, SLIP_SIO_SPEED(priv->sd));

#if SLIP_USE_RX_THREAD
  /* Create a thread to poll the serial line. */
  sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop_thread, netif,
    SLIPIF_THREAD_STACKSIZE, SLIPIF_THREAD_PRIO);
#endif /* SLIP_USE_RX_THREAD */
  return ERR_OK;
}
Exemple #5
0
static ALCenum sndio_open_playback(ALCdevice *device, const ALCchar *deviceName)
{
    sndio_data *data;

    if(!deviceName)
        deviceName = sndio_device;
    else if(strcmp(deviceName, sndio_device) != 0)
        return ALC_INVALID_VALUE;

    data = calloc(1, sizeof(*data));
    data->killNow = 0;

    data->sndHandle = sio_open(NULL, SIO_PLAY, 0);
    if(data->sndHandle == NULL)
    {
        free(data);
        ERR("Could not open device\n");
        return ALC_INVALID_VALUE;
    }

    device->DeviceName = strdup(deviceName);
    device->ExtraData = data;

    return ALC_NO_ERROR;
}
Exemple #6
0
/**
 * SLIP netif initialization
 *
 * Call the arch specific sio_open and remember
 * the opened device in the state field of the netif.
 *
 * @param netif the lwip network interface structure for this slipif
 * @return ERR_OK if serial line could be opened,
 *         ERR_IF is serial line couldn't be opened
 *
 * @note netif->num must contain the number of the serial port to open
 *       (0 by default)
 */
err_t
slipif_init(struct netif *netif)
{

  LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%"U16_F"\n", (u16_t)netif->num));

  netif->name[0] = 's';
  netif->name[1] = 'l';
  netif->output = slipif_output;
  netif->mtu = MAX_SIZE;
  netif->flags = NETIF_FLAG_POINTTOPOINT;

  /* Try to open the serial port (netif->num contains the port number). */
  netif->state = sio_open(netif->num);
  if (!netif->state) {
    /* Opening the serial port failed. */
    return ERR_IF;
  }

  /* initialize the snmp variables and counters inside the struct netif
   * ifSpeed: no assumption can be made without knowing more about the
   * serial line!
   */
  NETIF_INIT_SNMP(netif, snmp_ifType_slip, 0);

  /* Create a thread to poll the serial line. */
  sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop, netif, SLIPIF_THREAD_STACKSIZE, SLIPIF_THREAD_PRIO);
  return ERR_OK;
}
Exemple #7
0
static int
audio_open(void)
{
 hdl = sio_open(NULL, SIO_PLAY, 0);
 if (hdl == NULL)
  {
   fprintf(stderr, "sio_open failed\n");
   return 0;
  }
 return 1;
}
int
audioOpen()
{
	hdl = sio_open(NULL, SIO_PLAY, 0);
	if (hdl == NULL) {
		fprintf(stderr, "unable to open audio device\n");
		return 0;
	}

	return true;
}
Exemple #9
0
/* used to probe and to configure the device.  don't use sio_start() here. */
static int
open_sndio_device(int input)
{
	hdl = sio_open(NULL, (input ? SIO_REC : SIO_PLAY), 0);
	if (hdl == NULL) {
		uszprintf(allegro_error, ALLEGRO_ERROR_SIZE,
		    get_config_text("sio_opn failed"));
		return -1;
	}

	sio_initpar(&par);
	par.bits = (_sound_bits == 8) ? 8 : 16;
	par.sig = (_sound_bits == 8) ? 0 : 1;
	if (input)
		par.rchan = (_sound_stereo) ? 2 : 1;
	else
		par.pchan = (_sound_stereo) ? 2 : 1;
	par.rate = (_sound_freq > 0) ? _sound_freq : 48000;
	par.le = SIO_LE_NATIVE;
	/* allegro wants small blocks */
	par.round = 512;
	par.appbufsz = par.rate / 10;

	if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par) ||
	    (par.bits != 8 && par.bits != 16) ||
	    (par.bits == 8 && par.sig) ||
	    (par.bits == 16 && !par.sig) ||
	    (par.bits == 16 && par.le != SIO_LE_NATIVE) ||
	    (input && (par.rchan != 1 && par.rchan != 2)) ||
	    (!input && (par.pchan != 1 && par.pchan != 2))) {
		ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE,
		    get_config_text("could not set sndio parameters"));
		sio_close(hdl);
		return -1;
	}

	_sound_bits = par.bits;
	_sound_stereo = input ? par.rchan == 2 : par.pchan == 2;
	_sound_freq = par.rate;

	if (input) {
		sndio_rec_round = par.round; 
		sndio_rec_appbufsz = par.appbufsz;
		sndio_rec_bufsize = par.round * par.bps * par.rchan;
	} else {
		sndio_play_round = par.round;
		sndio_play_appbufsz = par.appbufsz;
		sndio_play_bufsize = sndio_play_round * par.bps * par.pchan;
	}
	sndio_signed = par.sig ? 1 : 0;

	return 0;
}
Exemple #10
0
static int Audio_Available(void)
{
	struct sio_hdl *this_hdl;
	int available = 0;

	if ( (this_hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0)) != NULL ) {
		sio_close(this_hdl);
		available = 1;
	}

	return available;
}
Exemple #11
0
static int open_output(void)
{
  static struct sio_par par, newpar;

  sndio_ctx = sio_open(NULL, SIO_PLAY, 0);
  if (sndio_ctx == NULL) {
    ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "sio_open() failed");
    return -1;
  }

  sio_initpar(&par);

  par.sig = 1;
  par.pchan = (dpm.encoding & PE_MONO) ? 1 : 2;
  par.le = SIO_LE_NATIVE;
  par.rate = dpm.rate;
  if (dpm.encoding & PE_24BIT) {
    par.bits = 24;
    par.bps = 3;
  } else if (dpm.encoding & PE_16BIT) {
    par.bits = 16;
    par.bps = 2;
  } else {
    par.bits = 8;
    par.bps = 1;
  }

  if (!sio_setpar(sndio_ctx, &par)) {
    ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "sio_setpar() failed");
    return -1;
  }

  if (sio_getpar(sndio_ctx, &newpar) == 0) {
    ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "sio_getpar() failed");
    return -1;
  }
  if (newpar.sig != par.sig ||
      newpar.le != par.le ||
      newpar.pchan != par.pchan ||
      newpar.bits != par.bits ||
      newpar.bps != par.bps ||
      newpar.rate * 1000 > par.rate * 1005 ||
      newpar.rate * 1000 < par.rate *  995) {
    ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "couldn't set output play parameters");
    return -1;
  }

  if (!sio_start(sndio_ctx)) {
    ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "sio_start() failed");
    return -1;
  }
  return 0;
}
Exemple #12
0
int ai_sndio_init(audio_in_t *ai)
{
    int err;

    if ((ai->sndio.hdl = sio_open(ai->sndio.device, SIO_REC, 0)) == NULL) {
	mp_msg(MSGT_TV, MSGL_ERR, "could not open sndio audio");
	return -1;
    }

    err = ai_sndio_setup(ai);

    return err;
}
Exemple #13
0
static void
sndio_play (int argc, char *argv [])
{	struct sio_hdl	*hdl ;
	struct sio_par	par ;
	short	 	buffer [BUFFER_LEN] ;
	SNDFILE	*sndfile ;
	SF_INFO	sfinfo ;
	int		k, readcount ;

	for (k = 1 ; k < argc ; k++)
	{	printf ("Playing %s\n", argv [k]) ;
		if (! (sndfile = sf_open (argv [k], SFM_READ, &sfinfo)))
		{	puts (sf_strerror (NULL)) ;
			continue ;
			} ;

		if (sfinfo.channels < 1 || sfinfo.channels > 2)
		{	printf ("Error : channels = %d.\n", sfinfo.channels) ;
			continue ;
			} ;

		if ((hdl = sio_open (NULL, SIO_PLAY, 0)) == NULL)
		{	fprintf (stderr, "open sndio device failed") ;
			return ;
			} ;

		sio_initpar (&par) ;
		par.rate = sfinfo.samplerate ;
		par.pchan = sfinfo.channels ;
		par.bits = 16 ;
		par.sig = 1 ;
		par.le = SIO_LE_NATIVE ;

		if (! sio_setpar (hdl, &par) || ! sio_getpar (hdl, &par))
		{	fprintf (stderr, "set sndio params failed") ;
			return ;
			} ;

		if (! sio_start (hdl))
		{	fprintf (stderr, "sndio start failed") ;
			return ;
			} ;

		while ((readcount = sf_read_short (sndfile, buffer, BUFFER_LEN)))
			sio_write (hdl, buffer, readcount * sizeof (short)) ;

		sio_close (hdl) ;
		} ;

	return ;
} /* sndio_play */
Exemple #14
0
static void
swfdec_playback_stream_open (SwfdecPlayback *sound, SwfdecAudio *audio)
{
  Stream *stream;
  struct sio_hdl *hdl;
  struct sio_par par;

  hdl = sio_open (NULL, SIO_PLAY, 0);
  if (hdl == NULL) {
    g_printerr ("Could not open sndio\n");
    return;
  }

  sio_initpar (&par);

  par.bits = 16;
  par.sig = 1;
  par.pchan = 2;
  par.rate = 44100;
  par.appbufsz = 8192;

  if (!sio_setpar (hdl, &par)) {
    g_printerr ("\n\nCould not set sndio hardware parameters\n");
    goto fail;
  }
  if (!sio_getpar (hdl, &par)) {
    g_printerr ("\n\nCould not get sndio hardware parameters\n");
    goto fail;
  }

  stream = g_new0 (Stream, 1);
  stream->write = try_write;
  stream->sound = sound;
  stream->audio = g_object_ref (audio);
  stream->hdl = hdl;
  stream->par = par;
  sound->streams = g_list_prepend (sound->streams, stream);

  sio_onmove (hdl, sndio_movecb, stream);
  stream->f_written = stream->f_played = 0;

  g_signal_connect (stream->audio, "changed", 
      G_CALLBACK (swfdec_playback_stream_changed), stream);
  g_signal_connect (stream->audio, "new-data", 
      G_CALLBACK (swfdec_playback_stream_new_data), stream);
  swfdec_playback_stream_start (stream);
  return;

fail:
  sio_close (hdl);
}
Exemple #15
0
//---------------------------------------------------------------------------
bool __fastcall CSerialPort::Open(int nPort,int nBaudRate,int nMode)
{
        m_nPortNo=nPort;
  if(sio_open(nPort)!=SIO_OK)
    return false;

  //if(sio_ioctl(nPort,B9600,BIT_8|STOP_1|P_NONE)!=SIO_OK)
        if( sio_ioctl(nPort,nBaudRate,nMode) != SIO_OK )
                return false;

  //sio_SetReadTimeouts(nPort,MAXDWORD,2000);

	return true;
}
Exemple #16
0
/**
 * SLIP netif initialization
 *
 * Call the arch specific sio_open and remember
 * the opened device in the state field of the netif.
 *
 * @param netif the lwip network interface structure for this slipif
 * @return ERR_OK if serial line could be opened,
 *         ERR_MEM if no memory could be allocated,
 *         ERR_IF is serial line couldn't be opened
 *
 * @note netif->num must contain the number of the serial port to open
 *       (0 by default)
 */
err_t
slipif_init(struct netif *netif)
{
  struct slipif_priv *priv;

  LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%"U16_F"\n", (u16_t)netif->num));

  /* Allocate private data */
  priv = mem_malloc(sizeof(struct slipif_priv));
  if (!priv) {
    return ERR_MEM;
  }

  netif->name[0] = 's';
  netif->name[1] = 'l';
  netif->output = slipif_output;
  netif->mtu = SLIP_MAX_SIZE;
  netif->flags |= NETIF_FLAG_POINTTOPOINT;

  /* Try to open the serial port (netif->num contains the port number). */
  priv->sd = sio_open(netif->num);
  if (!priv->sd) {
    /* Opening the serial port failed. */
    mem_free(priv);
    return ERR_IF;
  }

  /* Initialize private data */
  priv->p = NULL;
  priv->q = NULL;
  priv->state = SLIP_RECV_NORMAL;
  priv->i = 0;
  priv->recved = 0;

  netif->state = priv;

  /* initialize the snmp variables and counters inside the struct netif
   * ifSpeed: no assumption can be made without knowing more about the
   * serial line!
   */
  NETIF_INIT_SNMP(netif, snmp_ifType_slip, 0);

#if !NO_SYS
  /* Create a thread to poll the serial line. */
  sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop_thread, netif,
    SLIPIF_THREAD_STACKSIZE, SLIPIF_THREAD_PRIO);
#endif
  return ERR_OK;
}
Exemple #17
0
static int sndio_open(sample_format_t sf, const channel_position_t *channel_map)
{
	int ret = 0;

	hdl = sio_open(NULL, SIO_PLAY, 0);
	if (hdl == NULL)
		return -OP_ERROR_INTERNAL;

	if ((ret = sndio_set_sf(sf)) < 0) {
		sndio_close();
		return ret;
	}

	return OP_ERROR_SUCCESS;
}
static int
init (struct xmp_context *ctx)
{
	 struct sio_par par, askpar;
	 struct xmp_options *opt = &ctx->o;

	 hdl = sio_open (NULL, SIO_PLAY, 0);
	 if (hdl == NULL) {
		 fprintf (stderr, "%s: failed to open audio device\n",
			 __func__);
		 return XMP_ERR_DINIT;
	 }

	 sio_initpar (&par);
	 par.pchan = opt->outfmt & XMP_FMT_MONO ? 1 : 2;
	 par.rate = opt->freq;
	 par.bits = opt->resol;
	 par.sig = opt->resol > 8 ? 1 : 0;
	 par.le = SIO_LE_NATIVE;
	 par.appbufsz = par.rate / 4;

	 askpar = par;
	 if (!sio_setpar (hdl, &par) || !sio_getpar (hdl, &par)) {
		 fprintf (stderr, "%s: failed to set parameters\n", __func__);
		 goto error;
	 }

	 if ((par.bits == 16 && par.le != askpar.le) ||
	     par.bits != askpar.bits ||
	     par.sig != askpar.sig ||
	     par.pchan != askpar.pchan ||
	     ((par.rate * 1000 < askpar.rate * 995) ||
	      (par.rate * 1000 > askpar.rate * 1005))) {
		 fprintf (stderr, "%s: parameters not supported\n", __func__);
		 goto error;
	 }

	 if (!sio_start (hdl)) {
		 fprintf (stderr, "%s: failed to start audio device\n",
			 __func__);
		 goto error;
	 }
	 return xmp_smix_on (ctx);

error:
	 sio_close (hdl);
	 return XMP_ERR_DINIT;
}
int
sa_stream_open(sa_stream_t *s)
{
	struct sio_hdl *handle;
	struct sio_par par;

	if (s == NULL)
		return SA_ERROR_NO_INIT;

	if (s->handle != NULL)
		return SA_ERROR_INVALID;

	handle = sio_open(NULL, SIO_PLAY, 0);
	if (handle == NULL)
		return SA_ERROR_NO_DEVICE;

	sio_initpar(&par);
	par.bits = s->format;
	par.le = SIO_LE_NATIVE;
	par.pchan = s->channels;
	par.rate = s->rate;
	par.sig = 1;

	if (!sio_setpar(handle, &par) || !sio_getpar(handle, &par)) {
		sio_close(handle);
		return SA_ERROR_NOT_SUPPORTED;
	}

	if (par.bits != s->format || par.le != SIO_LE_NATIVE ||
	    par.pchan != s->channels || par.rate != s->rate || par.sig != 1) {
		sio_close(handle);
		return SA_ERROR_NOT_SUPPORTED;
	}

	sio_onmove(handle, onmove_callback, s);

	if (!sio_start(handle)) {
		sio_close(handle);
		return SA_ERROR_NOT_SUPPORTED;
	}

	s->bpf = par.pchan * par.bps;
	s->buffer = par.bufsz * s->bpf;
	s->handle = handle;

	return SA_SUCCESS;
}
Exemple #20
0
 /******************* Start Scan ***************/
 void CMainFrame:: OnStartscan()
 {
	 if(SIO_OK!=sio_open(Port))
		{
			MessageBox("串口打开错误");
			return;
		}
   else
		{
			sio_ioctl(Port,BaudRate,DataBits | StopBits | Parity);
			sio_cnt_irq(Port,CntIrq,1);
		}

   Scan_num=0;
   OnBtnSend(num);
   //OnBtnSend('1');
 }
Exemple #21
0
//初始化端口
BOOL CComm_Thread::Init_ComPort()
{
    COApp* pApp=(COApp*)AfxGetApp();
    unsigned int x_Baud[]= {B300,B600,B1200,B2400,B4800,B9600,B19200,B38400,B57600};

    if(CommLink)
        return false;

    if(sio_open(pApp->x_Port)!=0)
        return false;

    sio_ioctl(pApp->x_Port,x_Baud[pApp->x_Order],P_NONE|BIT_8|STOP_1);
    sio_SetReadTimeouts(pApp->x_Port,200,200);
    sio_flush(pApp->x_Port,2);

    return true;
}
Exemple #22
0
/**
 * SLIP netif initialization
 *
 * Call the arch specific sio_open and remember
 * the opened device in the state field of the netif.
 */
err_t
slipif_init(struct netif *netif)
{

  LWIP_DEBUGF(SLIP_DEBUG, ("slipif_init: netif->num=%x\n", (int)netif->num));

  netif->name[0] = 's';
  netif->name[1] = 'l';
  netif->output = slipif_output;
  netif->mtu = 1500;
  netif->flags = NETIF_FLAG_POINTTOPOINT;

  netif->state = sio_open(netif->num);
  if (!netif->state)
    return ERR_IF;

  sys_thread_new(slipif_loop, netif, SLIPIF_THREAD_PRIO);
  return ERR_OK;
}
Exemple #23
0
/***************************************************************
【函数功能】: 打开串口
【输    入】: port:串口号(默认0)。【构造函数时也可指定串口号】
【输    出】: 执行结果:0正确,-1错误。
【说    明】: 正确用法有3种:<1> CGyro *p = new CGyro(n);  p->open();
					<2> CGyro *p = new CGyro(n); p->open(n);
					<3> CGyro *p = new CGyro;   p->open(n);
***************************************************************/
int CGyro::Open(int port)
{
	if(m_bPortOpened)
		return 1;
	// 读取配置
	string iniFile = string(INI_FILE);
	//if (mrpt::system::fileExists(iniFile) == false)	// INI 文件找不到
	//{
	//	cout << "!Gyro惯导:start():找不到ini文件!" << iniFile << endl;
	//	return -1;	
	//}					// ini文件在主窗口init时检查一次即可,不存在则退出
	mrpt::utils::CConfigFile INI_Cfg(iniFile);
	m_iPort = INI_Cfg.read_int("Gyro", "COM_Port", 0);

	// 如果形参有传入,则以传入值为主,并修改ini文件
	if (port > 0)
	{
		INI_Cfg.write("Gyro", "COM_Port", port);	// 用传入形参更新配置文件数据
		m_iPort = port;
	}
	else
	{
		if (m_iPort <= 0)
		{
			cout<<"[!!!] Gyro: 必须指定一个大于0的串口号!"<<endl;
			return -1;
		}
	}
	// 打开串口
	if(sio_open(m_iPort) != SIO_OK)
	{
		cout<<"[!!!] Gyro: 打开串口错误!"<<endl;
		return -1;
	}
	sio_ioctl(m_iPort, B115200, P_NONE | BIT_8 | STOP_1 );
	sio_cnt_irq(m_iPort,RecvCall, 1);

	m_bPortOpened = true;
	cout<<"[+] Gyro: Started!"<<endl;

	return 0;
}
Exemple #24
0
static int init(int argc, char **argv) {
	sio = sio_open(SIO_DEVANY, SIO_PLAY, 0);
	if (!sio)
		die("sndio: cannot connect to sound server");

	sio_initpar(&par);

	par.bits = 16;
	par.rate = 44100;
	par.pchan = 2;
	par.le = SIO_LE_NATIVE;
	par.sig = 1;

	if (!sio_setpar(sio, &par))
		die("sndio: failed to set audio parameters");
	if (!sio_getpar(sio, &par))
		die("sndio: failed to get audio parameters");

	return 0;
}
Exemple #25
0
int
main(int argc, char **argv) {
	int ch;
	unsigned mode = SIO_PLAY | SIO_REC;
	struct sio_hdl *hdl;
	
	while ((ch = getopt(argc, argv, "pr")) != -1) {
		switch(ch) {
		case 'p':
			mode &= ~SIO_REC;
			break;
		case 'r':
			mode &= ~SIO_PLAY;
			break;
		default:
			usage();
			exit(1);
			break;
		}
	}
	if (mode == 0) {
		fprintf(stderr, "-p and -r flags are mutualy exclusive\n");
		exit(1);
	}
	hdl = sio_open(NULL, mode, 0);
	if (hdl == NULL) {
		fprintf(stderr, "sio_open() failed\n");
		exit(1);
	}
	if (!sio_getcap(hdl, &cap)) {
		fprintf(stderr, "sio_setcap() failed\n");
		exit(1);
	}
	cap_pr(&cap);
	sio_close(hdl);
	return 0;
}
Exemple #26
0
static int play_alloc(struct auplay_st **stp, const struct auplay *ap,
		      struct auplay_prm *prm, const char *device,
		      auplay_write_h *wh, void *arg)
{
	struct auplay_st *st;
	struct sio_par *par = NULL;
	int err;
	const char *name;

	if (!stp || !ap || !prm)
		return EINVAL;

	name = (str_isset(device)) ? device : SIO_DEVANY;

	if ((st = mem_zalloc(sizeof(*st), auplay_destructor)) == NULL)
		return ENOMEM;

	st->ap  = ap;
	st->wh  = wh;
	st->arg = arg;
	st->hdl = sio_open(name, SIO_PLAY, 0);

	if (!st->hdl) {
		warning("sndio: could not open auplay device '%s'\n", name);
		err = EINVAL;
		goto out;
	}

	par = sndio_initpar(prm->srate, prm->ch);
	if (!par) {
		err = ENOMEM;
		goto out;
	}

	if (!sio_setpar(st->hdl, par)) {
		err = EINVAL;
		goto out;
	}

	if (!sio_getpar(st->hdl, par)) {
		err = EINVAL;
		goto out;
	}

	st->sampc = prm->srate * prm->ch * prm->ptime / 1000;

	st->sampv = mem_alloc(2 * st->sampc, NULL);
	if (!st->sampv) {
		err = ENOMEM;
		goto out;
	}

	st->run = true;
	err = pthread_create(&st->thread, NULL, write_thread, st);
	if (err)
		st->run = false;

 out:
	mem_deref(par);
	if (err)
		mem_deref(st);
	else
		*stp = st;

	return err;
}
Exemple #27
0
/*
 * Open the device.
 */
struct siofile *
siofile_new(struct fileops *ops, char *path, unsigned int *rmode,
    struct aparams *ipar, struct aparams *opar,
    unsigned int *bufsz, unsigned int *round)
{
	struct sio_par par;
	struct sio_hdl *hdl;
	struct siofile *f;
	unsigned int mode = *rmode;

	hdl = sio_open(path, mode, 1);
	if (hdl == NULL) {
		if (mode != (SIO_PLAY | SIO_REC))
			return NULL;
		hdl = sio_open(path, SIO_PLAY, 1);
		if (hdl != NULL)
			mode = SIO_PLAY;
		else {
			hdl = sio_open(path, SIO_REC, 1);
			if (hdl != NULL)
				mode = SIO_REC;
			else
				return NULL;
		}
#ifdef DEBUG
		if (debug_level >= 1) {
			dbg_puts("warning, device opened in ");
			dbg_puts(mode == SIO_PLAY ? "play-only" : "rec-only");
			dbg_puts(" mode\n");
		}
#endif
	}

	sio_initpar(&par);
	if (mode & SIO_REC) {
		par.bits = ipar->bits;
		par.bps = ipar->bps;
		par.sig = ipar->sig;
		par.le = ipar->le;
		par.msb = ipar->msb;
		par.rate = ipar->rate;
		par.rchan = ipar->cmax + 1;
	} else {
		par.bits = opar->bits;
		par.bps = opar->bps;
		par.sig = opar->sig;
		par.le = opar->le;
		par.msb = opar->msb;
		par.rate = opar->rate;
	}
	if (mode & SIO_PLAY)
		par.pchan = opar->cmax + 1;
	if (*bufsz)
		par.appbufsz = *bufsz;
	if (*round)
		par.round = *round;
	if (!sio_setpar(hdl, &par))
		goto bad_close;
	if (!sio_getpar(hdl, &par))
		goto bad_close;
	if (mode & SIO_REC) {
		ipar->bits = par.bits;
		ipar->bps = par.bps;
		ipar->sig = par.sig;
		ipar->le = par.le;
		ipar->msb = par.msb;
		ipar->rate = par.rate;
		ipar->cmin = 0;
		ipar->cmax = par.rchan - 1;
	}
	if (mode & SIO_PLAY) {
		opar->bits = par.bits;
		opar->bps = par.bps;
		opar->sig = par.sig;
		opar->le = par.le;
		opar->msb = par.msb;
		opar->rate = par.rate;
		opar->cmin = 0;
		opar->cmax = par.pchan - 1;
	}
	*rmode = mode;
	*bufsz = par.bufsz;
	*round = par.round;
	f = (struct siofile *)file_new(ops, path, sio_nfds(hdl));
	if (f == NULL)
		goto bad_close;
	f->hdl = hdl;
	f->started = 0;
	f->wtickets = 0;
	f->rtickets = 0;
	f->wbpf = par.pchan * par.bps;
	f->rbpf = par.rchan * par.bps;
	f->bufsz = par.bufsz;
	sio_onmove(f->hdl, siofile_cb, f);
	return f;
 bad_close:
	sio_close(hdl);
	return NULL;
}
Exemple #28
0
/*
---------------------------------------
    打开 RS232 通讯接口
---------------------------------------
*/
static bool_t
qst_com_rs232 (
  __CR_IN__ void_t*     parm,
  __CR_IN__ uint_t      argc,
  __CR_IN__ ansi_t**    argv
    )
{
    int32u  baud;
    uint_t  port, bits;
    uint_t  stop, parity;
    /* --------------- */
    const ansi_t*   sstop;
    const ansi_t*   sparity;

    /* 参数解析 <串口号> [波特率] [数据位] [校验位] [停止位] */
    if (argc < 2)
        return (FALSE);
    bits = 8;
    baud = 115200UL;
    stop = CR_SIO_STOP10;
    parity = CR_SIO_NOP;
    sstop = "1";
    sparity = "no";
    port = str2intxA(argv[1]);
    if (argc > 2) {
        baud = str2intx32A(argv[2]);
        if (argc > 3) {
            bits = str2intxA(argv[3]);
            if (argc > 4) {
                sparity = argv[4];
                if (str_cmpA(argv[4], "no") == 0)
                    parity = CR_SIO_NOP;
                else
                if (str_cmpA(argv[4], "odd") == 0)
                    parity = CR_SIO_ODD;
                else
                if (str_cmpA(argv[4], "even") == 0)
                    parity = CR_SIO_EVEN;
                else
                if (str_cmpA(argv[4], "mark") == 0)
                    parity = CR_SIO_MARK;
                else
                if (str_cmpA(argv[4], "space") == 0)
                    parity = CR_SIO_SPCE;
                else
                    sparity = "no";
                if (argc > 5) {
                    sstop = argv[5];
                    if (str_cmpA(argv[5], "1") == 0)
                        stop = CR_SIO_STOP10;
                    else
                    if (str_cmpA(argv[5], "1.5") == 0)
                        stop = CR_SIO_STOP15;
                    else
                    if (str_cmpA(argv[5], "2") == 0)
                        stop = CR_SIO_STOP20;
                    else
                        sstop = "1";
                }
            }
        }
    }

    sQstComm*   ctx = (sQstComm*)parm;

    /* 关闭当前接口并打开串口 */
    if (!sio_open(port))
        return (FALSE);
    sio_setup(port, baud, bits, parity, stop);
    sio_set_buffer(port, 1024, 1024);
    sio_set_rd_timeout(port, 0, 0, QCOM_CUTDOWN);
    sio_set_wr_timeout(port, 0, QCOM_SNDTOUT);
    sio_clear_error(port);
    sio_flush(port, CR_SIO_FLU_RT);

    /* 设置工作参数 */
    qst_com_close(parm, argc, argv);
    ctx->comm.obj.port = port;
    ctx->comm.send = qst_rs232_send;

    /* 启动接收线程 */
    ctx->comm.thrd = thread_new(0, qst_rs232_main, parm, FALSE);
    if (ctx->comm.thrd == NULL) {
        sio_close(port);
        return (FALSE);
    }
    TRY_FREE(ctx->comm.title);
    ctx->comm.title = str_fmtA(" - COM%u, %u, %u, %s, %s",
                            port, baud, bits, sparity, sstop);
    qst_update_title(ctx);
    return (TRUE);
}
Exemple #29
0
static int
sndio_stream_init(cubeb * context,
                  cubeb_stream ** stream,
                  char const * stream_name,
                  cubeb_devid input_device,
                  cubeb_stream_params * input_stream_params,
                  cubeb_devid output_device,
                  cubeb_stream_params * output_stream_params,
                  unsigned int latency_frames,
                  cubeb_data_callback data_callback,
                  cubeb_state_callback state_callback,
                  void *user_ptr)
{
  cubeb_stream *s;
  struct sio_par wpar, rpar;
  cubeb_sample_format format;
  int rate;
  size_t bps;

  DPR("sndio_stream_init(%s)\n", stream_name);

  s = malloc(sizeof(cubeb_stream));
  if (s == NULL)
    return CUBEB_ERROR;
  memset(s, 0, sizeof(cubeb_stream));
  s->mode = 0;
  if (input_stream_params) {
    if (input_stream_params->prefs & CUBEB_STREAM_PREF_LOOPBACK) {
      DPR("sndio_stream_init(), loopback not supported\n");
      goto err;
    }
    s->mode |= SIO_REC;
    format = input_stream_params->format;
    rate = input_stream_params->rate;
  }
  if (output_stream_params) {
    if (output_stream_params->prefs & CUBEB_STREAM_PREF_LOOPBACK) {
      DPR("sndio_stream_init(), loopback not supported\n");
      goto err;
    }
    s->mode |= SIO_PLAY;
    format = output_stream_params->format;
    rate = output_stream_params->rate;
  }
  if (s->mode == 0) {
    DPR("sndio_stream_init(), neither playing nor recording\n");
    goto err;
  }
  s->context = context;
  s->hdl = sio_open(NULL, s->mode, 1);
  if (s->hdl == NULL) {
    DPR("sndio_stream_init(), sio_open() failed\n");
    goto err;
  }
  sio_initpar(&wpar);
  wpar.sig = 1;
  wpar.bits = 16;
  switch (format) {
  case CUBEB_SAMPLE_S16LE:
    wpar.le = 1;
    break;
  case CUBEB_SAMPLE_S16BE:
    wpar.le = 0;
    break;
  case CUBEB_SAMPLE_FLOAT32NE:
    wpar.le = SIO_LE_NATIVE;
    break;
  default:
    DPR("sndio_stream_init() unsupported format\n");
    goto err;
  }
  wpar.rate = rate;
  if (s->mode & SIO_REC)
    wpar.rchan = input_stream_params->channels;
  if (s->mode & SIO_PLAY)
    wpar.pchan = output_stream_params->channels;
  wpar.appbufsz = latency_frames;
  if (!sio_setpar(s->hdl, &wpar) || !sio_getpar(s->hdl, &rpar)) {
    DPR("sndio_stream_init(), sio_setpar() failed\n");
    goto err;
  }
  if (rpar.bits != wpar.bits || rpar.le != wpar.le ||
      rpar.sig != wpar.sig || rpar.rate != wpar.rate ||
      ((s->mode & SIO_REC) && rpar.rchan != wpar.rchan) ||
      ((s->mode & SIO_PLAY) && rpar.pchan != wpar.pchan)) {
    DPR("sndio_stream_init() unsupported params\n");
    goto err;
  }
  sio_onmove(s->hdl, sndio_onmove, s);
  s->active = 0;
  s->nfr = rpar.round;
  s->rbpf = rpar.bps * rpar.rchan;
  s->pbpf = rpar.bps * rpar.pchan;
  s->rchan = rpar.rchan;
  s->pchan = rpar.pchan;
  s->nblks = rpar.bufsz / rpar.round;
  s->data_cb = data_callback;
  s->state_cb = state_callback;
  s->arg = user_ptr;
  s->mtx = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
  s->hwpos = s->swpos = 0;
  if (format == CUBEB_SAMPLE_FLOAT32LE) {
    s->conv = 1;
    bps = sizeof(float);
  } else {
    s->conv = 0;
    bps = rpar.bps;
  }
  if (s->mode & SIO_PLAY) {
    s->pbuf = malloc(bps * rpar.pchan * rpar.round);
    if (s->pbuf == NULL)
      goto err;
  }
  if (s->mode & SIO_REC) {
    s->rbuf = malloc(bps * rpar.rchan * rpar.round);
    if (s->rbuf == NULL)
      goto err;
  }
  *stream = s;
  DPR("sndio_stream_init() end, ok\n");
  (void)context;
  (void)stream_name;
  return CUBEB_OK;
err:
  if (s->hdl)
    sio_close(s->hdl);
  if (s->pbuf)
    free(s->pbuf);
  if (s->rbuf)
    free(s->pbuf);
  free(s);
  return CUBEB_ERROR;
}
Exemple #30
0
int
main(int argc, char **argv) {
	int ch;
	int tty;
	struct sio_hdl *hdl;
	struct termios tio;
	struct pollfd pfd[2];
	char cmd;
	ssize_t n, len;
	
	/*
	 * defaults parameters
	 */
	sio_initpar(&par);
	par.sig = 1;
	par.bits = 16;
	par.pchan = 2;
	par.rate = 44100;

	if (isatty(STDIN_FILENO)) {
		fprintf(stderr, "stdin can't be a tty\n");
		exit(1);
	}
	tty = open("/dev/tty", O_RDWR);
	if (tty < 0) {
		perror("/dev/tty");
		exit(1);
	}
	if (tcgetattr(tty, &tio) < 0) {
		perror("tcsetattr");
		exit(1);
	}
	tio.c_lflag &= ~ICANON;
	tio.c_lflag &= ~ECHO;
	tio.c_cc[VMIN] = 1;
	tio.c_cc[VTIME] = 0;
	if (tcsetattr(tty, TCSAFLUSH, &tio) < 0) {
		perror("tcsetattr");
		exit(1);
	}

	while ((ch = getopt(argc, argv, "r:c:e:b:x:")) != -1) {
		switch(ch) {
		case 'r':
			if (sscanf(optarg, "%u", &par.rate) != 1) {
				fprintf(stderr, "%s: bad rate\n", optarg);
				exit(1);
			}
			break;
		case 'c':
			if (sscanf(optarg, "%u", &par.pchan) != 1) {
				fprintf(stderr, "%s: bad channels\n", optarg);
				exit(1);
			}
			break;
		case 'e':
			if (!sio_strtoenc(&par, optarg)) {
				fprintf(stderr, "%s: bad encoding\n", optarg);
				exit(1);
			}
			break;
		default:
			usage();
			exit(1);
			break;
		}
	}

	hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0);
	if (hdl == NULL) {
		fprintf(stderr, "sio_open() failed\n");
		exit(1);
	}
	if (!sio_setpar(hdl, &par)) {
		fprintf(stderr, "sio_setpar() failed\n");
		exit(1);
	}
	if (!sio_onvol(hdl, onvol, NULL))
		fprintf(stderr, "warning: no volume knob on this device\n");
	fprintf(stderr, "use ``+'' and ``-'' to adjust the volume\n");
	if (!sio_start(hdl)) {
		fprintf(stderr, "sio_start() failed\n");
		exit(1);
	}
	for (;;) {
		pfd[0].fd = tty;
		pfd[0].events = POLLIN;
		sio_pollfd(hdl, &pfd[1], POLLOUT);
		if (poll(pfd, 2, -1) < 0) {
			perror("poll");
			exit(1);
		}
		if (pfd[0].revents & POLLIN) {
			if (read(tty, &cmd, 1) < 0) {
				perror("read(tty)");
				exit(1);
			}
			switch (cmd) {
			case '+':
				if (vol < SIO_MAXVOL) {
					vol++;
					sio_setvol(hdl, vol);
				}
				break;
			case '-':
				if (vol > 0) {
					vol--;
					sio_setvol(hdl, vol);
				}
				break;
			}
		}
		if (sio_revents(hdl, &pfd[1]) & POLLOUT) {
			len = read(STDIN_FILENO, buf, BUFSZ);
			if (len < 0) {
				perror("stdin");
				exit(1);
			}
			if (len == 0)
				break;
			n = sio_write(hdl, buf, len);
			if (n == 0) {
				fprintf(stderr, "sio_write: failed\n");
				exit(1);
			}
		}
	}
	sio_close(hdl);
	return 0;
}