2 * This file is Copyright (c) 2010 by the GPSD project
3 * BSD terms apply: see the file COPYING in the distribution root for details.
5 * Python binding for selected libgps library functions
11 #include "gpsdclient.h"
14 * Client utility functions
18 gpsclient_deg_to_str(PyObject *self, PyObject *args)
23 if (!PyArg_ParseTuple(args, "id", &fmt, °rees))
25 return Py_BuildValue("s", deg_to_str((enum deg_str_type)fmt, degrees));
29 gpsclient_gpsd_units(PyObject *self, PyObject *args)
31 if (!PyArg_ParseTuple(args, ""))
33 return Py_BuildValue("i", (int)gpsd_units());
41 gpsclient_wgs84_separation(PyObject *self, PyObject *args)
43 const double lat, lon;
46 if (!PyArg_ParseTuple(args, "dd", &lat, &lon))
48 sep = wgs84_separation(lat, lon);
49 return Py_BuildValue("d", sep);
52 /* List of functions defined in the module */
54 static PyMethodDef gpsclient_methods[] = {
55 {"wgs84_separation", gpsclient_wgs84_separation, METH_VARARGS,
56 PyDoc_STR("Return WGS84 geodetic separation in meters.")},
57 {"deg_to_str", gpsclient_deg_to_str, METH_VARARGS,
58 PyDoc_STR("String-format a latitude/longitude.")},
59 {"gpsd_units", gpsclient_gpsd_units, METH_VARARGS,
60 PyDoc_STR("Deduce a set of units from locale and environment.")},
61 {NULL, NULL} /* sentinel */
64 PyDoc_STRVAR(module_doc,
65 "Python wrapper for selected libgps library routines.\n\
69 initclienthelpers(void)
73 m = Py_InitModule3("gps.clienthelpers", gpsclient_methods, module_doc);
75 PyModule_AddIntConstant(m, "deg_dd", deg_dd);
76 PyModule_AddIntConstant(m, "deg_ddmm", deg_ddmm);
77 PyModule_AddIntConstant(m, "deg_ddmmss", deg_ddmmss);
79 PyModule_AddIntConstant(m, "unspecified", unspecified);
80 PyModule_AddIntConstant(m, "imperial", imperial);
81 PyModule_AddIntConstant(m, "nautical", nautical);
82 PyModule_AddIntConstant(m, "metric", metric);