📄 gpsd.php
字号:
$GPS['fix'] = 'No'; if (preg_match('/M=(\d),/', $resp, $m)){ switch ($m[1]){ case 2: $GPS['fix'] = '2D'; break; case 3: $GPS['fix'] = '3D'; break; case 4: $GPS['fix'] = '3D (PPS)'; break; default: $GPS['fix'] = "No"; } } if (preg_match('/S=(\d),/', $resp, $m)){ $GPS['fix'] .= ' ('; if ($m[1] != 2){ $GPS['fix'] .= 'not '; } $GPS['fix'] .= 'DGPS corrected)'; } if (preg_match('/A=([0-9\.-]+),/', $resp, $m)){ $GPS['alt'] = ($m[1] . ' m'); } if (preg_match('/P=([0-9\.-]+) ([0-9\.-]+),/', $resp, $m)){ $GPS['lat'] = $m[1]; $GPS['lon'] = $m[2]; } if (preg_match('/Q=(\d+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+)/', $resp, $m)){ $GPS['sat'] = $m[1]; $GPS['gdop'] = $m[2]; $GPS['hdop'] = $m[3]; $GPS['vdop'] = $m[4]; } if ($GPS['lat'] != 'Unavailable' && $GPS['lon'] != 'Unavailable'){ $GPS['lat'] = dfix($GPS['lat'], 'N', 'S'); $GPS['lon'] = dfix($GPS['lon'], 'E', 'W'); $GPS['loc'] = sprintf('at %s / %s', $GPS['lat'], $GPS['lon']); } if (preg_match('/^No/', $GPS['fix'])){ clearstate(); } } else $GPS['loc'] = ''; $GPS['gt'] = time(); $GPS['lt'] = date("r", $GPS['gt']); $GPS['gt'] = gmdate("r", $GPS['gt']);}function write_html($resp){ global $GPS, $sock, $errstr, $errno, $server, $port, $head, $body; global $blurb, $title, $autorefresh, $googlemap, $gmap_key, $footer; global $magic; header("Content-type: text/html; charset=UTF-8"); global $lat, $lon; $lat = (float)$GPS['lat']; $lon = -(float)$GPS['lon']; $x = $server; $y = $port; $imgdata = base64_encode($resp); include("gpsd_config.inc"); # breaks things $server = $x; $port = $y; if ($autorefresh > 0) $autorefresh = "<meta http-equiv='Refresh' content='$autorefresh'/>"; else $autorefresh = ''; $gmap_head = $gmap_body = $gmap_code = ''; if ($googlemap){ $gmap_head = gen_gmap_head(); $gmap_body = 'onload="Load()" onunload="GUnload()"'; $gmap_code = gen_gmap_code(); } $svn ='$Rev: 4680 $'; $part1 = <<<EOF<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>{$head}{$gmap_head}<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta http-equiv="Content-Language" content="en,en-us"/><title>{$title} - GPSD Test Station {$GPS['loc']}</title>{$autorefresh}<style>.warning { color: #FF0000; }.fixed { font-family: courier, fixed;}.caption { text-align: left; margin: 1ex 3em 1ex 3em; /* top right bottom left */}.administrivia { font-size: small; font-family: verdana, sans-serif;}</style></head><body {$body} {$gmap_body}><center><table border="0"><tr><td align="justify">{$blurb}</td>EOF; if (!strlen($advertise)) $advertise = $server; if ($magic && !$sock) $part2 = ""; else $part2 = <<<EOF<!-- ------------------------------------------------------------ --><td rowspan="4" align="center" valign="top"><img src="?op=view&imgdata={$imgdata}"width="640" height="640"/><br clear="all"/><p class="caption">A filled circle means the satellite was used inthe last fix. Green-yellow-red colors indicate signal strength in dB, green=most and red=least. Diamonds indicate SBAS satellites.</p></td></tr>EOF; $part3 = <<<EOF<!-- ------------------------------------------------------------ --><tr><td align="justify">To get real-time information, connect to<span class="fixed">telnet://{$advertise}:{$port}/</span> and type "R".<br/>Use a different server:<br/><form method=GET action="${_SERVER['SCRIPT_NAME']}"><input name="host" value="{$advertise}">:<input name="port" value="{$port}" size="5" maxlength="5"><input type=submit value="Get Position"><input type=reset></form><br/></td></tr>EOF; if ($magic && !$sock) $part4 = "<tr><td><font color='red'>The gpsd instance that this page monitors is not running.</font></td></tr>"; else $part4 = <<<EOF<!-- ------------------------------------------------------------ --> <tr><td align=center valign=top> <table border=1> <tr><td colspan=2 align=center><b>Current Information</b></td></tr> <tr><td>Time (Local)</td><td>{$GPS['lt']}</td></tr> <tr><td>Time (UTC)</td><td>{$GPS['gt']}</td></tr> <tr><td>Latitude</td><td>{$GPS['lat']}</td></tr> <tr><td>Longitude</td><td>{$GPS['lon']}</td></tr> <tr><td>Altitude</td><td>{$GPS['alt']}</td></tr> <tr><td>Fix Type</td><td>{$GPS['fix']}</td></tr> <tr><td>Satellites</td><td>{$GPS['sat']}</td></tr> <tr><td>HDOP</td><td>{$GPS['hdop']}</td></tr> </table></tr><tr><td><small>{$resp}</small></td></tr>EOF; $part5 = <<<EOF</table></center>{$footer}<hr/><span class="administrivia">This script is distributed by the <a href="http://gpsd.berlios.de">GPSD project</a>.</span><br/><span class="administrivia">{$svn}<br/></body></body>EOF;print $part1 . $part2 . $part3 . $part4 . $part5;}function write_config(){ $f = fopen("gpsd_config.inc", "a"); if (!$f) die("can't generate prototype config file. try running this script as root in DOCUMENT_ROOT"); $buf = <<<EOB<?PHP\$title = 'My GPS Server';\$server = '127.0.0.1';#\$advertise = '127.0.0.1';\$port = 2947;\$autorefresh = 0; # number of seconds after which to refresh\$googlemap = 0; # set to 1 if you want to have a google map\$gmap_key = 'GetYourOwnGoogleKey'; # your google API key goes here\$swap_ew = 0; # set to 1 if you don't understand projections## You can read the header, footer and blurb from a file...# \$head = file_get_contents('/path/to/header.inc');# \$body = file_get_contents('/path/to/body.inc');# \$footer = file_get_contents('/path/to/footer.hinc');# \$blurb = file_get_contents('/path/to/blurb.inc');## ... or you can just define them here\$head = '';\$body = '';\$footer = '';\$blurb = <<<EOTThis is a<a href="http://gpsd.berlios.de">gpsd</a>server <blink><font color="red">located someplace</font></blink>.The hardware is a<blink><font color="red">hardware description and link</font></blink>.This machine is maintained by<a href="mailto:you@example.com">Your Name Goes Here</a>.<br/>EOT;?>EOB; fwrite($f, $buf); fclose($f);}function gen_gmap_head() {global $gmap_key;return <<<EOT<script src="http://maps.google.com/maps?file=api&v=2&key={$gmap_key}" type="text/javascript"></script><script type="text/javascript"> <!-- // Create a base icon for all of our markers that specifies the shadow, icon // dimensions, etc.function Load() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map")); var point = new GLatLng( {$GLOBALS['lat']}, {$GLOBALS['lon']} ); map.setCenter( point, 14); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); var baseIcon = new GIcon(); baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png"; baseIcon.iconSize = new GSize(20, 34); baseIcon.shadowSize = new GSize(37, 34); baseIcon.iconAnchor = new GPoint(9, 34); baseIcon.infoWindowAnchor = new GPoint(9, 2); baseIcon.infoShadowAnchor = new GPoint(18, 25); var icon = new GIcon(baseIcon); icon.image = "http://www.google.com/mapfiles/marker.png"; var marker = new GMarker(point, icon); map.addOverlay(marker); }} --> </script>EOT;}function gen_gmap_code() {return <<<EOT<br/> <div id="map" style="width: 550px; height: 400px; border:1px; border-style: solid;"> Loading... <noscript><span class='warning'>Sorry: you must enable javascript to view our maps.</span><br/> </noscript></div>EOT;}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -