Hello

I would like to make my Pinnacle PCTV remote command (with its serial receiver) usable under Windows. I failed to make WinLIRC work so I tried lirc with Cygwin.
I successfully compiled lirc-0.8.5 on Windows Vista x64 with Cygwin 1.7.

I will explain the steps to make it work, some people may be interested in.

First my installation is:
- Windows Vista x64 business (should work on other Windows)
- Cygwin 1.7 beta basic install (common install + development tools (gcc 4.3.2, binutils, ...) + python (I don't know if it is used))

Compilation:
tar xjvf lirc-0.8.5.tar.bz2
cd lirc-0.8.5

patch -p1 -i ../lirc_cygwin-0.8.5.patch
# I'll detail this patch later

CFLAGS="-O2" CXXFLAGS="-O2" ./configure --with-driver=pctv --with-tty=/dev/ttyS0
# I don't need debug info; works also with default flags
# I have a Pinnacle PCTV remote command with its receiver connected to the first serial port.
make
make install

mkdir /var/lock
# Cygwin does not create this folder

Execution:
# -n: No daemon for test (also works without this flag)
# -H pinsys: my remote (may be omitted as specified at configure step)
# -d /dev/ttyS0: serial port to use (may be omitted as specified at configure step and /dev/lirc -> ttyS0 link created at install)
# -l: enable inet socket, WinLIRC works like that
# remotes/pinnacle_systems/lircd.conf.pctv is copied as /etc/pctv.conf at install so no config file precified
/usr/local/sbin/lircd.exe -n -H pinsys -d /dev/ttyS0 -l

Test:
irw.exe
0000000000fe173f 00 Chan+Play PinnacleSysPCTVRemote
0000000000fe7e17 00 channel+ PinnacleSysPCTVRemote
0000000000fe7e17 01 channel+ PinnacleSysPCTVRemote
0000000000fe7e17 02 channel+ PinnacleSysPCTVRemote
0000000000fe7e17 03 channel+ PinnacleSysPCTVRemote
0000000000fe7e17 04 channel+ PinnacleSysPCTVRemote
0000000000fe851b 00 vol+ PinnacleSysPCTVRemote
0000000000feb53c 00 Mute PinnacleSysPCTVRemote
0000000000fe4325 00 Chan_Last PinnacleSysPCTVRemote
0000000000fe4325 00 Chan_Last PinnacleSysPCTVRemote
# It uses /dev/lircd
# Output matches key pressed on the remote
# Any application working with WinLIRC can connect to 127.0.0.1:8765. I tried with Media Player Classic Home Cinema

lirc_cygwin-0.8.5.patch:
diff -Nru a/daemons/irrecord.c b/daemons/irrecord.c
--- a/daemons/irrecord.c    2009-04-28 18:24:36.000000000 +0200
+++ b/daemons/irrecord.c    2009-08-26 15:23:26.492495400 +0200
@@ -244,7 +244,7 @@
     "emulation"
 };
 
-static int iprintf(int interactive, char *format_str, ...)
+static int interactive_printf(int interactive, char *format_str, ...)
 {
     va_list ap;
     int ret = 0;
@@ -1771,7 +1771,7 @@
                         {
                             remote->gap=calc_signal(scan);
                             remote->flags|=CONST_LENGTH;
-                            iprintf(interactive, "\nFound const length: %lu\n",(unsigned long) remote->gap);
+                            interactive_printf(interactive, "\nFound const length: %lu\n",(unsigned long) remote->gap);
                             break;
                         }
                         scan=scan->next;
@@ -1786,7 +1786,7 @@
                             if(scan->count>SAMPLES)
                             {
                                 remote->gap=calc_signal(scan);
-                                iprintf(interactive, "\nFound gap: %lu\n",(unsigned long) remote->gap);
+                                interactive_printf(interactive, "\nFound gap: %lu\n",(unsigned long) remote->gap);
                                 break;
                             }
                             scan=scan->next;
@@ -1794,7 +1794,7 @@
                     }
                     if(scan!=NULL)
                     {
-                        iprintf(interactive, "Please keep on pressing buttons like described above.\n");
+                        interactive_printf(interactive, "Please keep on pressing buttons like described above.\n");
                         mode=MODE_HAVE_GAP;
                         sum=0;
                         count=0;
@@ -1968,7 +1968,7 @@
 #endif
                 if(count_signals>=SAMPLES)
                 {
-                    iprintf(interactive, "\n");
+                    interactive_printf(interactive, "\n");
                     get_scheme(remote, interactive);
                     if(!get_header_length(remote, interactive) ||
                        !get_trail_length(remote, interactive) ||
@@ -2151,8 +2151,8 @@
     if(lengths[length]>=TH_SPACE_ENC*sum/100)
     {
         length++;
-        iprintf(interactive, "Space/pulse encoded remote control found.\n");
-        iprintf(interactive, "Signal length is %u.\n",length);
+        interactive_printf(interactive, "Space/pulse encoded remote control found.\n");
+        interactive_printf(interactive, "Signal length is %u.\n",length);
         /* this is not yet the
            number of bits */
         remote->bits=length;
@@ -2195,12 +2195,12 @@
                    (calc_signal(maxs)<TH_RC6_SIGNAL ||
                     calc_signal(max2s)<TH_RC6_SIGNAL))
                 {
-                    iprintf(interactive, "RC-6 remote control found.\n");
+                    interactive_printf(interactive, "RC-6 remote control found.\n");
                     set_protocol(remote, RC6);
                 }
                 else
                 {
-                    iprintf(interactive, "RC-5 remote control found.\n");
+                    interactive_printf(interactive, "RC-5 remote control found.\n");
                     set_protocol(remote, RC5);
                 }
                 return;
@@ -2208,7 +2208,7 @@
         }
     }
     length++;
-    iprintf(interactive, "Suspicious data length: %u.\n",length);
+    interactive_printf(interactive, "Suspicious data length: %u.\n",length);
     /* this is not yet the number of bits */
     remote->bits=length;
     set_protocol(remote, SPACE_ENC);
@@ -2259,12 +2259,12 @@
 #       endif
     if(max_count>=sum*TH_TRAIL/100)
     {
-        iprintf(interactive, "Found trail pulse: %lu\n",
+        interactive_printf(interactive, "Found trail pulse: %lu\n",
             (unsigned long) calc_signal(max_length));
         remote->ptrail=calc_signal(max_length);
         return(1);
     }
-    iprintf(interactive, "No trail pulse found.\n");
+    interactive_printf(interactive, "No trail pulse found.\n");
     return(1);
 }
 
@@ -2285,7 +2285,7 @@
 #       endif
     if(max_count>=sum*TH_LEAD/100)
     {
-        iprintf(interactive, "Found lead pulse: %lu\n",
+        interactive_printf(interactive, "Found lead pulse: %lu\n",
                (unsigned long) calc_signal(max_length));
         remote->plead=calc_signal(max_length);
         return(1);
@@ -2302,12 +2302,12 @@
     }
     if(abs(2*a-b)<b*eps/100 || abs(2*a-b)<aeps)
     {
-        iprintf(interactive, "Found hidden lead pulse: %lu\n",
+        interactive_printf(interactive, "Found hidden lead pulse: %lu\n",
                (unsigned long) a);
         remote->plead=a;
         return(1);
     }
-    iprintf(interactive, "No lead pulse found.\n");
+    interactive_printf(interactive, "No lead pulse found.\n");
     return(1);
 }
 
@@ -2324,7 +2324,7 @@
     }
     else
     {
-        iprintf(interactive, "No header data.\n");
+        interactive_printf(interactive, "No header data.\n");
         return(1);
     }
 #       ifdef DEBUG
@@ -2344,20 +2344,20 @@
             headerp=calc_signal(max_plength);
             headers=calc_signal(max_slength);
 
-            iprintf(interactive, "Found possible header: %lu %lu\n",
+            interactive_printf(interactive, "Found possible header: %lu %lu\n",
                 (unsigned long) headerp,
                 (unsigned long) headers);
             remote->phead=headerp;
             remote->shead=headers;
             if(first_lengths<second_lengths)
             {
-                iprintf(interactive, "Header is not being repeated.\n");
+                interactive_printf(interactive, "Header is not being repeated.\n");
                 remote->flags|=NO_HEAD_REP;
             }
             return(1);
         }
     }
-    iprintf(interactive, "No header found.\n");
+    interactive_printf(interactive, "No header found.\n");
     return(1);
 }
 
@@ -2375,7 +2375,7 @@
             printf("Repeat inconsitentcy.\n");
             return(0);
         }
-        iprintf(interactive, "No repeat code found.\n");
+        interactive_printf(interactive, "No repeat code found.\n");
         return(1);
     }
 
@@ -2410,7 +2410,7 @@
             repeatp=calc_signal(max_plength);
             repeats=calc_signal(max_slength);
            
-            iprintf(interactive, "Found repeat code: %lu %lu\n",
+            interactive_printf(interactive, "Found repeat code: %lu %lu\n",
                 (unsigned long) repeatp,
                 (unsigned long) repeats);
             remote->prepeat=repeatp;
@@ -2420,7 +2420,7 @@
                 max_slength=get_max_length(first_repeat_gap,
                                NULL);
                 repeat_gap=calc_signal(max_slength);
-                iprintf(interactive, "Found repeat gap: %lu\n",
+                interactive_printf(interactive, "Found repeat gap: %lu\n",
                     (unsigned long) repeat_gap);
                 remote->repeat_gap=repeat_gap;
                
@@ -2428,7 +2428,7 @@
             return(1);
         }
     }
-    iprintf(interactive, "No repeat header found.\n");
+    interactive_printf(interactive, "No repeat header found.\n");
     return(1);
 
 }
@@ -2533,7 +2533,7 @@
                     printf("Unknown encoding found.\n");
                     return(0);
                 }
-                iprintf(interactive, "Signals are biphase encoded.\n");
+                interactive_printf(interactive, "Signals are biphase encoded.\n");
                 p1=calc_signal(max_plength);
                 p2=calc_signal(max2_plength);
                 s1=calc_signal(max_slength);
@@ -2562,7 +2562,7 @@
                 if(max2_plength)
                 {
                     p2=calc_signal(max2_plength);
-                    iprintf(interactive, "Signals are pulse encoded.\n");
+                    interactive_printf(interactive, "Signals are pulse encoded.\n");
                     remote->pone=max(p1,p2);
                     remote->sone=s1;
                     remote->pzero=min(p1,p2);
@@ -2576,7 +2576,7 @@
                 else
                 {
                     s2=calc_signal(max2_slength);
-                    iprintf(interactive, "Signals are space encoded.\n");
+                    interactive_printf(interactive, "Signals are space encoded.\n");
                     remote->pone=p1;
                     remote->sone=max(s1,s2);
                     remote->pzero=p1;
@@ -2595,7 +2595,7 @@
                 {
                     remote->phead=remote->shead=0;
                     remote->flags&=~NO_HEAD_REP;
-                    iprintf(interactive, "Removed header.\n");
+                    interactive_printf(interactive, "Removed header.\n");
                 }
                 if(is_biphase(remote) &&
                    expect(remote,remote->shead,remote->sone))
@@ -2603,7 +2603,7 @@
                     remote->plead=remote->phead;
                     remote->phead=remote->shead=0;
                     remote->flags&=~NO_HEAD_REP;
-                    iprintf(interactive, "Removed header.\n");
+                    interactive_printf(interactive, "Removed header.\n");
                 }
             }
             if(is_biphase(remote))
@@ -2630,7 +2630,7 @@
                           (has_header(remote) ? 2:0)+
                           1-(remote->ptrail>0 ? 2:0))/2;
             }
-            iprintf(interactive, "Signal length is %d\n",remote->bits);
+            interactive_printf(interactive, "Signal length is %d\n",remote->bits);
             free_lengths(&max_plength);
             free_lengths(&max_slength);
             return(1);
diff -Nru a/daemons/lircd.c b/daemons/lircd.c
--- a/daemons/lircd.c    2009-04-28 18:25:50.000000000 +0200
+++ b/daemons/lircd.c    2009-08-26 14:03:40.110495400 +0200
@@ -156,7 +156,7 @@
 #endif
 
 /* quite arbitrary limits */
-#define MAX_PEERS    100
+#define MAX_PEERS    30
 /* substract one for lirc, sockfd, sockinet, logfile, pidfile, uinput */
 #define MAX_CLIENTS     (FD_SETSIZE-6-MAX_PEERS)
 
@@ -330,7 +330,9 @@
 
     if(uinputfd != -1)
     {
+#if defined(__linux__)
         ioctl(uinputfd, UI_DEV_DESTROY);
+#endif
         close(uinputfd);
         uinputfd = -1;
     }
diff -Nru a/drivers/lirc.h b/drivers/lirc.h
--- a/drivers/lirc.h    2009-01-30 20:39:26.000000000 +0100
+++ b/drivers/lirc.h    2009-08-26 15:21:05.828495400 +0200
@@ -5,10 +5,11 @@
 
 #if defined(__linux__)
 #include <linux/ioctl.h>
-#else
-#if defined(__NetBSD__)
+#elif defined(__NetBSD__)
+#include <sys/ioctl.h>
+#elif defined(__CYGWIN__)
+#define __USE_LINUX_IOCTL_DEFS
 #include <sys/ioctl.h>
-#endif
 #endif
 
 #define PULSE_BIT  0x01000000
diff -Nru a/tools/mode2.c b/tools/mode2.c
--- a/tools/mode2.c    2008-07-01 22:51:43.000000000 +0200
+++ b/tools/mode2.c    2009-08-26 15:20:14.231495400 +0200
@@ -15,6 +15,10 @@
 # include <config.h>
 #endif
 
+#ifdef __CYGWIN__
+#define __USE_LINUX_IOCTL_DEFS
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>

- daemons/irrecord.c:
iprintf was conflicting with /usr/include/stdio.h declaration so I renamed it.

- daemons/lircd.c:
In CYGWIN, FD_SETSIZE is 64 so with
#define MAX_PEERS    100
MAX_CLIENTS would be -42. Thanks to gcc to notify the error! I don't know what is a peer and what is a client (irw is a client?) so may be this value should be tuned.
Also ioctl(uinputfd, UI_DEV_DESTROY); cannot be compiled so I put this code for Linux only.

- drivers/lirc.h b/drivers/lirc.h and tools/mode2.c b/tools/mode2.c
_IOR used in lirc.h is defined in sys/ioctl.h only if __USE_LINUX_IOCTL_DEFS is defined...


I'll now try to make it work as a service (it should not be hard) and connect applications to it.
Thanks for your attention.

Cédric Delmas


P.S.: sorry for my English, I don't use it very often.


Découvrez toutes les possibilités de communication avec vos proches