source: src/webapp/webservice/inc/GnuBoat/Nmea/Nmea0183/Nmea0183Rmc.php@ fc63b30

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

Added Nmea0183 Parsers to the PHP webservice to allow the user to load a logfile into the map
(loading the logfile and display it on the map is not implemented yet)

  • Property mode set to 100644
File size: 4.4 KB
Line 
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\Nmea\Nmea0183;
20
21class Nmea0183Rmc extends Nmea0183Sentence
22{
23 function __construct($talker, $checksum, $sentence)
24 {
25 parent::__construct("RMC", $talker, $checksum, $sentence);
26
27 // init default values
28 $this->_dateTimeUtc = null;
29 $this->_status = Nmea0183RmcStatus::V;
30 $this->_latitude = 0;
31 $this->_latitudeDirection = Nmea0183Direction::Invalid;
32 $this->_longitude = 0;
33 $this->_longitudeDirection = Nmea0183Direction::Invalid;
34 $this->_speedOverGround = 0;
35 $this->_courseOverGround = 0;
36 $this->_magneticDeclination = 0;
37 $this->_magneticDeclinationDirection = Nmea0183Direction::Invalid;
38 $this->_signalIntegrity = Nmea0183RmcSignal::DataNotValid;
39
40 $content = explode(",", $sentence);
41 if(count($content) != 13)
42 return;
43
44 if(strlen($content[1]) > 6)
45 $this->_dateTimeUtc = \DateTime::createFromFormat('dmy His.u', $content[9] ." ". $content[1], new \DateTimeZone("UTC"));
46 else
47 $this->_dateTimeUtc = \DateTime::createFromFormat('dmy His', $content[9] ." ". $content[1], new \DateTimeZone("UTC"));
48
49 if($content[2] == 'A')
50 $this->_status = Nmea0183RmcStatus::A;
51
52 $this->_latitude = $content[3];
53 $this->_latitudeDirection = Nmea0183Rmc::directionToEnum($content[4]);
54
55 $this->_longitude = $content[5];
56 $this->_longitudeDirection = Nmea0183Rmc::directionToEnum($content[6]);
57
58 $this->_speedOverGround = $content[7];
59
60 $this->_courseOverGround = $content[8];
61
62 $this->_magneticDeclination = $content[10];
63 $this->_magneticDeclinationDirection = Nmea0183Rmc::directionToEnum($content[11]);
64
65 $tmp = explode("*", $content[12]);
66 $this->_signalIntegrity = Nmea0183Rmc::signalIntegrityToEnum($tmp[0]);
67 }
68
69 public function dateTime($timezone = "UTC")
70 {
71 $timezone = new \DateTimeZone($timezone);
72 $date = $this->_dateTimeUtc;
73 if($date == null)
74 return null;
75 $date->setTimezone($timezone);
76 return $date;
77 }
78
79 public function status()
80 {
81 return $this->_status;
82 }
83
84 public function latitude()
85 {
86 return $this->_latitude;
87 }
88
89 public function latitudeDirection()
90 {
91 return $this->_latitudeDirection;
92 }
93
94 public function longitude()
95 {
96 return $this->_longitude;
97 }
98
99 public function longitudeDirection()
100 {
101 return $this->_longitudeDirection;
102 }
103
104 public function speedOverGround()
105 {
106 return $this->_speedOverGround;
107 }
108
109 public function courseOverGround()
110 {
111 return $this->_courseOverGround;
112 }
113
114 public function magneticDeclination()
115 {
116 return $this->_magneticDeclination;
117 }
118
119 public function magneticDeclinationDirection()
120 {
121 return $this->_magneticDeclinationDirection;
122 }
123
124 public function signalIntegrity()
125 {
126 return $this->_signalIntegrity;
127 }
128
129 private static function directionToEnum($direction)
130 {
131 switch($direction){
132 case 'N':
133 return Nmea0183Direction::North;
134 case 'E':
135 return Nmea0183Direction::East;
136 case 'S':
137 return Nmea0183Direction::South;
138 case 'W':
139 return Nmea0183Direction::West;
140 }
141 return Nmea0183Direction::Invalid;
142 }
143
144 private static function signalIntegrityToEnum($integrity)
145 {
146 switch($integrity){
147 case 'A':
148 return Nmea0183RmcSignal::AutonomousMode;
149 case 'D':
150 return Nmea0183RmcSignal::DifferentialMode;
151 case 'E':
152 return Nmea0183RmcSignal::EstimatedMode;
153 case 'M':
154 return Nmea0183RmcSignal::ManualInputMode;
155 case 'S':
156 return Nmea0183RmcSignal::SimulatedMode;
157 }
158 return Nmea0183RmcSignal::DataNotValid;
159 }
160
161 private $_dateTimeUtc;
162 private $_status;
163 private $_latitude;
164 private $_latitudeDirection;
165 private $_longitude;
166 private $_longitudeDirection;
167 private $_speedOverGround;
168 private $_courseOverGround;
169 private $_magneticDeclination;
170 private $_magneticDeclinationDirection;
171 private $_signalIntegrity;
172}
173
174?>
Note: See TracBrowser for help on using the repository browser.