aboutsummaryrefslogtreecommitdiff
path: root/test/location.py
blob: 96cd1e54e52e8dc88cef0b4f76ff963c9406db02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python
# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details:
#
# Copyright (C) 2009 - 2010 Red Hat, Inc.
#

import sys, dbus, time

DBUS_INTERFACE_PROPERTIES='org.freedesktop.DBus.Properties'
MM_DBUS_SERVICE='org.freedesktop.ModemManager'
MM_DBUS_PATH='/org/freedesktop/ModemManager'
MM_DBUS_INTERFACE='org.freedesktop.ModemManager'
MM_DBUS_INTERFACE_MODEM='org.freedesktop.ModemManager.Modem'
MM_DBUS_INTERFACE_MODEM_LOCATION='org.freedesktop.ModemManager.Modem.Location'

MM_MODEM_LOCATION_CAPABILITY_UNKNOWN    = 0x00000000
MM_MODEM_LOCATION_CAPABILITY_GPS_NMEA   = 0x00000001
MM_MODEM_LOCATION_CAPABILITY_GSM_LAC_CI = 0x00000002
MM_MODEM_LOCATION_CAPABILITY_GPS_RAW    = 0x00000004

bus = dbus.SystemBus()
objpath = sys.argv[1]
if objpath[:1] != '/':
    objpath = "/org/freedesktop/ModemManager/Modems/" + str(objpath)
proxy = bus.get_object(MM_DBUS_SERVICE, objpath)
modem = dbus.Interface(proxy, dbus_interface=MM_DBUS_INTERFACE_MODEM)

props = dbus.Interface(proxy, dbus_interface=DBUS_INTERFACE_PROPERTIES)
caps = props.Get(MM_DBUS_INTERFACE_MODEM_LOCATION, "Capabilities")

print "Location Capabilities:"
if caps & MM_MODEM_LOCATION_CAPABILITY_GPS_NMEA:
    print "    GPS_NMEA"
if caps & MM_MODEM_LOCATION_CAPABILITY_GSM_LAC_CI:
    print "    GSM_LAC_CI"
if caps & MM_MODEM_LOCATION_CAPABILITY_GPS_RAW:
    print "    GPS_RAW"
print ""

loc = dbus.Interface(proxy, dbus_interface=MM_DBUS_INTERFACE_MODEM_LOCATION)
loc.Enable(True, True)

for i in range(0, 5):
    locations = loc.GetLocation()
    if locations.has_key(MM_MODEM_LOCATION_CAPABILITY_GSM_LAC_CI):
        print "GSM_LAC_CI: %s" % str(locations[MM_MODEM_LOCATION_CAPABILITY_GSM_LAC_CI])
    time.sleep(1)

loc.Enable(False, False)