📄 watchdog.tcl
字号:
# {{{ Banner # ============================================================================# # watchdog.tcl# # Watchdog support for the eCos synthetic target I/O auxiliary# # ============================================================================# ####COPYRIGHTBEGIN##### # ----------------------------------------------------------------------------# Copyright (C) 2002 Bart Veer# # This file is part of the eCos host tools.# # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version.# # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details.# # You should have received a copy of the GNU General Public License along with# this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.# # ----------------------------------------------------------------------------# # ####COPYRIGHTEND##### ============================================================================# #####DESCRIPTIONBEGIN##### # Author(s): bartv# Contact(s): bartv# Date: 2002/09/04# Version: 0.01# Description:# Implementation of the watchdog device. This script should only ever# be run from inside the ecosynth auxiliary.# # ####DESCRIPTIONEND##### ============================================================================# }}}namespace eval watchdog { # Was initialization successful? variable init_ok 1 # Has the alarm triggered? variable alarm_triggered 0 # The eCos application process id. This is needed to send a SIGPWR signal # if the watchdog triggers, and to access /proc/<pid>/stat to obtain # timing information. Strictly speaking _ppid is not exported by # the I/O auxiliary. if { ! [info exists synth::_ppid] } { synth::report_error "Watchdog initialization failed, _ppid variable required" return "" } variable ecos_pid $synth::_ppid # Resolution, i.e. how long to go between checks. Currently this is hard-wired # to one second, or 1000 ms. This may become configurable, either on the # target-side via CDL or on the host-side via the target definition file. # Note that currently the watchdog device and the GUI get updated via the # same timer. If the resolution is changed to e.g. 10 seconds then it might # be a good idea to update the GUI more frequently, although there are # arguments for keeping the animation in step with the real work. variable resolution 1000 # Options from the target definition file variable use_wallclock 0 variable window_pack "-in .main.n -side right" variable sound_file "" variable sound_player "play" if { [synth::tdf_has_device "watchdog"] } { if { [synth::tdf_has_option "watchdog" "use"] } { set _use [synth::tdf_get_option "watchdog" "use"] if { "wallclock_time" == $_use } { set watchdog::use_wallclock 1 } elseif { "consumed_cpu_time" == $_use } { set watchdog::use_wallclock 0 } else { synth::report_error "Invalid entry in target definition file $synth::target_definition\n\ \ Device watchdog, option \"use\" should be \"wallclock_time\" or \"consumed_cpu_time\"\n" } unset _use } if { [synth::tdf_has_option "watchdog" "watchdog_pack"] } { set watchdog::window_pack [synth::tdf_get_option "watchdog" "watchdog_pack"] # Too complicated to validate here, instead leave it to a catch statement # when the window actually gets packed } if { [synth::tdf_has_option "watchdog" "sound"] } { set _sound_file [synth::tdf_get_option "watchdog" "sound"] # Look for this sound file in the install tree first, then absolute or relative if { [file exists [file join $synth::device_install_dir $_sound_file] ] } { set _sound_file [file join $synth::device_install_dir $_sound_file] } if { ![file exists $_sound_file] } { synth::report_error "Invalid entry in target definition file $synth::target_definition\n\ \ Device watchdog, option \"sound\", failed to find $_sound_file\n" } elseif { ! [file readable $_sound_file] } { synth::report_error "Invalid entry in target definition file $synth::target_definition\n\ \ Device watchdog, option \"sound\", no read access to file $_sound_file\n" } else { set watchdog::sound_file $_sound_file } unset _sound_file } if { [synth::tdf_has_option "watchdog" "sound_player"] } { set watchdog::sound_player [synth::tdf_get_option "watchdog" "sound_player"] } } # There is no point in creating the watchdog window if any of the image files are missing if { $synth::flag_gui } { foreach _image [list "doghouse.gif" "alarm.gif" "eye.gif" "asleep.gif"] { variable image_[file rootname $_image] if { ! [synth::load_image "watchdog::image_[file rootname $_image]" [file join $synth::device_install_dir $_image]] } { synth::report_error "Watchdog device, unable to load image $_image\n\ \ This file should have been installed in $synth::device_install_dir\n" set watchdog::init_ok 0 } } } if { $synth::flag_gui && $watchdog::init_ok } { canvas .watchdog -width [image width $image_doghouse] -height [image height $image_doghouse] \ -borderwidth 0 variable background [.watchdog create image 0 0 -anchor nw -image $image_doghouse] # Eye positions inside the doghouse. The eye is an 8x10 gif, # mostly white but transparent around the corners variable left_eye_x 48 variable left_eye_y 70 variable right_eye_x 58 variable right_eye_y 70 # Pupil positions relative to the eye. The pupils are 3x3 rectangles. # The dog can look in one of nine different directions, with both eyes # looking in the same direction (if visible) variable pupil_positions { { 1 6 } { 1 5 } { 1 3 } { 3 1 } { 3 4 } { 3 6 } { 4 3 } { 4 5 } { 4 6 } } # Which eyes are currently visible: none, left, right or both variable eyes "none" # What is the current pupil position? variable pupils 4 variable left_eye [.watchdog create image $left_eye_x $left_eye_y -anchor nw -image $image_eye] variable right_eye [.watchdog create image $right_eye_x $right_eye_y -anchor nw -image $image_eye] variable left_pupil \ [.watchdog create rectangle \ [expr $left_eye_x + [lindex [lindex $pupil_positions $pupils] 0]] \ [expr $left_eye_y + [lindex [lindex $pupil_positions $pupils] 1]] \ [expr $left_eye_x + [lindex [lindex $pupil_positions $pupils] 0] + 2] \ [expr $left_eye_y + [lindex [lindex $pupil_positions $pupils] 1] + 2] \ -fill black] variable right_pupil \ [.watchdog create rectangle \ [expr $right_eye_x + [lindex [lindex $pupil_positions $pupils] 0]] \ [expr $right_eye_y + [lindex [lindex $pupil_positions $pupils] 1]] \ [expr $right_eye_x + [lindex [lindex $pupil_positions $pupils] 0] + 2] \ [expr $right_eye_y + [lindex [lindex $pupil_positions $pupils] 1] + 2] \ -fill black] # The dog is asleep until the eCos application activates the watchdog device .watchdog lower $left_eye $background .watchdog lower $right_eye $background .watchdog lower $left_pupil $background .watchdog lower $right_pupil $background # Prepare for an alarm, but obviously the alarm picture should be hidden for now. variable alarm [.watchdog create image 30 56 -anchor nw -image $image_alarm] .watchdog lower $alarm $background # Start asleep variable asleep [.watchdog create image 48 70 -anchor nw -image $image_asleep] # Now try to pack the watchdog window using the option provided by the # user. If that fails, report the error and pack in a default window. if { [catch { eval pack .watchdog $watchdog::window_pack } message] } { synth::report_error "Watchdog device, failed to pack window in $watchdog::window_pack\n $message" pack .watchdog -in .main.n -side right } # Updating the display. This happens once a second. # If neither eye is visible, choose randomly between # left-only, right-only or both. Otherwise there is # a one in eight chance of blinking, probably switching # to one of the other eye modes # # Also, the visible pupil(s) will move every second, to one # of nine positions proc gui_update { } { if { "none" == $watchdog::eyes} { set rand [expr int(3 * rand())] if { 0 == $rand } { set watchdog::eyes "left" .watchdog raise $watchdog::left_eye $watchdog::background .watchdog raise $watchdog::left_pupil $watchdog::left_eye } elseif { 1 == $rand } { set watchdog::eyes "right" .watchdog raise $watchdog::right_eye $watchdog::background
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -