~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/applications/camera-server/camera-srvr.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # camera-srvr.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  4 #
  5 # Copyright (c) 1996-2002 The Regents of the University of California.
  6 # All rights reserved.
  7 #
  8 # Redistribution and use in source and binary forms, with or without
  9 # modification, are permitted provided that the following conditions are met:
 10 #
 11 # A. Redistributions of source code must retain the above copyright notice,
 12 #    this list of conditions and the following disclaimer.
 13 # B. Redistributions in binary form must reproduce the above copyright notice,
 14 #    this list of conditions and the following disclaimer in the documentation
 15 #    and/or other materials provided with the distribution.
 16 # C. Neither the names of the copyright holders nor the names of its
 17 #    contributors may be used to endorse or promote products derived from this
 18 #    software without specific prior written permission.
 19 #
 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30 #
 31 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/applications/camera-server/camera-srvr.tcl,v 1.17 2002/02/03 04:21:42 lim Exp $
 32 
 33 
 34 import SerialChannel/Camera-Sony-EVID30 SerialChannel/Camera-Canon-VCC1 \
 35                 UDPServer Rendezvous
 36 
 37 # Camera messaging interface -- handles all transmission of state
 38 # announcements of the underlying agent. <p>
 39 #
 40 Class UDPServer/Camera -superclass UDPServer
 41 
 42 # only uses the port num and performs multiple unicasts to
 43 # all known clients <P> FIXME need to time them out; enable mcast
 44 #
 45 UDPServer/Camera public init {addrspec parent {mtu 1500}} {
 46     $self instvar parent_ pending_
 47     set parent_ $parent
 48     set pending_ -1
 49 
 50     eval [list $self] next $addrspec $mtu
 51 }
 52 
 53 # Receive a msg to the Camera Server.
 54 # <br>
 55 # format of received announcement is:
 56 #  "method args ..."
 57 #
 58 UDPServer/Camera private recv {addr port data size} {
 59     #puts "Msg: $addr\[$size\]: $data"
 60 
 61     $self instvar parent_ pending_
 62     set c [$parent_ set cam_]
 63 
 64     set theMethod [lindex $data 0]
 65     set theArgs [lrange $data 1 end]
 66 
 67     if {[lsearch [[$c info class] info instprocs] $theMethod] != -1} {
 68         # disallow list:
 69         if {$theMethod == "init"} {return}
 70         # check number of args
 71         set maxArgs [llength [[$c info class] info instargs $theMethod]]
 72         set reqArgs 0
 73         foreach i [[$c info class] info instargs $theMethod] {
 74                 if {[[$c info class] info instdefault $theMethod $i ""] == 0} {
 75                         incr reqArgs
 76                 }
 77         }
 78         if {[llength $theArgs] < $reqArgs || [llength $theArgs] > $maxArgs} {
 79             puts "Bad arg count to $theMethod"
 80             return
 81         }
 82         # okay, invoke the camera command
 83         #puts -nonewline "invoking: $c $theMethod $theArgs... "
 84         set reply [eval $c $theMethod $theArgs]
 85         # don't return reply; should be subset of full state update
 86 
 87         if {$pending_ != -1} {
 88             after cancel $pending_
 89         }
 90         # wait a bit to coalesce bursts of updates
 91         set pending_ [after 300 $self announce_state]
 92     } else {
 93         if {$theMethod == "update_state"} {
 94             $self announce_state
 95         } else {
 96             puts "msg with method '$theMethod' not found.  ignored."
 97         }
 98     }
 99 }
100 
101 #
102 # a wrapper for sending a complete state update
103 #
104 UDPServer/Camera private announce_state {} {
105     $self instvar parent_ pending_
106 
107     set c [$parent_ set cam_]
108     set tmp "z: [$c set zoomPerc_]"
109     append tmp " t: [$c set tiltPerc_]"
110     append tmp " p: [$c set panPerc_]"
111     append tmp " pre: "
112     foreach i "[$c array names presets_]" {
113         append tmp "$i [$c get_preset $i] "
114     }
115 
116     $self announce "$tmp"
117     after 40 $self announce [list "$tmp"]
118     set pending_ -1
119 }
120 
121 # a UI-less server for controlling local camera(s)
122 #<br>
123 # simple wrapper for accepting remote commands (method invocations)
124 # and passing them on the the underlying camera object
125 #
126 Class CameraServer
127 
128 #
129 # init takes 3 args: addrspec, type of camera (the class has to be
130 # pre-imported), and the device name
131 #
132 CameraServer public init {addrspec {device /dev/cuac00} \
133         {type SerialChannel/Camera-Sony-EVID30}} {
134 
135     $self instvar cam_ al_
136 
137     set al_ [new UDPServer/Camera $addrspec $self]
138     set cam_ [new $type]
139     # hack until -device $dev works in constructor
140     $cam_ close
141     $cam_ device $device
142     $cam_ open
143 }
144 
145 # start advertising cameras on rendezvous channel `rspec' with
146 # `camctrladdr' as addr for controlling camera
147 # (camera name is grabbed from the options)
148 CameraServer public start_rendezvous_ads {rspec camctrladdr} {
149     $self instvar advertiser_
150     set advertiser_ [new Rendezvous $rspec]
151     set camname [$self get_option camname]
152     if ![invalid_addr $camname] {
153         set m "camera: camCtrl:$camctrladdr cname:$camname"
154     } else {
155         set m "camera: camName:$camname camCtrl:$camctrladdr"
156     }
157     puts  "advertising '$m' to $rspec"
158     $advertiser_ start $m
159 
160     set m "will-provide: mash-object=CameraServer ctrlspec=$camctrladdr"
161     set uid [$self get_option uniqid]
162     if {$uid != ""} {set m "$m uniqid=$uid"}
163     $advertiser_ start $m
164 }
165 
166 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.