Wednesday, May 28, 2008

HVR-950 infrared receiver reverse engineered

Since I finally got my Windows XP system working, I was able to run usbsnoop and see how the IR works.

From the trace, I can see that every 93ms the Windows driver reads four bytes out of register 0x45. This register isn't listed in v4l's em28xx-reg.h. This fits well into my belief that the HVR-950 is using the onboard IR receiver provided in the em2883, whereas devices based on earlier Empia designs used an external IR chip accessed via i2c.

The only thing I'm not sure of yet is how the driver detects duplicate keypresses. If the register always contains the last code received, how can you distinguish between "4" and "444"?

I think it has something to do with the format of the 4 byte responses. I believe the first couple of bytes are some sort of rolling counter, while the third byte is the actual key being hit. I don't know what the forth byte does but it always seems to be zero. Perhaps the key value is two bytes, and I just haven't seen any codes over 0xff?

For example, when I hit "2" three times, this is what I get back:

[8223488 ms] 01 1e 02 00
[8223582 ms] 01 1e 02 00
[8223676 ms] 00 1e 02 00
[8223769 ms] 00 1e 02 00
[8223863 ms] 00 1e 02 00
[8223957 ms] 00 1e 02 00
[8224051 ms] 00 1e 02 00
[8224144 ms] 00 1e 02 00
[8224238 ms] 00 1e 02 00
[8224332 ms] 81 1e 02 00
[8224426 ms] 81 1e 02 00

The other thing that will be annoying is that the current devices expect a 1-1 correlation between devices and remote controls. They're using ir-kbd-i2c instead of using lircd and so it's not as easy as defining a different remote profile. In my case in particular, it's really a problem since the HVR-950 can be using the Hauppauge "dog bone" remote or the remote that came with my Elgato EyeTV Hybrid. Fortunately I have one of each, so at least I can experiment...

Since I was up at 4am, I really should have gone to bed early. Crap.

HVR-950 on Windows

Couldn't sleep, so at 4am I found myself in my pajamas eating Ben and Jerry's in front of the computer while reinstalling a fresh copy of Windows XP on my test PC. Got all the drivers installed (Ethernet, Intel chipset, video, sound).

I'm trying to get the HVR-950's remote control support working under Linux, so I wanted to do a usbsnoop under Windows. This has proven to be a greater challenge than expected (read my failed attempt from Saturday). This time I got a retail build of Windows installed and working as expected, downloaded and installed the latest drivers and WinTV from Hauppauge, and now WinTV crashes at startup. I was able to run it exactly one time to do the ATSC channel scan, and now it crashes whenever I start the application.

If I can't even get it to work on Windows XP SP2 with a completely fresh OS install, that is saying something.

Running Windows Update now, which means I'm installing SP3. Maybe WinTV has some undocumented incompatibility that gets fixed with a newer version of Windows.

To make matters worse, it's an Elgato EyeTV Hybrid and not actually an HVR-950, so it's not like I can call Hauppauge for tech support since it's not supported. It was working before i rebuilt the PC, so I know it should work fine.

Argh.

Tuesday, May 27, 2008

The Big Hammer

Went out for Thai with Joe, Packy, and Milosz tonight. Joe commented there was no way to figure out which process delivered a SIGTERM signal to the Linux PPTP daemon, to which I mused that "of course there is, I can do it in three lines in the kernel."

Of course what Joe meant was that there was no user friendly POSIX call for getting that information. The method I had proposed was extreme by just about any standard.

Ken Thompson is attributed with having said, "When in doubt, use brute force."

I like brute force. The big hammer can solve problems where other tools fail.

Got a problem where you don't have the source? Disassemble it.
Networking problem? Put a protocol dissector on the wire.
Intermittent hardware reset? Put a logic analyzer on the CPU's address and data bus.
Application problem? Strace it.
Driver problem? Hack the kernel.

If the usual methods of problem solving don't work, don't be afraid to go medieval on its ass.

My father, an experienced carpenter, used to say "there's a tool for every job."

He also used to say "When your only tool is a hammer, everything starts to look like a nail." I'm not saying the big hammer is always the right tool. It's just another tool you keep in your bag for the appropriate occasion.

=== begin rant ===
Maybe it's just because I'm getting older that makes me think today's Compsci graduates are wussies. They learn languages with automatic memory protection and garbage collection. Template libraries and canned data structures. ASP, C#, and Java. You ask them what to do when a program prints "Segmentation fault (core dump)" and they give you a blank stare.

Don't get me wrong, as technologies go all of the buzzwords above are "good things". But not knowing what goes on under the hood makes people crappy programmers. They can't problem-solve. As soon as the problem leaves their little world of understanding they're like a deer caught in headlights.

Saturday, May 24, 2008

Hardware hacking day fizzled out

So my plan for today was to get working the only remaining unimplemented piece of functionality in my HVR-950 driver - the IR support required for the remote control. Things didn't quite work out as planned.

Overslept and didn't fall out of bed until noon.

Poked at the v4l code for the em28xx driver and found out that unlike other em28xx based devices, there is no i2c device for the IR port on the HVR-950. I guess they're using the onboard em2883 IR port, but no other device supported seems to do it this way. So much for my hopes of flipping a bit and having the IR "just work". No datasheets available from EmpiaTech, so I'm going to have to do it "the hard way".

Went to rebuild my Windows XP so I can do a USB snoop and see how the IR port works. Had to install the "checked build" from MSDN since I don't have a copy of the retail build lying around. Got stuck and had to go to the office when I found out I didn't have the CD key.

The PC is from 2004, and pretty much all of the hardware support wasn't available in the stock version of XP (including the Ethernet driver, which creates a chicken/egg situation since I can't just download the needed drivers if there is no Ethernet). The fact that HP shipped some of the PCs with my model number with an Intel Ethernet and some with a Broadcom Ethernet, combined with Windows not making it easy to see who the hardware vendor is for unrecognized devices forced me to download both drivers (each around 25 MB).

Now the PC is caught in a loop rebooting every time the desktop comes up. I think I'm going to have to reinstall Windows and try again...

And either there is a driver problem or none of the USB ports support USB 2.0, so I'm going to have to stick a USB 2.0 PCI card in the PC if I'm going to be able to do anything with the HVR-950.

Oh yeah, and because I'm using the checked build, I can see how poorly engineered everybody else's software is because Windows keeps showing dialogs with assertions whenever some application does something illegal. You would think that vendors who write device drivers would try them out on a checked build (Hauppauge, SoundMax, are you listening?)

Enough ranting about my PC woes. Does anybody even care? I guess at least it's cathartic to have somewhere to vent...

On the upside, I did watch No Country for Old Men. Weird.

Looking down at 35th street, a party at the bar seems to have spilled out onto the sidewalk. I can hear the music here in my living room as I write this.

I have to wake up relatively early tomorrow to catch a train to New Jersey for the day. Will be good to see the family and there is the promise of spaghetti since my birthday was earlier in the week.

USAA article on Consumerist (and it's good)

So I admit it. I'm addicted to The Consumerist.

The downside is though that the site leaves me typically feeling pretty helpless. For example, Bank of America is a frequent offender mentioned on the site, and yet I still use them as my bank because it seems like everybody else is just as bad.

There was an article today about USAA, the insurance company I use. I had never seen any articles about USAA on the site before so it caught my attention. I was pleasantly surprised to see that the article was not a complaint about the company but rather was about how good a job they were doing.

http://consumerist.com/tag/above-and-beyond/?i=5010377&t=usaa-lays-smackdown-on-shady-enterprise-rental

So, at least I don't feel bad about my insurance company. :-)

Now if only I can find an honest bank, cable provider, cell phone company, telephone company, internet provider, airline, and electronics outlet...

Friday, May 23, 2008

Tux droid

Spent a good portion of the afternoon playing with my new Tux Droid. Downloaded the source. Started to learn some more about how D-BUS works. Played with the Festival Text to Speech Engine.

I was all excited since I got it to talk with the open source text to speech, and when I spoke to Victoria tonight, I held the phone up next to the Penguin so she could hear it talk:
Hello Devin. My name is Tux. What is your name?
I was so proud that I had gotten it to work. Her reply:
Why is it asking what your name is when it just said "Hello Devin"?
And that is why she is the Doctoral student and I am the college dropout.

Also, I was originally a bit disappointed that the audio quality was so poor. However, the problem with the audio was just a result of where I happened to put the Penguin on my desk to try it out.

It's kind of obvious after the fact, but it's generally a bad idea to put a 2.4 GHz wireless device with realtime delivery requirements within six inches of an 802.11g wireless router.

Ubuntu 8.04, mplayer, and my HVR-950 driver

I upgraded to Ubuntu 8.04 this week to test the V4L HVR-950 driver and ran into a problem where mplayer would work the first time but then subsequent attempts to run it would show an error suggesting that the open() call to /dev/dvb/adapter0/dvr0 would always return EBUSY. I assumed this was some bug in my driver exposed by upgrading to the new kernel, and I wanted to get it fixed before the 2.6.26 merge window closed.

After spending the morning littering the driver with debug code trying to locate what I thought was a bug in the referencing counting, it occurred to me to just run fuser against the device file.

root@devin-desktop:~# fuser -v /dev/dvb/adapter0/dvr0
USER PID ACCESS COMMAND
/dev/dvb/adapter0/dvr0:
root 6455 f.... mplayer
root 6459 f.... dbus-launch
root 6460 f.... dbus-daemon

Looks like they integrated mplayer with dbus, but they don't close the file handles on fork() so dbus inherits the file indefinitely (since it doesn't exit when mplayer exits).

