gpt4 book ai didi

c - 无法连接到 gpsd

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:51:38 25 4
gpt4 key购买 nike

我有一 block 板子,上面运行着 Linux Ångström。现在我不想在我的程序中获取 GPS 数据。所以我设置了一个 gpsdeamon 从调制解调器获取他的 gps 信息。守护进程运行良好,如果我远程登录到 localhost:2947(这是 gpsd 的标准端口),我会从守护进程接收到一堆 json 字符串,如下所示:

{"class":"TPV","tag":"GGA","device":"/dev/ttyUSB2","mode":3,"lat":51.282822633," lon":11.404333250,"alt":327.500}

所以 gpsd 似乎设置正确。

但是在我的 C 程序中我无法连接到这个端口,我也不知道为什么。我的代码看起来像这样:

#include <gps.h>
struct gps_data_t *gpsdata = 0;

int main() {
if(gps_open("localhost", "2947", gpsdata)<0){
fprintf(stderr,"Could not connect to GPSd\n");
return(-1);
}
/* some more stuff */
}

问题是,函数 gps_open() 总是返回 -1。所有库似乎都已正确安装。你有什么想法,我可以尝试让它发挥作用吗?

最佳答案

您可以使用 gps_errstr 函数查看错误,如下所示

#include <errno.h>
...

int main()
{
if(gps_open("localhost", "2947", gpsdata)<0){
fprintf(stderr,"Could not connect to GPSd (error %s)\n",
gps_errstr(errno));
return(-1);
}
/* some more stuff */
}

但是,问题是 gps_open 需要一个指向有效(非空)gps_data_t 结构的指针,您可以声明 gpsdata这样

struct gps_data_t gpsdata[1];

关于c - 无法连接到 gpsd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30773098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com