So you might already know that my favourite subsystem is GPS so I'll start with that. It's also safer and more interesting than demonstrating the GSM subsystem if you're on a plane. :-)
The program I'll be using to demonstrate the functions is cli-framework, which is just a convenient way to access the DBus functions through python.
Okay, so here we go:
usageiface is a DBus Interface object which lets you access methods at a specific bus address (org.freesmartphone.ousaged), object path (/org/freesmartphone/Usage) and interface (org.freesmartphone.Usage). So let's request GPS.
root@om-gta02:~# cli-framework freesmartphone.org interactive command line >>> usageiface.RequestResource("GPS") None
This command might take some time to complete because the GPS chip needs to be initialized. GPS will stay active until all requesters have either called ReleaseResource or quit.
>>> gpsposition.GetPosition() ( dbus.Int32(7), dbus.Int32(1223757219), dbus.Double(24.3323283), dbus.Double(89.149197900000004), dbus.Double(10252.375))
This is the Gypsy DBus interface. The meaning of the parameters are: The first parameter is a bitfield specifying which fields are valid. 7 means latitude, longitude and altitude are valid.
The next fields are a timestamp, latitude and longitude and altitude which is 10km (did I mention I'm in an airplane?) You can also listen for the signals of course, but I'll just show you some of the methods.
>>> gpssatellite.GetSatellites() [ ( dbus.UInt32(21L), dbus.Boolean(True), dbus.UInt32(20L), dbus.UInt32(163L), dbus.UInt32(34L)), ( dbus.UInt32(18L), dbus.Boolean(True), dbus.UInt32(41L), dbus.UInt32(96L), dbus.UInt32(27L)), ( dbus.UInt32(14L), dbus.Boolean(False), dbus.UInt32(53L), dbus.UInt32(334L), dbus.UInt32(16L)), ...
GetSatellites returns a list of satellite information. The first parameter is the SV id, the second tells us whether this SV is used for navigation, then follows elevation, azimuth and signal strength.
Hmm, now we want to find out our course and speed, but there's no object for that in cli-framework. As long as we know the bus name, object path and the interface we can create one ourselves:
>>> gpscourse = getInterface('org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy', 'org.freedesktop.Gypsy.Course') >>> gpscourse.GetCourse() ( dbus.Int32(7), dbus.Int32(1223758389), dbus.Double(469.67170808999998), dbus.Double(294.69866000000002), dbus.Double(-1.1663066999999998))
The parameters are again validity bitmask, timestamp, speed in knots, heading and vertical speed in knots.
So this is too complicated you say? You just want to connect to gpsd and parse the NMEA sentences directly? No problem! Let's tell the framework we don't need GPS anymore.
>>> usageiface.ReleaseResource('GPS') None
GPS will be disabled again unless some other application is using it. Now let's just try to connect gpsd style:
root@om-gta02:~# telnet localhost gpsd r GPSD,R=1 $GPGGA,210251.00,2533.25409,N,08517.88533,E,2,06,1.57,10225.6,M,,,,*0d $GPGSA,A,2,21,18,14,19,22,11,05,12,32,30,06,31,2.21,1.57,1.54*06 $GPGSV,3,1,12,21,06,159,28,18,29,109,30,14,52,358,14,19,05,259,25*7e $GPGSV,3,2,12,22,61,074,25,11,07,313,00,05,21,072,00,12,10,058,00*72 $GPGSV,3,3,12,32,05,310,00,30,27,100,27,06,02,218,24,31,57,209,35*7a $GPRMC,210251.00,A,2533.25409,N,08517.88533,E,415.419,280.94,111008,,*07 $GPGLL,2533.25409,N,08517.88533,E,210251.00,A*02 $GPVTG,280.94,T,,,415.419,N,769.356,K*1e
Cool, it's working! I had GPS on all the time so I got a fix right away, but GPS will be enabled automatically as soon as you connect to the port. A neat little proxy fso-gpsd handles requesting and releasing the resource for you and generates NMEA sentences out of the DBus signals.
Use the following link to trackback from your own site: