Changeset 0662b2d


Ignore:
Timestamp:
Aug 30, 2017, 2:45:37 PM (9 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
0.5, debian/bullseye, debian/jessie, master
Children:
a50c18f
Parents:
89c510f
Message:

Improved webservice class to use TrackItem in ServiceData.php and added some tests

Location:
src/webapp
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • src/webapp/build.xml

    r89c510f r0662b2d  
    7373
    7474        <target name="test">
    75                 <phpunit bootstrap="webservice/inc/autoloader.php" pharlocation="phpunit-4.8.9.phar" haltonfailure="true" haltonerror="true" printsummary="true" codecoverage="false">
    76                         <formatter type="plain" usefile="false"/>
     75                <exec command="php phpunit-4.8.9.phar" passthru="true" checkreturn="true"/>
     76                <!--<phpunit pharlocation="phpunit-4.8.9.phar" configuration="phpunit.xml" haltonfailure="true" haltonerror="true" printsummary="true" codecoverage="false">
     77                        <formatter type="plain" usefile="false"/> -->
    7778                        <!--<formatter type="JUnit" usefile="true"/>-->
    78                         <batchtest>
     79<!--                    <batchtest>
    7980                                <fileset dir="webservice">
    8081                                        <include name="tests/*Test.php"/>
    8182                                </fileset>
    8283                        </batchtest>
    83                 </phpunit>
     84                </phpunit>-->
    8485        </target>
    8586</project>
  • src/webapp/webservice/inc/GnuBoat/Service.php

    r89c510f r0662b2d  
    4545        }
    4646       
    47         public static function error($message)
     47        public static function errorStatic($message, $additionalContent = array(), $debug)
    4848        {
    49                 Service::output(["error" => 1, "errormessage" => $message]);
     49                error_log($message);
     50                if($debug > 0)
     51                        print $message ."\n";
     52                $result = ["error" => 1, "errormessage" => $message];
     53                Service::outputStatic(array_merge($result, $additionalContent), $debug);
    5054        }
    5155       
    52         public static function output($content)
     56        public static function outputStatic($content, $debug)
    5357        {
    5458                header('Content-Type: application/json');
    55                 echo json_encode($content);
     59                if($debug > 0){
     60                        echo json_encode($content,  JSON_PRETTY_PRINT) ."\n";
     61                }
     62                else{
     63                        echo json_encode($content) ."\n";
     64                }
     65        }
     66       
     67        protected function error($message, $additionalContent = array())
     68        {
     69                Service::errorStatic($message, $additionalContent, $this->debug());
     70        }
     71       
     72        protected function output($content)
     73        {
     74                Service::outputStatic($content, $this->debug());
    5675        }
    5776
  • src/webapp/webservice/inc/GnuBoat/ServiceData.php

    r89c510f r0662b2d  
    2929                $this->_configRound = array
    3030                (
    31                         "latitude" => 5,
    32                         "longitude" => 5,
     31                        "latitude" => 4,
     32                        "longitude" => 4,
    3333                        "speedthroughwater" => 1,
    3434                        "speedoverground" => 1,
     35                        "courseoverground" => 1,
    3536                        "waterdepth" => 1,
    3637                        "watertemperature" => 1,
    … …  
    4849                $result["track"] = array();
    4950
    50                 if(!file_exists($dbFile)){
    51                         if($debug > 0)
    52                                 echo "Database file ". $dbFile ." does not exist!";
    53                         error_log("Database file ". $dbFile ." does not exist");
    54                         return;
    55                 }
     51                if(!file_exists($dbFile))
     52                        return $this->error("Database file ". $dbFile ." does not exist");
     53
    5654                // Fetch entries of the last 30s with maximum (available) resolution of 2s
    5755                $this->addRrdData($dbFile, "2", "240", $result, $lastValid);
    58                 if($lastValid){
    59                         $result["lastvalid"] = $lastValid;
     56                if($lastValid !== false){
     57                        $result["lastvalid"] = $lastValid->toArray();
    6058                }
    6159                // Fetch entries of the last 1h with maximum (available) resolution of 10s
    … …  
    6462                $this->addRrdData($dbFile, "60", "86400", $result, $lastTime);
    6563
    66                 if($debug > 0){
    67                         echo json_encode($result,  JSON_PRETTY_PRINT) ."\n";
    68                 }
    69                 else{
    70                         header('Content-Type: application/json');
    71                         echo json_encode($result) ."\n";
    72                 }
     64                return $this->output($result);
    7365        }
    7466
    … …  
    8173                $data = rrd_fetch($dbFile, array("AVERAGE", "--resolution", $interval, "--start", $startTime, "--end", $endTime));
    8274                // $data = rrd_fetch($dbFile, array("AVERAGE", "--resolution", $interval, "--start", "-". $period, "--end", "start+". $period, "--align-start"));
    83                 if($data === false){
    84                         echo json_encode($result);
    85                         $message = "Failure reading rrd database ". $dbFile .": ". rrd_error();
    86                         if($debug > 0)
    87                                 echo $message;
    88                         else
    89                                 error_log($message);
    90                         return;
    91                 }
     75                if($data === false)
     76                        return $this->error("Failure reading rrd database ". $dbFile .": ". rrd_error(), $result);
    9277
    9378                if($debug > 2){
    94                         echo "<pre>";
    9579                        var_dump($data);
    96                         echo "</pre>";
    9780                }
    9881
    … …  
    10184                // transform them into json format
    10285                $i = 0;
    103                 $lastValid = -1;
     86                $lastValid = false;
    10487                $keys = array_keys($data);
    10588                $keyTimeframes = $keys[0];
    10689                $itemCount = count($keys);
    107                 if($itemCount < 0 ){
    108                         error_log("No keys in fetched rrd data from ". $dbFile);
    109                         echo json_encode("");
    110                         exit;
    111                 }
     90                if($itemCount < 0 )
     91                        return $this->error("No keys in fetched rrd data from ". $dbFile);
     92
    11293                $timeframesCount = count($data[$keyTimeframes]);
    113                 if($debug > 0){
    114                         echo "<p>Variables: ". $itemCount ."; Timeframes: ". $timeframesCount ."</p>\n";
     94                if($debug > 1){
     95                        error_log("Variables: ". $itemCount ."; Timeframes: ". $timeframesCount);
    11596                }
    11697                foreach($data[$keys[0]] as $timeframe => $value){
    117                         $allValid = true;
    118                         $gpsFix = false;
    119                         $tmp = array();
     98                        $tmp = new TrackItem($timeframe);
    12099                        foreach($keys as $key){
    121                                 if($key == "gpsfix"){
    122                                         switch($data[$key][$timeframe]){
    123                                                 case 2:
    124                                                         $tmp[$key] = "2D";
    125                                                         $gpsFix = true;
    126                                                         break;
    127                                                 case 3:
    128                                                         $tmp[$key] = "3D";
    129                                                         $gpsFix = true;
    130                                                         break;
    131                                                 default:
    132                                                         $tmp[$key] = "-";
    133                                         }
    134                                 }
    135                                 else{
    136                                         $tmp[$key] = $data[$key][$timeframe];
    137                                         if(!is_numeric($tmp[$key]) || is_nan($tmp[$key])){
    138                                                 $allValid = false;
    139                                                 if($debug > 1){
    140                                                         echo "Invalid value ". $key ." (". $tmp[$key] .") at time ". $timeframe ."<br/>";
    141                                                 }
    142                                         }
    143                                         elseif(array_key_exists($key, $this->_configRound) && is_integer($this->_configRound[$key]))
    144                                                 $tmp[$key] = round($tmp[$key], $this->_configRound[$key]);
    145                                 }
     100                                $value = $data[$key][$timeframe];
     101                                if(array_key_exists($key, $this->_configRound) && is_integer($this->_configRound[$key]))
     102                                        $value = round($value, $this->_configRound[$key]);
     103                                if(!$tmp->setProperty($key, $value) && $debug > 1)
     104                                        error_log("Coult not set property ". $key ." to value ". $value ." at ". $timeframe);
    146105                        }
    147106                        // only add the timeframe to the track, if the values are valid and we had a gps fix at that time
    148                         if($allValid){
     107                        if($tmp->isValid()){
    149108                                $lastValid = $tmp;
    150                                 if($gpsFix){
     109                                if($tmp->gpsFixed()){
    151110                                        if(!array_key_exists($timeframe, $result["track"])){
    152                                                 $result["track"][$timeframe] = $tmp;
     111                                                $result["track"][$timeframe] = $tmp->toArray();
    153112                                        }
    154113                                }
  • src/webapp/webservice/inc/GnuBoat/ServiceLogFiles.php

    r89c510f r0662b2d  
    3939                        $files = glob($config->logDirectory() ."*.log");
    4040                        array_walk($files, 'GnuBoat\ServiceLogFiles::stripLogDirectory');
     41                        return $this->output($files);
     42                }
    4143
    42                         header('Content-Type: application/json');
    43                         if($debug > 0){
    44                                 echo json_encode($files,  JSON_PRETTY_PRINT) ."\n";
     44                // prepare a download of available log files
     45                $files = $_POST["logfilesSelected"];
     46                if(count($files) < 1)
     47                        return $this->error("No logfile selected");
     48                elseif(count($files) == 1){
     49                        $content = file_get_contents($config->logDirectory() . $files[0]);
     50                        if($content === false){
     51                                echo "<html><head></head><body>Failed to read logfile ". $files[0] ."</body></html>";
    4552                        }
    46                         else{
    47                                 echo json_encode($files) ."\n";
    48                         }
     53               
     54                        header('Content-Type: text/plain');
     55                        header('Content-disposition: attachment; filename="'. $files[0] .'"');
     56                        header('Content-Length: ' . filesize($config->logDirectory() . $files[0]));
     57                        echo $content;
    4958                }
    5059                else{
    51                         // prepare a download of available log files
    52                         $files = $_POST["logfilesSelected"];
    53                         if(count($files) < 1){
     60                        $date = new \DateTime('NOW');
     61                        $archiveName = "gnuboat-logs-". $date->format("Y-m-d");
     62               
     63                        // provide files as zip file
     64                        $tmpArchive = tempnam(sys_get_temp_dir(), $archiveName);
     65                        $zip = new \ZipArchive();
     66                        if($zip->open($tmpArchive, \ZipArchive::CREATE) !== TRUE){
     67                                echo "<html><head></head><body>Failed to create zip file</body></html>";
    5468                                return;
    5569                        }
    56                         elseif(count($files) == 1){
    57                                 $content = file_get_contents($config->logDirectory() . $files[0]);
    58                                 if($content === false){
    59                                         echo "<html><head></head><body>Failed to read logfile ". $files[0] ."</body></html>";
    60                                 }
    61                        
    62                                 header('Content-Type: text/plain');
    63                                 header('Content-disposition: attachment; filename="'. $files[0] .'"');
    64                                 header('Content-Length: ' . filesize($config->logDirectory() . $files[0]));
    65                                 echo $content;
    66                         }
    67                         else{
    68                                 $date = new \DateTime('NOW');
    69                                 $archiveName = "gnuboat-logs-". $date->format("Y-m-d");
    70                        
    71                                 // provide files as zip file
    72                                 $tmpArchive = tempnam(sys_get_temp_dir(), $archiveName);
    73                                 $zip = new \ZipArchive();
    74                                 if($zip->open($tmpArchive, \ZipArchive::CREATE) !== TRUE){
    75                                         echo "<html><head></head><body>Failed to create zip file</body></html>";
     70                        foreach($files as $file){
     71                                if($zip->addFile($config->logDirectory() . $file, $archiveName ."/". $file) !== true){
     72                                        $zip->close();
     73                                        echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>";
    7674                                        return;
    7775                                }
    78                                 foreach($files as $file){
    79                                         if($zip->addFile($config->logDirectory() . $file, $archiveName ."/". $file) !== true){
    80                                                 $zip->close();
    81                                                 echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>";
    82                                                 return;
    83                                         }
    84                                 }
    85                                 if($zip->close() !== true){
    86                                                 echo "<html><head></head><body>Failed to save zip file</body></html>";
    87                                                 return;
    88                                 }
    89                                
    90                                 echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>";
    91                                
    92                                 //Send zip folder
    93                                 while (ob_get_level()) {
    94                                         ob_end_clean();
    95                                 }
    96                                 ob_start();
    97                                 header('Content-Type: application/zip');
    98                                 header('Content-Transfer-Encoding: Binary');
    99                                 header('Content-disposition: attachment; filename=' . $archiveName . '.zip');
    100                                 header('Content-Length: ' . filesize($tmpArchive));
    101                                 ob_flush();
    102                                 ob_clean();
    103                                 readfile($tmpArchive);
    104                                 unlink($tmpArchive);
    105                                 return;
    10676                        }
     77                        if($zip->close() !== true){
     78                                        echo "<html><head></head><body>Failed to save zip file</body></html>";
     79                                        return;
     80                        }
     81                       
     82                        echo "<html><head></head><body>Failed to add logfile ". $file ." to the zip file</body></html>";
     83                       
     84                        //Send zip folder
     85                        while (ob_get_level()) {
     86                                ob_end_clean();
     87                        }
     88                        ob_start();
     89                        header('Content-Type: application/zip');
     90                        header('Content-Transfer-Encoding: Binary');
     91                        header('Content-disposition: attachment; filename=' . $archiveName . '.zip');
     92                        header('Content-Length: ' . filesize($tmpArchive));
     93                        ob_flush();
     94                        ob_clean();
     95                        readfile($tmpArchive);
     96                        unlink($tmpArchive);
     97                        return;
    10798                }
    10899        }
  • src/webapp/webservice/inc/GnuBoat/ServiceMap.php

    r89c510f r0662b2d  
    3030        protected function process()
    3131        {
    32                 header('Content-type: application/json');
     32                if(!array_key_exists("mapName", $_POST))
     33                        return $this->error("Please specify map name (no value)");
    3334
    34                 $result["error"] = 1;
    35                 $result["errormessage"] = "Unknown Error";
    36 
    37                 if(!array_key_exists("mapName", $_POST)){
    38                         $result["error"] = 1;
    39                         $result["errormessage"] = "Please specify map name (no value)";
    40                         echo json_encode($result);
    41                         return;
    42                 }
    4335                $mapName = $_POST["mapName"];
    44                 if(empty($mapName) || $mapName == ""){
    45                         $result["error"] = 1;
    46                         $result["errormessage"] = "Please specifiy map name (empty value)";
    47                         echo json_encode($result);
    48                         return;
    49                 }
     36                if(empty($mapName) || $mapName == "")
     37                        return $this->error("Please specifiy map name (empty value)");
    5038
    5139                $mapDirectory = __DIR__ ."/../../maps";
    52                 if(!array_key_exists("mapFile", $_FILES)){
    53                         $result["error"] = 1;
    54                         $result["errormessage"] = "No map file recieved";
    55                         echo json_encode($result);
    56                         return;
    57                 }
    58                 if (!isset($_FILES['mapFile']['error']) || is_array($_FILES['mapFile']['error'])){
    59                         $result["error"] = 1;
    60                         $result["errormessage"] = "Invalid parameters";
    61                         echo json_encode($result);
    62                         return;
    63                 }
     40                if(!array_key_exists("mapFile", $_FILES))
     41                        return $this->error("No map file recieved");
     42
     43                if (!isset($_FILES['mapFile']['error']) || is_array($_FILES['mapFile']['error']))
     44                        return $this->error("Invalid parameters");
     45
    6446                switch ($_FILES['mapFile']['error']) {
    6547                        case UPLOAD_ERR_OK:
    6648                                break;
    6749                        case UPLOAD_ERR_NO_FILE:
    68                                 $result["error"] = 1;
    69                                 $result["errormessage"] = "No file sent";
    70                                 echo json_encode($result);
    71                                 return;
     50                                return $this->error("No file sent");
    7251                        case UPLOAD_ERR_INI_SIZE:
    7352                        case UPLOAD_ERR_FORM_SIZE:
    74                                 $result["error"] = 1;
    75                                 $result["errormessage"] = "Exceeded filesize limit.";
    76                                 echo json_encode($result);
    77                                 return;
     53                                return $this->error("Exceeded filesize limit.");
    7854                        default:
    79                                 $result["error"] = 1;
    80                                 $result["errormessage"] = "Unknown PHP Error";
    81                                 echo json_encode($result);
    82                                 return;
     55                                return $this->error("Unknown PHP Error");
    8356                }
    8457                $mapFileName = $mapDirectory ."/". sha1_file($_FILES['mapFile']['tmp_name']) .".mbtiles";
    8558                if(move_uploaded_file($_FILES['mapFile']['tmp_name'], $mapFileName)){
    86                         if(!chmod($mapFileName, 0755)){
    87                                 $result["error"] = 1;
    88                                 $result["errormessage"] = "Could not change permissions of the map file";
    89                         }
    90                         else{
    91                                 // correct map metadata
    92                                 $resultRename = $this->setMapName($mapFileName, $mapName);
    93                                 if($resultRename[0] === true){
    94                                         $result["error"] = 0;
    95                                         $result["errormessage"] = "";
    96                                 }
    97                                 else{
    98                                         $result["error"] = 1;
    99                                         $result["errormessage"] = $resultRename[1];
    100                                 }
    101                         }
     59                        if(!chmod($mapFileName, 0755))
     60                                return $this->error("Could not change permissions of the map file");
     61                        // correct map metadata
     62                        $resultRename = $this->setMapName($mapFileName, $mapName);
     63                        if($resultRename[0] === true)
     64                                return $this->output(["error" => 0, "errormessage" => ""]);
     65                       
     66                        return $this->error($resultRename[1]);
    10267                }
    103                 else {
    104                         $result["error"] = 1;
    105                         $result["errormessage"] = "Could not move map in place";
    106                 }
    107                 echo json_encode($result);
     68                else
     69                        return $this->error("Could not move map in place");
    10870        }
    10971       
  • src/webapp/webservice/inc/GnuBoat/ServiceShutdown.php

    r89c510f r0662b2d  
    3636                if($handle === false){
    3737                        $message = "Could not create file (". $config->shutdownRequestFile() .") to indicate shutdown to the daemon.";
    38                         error_log($message);
    39                         $result["shutdownstart"] = -1;
    40                         $result["errormessage"] = $message;
    41                 }
    42                 else{
    43                         $shutdownTime = new \DateTime('NOW');
    44                         $shutdownTime->modify("+15 seconds");
    45                         fwrite($handle, $shutdownTime->format(\DateTime::ATOM));
    46                         $result["shutdownstart"] = $shutdownTime->format(\DateTime::ATOM);
     38                        return $this->error($message, ["shutdownstart" => -1]);
    4739                }
    4840
    49                 header('Content-Type: application/json');
    50                 if($debug > 0){
    51                         echo json_encode($result,  JSON_PRETTY_PRINT) ."\n";
    52                 }
    53                 else{
    54                         echo json_encode($result) ."\n";
    55                 }
     41                $shutdownTime = new \DateTime('NOW');
     42                $shutdownTime->modify("+15 seconds");
     43                fwrite($handle, $shutdownTime->format(\DateTime::ATOM));
     44                fclose($handle);
     45                $result["shutdownstart"] = $shutdownTime->format(\DateTime::ATOM);
     46                $this->output($result);
    5647        }
    5748}
  • src/webapp/webservice/inc/GnuBoat/TrackItem.php

    r89c510f r0662b2d  
    2424class TrackItem
    2525{
    26         function __construct()
    27         {
    28                 $this->_time = null;
    29                 $this->_latitude = null;
    30                 $this->_longitude = null;
     26        function __construct($timestamp = null, $latitude = null, $longitude = null)
     27        {
     28                $this->setTimestamp($timestamp);
     29                $this->setLatitude($latitude);
     30                $this->setLongitude($longitude);
    3131                $this->_speedThroughWater = null;
    3232                $this->_speedOverGround = null;
    … …  
    3535                $this->_waterTemperature = null;
    3636                $this->_gpsfix = null;
    37         }
    38 
     37               
     38                $this->_properties = [
     39                        "time" => ["timestamp", "setTimestamp"],
     40                        "latitude" => ["latitude", "setLatitude"],
     41                        "longitude" => ["longitude", "setLongitude"],
     42                        "speedthroughwater" => ["speedThroughWater", "setSpeedThroughWater"],
     43                        "speedoverground" => ["speedOverGround", "setSpeedOverGround"],
     44                        "courseoverground" => ["courseOverGround", "setCourseOverGround"],
     45                        "waterdepth" => ["waterDepth", "setWaterDepth"],
     46                        "watertemperature" => ["waterTemperature", "setWaterTemperature"],
     47                        "gpsfix" => ["gpsFix", "setGpsFix"],
     48                ];
     49        }
     50
     51        public function hasProperty($property)
     52        {
     53                return array_key_exists(strtolower($property), $this->_properties);
     54        }
     55       
     56        public function getProperty($property)
     57        {
     58                $property = strtolower($property);
     59                if(!$this->hasProperty($property))
     60                        return null;
     61                return call_user_func(array($this, $this->_properties[$property][0]));
     62        }
     63       
     64        public function setProperty($property, $value)
     65        {
     66                $property = strtolower($property);
     67                if(!$this->hasProperty($property))
     68                        return false;
     69                return call_user_func(array($this, $this->_properties[$property][1]), $value);
     70        }
     71       
    3972        public function setTimestamp($time)
    4073        {
     74                if(!is_numeric($time) || is_nan($time)){
     75                        $this->_time = null;
     76                        return false;
     77                }
    4178                $this->_time = $time;
     79                return true;
    4280        }
    4381       
    … …  
    4583        {
    4684                $timezone = new \DateTimeZone("UTC");
    47                 if($dateTime == null)
     85                if($dateTime == null){
    4886                        $this->_time = null;
     87                        return true;
     88                }
    4989                $dateTime->setTimezone($timezone);
    5090                $this->_time = $dateTime->getTimestamp();
     91                return true;
    5192        }
    5293       
    … …  
    5697        }
    5798       
    58                 public function setLatitude($latitude)
    59         {
     99        public function setLatitude($latitude)
     100        {
     101                if(!is_numeric($latitude) || is_nan($latitude)){
     102                        $this->_latitude = null;
     103                        return false;
     104                }
    60105                $this->_latitude = $latitude;
     106                return true;
    61107        }
    62108       
    … …  
    66112        }
    67113       
    68                 public function setLongitude($longitude)
    69         {
     114        public function setLongitude($longitude)
     115        {
     116                if(!is_numeric($longitude) || is_nan($longitude)){
     117                        $this->_longitude = null;
     118                        return false;
     119                }
    70120                $this->_longitude = $longitude;
     121                return true;
    71122        }
    72123       
    … …  
    76127        }
    77128       
    78                 public function setSpeedThroughWater($speedThroughWater)
    79         {
     129        public function setSpeedThroughWater($speedThroughWater)
     130        {
     131                if(!is_numeric($speedThroughWater) || is_nan($speedThroughWater)){
     132                        $this->_speedThroughWater = null;
     133                        return false;
     134                }
    80135                $this->_speedThroughWater = $speedThroughWater;
     136                return true;
    81137        }
    82138       
    … …  
    86142        }
    87143       
    88                 public function setSpeedOverGround($speedOverGround)
    89         {
     144        public function setSpeedOverGround($speedOverGround)
     145        {
     146                if(!is_numeric($speedOverGround) || is_nan($speedOverGround)){
     147                        $this->_speedOverGround = null;
     148                        return false;
     149                }
    90150                $this->_speedOverGround = $speedOverGround;
     151                return true;
    91152        }
    92153       
    … …  
    96157        }
    97158       
    98                 public function setCourseOverGround($courseOverGround)
    99         {
     159        public function setCourseOverGround($courseOverGround)
     160        {
     161                if(!is_numeric($courseOverGround) || is_nan($courseOverGround)){
     162                        $this->_courseOverGround = null;
     163                        return false;
     164                }
    100165                $this->_courseOverGround = $courseOverGround;
     166                return true;
    101167        }
    102168       
    … …  
    106172        }
    107173       
    108                 public function setWaterDepth($waterDepth)
    109         {
     174        public function setWaterDepth($waterDepth)
     175        {
     176                if(!is_numeric($waterDepth) || is_nan($waterDepth)){
     177                        $this->_waterDepth = null;
     178                        return false;
     179                }
    110180                $this->_waterDepth = $waterDepth;
     181                return true;
    111182        }
    112183       
    … …  
    116187        }
    117188       
    118                 public function setWaterTemperature($waterTemperature)
    119         {
     189        public function setWaterTemperature($waterTemperature)
     190        {
     191                if(!is_numeric($waterTemperature) || is_nan($waterTemperature)){
     192                        $this->_waterTemperature = null;
     193                        return false;
     194                }
    120195                $this->_waterTemperature = $waterTemperature;
     196                return true;
    121197        }
    122198       
    … …  
    126202        }
    127203       
    128                 public function setGpsFix($gpsFix)
    129         {
     204        public function setGpsFix($gpsFix)
     205        {
     206                if(!is_numeric($gpsFix) || is_nan($gpsFix)){
     207                        $this->_gpsFix = null;
     208                        return false;
     209                }
    130210                $this->_gpsFix = $gpsFix;
     211                return true;
    131212        }
    132213       
    … …  
    136217        }
    137218       
     219        public function gpsFixString()
     220        {
     221                switch($this->gpsFix()){
     222                        case 2:
     223                                return "2D";
     224                        case 3:
     225                                return "3D";
     226                        default:
     227                                return "-";
     228                }
     229        }
     230       
     231        public function gpsFixed()
     232        {
     233                if($this->gpsFix() != null && $this->gpsFix() > 1)
     234                        return true;
     235                return false;
     236        }
     237       
    138238        public function isValid()
    139239        {
    … …  
    149249        public function toArray()
    150250        {
    151                 $speedThroughWater = ($this->speedThroughWater() != null) ? $this->speedThroughWater() : 0;
    152                 $speedOverGround = ($this->speedOverGround() != null) ? $this->speedOverGround() : 0;
    153                 $courseOverGround = ($this->courseOverGround() != null) ? $this->courseOverGround() : 0;
    154                 $waterDepth = ($this->waterDepth() != null) ? $this->waterDepth() : 0;
    155                 $waterTemperature = ($this->waterTemperature() != null) ? $this->waterTemperature() : 0;
    156                 $gpsFix = ($this->gpsFix() != null) ? $this->gpsFix() : 0;
     251                $speedThroughWater = ($this->speedThroughWater() != null) ? $this->speedThroughWater() : "-";
     252                $speedOverGround = ($this->speedOverGround() != null) ? $this->speedOverGround() : "-";
     253                $courseOverGround = ($this->courseOverGround() != null) ? $this->courseOverGround() : "-";
     254                $waterDepth = ($this->waterDepth() != null) ? $this->waterDepth() : "-";
     255                $waterTemperature = ($this->waterTemperature() != null) ? $this->waterTemperature() : "-";
     256                $gpsFix = $this->gpsFixString();
    157257       
    158258                return [
  • src/webapp/webservice/inc/GnuBoat/Webservice.php

    r89c510f r0662b2d  
    4343
    4444                if(!array_key_exists($request, $this->_requests)){
    45                         return Service::error("Request ". $request ." not implemented");
     45                        return Service::errorStatic("Request ". $request ." not implemented", $this->_debug);
    4646                }
    4747               
  • src/webapp/webservice/tests/ServiceTest.php

    r89c510f r0662b2d  
    5050                $webservice->process();
    5151        }
    52        
     52
    5353        public function testMap()
    5454        {
    … …  
    5858                $webservice->process();
    5959        }
    60        
     60
    6161        public function testReplay()
    6262        {
    … …  
    6868}
    6969
    70         function error_log($msg)
    71         {
    72                 echo "ERR GnuBoat: ". $msg ."\n";
    73         }
     70function error_log($msg)
     71{
     72        echo "ERR GnuBoat: ". $msg ."\n";
     73}
    7474
    7575?>
Note: See TracChangeset for help on using the changeset viewer.