Changeset 4ab1c0a for src/webapp
- Timestamp:
- Jul 12, 2016, 6:39:45 PM (10 years ago)
- Branches:
- 0.5, app-cordova, debian/bullseye, debian/jessie, master
- Children:
- d0e98d5
- Parents:
- f8dfbe7
- Location:
- src/webapp
- Files:
-
- 1 added
- 4 edited
-
webclient/css/main.css (modified) (3 diffs)
-
webclient/javascript/main.js (modified) (3 diffs)
-
webclient/root/index.php (modified) (1 diff)
-
webservice/inc/Config.php (added)
-
webservice/index.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/webclient/css/main.css
rf8dfbe7 r4ab1c0a 72 72 position: absolute; 73 73 top: 2mm; 74 left: 28mm;74 left: 30mm; 75 75 } 76 76 … … 81 81 } 82 82 83 #display #gps {83 #display #gpsfix { 84 84 position: absolute; 85 85 top: 21mm; … … 90 90 position: absolute; 91 91 top: 21mm; 92 left: 28mm;92 left: 30mm; 93 93 } 94 94 -
src/webapp/webclient/javascript/main.js
rf8dfbe7 r4ab1c0a 21 21 22 22 var map; 23 var points = [];24 23 var polyline; 25 24 … … 29 28 30 29 function displayDataSet(data){ 31 $("#display #speedthroughwater #value").text(data["speedthroughwater"].toString()); 32 $("#display #speedoverground #value").text(data["speedoverground"].toString()); 33 $("#display #waterdepth #value").text(data["waterdepth"].toString()); 34 $("#display #watertemperature #value").text(Math.round(data["watertemperature"]).toString()); 35 $("#display #gps #value").text(data["gpsfix"]); 30 if(!("lastvalid" in data)){ 31 console.log("No last valid values given!"); 32 } 33 else{ 34 var lastValid = data["lastvalid"]; 35 var keys = ["speedthroughwater", "speedoverground", "waterdepth", "watertemperature", "gpsfix"]; 36 for(var i = 0; i < keys.length; i++){ 37 var key = keys[i]; 38 var value = lastValid[key]; 39 if($.isNumeric(value)){ 40 if(key == "watertemperature"){ 41 value = Math.round(value); 42 } 43 $("#display #"+ keys[i] +" #value").text(value.toString()); 44 } 45 else if(key == "gpsfix"){ 46 $("#display #"+ keys[i] +" #value").text(value); 47 } 48 } 49 } 36 50 37 var latitude = data["latitude"]; 38 var longitude = data["longitude"]; 39 if(latitude && longitude){ 51 if(!("track" in data)){ 52 console.log("No track given!"); 53 } 54 else{ 55 var track = data["track"]; 56 var points = []; 57 for(var time in track){ 58 points.push(new L.latLng(track[time]["latitude"], track[time]["longitude"])); 59 } 40 60 if(points.length > 0){ 41 var lastPoint = points[points.length - 1];42 if(lastPoint.lat != latitude || lastPoint.lng != longitude){43 points.push(new L.latLng(latitude, longitude));44 console.log(points);61 if(!polyline){ 62 polyline = L.polyline(points, {color: 'red'}).addTo(map); 63 } 64 else{ 45 65 polyline.setLatLngs(points); 46 map.fitBounds(polyline.getBounds());47 66 } 67 map.fitBounds(polyline.getBounds()); 48 68 } 49 69 } … … 80 100 attribution: 'undefined',opacity: 0.85 81 101 }).addTo(map); 82 83 points.push(new L.latLng(47.5914051, 10.710862));84 points.push(new L.latLng(47.576667, 10.735278));85 polyline = L.polyline(points, {color: 'red'}).addTo(map);86 102 } 87 103 -
src/webapp/webclient/root/index.php
rf8dfbe7 r4ab1c0a 83 83 <span id="value">-</span>°C 84 84 </div> 85 <div id="gps ">85 <div id="gpsfix"> 86 86 <h2>Fix</h2> 87 87 <span id="value">-</span> -
src/webapp/webservice/index.php
rf8dfbe7 r4ab1c0a 17 17 */ 18 18 19 /** 20 * The GPSD parts are adepted from the gpsd.php script deployed with GPSD package! 21 */ 19 require_once(__DIR__ ."/inc/Config.php"); 20 $config = new Config(); 21 $dbFile = $config->databaseFile(); 22 22 23 $gpsdHost = "localhost"; 24 $gpsdPort = "2947"; 23 // configure roundings per value (key) and precision (value) 24 $configRound = array 25 ( 26 "latitude" => 5, 27 "longitude" => 5, 28 "speedthroughwater" => 1, 29 "speedoverground" => 1, 30 "waterdepth" => 1, 31 "watertemperature" => 1, 32 ); 25 33 26 set_time_limit(3); 27 ini_set('max_execution_time', 3); 34 $debug = 0; 35 if(array_key_exists("debug", $_GET)) 36 $debug = $_GET["debug"]; 28 37 29 function readGpsd(){ 30 global $gpsdHost, $gpsdPort;38 if($debug == 0) 39 header('Content-Type: application/json'); 31 40 32 33 $speedOverGround = "-"; 34 $gpsfix = "-"; 35 $latitude = ""; 36 $longitude = ""; 37 $errno = ""; 38 $errstr = ""; 39 40 $sock = @fsockopen($gpsdHost, $gpsdPort, $errno, $errstr, 2); 41 if(!$sock){ 42 $speedOverGround = "-"; 43 $gpsfix = -1; 44 } 45 @fwrite($sock, "?WATCH={\"enable\":true}\n"); 46 usleep(1000); 47 @fwrite($sock, "?POLL;\n"); 48 usleep(1000); 49 for($tries = 0; $tries < 10; $tries++){ 50 $response = @fread($sock, 2000); # SKY can be pretty big 51 if (preg_match('/{"class":"POLL".+}/i', $response, $m)){ 52 $response = $m[0]; 53 break; 41 $result["lastvalid"] = array(); 42 $result["track"] = array(); 43 44 // Fetch entries of the last 12hours 45 $data = rrd_fetch($dbFile, array( "AVERAGE", "--start", "-12h")); 46 if($data === false){ 47 echo json_encode($result); 48 $message = "Could not open rrd database ". $dbFile; 49 if($debug > 0) 50 echo $message; 51 else 52 error_log($message); 53 exit; 54 } 55 56 if($debug > 2){ 57 echo "<pre>"; 58 var_dump($data); 59 echo "</pre>"; 60 } 61 62 $data = $data["data"]; 63 64 // transform them into json format 65 $i = 0; 66 $lastTime = -1; 67 $keys = array_keys($data); 68 if(count($keys) < 0 ){ 69 error_log("No keys in fetched rrd data from ". $dbFile); 70 echo json_encode(""); 71 exit; 72 } 73 for($i = 0; $i < count($data[$keys[0]]); $i++){ 74 $time = array_keys($data[$keys[0]])[$i]; 75 $allValid = true; 76 $tmp = array(); 77 foreach($keys as $key){ 78 if($key == "gpsfix"){ 79 switch($data[$key][$time]){ 80 case 1: 81 $tmp[$key] = "2D"; 82 break; 83 case 2: 84 $tmp[$key] = "3D"; 85 break; 86 default: 87 $tmp[$key] = "-"; 88 } 89 } 90 else{ 91 $tmp[$key] = $data[$key][$time]; 92 if(!is_numeric($tmp[$key]) || is_nan($tmp[$key])){ 93 $allValid = false; 94 } 95 elseif(array_key_exists($key, $configRound) && is_integer($configRound[$key])) 96 $tmp[$key] = round($tmp[$key], $configRound[$key]); 54 97 } 55 98 } 56 @fclose($sock);57 if( !$response){58 $ speedOverGround = "-";59 $ gpsfix = -2;99 // only add the timeframe to the track, if the values are valid and we had a gps fix at that time 100 if($allValid && $tmp["gpsfix"] != "-"){ 101 $result["track"][$time] = $tmp; 102 $lastTime = $time; 60 103 } 61 104 else{ 62 $data = json_decode($response, true); 63 if ($data['class'] != 'POLL'){ 64 $speedOverGround = "-"; 65 $gpsfix = -3; 66 } 67 if(!array_key_exists('tpv', $data) && is_array($data['tpv'])){ 68 $speedOverGround = "-"; 69 $gpsfix = -4; 70 } 71 $tpv = $data['tpv'][0]; 72 73 if(!array_key_exists('mode', $tpv)){ 74 $gpsfix = -5; 75 } 76 else{ 77 switch($tpv['mode']){ 78 case 1: 79 $gpsfix = "2D"; 80 break; 81 case 2: 82 $gpsfix = "3D"; 83 break; 84 default: 85 $gpsfix = "-"; 86 } 87 } 88 89 if(!array_key_exists('speed', $tpv)){ 90 $speedOverGround = "-1"; 91 } 92 else{ 93 $speedOverGround = $tpv['speed']; 94 } 95 96 if(!array_key_exists('lat', $tpv)){ 97 $latitude = ""; 98 } 99 else{ 100 $latitude = $tpv['lat']; 101 } 102 if(!array_key_exists('lon', $tpv)){ 103 $longitude = ""; 104 } 105 else{ 106 $longitude = $tpv['lon']; 105 if($debug > 0){ 106 echo "Failed <pre>"; 107 var_dump($tmp); 108 echo "</pre>\n"; 107 109 } 108 110 } 109 110 return array("speedOverGround" => $speedOverGround, "gpsfix" => $gpsfix, "latitude" => $latitude, "longitude" => $longitude); 111 } 112 if($lastTime > -1){ 113 $result["lastvalid"] = $result["track"][$lastTime]; 111 114 } 112 115 113 114 115 mt_srand((double) microtime() * 1000000); 116 117 $result = array(); 118 119 $gpsdResult = readGpsd(); 120 121 $result["speedthroughwater"] = mt_rand(0, 10); 122 $result["speedoverground"] = $gpsdResult["speedOverGround"]; 123 $result["waterdepth"] = mt_rand(1, 30) + 0.5; 124 $result["watertemperature"] = mt_rand(15, 25) + 0.5; 125 $result["gpsfix"] = $gpsdResult["gpsfix"]; 126 $result["latitude"] = $gpsdResult["latitude"]; 127 $result["longitude"] = $gpsdResult["longitude"]; 128 129 echo json_encode($result); 116 if($debug > 0){ 117 echo json_encode($result, JSON_PRETTY_PRINT); 118 } 119 else{ 120 echo json_encode($result); 121 } 130 122 131 123 ?>
Note:
See TracChangeset
for help on using the changeset viewer.
