elsayed85/nmea-parser

NMEA PHP 解析器

1.0.0 2017-09-17 00:00 UTC

This package is auto-updated.

Last update: 2024-09-26 04:21:17 UTC


README

Build Status Code Coverage Scrutinizer Code Quality

Latest Stable Version Latest Unstable Version License

读取 NMEA 行,检测帧类型并将行解析以获取所有数据。

支持的帧类型

  • GGA
  • GLL
  • GSA
  • GSV
  • RMC
  • VTG

安装它

使用 composer

将以下内容添加到 composer.json 文件中

{
    "require": {
        "bulton-fr/nmea-parser": "master",
    }
}

使用它

<?php

//Require composer autoload
require_once(__DIR__.'/vendor/autoload.php');

//Instanciate the parser
$parser = new Elsayed85\NMEA\Parser;

//Déclare a line to parse
$line = '$GPGGA,064036.289,4836.5375,N,00740.9373,E,1,04,3.2,200.2,M,,,,0000*0E';

//Parse the line
$frame = $parser->readLine($line);

$frame 包含关于读取行的所有数据。如果你 var_dump($frame)

class Elsayed85\NMEA\Frames\GGA#2 (19) {
  protected $frameType => string(3) "GGA"
  protected $frameRegex => string(175) "/^([A-Z]{2}[A-Z]{3}),(\d{6}\.\d{2,3}),([0-9\.]+),(N|S),([0-9\.]+),(E|W),(\d{0,1}),(\d{0,2}),([0-9\.]*),([0-9\.]*),([A-Z]{0,1}),([0-9\.-]*),([A-Z]{0,1}),([0-9\.]*),(\d{0,4})$/m"
  protected $utcTime => class DateTime#5 (3) {
    public $date => string(26) "2017-09-29 06:40:36.289000"
    public $timezone_type => int(3)
    public $timezone => string(3) "UTC"
  }
  protected $latitude => string(9) "4836.5375"
  protected $latitudeDirection => string(1) "N"
  protected $longitude => string(10) "00740.9373"
  protected $longitudeDirection => string(1) "E"
  protected $gpsQuality => int(1)
  protected $nbSatellites => int(4)
  protected $horizontalDilutionPrecision => double(3.2)
  protected $altitude => double(200.2)
  protected $altitudeUnit => string(1) "M"
  protected $geoidalSeparation => double(0)
  protected $geoidalSeparationUnit => string(0) ""
  protected $ageGpsData => double(0)
  protected $differentialRefStationId => int(0)
  protected $line => string(70) "$GPGGA,064036.289,4836.5375,N,00740.9373,E,1,04,3.2,200.2,M,,,,0000*0E"
  protected $message => string(66) "GPGGA,064036.289,4836.5375,N,00740.9373,E,1,04,3.2,200.2,M,,,,0000"
  protected $checksum => string(2) "0E"
}

除了 frameRegexmessagechecksum 之外的所有属性都有一个 getter。

添加新帧类型

在命名空间 Elsayed85\NMEA\Frames 中添加一个新类。否则,你需要扩展 Parser 类并重新定义 obtainFrameParser 方法。

类的名称需要是帧类型的名称。例如,对于帧类型 GGA,类名应该是 GGA。这个类应该扩展 \Elsayed85\NMEA\Frame 类。

你应该有 $frameType$frameRegex 属性。并且应该声明 decodeFrame 方法。

$frameType 应该包含帧类型的名称。

$frameRegex 是用于解析行的正则表达式。

decodeFrame 是在用正则表达式解析行之后调用的方法。此方法的参数是 preg_match 函数的第三个参数。因此,此参数包含消息的所有部分。在这个方法中,你可以使用行的值填充你的属性。