Hack 98. Catching TiVo Events

   

Hack 98 Catching TiVo Events

figs/expert.gif figs/hack98.gif

Instead of being one monolithic system, the TiVo is broken down into smaller programs that communicate with one another by passing messages around. If you intercept that message stream, you can get a clue into what the TiVo is doing .

One common software paradigm is to break up large pieces of code into smaller chunks of code that call one another when they need to interact. The TiVo software isn't much different. It has various subsystems, all talking to each other through a central event switcher. Think of the event switcher as a message board. An event is posted to the event switcher, which makes sure that everybody sees the event. Each software component can then choose if and how to react .

These events are structured in three parts : an event type, an event subtype, and the data carried. You can learn something about the event IDs through /tvlib/tcl/tv/Inc.tcl . If you scroll far enough through that file, you'll see these lines:

 namespace eval TmkEvent {     # message enums taken directly from mom/event.h     variable EVT_PAUSE                    0     variable EVT_RESET                    1     variable EVT_SHUTDOWN                 2     variable EVT_EOD                      3     variable EVT_RESOURCE_UNAVAILABLE     4     variable EVT_SHUTDOWN_COMPLETE        5     variable EVT_READY                    6     variable EVT_SET_POSITION             7     variable EVT_SET_POSITION_RESULT      8     variable EVT_OSD                      9     variable EVT_RELEASE_RUN              10     variable EVT_TRICKPLAY                11     variable EVT_FLUSH                    12 ... 

These are all constant names assigned to the different event types. Unfortunately, none of this information is documented anywhere . To deduce anything, we'll have to see these events in action.

The Code

This script registers itself with the event switcher to receive a callback for events through 74 listed in Inc.tcl . When it gets the call, it prints the event type it received, as well as all the data that came along with it.

 #!/tvbin/tivosh proc event_callback { type subtype } {   global EventData     binary scan $EventData I* idata   puts "[format "%02d" $type] [format "%02d" $subtype] : $idata" }    for {set x 0} {$x <= 74} {incr x} {       event register $x event_callback  } set StillWaiting 1  vwait StillWaiting 

Save the code as events.tcl in your TiVo's /var/hack/bin directory, and make it executable:

 bash-2.02#  chmod 755 /var/hack/bin/events.tcl  

Running the Hack

Run the script from TiVo's command line Section 3.3. You might not see anything at first. To give TiVo an event to react to, hit the figs/tivomono.gif button. While the details are sure to be different, you should see something like this:

 bash-2.02#  /var/hack/bin/events.tcl  28 01 : 5 1 1 1 245946781 1373220824 

The second line represents the event sent out when the figs/tivomono.gif button is pressed: 28 is the event type, 01 is the event subtype, and everything thereafter is additional data. Inc.tcl says that event 28 maps to EVT_REMOTEEVENT , probably referring to a remote control event. If, instead, you press the 1 button on your remote, you'll see something like this:

 28 01 : 17 1 1 1 245946833 -889979864 

Again, you capture an event of type 28 , subtype 01 . We can deduce that the subtype doesn't detail which key is pressed. Perhaps that information is in the data field? Let's see what happens when you press the 2 button instead:

 28 01 :  18  1 1 1 245946847 395401288 

Notice the change in the number after the colon ; the 1 button generated a 17 , while the 2 button generated an 18 . As you work your way up the number scale on your remote, you'll see that data number increasing as you go.

And events spawn other events; you'll see other events as you go poking about pressing buttons on the remote control. The figs/tivomono.gif button, for instance, is probably going to cause one of the subsystems to send out another event telling whatever controls TiVo's menu and display systems to show the TiVo Central menu on your television screen.

So, now that we've captured an event, let's see what can we do with it [Hack #99].


   
Top


Tivo Hacks. 100 Industrial-strength Tips Tools 2003
Tivo Hacks. 100 Industrial-strength Tips Tools 2003
ISBN: 1597490318
EAN: N/A
Year: 2004
Pages: 164

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net