Beispiel #1
0
/**************************************************************************
 * Lock and initialize the serial port.
 * This function is called by the LIRC daemon when the first client
 * registers itself.
 * Return 1 on success, 0 on error.
 **************************************************************************/
int mplay_init(void)
{
	int result = 1;
	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");
		result = 0;
	}
	/* Try to open serial port */
	else if ((hw.fd = open(hw.device, O_RDWR | O_NONBLOCK | O_NOCTTY)) < 0) {
		logprintf(LOG_ERR, "Could not open the serial port");
		LOGPRINTF(1, "Could not open the serial port");
		mplay_deinit();
		result = 0;
	}
	/* Serial port configuration */
	else if (!tty_reset(hw.fd) || !tty_setbaud(hw.fd, MPLAY_BAUD_RATE)) {
		logprintf(LOG_ERR, "could not configure the serial port for '%s'", hw.device);
		LOGPRINTF(1, "could not configure the serial port for '%s'", hw.device);
		mplay_deinit();
	}
	return result;
}
Beispiel #2
0
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);
}
Beispiel #3
0
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;
}
Beispiel #4
0
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;
}
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);
}
Beispiel #6
0
int bte_connect(void)
{
	struct termios tattr;

	LOGPRINTF(3, "bte_connect called");

	if (hw.fd >= 0)
		close(hw.fd);

	do			//try block
	{
		errno = 0;
		if ((hw.fd = open(hw.device, O_RDWR | O_NOCTTY)) == -1) {
			LOGPRINTF(1, "could not open %s", hw.device);
			LOGPERROR(1, "bte_connect");
			break;
		}
		if (tcgetattr(hw.fd, &tattr) == -1) {
			LOGPRINTF(1, "bte_connect: tcgetattr() failed");
			LOGPERROR(1, "bte_connect");
			break;
		}
		LOGPRINTF(1, "opened %s", hw.device);
		LOGPERROR(1, "bte_connect");
		cfmakeraw(&tattr);
		tattr.c_cc[VMIN] = 1;
		tattr.c_cc[VTIME] = 0;
		if (tcsetattr(hw.fd, TCSAFLUSH, &tattr) == -1) {
			LOGPRINTF(1, "bte_connect: tcsetattr() failed");
			LOGPERROR(1, "bte_connect");
			break;
		}
		if (!tty_setbaud(hw.fd, 115200)) {
			LOGPRINTF(1, "bte_connect: could not set baud rate %s", hw.device);
			LOGPERROR(1, "bte_connect");
			break;
		}
		logprintf(LOG_ERR, "bte_connect: connection established");
		io_failed = 0;

		if (bte_sendcmd("E?", BTE_INIT))	// Ask for echo state just to syncronise
		{
			return (1);
		} else {
			LOGPRINTF(1, "bte_connect: device did not respond");
		}
	} while (0);

	//try block failed
	io_failed = 1;
	if (hw.fd >= 0)
		close(hw.fd);
	if ((hw.fd = open("/dev/zero", O_RDONLY)) == -1) {
		logprintf(LOG_ERR, "could not open /dev/zero/");
		logperror(LOG_ERR, "bte_init()");
	}
	sleep(1);
	return 0;
}
Beispiel #7
0
int check_tira(void)
{
	logprintf(LOG_ERR, "Searching for Tira");
	if(!tty_reset(hw.fd) ||
	   !tty_setbaud(hw.fd, 9600) ||
	   !tty_setrtscts(hw.fd, 1)) return 0;

	usleep (50000);
	
	return tira_setup();
}
Beispiel #8
0
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;
}
Beispiel #9
0
int ira_setup(void)
{
	int  i;
	int ptr;
	/* Clear the port of any random data */
	while (read(hw.fd, &ptr, 1) >= 0) ;
	
	if (ira_setup_sixbytes(0) == 0) return 0;
	
	if (write (hw.fd, "I", 1) != 1)
	{
		logprintf(LOG_ERR, failwrite);
		return 0;
	}
	usleep(200000);
	if (write (hw.fd, "P", 1) != 1)
	{
		logprintf(LOG_ERR, failwrite);
		return 0;
	}
	
	/* Wait till the chars are written, should use tcdrain but
	   that don't seem to work... *shrug*
	*/
	if (!tty_setbaud(hw.fd, 57600)) return 0;
	usleep(50000);
	i = read (hw.fd, response, 5);

	if (!tty_setbaud(hw.fd, 9600)) return 0;

	if (i < 5) return 0;
	if (strncmp(response, "OIP", 3) == 0)
	{
		deviceflags = response[4] & 0x0f;
		if (response[4] & 0xF0)
		{
			/* Lets get the firmware version */
			if (write (hw.fd, "I", 1) != 1)
			{
				logprintf(LOG_ERR, failwrite);
				return 0;
			}
			usleep(200000);
			if (write (hw.fd, "V", 1) != 1)
			{
				logprintf(LOG_ERR, failwrite);
				return 0;
			}

			usleep(200000);
			memset (response, 0, sizeof(response));
			i = read (hw.fd, response, sizeof(response)-1);
			logprintf(LOG_INFO, "Ira %s detected",response);
		}
		else
		{
			logprintf(LOG_INFO, "Ira-1 detected");
		}
	  
		if (hw.rec_mode == LIRC_MODE_LIRCCODE) return(ira_setup_sixbytes(1));	//switch back to 6bytes mode
		if (hw.rec_mode == LIRC_MODE_MODE2) return(tira_setup_timing(1));
		return 0;	//unknown recmode
	}
	logprintf(LOG_ERR, "unexpected response from device");
	return 0;
}
Beispiel #10
0
int tira_setup_timing(int oldprotocol)
{
	long fd_flags;
	int i;

	if (oldprotocol)
	      if (!tty_setbaud(hw.fd, 57600)) return 0;
	  
	logprintf(LOG_INFO, "Switching to timing mode");
	if (!oldprotocol)
	{  
		if (write(hw.fd, "IC\0\0", 4 ) != 4)
		{
			logprintf(LOG_ERR, "failed switching device into timing mode");
			return 0;
		}
		/* wait for the chars to be written */
		usleep (2 * (100 * 1000));
		
		i = read (hw.fd, response, 3);
		if (i != 3)
		{
			  logprintf(LOG_ERR, "failed reading response to timing mode command");
			  return 0;
		}
		if (strncmp(response, "OIC", 3) != 0) return 0;
	}
	pulse_space=1;	//pulse
	/* Allocate a pipe for lircd to read from */
	if (pipe(pipe_fd) == -1)
	{
		logperror(LOG_ERR, "unable to create pipe");
		goto fail;
	}


	fd_flags = fcntl(pipe_fd[0], F_GETFL);
  	if(fcntl(pipe_fd[0], F_SETFL, fd_flags | O_NONBLOCK) == -1)
	{
		logperror(LOG_ERR, "can't set pipe to non-blocking");
		goto fail;
	}	
	
	/* Spawn the child process */
	
	child_pid = fork();
	if (child_pid == -1)
	{
		logperror(LOG_ERR, "unable to fork child process");
		goto fail;
	}
	else if (child_pid == 0)
	{
		close(pipe_fd[0]);
		child_process(pipe_fd[1], oldprotocol);
		close(pipe_fd[1]);
		_exit(0);
	}
	else
	{
		/* parent reads from pipe */
		close(hw.fd);
		hw.fd = pipe_fd[0];
	}
	close(pipe_fd[1]);
	displayonline();
	return(1);

fail:
	if (pipe_fd[0] != -1)
	{
		close(pipe_fd[0]);
		close(pipe_fd[1]);
	}
	return(0);

}
Beispiel #11
0
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);
}
Beispiel #12
0
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);
}