Devuan fork of gpsd
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

306 lines
12 KiB

  1. '\" t
  2. .\" Title: libgps
  3. .\" Author: [see the "AUTHOR" section]
  4. .\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
  5. .\" Date: 4 Feb 2019
  6. .\" Manual: GPSD Documentation
  7. .\" Source: The GPSD Project
  8. .\" Language: English
  9. .\"
  10. .TH "LIBGPS" "3" "4 Feb 2019" "The GPSD Project" "GPSD Documentation"
  11. .\" -----------------------------------------------------------------
  12. .\" * Define some portability stuff
  13. .\" -----------------------------------------------------------------
  14. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. .\" http://bugs.debian.org/507673
  16. .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
  17. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. .ie \n(.g .ds Aq \(aq
  19. .el .ds Aq '
  20. .\" -----------------------------------------------------------------
  21. .\" * set default formatting
  22. .\" -----------------------------------------------------------------
  23. .\" disable hyphenation
  24. .nh
  25. .\" disable justification (adjust text to left margin only)
  26. .ad l
  27. .\" -----------------------------------------------------------------
  28. .\" * MAIN CONTENT STARTS HERE *
  29. .\" -----------------------------------------------------------------
  30. .SH "NAME"
  31. libgps \- C service library for communicating with the GPS daemon
  32. .SH "SYNOPSIS"
  33. .sp
  34. .ft B
  35. .nf
  36. C:
  37. #include <gps\&.h>
  38. .fi
  39. .ft
  40. .HP \w'int\ gps_open('u
  41. .BI "int gps_open(char\ *" "server" ", char\ *" "port" ", struct\ gps_data_t\ *" "gpsdata" ");"
  42. .HP \w'int\ gps_send('u
  43. .BI "int gps_send(struct\ gps_data_t\ *" "gpsdata" ", char\ *" "fmt" "\&.\&.\&.);"
  44. .HP \w'int\ gps_read('u
  45. .BI "int gps_read(struct\ gps_data_t\ *" "gpsdata" ", char\ *" "message" ", int\ " "message_size" ");"
  46. .HP \w'bool\ gps_waiting('u
  47. .BI "bool gps_waiting(const\ struct\ gps_data_t\ *" "gpsdata" ", int\ " "timeout" ");"
  48. .HP \w'char\ *gps_data('u
  49. .BI "char *gps_data(const\ struct\ gps_data_t\ *" "gpsdata" ");"
  50. .HP \w'int\ gps_unpack('u
  51. .BI "int gps_unpack(char\ *" "buf" ", struct\ gps_data_t\ *" "gpsdata" ");"
  52. .HP \w'int\ gps_close('u
  53. .BI "int gps_close(struct\ gps_data_t\ *" "gpsdata" ");"
  54. .HP \w'int\ gps_stream('u
  55. .BI "int gps_stream(struct\ gps_data_t\ *" "gpsdata" ", unsigned\ int" "flags" ", void\ *" "data" ");"
  56. .HP \w'int\ gps_mainloop('u
  57. .BI "int gps_mainloop(struct\ gps_data_t\ *" "gpsdata" ", int\ " "timeout" ", void\ (*" "hook" ")(struct\ gps_data_t\ *gpsdata));"
  58. .HP \w'const\ char\ *gps_errstr('u
  59. .BI "const char *gps_errstr(int\ " "err" ");"
  60. .sp
  61. .ft B
  62. .nf
  63. Python:
  64. import gps
  65. session = gps\&.gps(host="localhost", port="2947")
  66. session\&.stream(flags=gps\&.WATCH_JSON)
  67. for report in session:
  68. process(report)
  69. del session
  70. .fi
  71. .ft
  72. .SH "DESCRIPTION"
  73. .PP
  74. \fBlibgps\fR
  75. is a service library which supports communicating with an instance of the
  76. \fBgpsd\fR(8); link it with the linker option \-lgps\&.
  77. .if n \{\
  78. .sp
  79. .\}
  80. .RS 4
  81. .it 1 an-trap
  82. .nr an-no-space-flag 1
  83. .nr an-break-flag 1
  84. .br
  85. .ps +1
  86. \fBWarning\fR
  87. .ps -1
  88. .br
  89. .PP
  90. Take care to conditionalize your code on the major and minor API version symbols in
  91. gps\&.h; ideally, force a compilation failure if GPSD_API_MAJOR_VERSION is not a version you recognize\&. See the GPSD project website for more information on the protocol and API changes\&.
  92. .sp .5v
  93. .RE
  94. .PP
  95. Calling
  96. \fBgps_open()\fR
  97. initializes a GPS\-data structure to hold the data collected by the GPS, and sets up access to
  98. \fBgpsd\fR(1)
  99. via either the socket or shared\-memory export\&. The shared\-memory export is faster, but does not carry information about device activation and deactivation events and will not allow you to monitor device packet traffic\&.
  100. .PP
  101. \fBgps_open()\fR
  102. returns 0 on success, \-1 on errors and is re\-entrant\&. errno is set depending on the error returned from the socket or shared\-memory interface; see
  103. gps\&.h
  104. for values and explanations; also see
  105. \fBgps_errstr()\fR\&. The host address may be a DNS name, an IPv4 dotted quad, an IPV6 address, or the special value
  106. \fBGPSD_SHARED_MEMORY\fR
  107. referring to the shared\-memory export; the library will do the right thing for any of these\&.
  108. .PP
  109. \fBgps_close()\fR
  110. ends the session and should only be called after a successful
  111. \fBgps_open()\fR\&. It returns 0 on success, \-1 on errors\&. The shared\-memory interface close always returns 0, whereas a socket close can result in an error\&. For a socket close error it will have set an errno from the call to the system\*(Aqs
  112. \fBclose()\fR\&.
  113. .PP
  114. \fBgps_send()\fR
  115. writes a command to the daemon\&. It does nothing when using the shared\-memory export\&. The second argument must be a format string containing elements from the command set documented at
  116. \fBgpsd\fR(1)\&. It may have % elements as for
  117. \fBsprintf\fR(3), which will be filled in from any following arguments\&. This function returns a \-1 if there was a Unix\-level write error, otherwise 0\&. Please read the LIMITATIONS section for additional information and cautions\&. See
  118. \fBgps_stream()\fR
  119. as a possible alternative\&.
  120. .PP
  121. \fBgps_read()\fR
  122. accepts a response, or sequence of responses, from the daemon and interprets\&. This function does either a nonblocking read for data from the daemon or a fetch from shared memory; it returns a count of bytes read for success, \-1 with errno set on a Unix\-level read error, \-1 with errno not set if the socket to the daemon has closed or if the shared\-memory segment was unavailable, and 0 if no data is available\&.
  123. .PP
  124. \fBgps_waiting()\fR
  125. can be used to check whether there is new data from the daemon\&. The second argument is the maximum amount of time to wait (in microseconds) on input before returning\&. It returns true if there is input waiting, false on timeout (no data waiting) or error condition\&. When using the socket export, this function is a convenience wrapper around a
  126. \fBselect\fR(2)
  127. call, and zeros
  128. \fIerrno\fR
  129. on entry; you can test
  130. \fIerrno\fR
  131. after exit to get more information about error conditions\&. Warning: under the shared\-memory interface there is a tiny race window between
  132. \fBgps_waiting()\fR
  133. and a following
  134. \fBgps_read()\fR; in that context, because the latter does not block, it is probably better to write a simple read loop\&.
  135. .PP
  136. \fBgps_mainloop()\fR
  137. enables the provided hook function to be continually called whenever there is gpsd data\&. The second argument is the maximum amount of time to wait (in microseconds) on input before exiting the loop (and return a value of \-1)\&. It will also return a negative value on various errors\&.
  138. .PP
  139. \fBgps_unpack()\fR
  140. parses JSON from the argument buffer into the target of the session structure pointer argument\&. Included in case your application wishes to manage socket I/O itself\&.
  141. .PP
  142. \fBgps_data()\fR
  143. returns the contents of the client data buffer (it returns NULL when using the shared\-memory export)\&. Use with care; this may fail to be a NUL\-terminated string if WATCH_RAW is enabled\&.
  144. .PP
  145. \fBgps_stream()\fR
  146. asks
  147. gpsd
  148. to stream the reports it has at you, to be made available when you poll (not available when using the shared\-memory export)\&. The second argument is a flag mask that sets various policy bits; see the list below\&. Calling
  149. \fBgps_stream()\fR
  150. more than once with different flag masks is allowed\&.
  151. .PP
  152. WATCH_DISABLE
  153. .RS 4
  154. Disable the reporting modes specified by the other WATCH_ flags\&.
  155. .RE
  156. .PP
  157. WATCH_ENABLE
  158. .RS 4
  159. Disable the reporting modes specified by the other WATCH_ flags\&. This is the default\&.
  160. .RE
  161. .PP
  162. WATCH_JSON
  163. .RS 4
  164. Enable JSON reporting of data\&. If WATCH_ENABLE is set, and no other WATCH flags are set, this is the default\&.
  165. .RE
  166. .PP
  167. WATCH_NMEA
  168. .RS 4
  169. Enable generated pseudo\-NMEA reporting on binary devices\&.
  170. .RE
  171. .PP
  172. WATCH_RARE
  173. .RS 4
  174. Enable reporting of binary packets in encoded hex\&.
  175. .RE
  176. .PP
  177. WATCH_RAW
  178. .RS 4
  179. Enable literal passthrough of binary packets\&.
  180. .RE
  181. .PP
  182. WATCH_SCALED
  183. .RS 4
  184. When reporting AIS or Subframe data, scale integer quantities to floats if they have a divisor or rendering formula associated with them\&.
  185. .RE
  186. .PP
  187. WATCH_NEWSTYLE
  188. .RS 4
  189. Force issuing a JSON initialization and getting new\-style responses\&. This is the default\&.
  190. .RE
  191. .PP
  192. WATCH_OLDSTYLE
  193. .RS 4
  194. Force issuing a W or R command and getting old\-style responses\&. Warning: this flag (and the capability) will be removed in a future release\&.
  195. .RE
  196. .PP
  197. WATCH_DEVICE
  198. .RS 4
  199. Restrict watching to a specified device, path given as second argument\&.
  200. .RE
  201. .PP
  202. \fBgps_errstr()\fR
  203. returns an ASCII string (in English) describing the error indicated by a nonzero return value from
  204. \fBgps_open()\fR\&.
  205. .PP
  206. Consult
  207. gps\&.h
  208. to learn more about the data members and associated timestamps\&. Note that information will accumulate in the session structure over time, and the \*(Aqvalid\*(Aq field is not automatically zeroed by each
  209. \fBgps_read()\fR\&. It is up to the client to zero that field when appropriate and to keep an eye on the fix and sentence timestamps\&.
  210. .PP
  211. The Python implementation supports the same facilities as the socket\-export calls in the C library; there is no shared\-memory interface\&.
  212. \fBgps_open()\fR
  213. is replaced by the initialization of a gps session object; the other calls are methods of that object, and have the same names as the corresponding C functions\&. However, it is simpler just to use the session object as an iterator, as in the example given below\&. Resources within the session object will be properly released when it is garbage\-collected\&.
  214. .SH "ENVIRONMENT VARIABLES"
  215. .PP
  216. By setting the environment variable
  217. \fBGPSD_SHM_KEY\fR, you can control the key value used to create shared\-memory segment used for communication with
  218. gpsd\&. This will be useful mainly when isolating test instances of
  219. gpsd
  220. from production ones\&.
  221. .SH "CODE EXAMPLE"
  222. .PP
  223. The following is an excerpted and simplified version of the libgps interface code from
  224. \fBcgps\fR(1)\&.
  225. .sp
  226. .if n \{\
  227. .RS 4
  228. .\}
  229. .nf
  230. struct gps_data_t gps_data;
  231. ret = gps_open(hostName, hostPort, &gps_data);
  232. (void) gps_stream(&gps_data, WATCH_ENABLE | WATCH_JSON, NULL);
  233. /* Put this in a loop with a call to a high resolution sleep () in it\&. */
  234. if (gps_waiting(&gps_data, 500)) {
  235. errno = 0;
  236. if (gps_read(&gps_data, NULL, 0) == \-1) {
  237. \&.\&.\&.
  238. } else {
  239. /* Display data from the GPS receiver\&. */
  240. if (gps_data\&.set & \&.\&.\&.
  241. }
  242. }
  243. /* When you are done\&.\&.\&. */
  244. (void) gps_stream(&gps_data, WATCH_DISABLE, NULL);
  245. (void) gps_close (&gps_data);
  246. .fi
  247. .if n \{\
  248. .RE
  249. .\}
  250. .SH "LIMITATIONS"
  251. .PP
  252. On some systems (those which do not support implicit linking in libraries) you may need to add \-lm to your link line when you link libgps\&. It is always safe to do this\&.
  253. .PP
  254. In the C API, incautious use of
  255. \fBgps_send()\fR
  256. may lead to subtle bugs\&. In order to not bloat
  257. struct gps_data_t
  258. with space used by responses that are not expected to be shipped in close sequence with each other, the storage for fields associated with certain responses are combined in a union\&.
  259. .PP
  260. The risky set of responses includes VERSION, DEVICELIST, RTCM2, RTCM3, SUBFRAME, AIS, GST, and ERROR; it may not be limited to that set\&. The logic of the daemon\*(Aqs watcher mode is careful to avoid dangerous sequences, but you should read and understand the layout of
  261. struct gps_data_t
  262. before using
  263. \fBgps_send()\fR
  264. to request any of these responses\&.
  265. .SH "COMPATIBILITY"
  266. .PP
  267. The
  268. \fBgps_query()\fR
  269. supported in major versions 1 and 2 of this library has been removed\&. With the new streaming\-oriented wire protocol behind this library, it is extremely unwise to assume that the first transmission from the daemon after a command is shipped to it will be the response to command\&.
  270. .PP
  271. If you must send commands to the daemon explicitly, use
  272. \fBgps_send()\fR
  273. but beware that this ties your code to the GPSD wire protocol\&. It is not recommended\&.
  274. .PP
  275. In earlier versions of the API
  276. \fBgps_read()\fR
  277. was a blocking call and there was a POLL_NONBLOCK option to make it nonblocking\&.
  278. \fBgps_waiting()\fR
  279. was added to reduce the number of wrong ways to code a polling loop\&.
  280. .PP
  281. See the comment above the symbol GPSD_API_MAJOR_VERSION in
  282. gps\&.h
  283. for recent changes\&.
  284. .SH "SEE ALSO"
  285. .PP
  286. \fBgpsd\fR(8),
  287. \fBgps\fR(1),
  288. \fBlibgpsmm\fR(3)\&.
  289. .SH "AUTHOR"
  290. .PP
  291. Eric S\&. Raymond <esr@thyrsus\&.com>, C sample code Charles Curley <charlescurley@charlescurley\&.com>