summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/20-07-2011
diff options
context:
space:
mode:
Diffstat (limited to 'For Weekly Test/20-07-2011')
-rw-r--r--For Weekly Test/20-07-2011/Controller.py17
-rw-r--r--For Weekly Test/20-07-2011/LandlineCall.py166
-rw-r--r--For Weekly Test/20-07-2011/LandlineReceiver.py160
-rw-r--r--For Weekly Test/20-07-2011/classController.py19
-rw-r--r--For Weekly Test/20-07-2011/classController.pycbin5084 -> 5346 bytes
-rw-r--r--For Weekly Test/20-07-2011/gsmcall2_.py102
-rw-r--r--For Weekly Test/20-07-2011/gsmcall_.py2
-rw-r--r--For Weekly Test/20-07-2011/gsmincom_.py58
-rw-r--r--For Weekly Test/20-07-2011/sipCall.py138
-rw-r--r--For Weekly Test/20-07-2011/sipReceiver.py178
10 files changed, 141 insertions, 699 deletions
diff --git a/For Weekly Test/20-07-2011/Controller.py b/For Weekly Test/20-07-2011/Controller.py
index 9851425..a4e64f1 100644
--- a/For Weekly Test/20-07-2011/Controller.py
+++ b/For Weekly Test/20-07-2011/Controller.py
@@ -82,7 +82,7 @@ if dbStatus == 1:
if callTo == "gsmrz1":
- x = classController.test(sipCall, "localhost", "gsmincom_.py", "localhost","4661473")
+ x = classController.test(sipCall, "localhost", "gsmincom_.py", "localhost","4661455")
x.FuncTest()
print "Finish test"
db.addResult(taskID, testResult)
@@ -98,7 +98,8 @@ if dbStatus == 1:
print "[failed] 500 Server Internal Error"
else:
- x.FuncTest(sipCall, "localhost", "Box1", "132.0.0.2","404")
+ x = classController.test(sipCall, "localhost", "Box1", "132.0.0.2","404")
+ x.FuncTest()
db.addResult(taskID, testResult)
if repeatTest == "true":
#select temporary table, if there are have test from gsmrz to sip then skip
@@ -111,18 +112,21 @@ if dbStatus == 1:
print "[failed] 500 Server Internal Error"
else:
- x.FuncTest(sipCall, "localhost", "Box2", "132.0.0.3","405")
+ x = classController.test(sipCall, "localhost", "Box2", "132.0.0.3","405")
+ x.FuncTest()
db.addResult(taskID, testResult)
if repeatTest == "true":
#select temporary table, if there are have test from gsmrz to sip then skip
#else, update db, put new data to tasktable. from gsmrz to sip
update
if callTo == "landline":
- if sipGateSeverStatus == 0:
+
+ if sipGateServerStatus == 0:
print "[failed] 500 Server Internal Error"
else:
- x.FuncTest(sipCall, "localhost", landlnRec, "localhost",landlnNum)
+ x = classController.test(sipCall, "localhost", landlnRec, "localhost",landlnNum)
+ x.FuncTest()
db.addResult(taskID, testResult)
if callTo == "localsip":
@@ -130,7 +134,8 @@ if dbStatus == 1:
print "[failed] 500 Server Internal Error"
else:
- x.FuncTest(sipCall, "localhost", localSipRec, "localhost",unisipNum)
+ x = classController.test(sipCall, "localhost", localSipRec, "localhost",unisipNum)
+ x.FuncTest()
db.addResult(taskID, testResult)
if callTo == "externalgsm":
diff --git a/For Weekly Test/20-07-2011/LandlineCall.py b/For Weekly Test/20-07-2011/LandlineCall.py
deleted file mode 100644
index a0b96e5..0000000
--- a/For Weekly Test/20-07-2011/LandlineCall.py
+++ /dev/null
@@ -1,166 +0,0 @@
-import sys
-import pjsua as pj
-
-import classServer
-
-from time import sleep
-from datetime import datetime
-import string
-
-
-stop =False
-
-
-LOG_LEVEL=2
-current_call = None
-status = None
-
-
-# Logging
-def log_cb(level, str, len):
- print str, "SIP log"
-
-
-# Receive events from account
-class MyAccountCallback(pj.AccountCallback):
-
- def __init__(self, account=None):
- pj.AccountCallback.__init__(self, account)
-
-
-# Receive events from Call
-class MyCallCallback(pj.CallCallback):
-
- def __init__(self, call=None):
- pj.CallCallback.__init__(self, call)
-
-
- def on_state(self):
- global current_call
- global status
-
- if self.call.info().state <> pj.CallState.DISCONNECTED:
- if self.call.info().state_text == "CONNECTING":
- print "CONNECTING CALL"
-
- print "CALL CONFIRMED and ESTABLISH", self.call.info().state_text
- sleep(2)
- current_call.hangup()
- status = 200
- server.sendData(status)
- else:
- sleep(0.5)
-
-
- if self.call.info().last_reason <> "":
-
- if self.call.info().last_reason == "Busy Here":
-
- print "486 Busy Here"
- print ""
- status = 486
- server.sendData(status)
-
- if self.call.info().state == pj.CallState.DISCONNECTED:
- current_call = None
- print 'Current call Disconnected'
-
-#Function to make call
-def make_call(uri):
- try:
- print "Making call to", uri
- cb=MyCallCallback()
- return acc.make_call(uri, cb)
- except pj.Error, e:
- print "408 Request Time-out (Couldn't find the user in time) " + str(e)
- return None
-
-
-
-
-lib = pj.Lib()
-while stop <> True:
-
-
- lib.init(log_cfg = pj.LogConfig(level=LOG_LEVEL, 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()
-
-
- 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())
-
-
- if acc.info().reg_status < 700:
-
- my_sip_uri = "sip:" + transport.info().host + ":" + str(transport.info().port)
- print my_sip_uri
-
- server.sendData('ready')
- print "Status: ", server.connected
-
- while 1:
- try:
- data = server.receiveData()
-
- if data == "start":
-
- while 1:
-
- num = server.receiveData()
- if num <> "":
-
- number = "sip:"+num+"@132.230.4.8"
- current_call = make_call(number)
- break
-
- if data == "487":
- stop = True
- break
-
- except ValueError:
- print "813 General socket layer error: Failed send message"
- server.closeConnection()
- del server
-
- server.closeConnection()
- del server
-
- else:
- Regis_status= "Bad"
- print "488 Not Acceptable Here"
-
- lib.destroy()
- lib = None
- acc = None
-
-
- server.closeConnection()
- del server
- except ValueError:
- print "401 Unauthorized " + str(e)
-
-print "Goodbye"
-sleep(3)
-acc.delete()
-lib.destroy()
-server.closeConnection()
-del server
-lib = None
-acc = None
-
diff --git a/For Weekly Test/20-07-2011/LandlineReceiver.py b/For Weekly Test/20-07-2011/LandlineReceiver.py
deleted file mode 100644
index 607f56d..0000000
--- a/For Weekly Test/20-07-2011/LandlineReceiver.py
+++ /dev/null
@@ -1,160 +0,0 @@
-import sys
-import pjsua as pj
-import string
-import classServer
-
-from time import sleep
-from datetime import datetime
-
-stop = False
-
-LOG_LEVEL=2
-current_call = None
-status = None
-global accept
-accept = None
-
-
-# Logging
-def log_cb(level, str, len):
- print str, "SIP Handler Receiver Log"
-
-
-
-class MyAccountCallback(pj.AccountCallback):
-
- global success
-
- def __init__(self, account=None):
- pj.AccountCallback.__init__(self, account)
-
- def on_incoming_call(self, call):
- global current_call
- global number
-
- if current_call:
- call.answer(486, "Busy")
- return
-
- number = call.info().remote_uri
-
- current_call = call
-
- call_cb = MyCallCallback(current_call)
- current_call.set_callback(call_cb)
-
- current_call.answer(180)
- print "accept call"
-
- if current_call <> None:
- accept = True
-
- if accept == True:
- sleep(0.5)
- current_call.answer(200)
- sleep(1.5)
- current_call.hangup()
- status = 200
- server.sendData(success)
-
-class MyCallCallback(pj.CallCallback):
-
- def __init__(self, call=None):
- pj.CallCallback.__init__(self, call)
-
-
- def on_state(self):
- global current_call
- global success
-
- if self.call.info().state == pj.CallState.CONNECTING:
- print self.call.info().state_text
- status = 200
-
- if self.call.info().state == pj.CallState.DISCONNECTED:
- current_call = None
- print '701 The called party has hung up'
-
-
-lib = pj.Lib()
-
-try:
-
- server = classServer.ServerHandler(50104)
- 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()
-
- lib.init(log_cfg = pj.LogConfig(level=LOG_LEVEL, 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()
-
-
-
- try:
- acc_cfg = pj.AccountConfig("132.230.4.8", "mpselftest2", "2mpselftest")
- acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
-
- if acc.info().reg_status < 700:
-
- my_sip_uri = "sip:" + transport.info().host + ":" + str(transport.info().port)
-
- server.sendData('ready')
-
- while stop <> True:
-
- data = server.receiveData()
-
- if data == "487":
- stop = True
- break
-
- if current_call == None:
- accept = None
- continue
- else:
- print "Incoming call from :", number
-
-
-
-
- transport = None
- acc.delete()
- acc = None
- lib.destroy()
- lib = None
- server.closeConnection()
-
- else:
- print "Bad Register"
-
- lib.destroy()
- lib = None
- acc = None
- server.closeConnection()
-
-
- except pj.Error, e:
- print "401 Unauthorized " +str(e)
- lib.destroy()
- lib = None
- server.closeConnection()
-
-
-except pj.Error, e:
- print "Exception: " + str(e)
- lib.destroy()
- lib = None
- server.closeConnection()
- del server
diff --git a/For Weekly Test/20-07-2011/classController.py b/For Weekly Test/20-07-2011/classController.py
index a3e98ff..e26250d 100644
--- a/For Weekly Test/20-07-2011/classController.py
+++ b/For Weekly Test/20-07-2011/classController.py
@@ -34,7 +34,7 @@ class test:
def timeout_handler(signum, frame):
raise TimeoutException()
-
+ print ""
print "====================== Preparing Test ======================"
try:
@@ -102,7 +102,7 @@ class test:
print ""
try:
- global portDest
+ print self.dest
if self.dest =="gsmBox1" or self.dest =="gsmBox2":
@@ -112,7 +112,7 @@ class test:
if self.dest =="gsmBox2":
self.portDest = 50103
- y = classClient.Connection(destAdd,portDest)
+ y = classClient.Connection(self.destAdd, self.portDest)
print "Connecting to Receiver handler"
print "Receiver handler status: ", y.connect()
y.sendData('hello server please wakeup the handler and be receiver')
@@ -126,7 +126,7 @@ class test:
if self.dest=="SIPReceiver.py":
self.portDest = 50104
- if self.dest=="rz1Receiver.py":
+ if self.dest=="gsmincom_.py":
self.portDest = 50105
if self.dest == "landlineReceiver.py":
@@ -139,10 +139,9 @@ class test:
#print "not define yet"
#portDest = 50108
- y = classClient.Connection(self.destAdd,portDest)
- print "Connecting to Receiver handler"
+ y = classClient.Connection(self.destAdd, self.portDest)
+ print "Connecting to Receiver handler xx", self.destAdd, self.portDest, self.dest
print "Receiver handler status:", y.connect()
- y.sendData('hello Receiver')
signal.signal(signal.SIGALRM, timeout_handler)
@@ -173,7 +172,7 @@ class test:
y.connect()
signal.signal(signal.SIGALRM, timeout_handler)
- signal.alarm(120)
+ signal.alarm(1200)
print "------------ Test Result ------------"
print ""
@@ -184,7 +183,7 @@ class test:
resultOrig = x.receiveData()
resultDest = y.receiveData()
- if resultOrig <> "" or resultDest <> "":
+ if resultOrig <> "" and resultDest <> "":
break
except TimeoutException:
@@ -214,7 +213,7 @@ class test:
resultOrig = x.receiveData()
resultDest = y.receiveData()
- if resultOrig <> "" or resultDest <> "":
+ if resultOrig <> "" and resultDest <> "":
break
except TimeoutException:
diff --git a/For Weekly Test/20-07-2011/classController.pyc b/For Weekly Test/20-07-2011/classController.pyc
index 7364fa7..6abfa92 100644
--- a/For Weekly Test/20-07-2011/classController.pyc
+++ b/For Weekly Test/20-07-2011/classController.pyc
Binary files differ
diff --git a/For Weekly Test/20-07-2011/gsmcall2_.py b/For Weekly Test/20-07-2011/gsmcall2_.py
deleted file mode 100644
index bf8e662..0000000
--- a/For Weekly Test/20-07-2011/gsmcall2_.py
+++ /dev/null
@@ -1,102 +0,0 @@
-import sys
-import pjsua as pj
-import socket
-import time
-
-import subprocess
-import os
-from serial import *
-
-import classServer
-
-from time import sleep
-from datetime import datetime
-import string
-
-
-stop ="false"
-success = "failed"
-
-
-try:
- global ser
- portAddress = '/dev/ttyUSB0'
- portName = portAddress[-4:]
- portExist = os.popen('dmesg | grep ' + portName).read()
-
- if portExist == '':
- print 'The serial port does not exist'
- sys.exit()
-
- ser = Serial(
- port=portAddress,
- baudrate=19200,
- bytesize=EIGHTBITS,
- parity=PARITY_NONE,
- stopbits=STOPBITS_ONE)
-
-
- ser.open()
-
- server = classServer.ServerHandler(50098)
- 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()
-
-
- server.sendData('ready')#send message to controller
- print "Status Server:", server.connected
- print ""
-
- while stop <> "true":
- try:
- data = server.receiveData() # waiting mode, until receiver start message or terminate message
- ser.write('AT+CSQ\r')
- signalQuality = ser.read(35)
- print "Signal Bar: ", signalQuality
- #
-
-
- if data == "start": # if receiver start message, handler start to call destination
- while 1:
-
- num = server.receiveData() # waiting destination number
-
- #num = 929
-
- if num <> "":
-
- ser.write('ATD' + num + ';\r')
- sleep(5)
- success = "success"
- server.sendData(success)
- ser.write('AT+CHUP\r')
-
- break
-
- if data == "terminated": # will terminate the handler if controller send terminate message
- stop = "true"
- break
-
- except ValueError:
- print "error on calling mode"
- server.closeConnection()
- del server
-
-
-
- server.sendData(success)
- server.closeConnection()
- ser.close()
- del server
-
-except ValueError:
- print "Exception: "
-
-print "Goodbye"
-sleep(3)
diff --git a/For Weekly Test/20-07-2011/gsmcall_.py b/For Weekly Test/20-07-2011/gsmcall_.py
index 55c599e..70e9c72 100644
--- a/For Weekly Test/20-07-2011/gsmcall_.py
+++ b/For Weekly Test/20-07-2011/gsmcall_.py
@@ -18,7 +18,7 @@ success = "failed"
global server
global ser
-portAddress = '/dev/ttyACM0'
+portAddress = '/dev/ttyUSB0'
portName = portAddress[-4:]
portExist = os.popen('dmesg | grep ' + portName).read()
diff --git a/For Weekly Test/20-07-2011/gsmincom_.py b/For Weekly Test/20-07-2011/gsmincom_.py
index 413db25..0b2c48e 100644
--- a/For Weekly Test/20-07-2011/gsmincom_.py
+++ b/For Weekly Test/20-07-2011/gsmincom_.py
@@ -32,13 +32,6 @@ try:
server = classServer.ServerHandler(50105)
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()
-
print "here:", server.connected
if server.connected == 1:
@@ -70,49 +63,70 @@ try:
buffer = buffer + ser.read(ser.inWaiting()) #read the serial port and add it to the buffer variable
- if '\n' in buffer:
- #if a new line character is found in the buffer then the cellphone has sent something
+ if '\n' in buffer: #if a new line character is found in the buffer then the cellphone has sent something
lines = buffer.split('\n') #parse the buffer variable with the new line character
last_received = lines.pop(0) #put into last_received variable the first content from lines (FIFO)
- print "apa iyi", buffer
- #buffer = "".join(lines) #add a new line to the buffer variable
-
+
+ buffer = '\n'.join(lines) #add a new line to the buffer variable
+
last_received=last_received.split('\n') #parse the last received value with new lines
line = last_received[0].replace(chr(13), '')
print "buffer:", buffer
print "line:", line
- linesa = ser.read(ser.inWaiting())
- print "new line:", linesa
- sleep(1)
- if line =="RING" or linesa =="RING":
+ if len(line) > 0:
- if line =="RING" or lines =="RING":
+ if line=="RING":
print "Somebody calling"
print ""
sleep(1)
ser.write('ATA\r')
+ sleep(1)
+ ser.write('AT+CSQ\r')
+
+ sleep(2)
+ ser.write('AT+CLCC\r')
+
+
+ if line[0:5] == '+CSQ:':
+
+ space = int(string.find(line,' '))+1
+ coma = int(string.find(line,','))
+ signalStr = (int(line[space:coma])*2)-113
+ line=''
+
+ if line[0:6]=='+CLCC:':
+
+ pickUp = 1
print "I will hangup the call"
print ""
- sleep(1)
+ sleep(5)
ser.write('AT+CHUP\r')
pickUp = 0
ser.close()
- print "here I am"
- tried = server.openSocket()
+ quotation1 = int(string.find(line,'"'))+1
+ lineTemp = line[quotation1:]
+ quotation2 = int(string.find(lineTemp,'"'))
+ numberOfCaller = line[quotation1:quotation1+quotation2]
+
+ print "Signal Strength: ", signalStr
+ print ""
+
+ tried = server.openSocket()
+ server.sendData('I got call from :' +numberOfCaller)
+ print "with caller number", numberOfCaller
sleep(1)
server.sendData('success')
stop = True
- sleep (5)
- break
+ sleep (3)
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)
diff --git a/For Weekly Test/20-07-2011/sipReceiver.py b/For Weekly Test/20-07-2011/sipReceiver.py
index 6404f10..b58990b 100644
--- a/For Weekly Test/20-07-2011/sipReceiver.py
+++ b/For Weekly Test/20-07-2011/sipReceiver.py
@@ -1,173 +1,83 @@
import sys
import pjsua as pj
-import socket
-import time
-import os
-import string
import classServer
-
from time import sleep
-from datetime import datetime
-
-stop ="false"
-server = "132.230.4.8"
-username = "mpselftest2"
-password = "2mpselftest"
-LOG_LEVEL=2
-current_call = None
-success = ""
-global accept
-accept = None
-# Logging callback
def log_cb(level, str, len):
- print str, "I am here"
+ print str, "SIP Handler Receiver Log"
-# 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_incoming_call(self, call):
- global current_call
- global number
- if current_call:
- call.answer(486, "Busy")
- return
-
- number = call.info().remote_uri
-
- current_call = call
-
- call_cb = MyCallCallback(current_call)
- current_call.set_callback(call_cb)
-
- current_call.answer(180)
- print "accept call"
- if current_call <> None:
- accept = True
- if accept == True:
- sleep(2)
- current_call.answer(200)
- sleep(3)
- current_call.hangup()
- accept = "true"
- server.sendData('success')
-
- #server.sendData(success)
-
-
-
-
-
-# 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
-
- if self.call.info().state_text == "CONNECTING":
- print self.call.info().state_text
- success = "success"
-
- if self.call.info().state == pj.CallState.DISCONNECTED:
- current_call = None
- print 'Current call is', current_call
+ def on_incoming_call(self, call):
- # Notification when call's media state has changed.
- def on_media_state(self):
- if self.call.info().media_state == pj.MediaState.ACTIVE:
- # Connect the call to sound device
- call_slot = self.call.info().conf_slot
- pj.Lib.instance().conf_connect(call_slot, 0)
- pj.Lib.instance().conf_connect(0, call_slot)
- #server.sendData('establish connection')
+ current_call = call
- print "Media is now active"
-
+ sleep(0.5)
+ call.answer(200)
- else:
- print "Media is inactive"
+ sleep(0.5)
+ if current_call <> None:
+ call.hangup()
+
+ server.sendData('200')
lib = pj.Lib()
+stop = False
try:
- #open socket connection to the controller
+
server = classServer.ServerHandler(50104)
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()
- 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"
-
- # Start the library
+
lib.start()
lib.set_null_snd_dev()
+ try:
+ acc_cfg = pj.AccountConfig("132.230.4.8", "mpselftest2", "2mpselftest")
+ acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
- # Create local account
- acc_cfg = pj.AccountConfig("132.230.4.8", "mpselftest2", "2mpselftest")
- acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
+ if acc.info().reg_status < 700:
- if acc.info().reg_status < 700:
+ server.sendData('ready')
- my_sip_uri = "sip:" + transport.info().host + ":" + str(transport.info().port)
-
- server.sendData('ready')#send message to controller that the handler ready
+ while stop <> True:
+
+ data = server.receiveData()
+
+ if data == "487":
+ stop = True
+ break
+
+ transport = None
+ acc.delete()
+ acc = None
+ lib.destroy()
+ lib = None
+ server.closeConnection()
+
+ else:
+ print "Bad Register"
- while stop <> "true":
+ lib.destroy()
+ lib = None
+ acc = None
+ server.closeConnection()
- data = server.receiveData()#waiting message from controller
- if data == "terminated":
- break
-
- if current_call == None:
- accept = None
- continue
- else:
- print "Incoming call from :", number
-
- sleep(4)
-
- # Shutdown the library
- transport = None
- acc.delete()
- acc = None
+ except pj.Error, e:
+ print "401 Unauthorized " +str(e)
lib.destroy()
lib = None
- server.closeConnection()
- del server
- else:
- Regis_status= "Bad"
- print "error when register"
-
- lib.destroy()
- lib = None
- acc = None
- server.closeConnection()
- del server
+ server.closeConnection()
+
except pj.Error, e:
print "Exception: " + str(e)