nykopol / gpsd-client
GPSD服务客户端类
Requires
- php: >=5.3||^7.0
This package is auto-updated.
Last update: 2024-09-10 04:36:42 UTC
README
PHP客户端,用于从GPSD服务中检索信息。更多关于GPSD的信息:http://catb.org/gpsd/
安装
composer require nykopol/gpsd-client 1.*
使用方法
基本使用
$client = new Client(); // new client for localhost on port 2947 $client->connect(); // Initiate socket with the service $client->watch(); // Tell the service to start report event $infos = $client->getNext('TPV'); // Get the next message of class TPV ()
文档
__construct($host = 'localhost', $port = 2947)
类实例化接受两个参数: $host string
(默认: localhost
)我们想要监听的宿主机 $port integer
(默认: 2947
)套接字端口
connect()
此方法将套接字连接到服务。返回值是服务返回的标识自己的字符串。例如:{"class":"VERSION","release":"2.93","rev":"2010-03-30T12:18:17", "proto_major":3,"proto_minor":2}
watch($enable = true, $format = 'json')
watch方法告诉服务开始报告传感器事件。此方法接受两个参数: $enable bool
(默认: true
)告诉服务开始或停止监听。 $format string
(默认: json
)设置返回数据的所需格式
getNext($class, $buffer = false, $blocking = true)
返回给定类的下一个消息。当前服务类包括 WATCH
、DEVICES
、DEVICE
、TPV
、AIS
。此方法接受三个参数: $class string
想要的类名。 $buffer bool
(默认: false
)设备同步后,服务通常每秒报告一条消息。此参数指定我们是否想要来自缓冲区的下一个消息还是时间上的下一个消息。 $blocking bool
(默认: true
)等待下一个消息,如果没有新消息则返回null。此选项仅在启用缓冲区时相关。
例如,如果您已连接到服务1分钟,并且传感器已同步,则缓冲区中的下一个消息可能已老化约1分钟。而请求时间上的下一个消息将刷新缓冲区,然后等待所需类的下一个消息。
返回值是服务返回的原始字符串。因此,如果您使用watch方法请求json格式,则返回值将类似于:{"class":"TPV","tag":"MID2","time":"2010-04...
disconnect()
从服务断开连接。