PyMaemo/Phone call and SMS examples

(use <source>)
 
(2 intermediate revisions not shown)
Line 1: Line 1:
{{Recommended phone usage}}
{{Recommended phone usage}}
-
 
-
 
== SMS ==
== SMS ==
-
 
*Method calls:
*Method calls:
Line 14: Line 11:
***Destination: com.nokia.phone.SMS
***Destination: com.nokia.phone.SMS
**Code: Python
**Code: Python
-
<code>
+
<source lang="python">
-
        import dbus
+
import dbus
-
        bus = dbus.SystemBus()
+
bus = dbus.SystemBus()
-
        smsobject = bus.get_object('com.nokia.phone.SMS', '/com/nokia/phone/SMS/ba212ae1')
+
smsobject = bus.get_object('com.nokia.phone.SMS', '/com/nokia/phone/SMS/ba212ae1')
-
        smsiface = dbus.Interface(smsobject, 'com.nokia.csd.SMS.Outgoing')
+
smsiface = dbus.Interface(smsobject, 'com.nokia.csd.SMS.Outgoing')
-
        arr = dbus.Array(pdu_array)
+
arr = dbus.Array(pdu_array)
-
        msg = dbus.Array([arr])  
+
msg = dbus.Array([arr])  
-
        smsiface.Send(msg,'')
+
smsiface.Send(msg,'')
-
</code>
+
</source>
*Signals:
*Signals:
Line 31: Line 28:
***Path: /com/nokia/phone/SMS
***Path: /com/nokia/phone/SMS
**Code: Python
**Code: Python
-
<code>
+
<source lang="python">
-
    import gobject, dbus
+
import gobject, dbus
-
    from dbus.mainloop.glib import DBusGMainLoop
+
from dbus.mainloop.glib import DBusGMainLoop
 +
 
 +
def handle_sms(pdu, msgcenter, somestring, sendernumber):
 +
    print 'New message from %s' % sendernumber
      
      
-
    def handle_sms(pdu, msgcenter, somestring, sendernumber):
+
DBusGMainLoop(set_as_default=True)
-
        print 'New message from %s' % sendernumber
+
bus = dbus.SystemBus()
-
       
+
bus.add_signal_receiver(handle_sms, path='/com/nokia/phone/SMS',  dbus_interface='Phone.SMS', signal_name='IncomingSegment')
-
    DBusGMainLoop(set_as_default=True)
+
gobject.MainLoop().run()
-
    bus = dbus.SystemBus()
+
</source>
-
    bus.add_signal_receiver(handle_sms, path='/com/nokia/phone/SMS',  dbus_interface='Phone.SMS', signal_name='IncomingSegment')
+
-
    gobject.MainLoop().run()
+
-
</code>
+
-
 
+
== Call ==
== Call ==
-
 
*Method calls:
*Method calls:
Line 56: Line 51:
***Destination: com.nokia.csd.Call
***Destination: com.nokia.csd.Call
**Code: Python
**Code: Python
-
<code>
+
<source lang="python">
-
    bus = dbus.SystemBus()
+
bus = dbus.SystemBus()
-
    callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
+
callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
-
    smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
+
smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
-
    smsiface.Release()
+
smsiface.Release()
-
</code>
+
</source>
 +
 
 +
**Method: Answer
 +
***Description: Answer call
 +
***Parameters: () 
 +
***Interface: com.nokia.csd.Call.Instance
 +
***Path: /com/nokia/csd/call/1
 +
***Destination: com.nokia.csd.Call
 +
**Code: Python
 +
<source lang="python">
 +
# Just answer
 +
bus = dbus.SystemBus()
 +
callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
 +
smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
 +
smsiface.Answer()
 +
</source>
 +
 
 +
<source lang="python">
 +
# Answer then hangup
 +
import time
 +
 
 +
bus = dbus.SystemBus()
 +
callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
 +
smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
 +
smsiface.Answer()
 +
time.sleep(0.5)    # wait 0.5 secs or 500 ms
 +
smsiface.Release()
 +
</source>
*Signals:
*Signals:
Line 70: Line 92:
***Path: /com/nokia/csd/call
***Path: /com/nokia/csd/call
**Code: Python
**Code: Python
-
<code>
+
<source lang="python">
-
    import gobject, dbus
+
import gobject, dbus
-
    from dbus.mainloop.glib import DBusGMainLoop
+
from dbus.mainloop.glib import DBusGMainLoop
 +
 
 +
def handle_call(obj_path, callernumber):
 +
    print '%s is calling' % callernumber
      
      
-
    def handle_call(obj_path, callernumber):
+
DBusGMainLoop(set_as_default=True)
-
        print '%s is calling' % callernumber
+
bus = dbus.SystemBus()
-
       
+
bus.add_signal_receiver(handle_call, path='/com/nokia/csd/call', dbus_interface='com.nokia.csd.Call', signal_name='Coming')
-
    DBusGMainLoop(set_as_default=True)
+
gobject.MainLoop().run()
-
    bus = dbus.SystemBus()
+
</source>
-
    bus.add_signal_receiver(handle_call, path='/com/nokia/csd/call', dbus_interface='com.nokia.csd.Call', signal_name='Coming')
+
 
-
    gobject.MainLoop().run()
+
[[Category:Python]]
-
</code>
+

Latest revision as of 10:28, 23 June 2010

Image:Ambox_notice.png
Please be aware that the recommended way to use the phone functionality is Telepathy:


[edit] SMS

  • Method calls:
    • Method: Send
      • Description: Use method to send messages
      • Parameters: (string, string) - (message, )
      • Interface: com.nokia.csd.SMS.Outgoing
      • Path: /com/nokia/phone/SMS/ba212ae1
      • Destination: com.nokia.phone.SMS
    • Code: Python
import dbus
bus = dbus.SystemBus()
smsobject = bus.get_object('com.nokia.phone.SMS', '/com/nokia/phone/SMS/ba212ae1')
smsiface = dbus.Interface(smsobject, 'com.nokia.csd.SMS.Outgoing')
arr = dbus.Array(pdu_array)
msg = dbus.Array([arr]) 
smsiface.Send(msg,'')
  • Signals:
    • Signal name: IncomingSegment
      • Description: Can be used to listen to incoming messages
      • Callback Parameters: (string, string, string, string)
      • Interface: Phone.SMS
      • Path: /com/nokia/phone/SMS
    • Code: Python
import gobject, dbus
from dbus.mainloop.glib import DBusGMainLoop
 
def handle_sms(pdu, msgcenter, somestring, sendernumber):
    print 'New message from %s' % sendernumber
 
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(handle_sms, path='/com/nokia/phone/SMS',   dbus_interface='Phone.SMS', signal_name='IncomingSegment')
gobject.MainLoop().run()

[edit] Call

  • Method calls:
    • Method: Release
      • Description: Reject call
      • Parameters: ()
      • Interface: com.nokia.csd.Call.Instance
      • Path: /com/nokia/csd/call/1
      • Destination: com.nokia.csd.Call
    • Code: Python
bus = dbus.SystemBus()
callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
smsiface.Release()
    • Method: Answer
      • Description: Answer call
      • Parameters: ()
      • Interface: com.nokia.csd.Call.Instance
      • Path: /com/nokia/csd/call/1
      • Destination: com.nokia.csd.Call
    • Code: Python
# Just answer
bus = dbus.SystemBus()
callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
smsiface.Answer()
# Answer then hangup
import time
 
bus = dbus.SystemBus()
callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
smsiface.Answer()
time.sleep(0.5)    # wait 0.5 secs or 500 ms
smsiface.Release()
  • Signals:
    • Signal name: Coming
      • Description: Can be used to listen to incoming calls
      • Callback Parameters: (string, string) - (obj_path, callernumber)
      • Interface: com.nokia.csd.Call
      • Path: /com/nokia/csd/call
    • Code: Python
import gobject, dbus
from dbus.mainloop.glib import DBusGMainLoop
 
def handle_call(obj_path, callernumber):
    print '%s is calling' % callernumber
 
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(handle_call, path='/com/nokia/csd/call', dbus_interface='com.nokia.csd.Call', signal_name='Coming')
gobject.MainLoop().run()