|
From: Kristian L. <kri...@ho...> - 2009-01-22 22:18:08
|
Hi Sure thing - I will share /* $Id: hw_tira.c,v 5.6 2007/07/29 18:20:09 lirc Exp $ */ /***************************************************************************** ** hw_tira.c **************************************************************** ***************************************************************************** * Routines for the HomeElectronics TIRA-2 USB dongle. * * Serial protocol described at: * http://www.home-electro.com/Download/Protocol2.pdf * * Copyright (C) 2003 Gregory McLean <gr...@gx...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <limits.h> #include <signal.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/ioctl.h> #include <errno.h> #include <termios.h> #include "hardware.h" #include "receive.h" #include "serial.h" #include "ir_remote.h" #include "lircd.h" #include "hw_tira.h" #include "hw_tira_myCustomIR.h" void HandleIrInputVersion1( char *inBuffer ); void HandleIrFormat0( struct LSL_DATA *pLslMsg ); void HandleIrFormat1( struct LSL_DATA *pLslMsg ); static struct timeval start,end,last; #define NUMBER_BYTES 15 #define NO_OF_USED_BYTES 4 #define CODE_LENGTH NO_OF_USED_BYTES*8 static unsigned char b[NUMBER_BYTES]; static ir_code code; struct hardware hw_tira = { "/dev/ttyUSB0", /* Default device */ -1, /* fd */ LIRC_CAN_REC_LIRCCODE, /* Features */ 0, /* send_mode */ LIRC_MODE_LIRCCODE, /* rec_mode */ CODE_LENGTH, /* code_length */ tira_init, /* init_func */ NULL, /* config_func */ tira_deinit, /* deinit_func */ NULL, /* send_func */ tira_rec, /* rec_func */ tira_decode, /* decode_func */ NULL, /* ioctl_func */ NULL, /* readdata */ "tira" }; int tira_setup(void); int tira_decode (struct ir_remote *remote, ir_code *prep, ir_code *codep, ir_code *postp, int *repeat_flagp, lirc_t *min_remaining_gapp, lirc_t *max_remaining_gapp) { logprintf(LOG_ERR, "tira_decode length=%d", CODE_LENGTH); if(!map_code(remote, prep, codep, postp, 0, 0, CODE_LENGTH, code, 0, 0)) { return 0; } map_gap(remote, &start, &last, 0, repeat_flagp, min_remaining_gapp, max_remaining_gapp); return 1; } int tira_setup(void) { logprintf(LOG_ERR, "tira_setup"); char response[64+1]; int i; int ptr; char buffer[100]; for (i = 0; i< 65; ++i) response[i] = '\0'; /* Clear the port of any random data */ while (read(hw.fd, &ptr, 1) >= 0) ; /* Start off with the IP command. This was initially used to switch to timing mode on the Tira-1. The Tira-2 also supports this mode, however it does not switch the Tira-2 into timing mode. */ /* Get software version */ if (write (hw.fd, "VER\r\n", 5) != 5) { logprintf(LOG_ERR, "failed writing to device"); return 0; } /* Wait till the chars are written, should use tcdrain but that don't seem to work... *shrug* */ usleep (5 * (100 * 1000)); i = read (hw.fd, response, 4); logprintf(LOG_ERR, "Response '%s' with #bytes %d", response, i); if (strncmp(response, "1.2", 3) == 0) { logprintf(LOG_ERR, "device '%s' is ready and has version 1.2", hw.device); /* setup receiving hex data */ strcpy( buffer, "READHEXIR\r" ); write( hw.fd, buffer, strlen(buffer) ); /* wait for the chars to be written */ usleep (strlen(buffer) * (100 * 1000)); return 1; } logprintf(LOG_ERR, "unexpected response from device"); return 0; } int check_if_devicedriver_exists(char * device) { logprintf(LOG_ERR, "check_if_devicedriver_exists - function must be fixed"); struct stat fdCheck; // used to check if the device driver exist while( stat(device, &fdCheck) < 0 ) { logprintf(LOG_ERR, "Device %s has no driver"); usleep(500000); // chech if usb device exits } logprintf(LOG_ERR, "Driver for Device %s is found", device); return 1; } int tira_init(void) { logprintf(LOG_ERR, "tira_init"); check_if_devicedriver_exists(hw.device); logprintf(LOG_ERR, "Custom Dongle init"); // if(!tty_create_lock(hw.device)) // { // logprintf(LOG_ERR,"could not create lock files"); // return 0; // } logprintf(LOG_ERR, "Custom Dongle init - step 2"); logprintf(LOG_ERR, "Opening %s", hw.device); if ( (hw.fd = open (hw.device, O_RDWR | O_NONBLOCK | O_NOCTTY)) < 0) { logprintf(LOG_ERR, "Custom Dongle init - step 3"); //tty_delete_lock (); logprintf (LOG_ERR, "Could not open the '%s' device", hw.device); return 0; } logprintf(LOG_ERR, "device '%s' opened", hw.device); // the following comment is TIRA specific and does not mean anything /* 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. */ logprintf(LOG_ERR, "Setting port"); if(!tty_reset(hw.fd) || !tty_setbaud(hw.fd, 56700) // || // !tty_setrtscts(hw.fd, 1) ) { tira_deinit(); return 0; } logprintf(LOG_ERR, "Port is now set"); /* Device should be activated by this point... wait... */ usleep (50000); if(!tira_setup()) { tira_deinit(); return 0; } return 1; } int tira_deinit (void) { close(hw.fd); sleep(1); //tty_delete_lock(); return 1; } char *tira_rec (struct ir_remote *remotes) { logprintf(LOG_ERR, "tira_rec"); char *m; int i, x; last = end; x = 0; gettimeofday (&start, NULL); for (i = 0 ; i < NUMBER_BYTES; i++) { if (i > 0) { if (!waitfordata(20000)) { logprintf(LOG_ERR,"timeout reading byte %d",i); /* likely to be !=NUMBER_BYTES bytes, so flush. */ tcflush(hw.fd, TCIFLUSH); return NULL; } } if (read(hw.fd, &b[i], 1) != 1) { logprintf(LOG_ERR, "reading of byte %d failed.", i); logperror(LOG_ERR, NULL); return NULL; } logprintf(LOG_ERR, "byte %d: %02x", i, b[i]); x++; } gettimeofday(&end,NULL); code = 0; /* // We do not need this code because we are currently only using 4 of the 15-16 bytes for ( i = 0 ; i < NO_OF_USED_BYTES ; i++ ) // we only need four bytes { code |= ((ir_code) b[i]); code = code << 8; } */ HandleIrInputVersion1(b); // Will set the "code" variable with 4 bytes logprintf(LOG_ERR," -> %0llx",(unsigned long long) code); m = decode_all(remotes); return m; } void HandleIrInputVersion1( char *inBuffer ) { char *endptr; struct LSL_DATA irLslData; memset( (char*)&irLslData, 0x00, sizeof(irLslData) ); irLslData.format_low = (unsigned char) strtoul( inBuffer, &endptr, 16 ); irLslData.to_addr_low = (unsigned char) strtoul( endptr, &endptr, 16 ); irLslData.command_low = (unsigned char) strtoul( endptr, &endptr, 16 ); /* handle link bit */ if( (irLslData.format_low & 0x08) != 0 ) { irLslData.format_low = (irLslData.format_low & 0x07) | 0x80; } switch( irLslData.format_low & 0x0F ) { case IR_FORMAT_0: HandleIrFormat0( &irLslData ); break; case IR_FORMAT_1: HandleIrFormat1( &irLslData ); break; } } void HandleIrFormat0( struct LSL_DATA *pLslMsg ) { char strLinkBit[] = "Link bit is 0"; // check for Link bit if( (pLslMsg->format_low & 0x80) != 0 ) strLinkBit[strlen(strLinkBit) - 1] = '1'; logprintf(LOG_ERR, "IR format 0: %s: Source %02X: Command %02X\n", strLinkBit, pLslMsg->to_addr_low, pLslMsg->command_low); // first byte - link code |= ((ir_code) pLslMsg->format_low); code = code << 8; // SECOND BYTE - source code |= ((ir_code)pLslMsg->to_addr_low); code = code << 8; // third BYTE - unit - here 0x00 code |= ((ir_code) 0x00); code = code << 8; // fourth byte - command code |= ((ir_code) pLslMsg->command_low); // code = code << 8; not necessary // this should not be necessary // We are now using the first 4 bytes logprintf(LOG_ERR," -> %0llx",(unsigned long long) code); } void HandleIrFormat1( struct LSL_DATA *pLslMsg ) { // not impl yet } > Date: Thu, 22 Jan 2009 22:08:00 +0100 > From: li...@ba... > To: lir...@li... > Subject: Re: How to generate mapping? > > Hi! > > Kristian Lippert "kri...@ho..." wrote: > > Sorry, I'm new to this LIRC driver plugin system. > > It would be easier for all of us if you just showed all your code. > > Christoph > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf-spreadtheword _________________________________________________________________ Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us |