| [86442cb] | 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;
|
|---|
| 20 |
|
|---|
| 21 | require_once(__DIR__ ."/../../autoloader.php");
|
|---|
| 22 |
|
|---|
| 23 | /**
|
|---|
| 24 | * @brief Use this class to parse a single NMEA sentence (parseSentence()) or a complete file (parseFile())
|
|---|
| 25 | *
|
|---|
| 26 | */
|
|---|
| 27 | class Parser
|
|---|
| 28 | {
|
|---|
| 29 | function __construct($debug = 0)
|
|---|
| 30 | {
|
|---|
| 31 | $this->_debug = $debug;
|
|---|
| 32 |
|
|---|
| 33 | $this->_formats = array();
|
|---|
| 34 | if(canClassBeLoaded("GnuBoat\Nmea\Nmea0183\Parser"))
|
|---|
| 35 | $this->_formats["0183"] = "GnuBoat\Nmea\Nmea0183\Parser";
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | public function formatsSupported()
|
|---|
| 39 | {
|
|---|
| 40 | return array_keys($this->_formats);
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | /**
|
|---|
| 44 | * @brief Returns an array of NmeaSentence objects, specialized for the type of sentence
|
|---|
| 45 | */
|
|---|
| 46 | function parseFile($file, $format)
|
|---|
| 47 | {
|
|---|
| 48 | return call_user_func(array(new $this->_formats[$format], "parseFile"), $file, $this->_debug);
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | /**
|
|---|
| 52 | * @brief Returns an NmeaSentence object, specialized for the type of sentence
|
|---|
| 53 | */
|
|---|
| 54 | function parseSentence($sentence, $format)
|
|---|
| 55 | {
|
|---|
| 56 | if(!array_key_exists($format, $this->_formats)){
|
|---|
| 57 | $message = "No handler for requested format ". $format ." found\n";
|
|---|
| 58 | error_log($message);
|
|---|
| 59 | if($this->_debug > 0)
|
|---|
| 60 | print $message;
|
|---|
| 61 | return null;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | if(empty($sentence)){
|
|---|
| 65 | $message = "Empty sentence\n";
|
|---|
| 66 | error_log($message);
|
|---|
| 67 | if($this->_debug > 0)
|
|---|
| 68 | print $message;
|
|---|
| 69 | return null;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | return call_user_func(array(new $this->_formats[$format], "parseSentence"), $sentence, $this->_debug);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | private $_formats;
|
|---|
| 76 | private $_debug;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | ?>
|
|---|