LIRC Transmit Repeat Problem + USB-UIRT Speed Problem

Having problems? Use this forum to find help!

Moderator: jrhees

LIRC Transmit Repeat Problem + USB-UIRT Speed Problem

Postby DapperDan » Sun Mar 30, 2008 7:10 am

I am cross posting this both at the USB UIRT forum and the LIRC mailing list.


I recently began setting up LIRC + USB-UIRT and immediately ran into problems, out of the box it would control my Sat Receiver, however it would not control my Sony XBR2. In order to make it work, I've made a few changes to the LIRC code and can successfully make it work, hopefully someone with more LIRC knowledge would review the fixes and advise if there is perhaps an easier way. All of these problems relate back to that the Sony XBR requires the IR codes to be repeated quickly at minimum it seems 3 times. USB-UIRT worked amazingly and easily in windows, but LIRC had the below items I had to overcome.

Problem 1 - Repeat Problem
> With any min_repeat value, commands will not work, I get an IRSend: timeout error. Looking into the code I noticed the last_code was not set (see diff) and thus any timer event would fail as the first check is against the last code which is null. Also, by not calling send_success right away and waiting for the timerevent to do its thing, I got mixed/unstable results that left the daemon in weird states. I am not sure why, but putting in the send_success upfront lircd is much more stable for me.

Problem 2 - Now that LIRC was repeating itself, I noticed that it was not able to repeat itself fast enough on my box, I traced this down to usage of gettimeofday versus clock_gettime, apparently on some systems (like mine), gettimeofday can be sorta slow, by switching this function over, everything sped up and my TV started to receive signals. I also had to remove a read piece of code that was always timing out, its that line that I am most worried about/least confident I've done the right thing.

Problem 3 - Just an FYI for other people, keep in mind LIRC uses your machines hostname to connect a socket back to it, so it must be able to resolve your hostname 'nslookup tvremotebox', if it cannot you could waiting an extra second or more each command as DNS timesout. Setup a DNS entry for your box name or switch the hostname to localhost.

Thanks
Dan



diff -Naur new/daemons/hw_uirt2_common.c old/daemons/hw_uirt2_common.c
--- new/daemons/hw_uirt2_common.c 2008-03-29 23:13:55.000000000 -0700
+++ old/daemons/hw_uirt2_common.c 2008-03-29 23:05:30.000000000 -0700
@@ -34,7 +34,6 @@
#include <stdio.h>
#include <unistd.h>
#include <string.h>
-#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
@@ -53,22 +52,6 @@
#define HEXDUMP(buf, len)
#endif

-
-#ifndef TIMESPEC_TO_TIMEVAL
-# define TIMESPEC_TO_TIMEVAL(tv, ts) { \
- (tv)->tv_sec = (ts)->tv_sec; \
- (tv)->tv_usec = (ts)->tv_nsec / 1000; \
-}
-#endif
-
-#ifndef TIMEVAL_TO_TIMESPEC
-# define TIMEVAL_TO_TIMESPEC(tv, ts) { \
- (ts)->tv_sec = (tv)->tv_sec; \
- (ts)->tv_nsec = (tv)->tv_usec * 1000; \
-}
-#endif
-
-
struct tag_uirt2_t {
int fd;
int flags;
@@ -146,7 +129,7 @@
pos += 3;
}

- LOGPRINTF(LOG_DEBUG, "%s", str);
+ logprintf(LOG_DEBUG, "%s", str);
}
#endif /* DEBUG */

@@ -214,15 +197,11 @@

if (timerisset(&dev->pre_delay))
{
- struct timespec cur_tspec;
struct timeval cur;
struct timeval diff;
struct timeval delay;

- clock_gettime(CLOCK_REALTIME, &cur_tspec);
- TIMESPEC_TO_TIMEVAL(&cur, &cur_tspec);
-
-//gettimeofday(&cur, NULL);
+ gettimeofday(&cur, NULL);
timersub(&cur, &dev->pre_time, &diff);
PRINT_TIME(&diff);

@@ -231,7 +210,7 @@
timersub(&dev->pre_delay, &diff, &delay);
PRINT_TIME(&delay);

- LOGPRINTF(LOG_DEBUG, "udelay %lu %lu",
+ LOGPRINTF(1, "udelay %lu %lu",
delay.tv_sec, delay.tv_usec);
sleep(delay.tv_sec);
usleep(delay.tv_usec);
@@ -239,10 +218,10 @@

timerclear(&dev->pre_delay);
}
-//Unsure ramifications of removing this, definitly more stable without it/faster
-// uirt2_readflush(dev);

- LOGPRINTF(LOG_DEBUG, "writing command %02x", buf[0]);
+ uirt2_readflush(dev);
+
+ LOGPRINTF(1, "writing command %02x", buf[0]);

HEXDUMP(tmp, len + 2);
res = write(dev->fd, tmp, len + 2);
@@ -252,7 +231,7 @@
return -1;
}

- LOGPRINTF(LOG_DEBUG, "wrote %d", res);
+ LOGPRINTF(1, "wrote %d", res);

if (!mywaitfordata(dev, (long) 1000000)) {
logprintf(LOG_ERR, "uirt2_raw: did not receive results");
@@ -266,19 +245,19 @@
return -1;
}

- LOGPRINTF(LOG_DEBUG, "cmd res %d:", res);
+ LOGPRINTF(1, "cmd res %d:", res);
HEXDUMP(out + 1, out[0]);
- LOGPRINTF(LOG_DEBUG, "");
+ LOGPRINTF(1, "");

if (out[0] > 1) {
int check = checksum(out + 1, out[0]);

if (check != 0) {
-//unsure why this keeps happening, but log entry is annoying so lets hide for now
-// logprintf(LOG_ERR, "uirt2_raw: checksum error");
- return -1;
+ logprintf(LOG_ERR, "uirt2_raw: checksum error");
+ return -1;
}
}
+
return 0;
}

@@ -343,7 +322,7 @@
int bHdr = unit * (buf->bHdr1 + buf->bHdr0);
unsigned long bBitLength = calc_bits_length(buf);

- LOGPRINTF(LOG_DEBUG, "bBitLength %lu repeat %d", bBitLength, repeat);
+ LOGPRINTF(1, "bBitLength %lu repeat %d", bBitLength, repeat);

return (repeat + 1) * (bISDly + bHdr + bBitLength);
}
@@ -409,7 +388,7 @@

if (uirt2_getmode(dev) == mode)
{
- logprintf(1, "uirt2_setmode: already in requested mode");
+ LOGPRINTF(1, "uirt2_setmode: already in requested mode");
return 0;
}

@@ -484,18 +463,16 @@
* protocol, which sends extended information when
* the version is requested.
*/
-// Failed is misleading and make you worried, but this is normal for newerversions, so lets only print an message if detection fails completly
- LOGPRINTF(LOG_DEBUG, "uirt2: detection of uirt2 failed");
- LOGPRINTF(LOG_DEBUG, "uirt2: trying to detect newer uirt firmware");
+ LOGPRINTF(0, "uirt2: detection of uirt2 failed");
+ LOGPRINTF(0, "uirt2: trying to detect newer uirt firmware");
uirt2_readflush(dev);

out[0] = 8;
if (command_ext(dev, in, out) >= 0) {
*version = out[2] + (out[1] << 8);
-
return 0;
}
- logprintf(LOG_ERR, "detection failed");
+
return -1;
}

@@ -657,7 +634,7 @@
return 0;
}

- logprintf(3, "read_raw %02x", b);
+ LOGPRINTF(3, "read_raw %02x", b);

if (b == 0xff) {
dev->new_signal = 1;
@@ -668,7 +645,7 @@
byte_t isdly[2];

isdly[0] = b;
- logprintf(1, "dev->new_signal");
+ LOGPRINTF(1, "dev->new_signal");

res = readagain(dev->fd, &isdly[1], 1);

@@ -734,7 +711,7 @@
tmp[1] = sizeof(rem_ext) + 1;

memcpy(tmp + 2, &rem_ext, sizeof(rem_ext));
- res = command(dev, tmp, sizeof(rem_ext) + 1);
+ res = command(dev, tmp, sizeof(rem_ext) + 1);
}
else
{
@@ -751,15 +728,11 @@
res = command(dev, (byte_t *) &rem, sizeof(rem) - 2);
}
delay = calc_struct1_length(bRepeatCount, buf);
- //gettimeofday(&dev->pre_time, NULL);
- struct timespec pre_time_tspec;
- clock_gettime(CLOCK_REALTIME, &pre_time_tspec);
- TIMESPEC_TO_TIMEVAL(&dev->pre_time, &pre_time_tspec);
-
- dev->pre_delay.tv_sec = delay / 100000000;
- dev->pre_delay.tv_usec = delay % 100000000;
+ gettimeofday(&dev->pre_time, NULL);
+ dev->pre_delay.tv_sec = delay / 1000000;
+ dev->pre_delay.tv_usec = delay % 1000000;

- LOGPRINTF(LOG_DEBUG, "set dev->pre_delay %lu %lu",
+ LOGPRINTF(1, "set dev->pre_delay %lu %lu",
dev->pre_delay.tv_sec, dev->pre_delay.tv_usec);

return res;
diff -Naur new/daemons/lircd.c old/daemons/lircd.c
--- new/daemons/lircd.c 2008-03-29 22:47:15.000000000 -0700
+++ old/daemons/lircd.c 2008-03-29 22:50:07.000000000 -0700
@@ -1473,9 +1473,7 @@
return(0);
}
setitimer(ITIMER_REAL,&repeat_timer,NULL);
- repeat_remote->last_code=code;
- //return(1);
-return(send_success(fd,message));
+ return(1);
}
else
{
diff -Naur new/setup.sh old/setup.sh
--- new/setup.sh 2008-03-29 23:31:40.000000000 -0700
+++ old/setup.sh 2008-03-29 23:31:57.000000000 -0700
@@ -335,7 +335,7 @@
echo '#! /bin/sh' >$START
echo >>$START
echo "./configure \\" >>$START
- echo "--with-moduledir=/lib/modules/`uname -r`/misc CFLAGS=-lrt \\" >>$START
+ echo "--with-moduledir=/lib/modules/`uname -r`/misc \\" >>$START
if test "$LIRC_DRIVER" = "serial"; then
{
if test "$SOFT_CARRIER" = "off"; then echo "--without-soft-carrier \\" >>$START; fi
DapperDan
 
Posts: 1
Joined: Sun Mar 30, 2008 7:07 am

Return to Troubleshooting

Who is online

Users browsing this forum: No registered users and 30 guests

cron