OSDN Git Service

20140826WITs
[vem/WITs.git] / cgi-bin / vemclient.rb~
1 #!/usr/local/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   socket.puts "Control:#{parameter}"
46   result = socket.gets
47   
48 when "detailcatch" then
49
50   socket = TCPSocket.open($activehost,$activeport)
51      
52   movex=cgi['x']
53   movex=CGI.unescapeHTML(movex)
54   movey=cgi['y'] 
55   movey=CGI.unescapeHTML(movey)
56   movez=cgi['z'] 
57   movez=CGI.unescapeHTML(movez)
58   tilta=cgi['a'] 
59   tilta=CGI.unescapeHTML(tilta)
60
61   position={"Command"=>"Control","Parameter"=>"StargesetA","GonionXA"=>movex.to_i,"GonionYA"=>movey.to_i,"GonionZA"=>movez.to_i,"GonionAA"=>tilta.to_i}
62
63 =begin .to_json not use!
64   socket.puts "{'Command':'Control','Parameter':'StargesetA','GonionX':"+movex.to_s+",'GonionY':"+movey.to_s+",'GonionZ':"+movez.to_s+",'GonionA':"+tilta.to_s+"}"
65   puts "{'Command':'Control','Parameter':'StargesetA','GonionX':"+movex.to_s+",'GonionY':"+movey.to_s+",'GonionZ':"+movez.to_s+",'GonionA':"+tilta.to_s+"}"
66 =end
67
68   positionj=position.to_json
69   socket.puts   positionj
70   puts positionj
71
72   result = "move x ="+movex.to_s+" move y ="+movey.to_s+" move z ="+movez.to_s+" tilt a ="+tilta.to_s+"<br>"
73
74 when "currentcondition" then
75  socket = TCPsocket.open($activehost,$activeport)
76  sosket.puts '{"Command":"Require"}'
77  result = socket.gets 
78   
79
80 when "TakePhoto" then
81   filename = parameter.split(":")
82   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"
83   systemu tiff2gif
84
85   result = "<img src = 'images/#{filename[1]}.gif' height=400 width=400><br>"
86
87 when "Brightnessset" then
88    
89    socket = TCPSocket.open($activehost,$activeport)
90    Bv=cgi['catchvalue']
91    Bv=CGI.unescapeHTML(Bv)
92    
93    brightinfo={"Command"=>"Control","Parameter"=>"Brightnessset","Brightvalue"=>Bv.to_i}
94    
95    brightinfoj=brightinfo.to_json
96    socket.puts brightinfoj
97    puts brightinfoj
98    
99    result = Bv.to_s
100
101 when "Voltageset" then
102
103    socket = TCPSocket.open($activehost,$activeport)
104    Voltagevalue=cgi['catchvalue']
105    Voltagevalue=CGI.unescapeHTML(Voltagevalue)
106    
107    voltageinfo={"Command"=>"Control","Parameter"=>"Voltageset","Voltagevalue"=>Voltagevalue.to_i}
108    
109    voltageinfoj=voltageinfo.to_json
110    socket.puts voltageinfoj
111    puts voltageinfoj
112    
113    result = "Volatege : "+Voltagevalue.to_s+"<br>"
114
115 else
116   #do_something_other
117 end
118
119
120 #return ajax-engine::create HTML code
121 puts "Content-type: text/html\n\n"
122 puts ""
123
124 puts result