Changeset 008bce9 for src/webapp/webservice/inc/GnuBoat
- Timestamp:
- Aug 29, 2017, 6:19:00 PM (9 years ago)
- Branches:
- 0.5, debian/bullseye, debian/jessie, master
- Children:
- 89c510f
- Parents:
- fc63b30
- Location:
- src/webapp/webservice/inc/GnuBoat
- Files:
-
- 2 added
- 10 edited
-
Config.php (modified) (3 diffs)
-
Nmea/Nmea0183/Nmea0183Dpt.php (modified) (1 diff)
-
Nmea/Nmea0183/Nmea0183Mtw.php (modified) (1 diff)
-
Nmea/Nmea0183/Nmea0183Rmc.php (modified) (5 diffs)
-
Nmea/Nmea0183/Parser.php (modified) (6 diffs)
-
Nmea/NmeaSentence.php (modified) (1 diff)
-
Service.php (modified) (1 diff)
-
ServiceData.php (modified) (1 diff)
-
ServiceLogFiles.php (modified) (1 diff)
-
ServiceReplay.php (added)
-
TrackItem.php (added)
-
Webservice.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/webservice/inc/GnuBoat/Config.php
rfc63b30 r008bce9 26 26 public function __construct() 27 27 { 28 $configFile = __DIR__ ."/../ config/config.php";28 $configFile = __DIR__ ."/../../config/config.php"; 29 29 if(file_exists($configFile)){ 30 30 include($configFile); … … 51 51 { 52 52 if(array_key_exists("datadirectory", $this->_config)) 53 return addTrailingSlash($this->_config["datadirectory"]);53 return $this->addTrailingSlash($this->_config["datadirectory"]); 54 54 return "/var/lib/gnuboat/"; 55 55 } … … 58 58 { 59 59 if(array_key_exists("logdirectory", $this->_config)) 60 return addTrailingSlash($this->_config["logdirectory"]);60 return $this->addTrailingSlash($this->_config["logdirectory"]); 61 61 return "/var/log/gnuboat/"; 62 62 } -
src/webapp/webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Dpt.php
rfc63b30 r008bce9 33 33 return; 34 34 35 $this->_depth = $content[1];35 $this->_depth = (float)$content[1]; 36 36 $tmp = explode("*", $content[2]); 37 37 $this->_offset = $tmp[0]; -
src/webapp/webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Mtw.php
rfc63b30 r008bce9 33 33 return; 34 34 35 $this->_temperature = $content[1];35 $this->_temperature = (float)$content[1]; 36 36 $tmp = explode("*", $content[2]); 37 37 $this->_unit = $tmp[0]; -
src/webapp/webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Rmc.php
rfc63b30 r008bce9 19 19 namespace GnuBoat\Nmea\Nmea0183; 20 20 21 /** 22 * @brief NMEA0183 RMC Naviation sentence 23 * 24 * Keep in mind, that the latitude() and longitude() is converted to +/- values 25 */ 21 26 class Nmea0183Rmc extends Nmea0183Sentence 22 27 { … … 49 54 if($content[2] == 'A') 50 55 $this->_status = Nmea0183RmcStatus::A; 51 52 $this->_latitude = $content[3];53 $this->_latitudeDirection = Nmea0183Rmc::directionToEnum($content[4]);54 56 55 $this->_longitude = $content[5]; 56 $this->_longitudeDirection = Nmea0183Rmc::directionToEnum($content[6]); 57 $this->_latitude = (float)$content[3]; 58 if(Nmea0183Rmc::directionToEnum($content[4]) == Nmea0183Direction::South) 59 $this->_latitude = $this->_latitude * -1; 57 60 58 $this->_speedOverGround = $content[7]; 61 $this->_longitude = (float)$content[5]; 62 if(Nmea0183Rmc::directionToEnum($content[6]) == Nmea0183Direction::West) 63 $this->_longitude = $this->_longitude * -1; 59 64 60 $this->_ courseOverGround = $content[8];65 $this->_speedOverGround = (float)$content[7]; 61 66 62 $this->_magneticDeclination = $content[10]; 67 $this->_courseOverGround = (float)$content[8]; 68 69 $this->_magneticDeclination = (float)$content[10]; 63 70 $this->_magneticDeclinationDirection = Nmea0183Rmc::directionToEnum($content[11]); 64 71 … … 82 89 } 83 90 91 /** 92 * @brief Latitude with North (+) and South (-) 93 */ 84 94 public function latitude() 85 95 { … … 87 97 } 88 98 89 public function latitudeDirection() 90 { 91 return $this->_latitudeDirection; 92 } 93 99 /** 100 * @brief Longitude with East (+) and West (-) 101 */ 94 102 public function longitude() 95 103 { 96 104 return $this->_longitude; 97 }98 99 public function longitudeDirection()100 {101 return $this->_longitudeDirection;102 105 } 103 106 … … 162 165 private $_status; 163 166 private $_latitude; 164 private $_latitudeDirection;165 167 private $_longitude; 166 private $_longitudeDirection;167 168 private $_speedOverGround; 168 169 private $_courseOverGround; -
src/webapp/webservice/inc/GnuBoat/Nmea/Nmea0183/Parser.php
rfc63b30 r008bce9 35 35 $result = array(); 36 36 if(!file_exists($file)){ 37 $message = "NMEA file to parse does not exists: ". $file ."\n";37 $message = "NMEA file to parse does not exists: ". $file; 38 38 error_log($message); 39 39 if($debug > 0) 40 print $message ;40 print $message ."\n"; 41 41 return $result; 42 42 } … … 44 44 $fileHandler = fopen($file, 'r'); 45 45 if(!$fileHandler){ 46 $message = "NMEA file to parse could not be opend for reading: ". $file ."\n";46 $message = "NMEA file to parse could not be opend for reading: ". $file; 47 47 error_log($message); 48 48 if($debug > 0) 49 print $message ;49 print $message ."\n"; 50 50 return $result; 51 51 } … … 61 61 $result[] = $parsedSentence; 62 62 else{ 63 $message = "Skipped sentence on line ". $line .": ". $sentence ."\n";63 $message = "Skipped sentence on line ". $line .": ". $sentence; 64 64 error_log($message); 65 65 if($debug > 0) 66 print $message ;66 print $message ."\n"; 67 67 } 68 68 } … … 75 75 $sentence = trim($sentence); 76 76 if(empty($sentence)){ 77 $message = "Empty sentence \n";77 $message = "Empty sentence"; 78 78 error_log($message); 79 79 if($debug > 0) 80 print $message ;80 print $message ."\n"; 81 81 return null; 82 82 } … … 85 85 $result = preg_match('/^[\$!]{1}([\w]{2})([\w]{3})([^\*]+)\*([\da-zA-Z]+)$/', $sentence, $matches); 86 86 if($result === false || $result != 1 || count($matches) != 5){ 87 $message = "Could not detect talker, type and checksum from ". $sentence ."\n";87 $message = "Could not detect talker, type and checksum from ". $sentence; 88 88 error_log($message); 89 89 if($debug > 0) 90 print $message ;90 print $message ."\n"; 91 91 return null; 92 92 } … … 97 97 98 98 if(!array_key_exists(strtolower($type), $this->_types)){ 99 $message = "Skipping unknown NMEA0183 sentence of type ". $type .": ". $sentence ."\n";99 $message = "Skipping unknown NMEA0183 sentence of type ". $type .": ". $sentence; 100 100 error_log($message); 101 101 if($debug > 0) 102 print $message ;102 print $message ."\n"; 103 103 return null; 104 104 } -
src/webapp/webservice/inc/GnuBoat/Nmea/NmeaSentence.php
rfc63b30 r008bce9 48 48 public function type() 49 49 { 50 return $this->_type;50 return strtolower($this->_type); 51 51 } 52 52 -
src/webapp/webservice/inc/GnuBoat/Service.php
rfc63b30 r008bce9 44 44 $this->process(); 45 45 } 46 47 public static function error($message) 48 { 49 Service::output(["error" => 1, "errormessage" => $message]); 50 } 51 52 public static function output($content) 53 { 54 header('Content-Type: application/json'); 55 echo json_encode($content); 56 } 46 57 47 58 /** -
src/webapp/webservice/inc/GnuBoat/ServiceData.php
rfc63b30 r008bce9 49 49 50 50 if(!file_exists($dbFile)){ 51 echo json_encode("");52 51 if($debug > 0) 53 52 echo "Database file ". $dbFile ." does not exist!"; 54 53 error_log("Database file ". $dbFile ." does not exist"); 55 exit;54 return; 56 55 } 57 56 // Fetch entries of the last 30s with maximum (available) resolution of 2s -
src/webapp/webservice/inc/GnuBoat/ServiceLogFiles.php
rfc63b30 r008bce9 32 32 $debug = $this->debug(); 33 33 $config = new Config(); 34 if($debug > 1) 35 print "Log directory: ". $config->logDirectory() ."\n"; 34 36 35 37 if(!array_key_exists("logfilesSelected", $_POST)){ -
src/webapp/webservice/inc/GnuBoat/Webservice.php
rfc63b30 r008bce9 23 23 class WebService 24 24 { 25 function __construct( )25 function __construct($debug) 26 26 { 27 27 $this->_requests = array(); … … 30 30 $this->_requests["logfiles"] = "GnuBoat\ServiceLogFiles"; 31 31 $this->_requests["map"] = "GnuBoat\ServiceMap"; 32 $this->_requests["replay"] = "GnuBoat\ServiceReplay"; 33 34 $this->_debug = $debug; 32 35 } 33 36 34 37 public function process() 35 38 { 36 $debug = 0;37 if(is_array($_GET) && array_key_exists("debug", $_GET))38 $debug = $_GET["debug"];39 40 39 $request = array_keys($this->_requests)[0]; 41 40 if(is_array($_GET) && array_key_exists("request", $_GET)){ … … 44 43 45 44 if(!array_key_exists($request, $this->_requests)){ 46 $result["error"] = 1; 47 $result["errormessage"] = "Request ". $request ." not implemented"; 48 49 header('Content-Type: application/json'); 50 echo json_encode($result) ."\n"; 51 return; 45 return Service::error("Request ". $request ." not implemented"); 52 46 } 53 54 call_user_func(array(new $this->_requests[$request], "processRequest"), $ debug);47 48 call_user_func(array(new $this->_requests[$request], "processRequest"), $this->_debug); 55 49 } 56 50 57 51 private $_requests; 52 private $_debug; 58 53 } 59 54
Note:
See TracChangeset
for help on using the changeset viewer.
