# Copyright (c) 2001 Courtney Bailey Court_Bailey@bigfoot.com # Phone Connection for TivoWeb # development Status: # V .1a - Added Daily Call # V .3a - Inital Event Capture # V .5a - Revised Event Capture # V .7a - JavaScript # V .9b - First Beta # V 1.4b - lots of headaches later we have a poor man's server push # V 1.5.2F - Cleaned code, made "Guide Data TO" more fault tolerrant # V 1.5.5F - Completly change how we get "Guide data to:" again =P # V 1.5.6F - Add Assoc Array for Data, and decreased reload time # V 1.6 - Make the TmkEvent calls conditional on software version # # $Id: phone.itcl,v 1.2 2005/08/03 06:02:46 davidlallen Exp $ if {$::version > 4} {continue} # ---------Debuging function # Prints Event Data to console when enabled, surf to "http://tivo/Pbug" to toggle proc action_Pbug {chan path env} { global PHInfo if { $PHInfo(Debug_mode) == 0 } { set PHInfo(Debug_mode) 1 } else { set PHInfo(Debug_mode) 0 } action_Phone $chan $path $env } # --------- End Debug function #config variables and Constants need for Calls catch {source $tcl_library/tv/StatusStrings.itcl} # --------- config/Start Event Capture for Dialup Events # Our Callback function borrowed from screenTestsFramework proc DialupCallback { type subtype } { global EventData PHInfo switch -exact -- $subtype { 0 { set info "IMMEDIATE"; set PHInfo(CallInProgress) 1; set PHInfo(Data) [PHGetMessage 4]; set PHInfo(Stat) 4} 1 { set info "config" } 2 { set info "HEADEND" } 3 { set info "TEST"; set PHInfo(CallInProgress) 1; set PHInfo(Data) [PHGetMessage 4]; set PHInfo(Stat) 4} 4 { set info "TESTSTRING" } 5 { set info "ALLHEADENDS" } 6 { set info "FORCE" } 7 { set info "SUCCEED"; set PHInfo(CallInProgress) 0; set PHInfo(Stat) $PHInfo(Stat)} 8 { set info "FAIL"; set PHInfo(CallInProgress) 0; set PHInfo(Stat) $PHInfo(Stat) } 9 { set info "CHANGE"; set PHInfo(CallInProgress) 1 } 10 { set info "ONLINE" } 11 { set info "OFFLINE" } default { set info "XXX" } } binary scan $EventData c20 bytes set data "EventData: $bytes" set PHInfo(Debug) $data if { $info == "CHANGE" } { regsub "\000.*\$" $EventData {} data append info " $data" regsub -nocase {[a-z][a-z][\|]} $data {} PHInfo(Stat) if { $PHInfo(Stat) == 30 } { #give those good people not using modems their LED back if {$::version < 6} { event send $TmkEvent::EVT_DIALUPEVENT 10 0 } } if { [regexp {%} $PHInfo(Stat)] } { set PHInfo(Data) "Loading Data... $PHInfo(Stat)" set PHInfo(Stat) 42 } else { set PHInfo(Data) [PHGetMessage $PHInfo(Stat)] } } append PHInfo(Debug) " $info" if { $PHInfo(Debug_mode) == 1 } { puts "Phone.itcl: $PHInfo(Debug)" } } # Start Capture of Dialup Events event connect # # The registration of a callback can help trigger the v3.0 Event Bug # So let's only do it if the user actually tries to use the module. # if {$reload == 0} { set phone_callback 0 } proc setup_CallBack {} { global phone_callback if {$::version < 6 && $phone_callback == 0} { set phone_callback 1 event register $TmkEvent::EVT_DIALUPEVENT DialupCallback } } # --------- End Event Capture # --------- Phone Body # Daily Call proc action_Dcall {chan path env} { global PHInfo setup_CallBack if { $PHInfo(CallInProgress) == 0 } { set PHInfo(CallInProgress) 1 set PHInfo(Data) [PHGetMessage 4] set PHInfo(Stat) 4 set Daily [binary format c20 "127 -60 126 100 127 -1 -15 -80 1 -78 92 -56 127 -18 -5 116 127 -75 -91 -8"] if {$::version < 6} { event send $TmkEvent::EVT_DIALUPEVENT 0 $Daily } } action_Phone $chan $path $env } # Test Call proc action_Tcall {chan path env} { global PHInfo setup_CallBack if { $PHInfo(CallInProgress) == 0 } { set PHInfo(CallInProgress) 1 set PHInfo(Data) [PHGetMessage 4] set PHInfo(Stat) 4 set Test [binary format c20 "127 -65 98 28 127 -1 -17 -80 0 0 0 0 127 -1 -16 56 127 -76 42 40"] if {$::version < 6} { event send $TmkEvent::EVT_DIALUPEVENT 3 $Test } } action_Phone $chan $path $env } proc action_Phone {chan path env} { global PHInfo action_Phone_UI $chan $path $env if { $PHInfo(CallInProgress) == 1 } { catch {flush $chan} vwait PHInfo(Stat) puts $chan "" } } # User Interface proc action_Phone_UI {chan path env} { puts $chan [html_start "Phone"] global tivoswversion global PHInfo global phone_callback PHUpdateData if {$::lang == "en"} { set seconds [expr $PHInfo(GuideDataTo) * 86400] set daystr [nth [clock format $seconds -format "%e"]] set CD_gdt [clock format $seconds -format "%A, $daystr %b %Y"] set seconds [expr $PHInfo(LastSuccessCall)] set daystr [nth [ftime $seconds "%e"]] set CD_lsc [ftime $seconds "%A, $daystr %b at %H:%M"] set seconds [expr $PHInfo(LastCallAttempt)] set daystr [nth [ftime $seconds "%e"]] set CD_lca [ftime $seconds "%A, $daystr %b at %H:%M"] set seconds [expr $PHInfo(NextCallAttempt)] set daystr [nth [ftime $seconds "%e"]] set CD_nsc [ftime $seconds "%A, $daystr %b at %H:%M"] } else { set CD_gdt [clock format [expr $PHInfo(GuideDataTo) * 86400] -format "%A, %b %d, %Y"] set CD_lsc [ftime [expr $PHInfo(LastSuccessCall)] "%A, %b %d at %1I:%M %P"] set CD_lca [ftime [expr $PHInfo(LastCallAttempt)] "%A, %b %d at %1I:%M %P"] set CD_nsc [ftime [expr $PHInfo(NextCallAttempt)] "%A, %b %d at %1I:%M %P"] } set CD_las $PHInfo(LastCallStatus) puts $chan "