OSDN Git Service

replaced all files
[vem/WITs.git] / tsurutafile / cgi-bin / vemclient.rb
1 #!/usr/bin/ruby
2
3 require "cgi"
4 require "socket"
5 require "./cgi-bin/settem"
6 require "./cgi-bin/activetem"
7 require "rubygems"
8 require "systemu"
9 require "json"
10
11 cgi = CGI.new
12
13 command = cgi['command']
14 command = CGI.unescapeHTML(command)
15
16 parameter = cgi['parameter']
17 parameter = CGI.unescapeHTML(parameter)
18
19
20 case command
21
22 when "Connect" then
23         temset = SetTem.new(parameter)
24         result = temset.connect
25
26 when "StageSet", "MagnificationSet", "ImageShift" then
27         socket = TCPSocket.open($activehost,$activeport)
28         socket.puts parameter
29
30
31         result = socket.gets.chomp
32         if result == "Accepted!" then
33                 tiff2gif = "source Eos/env/Eos_env;tiff2mrc -i images/download.tif -o images/download.mrc;mrc2gif -i images/download.mrc -o images/download.gif"
34                 systemu tiff2gif
35         end
36         result = "<img src = 'images/download.gif' height=200 width=400><br>"
37
38
39 #when something then
40         #do_something
41         #
42         #
43 when "Control" then
44         socket = TCPSocket.open($activehost,$activeport)
45
46         control={"Command"=>"Connect","Parameter"=>parameter}
47         controlj=control.to_json
48         socket.puts controlj
49         puts controlj
50         result = socket.gets
51
52
53 when "detailcatch" then
54
55         socket = TCPSocket.open($activehost,$activeport)
56
57         movex=cgi['x']
58         movex=CGI.unescapeHTML(movex)
59         movey=cgi['y']
60         movey=CGI.unescapeHTML(movey)
61         movez=cgi['z']
62         movez=CGI.unescapeHTML(movez)
63         tilta=cgi['a']
64         tilta=CGI.unescapeHTML(tilta)
65
66         position={"Command"=>"Control","Parameter"=>"StagesetA","GonionXA"=>movex.to_i,"GonionYA"=>movey.to_i,"GonionZA"=>movez.to_i,"GonionAA"=>tilta.to_i}
67
68 =begin .to_json not use!
69         socket.puts "{'Command':'Control','Parameter':'StargesetA','GonionX':"+movex.to_s+",'GonionY':"+movey.to_s+",'GonionZ':"+movez.to_s+",'GonionA':"+tilta.to_s+"}"
70         puts "{'Command':'Control','Parameter':'StargesetA','GonionX':"+movex.to_s+",'GonionY':"+movey.to_s+",'GonionZ':"+movez.to_s+",'GonionA':"+tilta.to_s+"}"
71 =end
72
73         positionj=position.to_json
74         socket.puts   positionj
75         puts positionj
76
77         result = socket.gets
78
79         result = "move x ="+movex.to_s+" move y ="+movey.to_s+" move z ="+movez.to_s+" tilt a ="+tilta.to_s+"<br>"
80
81 when "request" then
82  socket = TCPSocket.open($activehost,$activeport)
83  request = {"Command"=>"Request"}
84  requestj = request.to_json
85  socket.puts requestj
86  result = socket.gets
87
88 =begin
89         currentcondition=socket.gets
90  currentcondition = JSON.parse(currentcondition)
91 =end
92
93 when "TakePhoto" then
94         filename = parameter.split(":")
95         tiff2gif = "source Eos/env/Eos_env;tiff2mrc -i images/#{filename[0]}.tif -o images/#{filename[0]}.mrc;mrc2gif -i images/#{filename[0]}.mrc -o images/#{filename[1]}.gif"
96         systemu tiff2gif
97
98         result = "<img src = 'images/#{filename[1]}.gif' height=400 width=400><br>"
99
100 when "Brightnessset" then
101
102          socket = TCPSocket.open($activehost,$activeport)
103          Bv=cgi['catchvalue']
104          Bv=CGI.unescapeHTML(Bv)
105
106          brightinfo={"Command"=>"Control","Parameter"=>"Brightnessset","Brightvalue"=>Bv.to_i}
107
108          brightinfoj=brightinfo.to_json
109          socket.puts brightinfoj
110          puts brightinfoj
111          result = "Brightness: "+Bv.to_s
112
113 when "Voltageset" then
114
115          socket = TCPSocket.open($activehost,$activeport)
116          Voltagevalue=cgi['catchvalue']
117          Voltagevalue=CGI.unescapeHTML(Voltagevalue)
118
119          voltageinfo={"Command"=>"Control","Parameter"=>"Voltageset","Voltagevalue"=>Voltagevalue.to_i}
120
121          voltageinfoj=voltageinfo.to_json
122          socket.puts voltageinfoj
123          puts voltageinfoj
124
125          result = "Volatege : "+Voltagevalue.to_s+"<br>"
126
127 when "EucentricHeight" then
128          socket = TCPSocket.open($activehost,$activeport)
129          max=cgi['max']
130          max=CGI.unescapeHTML(max)
131          speed=cgi['speed']
132          speed=CGI.unescapeHTML(speed)
133          place=cgi['place']
134          place=CGI.unescapeHTML(place)
135
136         currentcondition={"ap"=>0}
137         currentcondition["ap"]=currentcondition["ap"].to_i+place.to_i
138
139         eucentricheightinfo={"Command"=>"Control","Parameter"=>"EucentricHeight","max"=>max.to_i,"speed"=>speed.to_i,"place"=>currentcondition["ap"].to_i}
140
141         eucentricheightinfoj=eucentricheightinfo.to_json
142         socket.puts eucentricheightinfoj
143         puts eucentricheightinfoj
144
145         result = eucentricheightinfoj
146
147 else
148         #do_something_other
149 end
150
151
152 #return ajax-engine::create HTML code
153 puts "Content-type: text/html\n\n"
154 puts ""
155
156 puts result