I then put "ubuntu dbus" into my search and it turns up I'm about a week behind Markus Rechberger because he appears to have already found the issue:

http://www.mail-archive.com/em28xx@mcentral.de/msg01097.html

And he has already submitted a fix to Ubuntu:

https://bugs.launchpad.net/ubuntu/+source/dbus/+bug/230877

While I'm happy it wasn't a bug in my driver, I'm a bit annoyed about spending the first half of my day off from work debugging what turned up to be an issue somebody already found and fixed.

Wednesday, May 21, 2008

How things change...

So today is my 31st birthday. Thanks to everybody who took the time to reach out and call/email/write/IM.

Recent events in my family have had me thinking alot recently about the time I spent growing up in Florida. I've also been pondering how different a person I am from then, having left fifteen years ago next month.

Just for fun, here's a brief summary:











19932008
Satellite Beach, FloridaNew York, New York
I like steak!Vegetarian
Member of Teenage Republicans of South BrevardStaunch Democrat
Can I borrow the car?Takes the subway or walks everywhere
NerdNerd, but no longer ashamed...
Sad and lonelyCommitted relationship
386sx/16MHz, 4MB RAM, 20MB HDCore2Duo/1.8GHz, 1GB RAM, 300GB HD
High school studentSoftware Developer
Boy scout campDefCon in Las Vegas


I sometimes think about the people I left behind and wonder where they are now and how they turned out.

Monday, May 19, 2008

Tired

Had a long day today.

Was at the office until 9pm trying to figure out why a call to CreateProcess() in the Perl Win32::Job XS module was failing with GetLastError() returning "Access Denied". Hooked up the remote debugger to the Perl core and for the life of me I can't see anything wrong with the arguments being fed to the call. To make matters worse, it only happens when run from within an NT service (a bit of irony to get an "Access Denied" error from a service running as the Local Security Authority).

After work Packy, Milosz, and I got some Mexican food down on University Place, which was pretty good.

Confirmed that indeed my HVR-950 driver is broken under Ubuntu 8.04. I need to add some debugging and get a fix in before the 2.6.26 window closes. I'm just too tired to do it tonight.

Watched the season finale of House, which was pretty good. No more TV for me to watch this season.

Sunday, May 18, 2008

Too many projects, too little time

My job aside, there just aren't enough hours in the day. My list of projects is piling up, despite my efforts to focus. Here's a quick TODO list:
  • Finish upgrading my desktop to Ubuntu 8.04
  • Fix the resulting bug exposed in my HVR-950 driver
  • Get MythTV working again
  • Get the IR support working for my HVR-950
  • Upgrade my Macbook to Leopard
  • Get my Pinnacle PCTV HD Pro USB stick working under linux
  • Use my external USB drive enclosure to archive old hard drives
  • Get Tux Droid integrated with MythTV
  • Order the parts for Jon's garage door opener
  • Add ATSC scanning support to Kaffeine
  • Install moulding

