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