bulton-fr / nmea-parser
NMEA PHP 解析器
1.0.0
2017-09-17 00:00 UTC
Requires
- php: >=7.1.0
Requires (Dev)
- atoum/atoum: ~3.2
- atoum/visibility-extension: ^1.3
- scrutinizer/ocular: ~1.5
This package is auto-updated.
Last update: 2024-08-27 00:22:00 UTC
README
读取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 BultonFr\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 BultonFr\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"
}
除了 frameRegex
、message
和 checksum
之外的所有属性都有一个getter。
添加新的帧类型
在命名空间 BultonFr\NMEA\Frames
中添加一个新的类。否则,您需要扩展 Parser
类并重新定义方法 obtainFrameParser
。
类的名称需要与帧类型名称相同。例如,对于帧类型 GGA,名称为 GGA
。这个类应该扩展类 \BultonFr\NMEA\Frame
。
您应该有属性 $frameType
和 $frameRegex
。并且应该声明方法 decodeFrame
。
$frameType
应该包含帧类型的名称。
$frameRegex
是用于解析行的正则表达式。
decodeFrame
是在正则表达式解析行之后调用的方法。此方法的参数是 preg_match
函数的第三个参数。因此,此参数包含消息的所有部分。在此方法中,您可以填充属性以使用行值。