Exemplo n.º 1
0
static void setup_tty_speed(int tty, unsigned int baud)
{
	if (tty < 0)
		return;
    unsigned int speed = get_baud_rate(baud);
    if (speed == B0)
        return;
	struct termios term;
	tcgetattr(tty, &term);
	cfsetispeed(&term, speed);
	cfsetospeed(&term, speed);
	tcsetattr(tty, TCSANOW, &term);

}
Exemplo n.º 2
0
static void setup_tty(int tty, unsigned int baud)
{
	if (tty < 0)
		return;
    unsigned int speed = get_baud_rate(baud);
    if (speed == B0)
        return;
    unsigned int databits = get_data_bits(8);
	struct termios term;
	tcgetattr(tty, &term);
	term.c_iflag     = 0;
	term.c_oflag     = 0;
	term.c_lflag     = 0;
	term.c_cflag     &= ~(CSIZE | PARENB | INPCK);
	term.c_cflag     |= CLOCAL | databits;
	term.c_cc[VMIN]  = 1;
	term.c_cc[VTIME] = 0;
	cfsetispeed(&term, speed);
	cfsetospeed(&term, speed);
	tcsetattr(tty, TCSANOW, &term);
}
Exemplo n.º 3
0
// Initializes and "pings" the LDP/VLDP and returns true if the player is online and detected
// or false if the LDP could not be initialized
bool ldp::pre_init()
{

	bool result = true;	// assume everything works until we find out otherwise
	bool temp = true;	// needed to make && work the way we want below

	// If we are controlling a real LDP,
	// or if we are controlling a combo and DVD initialized properly,
	// then initialize the serial port here
	if (need_serial)
	{
		printline("NOTE : You are attempting to use DAPHNE with a real laserdisc player!");
		printline("If you don't have DAPHNE plugged into a real laserdisc player,");
		printline("you should be using VLDP instead.");
		serial_initialized = serial_init(get_serial_port(), get_baud_rate());
		temp = serial_initialized;
	}
	
	player_initialized = init_player();
	result = temp && player_initialized;
	m_start_time = GET_TICKS();
	m_uElapsedMsSincePlay = 0;
	m_uBlockedMsSincePlay = 0;
	m_uElapsedMsSinceStart = 0;
	m_uMsVblankBoundary = 0;
	m_bPreInitCalled = true;
	m_bWaitingForVblankToPlay = false;
	m_iSkipOffsetSincePlay = 0;
	m_uMsFrameBoundary = 0;
	m_uVblankCount = 0;
	m_uVblankMiniCount = 0;
	m_uFramesToSkipPerFrame = 0;
	m_uFramesToStallPerFrame = 0;
	m_uStallFrames = 0;
	m_bVerbose = true;

	return(result);

}
int main(int argc, char **argv)
{
        int sensor_id;
	char *filename;
	int fd, rc = 1;
	unsigned int baudrate = 0;
	int have_baudrate = 0;

	int c, optidx = 0;
	struct option options[] = {
		{"help", 0, NULL, 'h'},
		{"verbose", 0, NULL, 'v'},
		{"version", 0, NULL, 'V'},
		{"baudrate", 1, NULL, 'b'},
		{NULL, 0, NULL, 0}
	};

	while ((c = getopt_long(argc, argv, "h", options, &optidx)) != -1) {
		switch(c) {
			case 'v':
				verbose = 1;
				break;
			case 'V':
				version();
				return 0;
			case 'b':
				have_baudrate = 1;
				baudrate = (unsigned int)atoi(optarg);
				if (baudrate == 0) {
					usage();
					return 1;
				}
				break;
			case 'h':
			default:
				usage();
				return 0;
		}
	}

	if (optind == argc) {
		usage();
		return 1;
	}

	filename = argv[optind];

	fd = open_device(filename);
	if (fd < 0)
		goto out;

	/* only guess if we didn't get a baud rate */
	if (!have_baudrate && (baudrate = get_baud_rate(fd)) == 0)
		goto out;

	set_serial_attr(fd, baudrate);

	sensor_id = query_tablet(fd);
	if (sensor_id < 0 && !have_baudrate) {
		/* query failed, maybe the wrong baud rate? */
		baudrate = (baudrate == 19200) ? 38400 : 19200;

		printf("Initial tablet query failed. Trying with baud rate %d.\n", baudrate);

		set_serial_attr(fd, baudrate);
		sensor_id = query_tablet(fd);
	}

	if (sensor_id < 0) {
		fprintf(stderr, "Tablet query failed, cannot initialize.\n");
		return 1;
	}

	/* some of the 19200 tablets can't set the line discipline */
	set_line_discipline(fd, N_MOUSE);

	if (bind_kernel_driver(fd) < 0) {
		fprintf(stderr, "Failed to bind the kernel driver.\n");
		goto out;
	}

	signal(SIGINT, sighandler);
	signal(SIGHUP, sighandler);
	rc = (int)read(fd, NULL, 0); /* warning fix only, ignore error */

	set_line_discipline(fd, 0);

	rc = 0;
out:
	if (fd >= 0)
		close(fd);
	return rc;
}
Exemplo n.º 5
0
/******************************************************************
 *		COMM_DeviceIoControl
 *
 *
 */
