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/webservice/inc/GnuBoat
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.