-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathf9wfs_gui
More file actions
executable file
·325 lines (278 loc) · 7.73 KB
/
f9wfs_gui
File metadata and controls
executable file
·325 lines (278 loc) · 7.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/usr/bin/ruby
# This runs the f9 WFS GUI (to take manual exposures)
# It also launches the catalog GUI
#
# tjt 2-25-2011 made changes
# inspects WFSROOT variable and sets the path variable internally
# inspects WFSDEBUG environment variable and takes actions.
#
# As of ruby 1.9 (and Fedora 17), the soap package is no
# longer available as an RPM via yum, you must do:
# gem install soap4r-ruby1.9 8-3-2012
require 'libglade2'
require 'thread'
# As of Ruby 1.9 this package spits out:
# iconv will be deprecated in the future, use String#encode instead.
# so we suppress this warning while we wait for an upstream fix.
save_verbose=$VERBOSE; $VERBOSE=nil
#In summer 2015, we changed the way calls to the
#F9 topbox were done to remove the need for soap.
#require 'soap/rpc/driver'
$VERBOSE=save_verbose
#Define the new lampserver class
class LampServerClient
def initialize
require 'resolv'
srvname = "lampbox"
dns = Resolv::DNS.open
resource = dns.getresource("_#{srvname}._tcp.mmto.arizona.edu", Resolv::DNS::Resource::IN::SRV)
@host = resource.target.to_s
@port = resource.port.to_s
@timeout = 120
end
# returns "0" for success, "1" for timeout, or "X" for problem
# Argument: "mirror" = "in" or "out"
def set_mirror_exclusive(mirror)
reply = "X"
service = nil
begin
Timeout::timeout(@timeout) do
service = TCPSocket.open(@host, @port.to_i)
service.puts("set_mirror_exclusive #{mirror.strip}")
reply = service.gets()
reply = reply.chomp if reply
end
ensure
service.close if service
end
return reply
end
# returns "OUT", "IN", or "BUSY", or "X" or message for problem
def get_mirror
reply = "X"
service = nil
begin
Timeout::timeout(@timeout) do
service = TCPSocket.open(@host, @port.to_i)
service.puts("get_mirror")
reply = service.gets()
reply = reply.chomp if reply
end
ensure
service.close if service
end
return reply
end
end
### define the main GUI window
class MainWindow
def initialize(inst,root,debug)
@inst = inst
@path = root
@dir = @path + "/datadir"
@debug = debug
require @path + "/wfscat.rb"
@glade = GladeXML.new("#{@path}/glade/f9wfs_gui.glade") {|handler| method(handler)}
@mirror_text = @glade.get_widget("CompStatus")
@mirror_button = @glade.get_widget("CompMirror")
#These were the original SOAP calls, need to replace them
# @lampserver = SOAP::RPC::Driver.new("http://hacksaw.mmto.arizona.edu:7851", "urn:Lamp")
# @lampserver.options["protocol.http.receive_timeout"] = 120
# @lampserver.add_method("set_mirror_exclusive", "mirror")
# @lampserver.add_method("get_mirror")
# @lampserver.add_method("wait_mirror")
@lampserver = LampServerClient.new
get_mirror
Thread.new {
while @lampserver
get_mirror
sleep(5)
end
}
@mainwindow = @glade.get_widget("MainWindow")
@mainwindow.set_title("F/9 WFS Interface for #{@inst}")
@status = @glade.get_widget("StatusBar")
@menubar = @glade.get_widget("menubar1")
unless @debug
@catalog = WFSCat.new(self)
end
@automirror = true
# exposure configuration
@expose = @glade.get_widget("Expose")
@nexp = @glade.get_widget("NExp")
@exptime = @glade.get_widget("ExpTime")
@fileentry = @glade.get_widget("FileEntry")
end
# get mirror status and display it
def get_mirror
status = @lampserver.get_mirror
if !status || status =~ /X/
status = "UNKNOWN"
end
@mirror_text.set_markup("is: <b>#{status}</b>")
if status =~ /IN/
@on_axis = true
else
@on_axis = false
end
@mirror_stat = status
end
# are we on axis?
def on_axis?
return @on_axis
end
# kill the main window on a destroy
def on_MainWindow_destroy
Gtk.main_quit
end
# bring up catalog window
def on_wfs_catalog1_activate
unless @catalog
@catalog = WFSCat.new(self)
end
end
# clean up catalog pointer
def killcat
@catalog = nil
end
# handle toggling of comp mirror control
def on_CompToggle_toggled
if @automirror
@automirror = false
report("Automatic Comp Mirror control disabled.")
else
@automirror = true
report("Automatic Comp Mirror control enabled.")
end
end
# handle comp mirror click
def on_CompMirror_clicked
get_mirror
if @mirror_stat =~ /IN/
Thread.new {
move_mirror("out")
}
end
if @mirror_stat =~ /OUT/
Thread.new {
move_mirror("in")
}
end
end
def move_mirror(dir)
report("Moving Comp Mirror....")
@mirror_button.set_sensitive(false)
@mirror_stat = "BUSY"
@mirror_text.set_markup("is: <b>#{@mirror_stat}</b>")
@lampserver.set_mirror_exclusive(dir)
get_mirror
@mirror_button.set_sensitive(true)
report("Move completed.")
end
# handle call to put comp mirror on axis
def on_OnAxis_clicked
if @automirror
get_mirror
if @mirror_stat =~ /OUT/
Thread.new {
move_mirror("in")
}
end
else
return
end
end
# handle call to stow comp mirror
def on_StowWFS_clicked
if @automirror
get_mirror
if @mirror_stat =~ /IN/
Thread.new {
move_mirror("out")
}
end
else
return
end
end
# routine to print to statusbar
def report(text)
@status.pop(0)
@status.push(0, text)
end
# menubar callbacks
def on_quit_activate
Gtk.main_quit
end
def on_about1_activate
report("First cut at a remote f/9 WFS interface")
end
# configure and take exposure
def on_Expose_clicked
nexp = @nexp.value_as_int
exptime = @exptime.value.to_f
file = @fileentry.text
t = Thread.new {
@expose.set_sensitive(false)
n = 1
nexp.times {
# figure out the filename
if file == "test"
fullfilename = "#{@dir}/#{file}.fits"
filename = "#{file}.fits"
system("rm -f #{@path}/datadir/#{filename}")
else
num = 0
fullfilename = sprintf("%s/%s_%04d.fits", @dir, file, num)
filename = sprintf("%s_%04d.fits", file, num)
# while test(?e, fullfilename)
while test(?e, "#{@path}/datadir/#{filename}")
num = num + 1
fullfilename = sprintf("%s/%s_%04d.fits", @dir, file, num)
filename = sprintf("%s_%04d.fits", file, num)
end
end
if exptime > 1
count = Thread.new {
left = exptime.to_i
left.times {
report("Exposing \##{n} (#{filename})...#{left} sec left.")
sleep(1)
left = left - 1
}
report("Reading out \##{n} (#{filename})....")
}
else
report("Exposing \##{n} (#{filename})....")
end
system("sudo -u mmtop /usr/bin/rsh -n -l tim f9wfs \"/home/tim/get_apogee_image.tcl #{exptime} #{filename} \> /dev/null\"")
system("sudo -u mmtop /usr/bin/rcp tim@f9wfs:/home/tim/#{filename} #{fullfilename}")
system("sudo -u mmtop /usr/bin/rsh -n -l tim f9wfs \"rm -f #{filename} \> /dev/null\"")
system("sudo -u mmtop chmod g+w #{fullfilename}")
system("#{@path}/header.pl #{@path}/datadir/#{filename} #{exptime} F9")
system("/usr/bin/xpaset -p WFS file #{@path}/datadir/#{filename}")
n = n + 1
}
if nexp == 1
report("Completed Exposure.")
else
report("Completed Exposures.")
end
@expose.set_sensitive(true)
}
end
end
# Single command lineargument - F9 or F5 or some such
debug = false
root = "/mmt/shwfs"
if ENV.has_key? 'WFSDEBUG'
debug = true
end
if ENV.has_key? 'WFSROOT'
root = ENV['WFSROOT']
end
# get the ball rolling!
Gtk.init
MainWindow.new(ARGV[0],root,debug)
Gtk.main
# THE END