Add an example testing program.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@ install-sh
|
|||||||
ltmain.sh
|
ltmain.sh
|
||||||
missing
|
missing
|
||||||
stamp-h1
|
stamp-h1
|
||||||
|
*~
|
||||||
*.o
|
*.o
|
||||||
*.lo
|
*.lo
|
||||||
*.la
|
*.la
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
SUBDIRS = src plugins introspection
|
SUBDIRS = src plugins introspection test
|
||||||
|
|
||||||
pkgconfigdir = $(libdir)/pkgconfig
|
pkgconfigdir = $(libdir)/pkgconfig
|
||||||
pkgconfig_DATA = ModemManager.pc
|
pkgconfig_DATA = ModemManager.pc
|
||||||
|
@@ -18,6 +18,7 @@ AC_CONFIG_FILES([
|
|||||||
Makefile
|
Makefile
|
||||||
src/Makefile
|
src/Makefile
|
||||||
plugins/Makefile
|
plugins/Makefile
|
||||||
|
test/Makefile
|
||||||
introspection/Makefile
|
introspection/Makefile
|
||||||
ModemManager.pc
|
ModemManager.pc
|
||||||
])
|
])
|
||||||
|
3
test/Makefile.am
Normal file
3
test/Makefile.am
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
EXTRA_DIST = \
|
||||||
|
mm-test.py
|
||||||
|
|
141
test/mm-test.py
Executable file
141
test/mm-test.py
Executable file
@@ -0,0 +1,141 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import dbus
|
||||||
|
|
||||||
|
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'
|
||||||
|
|
||||||
|
bus = dbus.SystemBus()
|
||||||
|
manager_proxy = bus.get_object(MM_DBUS_SERVICE, MM_DBUS_PATH)
|
||||||
|
manager_iface = dbus.Interface(manager_proxy, dbus_interface=MM_DBUS_INTERFACE)
|
||||||
|
|
||||||
|
def enumerate_devices(manager):
|
||||||
|
modems = manager_iface.EnumerateDevices()
|
||||||
|
if not modems:
|
||||||
|
print "No modems found."
|
||||||
|
return
|
||||||
|
|
||||||
|
for modem_path in modems:
|
||||||
|
proxy = bus.get_object(MM_DBUS_SERVICE, modem_path)
|
||||||
|
modem = dbus.Interface(proxy, dbus_interface=DBUS_INTERFACE_PROPERTIES)
|
||||||
|
|
||||||
|
type = modem.Get(MM_DBUS_INTERFACE_MODEM, "Type")
|
||||||
|
if type == 1:
|
||||||
|
type = "GSM"
|
||||||
|
elif type == 2:
|
||||||
|
type = "CDMA"
|
||||||
|
else:
|
||||||
|
type = "(Unknown)"
|
||||||
|
|
||||||
|
print "%s\t%s\t%s" % (modem.Get(MM_DBUS_INTERFACE_MODEM, "DataDevice"),
|
||||||
|
modem.Get(MM_DBUS_INTERFACE_MODEM, "Driver"),
|
||||||
|
type)
|
||||||
|
|
||||||
|
def get_modem(manager):
|
||||||
|
modems = manager_iface.EnumerateDevices()
|
||||||
|
if not modems:
|
||||||
|
print "No modems found."
|
||||||
|
sys.exit(1)
|
||||||
|
dev_proxy = bus.get_object(MM_DBUS_SERVICE, modems[0])
|
||||||
|
return dbus.Interface(dev_proxy, dbus_interface=MM_DBUS_INTERFACE_MODEM)
|
||||||
|
|
||||||
|
def scan(modem):
|
||||||
|
results = modem.Scan()
|
||||||
|
for r in results:
|
||||||
|
status = r['status']
|
||||||
|
if status == "1":
|
||||||
|
status = "available"
|
||||||
|
elif status == "2":
|
||||||
|
status = "current"
|
||||||
|
elif status == "3":
|
||||||
|
status = "forbidden"
|
||||||
|
else:
|
||||||
|
status = "(Unknown)"
|
||||||
|
|
||||||
|
print "%s: %s" % (r['operator-long'], status)
|
||||||
|
|
||||||
|
def get_quality(modem):
|
||||||
|
print "Signal Quality: %d%%" % modem.GetSignalQuality()
|
||||||
|
|
||||||
|
def get_network_mode(modem):
|
||||||
|
mode = modem.GetNetworkMode()
|
||||||
|
if mode == 1:
|
||||||
|
mode = "GPRS"
|
||||||
|
elif mode == 2:
|
||||||
|
mode = "EDGE"
|
||||||
|
elif mode == 3:
|
||||||
|
mode = "3G"
|
||||||
|
elif mode == 4:
|
||||||
|
mode = "HSDPA"
|
||||||
|
else:
|
||||||
|
mode = "(Unknown)"
|
||||||
|
|
||||||
|
print "Mode: %s" % mode
|
||||||
|
|
||||||
|
def get_band(modem):
|
||||||
|
band = modem.GetBand()
|
||||||
|
if band == 0:
|
||||||
|
band = "Any"
|
||||||
|
elif band == 1:
|
||||||
|
band = "EGSM (900 MHz)"
|
||||||
|
elif band == 2:
|
||||||
|
band = "DCS (1800 MHz)"
|
||||||
|
elif band == 3:
|
||||||
|
band = "PCS (1900 MHz)"
|
||||||
|
elif band == 4:
|
||||||
|
band = "G850 (850 MHz)"
|
||||||
|
elif band == 5:
|
||||||
|
band = "U2100 (WCSMA 2100 MHZ, Class I)"
|
||||||
|
elif band == 6:
|
||||||
|
band = "U1700 (WCDMA 3GPP UMTS1800 MHz, Class III)"
|
||||||
|
elif band == 7:
|
||||||
|
band = "17IV (WCDMA 3GPP AWS 1700/2100 MHz, Class IV)"
|
||||||
|
elif band == 8:
|
||||||
|
band = "U800 (WCDMA 3GPP UMTS800 MHz, Class VI)"
|
||||||
|
elif band == 9:
|
||||||
|
band = "U850 (WCDMA 3GPP UMT850 MHz, Class V)"
|
||||||
|
elif band == 10:
|
||||||
|
band = "U900 (WCDMA 3GPP UMTS900 MHz, Class VIII)"
|
||||||
|
elif band == 11:
|
||||||
|
band = "U17IX (WCDMA 3GPP UMTS MHz, Class IX)"
|
||||||
|
else:
|
||||||
|
band = "(Unknown)"
|
||||||
|
|
||||||
|
print "Band: %s" % band
|
||||||
|
|
||||||
|
def connect(modem):
|
||||||
|
need_pin = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
modem.Enable(True)
|
||||||
|
except dbus.exceptions.DBusException, e:
|
||||||
|
need_pin = True
|
||||||
|
|
||||||
|
if need_pin:
|
||||||
|
modem.SetPin("1234")
|
||||||
|
|
||||||
|
modem.Register("")
|
||||||
|
modem.Connect('"*99#', '')
|
||||||
|
|
||||||
|
|
||||||
|
if '--list' in sys.argv:
|
||||||
|
enumerate_devices(manager_iface)
|
||||||
|
elif '--scan' in sys.argv:
|
||||||
|
scan(get_modem(manager_iface))
|
||||||
|
elif '--quality' in sys.argv:
|
||||||
|
get_quality(get_modem(manager_iface))
|
||||||
|
elif '--mode' in sys.argv:
|
||||||
|
get_network_mode(get_modem(manager_iface))
|
||||||
|
elif '--band' in sys.argv:
|
||||||
|
get_band(get_modem(manager_iface))
|
||||||
|
elif '--disable' in sys.argv:
|
||||||
|
get_modem(manager_iface).Enable(False)
|
||||||
|
elif '--disconnect' in sys.argv:
|
||||||
|
modem = get_modem(manager_iface)
|
||||||
|
modem.Disconnect()
|
||||||
|
elif '--connect' in sys.argv:
|
||||||
|
connect(get_modem(manager_iface))
|
Reference in New Issue
Block a user