Commit 98348a99 authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Add back some of Russ's code that allowed for clicking on the map, and

getting a crosshair painted in. Also use those coords and the
pixels_per_meter conversion from the DB to print out for the user
where he just clicked.

Change the SHOWNODE function to print out the coordinates (so when you
click on a robot in the map, you get a line that says what its coords
are).

Also generate table of all robot positions to place below the image.
parent dde7799c
......@@ -22,22 +22,10 @@ $isadmin = ISADMIN($uid);
unset($prefix);
#
# Verify page arguments. First allow user to optionally specify building/floor.
#
if (isset($building) && $building != "") {
# Sanitize for the shell.
if (!preg_match("/^[-\w]+$/", $building)) {
PAGEARGERROR("Invalid building argument.");
}
# Optional floor argument. Sanitize for the shell.
if (isset($floor) && !preg_match("/^[-\w]+$/", $floor)) {
PAGEARGERROR("Invalid floor argument.");
}
}
else {
$building = "MEB-ROBOTS";
unset($floor);
}
# One robot map right now ...
#
$building = "MEB-ROBOTS";
$floor = 3;
#
# Optional pid,eid. Without a building/floor, show all the nodes for the
......@@ -65,65 +53,68 @@ else {
}
#
# Figure out what channels are in use for the current building. We only
# have one building (MEB) at the moment, so this is quite easy.
# Also determine what the free,reserved,dead counts are.
# map_x and map_y are the map.x and map.y coordinates from clicking on the map.
#
if (isset($map_x) && $map_x != "") {
# Sanitize for the shell.
if (!preg_match("/^[0-9]+$/", $map_x)) {
PAGEARGERROR("Invalid map_x argument.");
}
}
else {
unset($map_x);
}
if (isset($map_y) && $map_y != "") {
# Sanitize for the shell.
if (!preg_match("/^[0-9]+$/", $map_y)) {
PAGEARGERROR("Invalid map_y argument.");
}
}
else {
unset($map_y);
}
#
# Assume a single image for the robot map. When user clicks, pixel
# coords correspond to building and floor.
#
$channels = array();
$nodecounts = array();
$nodes = array();
$query_result =
DBQueryFatal("select * from floorimages where ".
"building='$building' and floor='$floor'");
if (mysql_num_rows($query_result)) {
$row = mysql_fetch_array($query_result);
$pixels_per_meter = $row["pixels_per_meter"];
}
$nodecounts["free"] = 0;
$nodecounts["reserved"] = 0;
$nodecounts["dead"] = 0;
#
# Build a table of location info to print in table below image.
#
$locations = array();
$query_result =
DBQueryFatal("select loc.*,s.capval,r.pid,r.eid from location_info as loc ".
"left join interface_settings as s on ".
" s.node_id=loc.node_id and s.capkey='channel' ".
"left join reserved as r on r.node_id=loc.node_id");
DBQueryFatal("select loc.* from location_info as loc ".
"where loc.floor='$floor' and loc.building='$building'");
while ($row = mysql_fetch_array($query_result)) {
$channel = $row["capval"];
$node_id = $row["node_id"];
$locfloor = $row["floor"];
$rpid = $row["pid"];
$reid = $row["eid"];
#
# The above query to get the channels will give us multiple rows
# if there are multiple interface cards in use; do not want to
# count those twice.
#
if (!isset($nodes[$node_id])) {
$nodes[$node_id] = 1;
if ((!isset($pid) && !(isset($rpid))) ||
(isset($pid) && isset($rpid) && $pid == $rpid)) {
$nodecounts["free"]++;
}
elseif ($rpid == $NODEDEAD_PID && $reid == $NODEDEAD_EID) {
$nodecounts["dead"]++;
}
else {
$nodecounts["reserved"]++;
}
}
$loc_x = $row["loc_x"];
$loc_y = $row["loc_y"];
# Make sure an empty list is displayed if nothing allocated on a floor.
if (!isset($channels[$locfloor])) {
$channels[$locfloor] = array();
}
if (isset($pixels_per_meter) && $pixels_per_meter) {
$meters_x = sprintf("%.3f", $loc_x / $pixels_per_meter);
$meters_y = sprintf("%.3f", $loc_y / $pixels_per_meter);
if (!isset($channel))
continue;
$channels[$locfloor][$channel] = $channel;
$locations[$node_id] = "x=$meters_x, y=$meters_y meters";
}
else {
$locations[$node_id] = "x=$loc_x, y=$loc_y pixels";
}
}
#
# Run the Perl script. It will produce three output files; image, areamap, and state.
# We want to embed all of these images into the page we send back. This is painful!
# Run the Perl script. It will produce three output files; image, areamap,
# and state. We want to embed all of these images into the page we
# send back. This is painful!
#
# Need cleanup "handler" to make sure temp files get deleted!
#
......@@ -156,6 +147,8 @@ if (!preg_match("/^\/tmp\/([-\w]+)$/", $prefix, $matches)) {
$uniqueid = $matches[1];
$perl_args = "-o $prefix " .
# From clicking on a map image.
(isset($map_x) ? "-c $map_x,$map_y " : "") .
(isset($floor) ? "-f $floor " : "") .
(isset($building) ? "$building" : ""); # Building arg must be last!
......@@ -180,9 +173,27 @@ if (! readfile("${prefix}.map")) {
echo "<center>\n";
# Wrap the image and zoom controls together in an input form.
echo "<form method=\"get\" action=\"robotmap.php3\">\n";
# The image may be clicked to get node info or set a new center-point.
echo " Click on the dots below to see information about the robot\n";
echo " <br>\n";
echo " Click elsewhere to get its x,y location.\n";
echo " <br>\n";
if (isset($map_x) && isset($map_y)) {
if (isset($pixels_per_meter) && $pixels_per_meter) {
$meters_x = sprintf("%.3f", $map_x / $pixels_per_meter);
$meters_y = sprintf("%.3f", $map_y / $pixels_per_meter);
echo "Last click location was x=$meters_x, y=$meters_y meters.\n";
}
else {
echo "Last click location was x=$map_x, y=$map_y pixels\n";
}
echo "<br>\n";
}
echo " <input name=map type=image style=\"border: 2px solid\" ";
echo "src=\"floormap_aux.php3?prefix=$uniqueid\" ".
......@@ -194,6 +205,17 @@ echo " <br>\n";
echo " <input type=\"hidden\" name=\"prefix\" value=\"$uniqueid\">\n";
echo "</form>\n";
if (count($locations)) {
echo "<table align=center border=2 cellpadding=0 cellspacing=2>
<tr><th>Node</th><th>Location</th></tr>\n";
while (list($node_id, $location) = each($locations)) {
echo "<tr><td>$node_id</td> <td>$location</td> </tr>\n";
}
echo "</table>\n";
}
echo "</center>\n";
#
......
......@@ -1750,7 +1750,7 @@ function SHOWNODE($node_id, $flags = 0) {
"greatest(last_tty_act,last_net_act,last_cpu_act,".
"last_ext_act) as last_act, ".
" t.isvirtnode,t.isremotenode,t.isplabdslice, ".
" r.erole as rsrvrole, pi.IP as phys_IP ".
" r.erole as rsrvrole, pi.IP as phys_IP, loc.* ".
" from nodes as n ".
"left join reserved as r on n.node_id=r.node_id ".
"left join node_activity as na on n.node_id=na.node_id ".
......@@ -1759,6 +1759,7 @@ function SHOWNODE($node_id, $flags = 0) {
" and i.node_id=n.node_id ".
"left join interfaces as pi on pi.iface=t.control_iface ".
" and pi.node_id=n.phys_nodeid ".
"left join location_info as loc on loc.node_id=n.node_id ".
"where n.node_id='$node_id'");
if (mysql_num_rows($query_result) == 0) {
......@@ -1816,6 +1817,35 @@ function SHOWNODE($node_id, $flags = 0) {
if (!$startupcmd)
$startupcmd = "&nbsp";
if (!$short) {
#
# Location info.
#
if (isset($row["loc_x"]) && isset($row["loc_y"]) &&
isset($row["floor"]) && isset($row["building"])) {
$floor = $row["floor"];
$building = $row["building"];
$loc_x = $row["loc_x"];
$loc_y = $row["loc_y"];
$query_result =
DBQueryFatal("select * from floorimages ".
"where scale=1 and ".
" floor='$floor' and building='$building'");
if (mysql_num_rows($query_result)) {
$row = mysql_fetch_array($query_result);
if (isset($row["pixels_per_meter"]) &&
($pixels_per_meter = $row["pixels_per_meter"])) {
$meters_x = sprintf("%.3f", $loc_x / $pixels_per_meter);
$meters_y = sprintf("%.3f", $loc_y / $pixels_per_meter);
}
}
}
}
echo "<table border=2 cellpadding=0 cellspacing=2
align=center>\n";
......@@ -1895,7 +1925,20 @@ function SHOWNODE($node_id, $flags = 0) {
<td class=left>$allocstate ($when)</td>
</tr>\n";
}
}
if (!$short) {
#
# Location info.
#
if (isset($meters_x) && isset($meters_y)) {
echo "<tr>
<td>Location:</td>
<td class=left>x=$meters_x, y=$meters_y meters</td>
</tr>\n";
}
}
if (!$short && !$noperm) {
#
# We want the last login for this node, but only if its *after* the
# experiment was created (or swapped in).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment