OSDN Git Service

Changes to be committed:
[vem/WITs.git] / tsurutafile / cgi-bin / vemclient.rb~
diff --git a/tsurutafile/cgi-bin/vemclient.rb~ b/tsurutafile/cgi-bin/vemclient.rb~
new file mode 100755 (executable)
index 0000000..fbc3533
--- /dev/null
@@ -0,0 +1,132 @@
+#!/usr/local/bin/ruby
+
+require "cgi"
+require "socket"
+require "./cgi-bin/settem"
+require "./cgi-bin/activetem"
+require "rubygems"
+require "systemu"
+require "json"
+
+cgi = CGI.new
+
+command = cgi['command']
+command = CGI.unescapeHTML(command)
+
+parameter = cgi['parameter']
+parameter = CGI.unescapeHTML(parameter)
+
+
+case command
+
+when "Connect" then
+  temset = SetTem.new(parameter)
+  result = temset.connect
+
+when "StageSet", "MagnificationSet", "ImageShift" then
+  socket = TCPSocket.open($activehost,$activeport)
+  socket.puts parameter
+
+  
+  result = socket.gets.chomp
+  if result == "Accepted!" then
+    tiff2gif = "source Eos/env/Eos_env;tiff2mrc -i images/download.tif -o images/download.mrc;mrc2gif -i images/download.mrc -o images/download.gif"
+    systemu tiff2gif
+  end
+  result = "<img src = 'images/download.gif' height=200 width=400><br>"
+
+
+#when something then
+  #do_something
+  #
+  #
+when "Control" then
+  socket = TCPSocket.open($activehost,$activeport)
+  control={"Command"=>"Connect","Parameter"=>parameter}
+  controlj=control.to_json
+  socket.puts controlj
+  puts controlj
+  result = socket.gets
+  
+  
+when "detailcatch" then
+
+  socket = TCPSocket.open($activehost,$activeport)
+     
+  movex=cgi['x']
+  movex=CGI.unescapeHTML(movex)
+  movey=cgi['y'] 
+  movey=CGI.unescapeHTML(movey)
+  movez=cgi['z'] 
+  movez=CGI.unescapeHTML(movez)
+  tilta=cgi['a'] 
+  tilta=CGI.unescapeHTML(tilta)
+
+  position={"Command"=>"Control","Parameter"=>"StagesetA","GonionXA"=>movex.to_i,"GonionYA"=>movey.to_i,"GonionZA"=>movez.to_i,"GonionAA"=>tilta.to_i}
+
+=begin .to_json not use!
+  socket.puts "{'Command':'Control','Parameter':'StargesetA','GonionX':"+movex.to_s+",'GonionY':"+movey.to_s+",'GonionZ':"+movez.to_s+",'GonionA':"+tilta.to_s+"}"
+  puts "{'Command':'Control','Parameter':'StargesetA','GonionX':"+movex.to_s+",'GonionY':"+movey.to_s+",'GonionZ':"+movez.to_s+",'GonionA':"+tilta.to_s+"}"
+=end
+
+  positionj=position.to_json
+  socket.puts   positionj
+  puts positionj
+
+  result = "move x ="+movex.to_s+" move y ="+movey.to_s+" move z ="+movez.to_s+" tilt a ="+tilta.to_s+"<br>"
+
+when "request" then
+ socket = TCPSocket.open($activehost,$activeport)
+ request = {"Command"=>"Request"}
+ requestj = request.to_json
+ puts requestj
+ socket.puts requestj
+ result = socket.gets 
+ puts result
+  
+
+when "TakePhoto" then
+  filename = parameter.split(":")
+  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"
+  systemu tiff2gif
+
+  result = "<img src = 'images/#{filename[1]}.gif' height=400 width=400><br>"
+
+when "Brightnessset" then
+   
+   socket = TCPSocket.open($activehost,$activeport)
+   Bv=cgi['catchvalue']
+   Bv=CGI.unescapeHTML(Bv)
+   
+   brightinfo={"Command"=>"Control","Parameter"=>"Brightnessset","Brightvalue"=>Bv.to_i}
+   
+   brightinfoj=brightinfo.to_json
+   socket.puts brightinfoj
+   puts brightinfoj  
+   result = "Brightness: "+Bv.to_s
+
+when "Voltageset" then
+
+   socket = TCPSocket.open($activehost,$activeport)
+   Voltagevalue=cgi['catchvalue']
+   Voltagevalue=CGI.unescapeHTML(Voltagevalue)
+   
+   voltageinfo={"Command"=>"Control","Parameter"=>"Voltageset","Voltagevalue"=>Voltagevalue.to_i}
+   
+   voltageinfoj=voltageinfo.to_json
+   socket.puts voltageinfoj
+   puts voltageinfoj
+   
+   result = "Volatege : "+Voltagevalue.to_s+"<br>"
+
+else
+  #do_something_other
+end
+
+
+#return ajax-engine::create HTML code
+puts "Content-type: text/html\n\n"
+puts ""
+
+puts result