summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/20-07-2011/sipCall.py
diff options
context:
space:
mode:
authortriatmoko2011-07-18 16:15:35 +0200
committertriatmoko2011-07-18 16:15:35 +0200
commit7b2c90066692566044ac80ec421e15a1aee7ab25 (patch)
treeebe71e8809059d40b1d02569514ad173572bfb72 /For Weekly Test/20-07-2011/sipCall.py
parentJust two scripts that test the GSM2GSM system! (diff)
downloadgsm-selftest-7b2c90066692566044ac80ec421e15a1aee7ab25.tar.gz
gsm-selftest-7b2c90066692566044ac80ec421e15a1aee7ab25.tar.xz
gsm-selftest-7b2c90066692566044ac80ec421e15a1aee7ab25.zip
fixed bugs for calling part on sip.
Diffstat (limited to 'For Weekly Test/20-07-2011/sipCall.py')
-rw-r--r--For Weekly Test/20-07-2011/sipCall.py138
1 files changed, 40 insertions, 98 deletions
diff --git a/For Weekly Test/20-07-2011/sipCall.py b/For Weekly Test/20-07-2011/sipCall.py
index 0dbc133..f41756d 100644
--- a/For Weekly Test/20-07-2011/sipCall.py
+++ b/For Weekly Test/20-07-2011/sipCall.py
@@ -1,154 +1,96 @@
import sys
import pjsua as pj
-import socket
-import time
-import MySQLdb
-import subprocess
-
import classServer
-
from time import sleep
-from datetime import datetime
-import string
-
-
-stop ="false"
-server = "132.230.4.8"
-username = "mpselftest1"
-password = "1mpselftest"
-
-LOG_LEVEL=2
-current_call = None
-success = ""
-# Logging callback
def log_cb(level, str, len):
print str, "SIP log"
+# Receive events from Call
+class MyCallCallback(pj.CallCallback):
-# Callback to receive events from account
-class MyAccountCallback(pj.AccountCallback):
-
- def __init__(self, account=None):
- pj.AccountCallback.__init__(self, account)
-
- # Notification on incoming call##
-
+ def on_state(self):
+ global current_call
-
-# Callback to receive events from Call
-class MyCallCallback(pj.CallCallback):
-
- def __init__(self, call=None):
- pj.CallCallback.__init__(self, call)
-
- # Notification when call state has changed
- def on_state(self):
- global current_call
- global success
-
- if self.call.info().state_text <> "DISCONNCTD":
- if self.call.info().state_text == "CONNECTING":
- print "CONNECTING CALL"
- #print "isine opo:", self.call.info().state_text
- print "CALL CONFIRMED and ESTABLISH", self.call.info().state_text
- sleep(1)
- current_call.hangup()
- print "I am here now"
- success = "true"
- server.sendData(success)
- else:
- sleep(1)
- #print ""
+ if self.call.info().state <> pj.CallState.DISCONNECTED:
+ if self.call.info().state_text == "CONNECTING":
+ print "CALL : ", self.call.info().state_text
+ sleep(1)
+ if self.call.info().state <> pj.CallState.DISCONNECTED:
+ current_call.hangup()
+
+ server.sendData('200')
+ else:
+ sleep(0.5)
- if self.call.info().last_reason <> "":
if self.call.info().last_reason == "Busy Here":
-
- print "Destination Number is Busy or offline"
- print ""
- success = "false"
- server.sendData(success)
-
-
- #print self.call.info().state_text
+ server.sendData('486')
- if self.call.info().state == pj.CallState.DISCONNECTED:
- current_call = None
- print 'Current call Disconnected'
+ if self.call.info().state == pj.CallState.DISCONNECTED:
+ current_call = None
def make_call(uri):
+
try:
- print "Making call to", uri
+
cb=MyCallCallback()
return acc.make_call(uri, cb)
+
except pj.Error, e:
- print "Exception: " + str(e)
+ print "408 " + str(e)
return None
-
-
lib = pj.Lib()
-while stop <> "true":
+stop =False
+current_call = None
+while stop <> True:
- lib.init(log_cfg = pj.LogConfig(level=LOG_LEVEL, callback=log_cb))
+
+ lib.init(log_cfg = pj.LogConfig(level=1, callback=log_cb))
transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
- print "\nListening on", transport.info().host,
- print "port", transport.info().port, "\n"
lib.start()
lib.set_null_snd_dev()
- # open socket connection and connect to the controller
+
server = classServer.ServerHandler(50097)
tried = server.openSocket()
- if server.error != 'No error':
- print server.error
- if server.error == '[Errno 98] Address already in use':
- print 'one should try to kill the port'
- print server.killPort()
- server.closeConection()
-
try:
acc_cfg = pj.AccountConfig("132.230.4.8","mpselftest1","1mpselftest")
- acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
-
+ acc = lib.create_account(acc_cfg, cb=pj.AccountCallback())
if acc.info().reg_status < 700:
-
- my_sip_uri = "sip:" + transport.info().host + ":" + str(transport.info().port)
- print my_sip_uri
- server.sendData('ready')#send message to controller
- print "here:", server.connected
+
+ server.sendData('ready')
+ print "Status: ", server.connected
+
while 1:
try:
- data = server.receiveData() # waiting mode, until receiver start message or terminate message
+ data = server.receiveData()
- if data == "start": # if receiver start message, handler start to call destination
+ if data == "start":
while 1:
- num = server.receiveData() # waiting destination number
- print num
- server.closeConnection()
- tried = server.openSocket()
+ num = server.receiveData()
if num <> "":
number = "sip:"+num+"@132.230.4.8"
current_call = make_call(number)
break
- if data == "terminated": # will terminate the handler if controller send terminate message
- stop = "true"
+ if data == "487":
+ stop = True
break
except ValueError:
- print "error when sending message"
+ print "813 General socket layer error: Failed send message"
server.closeConnection()
del server
@@ -157,7 +99,7 @@ while stop <> "true":
else:
Regis_status= "Bad"
- print "error when register"
+ print "488 Not Acceptable Here"
lib.destroy()
lib = None
@@ -167,7 +109,7 @@ while stop <> "true":
server.closeConnection()
del server
except ValueError:
- print "Exception: " + str(e)
+ print "401 Unauthorized " + str(e)
print "Goodbye"
sleep(3)