PyMaemo/Python-GPSbt
(use <source> and <code>) |
|||
Line 11: | Line 11: | ||
API | API | ||
- | * gpsbt.start - establishes a new GPS connection and returns a context. This one is is used to inform stop method what connection to be ended. | + | * <code>gpsbt.start</code> - establishes a new GPS connection and returns a context. This one is is used to inform stop method what connection to be ended. |
- | + | <source lang="python"> | |
- | + | context = gps.start() | |
- | + | </source> | |
- | * gpsbt.stop - ends an active connection, passed through the context. gps.stop(context) | + | * <code>gpsbt.stop</code> - ends an active connection, passed through the context. gps.stop(context) |
- | * gpsbt.gps() - the class that gets information from GPS. Through it its possible to query, get_fix, get_position, etc. | + | * <code>gpsbt.gps()</code> - the class that gets information from GPS. Through it its possible to query, get_fix, get_position, etc. |
- | * gpsbt.gps.get_fix() - fills in the 'fix' structure with GPS data. The fields are: mode, time, ept, latitude, longitude, eph, altitude (meters), epv, track (degrees from true north), speed (knots), climb (meters per second), epd, eps and epc. | + | * <code>gpsbt.gps.get_fix()</code> - fills in the 'fix' structure with GPS data. The fields are: mode, time, ept, latitude, longitude, eph, altitude (meters), epv, track (degrees from true north), speed (knots), climb (meters per second), epd, eps and epc. |
- | * gpsbt.gps.get_position() - its a shortcut to return (latitude, longitude) info. | + | * <code>gpsbt.gps.get_position()</code> - its a shortcut to return (latitude, longitude) info. |
- | * gpsbt.gps.query() - allows user to send one letter commands to the GPS device. Its possible to group a sequence of commands to send, e.g.: | + | * <code>gpsbt.gps.query()</code> - allows user to send one letter commands to the GPS device. Its possible to group a sequence of commands to send, e.g.: |
- | ** gpsbt.gps.query('a') fills in the altitude field of 'fix' structure | + | ** <code>gpsbt.gps.query('a')</code> fills in the altitude field of 'fix' structure |
- | ** gpsbt.gps.query('as') fills in the altitude and speed fields | + | ** <code>gpsbt.gps.query('as')</code> fills in the altitude and speed fields |
- | * gpsbt.gps.satellites - contains a list of detected satellites, including information about usage and quality. | + | * <code>gpsbt.gps.satellites</code> - contains a list of detected satellites, including information about usage and quality. |
== Example == | == Example == | ||
The code below shows how to connect with a GPS device, get data and close this connection: | The code below shows how to connect with a GPS device, get data and close this connection: | ||
+ | <source lang="python"> | ||
+ | import gpsbt | ||
+ | import time | ||
+ | |||
+ | def main(): | ||
+ | context = gpsbt.start() | ||
+ | |||
+ | if context == None: | ||
+ | print 'Problem while connecting!' | ||
+ | return | ||
+ | |||
+ | # ensure that GPS device is ready to connect and to receive commands | ||
+ | time.sleep(2) | ||
+ | gpsdevice = gpsbt.gps() | ||
+ | |||
+ | # read 3 times and show information | ||
+ | for a in range(4): | ||
+ | gpsdevice.get_fix() | ||
+ | time.sleep(2) | ||
+ | |||
+ | # print information stored under 'fix' variable | ||
+ | print 'Altitude: %.3f'%gpsdevice.fix.altitude | ||
+ | # dump all information available | ||
+ | print gpsdevice | ||
+ | |||
+ | # ends Bluetooth connection | ||
+ | gpsbt.stop(context) | ||
- | + | main() | |
- | + | </source> | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
Download source code [http://pymaemo.garage.maemo.org/documentation/python_gps_examples/gpsbt-example.py here]. | Download source code [http://pymaemo.garage.maemo.org/documentation/python_gps_examples/gpsbt-example.py here]. | ||
[[Category:Python]] | [[Category:Python]] |
Latest revision as of 11:51, 22 June 2010
[edit] Introduction
Python-GPSbt is a binding, based on libgpsbt, that provides access to GPS data through osso-gpsd. It only depends on a Bluetooth GPS device already paired. How it works
Libgpsbt allows to connect with Bluetooth GPS devices and uses osso-gpsd daemon to provide a socket where you can send/receive information.
After a gps.start() its possible to send commands (trhough query) and receive data from GPS. Almost all information acquired from socket is stored inside a structure called 'fix'. To fill it just call the get_fix(). It does a query to get all necessary information from GPS device.
To finish the Bluetooth connection just call the gps.stop() method, providing the context (returned by gps.start()). API
-
gpsbt.start
- establishes a new GPS connection and returns a context. This one is is used to inform stop method what connection to be ended.
context = gps.start()
-
gpsbt.stop
- ends an active connection, passed through the context. gps.stop(context) -
gpsbt.gps()
- the class that gets information from GPS. Through it its possible to query, get_fix, get_position, etc. -
gpsbt.gps.get_fix()
- fills in the 'fix' structure with GPS data. The fields are: mode, time, ept, latitude, longitude, eph, altitude (meters), epv, track (degrees from true north), speed (knots), climb (meters per second), epd, eps and epc. -
gpsbt.gps.get_position()
- its a shortcut to return (latitude, longitude) info. -
gpsbt.gps.query()
- allows user to send one letter commands to the GPS device. Its possible to group a sequence of commands to send, e.g.:-
gpsbt.gps.query('a')
fills in the altitude field of 'fix' structure -
gpsbt.gps.query('as')
fills in the altitude and speed fields
-
-
gpsbt.gps.satellites
- contains a list of detected satellites, including information about usage and quality.
[edit] Example
The code below shows how to connect with a GPS device, get data and close this connection:
import gpsbt import time def main(): context = gpsbt.start() if context == None: print 'Problem while connecting!' return # ensure that GPS device is ready to connect and to receive commands time.sleep(2) gpsdevice = gpsbt.gps() # read 3 times and show information for a in range(4): gpsdevice.get_fix() time.sleep(2) # print information stored under 'fix' variable print 'Altitude: %.3f'%gpsdevice.fix.altitude # dump all information available print gpsdevice # ends Bluetooth connection gpsbt.stop(context) main()
Download source code here.
- This page was last modified on 22 June 2010, at 11:51.
- This page has been accessed 5,248 times.