Changeset 008bce9


Ignore:
Timestamp:
Aug 29, 2017, 6:19:00 PM (9 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
0.5, debian/bullseye, debian/jessie, master
Children:
89c510f
Parents:
fc63b30
Message:

First more or less working version of visualising logfiles on the map

Location:
src/webapp
Files:
3 added
19 edited

Legend:

Unmodified
Added
Removed
  • src/webapp/build.xml

    rfc63b30 r008bce9  
    4646        <target name="dist" depends="buildwebservice,buildwebclient,test">
    4747                <echo msg="Creating archive"/>
    48         <!--    <tar destfile="${builddir}/..//gnuboat-webapp.tar.gz" compression="gzip">
     48                <tar destfile="${builddir}/..//gnuboat-webapp.tar.gz" compression="gzip">
    4949                        <fileset refid="filesWebApp"/>
    50                 </tar>-->
     50                </tar>
    5151                <echo msg="Files copied and compressed in build directory weblcient.tar.gz OK!" />
    5252        </target>
    53         <target name="testdist" depends="buildwebservice,buildwebclient">
     53
     54        <target name="testdist" depends="buildwebservice,buildwebclient,test">
    5455                <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       
    5563                <copy todir="${user.home}/public_html/gnuboat">
    5664                        <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"/>
    5771                </copy>
    5872        </target>
    5973
    6074        <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">
    6276                        <formatter type="plain" usefile="false"/>
     77                        <!--<formatter type="JUnit" usefile="true"/>-->
    6378                        <batchtest>
    6479                                <fileset dir="webservice">
  • src/webapp/webclient/index.html

    rfc63b30 r008bce9  
    139139                                        <div id="map">
    140140                                                <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>
    142151                                                <div id="mapViewport" class="viewportGeometry"></div>
    143152                                        </div>
  • src/webapp/webclient/js/GnuBoat.js

    rfc63b30 r008bce9  
    5454{
    5555        if(GnuBoat.private.serverBaseUrl == null){
    56                 GnuBoat.displayMessage("No server set/found");
     56                GnuBoat.displayMessage('<span class="error">No server set/found</span>');
    5757                return;
    5858        }
    … …  
    6767{
    6868        if(GnuBoat.private.serverBaseUrl == null){
    69                 GnuBoat.displayMessage("No server set/found");
     69                GnuBoat.displayMessage('<span class="error">No server set/found</span>');
    7070                return;
    7171        }
    … …  
    7979{
    8080        if(GnuBoat.private.serverBaseUrl == null){
    81                 GnuBoat.displayMessage("No server set/found");
     81                GnuBoat.displayMessage('<span class="error">No server set/found</span>');
    8282                return;
    8383        }
    8484        $("#logfilesForm").empty();
    8585        $.getJSON(GnuBoat.private.serverBaseUrl +"?request=logfiles", function(data){
     86                GnuBoat.private.updateMapModus(data);
    8687                if(!Array.isArray(data) || data.length < 1){
    8788                        $("<p>No Logfiles found!</p>").appendTo("#logfilesForm");
    … …  
    9091                }
    9192                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);
    9596                        return;
    9697                }
    … …  
    108109{
    109110        if(GnuBoat.private.serverBaseUrl == null){
    110                 GnuBoat.displayMessage("No server set/found");
     111                GnuBoat.displayMessage('<span class="error">No server set/found</span>');
    111112                return;
    112113        }
    … …  
    129130{
    130131        if(GnuBoat.private.serverBaseUrl == null){
    131                 displayMessage("No server set/found");
     132                displayMessage('<span class="error">No server set/found</span>');
    132133                return;
    133134        }
    … …  
    142143                success: function(data){
    143144                        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>');
    145146                                $("#mapTileUploadProgress").hide();
    146147                                $("#mapFileInput").show();
    147148                                return;
    148149                        }
    149                         alert("Map upload successfully");
     150                        GnuBoat.displayMessage('<span class="error">Map upload successfully</span>');
    150151                        $("#mapTileUploadProgress").hide();
    151152                        $("#mapFileInput").show();
    … …  
    153154                },
    154155                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>');
    156157                        $("#mapTileUploadProgress").hide();
    157158                        $("#mapFileInput").show();
    … …  
    167168GnuBoat.initialize = function()
    168169{
     170        $("#mapModusSelect").change(function(){ GnuBoat.private.mapModusChanged(); });
    169171        $("#mapTileUploadProgress").hide();
    170172        $("#logfilesReload").click(GnuBoat.logfilesLoad);
    … …  
    242244{
    243245        if(GnuBoat.private.serverBaseUrl == null){
    244                 GnuBoat.displayMessage("No server set/found");
     246                GnuBoat.displayMessage('<span class="error">No server set/found</span>');
    245247                return;
    246248        }
    … …  
    250252        if(GnuBoat.private.timerDisplay == null)
    251253                GnuBoat.private.timerDisplay = setInterval(GnuBoat.displayDataGet, 10000);
    252         GnuBoat.logfilesLoad(); 
     254        GnuBoat.logfilesLoad();
    253255       
    254256        GnuBoat.private.animate();
    … …  
    276278        mapsMetadata: null,
    277279        mapBounds: null,
     280        mapModusLive: true,
    278281        dataMappings: {
    279282                speedthroughwater: {display: true, map: true, mapActive: false, titleLong: "Speed Through Water", titleShort: "STW", unit: "kts"},
    … …  
    302305        displayDataSet: function(data)
    303306        {
     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
    304317                var keysDisplay = [];
    305318                for(var key in GnuBoat.private.dataMappings){
    … …  
    307320                                keysDisplay.push(key);
    308321                }
    309                 if(!Array.isArray(data) && !(data instanceof Object)){
    310                         console.log("No data array returned!");
    311                         console.log(data);
    312                         return;
    313                 }
     322
    314323                if(!("lastvalid" in data)){
    315324                                console.log("No last valid values given!");
    … …  
    333342                }
    334343               
    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"]);
    399352        },
    400353       
    … …  
    578531                return result;
    579532        },
     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        },
    580664};
  • src/webapp/webservice/inc/GnuBoat/Config.php

    rfc63b30 r008bce9  
    2626        public function __construct()
    2727        {
    28                 $configFile = __DIR__ ."/../config/config.php";
     28                $configFile = __DIR__ ."/../../config/config.php";
    2929                if(file_exists($configFile)){
    3030                        include($configFile);
    … …  
    5151        {
    5252                if(array_key_exists("datadirectory", $this->_config))
    53                         return addTrailingSlash($this->_config["datadirectory"]);
     53                        return $this->addTrailingSlash($this->_config["datadirectory"]);
    5454                return "/var/lib/gnuboat/";
    5555        }
    … …  
    5858        {
    5959                if(array_key_exists("logdirectory", $this->_config))
    60                         return addTrailingSlash($this->_config["logdirectory"]);
     60                        return $this->addTrailingSlash($this->_config["logdirectory"]);
    6161                return "/var/log/gnuboat/";
    6262        }
  • src/webapp/webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Dpt.php

    rfc63b30 r008bce9  
    3333                        return;
    3434               
    35                 $this->_depth = $content[1];
     35                $this->_depth = (float)$content[1];
    3636                $tmp = explode("*", $content[2]);
    3737                $this->_offset = $tmp[0];
  • src/webapp/webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Mtw.php

    rfc63b30 r008bce9  
    3333                        return;
    3434               
    35                 $this->_temperature = $content[1];
     35                $this->_temperature = (float)$content[1];
    3636                $tmp = explode("*", $content[2]);
    3737                $this->_unit = $tmp[0];
  • src/webapp/webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Rmc.php

    rfc63b30 r008bce9  
    1919namespace GnuBoat\Nmea\Nmea0183;
    2020
     21/**
     22 * @brief NMEA0183 RMC Naviation sentence
     23 *
     24 * Keep in mind, that the latitude() and longitude() is converted to +/- values
     25 */
    2126class Nmea0183Rmc extends Nmea0183Sentence
    2227{
    … …  
    4954                if($content[2] == 'A')
    5055                        $this->_status = Nmea0183RmcStatus::A;
    51                        
    52                 $this->_latitude = $content[3];
    53                 $this->_latitudeDirection = Nmea0183Rmc::directionToEnum($content[4]);
    5456               
    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;
    5760               
    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;
    5964               
    60                 $this->_courseOverGround = $content[8];
     65                $this->_speedOverGround = (float)$content[7];
    6166               
    62                 $this->_magneticDeclination = $content[10];
     67                $this->_courseOverGround = (float)$content[8];
     68               
     69                $this->_magneticDeclination = (float)$content[10];
    6370                $this->_magneticDeclinationDirection = Nmea0183Rmc::directionToEnum($content[11]);
    6471               
    … …  
    8289        }
    8390       
     91        /**
     92         * @brief Latitude with North (+) and South (-)
     93         */
    8494        public function latitude()
    8595        {
    … …  
    8797        }
    8898       
    89         public function latitudeDirection()
    90         {
    91                 return $this->_latitudeDirection;
    92         }
    93        
     99        /**
     100         * @brief Longitude with East (+) and West (-)
     101         */
    94102        public function longitude()
    95103        {
    96104                return $this->_longitude;
    97         }
    98 
    99         public function longitudeDirection()
    100         {
    101                 return $this->_longitudeDirection;
    102105        }
    103106       
    … …  
    162165        private $_status;
    163166        private $_latitude;
    164         private $_latitudeDirection;
    165167        private $_longitude;
    166         private $_longitudeDirection;
    167168        private $_speedOverGround;
    168169        private $_courseOverGround;
  • src/webapp/webservice/inc/GnuBoat/Nmea/Nmea0183/Parser.php

    rfc63b30 r008bce9  
    3535                $result = array();
    3636                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;
    3838                        error_log($message);
    3939                        if($debug > 0)
    40                                 print $message;
     40                                print $message ."\n";
    4141                        return $result;
    4242                }
    … …  
    4444                $fileHandler = fopen($file, 'r');
    4545                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;
    4747                        error_log($message);
    4848                        if($debug > 0)
    49                                 print $message;
     49                                print $message ."\n";
    5050                        return $result;
    5151                }
    … …  
    6161                                $result[] = $parsedSentence;
    6262                        else{
    63                                 $message = "Skipped sentence on line ". $line .": ". $sentence ."\n";
     63                                $message = "Skipped sentence on line ". $line .": ". $sentence;
    6464                                error_log($message);
    6565                                if($debug > 0)
    66                                         print $message;
     66                                        print $message ."\n";
    6767                        }
    6868                }
    … …  
    7575                $sentence = trim($sentence);
    7676                if(empty($sentence)){
    77                         $message = "Empty sentence\n";
     77                        $message = "Empty sentence";
    7878                        error_log($message);
    7979                        if($debug > 0)
    80                                 print $message;
     80                                print $message ."\n";
    8181                        return null;
    8282                }
    … …  
    8585                $result = preg_match('/^[\$!]{1}([\w]{2})([\w]{3})([^\*]+)\*([\da-zA-Z]+)$/', $sentence, $matches);
    8686                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;
    8888                        error_log($message);
    8989                        if($debug > 0)
    90                                 print $message;
     90                                print $message ."\n";
    9191                        return null;
    9292                }
    … …  
    9797               
    9898                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;
    100100                        error_log($message);
    101101                        if($debug > 0)
    102                                 print $message;
     102                                print $message ."\n";
    103103                        return null;
    104104                }
  • src/webapp/webservice/inc/GnuBoat/Nmea/NmeaSentence.php

    rfc63b30 r008bce9  
    4848        public function type()
    4949        {
    50                 return $this->_type;
     50                return strtolower($this->_type);
    5151        }
    5252       
  • src/webapp/webservice/inc/GnuBoat/Service.php

    rfc63b30 r008bce9  
    4444                $this->process();
    4545        }
     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        }
    4657
    4758        /**
  • src/webapp/webservice/inc/GnuBoat/ServiceData.php

    rfc63b30 r008bce9  
    4949
    5050                if(!file_exists($dbFile)){
    51                         echo json_encode("");
    5251                        if($debug > 0)
    5352                                echo "Database file ". $dbFile ." does not exist!";
    5453                        error_log("Database file ". $dbFile ." does not exist");
    55                         exit;
     54                        return;
    5655                }
    5756                // Fetch entries of the last 30s with maximum (available) resolution of 2s
  • src/webapp/webservice/inc/GnuBoat/ServiceLogFiles.php

    rfc63b30 r008bce9  
    3232                $debug = $this->debug();
    3333                $config = new Config();
     34                if($debug > 1)
     35                        print "Log directory: ". $config->logDirectory() ."\n";
    3436
    3537                if(!array_key_exists("logfilesSelected", $_POST)){
  • src/webapp/webservice/inc/GnuBoat/Webservice.php

    rfc63b30 r008bce9  
    2323class WebService
    2424{
    25         function __construct()
     25        function __construct($debug)
    2626        {
    2727                $this->_requests = array();
    … …  
    3030                $this->_requests["logfiles"] = "GnuBoat\ServiceLogFiles";
    3131                $this->_requests["map"] = "GnuBoat\ServiceMap";
     32                $this->_requests["replay"] = "GnuBoat\ServiceReplay";
     33               
     34                $this->_debug = $debug;
    3235        }
    3336
    3437        public function process()
    3538        {
    36                 $debug = 0;
    37                 if(is_array($_GET) && array_key_exists("debug", $_GET))
    38                         $debug = $_GET["debug"];
    39 
    4039                $request = array_keys($this->_requests)[0];
    4140                if(is_array($_GET) && array_key_exists("request", $_GET)){
    … …  
    4443
    4544                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");
    5246                }
    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);
    5549        }
    5650
    5751        private $_requests;
     52        private $_debug;
    5853}
    5954
  • src/webapp/webservice/index.php

    rfc63b30 r008bce9  
    1919require_once(__DIR__ ."/inc/autoloader.php");
    2020
    21 $webservice = new GnuBoat\Webservice();
     21$debug = 0;
     22if(array_key_exists("debug", $_GET))
     23        $debug = $_GET["debug"];
     24
     25$webservice = new GnuBoat\Webservice($debug);
    2226$webservice->process();
    2327
  • src/webapp/webservice/tests/Nmea0183DptTest.php

    rfc63b30 r008bce9  
    4646        {
    4747                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],
    5252                ];
    5353        }
  • src/webapp/webservice/tests/Nmea0183MtwTest.php

    rfc63b30 r008bce9  
    4646        {
    4747                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],
    5252                ];
    5353        }
  • src/webapp/webservice/tests/Nmea0183RmcTest.php

    rfc63b30 r008bce9  
    4949                $this->assertEquals($sentence->status(), $status);
    5050                $this->assertEquals($latitude, $sentence->latitude());
    51                 $this->assertEquals($latitudeDirection, $sentence->latitudeDirection());
    5251                $this->assertEquals($longitude, $sentence->longitude());
    53                 $this->assertEquals($longitudeDirection, $sentence->longitudeDirection());
    5452                $this->assertEquals($speedOverGround, $sentence->speedOverGround());
    5553                $this->assertEquals($courseOverGround, $sentence->courseOverGround());
    … …  
    7169                        "wrong_data_count" => [
    7270                                '$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,
    7472                                GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::V, 0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid,
    7573                                0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid,
    … …  
    7977                        "wrong_checksum" => [
    8078                                '$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")),
    8280                                GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 5230.59, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
    8381                                1322.39, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
    … …  
    8785                        "valid1" => [
    8886                                '$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")),
    9088                                GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 5230.59, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
    9189                                1322.39, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
    … …  
    9492                        ],
    9593                        "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,
    10098                                10, 90, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
    101                                 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 13, true
     99                                GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, '1c', true
    102100                        ],
    103101                        "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")),
    106104                                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,
    108106                                10, 90, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
    109                                 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 'd', true
     107                                GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, '1f', true
    110108                        ]
    111109                ];
  • src/webapp/webservice/tests/NmeaTest.php

    rfc63b30 r008bce9  
    2020// declare(Strict_types=1);
    2121
    22 /**
    23   * @brief Covers Parser.php
    24   */
    25 final class NmeaTest extends PHPUnit_Framework_TestCase
     22namespace GnuBoat\Nmea
    2623{
     24
    2725        /**
    28           * @dataProvider formatsProvider
    29           */
    30         public function testFormats($format)
     26        * @brief Covers Parser.php
     27        */
     28        final class NmeaTest extends \PHPUnit_Framework_TestCase
    3129        {
    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                }
    4194        }
    4295
    43         /**
    44          * @dataProvider nmeaSentenceProvider
    45          */
    46         public function testNmeaSentence($format, $sentence, $classType, $valid)
     96        function error_log($msg)
    4797        {
    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";
    5899        }
    59        
    60         public function nmeaSentenceProvider()
     100}
     101
     102namespace GnuBoat\Nmea\Nmea0183
     103{
     104        function error_log($msg)
    61105        {
    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";
    90107        }
    91108}
  • src/webapp/webservice/tests/ServiceTest.php

    rfc63b30 r008bce9  
    2020// declare(Strict_types=1);
    2121
     22namespace GnuBoat;
     23
    2224/**
    23   * @brief Covers index.php tests
     25  * @brief Covers Service.php tests
    2426  */
    25 final class ServiceTest extends PHPUnit_Framework_TestCase
     27final class ServiceTest extends \PHPUnit_Framework_TestCase
    2628{
    2729        public function testData()
    2830        {
    29                 $webservice = new GnuBoat\Webservice();
    30                 $this->assertInstanceOf(GnuBoat\Webservice::class, $webservice);
     31                $webservice = new Webservice(0);
     32                $this->assertInstanceOf(Webservice::class, $webservice);
    3133                $_POST["request"] = "data";
    3234                $webservice->process();
    … …  
    3537        public function testLogFiles()
    3638        {
    37                 $webservice = new GnuBoat\Webservice();
    38                 $this->assertInstanceOf(GnuBoat\Webservice::class, $webservice);
     39                $webservice = new Webservice(0);
     40                $this->assertInstanceOf(Webservice::class, $webservice);
    3941                $_POST["request"] = "logfiles";
    4042                $webservice->process();
    … …  
    4345        public function testShutdown()
    4446        {
    45                 $webservice = new GnuBoat\Webservice();
    46                 $this->assertInstanceOf(GnuBoat\Webservice::class, $webservice);
     47                $webservice = new Webservice(0);
     48                $this->assertInstanceOf(Webservice::class, $webservice);
    4749                $_POST["request"] = "shutdown";
    4850                $webservice->process();
    … …  
    5153        public function testMap()
    5254        {
    53                 $webservice = new GnuBoat\Webservice();
    54                 $this->assertInstanceOf(GnuBoat\Webservice::class, $webservice);
     55                $webservice = new Webservice(0);
     56                $this->assertInstanceOf(Webservice::class, $webservice);
    5557                $_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";
    5666                $webservice->process();
    5767        }
    5868}
    5969
     70        function error_log($msg)
     71        {
     72                echo "ERR GnuBoat: ". $msg ."\n";
     73        }
     74
    6075?>
Note: See TracChangeset for help on using the changeset viewer.