Birthday weekend

Victoria and I celebrated my birthday this weekend (since it's in the middle of next week).

On Saturday, she took me to see Rent on Broadway and we had a nice dinner.

After my ranting last month about the notion of paying $3.99 for a piece of paper and an envelope, Victoria made me a card for my birthday:


To hell with Hallmark.

She also got me a Tux Droid, a new tea kettle, and a tiny RC helicopter which today we proceeded to take turns flying around the apartment.

Had some problems with the Tux Droid because I upgraded to Ubuntu 8.04 last week and the Tux Droid software has some issues with Ubuntu's changes to Python and udev. I pretty much got them straightened out last night though, and starting to think about ways I can integrate it with my MythTV.

Ah, the power of open source. Broken software? Just download the source code and fix it!

I started looking at writing a routine that would detect a instantaneous 40% increase in the light sensor between 6:30 and 9:00pm (indicating i had turned on the light when I came home), and would start announcing what new things MythTV recorded since last night.

Monday, May 12, 2008

Phone text messaging more expensive than getting data from Hubble

Here's a fun little article demonstrating how the cell phone companies are ripping you off on the cost of text messaging. He compares the cost to that of getting data from the Hubble Space Telescope:

http://www.physorg.com/news129793047.html

I'm sure you could guess without reading the article, but sending messages to the Hubble is way cheaper than text messaging your buddy down the street.

Wednesday, May 7, 2008

How is the cable company screwing you now?

Yeah, so the cable companies are sending out letters telling customers that they have to upgrade to digital service and get a cable box because of the FCC digital transition.

http://consumerist.com/379852/cablevision-blatantly-lies-to-subscribers-as-the-fcc-twiddles-its-thumbs

Of course, this is a complete lie. In fact, the FCC states pretty clearly on their site that this is not the case:

http://www.dtv.gov/consumercorner.html#faq30

Think of all your less technically savvy family members and friends receiving letters like this. Being told that they can't use their "cable ready" televisions anymore and instead are going to have to shell out another six or seven bucks to get cable boxes for every TV in their house. And they're going to blame the government.

Fuckers.

Orson Scott Card on J.K. Rowling lawsuit

I'm a couple of weeks behind the curve, but if you hadn't seen it, there was an entertaining read where Orson Scott Card discusses J.K. Rowling's lawsuit against the author of "The Harry Potter Lexicon".

This is hilarious.
Well, heck, I feel like the plot of my novel Ender's Game was stolen by J.K. Rowling.

A young kid growing up in an oppressive family situation suddenly learns that he is one of a special class of children with special abilities, who are to be educated in a remote training facility where student life is dominated by an intense game played by teams flying in midair, at which this kid turns out to be exceptionally talented and a natural leader. He trains other kids in unauthorized extra sessions, which enrages his enemies, who attack him with the intention of killing him; but he is protected by his loyal, brilliant friends and gains strength from the love of some of his family members. He is given special guidance by an older man of legendary accomplishments who previously kept the enemy at bay. He goes on to become the crucial figure in a struggle against an unseen enemy who threatens the whole world.
Here's the article:
http://greensboro.rhinotimes.com/Articles-i-2008-04-24-177772.112113_JK_Rowling_Lexicon_and_Oz.html

Thursday, May 1, 2008

Sounds stuck in my head...

It's strange sometimes how something can get stuck in your head from repetition. Like a catchy tune on the radio, the theme song from an old favorite TV show, or in my case tonight the sound of my father's Plectron:

<beep><beep><beep><beep><beep><beep><beep><beep><beep>
<honk><honk><honk><honk>
Allenhurst Police to the Allenhurst Fire Department and First Aid Squad
This is the daily test of the Plectron alarm.
Allenhurst Police to the Allenhurst Fire Department and First Aid Squad
This is the daily test of the Plectron alarm.
6:33 PM KDL905
<ssshhht>

I really need to do something about my insomnia.

FiOS coming...

Looks like Verizon has been busy in my building. The fiber optic conduit that has been sticking out of the wall for almost a year is now a fully wired panel. If there was doubt whether Verizon would ever get around to finishing the work, that doubt is gone. Yay!