source: src/webapp/webservice/inc/GnuBoat/ServiceReplay.php@ 26f77a6

0.5 debian/bullseye debian/jessie
Last change on this file since 26f77a6 was 008bce9, checked in by Joachim Langenbach <joachim.langenbach@…>, 9 years ago

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

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[008bce9]1<?php
2/*
3 Copyright (C) 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19namespace GnuBoat;
20
21require_once(__DIR__ ."/../autoloader.php");
22
23class ServiceReplay extends Service
24{
25 function __construct()
26 {
27 parent::__construct();
28 }
29
30 protected function process()
31 {
32 $debug = $this->debug();
33 $config = new Config();
34 if($debug > 1)
35 print "Log directory: ". $config->logDirectory() ."\n";
36
37 if(!array_key_exists("logfile", $_POST)){
38 return $this->error("No logfile to replay selected");
39 }
40
41 // prepare a download of available log files
42 $file = $config->logDirectory() . $_POST["logfile"];
43 if(!file_exists($file))
44 return $this->error("Logfile ". $file ." not found");
45
46 $parser = new Nmea\Parser();
47 $nmeaSentences = $parser->parseFile($file, '0183');
48 if($nmeaSentences == null)
49 return error("Error parsing logfile ". $file);
50
51 $result = ["track" => []];
52 $currentItem = new TrackItem();
53 foreach($nmeaSentences as $sentence){
54 if($sentence->type() == "rmc"){
55 if($currentItem->isValid()){
56 $result["track"][$currentItem->timestamp()] = $currentItem->toArray();
57 $currentItem = new TrackItem();
58 }
59 $currentItem->setDateTime($sentence->dateTime());
60 $currentItem->setLatitude($sentence->latitude());
61 $currentItem->setLongitude($sentence->longitude());
62 $currentItem->setSpeedOverGround($sentence->speedOverGround());
63 $currentItem->setCourseOverGround($sentence->courseOverGround());
64 }
65 elseif($sentence->type() == "dpt"){
66 $currentItem->setWaterDepth($sentence->depth());
67 }
68 elseif($sentence->type() == "mtw"){
69 $currentItem->setWaterTemperature($sentence->temperature());
70 }
71 }
72 if($currentItem->isValid())
73 $result["track"][$currentItem->timestamp()] = $currentItem->toArray();
74
75 $this->output($result);
76 }
77}
78
79?>
Note: See TracBrowser for help on using the repository browser.