File: incoming.py

package info (click to toggle)
gammu 1.28.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 21,972 kB
  • ctags: 8,504
  • sloc: ansic: 104,965; pascal: 7,209; cpp: 4,023; python: 3,639; php: 1,622; sh: 1,534; sql: 450; cs: 260; makefile: 192; perl: 107; asm: 31
file content (61 lines) | stat: -rwxr-xr-x 1,632 bytes parent folder | download | duplicates (3)
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
61
#!/usr/bin/env python

import gammu
import time

def Callback(sm, type, data):
    '''
    This callback receives notification about incoming event.

    @param sm: state machine which invoked action
    @type sm: gammu.StateMachine
    @param type: type of action, one of Call, SMS, CB, USSD
    @type type: string
    @param data: event data
    @type data: hash
    '''
    print 'Received incoming event type %s, data:' % type
    print data

# Create state machine
sm = gammu.StateMachine()
# Read gammurc
sm.ReadConfig()
# Initialize state machine and connect to phone
sm.Init()
# Set callback handler for incoming notifications
sm.SetIncomingCallback(Callback)

# Enable notifications from calls
try:
    sm.SetIncomingCall()
except gammu.ERR_NOTSUPPORTED:
    print 'Incoming calls notification is not supported.'

# Enable notifications from cell broadcast
try:
    sm.SetIncomingCB()
except gammu.ERR_NOTSUPPORTED:
    print 'Incoming CB notification is not supported.'
except gammu.ERR_SOURCENOTAVAILABLE:
    print 'Cell broadcasts support not enabled in Gammu.'

# Enable notifications from incoming SMS
try:
    sm.SetIncomingSMS()
except gammu.ERR_NOTSUPPORTED:
    print 'Incoming SMS notification is not supported.'

# Enable notifications for incoming USSD
try:
    sm.SetIncomingUSSD()
except gammu.ERR_NOTSUPPORTED:
    print 'Incoming USSD notification is not supported.'

# Just a busy waiting for event
# We need to keep communication with phone to get notifications
print 'Press Ctrl+C to interrupt'
while 1:
    q = sm.GetSignalQuality()
    print 'Signal is at %d%%' % q['SignalPercent']
    time.sleep(1)