- Timestamp:
- Aug 29, 2017, 6:19:00 PM (9 years ago)
- Branches:
- 0.5, debian/bullseye, debian/jessie, master
- Children:
- 89c510f
- Parents:
- fc63b30
- Location:
- src/webapp
- Files:
-
- 3 added
- 19 edited
-
build.xml (modified) (1 diff)
-
webclient/index.html (modified) (1 diff)
-
webclient/js/GnuBoat.js (modified) (16 diffs)
-
webservice/inc/GnuBoat/Config.php (modified) (3 diffs)
-
webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Dpt.php (modified) (1 diff)
-
webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Mtw.php (modified) (1 diff)
-
webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Rmc.php (modified) (5 diffs)
-
webservice/inc/GnuBoat/Nmea/Nmea0183/Parser.php (modified) (6 diffs)
-
webservice/inc/GnuBoat/Nmea/NmeaSentence.php (modified) (1 diff)
-
webservice/inc/GnuBoat/Service.php (modified) (1 diff)
-
webservice/inc/GnuBoat/ServiceData.php (modified) (1 diff)
-
webservice/inc/GnuBoat/ServiceLogFiles.php (modified) (1 diff)
-
webservice/inc/GnuBoat/ServiceReplay.php (added)
-
webservice/inc/GnuBoat/TrackItem.php (added)
-
webservice/inc/GnuBoat/Webservice.php (modified) (3 diffs)
-
webservice/index.php (modified) (1 diff)
-
webservice/tests/Nmea0183DptTest.php (modified) (1 diff)
-
webservice/tests/Nmea0183MtwTest.php (modified) (1 diff)
-
webservice/tests/Nmea0183RmcTest.php (modified) (5 diffs)
-
webservice/tests/NmeaTest.php (modified) (1 diff)
-
webservice/tests/ServiceTest.php (modified) (4 diffs)
-
webservice/tests/config.php (added)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/build.xml
rfc63b30 r008bce9 46 46 <target name="dist" depends="buildwebservice,buildwebclient,test"> 47 47 <echo msg="Creating archive"/> 48 <!--<tar destfile="${builddir}/..//gnuboat-webapp.tar.gz" compression="gzip">48 <tar destfile="${builddir}/..//gnuboat-webapp.tar.gz" compression="gzip"> 49 49 <fileset refid="filesWebApp"/> 50 </tar> -->50 </tar> 51 51 <echo msg="Files copied and compressed in build directory weblcient.tar.gz OK!" /> 52 52 </target> 53 <target name="testdist" depends="buildwebservice,buildwebclient"> 53 54 <target name="testdist" depends="buildwebservice,buildwebclient,test"> 54 55 <echo msg="Install project into ${user.home}/public_html/gnuboat"/> 56 <fileset id="filesConfig" dir="./webservice/tests"> 57 <include name="config.php"/> 58 </fileset> 59 <fileset id="filesLogs" dir="./webservice/tests/data"> 60 <include name="*.log"/> 61 </fileset> 62 55 63 <copy todir="${user.home}/public_html/gnuboat"> 56 64 <fileset refid="filesWebApp"/> 65 </copy> 66 <copy todir="${user.home}/public_html/gnuboat/logs"> 67 <fileset refid="filesLogs"/> 68 </copy> 69 <copy todir="${user.home}/public_html/gnuboat/webservice/config"> 70 <fileset refid="filesConfig"/> 57 71 </copy> 58 72 </target> 59 73 60 74 <target name="test"> 61 <phpunit bootstrap="webservice/inc/autoloader.php" pharlocation="phpunit-4.8.9.phar" haltonfailure="true" haltonerror="true" printsummary="true" >75 <phpunit bootstrap="webservice/inc/autoloader.php" pharlocation="phpunit-4.8.9.phar" haltonfailure="true" haltonerror="true" printsummary="true" codecoverage="false"> 62 76 <formatter type="plain" usefile="false"/> 77 <!--<formatter type="JUnit" usefile="true"/>--> 63 78 <batchtest> 64 79 <fileset dir="webservice"> -
src/webapp/webclient/index.html
rfc63b30 r008bce9 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> 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> 142 151 <div id="mapViewport" class="viewportGeometry"></div> 143 152 </div> -
src/webapp/webclient/js/GnuBoat.js
rfc63b30 r008bce9 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); … … 242 244 { 243 245 if(GnuBoat.private.serverBaseUrl == null){ 244 GnuBoat.displayMessage( "No server set/found");246 GnuBoat.displayMessage('<span class="error">No server set/found</span>'); 245 247 return; 246 248 } … … 250 252 if(GnuBoat.private.timerDisplay == null) 251 253 GnuBoat.private.timerDisplay = setInterval(GnuBoat.displayDataGet, 10000); 252 GnuBoat.logfilesLoad(); 254 GnuBoat.logfilesLoad(); 253 255 254 256 GnuBoat.private.animate(); … … 276 278 mapsMetadata: null, 277 279 mapBounds: null, 280 mapModusLive: true, 278 281 dataMappings: { 279 282 speedthroughwater: {display: true, map: true, mapActive: false, titleLong: "Speed Through Water", titleShort: "STW", unit: "kts"}, … … 302 305 displayDataSet: function(data) 303 306 { 307 // if(!Array.isArray(data) || data.length < 1){ 308 // console.log("No data array returned!"); 309 // console.log(data); 310 // return; 311 // } 312 if(("error" in data) && data["error"] == 1){ 313 GnuBoat.displayMessage('<span class="error">Failed to get display data and tracks: '+ data["errormessage"] +'</span>'); 314 return; 315 } 316 304 317 var keysDisplay = []; 305 318 for(var key in GnuBoat.private.dataMappings){ … … 307 320 keysDisplay.push(key); 308 321 } 309 if(!Array.isArray(data) && !(data instanceof Object)){ 310 console.log("No data array returned!"); 311 console.log(data); 312 return; 313 } 322 314 323 if(!("lastvalid" in data)){ 315 324 console.log("No last valid values given!"); … … 333 342 } 334 343 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 } 344 // map displays logged data 345 if(!GnuBoat.private.mapModusLive) 346 return; 347 else if(!("track" in data)){ 348 console.log("No track given!"); 349 return; 350 } 351 GnuBoat.private.mapAddTracks(data["track"]); 399 352 }, 400 353 … … 578 531 return result; 579 532 }, 533 534 updateMapModus: function(data) 535 { 536 var selected = $("#mapModusSelect").val(); 537 $("#mapModusSelect").empty(); 538 var selectedFound = false; 539 if(selected != null && Array.isArray(data)){ 540 data.forEach(function(value, index){ 541 if(value == selected) 542 selectedFound = true; 543 }); 544 } 545 var selectedString = ""; 546 if(!selectedFound) 547 selectedString = " selected"; 548 $('<option value="live"'+ selectedString +'>Live View</option>').appendTo("#mapModusSelect"); 549 if(!Array.isArray(data) || data.length < 1){ 550 console.log(data); 551 return; 552 } 553 if(("error" in data) && data["error"] == 1){ 554 GnuBoat.displayMessage('<span class="error">Failed to upload map: '+ data["errormessage"] +'</span>'); 555 return; 556 } 557 data.forEach(function(value, index){ 558 var selectedString = ""; 559 if(value == selected) 560 selectedString = " selected"; 561 $("<option value=\""+ value +"\""+ selected +">"+ value +"</option>").appendTo("#mapModusSelect"); 562 }); 563 }, 564 565 mapModusChanged: function() 566 { 567 var modus = $("#mapModusSelect").val(); 568 // live modus is automatically activated on displayDataSet 569 if(modus == "live"){ 570 GnuBoat.private.mapModusLive = true; 571 return; 572 } 573 // remove overlays 574 if(GnuBoat.private.mapControl != null){ 575 for(var key in GnuBoat.private.dataMappings){ 576 if(GnuBoat.private.dataMappings[key]["map"] === true) 577 if(key in GnuBoat.private.mapPolylines){ 578 GnuBoat.private.mapControl.removeLayer(GnuBoat.private.mapPolylines[key]); 579 GnuBoat.private.mapPolylines[key].remove(); 580 delete GnuBoat.private.mapPolylines[key]; 581 } 582 } 583 } 584 GnuBoat.private.mapModusLive = false; 585 $.post({ 586 url: GnuBoat.private.serverBaseUrl +'?request=replay', 587 data: { logfile: modus }, 588 success: function(data){ 589 // if(!Array.isArray(data) || data.length < 1){ 590 // console.log("No data array returned!"); 591 // console.log(data); 592 // return; 593 // } 594 if(("error" in data) && data["error"] == 1){ 595 GnuBoat.displayMessage('<span class="error">Failed to get logged tracks: '+ data["errormessage"] +'</span>'); 596 return; 597 } 598 if(!("track" in data)){ 599 console.log("No track given!"); 600 return; 601 } 602 GnuBoat.private.mapAddTracks(data["track"]); 603 } 604 }); 605 }, 606 607 mapAddTracks: function(track) 608 { 609 if(GnuBoat.private.map == null){ 610 console.log("No map in use"); 611 return; 612 } 613 614 var maximas = []; 615 var minimas = []; 616 var points = []; 617 var densityPoints = []; 618 619 var keysMap = []; 620 for(var key in GnuBoat.private.dataMappings){ 621 if(GnuBoat.private.dataMappings[key]["map"] === true) 622 keysMap.push(key); 623 } 624 for(var i = 0; i < keysMap.length; i++){ 625 points[keysMap[i]] = []; 626 } 627 628 // getting maximas, minimums for normalization and the tracks themselves 629 for(var time in track){ 630 for(var i = 0; i < keysMap.length; i++){ 631 var key = keysMap[i]; 632 if(key == "gpsfix") 633 continue; 634 if(!(key in maximas)) 635 maximas[key] = track[time][key] 636 else if(maximas[key] < track[time][key]) 637 maximas[key] = track[time][key]; 638 if(!(key in minimas)) 639 minimas[key] = track[time][key] 640 else if(minimas[key] > track[time][key]) 641 minimas[key] = track[time][key]; 642 points[key].push(new L.latLng(track[time]["latitude"], track[time]["longitude"], track[time][key])); 643 densityPoints.push({latitude: track[time]["latitude"], longitude: track[time]["longitude"], depth: track[time]["waterdepth"]}); 644 } 645 } 646 for(var i = 0; i < keysMap.length; i++){ 647 var key = keysMap[i]; 648 if(points[key].length > 0){ 649 if(key in GnuBoat.private.mapPolylines) 650 GnuBoat.private.mapPolylines[key].setLatLngs(points[key]); 651 else{ 652 GnuBoat.private.mapPolylines[key] = L.hotline(points[key], {weight: 3, outlineWidth: 0, min: minimas[key], max: maximas[key]}); 653 if(GnuBoat.private.mapControl){ 654 var name = GnuBoat.private.dataMappings[key]["titleLong"] +" in "+ GnuBoat.private.dataMappings[key]["unit"] +" ("+ GnuBoat.private.dataMappings[key]["titleShort"] +")"; 655 GnuBoat.private.mapControl.addOverlay(GnuBoat.private.mapPolylines[key], name); 656 } 657 if(GnuBoat.private.dataMappings[key]["mapActive"] === true) 658 GnuBoat.private.mapPolylines[key].addTo(GnuBoat.private.map); 659 } 660 } 661 } 662 GnuBoat.private.drawDensityEstimation(densityPoints, maximas["waterdepth"], minimas["waterdepth"]); 663 }, 580 664 }; -
src/webapp/webservice/inc/GnuBoat/Config.php
rfc63b30 r008bce9 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/Nmea/Nmea0183/Nmea0183Dpt.php
rfc63b30 r008bce9 33 33 return; 34 34 35 $this->_depth = $content[1];35 $this->_depth = (float)$content[1]; 36 36 $tmp = explode("*", $content[2]); 37 37 $this->_offset = $tmp[0]; -
src/webapp/webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Mtw.php
rfc63b30 r008bce9 33 33 return; 34 34 35 $this->_temperature = $content[1];35 $this->_temperature = (float)$content[1]; 36 36 $tmp = explode("*", $content[2]); 37 37 $this->_unit = $tmp[0]; -
src/webapp/webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Rmc.php
rfc63b30 r008bce9 19 19 namespace GnuBoat\Nmea\Nmea0183; 20 20 21 /** 22 * @brief NMEA0183 RMC Naviation sentence 23 * 24 * Keep in mind, that the latitude() and longitude() is converted to +/- values 25 */ 21 26 class Nmea0183Rmc extends Nmea0183Sentence 22 27 { … … 49 54 if($content[2] == 'A') 50 55 $this->_status = Nmea0183RmcStatus::A; 51 52 $this->_latitude = $content[3];53 $this->_latitudeDirection = Nmea0183Rmc::directionToEnum($content[4]);54 56 55 $this->_longitude = $content[5]; 56 $this->_longitudeDirection = Nmea0183Rmc::directionToEnum($content[6]); 57 $this->_latitude = (float)$content[3]; 58 if(Nmea0183Rmc::directionToEnum($content[4]) == Nmea0183Direction::South) 59 $this->_latitude = $this->_latitude * -1; 57 60 58 $this->_speedOverGround = $content[7]; 61 $this->_longitude = (float)$content[5]; 62 if(Nmea0183Rmc::directionToEnum($content[6]) == Nmea0183Direction::West) 63 $this->_longitude = $this->_longitude * -1; 59 64 60 $this->_ courseOverGround = $content[8];65 $this->_speedOverGround = (float)$content[7]; 61 66 62 $this->_magneticDeclination = $content[10]; 67 $this->_courseOverGround = (float)$content[8]; 68 69 $this->_magneticDeclination = (float)$content[10]; 63 70 $this->_magneticDeclinationDirection = Nmea0183Rmc::directionToEnum($content[11]); 64 71 … … 82 89 } 83 90 91 /** 92 * @brief Latitude with North (+) and South (-) 93 */ 84 94 public function latitude() 85 95 { … … 87 97 } 88 98 89 public function latitudeDirection() 90 { 91 return $this->_latitudeDirection; 92 } 93 99 /** 100 * @brief Longitude with East (+) and West (-) 101 */ 94 102 public function longitude() 95 103 { 96 104 return $this->_longitude; 97 }98 99 public function longitudeDirection()100 {101 return $this->_longitudeDirection;102 105 } 103 106 … … 162 165 private $_status; 163 166 private $_latitude; 164 private $_latitudeDirection;165 167 private $_longitude; 166 private $_longitudeDirection;167 168 private $_speedOverGround; 168 169 private $_courseOverGround; -
src/webapp/webservice/inc/GnuBoat/Nmea/Nmea0183/Parser.php
rfc63b30 r008bce9 35 35 $result = array(); 36 36 if(!file_exists($file)){ 37 $message = "NMEA file to parse does not exists: ". $file ."\n";37 $message = "NMEA file to parse does not exists: ". $file; 38 38 error_log($message); 39 39 if($debug > 0) 40 print $message ;40 print $message ."\n"; 41 41 return $result; 42 42 } … … 44 44 $fileHandler = fopen($file, 'r'); 45 45 if(!$fileHandler){ 46 $message = "NMEA file to parse could not be opend for reading: ". $file ."\n";46 $message = "NMEA file to parse could not be opend for reading: ". $file; 47 47 error_log($message); 48 48 if($debug > 0) 49 print $message ;49 print $message ."\n"; 50 50 return $result; 51 51 } … … 61 61 $result[] = $parsedSentence; 62 62 else{ 63 $message = "Skipped sentence on line ". $line .": ". $sentence ."\n";63 $message = "Skipped sentence on line ". $line .": ". $sentence; 64 64 error_log($message); 65 65 if($debug > 0) 66 print $message ;66 print $message ."\n"; 67 67 } 68 68 } … … 75 75 $sentence = trim($sentence); 76 76 if(empty($sentence)){ 77 $message = "Empty sentence \n";77 $message = "Empty sentence"; 78 78 error_log($message); 79 79 if($debug > 0) 80 print $message ;80 print $message ."\n"; 81 81 return null; 82 82 } … … 85 85 $result = preg_match('/^[\$!]{1}([\w]{2})([\w]{3})([^\*]+)\*([\da-zA-Z]+)$/', $sentence, $matches); 86 86 if($result === false || $result != 1 || count($matches) != 5){ 87 $message = "Could not detect talker, type and checksum from ". $sentence ."\n";87 $message = "Could not detect talker, type and checksum from ". $sentence; 88 88 error_log($message); 89 89 if($debug > 0) 90 print $message ;90 print $message ."\n"; 91 91 return null; 92 92 } … … 97 97 98 98 if(!array_key_exists(strtolower($type), $this->_types)){ 99 $message = "Skipping unknown NMEA0183 sentence of type ". $type .": ". $sentence ."\n";99 $message = "Skipping unknown NMEA0183 sentence of type ". $type .": ". $sentence; 100 100 error_log($message); 101 101 if($debug > 0) 102 print $message ;102 print $message ."\n"; 103 103 return null; 104 104 } -
src/webapp/webservice/inc/GnuBoat/Nmea/NmeaSentence.php
rfc63b30 r008bce9 48 48 public function type() 49 49 { 50 return $this->_type;50 return strtolower($this->_type); 51 51 } 52 52 -
src/webapp/webservice/inc/GnuBoat/Service.php
rfc63b30 r008bce9 44 44 $this->process(); 45 45 } 46 47 public static function error($message) 48 { 49 Service::output(["error" => 1, "errormessage" => $message]); 50 } 51 52 public static function output($content) 53 { 54 header('Content-Type: application/json'); 55 echo json_encode($content); 56 } 46 57 47 58 /** -
src/webapp/webservice/inc/GnuBoat/ServiceData.php
rfc63b30 r008bce9 49 49 50 50 if(!file_exists($dbFile)){ 51 echo json_encode("");52 51 if($debug > 0) 53 52 echo "Database file ". $dbFile ." does not exist!"; 54 53 error_log("Database file ". $dbFile ." does not exist"); 55 exit;54 return; 56 55 } 57 56 // Fetch entries of the last 30s with maximum (available) resolution of 2s -
src/webapp/webservice/inc/GnuBoat/ServiceLogFiles.php
rfc63b30 r008bce9 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)){ -
src/webapp/webservice/inc/GnuBoat/Webservice.php
rfc63b30 r008bce9 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::error("Request ". $request ." not implemented"); 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/index.php
rfc63b30 r008bce9 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/Nmea0183DptTest.php
rfc63b30 r008bce9 46 46 { 47 47 return [ 48 "wrong_data_count" => ['$SDDPT,00.71,00.71,00.00*51', 'SD', ' DPT', 0, 0, 51, false],49 "wrong_checksum" => ['$SDDPT,00.71,00.00*22', 'SD', ' DPT', 0.71, 0.0, 22, false],50 "valid1" => ['$SDDPT,00.71,00.00*51', 'SD', ' DPT', 0.71, 0.0, 51, true],51 "valid2" => ['!SDDPT,00.71,00.00*51', 'SD', ' DPT', 0.71, 0.0, 51, true],48 "wrong_data_count" => ['$SDDPT,00.71,00.71,00.00*51', 'SD', 'dpt', 0, 0, 51, false], 49 "wrong_checksum" => ['$SDDPT,00.71,00.00*22', 'SD', 'dpt', 0.71, 0.0, 22, false], 50 "valid1" => ['$SDDPT,00.71,00.00*51', 'SD', 'dpt', 0.71, 0.0, 51, true], 51 "valid2" => ['!SDDPT,00.71,00.00*51', 'SD', 'dpt', 0.71, 0.0, 51, true], 52 52 ]; 53 53 } -
src/webapp/webservice/tests/Nmea0183MtwTest.php
rfc63b30 r008bce9 46 46 { 47 47 return [ 48 "wrong_data_count" => ['$YXMTW,C*15', 'YX', ' MTW', 0, '', 15, false],49 "wrong_checksum" => ['$YXMTW,26.3,C*22', 'YX', ' MTW', 26.3, 'C', 22, false],50 "valid1" => ['$YXMTW,26.3,C*15', 'YX', ' MTW', 26.3, 'C', 15, true],51 "valid2" => ['!YXMTW,26.3,C*15', 'YX', ' MTW', 26.3, 'C', 15, true],48 "wrong_data_count" => ['$YXMTW,C*15', 'YX', 'mtw', 0, '', 15, false], 49 "wrong_checksum" => ['$YXMTW,26.3,C*22', 'YX', 'mtw', 26.3, 'C', 22, false], 50 "valid1" => ['$YXMTW,26.3,C*15', 'YX', 'mtw', 26.3, 'C', 15, true], 51 "valid2" => ['!YXMTW,26.3,C*15', 'YX', 'mtw', 26.3, 'C', 15, true], 52 52 ]; 53 53 } -
src/webapp/webservice/tests/Nmea0183RmcTest.php
rfc63b30 r008bce9 49 49 $this->assertEquals($sentence->status(), $status); 50 50 $this->assertEquals($latitude, $sentence->latitude()); 51 $this->assertEquals($latitudeDirection, $sentence->latitudeDirection());52 51 $this->assertEquals($longitude, $sentence->longitude()); 53 $this->assertEquals($longitudeDirection, $sentence->longitudeDirection());54 52 $this->assertEquals($speedOverGround, $sentence->speedOverGround()); 55 53 $this->assertEquals($courseOverGround, $sentence->courseOverGround()); … … 71 69 "wrong_data_count" => [ 72 70 '$GPRMC,162614,A,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13', 73 "GP", " RMC", null,71 "GP", "rmc", null, 74 72 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::V, 0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid, 75 73 0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid, … … 79 77 "wrong_checksum" => [ 80 78 '$GPRMC,162614,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*22', 81 "GP", " RMC", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")),79 "GP", "rmc", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")), 82 80 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 5230.59, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North, 83 81 1322.39, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East, … … 87 85 "valid1" => [ 88 86 '$GPRMC,162614,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13', 89 "GP", " RMC", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")),87 "GP", "rmc", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")), 90 88 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 5230.59, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North, 91 89 1322.39, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East, … … 94 92 ], 95 93 "valid2" => [ 96 '!GPRMC,162614,A,5230.5900, N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13',97 "GP", " RMC", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")),98 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 5230.59, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,99 1322.39, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,94 '!GPRMC,162614,A,5230.5900,S,01322.3900,W,10.0,90.0,131006,1.2,E,A*1c', 95 "GP", "rmc", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")), 96 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, -5230.59, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North, 97 -1322.39, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East, 100 98 10, 90, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East, 101 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 13, true99 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, '1c', true 102 100 ], 103 101 "valid3" => [ 104 '$GPRMC,162614.123,A,5230.5900,N,01322.3900, E,10.0,90.0,131006,1.2,E,A*d',105 "GP", " RMC", DateTime::createFromFormat($formatMilli, "2006-10-13 16:26:14.123", new DateTimeZone("UTC")),102 '$GPRMC,162614.123,A,5230.5900,N,01322.3900,W,10.0,90.0,131006,1.2,E,A*1f', 103 "GP", "rmc", DateTime::createFromFormat($formatMilli, "2006-10-13 16:26:14.123", new DateTimeZone("UTC")), 106 104 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 5230.59, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North, 107 1322.39, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,105 -1322.39, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East, 108 106 10, 90, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East, 109 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, ' d', true107 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, '1f', true 110 108 ] 111 109 ]; -
src/webapp/webservice/tests/NmeaTest.php
rfc63b30 r008bce9 20 20 // declare(Strict_types=1); 21 21 22 /** 23 * @brief Covers Parser.php 24 */ 25 final class NmeaTest extends PHPUnit_Framework_TestCase 22 namespace GnuBoat\Nmea 26 23 { 24 27 25 /** 28 * @dataProvider formatsProvider29 */30 public function testFormats($format)26 * @brief Covers Parser.php 27 */ 28 final class NmeaTest extends \PHPUnit_Framework_TestCase 31 29 { 32 $parser = new GnuBoat\Nmea\Parser(0); 33 $formats = $parser->formatsSupported(); 34 $this->assertInternalType('array', $formats); 35 $this->assertContains($format, $formats); 36 } 37 38 public function formatsProvider() 39 { 40 return [["0183"]]; 30 /** 31 * @dataProvider formatsProvider 32 */ 33 public function testFormats($format) 34 { 35 $parser = new Parser(0); 36 $formats = $parser->formatsSupported(); 37 $this->assertInternalType('array', $formats); 38 $this->assertContains($format, $formats); 39 } 40 41 public function formatsProvider() 42 { 43 return [["0183"]]; 44 } 45 46 /** 47 * @dataProvider nmeaSentenceProvider 48 */ 49 public function testNmeaSentence($format, $sentence, $classType, $valid) 50 { 51 $parser = new Parser(0); 52 $sentence = $parser->parseSentence($sentence, $format); 53 if($classType == null) 54 $this->assertNull($sentence); 55 else{ 56 $this->assertInstanceOf($classType, $sentence); 57 $message = ""; 58 $result = $sentence->valid($message); 59 $this->assertEquals($valid, $result, $message); 60 } 61 } 62 63 public function nmeaSentenceProvider() 64 { 65 return [ 66 "empty" => ['0183', '', null, false], 67 "unsupported_format" => ['abc', '', null, false], 68 "rmc0183" => ['0183', '$GNRMC,173658,A,0047.589,N,00010.713,E,01.1,147.4,260817,,,A*5F', Nmea0183\Nmea0183Rmc::class, true], 69 "dpt0183" => ['0183', '$SDDPT,00.71,00.00*51', Nmea0183\Nmea0183Dpt::class, true], 70 "mtw0183" => ['0183', '$YXMTW,26.3,C*15', Nmea0183\Nmea0183Mtw::class, true], 71 ]; 72 } 73 74 /** 75 * @dataProvider nmeaFileProvider 76 */ 77 public function testNmeaFile($file, $format, $count) 78 { 79 $parser = new Parser(0); 80 $sentences = $parser->parseFile($file, $format); 81 $this->assertInternalType('array', $sentences); 82 $this->assertCount($count, $sentences); 83 foreach($sentences as $sentence){ 84 $this->assertNotNull($sentence); 85 $this->assertInstanceOf(NmeaSentence::class, $sentence); 86 $this->assertEquals(true, $sentence->valid()); 87 } 88 } 89 90 public function nmeaFileProvider() 91 { 92 return [["webservice/tests/data/nmea0183.log", '0183', 2000]]; 93 } 41 94 } 42 95 43 /** 44 * @dataProvider nmeaSentenceProvider 45 */ 46 public function testNmeaSentence($format, $sentence, $classType, $valid) 96 function error_log($msg) 47 97 { 48 $parser = new GnuBoat\Nmea\Parser(0); 49 $sentence = $parser->parseSentence($sentence, $format); 50 if($classType == null) 51 $this->assertNull($sentence); 52 else{ 53 $this->assertInstanceOf($classType, $sentence); 54 $message = ""; 55 $result = $sentence->valid($message); 56 $this->assertEquals($valid, $result, $message); 57 } 98 echo "ERR Nmea: ". $msg ."\n"; 58 99 } 59 60 public function nmeaSentenceProvider() 100 } 101 102 namespace GnuBoat\Nmea\Nmea0183 103 { 104 function error_log($msg) 61 105 { 62 return [ 63 "empty" => ['0183', '', null, false], 64 "unsupported_format" => ['abc', '', null, false], 65 "rmc0183" => ['0183', '$GNRMC,173658,A,0047.589,N,00010.713,E,01.1,147.4,260817,,,A*5F', GnuBoat\Nmea\Nmea0183\Nmea0183Rmc::class, true], 66 "dpt0183" => ['0183', '$SDDPT,00.71,00.00*51', GnuBoat\Nmea\Nmea0183\Nmea0183Dpt::class, true], 67 "mtw0183" => ['0183', '$YXMTW,26.3,C*15', GnuBoat\Nmea\Nmea0183\Nmea0183Mtw::class, true], 68 ]; 69 } 70 71 /** 72 * @dataProvider nmeaFileProvider 73 */ 74 public function testNmeaFile($file, $format, $count) 75 { 76 $parser = new GnuBoat\Nmea\Parser(0); 77 $sentences = $parser->parseFile($file, $format); 78 $this->assertInternalType('array', $sentences); 79 $this->assertCount($count, $sentences); 80 foreach($sentences as $sentence){ 81 $this->assertNotNull($sentence); 82 $this->assertInstanceOf(GnuBoat\Nmea\NmeaSentence::class, $sentence); 83 $this->assertEquals(true, $sentence->valid()); 84 } 85 } 86 87 public function nmeaFileProvider() 88 { 89 return [["webservice/tests/data/nmea0183.log", '0183', 2000]]; 106 echo "ERR Nmea0183: ". $msg ."\n"; 90 107 } 91 108 } -
src/webapp/webservice/tests/ServiceTest.php
rfc63b30 r008bce9 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 29 public function testData() 28 30 { 29 $webservice = new GnuBoat\Webservice();30 $this->assertInstanceOf( GnuBoat\Webservice::class, $webservice);31 $webservice = new Webservice(0); 32 $this->assertInstanceOf(Webservice::class, $webservice); 31 33 $_POST["request"] = "data"; 32 34 $webservice->process(); … … 35 37 public function testLogFiles() 36 38 { 37 $webservice = new GnuBoat\Webservice();38 $this->assertInstanceOf( GnuBoat\Webservice::class, $webservice);39 $webservice = new Webservice(0); 40 $this->assertInstanceOf(Webservice::class, $webservice); 39 41 $_POST["request"] = "logfiles"; 40 42 $webservice->process(); … … 43 45 public function testShutdown() 44 46 { 45 $webservice = new GnuBoat\Webservice();46 $this->assertInstanceOf( GnuBoat\Webservice::class, $webservice);47 $webservice = new Webservice(0); 48 $this->assertInstanceOf(Webservice::class, $webservice); 47 49 $_POST["request"] = "shutdown"; 48 50 $webservice->process(); … … 51 53 public function testMap() 52 54 { 53 $webservice = new GnuBoat\Webservice();54 $this->assertInstanceOf( GnuBoat\Webservice::class, $webservice);55 $webservice = new Webservice(0); 56 $this->assertInstanceOf(Webservice::class, $webservice); 55 57 $_POST["request"] = "map"; 58 $webservice->process(); 59 } 60 61 public function testReplay() 62 { 63 $webservice = new Webservice(0); 64 $this->assertInstanceOf(Webservice::class, $webservice); 65 $_POST["request"] = "replay"; 56 66 $webservice->process(); 57 67 } 58 68 } 59 69 70 function error_log($msg) 71 { 72 echo "ERR GnuBoat: ". $msg ."\n"; 73 } 74 60 75 ?>
Note:
See TracChangeset
for help on using the changeset viewer.
