コード例 #1
0
ファイル: pinsys.c プロジェクト: andyvand/LIRC
/* returns 0-3, the port, or -1 if it can't find the device */
int autodetect(void)
{
	int port, i;
	long backup;
	char device[20];

	/* hardcoded the device names.. it's easy enough to change
	 * that, but it's unlikely to be on something else. */

	for (i = 0; i < 4; i++) {
		sprintf(device, "/dev/ttyS%d", i);

		if (!tty_create_lock(device))
			continue;
		port = open("/dev/ttyS0", O_RDONLY | O_NOCTTY);
		if (port < 0) {
			logprintf(LIRC_WARNING, "couldn't open %s", device);
			tty_delete_lock();
			continue;
		} else {
			ioctl(port, TIOCMGET, &backup);

			if (is_it_is_it_huh(port)) {
				ioctl(port, TIOCMSET, &backup);
				close(port);
				tty_delete_lock();
				return i;
			}
			ioctl(port, TIOCMSET, &backup);
			close(port);
		}
		tty_delete_lock();
	}
	return -1;
}
コード例 #2
0
int silitek_init(void) {
    if(!tty_create_lock(hw.device)) {
        logprintf(LOG_ERR, "could not create lock files");
        return(0);
    }

    if((hw.fd = open(hw.device, O_RDWR | O_NOCTTY | O_NDELAY)) < 0) {
        logprintf(LOG_ERR, "could not open %s", hw.device);
        logperror(LOG_ERR, "silitek_init()");
        tty_delete_lock();
        return(0);
    }

    if(!tty_reset(hw.fd)) {
        logprintf(LOG_ERR,"could not reset %s", hw.device);
        silitek_deinit();
        return(0);
    }

    if(!tty_setbaud(hw.fd, 1200)) {
        logprintf(LOG_ERR,"could not set baud rate on %s", hw.device);
        silitek_deinit();
        return(0);
    }

    return(1);
}
コード例 #3
0
ファイル: hw_ea65.c プロジェクト: zenwheel/lirc
int ea65_init(void)
{
	logprintf(LOG_INFO, "EA65: device %s", hw.device); 

	if (!tty_create_lock(hw.device)) {
		logprintf(LOG_ERR,"EA65: could not create lock files");
		return 0;
	}

	hw.fd = open(hw.device, O_RDWR | O_NONBLOCK | O_NOCTTY);
	if (hw.fd < 0) {
		logprintf(LOG_ERR,"EA65: could not open %s",hw.device);
		tty_delete_lock();
		return 0;
	}

	if (!tty_reset(hw.fd)) {
		logprintf(LOG_ERR,"EA65: could not reset tty");
		ea65_release();
		return 0;
	}

	if (!tty_setbaud(hw.fd, 9600)) {
		logprintf(LOG_ERR,"EA65: could not set baud rate");
		ea65_release();
		return 0;
	}

	return 1;
}
コード例 #4
0
ファイル: hw_tira.c プロジェクト: zenwheel/lirc
int tira_deinit (void)
{
	if (child_pid != -1)
	{
		/* Kill the child process, and wait for it to exit */
		if (kill(child_pid, SIGTERM) == -1)
		{
			return(0);
		}
		if (waitpid(child_pid, NULL, 0) == 0)
		{
			return(0);
		}
		child_pid = -1;
	}

	if(hw.fd != -1)
	{
		close(hw.fd); /* pipe_fd[0] or actual device */
		hw.fd = -1;
	}
	sleep(1);
	tty_delete_lock();
	return 1;
}
コード例 #5
0
//-------------------------------------------------------------------------
// Close and release the serial line.
//-------------------------------------------------------------------------
int accent_deinit(void)
{
    LOGPRINTF(LOG_DEBUG, "Entering accent_deinit()");
    close(hw.fd);
    tty_delete_lock();
    return(1);
}
コード例 #6
0
ファイル: hw_ea65.c プロジェクト: zenwheel/lirc
int ea65_release(void)
{
	close(hw.fd);
	tty_delete_lock();

	return 1;
}
コード例 #7
0
ファイル: hw_mp3anywhere.c プロジェクト: aldebaran/lirc
int mp3anywhere_init(void)
{
	signal_length=hw.code_length*1000000/9600;
	
	if(!tty_create_lock(hw.device))
	{
		logprintf(LOG_ERR,"could not create lock files");
		return(0);
	}
	if((hw.fd=open(hw.device,O_RDWR|O_NONBLOCK|O_NOCTTY))<0)
	{
		logprintf(LOG_ERR,"could not open %s",hw.device);
		logperror(LOG_ERR,"mp3anywhere_init()");
		tty_delete_lock();
		return(0);
	}
	if(!tty_reset(hw.fd))
	{
		logprintf(LOG_ERR,"could not reset tty");
		mp3anywhere_deinit();
		return(0);
	}
	if(!tty_setbaud(hw.fd,9600))
	{
		logprintf(LOG_ERR,"could not set baud rate");
		mp3anywhere_deinit();
		return(0);
	}
	return(1);
}
コード例 #8
0
ファイル: silitek.c プロジェクト: andyvand/LIRC
int silitek_init(void)
{
    if (!tty_create_lock(drv.device)) {
        logprintf(LIRC_ERROR, "could not create lock files");
        return 0;
    }

    drv.fd = open(drv.device, O_RDWR | O_NOCTTY | O_NDELAY);
    if (drv.fd < 0) {
        logprintf(LIRC_ERROR, "could not open %s", drv.device);
        logperror(LIRC_ERROR, "silitek_init()");
        tty_delete_lock();
        return 0;
    }

    if (!tty_reset(drv.fd)) {
        logprintf(LIRC_ERROR, "could not reset %s", drv.device);
        silitek_deinit();
        return 0;
    }

    if (!tty_setbaud(drv.fd, 1200)) {
        logprintf(LIRC_ERROR, "could not set baud rate on %s", drv.device);
        silitek_deinit();
        return 0;
    }

    return 1;
}
コード例 #9
0
ファイル: hw_mplay.c プロジェクト: TryndamereStark/lirc
/**************************************************************************
 * Close and release the serial line.
 **************************************************************************/
int mplay_deinit(void)
{
	LOGPRINTF(1, "Entering mplay_deinit()");
	close(hw.fd);
	tty_delete_lock();
	hw.fd = -1;
	return (1);
}
コード例 #10
0
ファイル: hw_irman.c プロジェクト: zenwheel/lirc
int irman_deinit(void)
{
	ir_finish();
	sleep(1); /* give hardware enough time to reset */
	close(hw.fd);
	tty_delete_lock();
	return(1);
}
コード例 #11
0
ファイル: hw_bte.c プロジェクト: TryndamereStark/lirc
int bte_deinit(void)
{
	// stop events forwarding
	bte_sendcmd("+CMER=0,0,0,0,0", 0);
	close(hw.fd);
	tty_delete_lock();
	LOGPRINTF(1, "bte_deinit: OK");
	return (1);
}
コード例 #12
0
ファイル: hw_tira.c プロジェクト: zenwheel/lirc
int tira_init(void)
{
	if (child_pid != -1) tira_deinit();

	LOGPRINTF (1, "Tira init");
	
	if(!tty_create_lock(hw.device))
	{
		logprintf(LOG_ERR,"could not create lock files");
		return 0;
	}
	if ( (hw.fd = open (hw.device, O_RDWR | O_NONBLOCK | O_NOCTTY)) < 0)
	{
		tty_delete_lock ();
		logprintf (LOG_ERR, "Could not open the '%s' device",
			   hw.device);
		return 0;
	}
	LOGPRINTF(1, "device '%s' opened", hw.device);

	/* We want 9600 8N1 with CTS/RTS handshaking, lets set that
	 * up. The specs state a baud rate of 100000, looking at the
	 * ftdi_sio driver it forces the issue so we can set to what
	 * we would like. And seeing as this is mapped to 9600 under
	 * windows should be a safe bet.
	 */

	/* Determine device type */
	device_type=0;
	if (check_tira()) device_type='t';else
	if (check_ira()) device_type='i';

#ifdef DEBUG
	const char *device_string;
	
	switch(device_type)
	{
	case 't':
		device_string = "Tira";
		break;
	case 'i':
		device_string = "Ira";
		break;
	default:
		device_string = "unknown";
	}
	LOGPRINTF(1, "device type %s", device_string);
#endif

	if (device_type == 0)
	{
		tira_deinit();
		return 0;
	}  

	return 1;
}
コード例 #13
0
ファイル: hw_irlink.c プロジェクト: zenwheel/lirc
static int irlink_close(const int port)
{
    if ( port != -1  )
    {
        tty_delete_lock();
        close(port);
        return 0;
    }
    return -1;
}
コード例 #14
0
ファイル: uirt2_raw.c プロジェクト: digideskio/lirc
static int uirt2_raw_deinit(void)
{
	int version;

	if (uirt2_getversion(dev, &version) >= 0 && version >= 0x0905)
		tty_setdtr(drv.fd, 1);
	uirt2_uninit(dev);
	dev = NULL;
	close(drv.fd);
	drv.fd = -1;
	tty_delete_lock();
	return 1;
}
コード例 #15
0
ファイル: hw_irman.c プロジェクト: zenwheel/lirc
int irman_init(void)
{
	if(!tty_create_lock(hw.device))
	{
		logprintf(LOG_ERR,"could not create lock files");
		return(0);
	}
	if((hw.fd=ir_init(hw.device))<0)
	{
		logprintf(LOG_ERR,"could not open %s",hw.device);
		logperror(LOG_ERR,"irman_init()");
		tty_delete_lock();
		return(0);
	}
	return(1);
}
コード例 #16
0
ファイル: hw_irlink.c プロジェクト: zenwheel/lirc
static int irlink_open(const char * portName)
{
    int port = -1;
    if(!tty_create_lock((char*)portName))
    {
        logprintf(LOG_ERR,"could not create lock files");
        return -1;
    }
    if((port=open(portName,O_RDWR | O_NOCTTY | O_NDELAY))<0)
    {
        logprintf(LOG_ERR,"could not open %s",hw.device);
        tty_delete_lock();
        return -1;
    }
    if(tty_reset(port) < 0 ||
            tty_setbaud(port , 115200) < 0 ||
            tty_setcsize(port , 8) < 0 ||
            tty_setrtscts(port , 0) < 0 )
    {
        irlink_close(port);
        port = -1;
    }
    return port;
}
コード例 #17
0
ファイル: hw_creative.c プロジェクト: aldebaran/lirc
int creative_deinit(void)
{
	close(hw.fd);
	tty_delete_lock();
	return(1);
}
コード例 #18
0
ファイル: hw_pixelview.c プロジェクト: fullstory-morgue/lirc
int pixelview_deinit(void)
{
	close(hw.fd);
	tty_delete_lock();
	return(1);
}
コード例 #19
0
ファイル: hw_mp3anywhere.c プロジェクト: aldebaran/lirc
int mp3anywhere_deinit(void)
{
	close(hw.fd);
	tty_delete_lock();
	return(1);
}
コード例 #20
0
ファイル: hw_uirt2_raw.c プロジェクト: TryndamereStark/lirc
static int uirt2_raw_init(void)
{
	int version;

	if (!tty_create_lock(hw.device)) {
		logprintf(LOG_ERR, "uirt2_raw: could not create lock files");
		return (0);
	}

	if ((hw.fd = open(hw.device, O_RDWR | O_NONBLOCK | O_NOCTTY)) < 0) {
		logprintf(LOG_ERR, "uirt2_raw: could not open %s", hw.device);
		tty_delete_lock();
		return (0);
	}

	if (!tty_reset(hw.fd)) {
		logprintf(LOG_ERR, "uirt2_raw: could not reset tty");
		close(hw.fd);
		tty_delete_lock();
		return (0);
	}

	/* Wait for UIRT device to power up */
	usleep(100 * 1000);

	if (!tty_setbaud(hw.fd, 115200)) {
		logprintf(LOG_ERR, "uirt2_raw: could not set baud rate");
		close(hw.fd);
		tty_delete_lock();
		return (0);
	}

	if (!tty_setcsize(hw.fd, 8)) {
		logprintf(LOG_ERR, "uirt2_raw: could not set csize");
		close(hw.fd);
		tty_delete_lock();
		return (0);
	}

	if (!tty_setrtscts(hw.fd, 1)) {
		logprintf(LOG_ERR, "uirt2_raw: could not enable hardware flow");
		close(hw.fd);
		tty_delete_lock();
		return (0);
	}

	if ((dev = uirt2_init(hw.fd)) == NULL) {
		logprintf(LOG_ERR, "uirt2_raw: No UIRT2 device found at %s", hw.device);
		close(hw.fd);
		tty_delete_lock();
		return (0);
	}

	if (uirt2_setmoderaw(dev) < 0) {
		logprintf(LOG_ERR, "uirt2_raw: could not set raw mode");
		uirt2_raw_deinit();
		return (0);
	}

	if (uirt2_getversion(dev, &version) < 0) {
		uirt2_raw_deinit();
		return (0);
	}
	if (version >= 0x0905) {
		if (!tty_setdtr(hw.fd, 0)) {
			logprintf(LOG_ERR, "uirt2_raw: could not set DTR");
			uirt2_raw_deinit();
			return (0);
		}
	}

	init_rec_buffer();
	init_send_buffer();

	rec_rptr = 0;
	rec_wptr = 0;
	rec_size = sizeof(rec_buf) / sizeof(rec_buf[0]);

	return (1);
}
コード例 #21
0
ファイル: hw_pinsys.c プロジェクト: Albinoman887/lirc
int pinsys_deinit(void)
{
	close(hw.fd);
	tty_delete_lock();
	return (1);
}
コード例 #22
0
ファイル: hw_pinsys.c プロジェクト: Albinoman887/lirc
int pinsys_init(void)
{
	signal_length = (hw.code_length + (hw.code_length / BITS_COUNT) * 2) * 1000000 / 1200;

	if (!tty_create_lock(hw.device)) {
		logprintf(LOG_ERR, "could not create lock files");
		return (0);
	}
	if ((hw.fd = open(hw.device, O_RDWR | O_NONBLOCK | O_NOCTTY)) < 0) {
		int detected;
		/* last character gets overwritten */
		char auto_lirc_device[] = "/dev/ttyS_";

		tty_delete_lock();
		logprintf(LOG_WARNING, "could not open %s, autodetecting on /dev/ttyS[0-3]", hw.device);
		logperror(LOG_WARNING, "pinsys_init()");
		/* it can also mean you compiled serial support as a
		   module and it isn't inserted, but that's unlikely
		   unless you're me. */

		detected = autodetect();

		if (detected == -1) {
			logprintf(LOG_ERR, "no device found on /dev/ttyS[0-3]");
			tty_delete_lock();
			return (0);
		} else {	/* detected */

			auto_lirc_device[9] = '0' + detected;
			hw.device = auto_lirc_device;
			if ((hw.fd = open(hw.device, O_RDWR | O_NONBLOCK | O_NOCTTY)) < 0) {
				/* unlikely, but hey. */
				logprintf(LOG_ERR, "couldn't open autodetected device \"%s\"", hw.device);
				logperror(LOG_ERR, "pinsys_init()");
				tty_delete_lock();
				return (0);
			}
		}
	}
	if (!tty_reset(hw.fd)) {
		logprintf(LOG_ERR, "could not reset tty");
		pinsys_deinit();
		return (0);
	}
	if (!tty_setbaud(hw.fd, 1200)) {
		logprintf(LOG_ERR, "could not set baud rate");
		pinsys_deinit();
		return (0);
	}
	/* set RTS, clear DTR */
	if (!tty_set(hw.fd, 1, 0) || !tty_clear(hw.fd, 0, 1)) {
		logprintf(LOG_ERR, "could not set modem lines (DTR/RTS)");
		pinsys_deinit();
		return (0);
	}

	/* I dunno, but when lircd starts may log `reading of byte 1
	   failed' I know that happened when testing, it's a zero
	   byte. Problem is, flushing doesn't fix it. It's not fatal,
	   it's an indication that it gets fixed.  still... */

	if (tcflush(hw.fd, TCIFLUSH) < 0) {
		logprintf(LOG_ERR, "could not flush input buffer");
		pinsys_deinit();
		return (0);
	}
	return (1);
}
コード例 #23
0
ファイル: pinsys.c プロジェクト: andyvand/LIRC
int pinsys_deinit(void)
{
	close(drv.fd);
	tty_delete_lock();
	return 1;
}
コード例 #24
0
ファイル: hw_mplay.c プロジェクト: TryndamereStark/lirc
int mplay2_init(void)
{
	struct termios portset;
	signed int len;
	char buf = 0x96;
	char psResponse[11];

	LOGPRINTF(1, "Entering mplay_init()");
	/* Creation of a lock file for the port */
	if (!tty_create_lock(hw.device)) {
		logprintf(LOG_ERR, "Could not create the lock file");
		LOGPRINTF(1, "Could not create the lock file");
		return 0;
	}

	LOGPRINTF(0, "open serial port");
	/* Try to open serial port (Monueal Moncaso 312 device doesn't like O_NONBLOCK */
	if ((hw.fd = open(hw.device, O_RDWR | O_NOCTTY)) < 0) {
		logprintf(LOG_ERR, "Could not open the serial port");
		LOGPRINTF(1, "Could not open the serial port");
		tty_delete_lock();
		return 0;
	}

	/* Get serial device parameters */
	if (tcgetattr(hw.fd, &portset) < 0) {
		logprintf(LOG_ERR, "Could not get serial port attributes");
		LOGPRINTF(1, "Could not get serial port attributes");
		mplay_deinit();
		return 0;
	}

	/* use own termios struct instead of using tty_reset , Moncaso doesn't like TCSAFLUSH */
	portset.c_cflag &= ~PARENB;
	portset.c_cflag &= ~CSTOPB;
	portset.c_cflag &= ~CSIZE;
	portset.c_cflag = B57600 | CS8;
	portset.c_cflag |= (CLOCAL | CREAD);
	portset.c_iflag |= (IXON | IXOFF | IXANY);
	portset.c_oflag &= ~OPOST;
	portset.c_lflag &= ~(ICANON | ECHOE | ECHO | ISIG);
	portset.c_cc[VSTART] = 0x11;
	portset.c_cc[VSTOP] = 0x13;
	portset.c_cc[VEOF] = 0x20;
	portset.c_cc[VMIN] = 1;
	portset.c_cc[VTIME] = 3;

	if (tcsetattr(hw.fd, TCSANOW, &portset) < 0) {
		logprintf(LOG_ERR, "Error setting TCSANOW mode of serial device");
		LOGPRINTF(1, "Error setting TCSANOW mode of serial device");
		mplay_deinit();
		return 0;
	}

	len = write(hw.fd, &buf, 1);
	if (len < 0) {
		LOGPRINTF(LOG_ERR, "couldn't write to device");
		mplay_deinit();
		return 0;
	}

	len = read(hw.fd, &psResponse, 11);
	if (len < 0) {
		LOGPRINTF(1, "No data recieved during reading");
		mplay_deinit();
		return 0;
	} else
		LOGPRINTF(1, "read chars: %s", psResponse);

	if (tcgetattr(hw.fd, &portset) < 0) {
		logprintf(LOG_ERR, "Could not get serial port attributes");
		LOGPRINTF(1, "Could not get serial port attributes");
		mplay_deinit();
		return 0;
	}

	portset.c_cflag &= ~PARENB;
	portset.c_cflag &= ~CSTOPB;
	portset.c_cflag &= ~CSIZE;
	portset.c_cflag = B57600 | CS8;
	portset.c_cflag |= (CLOCAL | CREAD);
	portset.c_iflag |= (IXON | IXOFF | IXANY);
	portset.c_oflag &= ~OPOST;
	portset.c_lflag &= ~(ICANON | ECHOE | ECHO | ISIG);
	portset.c_cc[VSTART] = 0x11;
	portset.c_cc[VSTOP] = 0x13;
	portset.c_cc[VEOF] = 0x1C;
	portset.c_cc[VMIN] = 1;
	portset.c_cc[VTIME] = 3;

	if (tcsetattr(hw.fd, TCSANOW, &portset) < 0) {
		logprintf(LOG_ERR, "Error setting TCSANOW mode of serial device");
		LOGPRINTF(1, "Error setting TCSANOW mode of serial device");
		mplay_deinit();
		return 0;
	}

	return 1;
}
コード例 #25
0
ファイル: hw_logitech.c プロジェクト: aldebaran/lirc
int logitech_deinit(void)
{
	close(hw.fd);
	tty_delete_lock();
	return(1);
}
コード例 #26
0
int silitek_deinit(void) {
    close(hw.fd);
    tty_delete_lock();
    return(1);
}
コード例 #27
0
ファイル: silitek.c プロジェクト: andyvand/LIRC
int silitek_deinit(void)
{
    close(drv.fd);
    tty_delete_lock();
    return 1;
}