libgps.xml

来自「gpsd, a popular GPS daemon.」· XML 代码 · 共 223 行

XML
223
字号
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"                   "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"><!-- lifted from troff+man by doclifter --><refentry><refentryinfo><date>14 Aug 2004</date></refentryinfo><refmeta><refentrytitle>3</refentrytitle><manvolnum>3</manvolnum><refmiscinfo class='source'>Linux</refmiscinfo></refmeta><refnamediv id='name'><refname>libgps</refname><refpurpose>C service library for communicating with the GPS daemon</refpurpose></refnamediv><refsynopsisdiv id='synopsis'><funcsynopsis><funcsynopsisinfo>C:#include &lt;gps.h&gt;</funcsynopsisinfo><funcprototype><funcdef>struct gps_data_t *<function>gps_open</function></funcdef>    <paramdef>char *<parameter>server</parameter></paramdef>    <paramdef>char * <parameter>port</parameter></paramdef></funcprototype><funcprototype><funcdef>int <function>gps_query</function></funcdef>    <paramdef>struct gps_data_t *<parameter>gpsdata</parameter></paramdef>    <paramdef>char *<parameter>fmt</parameter>...</paramdef></funcprototype><funcprototype><funcdef>void <function>gps_set_raw_hook</function></funcdef>    <paramdef>struct gps_data_t *<parameter>gpsdata</parameter></paramdef>    <paramdef>void (*<parameter>hook</parameter>)(struct gps_data_t *, char *buf)</paramdef></funcprototype><funcprototype><funcdef>int <function>gps_poll</function></funcdef>    <paramdef>struct gps_data_t *<parameter>gpsdata</parameter></paramdef></funcprototype><funcprototype><funcdef>void <function>gps_close</function></funcdef>    <paramdef>struct gps_data_t *<parameter>gpsdata</parameter></paramdef></funcprototype><funcprototype><funcdef>void <function>gps_set_callback</function></funcdef>    <paramdef>struct gps_data_t *<parameter>gpsdata</parameter></paramdef>    <paramdef>void (*<parameter>callback</parameter>)(struct gps_data_t *sentence, char *buf)</paramdef>    <paramdef>pthread_t *<parameter>handler</parameter></paramdef></funcprototype><funcprototype><funcdef>void <function>gps_del_callback</function></funcdef>    <paramdef>struct gps_data_t *<parameter>gpsdata</parameter></paramdef>    <paramdef>pthread *<parameter>handler</parameter></paramdef></funcprototype><funcprototype><funcdef>void <function>rtcm_unpack</function></funcdef>    <paramdef>struct rtcm_t *<parameter>rtcmp</parameter></paramdef>    <paramdef>char *<parameter>buf</parameter></paramdef></funcprototype><funcsynopsisinfo>Python:import gpssession = gps.gps(host="127.0.0.1", port="2947")session.set_raw_hook(raw_hook)session.query(commands)session.poll()del session</funcsynopsisinfo></funcsynopsis></refsynopsisdiv><refsect1 id='description'><title>DESCRIPTION</title><para><emphasis remap='B'>libgps</emphasis> is a service library whichsupports querying GPS devices; link it with the linker option-lgps. There are two interfaces supported in it; one high-levelinterface that goes through<citerefentry><refentrytitle>gpsd</refentrytitle><manvolnum>1</manvolnum></citerefentry>and is intended for concurrent use by several applications, and onelow-level interface that speaks directly with the serial or USB deviceto which the GPS is attached. This page describes the high-levelinterface that is safe for multiple applications to use simultaneously; itis probably the one you want.  The low-level interface is documentedat<citerefentry><refentrytitle>libgpsd</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para><para>Calling <function>gps_open()</function> initializes a GPS-datastructure to hold the data collected by the GPS, and returns a socketattached to<citerefentry><refentrytitle>gpsd</refentrytitle><manvolnum>1</manvolnum></citerefentry>. <function>gps_open()</function> returns NULL on errors.  errno isset depending on the error returned from the the socket layer; see<filename>gps.h</filename> for values and explanations.</para><para><function>gps_close()</function> ends the session.</para><para><function>gps_poll()</function> accepts a response, or sequenceof responses, from the daemon and interprets it as though it were aquery response (the return value is as for a query).<function>gps_poll()</function> returns the validity mask of thereceived structure.  This function does a blocking read waiting fordata from the daemon; it returns 0 for success, or -1 on a Unix-levelread error. </para><para><function>gps_query()</function> writes a command to thedaemon, accepts a one-line response, and updates parts of the GPS-datastructure that correspond to data changed since the last call.  Thesecond argument must be a format string containing letters from the commandset documented at<citerefentry><refentrytitle>gpsd</refentrytitle><manvolnum>1</manvolnum></citerefentry>.It may have % elements as for <citerefentry><refentrytitle>sprintf</refentrytitle><manvolnum>3</manvolnum></citerefentry>,which will be filled in from any following arguments.This function returns a 0 on success, or a -1 if there was aUnix-level read error.</para><para><function>gps_set_raw_hook()</function> takes a function youspecify and run it (synchronously) on the raw data pulled by a<function>gps_query()</function> or <function>gps_poll()</function>call.  The arguments passed to this hook will be a pointer to astructure containing parsed data, and a buffer containining theraw <application>gpsd</application> response.</para><para><function>gps_set_callback()</function> takes a function youspecify and runs it asynchronously each time new data arrives from<application>gpsd</application>, using POSIX threads.  For example,you can call gps_set_callback(gpsdata, my_function, handler) once inyour program, and from there on your gpsdata structure will be parsedby your <function>my_function()</function> each time new data areavailable.  <function>my_function()</function> could change someglobal variables in your program based on received data; it is yourresponsibility to ensure that your program uses mutexes or othermechanisms to avoid race conditions.</para><para><function>gps_del_callback()</function> deregisters the callbackfunction previously set with <function>gps_set_callback()</function>.After the invocation of this function no operation will be done whennew data arrives.</para><para>Consult <filename>gps.h</filename> to learn more about the data members and associated timestamps.  Note that information will accumulatein the session structure over time, and the 'valid' field is notautomatically zeroed by each poll.  It is up to the client tozero that field when appropriate and to keep an eye on the fix and sentence timestamps.</para><para>The <function>rtcm_unpack()</function> will be useful when youare connected to an RTCM-104 source in raw mode.  Use it as part of araw hook, calling it with the address of the <structname>structrtcm_t</structname> element of your session structure buffer as firstargument and the buffer as the second.  It will unpack a line of RTCMdata into the structure.  This function returns 0 when it has read thelast line of an RTCM-104 message, a positive int when it expects moredump lines, and a negative int on parse failure. You must zero out the<structname>struct rtcm_t</structname> each time before this functionis called on a new header (H) line, as it relies on the message typefield being initially zero and uses it to track what kind of following line is expected.</para><para>The Python implementation supports the same facilities as the Clibrary. <function>gps_open()</function> is replaced by theinitialization of a gps session object; the other calls are methods ofthat object, and have the same names as the corresponding C functions.Resources within the session object will be properly released when itis garbage-collected.</para></refsect1><refsect1 id='example'><title>CODE EXAMPLE</title><para>The following is an excerpted and simplified version of thelibgps interface code from<citerefentry><refentrytitle>gps</refentrytitle><manvolnum>1</manvolnum></citerefentry>.The function <function>handle_input()</function> is a trivial pies ofcode that calls gps_poll(gpsdata).</para><programlisting>    gpsdata = gps_open(server, port);    build_gui(toplevel);    gps_set_raw_hook(gpsdata, update_panel);	    (void)gps_query(gpsdata, "w+x\n");    (void)XtAppAddInput(app, gpsdata->gps_fd, 		  (XtPointer)XtInputReadMask, handle_input, NULL);    (void)XtAppMainLoop(app);    (void)gps_close(gpsdata);</programlisting></refsect1><refsect1 id='see_also'><title>SEE ALSO</title><para><citerefentry><refentrytitle>gpsd</refentrytitle><manvolnum>8</manvolnum></citerefentry>,<citerefentry><refentrytitle>gps</refentrytitle><manvolnum>1</manvolnum></citerefentry>,<citerefentry><refentrytitle>libgps</refentrytitle><manvolnum>3</manvolnum></citerefentry>.<citerefentry><refentrytitle>libgpsmm</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></refsect1><refsect1 id='author'><title>AUTHOR</title><para>Eric S. Raymond &lt;esr@thyrsus.com&gt;, Thread-callback methodsin the C binding added by Alfredo Pironti&lt;alfredo@users.sourceforge.net&gt;.</para></refsect1></refentry>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?