# 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 # # $Id: phone.itcl,v 1.7.2.4 2002/12/14 03:04:03 lightn Exp $ # ---------HTML Add-on # Html Link with mouse over, really unessecary but seeing JavaScript in the status window has always annoyed me proc html_link_mouse {link anchor} { return "$anchor" } # ---------End HTML Add-on # ---------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) [lindex $PHInfo(Messages) 4]; set PHInfo(Stat) 4} 1 { set info "config" } 2 { set info "HEADEND" } 3 { set info "TEST"; set PHInfo(CallInProgress) 1; set PHInfo(Data) [lindex $PHInfo(Messages) 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 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) [lindex $PHInfo(Messages) $PHInfo(Stat)] } } append PHInfo(Debug) " $info" if { $PHInfo(Debug_mode) == 1 } { puts "Phone.itcl: $PHInfo(Debug)" } } # Start Capture of Dialup Events event connect event register $TmkEvent::EVT_DIALUPEVENT DialupCallback # --------- End Event Capture # --------- Phone Body # Daily Call proc action_Dcall {chan path env} { global PHInfo if { $PHInfo(CallInProgress) == 0 } { set PHInfo(CallInProgress) 1 set PHInfo(Data) [lindex $PHInfo(Messages) 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"] event send $TmkEvent::EVT_DIALUPEVENT 0 $Daily } action_Phone $chan $path $env } # Test Call proc action_Tcall {chan path env} { global PHInfo if { $PHInfo(CallInProgress) == 0 } { set PHInfo(CallInProgress) 1 set PHInfo(Data) [lindex $PHInfo(Messages) 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"] 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 tzoffset global PHInfo PHUpdateData if {$::uktivo} { 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) + $tzoffset] set daystr [nth [clock format $seconds -format "%e"]] set CD_lsc [clock format $seconds -format "%A $daystr %b at %H:%M"] set seconds [expr $PHInfo(LastCallAttempt) + $tzoffset] set daystr [nth [clock format $seconds -format "%e"]] set CD_lca [clock format $seconds -format "%A $daystr %b at %H:%M"] set seconds [expr $PHInfo(NextCallAttempt) + $tzoffset] set daystr [nth [clock format $seconds -format "%e"]] set CD_nsc [clock format $seconds -format "%A $daystr %b at %H:%M"] } else { set CD_gdt [clock format [expr $PHInfo(GuideDataTo) * 86400] -format "%A, %b %d, %Y"] set CD_lsc [clock format [expr $PHInfo(LastSuccessCall) + $tzoffset] -format "%A, %b %d at %1I:%M %P"] set CD_lca [clock format [expr $PHInfo(LastCallAttempt) + $tzoffset] -format "%A, %b %d at %1I:%M %P"] set CD_nsc [clock format [expr $PHInfo(NextCallAttempt) + $tzoffset] -format "%A, %b %d at %1I:%M %P"] } set CD_las $PHInfo(LastCallStatus) puts $chan "