NTSTATUS COMM_DeviceIoControl(HANDLE hDevice, 
                              HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,
                              PVOID UserApcContext, 
                              PIO_STATUS_BLOCK piosb, 
                              ULONG dwIoControlCode,
                              LPVOID lpInBuffer, DWORD nInBufferSize,
                              LPVOID lpOutBuffer, DWORD nOutBufferSize)
{
    DWORD       sz = 0, access = FILE_READ_DATA;
    NTSTATUS    status = STATUS_SUCCESS;
    int         fd = -1;

    TRACE("%p %s %p %ld %p %ld %p\n",
          hDevice, iocode2str(dwIoControlCode), lpInBuffer, nInBufferSize,
          lpOutBuffer, nOutBufferSize, piosb);

    piosb->Information = 0;

    if (dwIoControlCode != IOCTL_SERIAL_GET_TIMEOUTS)
        if ((status = wine_server_handle_to_fd( hDevice, access, &fd, NULL )))
            goto error;

    switch (dwIoControlCode)
    {
    case IOCTL_SERIAL_CLR_DTR:
#ifdef TIOCM_DTR
        if (whack_modem(fd, ~TIOCM_DTR, 0) == -1) status = FILE_GetNtStatus();
#else
        status = STATUS_NOT_SUPPORTED;
#endif
        break;
    case IOCTL_SERIAL_CLR_RTS:
#ifdef TIOCM_RTS
        if (whack_modem(fd, ~TIOCM_RTS, 0) == -1) status = FILE_GetNtStatus();
#else
        status = STATUS_NOT_SUPPORTED;
#endif
        break;
    case IOCTL_SERIAL_GET_BAUD_RATE:
        if (lpOutBuffer && nOutBufferSize == sizeof(SERIAL_BAUD_RATE))
        {
            if (!(status = get_baud_rate(fd, (SERIAL_BAUD_RATE*)lpOutBuffer)))
                sz = sizeof(SERIAL_BAUD_RATE);
        }
        else
            status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_GET_CHARS:
        if (lpOutBuffer && nOutBufferSize == sizeof(SERIAL_CHARS))
        {
            if (!(status = get_special_chars(fd, (SERIAL_CHARS*)lpOutBuffer)))
                sz = sizeof(SERIAL_CHARS);
        }
        else
            status = STATUS_INVALID_PARAMETER;
        break;
     case IOCTL_SERIAL_GET_COMMSTATUS:
        if (lpOutBuffer && nOutBufferSize == sizeof(SERIAL_STATUS))
        {
            if (!(status = get_status(fd, (SERIAL_STATUS*)lpOutBuffer)))
                sz = sizeof(SERIAL_STATUS);
        }
        else status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_GET_HANDFLOW:
        if (lpOutBuffer && nOutBufferSize == sizeof(SERIAL_HANDFLOW))
        {
            if (!(status = get_hand_flow(fd, (SERIAL_HANDFLOW*)lpOutBuffer)))
                sz = sizeof(SERIAL_HANDFLOW);
        }
        else
            status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_GET_LINE_CONTROL:
        if (lpOutBuffer && nOutBufferSize == sizeof(SERIAL_LINE_CONTROL))
        {
            if (!(status = get_line_control(fd, (SERIAL_LINE_CONTROL*)lpOutBuffer)))
                sz = sizeof(SERIAL_LINE_CONTROL);
        }
        else
            status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_GET_MODEMSTATUS:
        if (lpOutBuffer && nOutBufferSize == sizeof(DWORD))
        {
            if (!(status = get_modem_status(fd, (DWORD*)lpOutBuffer)))
                sz = sizeof(DWORD);
        }
        else status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_GET_TIMEOUTS:
        if (lpOutBuffer && nOutBufferSize == sizeof(SERIAL_TIMEOUTS))
        {
            if (!(status = get_timeouts(hDevice, (SERIAL_TIMEOUTS*)lpOutBuffer)))
                sz = sizeof(SERIAL_TIMEOUTS);
        }
        else
            status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_GET_WAIT_MASK:
        if (lpOutBuffer && nOutBufferSize == sizeof(DWORD))
        {
            if (!(status = get_wait_mask(hDevice, (DWORD*)lpOutBuffer)))
                sz = sizeof(DWORD);
        }
        else
            status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_IMMEDIATE_CHAR:
        if (lpInBuffer && nInBufferSize == sizeof(CHAR))
            status = xmit_immediate(hDevice, fd, lpInBuffer);
        else
            status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_PURGE:
        if (lpInBuffer && nInBufferSize == sizeof(DWORD))
            status = purge(fd, *(DWORD*)lpInBuffer);
        else
            status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_RESET_DEVICE:
        FIXME("Unsupported\n");
        break;
    case IOCTL_SERIAL_SET_BAUD_RATE:
        if (lpInBuffer && nInBufferSize == sizeof(SERIAL_BAUD_RATE))
            status = set_baud_rate(fd, (const SERIAL_BAUD_RATE*)lpInBuffer);
        else
            status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_SET_BREAK_OFF:
#if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
	if (ioctl(fd, TIOCCBRK, 0) == -1)
        {
            TRACE("ioctl failed\n");
            status = FILE_GetNtStatus();
        }
#else
	FIXME("ioctl not available\n");
	status = STATUS_NOT_SUPPORTED;
#endif
        break;
    case IOCTL_SERIAL_SET_BREAK_ON:
#if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
	if (ioctl(fd, TIOCSBRK, 0) == -1)
        {
            TRACE("ioctl failed\n");
            status = FILE_GetNtStatus();
        }
#else
	FIXME("ioctl not available\n");
	status = STATUS_NOT_SUPPORTED;
#endif
        break;
    case IOCTL_SERIAL_SET_CHARS:
        if (lpInBuffer && nInBufferSize == sizeof(SERIAL_CHARS))
            status = set_special_chars(fd, (const SERIAL_CHARS*)lpInBuffer);
        else
            status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_SET_DTR:
#ifdef TIOCM_DTR
        if (whack_modem(fd, 0, TIOCM_DTR) == -1) status = FILE_GetNtStatus();
#else
        status = STATUS_NOT_SUPPORTED;
#endif
        break;
    case IOCTL_SERIAL_SET_HANDFLOW:
        if (lpInBuffer && nInBufferSize == sizeof(SERIAL_HANDFLOW))
            status = set_handflow(fd, (const SERIAL_HANDFLOW*)lpInBuffer);
        else
            status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_SET_LINE_CONTROL:
        if (lpInBuffer && nInBufferSize == sizeof(SERIAL_LINE_CONTROL))
            status = set_line_control(fd, (const SERIAL_LINE_CONTROL*)lpInBuffer);
        else
            status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_SET_QUEUE_SIZE:
        if (lpInBuffer && nInBufferSize == sizeof(SERIAL_QUEUE_SIZE))
            status = set_queue_size(fd, (const SERIAL_QUEUE_SIZE*)lpInBuffer);
        else
            status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_SET_RTS:
#ifdef TIOCM_RTS
        if (whack_modem(fd, 0, TIOCM_RTS) == -1) status = FILE_GetNtStatus();
#else
        status = STATUS_NOT_SUPPORTED;
#endif
        break;
    case IOCTL_SERIAL_SET_TIMEOUTS:
        if (lpInBuffer && nInBufferSize == sizeof(SERIAL_TIMEOUTS))
            status = set_timeouts(hDevice, fd, (const SERIAL_TIMEOUTS*)lpInBuffer);
        else
            status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_SET_WAIT_MASK:
        if (lpInBuffer && nInBufferSize == sizeof(DWORD))
        {
            status = set_wait_mask(hDevice, *(DWORD*)lpInBuffer);
        }
        else status = STATUS_INVALID_PARAMETER;
        break;
    case IOCTL_SERIAL_SET_XOFF:
        status = set_XOff(fd);
        break;
    case IOCTL_SERIAL_SET_XON:
        status = set_XOn(fd);
        break;
    default:
        FIXME("Unsupported IOCTL %lx (type=%lx access=%lx func=%lx meth=%lx)\n", 
              dwIoControlCode, dwIoControlCode >> 16, (dwIoControlCode >> 14) & 3,
              (dwIoControlCode >> 2) & 0xFFF, dwIoControlCode & 3);
        sz = 0;
        status = STATUS_INVALID_PARAMETER;
        break;
    }
    if (fd != -1) wine_server_release_fd( hDevice, fd );
 error:
    piosb->u.Status = status;
    piosb->Information = sz;
    if (hEvent) NtSetEvent(hEvent, NULL);
    return status;
}
Exemplo n.º 6
0
int set_port(pport_info p_info)
{
	struct termios old_opt,new_opt;
	int baud_rate,parity;

	memset(&old_opt,0,sizeof(old_opt));
	memset(&new_opt,0,sizeof(new_opt));

	cfmakeraw(&new_opt);
	tcgetattr(p_info->port_fd,&old_opt);
	/*=========以下设置串口波特率=========*/
        baud_rate=get_baud_rate(p_info->baud_rate);
	
	//修改new_opt结构中的串口输入/输出波特率参数
	cfsetispeed(&new_opt,baud_rate);
	cfsetospeed(&new_opt,baud_rate);
	
	//修改控制模式,保证程序不会占用串口
	new_opt.c_cflag |=CLOCAL;
	//修改控制模式,使得能够从串口中读取输入数据
 	new_opt.c_cflag |=CREAD;

	/*===========设置数据流控制==========*/
	switch(p_info->flow_ctrl){
		case '0':
			//不使用流控制
			new_opt.c_cflag &=~CRTSCTS;
			break;
		case '1':
			//使用硬件进行流控制
			new_opt.c_cflag |=CRTSCTS;
			break;
		case '2':
			new_opt.c_cflag |= IXON | IXOFF | IXANY;
			break;
	}
	
	/*===========设置数据位============*/
	new_opt.c_cflag &=~CSIZE;
	switch(p_info->data_bits){
		case '5':
			new_opt.c_cflag |=CS5;
			break;
		case '6':
			new_opt.c_cflag |=CS6;
			break;
		case '7':
			new_opt.c_cflag |=CS7;
			break;
		case '8':
			new_opt.c_cflag |=CS8;
			break;
		default:
			new_opt.c_cflag |=CS8;
		}

	/*===========设置奇偶效验位==========*/
	switch(p_info->parity){
		case '0':
			//不使用奇偶效验
			new_opt.c_cflag &=~PARENB;
			break;
		case '1':
			//使用偶效验
			new_opt.c_cflag |=PARENB;
			new_opt.c_cflag &=~PARODD;
			break;
		case '2':
			//使用奇效验
			new_opt.c_cflag |=PARENB;
			new_opt.c_cflag |=PARODD;
			break;
	}


	/*============设置停止位===========*/
	if(p_info->stop_bit=='2')
		new_opt.c_cflag |=CSTOPB;
	else
		new_opt.c_cflag &=~CSTOPB;

	//修改输出模式,原始数据输出
	new_opt.c_oflag &=~OPOST;
	//修改控制字符,读取字符的最少个数为1
	new_opt.c_cc[VMIN]=1;
	//修改控制字符,读取第一个字符等待1*(1/10)s
	new_opt.c_cc[VTIME]=1;

	//如果发生数据溢出,接收数据,但是不再读取
	tcflush(p_info->port_fd,TCIFLUSH);
	
	int result;
	result=tcsetattr(p_info->port_fd,TCSANOW,&new_opt);

	if(result==-1){
		perror("Cannot set the serial port parameters");
		return -1;
	}

	tcgetattr(p_info->port_fd,&old_opt);
	return result;
}
Exemplo n.º 7
0
static int set_port(pport_info p_info)
{
	struct termios old_opt, new_opt;
	int baud_rate;

	memset(&old_opt, 0, sizeof(old_opt));
	memset(&new_opt, 0, sizeof(new_opt));

	cfmakeraw(&new_opt);
	tcgetattr(p_info->port_fd, &old_opt);

	baud_rate = get_baud_rate(p_info->baud_rate);

	cfsetispeed(&new_opt, baud_rate);
	cfsetospeed(&new_opt, baud_rate);

	new_opt.c_cflag |= CLOCAL;

	new_opt.c_cflag |= CREAD;

	switch(p_info->flow_ctrl)
	{
		case '0':
			new_opt.c_cflag &= ~CRTSCTS;
		break;

		case '1':
			new_opt.c_cflag |= CRTSCTS;
		break;

		case '2':
			new_opt.c_cflag |= IXON | IXOFF | IXANY;
		break;
	}

	new_opt.c_cflag &= ~CSIZE;

	switch(p_info->data_bits)
	{
		case '5':
			new_opt.c_cflag |= CS5;
		break;

		case '6':
			new_opt.c_cflag |= CS6;
		break;

		case '7':
			new_opt.c_cflag |= CS7;
		break;

		case '8':
			new_opt.c_cflag |= CS8;
		break;

		default:
			new_opt.c_cflag |= CS8;
	}

	switch(p_info->parity)
	{
		case '0':
			new_opt.c_cflag &= ~PARENB;
		break;

		case '1':
			new_opt.c_cflag |= PARENB;
			new_opt.c_cflag &= ~PARODD;
		break;

		case '2':
			new_opt.c_cflag |= PARENB;
			new_opt.c_cflag |= PARODD;
		break;
	}

	if(p_info->stop_bit == '2')
	{
		new_opt.c_cflag |= CSTOPB;
	}
	else
	{
		new_opt.c_cflag &= ~CSTOPB;
	}

	new_opt.c_oflag &= ~OPOST;

	new_opt.c_cc[VMIN] = 1;
	new_opt.c_cc[VTIME] = 1;

	tcflush(p_info->port_fd, TCIFLUSH);

	int result;
	result = tcsetattr(p_info->port_fd, TCSANOW, &new_opt);

	if(result == -1)
	{
		perror("Cannot set the serial port parameters! \n");
		return -1;
	}

	tcgetattr(p_info->port_fd, &old_opt);
	return result;
}