Changeset 944372e for src/webapp
- Timestamp:
- Sep 21, 2017, 1:59:48 PM (9 years ago)
- Branches:
- debian/bullseye, debian/jessie
- Children:
- 6b3dd00
- Parents:
- 949f66d (diff), 3145648 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/webapp
- Files:
-
- 22 added
- 14 edited
-
build.xml (modified) (2 diffs)
-
phpunit.xml (added)
-
webclient/css/GnuBoat.css (modified) (2 diffs)
-
webclient/index.html (modified) (2 diffs)
-
webclient/js/GnuBoat.js (modified) (21 diffs)
-
webservice/config/config.php (added)
-
webservice/inc/GnuBoat/Config.php (modified) (3 diffs)
-
webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Direction.php (added)
-
webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Dpt.php (added)
-
webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Mtw.php (added)
-
webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Rmc.php (added)
-
webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183RmcSignal.php (added)
-
webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183RmcStatus.php (added)
-
webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Sentence.php (added)
-
webservice/inc/GnuBoat/Nmea/Nmea0183/Parser.php (added)
-
webservice/inc/GnuBoat/Nmea/NmeaParser.php (added)
-
webservice/inc/GnuBoat/Nmea/NmeaSentence.php (added)
-
webservice/inc/GnuBoat/Nmea/Parser.php (added)
-
webservice/inc/GnuBoat/Service.php (modified) (1 diff)
-
webservice/inc/GnuBoat/ServiceData.php (modified) (5 diffs)
-
webservice/inc/GnuBoat/ServiceLogFiles.php (modified) (2 diffs)
-
webservice/inc/GnuBoat/ServiceMap.php (modified) (1 diff)
-
webservice/inc/GnuBoat/ServiceReplay.php (added)
-
webservice/inc/GnuBoat/ServiceShutdown.php (modified) (1 diff)
-
webservice/inc/GnuBoat/TrackItem.php (added)
-
webservice/inc/GnuBoat/Webservice.php (modified) (3 diffs)
-
webservice/inc/autoloader.php (modified) (1 diff)
-
webservice/index.php (modified) (1 diff)
-
webservice/tests/Nmea0183DptTest.php (added)
-
webservice/tests/Nmea0183MtwTest.php (added)
-
webservice/tests/Nmea0183RmcTest.php (added)
-
webservice/tests/NmeaTest.php (added)
-
webservice/tests/ServiceTest.php (modified) (1 diff)
-
webservice/tests/TrackItemTest.php (added)
-
webservice/tests/logs/nmea0183.log (added)
-
webservice/tests/logs/replay-test.log (added)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/build.xml
r949f66d r944372e 28 28 <exclude name="mbtiles/**"/> 29 29 <exclude name="tests/**"/> 30 <exclude name="config/**"/> 30 31 </fileset> 31 32 <fileset dir="./webservice/mbtiles" id="filesWebserviceMaps"> … … 44 45 45 46 46 <target name="dist" depends="buildwebservice,buildwebclient ">47 <target name="dist" depends="buildwebservice,buildwebclient,test"> 47 48 <echo msg="Creating archive"/> 48 <!--<tar destfile="${builddir}/..//gnuboat-webapp.tar.gz" compression="gzip">49 <tar destfile="${builddir}/..//gnuboat-webapp.tar.gz" compression="gzip"> 49 50 <fileset refid="filesWebApp"/> 50 </tar> -->51 </tar> 51 52 <echo msg="Files copied and compressed in build directory weblcient.tar.gz OK!" /> 52 53 </target> 53 <target name="testdist" depends="buildwebservice,buildwebclient"> 54 55 <target name="testdist" depends="buildwebservice,buildwebclient,test"> 54 56 <echo msg="Install project into ${user.home}/public_html/gnuboat"/> 57 <fileset id="filesConfig" dir="./webservice/config"> 58 <include name="config.php"/> 59 </fileset> 60 <fileset id="filesLogs" dir="./webservice/tests/logs"> 61 <include name="*.log"/> 62 </fileset> 63 55 64 <copy todir="${user.home}/public_html/gnuboat"> 56 65 <fileset refid="filesWebApp"/> 57 66 </copy> 67 <copy todir="${user.home}/public_html/gnuboat/webservice/tests/logs"> 68 <fileset refid="filesLogs"/> 69 </copy> 70 <copy todir="${user.home}/public_html/gnuboat/webservice/config"> 71 <fileset refid="filesConfig"/> 72 </copy> 58 73 </target> 59 74 60 <!-- <phpunit bootstrap="webservice/inc/autoloader.php" pharlocation="phpunit-4.8.9.phar" haltonfailure="true" haltonerror="true" printsummary="true"> 61 <formatter type="plain" usefile="false"/> 62 <batchtest> 63 <fileset dir="webservice"> 64 <include name="tests/ServiceTest.php"/> 65 </fileset> 66 </batchtest> 67 </phpunit> --> 75 <target name="test"> 76 <exec command="php phpunit-4.8.9.phar" passthru="true" checkreturn="true"/> 77 <!--<phpunit pharlocation="phpunit-4.8.9.phar" configuration="phpunit.xml" haltonfailure="true" haltonerror="true" printsummary="true" codecoverage="false"> 78 <formatter type="plain" usefile="false"/> --> 79 <!--<formatter type="JUnit" usefile="true"/>--> 80 <!-- <batchtest> 81 <fileset dir="webservice"> 82 <include name="tests/*Test.php"/> 83 </fileset> 84 </batchtest> 85 </phpunit>--> 86 </target> 68 87 </project> -
src/webapp/webclient/css/GnuBoat.css
r949f66d r944372e 97 97 98 98 .viewportGeometry { 99 width: 100%; 99 /* width: 100%; */ 100 100 height: 24em; 101 101 } … … 129 129 background:url('../resources/view-refresh.svg') no-repeat left center; 130 130 } 131 132 .hidden { 133 display: none; 134 } 135 136 #mapLgend table { 137 margin-top: 0.25em; 138 margin-left: 1em; 139 } 140 141 #mapLegend table tr td.level { 142 text-align: right; 143 } -
src/webapp/webclient/index.html
r949f66d r944372e 139 139 <div id="map"> 140 140 <a name="map"></a> 141 <form id="mapSelectForm" class="pure-form"><select id="mapSelect" class="pure-input-1" size="1"></select></form> 142 <div id="mapViewport" class="viewportGeometry"></div> 141 <form id="mapSelectForm" class="pure-form pure-form-aligned"> 142 <div class="pure-control-group"> 143 <label for="mapModusSelect">Map Modus:</label> 144 <select id="mapModusSelect" size="1" class="pure-input-1-2"></select> 145 </div> 146 <div class="pure-control-group"> 147 <label for="mapSelect">Map Selection:</label> 148 <select id="mapSelect" size="1" class="pure-input-1-2"></select> 149 </div> 150 </form> 151 <div class="pure-g"> 152 <div class="pure-u-1 pure-u-md-4-5 pure-u-lg-4-5"> 153 <div id="mapViewport" class="viewportGeometry"></div> 154 </div> 155 <div class="pure-u-1 pure-u-md-1-5 pure-u-lg-1-5"> 156 <div id="mapLegend"></div> 157 </div> 158 </div> 143 159 </div> 144 160 <form id="mapTileUpload" class="pure-form pure-form-aligned" enctype="multipart/form-data"> … … 157 173 </form> 158 174 159 <h2 class="content-subhead">3D Rendering </h2>175 <h2 class="content-subhead">3D Rendering of Water Depth</h2> 160 176 <div> 161 177 <a name="rendering"></a> -
src/webapp/webclient/js/GnuBoat.js
r949f66d r944372e 54 54 { 55 55 if(GnuBoat.private.serverBaseUrl == null){ 56 GnuBoat.displayMessage( "No server set/found");56 GnuBoat.displayMessage('<span class="error">No server set/found</span>'); 57 57 return; 58 58 } … … 67 67 { 68 68 if(GnuBoat.private.serverBaseUrl == null){ 69 GnuBoat.displayMessage( "No server set/found");69 GnuBoat.displayMessage('<span class="error">No server set/found</span>'); 70 70 return; 71 71 } … … 79 79 { 80 80 if(GnuBoat.private.serverBaseUrl == null){ 81 GnuBoat.displayMessage( "No server set/found");81 GnuBoat.displayMessage('<span class="error">No server set/found</span>'); 82 82 return; 83 83 } 84 84 $("#logfilesForm").empty(); 85 85 $.getJSON(GnuBoat.private.serverBaseUrl +"?request=logfiles", function(data){ 86 GnuBoat.private.updateMapModus(data); 86 87 if(!Array.isArray(data) || data.length < 1){ 87 88 $("<p>No Logfiles found!</p>").appendTo("#logfilesForm"); … … 90 91 } 91 92 if(("error" in data) && data["error"] == 1){ 92 alert("Failed to upload map: "+ data["errormessage"]);93 $(" #mapTileUploadProgress").hide();94 $("#mapFileInput").show();93 GnuBoat.displayMessage('<span class="error">Failed to get log files: '+ data["errormessage"] +'</span>'); 94 $("<p>No Logfiles found!</p>").appendTo("#logfilesForm"); 95 console.log(data); 95 96 return; 96 97 } … … 108 109 { 109 110 if(GnuBoat.private.serverBaseUrl == null){ 110 GnuBoat.displayMessage( "No server set/found");111 GnuBoat.displayMessage('<span class="error">No server set/found</span>'); 111 112 return; 112 113 } … … 129 130 { 130 131 if(GnuBoat.private.serverBaseUrl == null){ 131 displayMessage( "No server set/found");132 displayMessage('<span class="error">No server set/found</span>'); 132 133 return; 133 134 } … … 142 143 success: function(data){ 143 144 if(("error" in data) && data["error"] == 1){ 144 alert("Failed to upload map: "+ data["errormessage"]);145 GnuBoat.displayMessage('<span class="error">Failed to upload map: '+ data["errormessage"] +'</span>'); 145 146 $("#mapTileUploadProgress").hide(); 146 147 $("#mapFileInput").show(); 147 148 return; 148 149 } 149 alert("Map upload successfully");150 GnuBoat.displayMessage('<span class="error">Map upload successfully</span>'); 150 151 $("#mapTileUploadProgress").hide(); 151 152 $("#mapFileInput").show(); … … 153 154 }, 154 155 error: function(jqXHR, exception, errorThrown){ 155 alert("Failed to upload map (XHR): "+ exception);156 GnuBoat.displayMessage('<span class="error">Failed to upload map (XHR): '+ exception +'</span>'); 156 157 $("#mapTileUploadProgress").hide(); 157 158 $("#mapFileInput").show(); … … 167 168 GnuBoat.initialize = function() 168 169 { 170 $("#mapModusSelect").change(function(){ GnuBoat.private.mapModusChanged(); }); 169 171 $("#mapTileUploadProgress").hide(); 170 172 $("#logfilesReload").click(GnuBoat.logfilesLoad); … … 214 216 GnuBoat.private.renderControls = new THREE.OrbitControls( GnuBoat.private.renderCamera, GnuBoat.private.renderRenderer.domElement ); 215 217 GnuBoat.private.renderControls.zoomSpeed = 2; 216 217 218 219 var deep = new THREE.Color(0x347C7C);220 var shallow = new THREE.Color(0xBCD9D9);221 var size = 5;222 GnuBoat.private.renderDepthSteps = 50;223 224 var deltaR = (Math.max(deep.r, shallow.r) - Math.min(deep.r, shallow.r))/GnuBoat.private.renderDepthSteps;225 var deltaG = (Math.max(deep.g, shallow.g) - Math.min(deep.g, shallow.g))/GnuBoat.private.renderDepthSteps;226 var deltaB = (Math.max(deep.b, shallow.b) - Math.min(deep.b, shallow.b))/GnuBoat.private.renderDepthSteps;227 for(var i = 0; i < GnuBoat.private.renderDepthSteps; i++){228 var stepColor = new THREE.Color(Math.max(deep.r, shallow.r) - i * deltaR,229 Math.max(deep.g, shallow.g) - i * deltaG,230 Math.max(deep.b, shallow.b) - i * deltaB);231 GnuBoat.private.renderDepthMaterials.push(stepColor);232 }233 GnuBoat.private.renderDepthMaterials.push(shallow);234 218 } 235 219 … … 242 226 { 243 227 if(GnuBoat.private.serverBaseUrl == null){ 244 GnuBoat.displayMessage( "No server set/found");228 GnuBoat.displayMessage('<span class="error">No server set/found</span>'); 245 229 return; 246 230 } … … 250 234 if(GnuBoat.private.timerDisplay == null) 251 235 GnuBoat.private.timerDisplay = setInterval(GnuBoat.displayDataGet, 10000); 252 GnuBoat.logfilesLoad(); 236 GnuBoat.logfilesLoad(); 253 237 254 238 GnuBoat.private.animate(); … … 276 260 mapsMetadata: null, 277 261 mapBounds: null, 262 mapModusLive: true, 263 mapHotlineGradientDefault: { absolute: false, palette: { 0.0: 'green', 0.5: 'yellow', 1.0: 'red' } }, 278 264 dataMappings: { 279 265 speedthroughwater: {display: true, map: true, mapActive: false, titleLong: "Speed Through Water", titleShort: "STW", unit: "kts"}, 280 266 speedoverground: {display: true, map: true, mapActive: false, titleLong: "Speed Over Ground", titleShort: "SOG", unit: "kts"}, 281 waterdepth: {display: true, map: true, mapActive: true, titleLong: "Waterdepth", titleShort: "Depth", unit: "m"}, 267 waterdepth: { 268 display: true, map: true, mapActive: true, titleLong: "Waterdepth", titleShort: "Depth", unit: "m", 269 gradient: { 270 absolute: true, 271 palette: { 0: 'DarkBlue', 2: 'DodgerBlue', 6: 'LightBlue', 10: 'AliceBlue'}, 272 } 273 }, 282 274 watertemperature: {display: true, map: true, mapActive: false, titleLong: "Watertemperature", titleShort: "Water", unit: "°C"}, 283 275 gpsfix: {display: true, map: false, mapActive: false, titleLong: "GPS Fix", titleShort: "Fix", unit: ""}, … … 292 284 renderControls: null, 293 285 renderCloud: null, 294 renderDepthMaterials: [],295 renderDepthSteps: null,296 286 297 287 openLink: function(target) … … 302 292 displayDataSet: function(data) 303 293 { 294 // if(!Array.isArray(data) || data.length < 1){ 295 // console.log("No data array returned!"); 296 // console.log(data); 297 // return; 298 // } 299 if(("error" in data) && data["error"] == 1){ 300 GnuBoat.displayMessage('<span class="error">Failed to get display data and tracks: '+ data["errormessage"] +'</span>'); 301 return; 302 } 303 304 304 var keysDisplay = []; 305 305 for(var key in GnuBoat.private.dataMappings){ … … 307 307 keysDisplay.push(key); 308 308 } 309 if(!Array.isArray(data) && !(data instanceof Object)){ 310 console.log("No data array returned!"); 311 console.log(data); 312 return; 313 } 309 314 310 if(!("lastvalid" in data)){ 315 311 console.log("No last valid values given!"); … … 333 329 } 334 330 335 if(!("track" in data)){ 336 console.log("No track given!"); 337 } 338 else{ 339 if(GnuBoat.private.map == null){ 340 console.log("No map in use"); 341 } 342 else{ 343 var track = data["track"]; 344 var maximas = []; 345 var minimas = []; 346 var points = []; 347 var densityPoints = []; 348 349 var keysMap = []; 350 for(var key in GnuBoat.private.dataMappings){ 351 if(GnuBoat.private.dataMappings[key]["map"] === true) 352 keysMap.push(key); 353 } 354 for(var i = 0; i < keysMap.length; i++){ 355 if(keysMap[i] == "gpsfix") 356 continue; 357 points[keysMap[i]] = []; 358 } 359 360 // getting maximas, minimums for normalization and the tracks themselves 361 for(var time in track){ 362 for(var i = 0; i < keysMap.length; i++){ 363 var key = keysMap[i]; 364 if(key == "gpsfix") 365 continue; 366 if(!(key in maximas)) 367 maximas[key] = track[time][key] 368 else if(maximas[key] < track[time][key]) 369 maximas[key] = track[time][key]; 370 if(!(key in minimas)) 371 minimas[key] = track[time][key] 372 else if(minimas[key] > track[time][key]) 373 minimas[key] = track[time][key]; 374 points[key].push(new L.latLng(track[time]["latitude"], track[time]["longitude"], track[time][key])); 375 densityPoints.push({latitude: track[time]["latitude"], longitude: track[time]["longitude"], depth: track[time]["waterdepth"]}); 376 } 377 } 378 for(var i = 0; i < keysMap.length; i++){ 379 var key = keysMap[i]; 380 if(key == "gpsfix") 381 continue; 382 if(points[key].length > 0){ 383 if(key in GnuBoat.private.mapPolylines) 384 GnuBoat.private.mapPolylines[key].setLatLngs(points[key]); 385 else{ 386 GnuBoat.private.mapPolylines[key] = L.hotline(points[key], {weight: 3, outlineWidth: 0, min: minimas[key], max: maximas[key]}); 387 if(GnuBoat.private.mapControl){ 388 var name = GnuBoat.private.dataMappings[key]["titleLong"] +" in "+ GnuBoat.private.dataMappings[key]["unit"] +" ("+ GnuBoat.private.dataMappings[key]["titleShort"] +")"; 389 GnuBoat.private.mapControl.addOverlay(GnuBoat.private.mapPolylines[key], name); 390 } 391 if(GnuBoat.private.dataMappings[key]["mapActive"] === true) 392 GnuBoat.private.mapPolylines[key].addTo(GnuBoat.private.map); 393 } 394 } 395 } 396 GnuBoat.private.drawDensityEstimation(densityPoints, maximas["waterdepth"], minimas["waterdepth"]); 397 } 398 } 331 // map displays logged data 332 if(!GnuBoat.private.mapModusLive) 333 return; 334 else if(!("track" in data)){ 335 console.log("No track given!"); 336 return; 337 } 338 GnuBoat.private.mapAddTracks(data["track"]); 399 339 }, 400 340 … … 432 372 // only initialize the map (viewport) once 433 373 GnuBoat.private.map = L.map('mapViewport'); 374 GnuBoat.private.map.on('overlayadd', function(layerObject){ GnuBoat.private.mapOverlayLegendSwitch(layerObject.layer); }); 375 GnuBoat.private.map.on('overlayremove', function(layerObject){ GnuBoat.private.mapOverlayLegendSwitch(layerObject.layer); }); 434 376 } 435 377 GnuBoat.private.map.setView([latitudeCenter, longitudeCenter], mapZoomStart); … … 527 469 }, 528 470 529 drawDensityEstimation: function(densityPoints, maximum, minimum) 530 { 471 drawDensityEstimation: function(densityPoints, gradient, maximum, minimum) 472 { 473 var colors = GnuBoat.private.gradientToRenderColors(gradient, maximum, minimum); 474 // converting all indizes into numbers to sort them correctly 475 // in descending order e.g. 10, 2, 1, 0 and not 2, 10, 1, 0 476 var colorsIndizes = Object.getOwnPropertyNames(colors); 477 colorsIndizes.sort(function(a, b){ 478 a = +a; 479 b = +b; 480 return a-b; 481 }); 482 var colorsCount = colorsIndizes.length; 483 531 484 var material = new THREE.PointsMaterial({vertexColors: THREE.VertexColors, size: 5}); 532 485 var geometry = new THREE.Geometry(); … … 538 491 var mercator = GnuBoat.private.mercator(densityPoints[i].latitude, densityPoints[i].longitude); 539 492 var vertex = new THREE.Vector3(mercator.x - mercatorSouthWest.x, mercator.y - mercatorSouthWest.y, (densityPoints[i].depth * -1) + maximum); 493 var step = (densityPoints[i].depth - minimum)/(maximum-minimum); 540 494 var color = new THREE.Color(0x000000); 541 if(GnuBoat.private.renderDepthSteps != null){ 542 var step = Math.floor((densityPoints[i].depth - minimum)/((maximum-minimum)/GnuBoat.private.renderDepthSteps)); 543 if(step >= 0 && step < GnuBoat.private.renderDepthMaterials.length) 544 color = GnuBoat.private.renderDepthMaterials[step]; 495 for(var j = 0; j < colorsCount; j++){ 496 if(j < colorsCount - 1) 497 color = colors[colorsIndizes[j]]; 498 if(step <= colorsIndizes[j+1]){ 499 color = colors[colorsIndizes[j]]; 500 break; 501 } 545 502 } 546 503 geometry.vertices.push(vertex); … … 578 535 return result; 579 536 }, 537 538 updateMapModus: function(data) 539 { 540 var selected = $("#mapModusSelect").val(); 541 $("#mapModusSelect").empty(); 542 var selectedFound = false; 543 if(selected != null && Array.isArray(data)){ 544 data.forEach(function(value, index){ 545 if(value == selected) 546 selectedFound = true; 547 }); 548 } 549 var selectedString = ""; 550 if(!selectedFound) 551 selectedString = " selected"; 552 $('<option value="live"'+ selectedString +'>Live View</option>').appendTo("#mapModusSelect"); 553 if(!Array.isArray(data) || data.length < 1){ 554 console.log(data); 555 return; 556 } 557 if(("error" in data) && data["error"] == 1){ 558 GnuBoat.displayMessage('<span class="error">Failed to upload map: '+ data["errormessage"] +'</span>'); 559 return; 560 } 561 data.forEach(function(value, index){ 562 var selectedString = ""; 563 if(value == selected) 564 selectedString = " selected"; 565 $("<option value=\""+ value +"\""+ selected +">"+ value +"</option>").appendTo("#mapModusSelect"); 566 }); 567 }, 568 569 mapModusChanged: function() 570 { 571 var modus = $("#mapModusSelect").val(); 572 // live modus is automatically activated on displayDataSet 573 if(modus == "live"){ 574 GnuBoat.private.mapModusLive = true; 575 return; 576 } 577 // remove overlays 578 if(GnuBoat.private.mapControl != null){ 579 for(var key in GnuBoat.private.dataMappings){ 580 if(GnuBoat.private.dataMappings[key]["map"] === true) 581 if(key in GnuBoat.private.mapPolylines){ 582 GnuBoat.private.mapControl.removeLayer(GnuBoat.private.mapPolylines[key]); 583 GnuBoat.private.mapPolylines[key].remove(); 584 delete GnuBoat.private.mapPolylines[key]; 585 } 586 } 587 } 588 GnuBoat.private.mapModusLive = false; 589 $.post({ 590 url: GnuBoat.private.serverBaseUrl +'?request=replay', 591 data: { logfile: modus }, 592 success: function(data){ 593 // if(!Array.isArray(data) || data.length < 1){ 594 // console.log("No data array returned!"); 595 // console.log(data); 596 // return; 597 // } 598 if(("error" in data) && data["error"] == 1){ 599 GnuBoat.displayMessage('<span class="error">Failed to get logged tracks: '+ data["errormessage"] +'</span>'); 600 return; 601 } 602 if(!("track" in data)){ 603 console.log("No track given!"); 604 return; 605 } 606 GnuBoat.private.mapAddTracks(data["track"]); 607 } 608 }); 609 }, 610 611 mapAddTracks: function(track) 612 { 613 if(GnuBoat.private.map == null){ 614 console.log("No map in use"); 615 return; 616 } 617 618 $("#mapLegend").empty(); 619 var maximas = []; 620 var minimas = []; 621 var points = []; 622 var densityPoints = []; 623 624 var keysMap = []; 625 for(var key in GnuBoat.private.dataMappings){ 626 if(GnuBoat.private.dataMappings[key]["map"] === true) 627 keysMap.push(key); 628 } 629 for(var i = 0; i < keysMap.length; i++){ 630 points[keysMap[i]] = []; 631 } 632 633 // getting maximas, minimums for normalization and the tracks themselves 634 for(var time in track){ 635 for(var i = 0; i < keysMap.length; i++){ 636 var key = keysMap[i]; 637 var value = track[time][key]; 638 if(!$.isNumeric(value)) 639 continue; 640 if(!(key in maximas)) 641 maximas[key] = value 642 else if(maximas[key] < value) 643 maximas[key] = value; 644 if(!(key in minimas)) 645 minimas[key] = value 646 else if(minimas[key] > value) 647 minimas[key] = value; 648 points[key].push(new L.latLng(track[time]["latitude"], track[time]["longitude"], value)); 649 if(key == "waterdepth") 650 densityPoints.push({latitude: track[time]["latitude"], longitude: track[time]["longitude"], depth: value}); 651 } 652 } 653 for(var i = 0; i < keysMap.length; i++){ 654 var key = keysMap[i]; 655 if(points[key].length > 0){ 656 var palette = GnuBoat.private.mapHotlineGradientDefault.palette; 657 var paletteLegend = GnuBoat.private.mapHotlineGradientDefault.palette; 658 if("gradient" in GnuBoat.private.dataMappings[key]){ 659 palette = GnuBoat.private.gradientToPalette(GnuBoat.private.dataMappings[key]["gradient"], maximas[key], minimas[key]); 660 // use original palette, to use absolute values, if possible 661 paletteLegend = GnuBoat.private.dataMappings[key]["gradient"]["palette"]; 662 } 663 664 var legendTable = $('<table id="'+ key +'" class="hidden"></table>'); 665 $("<tr><th colspan=2>"+ GnuBoat.private.dataMappings[key]["titleShort"] +" in "+ GnuBoat.private.dataMappings[key]["unit"] +"</th></tr>").appendTo(legendTable); 666 $("<tr><th>Level</th><th>Color</th></tr>").appendTo(legendTable); 667 // converting all indizes into numbers to sort them correctly 668 // e.g. 0, 1, 2, 10 and not 0, 1, 10, 2 669 var indizes = Object.getOwnPropertyNames(paletteLegend); 670 indizes.sort(function(a, b){ 671 a = +a; 672 b = +b; 673 return a-b; 674 }); 675 for(var j=0; j < indizes.length; j++){ 676 var index = indizes[j]; 677 $('<tr><td class="level">'+ index.toString() +'</td><td style="background-color: '+ paletteLegend[index] +'"></td></tr>').appendTo(legendTable); 678 } 679 $('<tr><td colspan="2">Extrema: '+ maximas[key].toString() +' / '+ minimas[key].toString() +'</td></tr>').appendTo(legendTable); 680 681 var hotlineOptions = { 682 weight: 3, 683 outlineWidth: 0, 684 min: minimas[key], 685 max: maximas[key], 686 palette: palette, 687 }; 688 689 legendTable.appendTo("#mapLegend"); 690 691 if(key in GnuBoat.private.mapPolylines){ 692 GnuBoat.private.mapPolylines[key].setStyle(hotlineOptions); 693 GnuBoat.private.mapPolylines[key].setLatLngs(points[key]); 694 if(GnuBoat.private.map.hasLayer(GnuBoat.private.mapPolylines[key])) 695 GnuBoat.private.mapOverlayLegendSwitch(GnuBoat.private.mapPolylines[key]); 696 GnuBoat.private.mapPolylines[key].unbindPopup(); 697 } 698 else{ 699 GnuBoat.private.mapPolylines[key] = L.hotline(points[key], hotlineOptions); 700 if(GnuBoat.private.mapControl){ 701 var name = GnuBoat.private.dataMappings[key]["titleLong"] +" in "+ GnuBoat.private.dataMappings[key]["unit"] +" ("+ GnuBoat.private.dataMappings[key]["titleShort"] +")"; 702 GnuBoat.private.mapControl.addOverlay(GnuBoat.private.mapPolylines[key], name); 703 } 704 if(GnuBoat.private.dataMappings[key]["mapActive"] === true) 705 GnuBoat.private.mapPolylines[key].addTo(GnuBoat.private.map); 706 } 707 GnuBoat.private.mapPolylines[key].bindPopup(legendTable[0].outerHTML); 708 } 709 } 710 var gradient = GnuBoat.private.mapHotlineGradientDefault.palette; 711 if("gradient" in GnuBoat.private.dataMappings["waterdepth"]) 712 gradient = GnuBoat.private.dataMappings["waterdepth"]["gradient"]; 713 GnuBoat.private.drawDensityEstimation(densityPoints, gradient, maximas["waterdepth"], minimas["waterdepth"]); 714 }, 715 716 gradientToPalette: function(gradient, maximum, minimum) 717 { 718 if(!("palette" in gradient)){ 719 return GnuBoat.private.mapHotlineGradientDefault.palette; 720 } 721 if(!("absolute" in gradient) || !gradient.absolute){ 722 // palette is already relative 723 return gradient.palette; 724 } 725 var range = maximum - minimum; 726 if(range == 0){ 727 console.log("Range is zero --> Could not make gradient relative"); 728 return GnuBoat.private.mapHotlineGradientDefault.palette; 729 } 730 var palette = {}; 731 var addedStop = false; 732 for(var indexAbs in gradient.palette){ 733 var indexRel = (indexAbs - minimum)/range; 734 if(indexRel < 0){ 735 // add the nearest minimum value (which might be configured smaller than minimum) 736 indexRel = 0; 737 palette[indexRel] = gradient.palette[indexAbs]; 738 addedStop = true; 739 } 740 else if(indexRel < 1){ 741 palette[indexRel] = gradient.palette[indexAbs]; 742 addedStop = true; 743 } 744 else{ 745 // add first index > 1 as the maximum value at 1 746 indexRel = 1; 747 palette[indexRel] = gradient.palette[indexAbs]; 748 addedStop = true; 749 break; 750 } 751 } 752 if(!addedStop) 753 return GnuBoat.private.mapHotlineGradientDefault.palette; 754 return palette; 755 }, 756 757 gradientToRenderColors: function(gradient, maximum, minimum) 758 { 759 var paletteRelative = GnuBoat.private.gradientToPalette(gradient, maximum, minimum); 760 761 var colors = {}; 762 for(var index in paletteRelative) 763 colors[index] = new THREE.Color(paletteRelative[index].toLowerCase()); 764 765 return colors; 766 }, 767 768 mapOverlayLegendSwitch: function(layer) 769 { 770 var overlayKey = null; 771 for(var key in GnuBoat.private.mapPolylines){ 772 if(GnuBoat.private.mapPolylines.hasOwnProperty(key)){ 773 if(GnuBoat.private.mapPolylines[key] === layer){ 774 overlayKey = key; 775 break; 776 } 777 } 778 } 779 // ECMAScript 6 780 // var overlayKey = Object.keys(GnuBoat.private.mapPolylines).find(key => GnuBoat.private.mapPolylines[key] === overlay); 781 if(overlayKey == null) 782 return; 783 if(overlayKey){ 784 $("#mapLegend #"+ overlayKey).toggleClass("hidden"); 785 } 786 }, 580 787 }; -
src/webapp/webservice/inc/GnuBoat/Config.php
r949f66d r944372e 26 26 public function __construct() 27 27 { 28 $configFile = __DIR__ ."/../ config/config.php";28 $configFile = __DIR__ ."/../../config/config.php"; 29 29 if(file_exists($configFile)){ 30 30 include($configFile); … … 51 51 { 52 52 if(array_key_exists("datadirectory", $this->_config)) 53 return addTrailingSlash($this->_config["datadirectory"]);53 return $this->addTrailingSlash($this->_config["datadirectory"]); 54 54 return "/var/lib/gnuboat/"; 55 55 } … … 58 58 { 59 59 if(array_key_exists("logdirectory", $this->_config)) 60 return addTrailingSlash($this->_config["logdirectory"]);60 return $this->addTrailingSlash($this->_config["logdirectory"]); 61 61 return "/var/log/gnuboat/"; 62 62 } -
src/webapp/webservice/inc/GnuBoat/Service.php
r949f66d r944372e 44 44 $this->process(); 45 45 } 46 47 public static function errorStatic($message, $additionalContent = array(), $debug) 48 { 49 error_log($message); 50 if($debug > 0) 51 print $message ."\n"; 52 $result = ["error" => 1, "errormessage" => $message]; 53 Service::outputStatic(array_merge($result, $additionalContent), $debug); 54 } 55 56 public static function outputStatic($content, $debug) 57 { 58 header('Content-Type: application/json'); 59 if($debug > 0){ 60 echo json_encode($content, JSON_PRETTY_PRINT) ."\n"; 61 } 62 else{ 63 echo json_encode($content) ."\n"; 64 } 65 } 66 67 protected function error($message, $additionalContent = array()) 68 { 69 Service::errorStatic($message, $additionalContent, $this->debug()); 70 } 71 72 protected function output($content) 73 { 74 Service::outputStatic($content, $this->debug()); 75 } 46 76 47 77 /** -
src/webapp/webservice/inc/GnuBoat/ServiceData.php
r949f66d r944372e 29 29 $this->_configRound = array 30 30 ( 31 "latitude" => 5,32 "longitude" => 5,31 "latitude" => 4, 32 "longitude" => 4, 33 33 "speedthroughwater" => 1, 34 34 "speedoverground" => 1, 35 "courseoverground" => 1, 35 36 "waterdepth" => 1, 36 37 "watertemperature" => 1, … … 48 49 $result["track"] = array(); 49 50 50 if(!file_exists($dbFile)){ 51 echo json_encode(""); 52 if($debug > 0) 53 echo "Database file ". $dbFile ." does not exist!"; 54 error_log("Database file ". $dbFile ." does not exist"); 55 exit; 56 } 51 if(!file_exists($dbFile)) 52 return $this->error("Database file ". $dbFile ." does not exist"); 53 57 54 // Fetch entries of the last 30s with maximum (available) resolution of 2s 58 55 $this->addRrdData($dbFile, "2", "240", $result, $lastValid); 59 if($lastValid ){60 $result["lastvalid"] = $lastValid ;56 if($lastValid !== false){ 57 $result["lastvalid"] = $lastValid->toArray(); 61 58 } 62 59 // Fetch entries of the last 1h with maximum (available) resolution of 10s … … 65 62 $this->addRrdData($dbFile, "60", "86400", $result, $lastTime); 66 63 67 if($debug > 0){ 68 echo json_encode($result, JSON_PRETTY_PRINT) ."\n"; 69 } 70 else{ 71 header('Content-Type: application/json'); 72 echo json_encode($result) ."\n"; 73 } 64 return $this->output($result); 74 65 } 75 66 … … 82 73 $data = rrd_fetch($dbFile, array("AVERAGE", "--resolution", $interval, "--start", $startTime, "--end", $endTime)); 83 74 // $data = rrd_fetch($dbFile, array("AVERAGE", "--resolution", $interval, "--start", "-". $period, "--end", "start+". $period, "--align-start")); 84 if($data === false){ 85 echo json_encode($result); 86 $message = "Failure reading rrd database ". $dbFile .": ". rrd_error(); 87 if($debug > 0) 88 echo $message; 89 else 90 error_log($message); 91 return; 92 } 75 if($data === false) 76 return $this->error("Failure reading rrd database ". $dbFile .": ". rrd_error(), $result); 93 77 94 78 if($debug > 2){ 95 echo "<pre>";96 79 var_dump($data); 97 echo "</pre>";98 80 } 99 81 … … 102 84 // transform them into json format 103 85 $i = 0; 104 $lastValid = -1;86 $lastValid = false; 105 87 $keys = array_keys($data); 106 88 $keyTimeframes = $keys[0]; 107 89 $itemCount = count($keys); 108 if($itemCount < 0 ){ 109 error_log("No keys in fetched rrd data from ". $dbFile); 110 echo json_encode(""); 111 exit; 112 } 90 if($itemCount < 0 ) 91 return $this->error("No keys in fetched rrd data from ". $dbFile); 92 113 93 $timeframesCount = count($data[$keyTimeframes]); 114 if($debug > 0){115 e cho "<p>Variables: ". $itemCount ."; Timeframes: ". $timeframesCount ."</p>\n";94 if($debug > 1){ 95 error_log("Variables: ". $itemCount ."; Timeframes: ". $timeframesCount); 116 96 } 117 97 foreach($data[$keys[0]] as $timeframe => $value){ 118 $allValid = true; 119 $gpsFix = false; 120 $tmp = array(); 98 $tmp = new TrackItem($timeframe); 121 99 foreach($keys as $key){ 122 if($key == "gpsfix"){ 123 switch($data[$key][$timeframe]){ 124 case 2: 125 $tmp[$key] = "2D"; 126 $gpsFix = true; 127 break; 128 case 3: 129 $tmp[$key] = "3D"; 130 $gpsFix = true; 131 break; 132 default: 133 $tmp[$key] = "-"; 134 } 135 } 136 else{ 137 $tmp[$key] = $data[$key][$timeframe]; 138 if(!is_numeric($tmp[$key]) || is_nan($tmp[$key])){ 139 $allValid = false; 140 if($debug > 1){ 141 echo "Invalid value ". $key ." (". $tmp[$key] .") at time ". $timeframe ."<br/>"; 142 } 143 } 144 elseif(array_key_exists($key, $this->_configRound) && is_integer($this->_configRound[$key])) 145 $tmp[$key] = round($tmp[$key], $this->_configRound[$key]); 146 } 100 $value = $data[$key][$timeframe]; 101 if(array_key_exists($key, $this->_configRound) && is_integer($this->_configRound[$key])) 102 $value = round($value, $this->_configRound[$key]); 103 if(!$tmp->setProperty($key, $value) && $debug > 1) 104 error_log("Coult not set property ". $key ." to value ". $value ." at ". $timeframe); 147 105 } 148 106 // only add the timeframe to the track, if the values are valid and we had a gps fix at that time 149 if($ allValid){107 if($tmp->isValid()){ 150 108 $lastValid = $tmp; 151 if($ gpsFix){109 if($tmp->gpsFixed()){ 152 110 if(!array_key_exists($timeframe, $result["track"])){ 153 $result["track"][$timeframe] = $tmp ;111 $result["track"][$timeframe] = $tmp->toArray(); 154 112 } 155 113 } -
src/webapp/webservice/inc/GnuBoat/ServiceLogFiles.php
r949f66d r944372e 32 32 $debug = $this->debug(); 33 33 $config = new Config(); 34 if($debug > 1) 35 print "Log directory: ". $config->logDirectory() ."\n"; 34 36 35 37 if(!array_key_exists("logfilesSelected", $_POST)){ … … 37 39 $files = glob($config->logDirectory() ."*.log"); 38 40 array_walk($files, 'GnuBoat\ServiceLogFiles::stripLogDirectory'); 41 return $this->output($files); 42 } 39 43 40 header('Content-Type: application/json'); 41 if($debug > 0){ 42 echo json_encode($files, JSON_PRETTY_PRINT) ."\n"; 44 // prepare a download of available log files 45 $files = $_POST["logfilesSelected"]; 46 if(count($files) < 1) 47 return $this->error("No logfile selected"); 48 elseif(count($files) == 1){ 49 $content = file_get_contents($config->logDirectory() . $files[0]); 50 if($content === false){ 51 echo "<html><head></head><body>Failed to read logfile ". $files[0] ."</body></html>"; 43 52 } 44 else{ 45 echo json_encode($files) ."\n"; 46 } 53 54 header('Content-Type: text/plain'); 55 header('Content-disposition: attachment; filename="'. $files[0] .'"'); 56 header('Content-Length: ' . filesize($config->logDirectory() . $files[0])); 57 echo $content; 47 58 } 48 59 else{ 49 // prepare a download of available log files 50 $files = $_POST["logfilesSelected"]; 51 if(count($files) < 1){ 60 $date = new \DateTime('NOW'); 61 $archiveName = "gnuboat-logs-". $date->format("Y-m-d"); 62 63 // provide files as zip file 64 $tmpArchive = tempnam(sys_get_temp_dir(), $archiveName); 65 $zip = new \ZipArchive(); 66 if($zip->open($tmpArchive, \ZipArchive::CREATE) !== TRUE){ 67 echo "<html><head></head><body>Failed to create zip file</body></html>"; 52 68 return; 53 69 } 54 elseif(count($files) == 1){ 55 $content = file_get_contents($config->logDirectory() . $files[0]); 56 if($content === false){ 57 echo "<html><head></head><body>Failed to read logfile ". $files[0] ."</body></html>"; 58 } 59 60 header('Content-Type: text/plain'); 61 header('Content-disposition: attachment; filename="'. $files[0] .'"'); 62 header('Content-Length: ' . filesize($config->logDirectory() . $files[0])); 63 echo $content; 64 } 65 else{ 66 $date = new \DateTime('NOW'); 67 $archiveName = "gnuboat-logs-". $date->format("Y-m-d"); 68 69 // provide files as zip file 70 $tmpArchive = tempnam(sys_get_temp_dir(), $archiveName); 71 $zip = new \ZipArchive(); 72 if($zip->open($tmpArchive, \ZipArchive::CREATE) !== TRUE){ 73 echo "<html><head></head><body>Failed to create zip file</body></html>"; 70 foreach($files as $file){ 71 if($zip->addFile($config->logDirectory() . $file, $archiveName ."/". $file) !== true){ 72 $zip->close(); 73 echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>"; 74 74 return; 75 75 } 76 foreach($files as $file){77 if($zip->addFile($config->logDirectory() . $file, $archiveName ."/". $file) !== true){78 $zip->close();79 echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>";80 return;81 }82 }83 if($zip->close() !== true){84 echo "<html><head></head><body>Failed to save zip file</body></html>";85 return;86 }87 88 echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>";89 90 //Send zip folder91 while (ob_get_level()) {92 ob_end_clean();93 }94 ob_start();95 header('Content-Type: application/zip');96 header('Content-Transfer-Encoding: Binary');97 header('Content-disposition: attachment; filename=' . $archiveName . '.zip');98 header('Content-Length: ' . filesize($tmpArchive));99 ob_flush();100 ob_clean();101 readfile($tmpArchive);102 unlink($tmpArchive);103 return;104 76 } 77 if($zip->close() !== true){ 78 echo "<html><head></head><body>Failed to save zip file</body></html>"; 79 return; 80 } 81 82 echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>"; 83 84 //Send zip folder 85 while (ob_get_level()) { 86 ob_end_clean(); 87 } 88 ob_start(); 89 header('Content-Type: application/zip'); 90 header('Content-Transfer-Encoding: Binary'); 91 header('Content-disposition: attachment; filename=' . $archiveName . '.zip'); 92 header('Content-Length: ' . filesize($tmpArchive)); 93 ob_flush(); 94 ob_clean(); 95 readfile($tmpArchive); 96 unlink($tmpArchive); 97 return; 105 98 } 106 99 } -
src/webapp/webservice/inc/GnuBoat/ServiceMap.php
r949f66d r944372e 30 30 protected function process() 31 31 { 32 header('Content-type: application/json'); 32 if(!array_key_exists("mapName", $_POST)) 33 return $this->error("Please specify map name (no value)"); 33 34 34 $result["error"] = 1;35 $result["errormessage"] = "Unknown Error";36 37 if(!array_key_exists("mapName", $_POST)){38 $result["error"] = 1;39 $result["errormessage"] = "Please specify map name (no value)";40 echo json_encode($result);41 return;42 }43 35 $mapName = $_POST["mapName"]; 44 if(empty($mapName) || $mapName == ""){ 45 $result["error"] = 1; 46 $result["errormessage"] = "Please specifiy map name (empty value)"; 47 echo json_encode($result); 48 return; 49 } 36 if(empty($mapName) || $mapName == "") 37 return $this->error("Please specifiy map name (empty value)"); 50 38 51 39 $mapDirectory = __DIR__ ."/../../maps"; 52 if(!array_key_exists("mapFile", $_FILES)){ 53 $result["error"] = 1; 54 $result["errormessage"] = "No map file recieved"; 55 echo json_encode($result); 56 return; 57 } 58 if (!isset($_FILES['mapFile']['error']) || is_array($_FILES['mapFile']['error'])){ 59 $result["error"] = 1; 60 $result["errormessage"] = "Invalid parameters"; 61 echo json_encode($result); 62 return; 63 } 40 if(!array_key_exists("mapFile", $_FILES)) 41 return $this->error("No map file recieved"); 42 43 if (!isset($_FILES['mapFile']['error']) || is_array($_FILES['mapFile']['error'])) 44 return $this->error("Invalid parameters"); 45 64 46 switch ($_FILES['mapFile']['error']) { 65 47 case UPLOAD_ERR_OK: 66 48 break; 67 49 case UPLOAD_ERR_NO_FILE: 68 $result["error"] = 1; 69 $result["errormessage"] = "No file sent"; 70 echo json_encode($result); 71 return; 50 return $this->error("No file sent"); 72 51 case UPLOAD_ERR_INI_SIZE: 73 52 case UPLOAD_ERR_FORM_SIZE: 74 $result["error"] = 1; 75 $result["errormessage"] = "Exceeded filesize limit."; 76 echo json_encode($result); 77 return; 53 return $this->error("Exceeded filesize limit."); 78 54 default: 79 $result["error"] = 1; 80 $result["errormessage"] = "Unknown PHP Error"; 81 echo json_encode($result); 82 return; 55 return $this->error("Unknown PHP Error"); 83 56 } 84 57 $mapFileName = $mapDirectory ."/". sha1_file($_FILES['mapFile']['tmp_name']) .".mbtiles"; 85 58 if(move_uploaded_file($_FILES['mapFile']['tmp_name'], $mapFileName)){ 86 if(!chmod($mapFileName, 0755)){ 87 $result["error"] = 1; 88 $result["errormessage"] = "Could not change permissions of the map file"; 89 } 90 else{ 91 // correct map metadata 92 $resultRename = $this->setMapName($mapFileName, $mapName); 93 if($resultRename[0] === true){ 94 $result["error"] = 0; 95 $result["errormessage"] = ""; 96 } 97 else{ 98 $result["error"] = 1; 99 $result["errormessage"] = $resultRename[1]; 100 } 101 } 59 if(!chmod($mapFileName, 0755)) 60 return $this->error("Could not change permissions of the map file"); 61 // correct map metadata 62 $resultRename = $this->setMapName($mapFileName, $mapName); 63 if($resultRename[0] === true) 64 return $this->output(["error" => 0, "errormessage" => ""]); 65 66 return $this->error($resultRename[1]); 102 67 } 103 else { 104 $result["error"] = 1; 105 $result["errormessage"] = "Could not move map in place"; 106 } 107 echo json_encode($result); 68 else 69 return $this->error("Could not move map in place"); 108 70 } 109 71 -
src/webapp/webservice/inc/GnuBoat/ServiceShutdown.php
r949f66d r944372e 36 36 if($handle === false){ 37 37 $message = "Could not create file (". $config->shutdownRequestFile() .") to indicate shutdown to the daemon."; 38 error_log($message); 39 $result["shutdownstart"] = -1; 40 $result["errormessage"] = $message; 41 } 42 else{ 43 $shutdownTime = new \DateTime('NOW'); 44 $shutdownTime->modify("+15 seconds"); 45 fwrite($handle, $shutdownTime->format(\DateTime::ATOM)); 46 $result["shutdownstart"] = $shutdownTime->format(\DateTime::ATOM); 38 return $this->error($message, ["shutdownstart" => -1]); 47 39 } 48 40 49 header('Content-Type: application/json'); 50 if($debug > 0){ 51 echo json_encode($result, JSON_PRETTY_PRINT) ."\n"; 52 } 53 else{ 54 echo json_encode($result) ."\n"; 55 } 41 $shutdownTime = new \DateTime('NOW'); 42 $shutdownTime->modify("+15 seconds"); 43 fwrite($handle, $shutdownTime->format(\DateTime::ATOM)); 44 fclose($handle); 45 $result["shutdownstart"] = $shutdownTime->format(\DateTime::ATOM); 46 $this->output($result); 56 47 } 57 48 } -
src/webapp/webservice/inc/GnuBoat/Webservice.php
r949f66d r944372e 23 23 class WebService 24 24 { 25 function __construct( )25 function __construct($debug) 26 26 { 27 27 $this->_requests = array(); … … 30 30 $this->_requests["logfiles"] = "GnuBoat\ServiceLogFiles"; 31 31 $this->_requests["map"] = "GnuBoat\ServiceMap"; 32 $this->_requests["replay"] = "GnuBoat\ServiceReplay"; 33 34 $this->_debug = $debug; 32 35 } 33 36 34 37 public function process() 35 38 { 36 $debug = 0;37 if(is_array($_GET) && array_key_exists("debug", $_GET))38 $debug = $_GET["debug"];39 40 39 $request = array_keys($this->_requests)[0]; 41 40 if(is_array($_GET) && array_key_exists("request", $_GET)){ … … 44 43 45 44 if(!array_key_exists($request, $this->_requests)){ 46 $result["error"] = 1; 47 $result["errormessage"] = "Request ". $request ." not implemented"; 48 49 header('Content-Type: application/json'); 50 echo json_encode($result) ."\n"; 51 return; 45 return Service::errorStatic("Request ". $request ." not implemented", $this->_debug); 52 46 } 53 54 call_user_func(array(new $this->_requests[$request], "processRequest"), $ debug);47 48 call_user_func(array(new $this->_requests[$request], "processRequest"), $this->_debug); 55 49 } 56 50 57 51 private $_requests; 52 private $_debug; 58 53 } 59 54 -
src/webapp/webservice/inc/autoloader.php
r949f66d r944372e 25 25 } 26 26 27 function canClassBeLoaded($class) { 28 $parts = explode('\\', $class); 29 $fileName = __DIR__ ."/". join("/", $parts) .".php"; 30 return file_exists($fileName); 31 } 32 27 33 spl_autoload_register("gnuboatAutoloader"); 28 34 -
src/webapp/webservice/index.php
r949f66d r944372e 19 19 require_once(__DIR__ ."/inc/autoloader.php"); 20 20 21 $webservice = new GnuBoat\Webservice(); 21 $debug = 0; 22 if(array_key_exists("debug", $_GET)) 23 $debug = $_GET["debug"]; 24 25 $webservice = new GnuBoat\Webservice($debug); 22 26 $webservice->process(); 23 27 -
src/webapp/webservice/tests/ServiceTest.php
r949f66d r944372e 20 20 // declare(Strict_types=1); 21 21 22 namespace GnuBoat; 23 22 24 /** 23 * @brief Covers index.php tests25 * @brief Covers Service.php tests 24 26 */ 25 final class ServiceTest extends PHPUnit_Framework_TestCase27 final class ServiceTest extends \PHPUnit_Framework_TestCase 26 28 { 27 /**28 * @runInSeparateProcess29 */30 29 public function testData() 31 30 { 32 $webservice = new GnuBoat\Webservice();33 $this->assertInstanceOf( GnuBoat\Webservice::class, $webservice);34 $_ POST["request"] = "data";31 $webservice = new Webservice(0); 32 $this->assertInstanceOf(Webservice::class, $webservice); 33 $_GET["request"] = "data"; 35 34 $webservice->process(); 36 35 } 37 36 38 /**39 * @runInSeparateProcess40 */41 37 public function testLogFiles() 42 38 { 43 $webservice = new GnuBoat\Webservice();44 $this->assertInstanceOf( GnuBoat\Webservice::class, $webservice);45 $_ POST["request"] = "logfiles";39 $webservice = new Webservice(0); 40 $this->assertInstanceOf(Webservice::class, $webservice); 41 $_GET["request"] = "logfiles"; 46 42 $webservice->process(); 47 43 } 48 44 49 /**50 * @runInSeparateProcess51 */52 45 public function testShutdown() 53 46 { 54 $webservice = new GnuBoat\Webservice();55 $this->assertInstanceOf( GnuBoat\Webservice::class, $webservice);56 $_ POST["request"] = "shutdown";47 $webservice = new Webservice(0); 48 $this->assertInstanceOf(Webservice::class, $webservice); 49 $_GET["request"] = "shutdown"; 57 50 $webservice->process(); 58 51 } 59 60 /** 61 * @runInSeparateProcess 62 */ 52 63 53 public function testMap() 64 54 { 65 $webservice = new GnuBoat\Webservice();66 $this->assertInstanceOf( GnuBoat\Webservice::class, $webservice);67 $_ POST["request"] = "map";55 $webservice = new Webservice(0); 56 $this->assertInstanceOf(Webservice::class, $webservice); 57 $_GET["request"] = "map"; 68 58 $webservice->process(); 59 } 60 61 public function testReplay() 62 { 63 $webservice = new Webservice(0); 64 $_GET["request"] = "replay"; 65 $_POST["logfile"] = "replay-test.log"; 66 $webservice->process(); 67 $output = $this->getActualOutput(); 68 $this->assertJsonStringEqualsJsonString('{"track":{"1503767412":{"latitude":10.001,"longitude":1.001,"speedthroughwater":"-","speedoverground":11,"courseoverground":21,"waterdepth":"-","watertemperature":"-","gpsfix":"-"},"1503767413":{"latitude":20.002,"longitude":2.002,"speedthroughwater":"-","speedoverground":12,"courseoverground":22,"waterdepth":"-","watertemperature":"-","gpsfix":"-"},"1503767414":{"latitude":30.003,"longitude":3.003,"speedthroughwater":"-","speedoverground":13,"courseoverground":23,"waterdepth":1,"watertemperature":21,"gpsfix":"-"},"1503767415":{"latitude":40.004,"longitude":4.004,"speedthroughwater":"-","speedoverground":14,"courseoverground":24,"waterdepth":2,"watertemperature":22,"gpsfix":"-"},"1503767416":{"latitude":50.005,"longitude":5.005,"speedthroughwater":"-","speedoverground":15,"courseoverground":25,"waterdepth":3,"watertemperature":23,"gpsfix":"-"}}}', $output); 69 69 } 70 70 } 71 71 72 function error_log($msg) 73 { 74 echo "ERR GnuBoat: ". $msg ."\n"; 75 } 76 72 77 ?>
Note:
See TracChangeset
for help on using the changeset viewer.
