Commit [732f01] Maximize Restore History

removed lirmand,

added support of shift encoded remotes to irrecord

columbus columbus 1999-09-06

removed drivers/irman
removed drivers/irman/.cvsignore
changed NEWS
changed TODO
changed configure.in
changed daemons
changed daemons/Makefile.am
changed daemons/hw_logitech.c
changed daemons/hw_logitech.h
changed daemons/hw_pixelview.c
changed daemons/hw_pixelview.h
changed daemons/ir_remote.c
changed daemons/ir_remote.h
changed daemons/irrecord.c
changed daemons/serial.c
changed drivers
changed drivers/Makefile.am
copied drivers/irman/Makefile.am -> daemons/hw_irman.h
copied drivers/irman/lirmand.c -> daemons/hw_irman.c
drivers/irman
File was removed.
drivers/irman/.cvsignore
File was removed.
NEWS Diff Switch to side-by-side view
Loading...
TODO Diff Switch to side-by-side view
Loading...
configure.in Diff Switch to side-by-side view
Loading...
daemons
Directory.
daemons/Makefile.am Diff Switch to side-by-side view
Loading...
daemons/hw_logitech.c Diff Switch to side-by-side view
Loading...
daemons/hw_logitech.h Diff Switch to side-by-side view
Loading...
daemons/hw_pixelview.c Diff Switch to side-by-side view
Loading...
daemons/hw_pixelview.h Diff Switch to side-by-side view
Loading...
daemons/ir_remote.c Diff Switch to side-by-side view
Loading...
daemons/ir_remote.h Diff Switch to side-by-side view
Loading...
daemons/irrecord.c Diff Switch to side-by-side view
Loading...
daemons/serial.c Diff Switch to side-by-side view
Loading...
drivers
Directory.
drivers/Makefile.am Diff Switch to side-by-side view
Loading...
drivers/irman/Makefile.am to daemons/hw_irman.h
--- a/drivers/irman/Makefile.am
+++ b/daemons/hw_irman.h
@@ -1,20 +1,25 @@
-## $Id: Makefile.am,v 5.0 1999/04/29 21:30:59 columbus Exp $
+/*      $Id: hw_irman.h,v 5.1 1999/09/06 14:56:04 columbus Exp $      */
 
-## Process this file with automake to produce Makefile.in 
+/****************************************************************************
+ ** hw_irman.h **************************************************************
+ ****************************************************************************
+ *
+ * routines for Irman
+ * 
+ * Copyright (C) 1999 Christoph Bartelmus <lirc@bartelmus.de>
+ *
+ */
 
-sbin_PROGRAMS = lirmand
-lirmand_SOURCES = lirmand.c
+#ifndef _HW_IRMAN_H
+#define _HW_IRMAN_H
 
-# this can be either -lirman or -lirman_sw
-lirmand_LDADD = @irman_lib@
+#include "drivers/lirc.h"
 
-install-exec-local: mkdev
-uninstall-local: rmdev
+int irman_decode(struct ir_remote *remote,
+		  ir_code *prep,ir_code *codep,ir_code *postp,
+		  int *repeat_flagp,lirc_t *remaining_gapp);
+int irman_init(void);
+int irman_deinit(void);
+char *irman_rec(struct ir_remote *remotes);
 
-mkdev:
-	test -p @devdir@/lirc || @mknod@ @devdir@/lirc p
-
-rmdev:
-	test -p @devdir@/lirc && $(RM) @devdir@/lirc
-
-CLEANFILES = *~
+#endif
drivers/irman/lirmand.c to daemons/hw_irman.c
--- a/drivers/irman/lirmand.c
+++ b/daemons/hw_irman.c
@@ -1,6 +1,14 @@
-/* lirmand.c, (c) 1998-1999 Tom Wheeley <tom.wheeley@bigfoot.com>   */
-/* This program is free software.  See file COPYING for details     */
-/* $Id: lirmand.c,v 5.4 1999/09/02 20:03:53 columbus Exp $           */
+/*      $Id: hw_irman.c,v 5.1 1999/09/06 14:56:04 columbus Exp $      */
+
+/****************************************************************************
+ ** hw_irman.c **********************************************************
+ ****************************************************************************
+ *
+ * routines for Irman
+ * 
+ * Copyright (C) 1999 Christoph Bartelmus <lirc@bartelmus.de>
+ *
+ */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
@@ -8,332 +16,195 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
 #include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
 #include <signal.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-  
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-#ifdef HAVE_FCNTL_H
-# include <fcntl.h>
-#endif
-
-#include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/types.h>
-#include <sys/stat.h>
+#include <sys/ioctl.h>
 
 #include <irman.h>
 
-#include "drivers/lirc.h"
-
-/* default bit order is MSB_TO_LSB */
-#ifndef LSB_TO_MSB
-# ifndef MSB_TO_LSB	/* neither defined */
-#  define MSB_TO_LSB 1
-# endif
-#else
-# ifdef MSB_TO_LSB	/* both defined */
-#  error "both LSB_TO_MSB and MSB_TO_LSB are defined. cannot cope"
-# endif
-#endif
-
-/* how lazy... */
-#define STRERR	strerror(errno)
-
-/* codes sent to lircd */
-lirc_t gap 	=  0x00010000;
-lirc_t pulse	=  0x00000400|PULSE_BIT;
-lirc_t one_space =  0x00000c00;
-lirc_t zero_space = 0x00000800;
-
-char *progname = "lirmand";
-
-/* these should be set by config.h (via acconfig.h) */
-#ifndef LIRC_DRIVER_DEVICE
-# define LIRC_DRIVER_DEVICE	"/tmp/lirc"
-#endif
-#ifndef LIRMAND_LOGFILE
-# define LIRMAND_LOGFILE	"/tmp/lirmand-log"
-#endif
-
-int lirc = 0;	/* file descriptor */
-int is_daemon = 0;
-FILE *log = NULL;
-
-FILE *open_log(void)
-{
-  time_t t=time(NULL);
-
-  if (!log) {
-    log = fopen(LIRMAND_LOGFILE, "a");
-    if (log) {
-      fprintf(log, "%s started at %s\n", progname, ctime(&t));
-    }
-  }
-  return log;
-}
-
-void close_log(void)
-{
-  time_t t = time(NULL);
-  
-  if (log) {
-    fprintf(log, "%s stopped at %s\n", progname, ctime(&t));
-    fclose(log);
-  }
-  log = NULL;
-}
-
-
-int debug_printf(char *format, ...)
-{
-  va_list va;
-  int ret = 0;
-  
-  if (!open_log())
-    return 0;
-  
-  va_start(va, format);
-  ret = vfprintf(log, format, va);
-  if (!is_daemon) {
-    fprintf(stderr, "%s: ", progname);
-    vfprintf(stderr, format, va);
-  }
-  va_end(va);
-
-  return ret;
-}
-
-
-/* print errors */
-int eprintf(char *format, ...)
-{
-  va_list va;
-  int ret = 0;
-
-  va_start(va, format);
-  if (open_log()) {
-    ret  = fprintf(log, "error: ");
-    ret += vfprintf(log, format, va);
-  }
-  if (!is_daemon) {
-    ret  = fprintf(stderr, "%s: ", progname);
-    ret += vfprintf(stderr, format, va);
-  }
-  va_end(va);
-
-  return ret;
-}
-
-
-/* Here we write out a single bit using REC-80 encoding */
-
-int write_encoded_bit(int value)
-{
-  if (value != 0) {
-    write(lirc, &one_space, sizeof one_space);
-  } else {
-    write(lirc, &zero_space, sizeof zero_space);
-  }
-  write(lirc, &pulse, sizeof pulse);
-}
-
-
-/* brrrr.  (default is MSB_TO_LSB, I see no reason for this to change) */
-#ifdef MSB_TO_LSB
-#  define ORDER(X)	(bit)
-#else
-#  define ORDER(x)	(numbits - bit - 1)
-#endif
-
-void write_encoded_uchar(unsigned char value, int numbits)
-{
-  int bit;
-  int max = 1 << (numbits - 1);
-  
-  for (bit=0; bit<numbits; bit++) {
-    write_encoded_bit((value & (max >> ORDER(bit))) ? 1 : 0);
-  } 
-}
-
-
-RETSIGTYPE sigterm(int sig)
-{
-  signal(sig, SIG_DFL);
-  
-  ir_finish();
-  close(lirc);
-  close_log();
-  
-  /* Vandoorselaere Yoann : yoann@coldserver.com
-   * The problem here is that we call raise(sig)
-   * without calling signal(signo, SIG_DFL) first.
-   * According to the manpage: On linux system, signal uses 
-   * BSD semantics and the default behaviour is not reset 
-   * when the signal is reset.
-   * This made lirmand entered in an endless loop when a signal was caught.
-   */ 
-  signal(sig, SIG_DFL);
-  raise(sig);
-}
-
-
-#ifdef DAEMONIZE
-void daemonize(void)
-{
-  pid_t pid;
-	
-  if ((pid = fork()) < 0) {		/* error */
-
-    eprintf("fork() failed: `%s'\n", STRERR);
-    exit(1);
-
-  } else if (pid) {			/* parent */
-
-    printf("%s installed (%d)\n", progname, (int)pid);
-    exit(0);
-
-  } else {				/* child */
-
-    is_daemon = 1;
-    fclose(stdin);
-    fclose(stdout);
-    fclose(stderr);
-    setsid();
-    chdir("/");
-    umask(0);
-  }
-}
-#endif
- 
-
-void loop()
-{
-  unsigned char *code;
-  char *text = NULL;
-  int i;
-
-  errno = 0;
-  for(;;) {
-
-    code = ir_get_code();
-
-    if (code) {
-      text = ir_code_to_text(code);
-      debug_printf("rx `%s'\n", text);
-
-      write(lirc, &gap, sizeof gap);
-      write(lirc, &pulse, sizeof pulse);
-
-      /* irrecord expects >20% of the bits to be '1'.
-	 The percentage in the code the Irman sends is too low.
-	 We'll fix that by sending a dummy 'pre_data' consisting of 0xffff */
-
-      write_encoded_uchar(0xff, 8);
-      write_encoded_uchar(0xff, 8);
-
-      for(i = 0; i < IR_CODE_LEN; i++) {
-        write_encoded_uchar(code[i], 8);
-      }
-
-    /* error handling dullness */
-    } else {
-      if (errno == IR_EDUPCODE) {
-        debug_printf("rx `%s' (dup - ignored)\n", text?text:"(null - bug)");
-      } else {
-        if (errno == IR_EDISABLED) {
-          eprintf("irman not initialised (this is a bug)\n");
-        } else {
-          eprintf("error reading code: `%s'\n", ir_strerror(errno));
-        }
-        return;
-      }
-    }
-  }
-
-}
-
-
-int main(int argc, char **argv)
-{
-  char *filename;
-
-  if (ir_init_commands(NULL, 1) < 0) {
-    fprintf(stderr, "error initialising irman software: %s\n", strerror(errno));
-    exit(1);
-  }
-
-  filename = ir_default_portname();
-  
-  if (argc == 2) {
-    filename = argv[1];
-  } else {
-    if (!filename) {
-      fprintf(stderr, "usage: lirmand device\n");
-      exit(0);
-    }
-  }
-
-/* daemonize moved here on suggestion from Vandoorselaere Yoann, to avoid
- * problems with the child doing all the work with the parent's files
- */
-
-#ifdef DAEMONIZE
-  daemonize();
-#else
-  fprintf(stderr, "%s running (non daemon)\n", progname);
-#endif
-
-  errno = 0;  
-  if (ir_init(filename) < 0) {
-    eprintf("error initialising irman hardware: `%s'\n", STRERR);
-    exit(1);
-  }
-
-  /* try and create the fifo we write to lircd through.  If it exists then
-   * we either get EEXIST or EACCES, so we can ignore these errors.  We get
-   * EACCES when it exists and we are not root.  open() will throw up an error
-   * if we don't have permission to write, so we can ignore EACCES for now.
-   */
-
-  if (mkfifo(LIRC_DRIVER_DEVICE, 0644) == -1) {
-    if(errno != EEXIST && errno != EACCES) {
-      eprintf("could not create fifo: `%s'\n", STRERR);
-      exit(1);
-    }
-  }
-  
-  lirc = open(LIRC_DRIVER_DEVICE, O_RDWR|O_NONBLOCK);
-  if (lirc == -1) {
-    eprintf("could not open fifo: `%s'\n", STRERR);
-    exit(1);
-  }
-
-  /* borrowed from lircmd */
-  signal(SIGPIPE,SIG_IGN);
-  signal(SIGTERM,sigterm);
-  signal(SIGINT,sigterm);
-
-
-  loop();
-
-  ir_finish();
-  close(lirc);
-  return 0;
-}
-
-/* end of lirmand.c */
+#include "hardware.h"
+#include "serial.h"
+#include "ir_remote.h"
+#include "lircd.h"
+#include "hw_irman.h"
+
+extern struct ir_remote *repeat_remote,*last_remote;
+
+unsigned char *codestring;
+struct timeval start,end,last;
+lirc_t gap;
+ir_code code;
+
+#define CODE_LENGTH 64
+
+struct hardware hw=
+{
+	-1,                       /* fd */
+	LIRC_CAN_REC_LIRCCODE,    /* features */
+	0,                        /* send_mode */
+	LIRC_MODE_LIRCCODE,       /* rec_mode */
+	CODE_LENGTH,              /* code_length */
+	irman_init,               /* init_func */
+	irman_deinit,             /* deinit_func */
+	NULL,                     /* send_func */
+	irman_rec,                /* rec_func */
+	irman_decode              /* decode_func */
+};
+
+int irman_decode(struct ir_remote *remote,
+		     ir_code *prep,ir_code *codep,ir_code *postp,
+		     int *repeat_flagp,lirc_t *remaining_gapp)
+{
+	ir_code help,mask;
+	int i;
+
+	if(remote->pre_data_bits+
+	   remote->bits+
+	   remote->post_data_bits!=CODE_LENGTH ||
+	   remote->flags&CONST_LENGTH) return(0);
+
+	help=code;
+
+	if(remote->post_data_bits>0)
+	{
+		mask=0;
+		for(i=0;i<remote->post_data_bits;i++)
+		{
+			mask=mask<<1;
+			mask=mask|1;
+		}
+		*postp=help&mask;
+		help=help>>remote->post_data_bits;
+	}
+	if(remote->bits>0)
+	{
+		mask=0;
+		for(i=0;i<remote->bits;i++)
+		{
+			mask=mask<<1;
+			mask=mask|1;
+		}
+		*codep=help&mask;
+		help=help>>remote->bits;
+	}
+	if(remote->pre_data_bits>0)
+	{
+		mask=0;
+		for(i=0;i<remote->pre_data_bits;i++)
+		{
+			mask=mask<<1;
+			mask=mask|1;
+		}
+		*prep=help&mask;
+		help=help>>remote->pre_data_bits;
+	}
+	
+	if(start.tv_sec-last.tv_sec>=2) /* >1 sec */
+	{
+		*repeat_flagp=0;
+	}
+	else
+	{
+		gap=time_elapsed(&last,&start);
+		
+		if(gap<=remote->remaining_gap*(100+remote->eps)/100
+		   || gap<=remote->remaining_gap+remote->aeps)
+			*repeat_flagp=1;
+		else
+			*repeat_flagp=0;
+	}
+	
+	*remaining_gapp=remote->gap;
+
+#       ifdef DEBUG
+	logprintf(1,"pre: %llx\n",(unsigned long long) *prep);
+	logprintf(1,"code: %llx\n",(unsigned long long) *codep);
+	logprintf(1,"post: %llx\n",(unsigned long long) *postp);
+	logprintf(1,"repeat_flag: %d\n",*repeat_flagp);
+	logprintf(1,"gap: %lu\n",(unsigned long) gap);
+	logprintf(1,"rem: %lu\n",(unsigned long) remote->remaining_gap);
+#       endif
+	return(1);
+}
+
+int irman_init(void)
+{
+	if(!tty_create_lock(LIRC_DRIVER_DEVICE))
+	{
+		logprintf(0,"could not create lock files\n");
+		return(0);
+	}
+	if((hw.fd=ir_init(LIRC_DRIVER_DEVICE))<0)
+	{
+		logprintf(0,"could not open lirc\n");
+		logperror(0,"irman_init()");
+		tty_delete_lock();
+		return(0);
+	}
+	return(1);
+}
+
+int irman_deinit(void)
+{
+	ir_finish();
+	sleep(1); /* give hardware enough time to reset */
+	close(hw.fd);
+	tty_delete_lock();
+	return(1);
+}
+
+char *irman_rec(struct ir_remote *remotes)
+{
+	static char *text=NULL;
+	char *m;
+	int i;
+	
+	gettimeofday(&start,NULL);
+	codestring=ir_get_code();
+	gettimeofday(&end,NULL);
+	if(codestring==NULL)
+	{
+#               ifdef DEBUG
+		if(errno==IR_EDUPCODE)
+		{
+			logprintf(1,"received \"%s\" (dup - ignored)\n",
+				  text ? text:"(null - bug)");
+		}
+		else if(errno==IR_EDISABLED)
+		{
+			logprintf(1,"irman not initialised (this is a bug)\n");
+		}
+		else
+		{
+			logprintf(1,"error reading code: \"%s\"\n",
+				  ir_strerror(errno));
+		}
+#               endif
+		return(NULL);
+	}
+	
+	text=ir_code_to_text(codestring);
+#       ifdef DEBUG
+	logprintf(1,"received \"%s\"\n",text);
+#       endif
+
+	/* this is only historical but it's necessary for
+	   compatibility to older versionns and it's handy to
+	   recognize Irman config files */
+	code=0xffff;
+
+	for(i=0;i<IR_CODE_LEN;i++)
+	{
+		code=code<<8;
+		code=code|(ir_code) (unsigned char) codestring[i];
+	}
+
+	m=decode_all(remotes);
+	last=end;
+	return(m);
+}