]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
Update website power supply control with our 5V switch boards
authorJan Michel <j.michel@gsi.de>
Tue, 29 Nov 2016 17:27:34 +0000 (18:27 +0100)
committerJan Michel <j.michel@gsi.de>
Tue, 29 Nov 2016 17:27:34 +0000 (18:27 +0100)
web/htdocs/tools/pwr/build_index.pl
web/htdocs/tools/pwr/index.html
web/htdocs/tools/pwr/pwr_switch.htm [new file with mode: 0644]
web/htdocs/tools/pwr/pwr_switch.pl [new file with mode: 0755]
web/htdocs/tools/styles.css

index 6b403004a4f7bf21dc7d7c5808e5fd73a5c37336..8c6fa8f23d3bc2295d241c81dbfee8410488b021 100755 (executable)
@@ -44,6 +44,13 @@ print <<EOF;
 EOF
 }
 
+if($type =~ /PWRSW/) {
+print <<EOF;
+<p>
+<iframe name="inlineframe" src="pwr_switch.htm?device=$ser_dev&id=$dev_id&type=$type&channels=$channels&speed=$speed" frameborder="0" scrolling="auto" width="800" height="340" ></iframe>
+</p>
+EOF
+}
 
 
        }
index 729595698f7ef3ab0a477cd0126acbcafd5e22e7..7aee7e758bca0bf794989de9ee5b144f7e90121e 100644 (file)
@@ -29,7 +29,7 @@ Note that you need to have libdevice-serialport-perl or perl-Device-SerialPort<b
 installed and that the /dev/ttyUSBn need to be accessible by normal users.<br>
 Feel free to alter the config file to accommodate your needs!<br>
 Please don't use the # character to comment out lines<br>
-Tested with HMC8043, HMP4040, HMP4030, PSP405, PSP2010, PST3202
+Tested with HMC8043, HMP4040, HMP4030, PSP405, PSP2010, PST3202, PWRSW
 <br><pre>
 //PWRSPLY:/path/to/device:Speed:Name:Type:Channels
 //PWRSPLY:IP0.0.0.0:Port:Name:Type:Channels
@@ -37,7 +37,7 @@ PWRSPLY:/dev/ttyUSB0:9600:PST3202:PST:3
 PWRSPLY:/dev/ttyUSB0:115200:HMP4030:HMP:3
 PWRSPLY:IP192.168.0.56:5050:HMP4040:HMP:4
 PWRSPLY:/dev/FTDI_FT232R_USB_UART_AH02HFZW:2400:PSP2010:PSP:1
-PWRSPLY:/dev/FTDI_FT232R_USB_UART_A702HE33:2400:PSP405:PSP:1</pre>
+PWRSPLY:/dev/FTDI_FT232R_USB_UART_A900LJXB:0:Desk:PWRSW:4</pre>
 <br>
 <TEXTAREA NAME="Address" id="config_field" ROWS=10 COLS=50 >
 Platzhalter
diff --git a/web/htdocs/tools/pwr/pwr_switch.htm b/web/htdocs/tools/pwr/pwr_switch.htm
new file mode 100644 (file)
index 0000000..9ff228d
--- /dev/null
@@ -0,0 +1,149 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+<link href="../styles.css" rel="stylesheet" type="text/css"/>
+<script src="../scripts.js" type="text/javascript"></script>
+<title>Power Supply Monitor and Access</title>
+</head>
+<body style="font-family: sans-serif;" class="powerswitch">
+
+
+<h3 id="headline"></h3>
+
+
+
+<form acion="">
+<table id="settings" class="smallboxes">
+<tr><th>Channel<th colspan='2'>Status<th>Current<th>Average<th>Limit
+
+<tfoot>
+<tr class="sep"><td colspan=5><input type="checkbox" checked="1" id="showreadings">Enable read-back of values<td colspan=4 id="date">
+
+<tr><td colspan=9 id="info">&nbsp;
+</tfoot>
+<tbody id="display"></tbody>
+</table>
+</form>
+
+
+<script language="javascript">
+var updaterate = 2000;
+var updateTask;
+var new_commands = new Array();
+var ser_dev = getParameterByName("device");
+var dev_id = getParameterByName("id");
+var type = getParameterByName("type");
+var channels = getParameterByName("channels");
+var speed = getParameterByName("speed");
+var readSettingsRequest = 1;
+var forceUpdate = 1;
+
+var Vstatus  = new Array();
+var Vcurrent = new Array();
+var Vaverage = new Array();
+var Vlimit   = new Array();
+var Vdate    = "x";
+
+function maketable() {
+  out = "";
+  for(i=0;i<channels;i++) {
+     out += "<tr><td>"+i;
+    if (Vstatus[i] == 1) {
+      out += '<td class="status" style="background:limegreen">&nbsp;';
+      }
+    else {
+      out += '<td class="status" style="background:#C00">&nbsp;';
+      }
+    out += '<td><input type="button" onClick="turn_on('+i+')" value="on">\
+            <input type="button" onClick="turn_off('+i+')" value="off"> ';  
+    out += '<td>'+Vcurrent[i]+'<td>'+Vaverage[i]+
+           '<td><input type="text" id="limit'+i+'" name="limit'+i+'" onChange="set_lim('+i+')" value="'+Vlimit[i]+'">'+"\n";
+    }
+  document.getElementById("display").innerHTML = out;  
+  document.getElementById("date").innerHTML = Vdate;
+  }
+
+  
+function set_lim(chan) {
+  if (chan > channels) return;
+  myi = chan.toString(16);
+  if (chan<16) {myi = '0'+myi;}
+  myv = (document.getElementById('limit'+chan).value*1.).toString(16);
+  if (myv<16) {myv = '00'+myv;}
+  if (myv<256) {myv = '0'+myv;}
+  new_commands.push('L'+myi+myv);
+}  
+
+function turn_on(chan) {
+  if (chan > channels) return;
+  myi = chan.toString(16);
+  if (chan<10) {myi = '0'+myi;}
+  new_commands.push('S'+myi+'1');
+}
+
+function turn_off(chan) {
+  if (chan > channels) return;
+  myi = chan.toString(16);
+  if (chan<10) {myi = '0'+myi;}
+  new_commands.push('S'+myi+'0');
+}
+
+function communication() {
+  if (document.getElementById("showreadings").checked == 1 || new_commands.length != 0) {
+    for(i=0;i<channels;i++) {
+      myi = i.toString(16);
+      if (i<10) {myi = '0'+myi;}
+      new_commands.push('S'+myi+'Q');
+      new_commands.push('C'+myi+'Q');
+      new_commands.push('D'+myi+'Q');
+      new_commands.push('L'+myi+'Q');
+      }
+    }
+  
+  cmds = new_commands.join('&');
+  if (cmds != "") {
+    getdata('pwr_switch.pl?'+ser_dev+'&'+cmds,update);
+    }
+  else {
+    updateTask = setTimeout("communication()",updaterate);
+    }
+       new_commands = new Array();
+}
+
+function update(data) {
+  var e = data.split("&");
+  Vdate = e.shift();
+  for(i=0;i<channels;i++) {
+    Vstatus[i] = e.shift();
+    Vcurrent[i] = e.shift();
+    Vaverage[i] = e.shift();
+    Vlimit[i] = e.shift();
+    }
+  maketable();  
+  updateTask = setTimeout("communication()",updaterate);  
+  }
+
+function getParameterByName(name)
+{
+  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
+  var regexS = "[\\?&]" + name + "=([^&#]*)";
+  var regex = new RegExp(regexS);
+  var results = regex.exec(window.location.search);
+  if(results == null)
+    return "";
+  else
+    return decodeURIComponent(results[1].replace(/\+/g, " "));
+}
+
+
+function readSettings() {
+  readSettingsRequest = 1;
+  }
+
+updateTask = setTimeout("communication()",updaterate);
+document.getElementById("headline").innerHTML  = "Power Switch "+'<b>'+dev_id+'</b>'+" [connected to "+'<b>'+ser_dev+'</b>'+"]" ;
+  
+maketable();  
+</script>
+</body></html>
diff --git a/web/htdocs/tools/pwr/pwr_switch.pl b/web/htdocs/tools/pwr/pwr_switch.pl
new file mode 100755 (executable)
index 0000000..9296361
--- /dev/null
@@ -0,0 +1,126 @@
+#!/usr/bin/perl -w
+if ($ENV{'SERVER_SOFTWARE'} =~ /HTTP-?i/i) {
+  &htsponse(200, "OK");
+  }
+print "Content-type: text/html\n\n";
+
+
+use strict;
+use warnings;
+use Device::SerialPort;
+use IO::Socket;
+use feature 'state';
+use URI::Escape;
+use Time::HiRes qw( usleep);
+use POSIX qw/floor ceil strftime/;
+
+my $envstring = $ENV{'QUERY_STRING'};
+$envstring =~ s/%20/ /g;
+$envstring =~ s/Q/\?/g;
+
+
+my @new_command = split('&',$envstring); 
+my $ser_dev = shift(@new_command);
+$ser_dev = "/dev/ttyUSB0" unless defined $ser_dev;
+
+# my $ser_type = shift(@new_command);
+# $ser_type = "PSP" unless defined $ser_type;
+# 
+# my $ser_speed = shift(@new_command);  #speed or port number
+# $ser_speed = "2400" unless defined $ser_speed;
+
+
+my $port;
+# my $isIP = 0;
+# my $isRemote = undef;
+# 
+# if($ser_dev =~ /^IP(.*)/) {
+#   $ser_dev = $1;
+#   $isIP = 1;
+#   $port = IO::Socket::INET->new(PeerAddr => $ser_dev, PeerPort => $ser_speed, Proto => "tcp", Type => SOCK_STREAM) 
+#               or die "ERROR: Cannot connect: $@";  
+#   }
+# elsif($ser_dev =~ /^SER(.*)/) {
+#   my $str = $1;
+#   ($isRemote,$ser_dev) = split('/',$str,2);
+#   $ser_dev = '/'.$ser_dev;
+#   }
+# else {  
+  $port = new Device::SerialPort($ser_dev);
+  unless ($port)
+  {
+    print "can't open serial interface $ser_dev\n";
+    exit;
+  }
+
+  $port->user_msg('ON'); 
+  $port->baudrate(57600); 
+  $port->parity("none"); 
+  $port->databits(8); 
+  $port->stopbits(1); 
+  $port->handshake("none"); 
+  $port->read_char_time(0);
+  $port->read_const_time(50);
+  $port->write_settings;
+
+
+# debug output
+#print "attempting to communicate with power supply connected to interface:\n$ser_dev\n\n";
+
+
+# if(defined $isRemote) {
+#   my $env = $ENV{'QUERY_STRING'};
+# #   $env =~ s/%20/ /g;
+#   $env =~ s/&/!/g;
+#   my $cmd = "bash -c \"ssh $isRemote 'QUERY_STRING=".$env." perl'\" <htdocs/tools/pwr/pwr_remote.pl";
+# #   system("ssh $isRemote 'QUERY_STRING=".$env." perl -v' ");
+# #   print $cmd."\n";
+#   print qx($cmd);
+#   }
+# else {
+  print receive_answer();
+#   }
+
+
+
+sub Cmd {
+  my ($c) = @_;
+  for my $i (0..2) {
+    $port->write($c."\n");
+    my $a = "";
+    for my $j (0..8) {
+      my ($l,$s) = $port->read(5);
+      $a .= $l;
+      if ($l < 5) {next;}
+      if ($s =~ /^\w[a-f0-9]{3}/) {return hex(substr($s,1,3)).'&';} 
+      if ($s =~ /^\w[a-f0-9]{2}/) {return hex(substr($s,1,2)).'&';}
+      usleep(10000);
+      }
+    usleep(50000);
+    #print '.';
+    }
+  }
+
+
+
+
+sub receive_answer {
+  print strftime("%H:%M:%S &", localtime());
+  my $ret ="";
+#   print strftime("%H:%M:%S &", localtime());
+  while ( my $command = shift(@new_command) ) {
+    my $r = Cmd($command);
+    print $r if($command =~ /\?/);
+    }
+  return $ret;
+  }
+
+
+  
+print "\n";
+  
+exit 1;
+
+
+
+
index e40f78639a22f907f710ddf074c5885622700835..7d6a735671db4009106db1d0b2179ea1f0d454ae 100644 (file)
@@ -40,4 +40,18 @@ td.state {
 #info {
 font-size:70%;
 text-align:right;
+}
+
+.powerswitch .status {
+  min-width:20px;
+  width:20px;
+}
+
+tfoot>tr:first-child {
+  border-top:1px solid black;
+}
+
+.powerswitch td {
+  border-left:1px solid black;
+  text-align:center;
 }
\ No newline at end of file