summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRefik Hadzialic2011-07-18 17:22:05 +0200
committerRefik Hadzialic2011-07-18 17:22:05 +0200
commit3c2c4f14c0dd26f03e5f664d91d51c62b617de7d (patch)
tree48fcd6a9af3d31cd2bddb74cfacf3fa055c7c45e
parentthe file was open while we commited a change, therefore it was automatically ... (diff)
parentedit landline handler (diff)
downloadgsm-selftest-3c2c4f14c0dd26f03e5f664d91d51c62b617de7d.tar.gz
gsm-selftest-3c2c4f14c0dd26f03e5f664d91d51c62b617de7d.tar.xz
gsm-selftest-3c2c4f14c0dd26f03e5f664d91d51c62b617de7d.zip
Merge branch 'master' of lab.ks.uni-freiburg.de:lsfks/projekte/gsm-selftest
-rw-r--r--For Weekly Test/20-07-2011/Controller.py2
-rw-r--r--For Weekly Test/20-07-2011/Testing.py20
-rw-r--r--For Weekly Test/20-07-2011/classClient.py8
-rw-r--r--For Weekly Test/20-07-2011/classClient.pycbin2884 -> 2791 bytes
-rw-r--r--For Weekly Test/20-07-2011/classController.py8
-rw-r--r--For Weekly Test/20-07-2011/classController.pycbin5346 -> 5353 bytes
-rw-r--r--For Weekly Test/20-07-2011/landlineCall.py166
-rw-r--r--For Weekly Test/20-07-2011/landlineReceiver.py161
-rw-r--r--For Weekly Test/20-07-2011/sipCall.py21
-rw-r--r--Handler/gsmcall_.py95
-rw-r--r--Handler/gsmincom_.py135
-rw-r--r--Handler/landlineCall.py256
-rw-r--r--Handler/landlineReceiver.py158
-rw-r--r--Handler/sipCall.py21
14 files changed, 522 insertions, 529 deletions
diff --git a/For Weekly Test/20-07-2011/Controller.py b/For Weekly Test/20-07-2011/Controller.py
index a4e64f1..5d4367c 100644
--- a/For Weekly Test/20-07-2011/Controller.py
+++ b/For Weekly Test/20-07-2011/Controller.py
@@ -100,6 +100,8 @@ if dbStatus == 1:
else:
x = classController.test(sipCall, "localhost", "Box1", "132.0.0.2","404")
x.FuncTest()
+ print ""
+ sleep(10)
db.addResult(taskID, testResult)
if repeatTest == "true":
#select temporary table, if there are have test from gsmrz to sip then skip
diff --git a/For Weekly Test/20-07-2011/Testing.py b/For Weekly Test/20-07-2011/Testing.py
new file mode 100644
index 0000000..78d1a47
--- /dev/null
+++ b/For Weekly Test/20-07-2011/Testing.py
@@ -0,0 +1,20 @@
+import sys
+import os
+import time
+import MySQLdb
+import subprocess
+import signal
+
+import classClient
+import classDb
+import classPing
+
+from time import sleep
+
+num= "445"
+data = "start|"+num
+first = data[0:5]
+second = data[6:]
+print first
+print second
+print data
diff --git a/For Weekly Test/20-07-2011/classClient.py b/For Weekly Test/20-07-2011/classClient.py
index 625e48e..ce02d19 100644
--- a/For Weekly Test/20-07-2011/classClient.py
+++ b/For Weekly Test/20-07-2011/classClient.py
@@ -64,11 +64,3 @@ class Connection:
else:
return 0
-#MAIN PART
-x = Connection('localhost',50008)
-print x.connect()
-x.sendData('hello server :)')
-print x.receiveData()
-x.sendData('I send you another message')
-x.closeConnection()
-
diff --git a/For Weekly Test/20-07-2011/classClient.pyc b/For Weekly Test/20-07-2011/classClient.pyc
index 85f1aa7..9255493 100644
--- a/For Weekly Test/20-07-2011/classClient.pyc
+++ b/For Weekly Test/20-07-2011/classClient.pyc
Binary files differ
diff --git a/For Weekly Test/20-07-2011/classController.py b/For Weekly Test/20-07-2011/classController.py
index e26250d..f39aafb 100644
--- a/For Weekly Test/20-07-2011/classController.py
+++ b/For Weekly Test/20-07-2011/classController.py
@@ -161,9 +161,7 @@ class test:
print "Receiver handler : Ready"
print ""
- x.sendData("start")#send message to handler to start the call
- sleep(0.5)
- x.sendData(self.destNo)
+ x.sendData("start|"+self.destNo)#send message to handler to start the call
x.closeConnection()
x.connect()
@@ -194,9 +192,7 @@ class test:
#if failed, tell everybody to try one more time
if resultOrig == 486 or resultDest == 486:
- x.sendData("start")
- sleep(0.5)
- x.sendData(self.destNo)
+ x.sendData("start|"+self.destNo)
x.closeConnection()
x.connect()
diff --git a/For Weekly Test/20-07-2011/classController.pyc b/For Weekly Test/20-07-2011/classController.pyc
index 6abfa92..3104b8a 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/landlineCall.py b/For Weekly Test/20-07-2011/landlineCall.py
new file mode 100644
index 0000000..4741d13
--- /dev/null
+++ b/For Weekly Test/20-07-2011/landlineCall.py
@@ -0,0 +1,166 @@
+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(50099)
+ 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("sipgate.de","1289459","MMW9AX")
+ 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
new file mode 100644
index 0000000..0890f36
--- /dev/null
+++ b/For Weekly Test/20-07-2011/landlineReceiver.py
@@ -0,0 +1,161 @@
+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 status
+
+ 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)
+ print "here"
+ current_call.answer(200)
+ sleep(1)
+ #current_call.hangup()
+ #status = 200
+ server.sendData('200')
+
+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
+ #server.sendData('200')
+
+ if self.call.info().state == pj.CallState.DISCONNECTED:
+ current_call = None
+
+ print '701 The called party has hung up'
+
+
+lib = pj.Lib()
+
+try:
+
+
+ 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("sipgate.de","1289459","MMW9AX")
+ 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 = classServer.ServerHandler(50106)
+ tried = server.openSocket()
+ print tried
+ server.sendData('ready')
+ server.closeConnection()
+ tried = server.openSocket()
+ while stop <> True:
+
+ data = server.receiveData()
+
+ if data == "487":
+ print "BYE BYE"
+ sleep(5)
+ stop = True
+ break
+
+ if current_call == None:
+ accept = None
+ continue
+ else:
+ accept = True
+ #print "Incoming call from :"
+ #current_call.answer(200)
+
+
+
+
+ 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/sipCall.py b/For Weekly Test/20-07-2011/sipCall.py
index f41756d..a863ce8 100644
--- a/For Weekly Test/20-07-2011/sipCall.py
+++ b/For Weekly Test/20-07-2011/sipCall.py
@@ -24,7 +24,6 @@ class MyCallCallback(pj.CallCallback):
else:
sleep(0.5)
-
if self.call.info().last_reason == "Busy Here":
server.sendData('486')
@@ -73,17 +72,15 @@ while stop <> True:
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
+ event = data[0:5]
+ num = data[6:]
+ if event == "start" and num <> "":
+
+ server.closeConnection()
+ tried = server.openSocket()
+
+ number = "sip:"+num+"@132.230.4.8"
+ current_call = make_call(number)
if data == "487":
stop = True
diff --git a/Handler/gsmcall_.py b/Handler/gsmcall_.py
deleted file mode 100644
index 1e2a010..0000000
--- a/Handler/gsmcall_.py
+++ /dev/null
@@ -1,95 +0,0 @@
-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"
-
-LOG_LEVEL=2
-current_call = None
-success = ""
-
-
-
-while stop <> "true":
-
-
- try:
- global ser
- portAddress = '/dev/ttyUSB1'
- 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(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()
-
-
- server.sendData('I am ready')#send message to controller
- print "here:", server.connected
-
- while 1:
- try:
- data = server.receiveData() # waiting mode, until receiver start message or terminate message
-
- if data == "start": # if receiver start message, handler start to call destination
-
- while 1:
-
- num = server.receiveData() # waiting destination number
- if num <> "":
-
- callBackNumber=
- ser.write('ATD' + num + ';\r')
- sleep(5)
- 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 when sending message"
- server.closeConnection()
- del server
- ser.close()
-
- server.closeConnection()
- del server
- ser.close()
-
- except ValueError:
- print "Exception: " + str(e)
-
-print "Goodbye"
-sleep(3)
diff --git a/Handler/gsmincom_.py b/Handler/gsmincom_.py
deleted file mode 100644
index 0c0d5a3..0000000
--- a/Handler/gsmincom_.py
+++ /dev/null
@@ -1,135 +0,0 @@
-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"
-
-
-success = ""
-
-
-
-
-try:
-
- global ser
- portAddress = '/dev/ttyACM0'
- portName = portAddress[-4:]
- portExist = os.popen('dmesg | grep ' + portName).read()
-
-
- ser = Serial(
- port=portAddress,
- baudrate=19200,
- bytesize=EIGHTBITS,
- parity=PARITY_NONE,
- stopbits=STOPBITS_ONE)
- ser.open()
-
- 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:
-
- server.sendData('I am ready')
-
- while stop <> "true":
-
- data = server.receiveData()
- if data == "terminated":
- print "I will", data
- break
-
- buffer = buffer + ser.read(ser.inWaiting())
- if '\n' in buffer:
- lines = buffer.split('\n')
- last_received = lines.pop(0)
-
- buffer = '\n'.join(lines)
-
- last_received=last_received.split('\n')
- line = last_received[0].replace(chr(13), '')
-
-
- if len(line) > 0:
-
- if line=='RING':
- if pickUp == 0:
-
- print "Somebody calling"
- sleep(1)
- ser.write('ATA\r')
-
- sleep(1)
- ser.write('AT+CSQ\r')
-
- sleep(2)
- ser.write('AT+CLCC\r')
- line=''
-
- 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"
- sleep(5)
-
- ser.write('AT+CHUP\r')
- pickUp = 0
-
- quotation1 = int(string.find(line,'"'))+1
- lineTemp = line[quotation1:]
-
- quotation2 = int(string.find(lineTemp,'"'))
- numberOfCaller = line[quotation1:quotation1+quotation2]
-
- server.sendData('I got call from' +numberOfCaller)
- print "caller number", numberOfCaller
- sleep(1)
- server.sendData('success')
- sleep (3)
- ser.close()
-
-
- server.closeConnection()
- del server
- else:
-
- print "not connected"
-
- del server
-
- ser.close()
-except ValueError:
- print "Exception: " + str(e)
- server.closeConnection()
- del server
-
-print "GOODBYE"
-sleep(5)
diff --git a/Handler/landlineCall.py b/Handler/landlineCall.py
index 9cec7e3..81648c1 100644
--- a/Handler/landlineCall.py
+++ b/Handler/landlineCall.py
@@ -1,203 +1,119 @@
import sys
import pjsua as pj
+import classServer
from time import sleep
-import string
-server = "sipgate.de"
-username = "1289459"
-password = "MMW9AX"
-number = ""
-LOG_LEVEL = 2
-current_call = None
-is486 = False
-isConfirmed = False
-isRinging = False
-isConnected = False
-isStopped = False
-firstTime502 = True
-firstTime100 = True
-TIMEOUT_LIMIT = 30
-
-# Logging callback
def log_cb(level, str, len):
- print str,
-
-# Callback to receive events from account
-class MyAccountCallback(pj.AccountCallback):
+ print str, "SIP log"
- def __init__(self, account=None):
- pj.AccountCallback.__init__(self, account)
-
-# Callback to receive events from Call
+# 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 isConfirmed
- global isConnected
- global isRinging
- global is486
-
- if self.call.info().state == pj.CallState.CALLING:
- print "CALLING..."
-
- if self.call.info().last_code == 486:
- is486 = True
- if self.call.info().state == pj.CallState.EARLY:
- isRinging = True
+ def on_state(self):
+ global current_call
+
+ 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()
- if self.call.info().state == pj.CallState.CONFIRMED:
- isConfirmed = True
- isConnected = True
- isRinging = False
-
- if self.call.info().state == pj.CallState.DISCONNECTED:
- current_call = None
- isConnected = False
-
+ server.sendData('200')
+ else:
+ sleep(0.5)
+
+ if self.call.info().last_reason == "Busy Here":
+ server.sendData('486')
+
+ 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
+
-print "Whenever something comes from the server (at the moment from you), it will continue. Imitating the server behaviour!"
+lib = pj.Lib()
+stop =False
+current_call = None
+
+while stop <> True:
-while not isStopped:
- lib = pj.Lib()
- 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))
- lib.start()
- lib.set_null_snd_dev()
-
-# server = classServer.ServerHandler(50099)
-# tried = server.openSocket()
-#
-# if server.error != 'No error':
-# print server.error
-# if server.error == '[Errno 98] Address already in use':
-# print "Trying to kill the port"
-# print server.killPort()
-# server.closeConection()
-
- acc_cfg = pj.AccountConfig(server,username,password)
- acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
-
- if acc.info().reg_status == 502:
- if firstTime502:
- print "CONNECTION ERROR!!"
- print "Please check your internet connection!\n"
- firstTime502 = False
-
- acc.delete()
- lib.destroy()
- lib = None
- acc = None
-# server.sendData('NOT ready')
- sleep(2)
- continue
+ lib.start()
+ lib.set_null_snd_dev()
- while acc.info().reg_status == 100:
- if firstTime100:
- print "Trying to register."
- firstTime100 = False
-
+ server = classServer.ServerHandler(50099)
+ tried = server.openSocket()
- while acc.info().reg_status == 408:
- print "408: REGISTRATION FAILED DUE TO TIMEOUT!!"
- print "Check your internet connection and SIP settings!"
-# server.sendData('NOT ready')
-
-
- if acc.info().reg_status == 200:
- print ("REGISTRATION IS SUCCESSFUL") #server.sendData('ready')
+ try:
+ acc_cfg = pj.AccountConfig("sipgate.de","1289459","MMW9AX")
+ acc = lib.create_account(acc_cfg, cb=pj.AccountCallback())
- while 1:
-# try:
- print "Waiting for server(at the moment YOU!) to send command here:" #This line should be deleted further!
- startStop = sys.stdin.readline().rstrip("\r\n") #startStop = server.receiveData()
-
- if startStop == "start":
- timeCounterRinging = 0
- firstTimeRinging = True
-
- while 1:
- #number = server.receiveData()
- print "Please enter the number to call:"
- number = sys.stdin.readline().rstrip("\r\n")
- if number <> "":
- numberToCall = "sip:"+number+"@"+server
- current_call = make_call(numberToCall)
+ if acc.info().reg_status < 700:
+
+ server.sendData('ready')
+ print "Status: ", server.connected
+
+ while 1:
+ try:
+ data = server.receiveData()
+ event = data[0:5]
+ num = data[6:]
+ if event == "start" and num <> "":
+
+ server.closeConnection()
+ tried = server.openSocket()
- while 1:
- if isRinging:
- sleep(1)
- timeCounterRinging = timeCounterRinging + 1
- if firstTimeRinging:
- print "RINGING..."
- firstTimeRinging = False
- if is486:
- print "THE NUMBER THAT YOU'VE DIALLED IS BUSY!!"
- isConfirmed = False
- isConnected = False
- isRinging = False
- is486 = False
- break
-
- if isConnected and isConfirmed:
- print "CALL SUCCESSFULLY ESTABLISHED!!"
- sleep(5)
- current_call.hangup()
- print "CALL SUCCESSFULLY TERMINATED!!"
- isConfirmed = False
- isConnected = False
- isRinging = False
- is486 = False
- break
-
- if timeCounterRinging == TIMEOUT_LIMIT and isRinging:
- current_call.hangup()
- print "THE NUMBER THAT YOU'VE DIALLED IS NOT ANSWERING!!"
- isConfirmed = False
- isConnected = False
- isRinging = False
- is486 = False
- break
- break
-
- if startStop == "stop":
- isStopped = True
- break
-
-# except ValueError:
-# print "813 General socket layer error: Failed send message"
-# server.closeConnection()
-# del server
+ number = "sip:"+num+"@sipgate.de"
+ current_call = make_call(number)
-# server.closeConnection()
-# del server
-
-# server.closeConnection()
-# del server
-
-sleep(2)
-print "LOGGING OUT..."
+ 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
-print "LOGOUT WAS SUCCESSFULL!!"
diff --git a/Handler/landlineReceiver.py b/Handler/landlineReceiver.py
index 22ae872..f61ff6a 100644
--- a/Handler/landlineReceiver.py
+++ b/Handler/landlineReceiver.py
@@ -1,111 +1,87 @@
import sys
import pjsua as pj
+import classServer
from time import sleep
-import string
-server = "sipgate.de"
-username = "1289459"
-password = "MMW9AX"
-current_call = None
-incomingCallNumber = ""
-LOG_LEVEL=2
-userInput = ""
-# Logging callback
def log_cb(level, str, len):
- print str,
+ 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)
+ def on_incoming_call(self, call):
-# Notification on incoming call
- def on_incoming_call(self, call):
- global current_call
+ current_call = call
- if current_call:
- call.answer(486, "Busy")
- return
-
- incomingCallNumber = call.info().remote_uri
- print "This number "+incomingCallNumber+" is calling."
+ sleep(0.5)
+ call.answer(200)
- current_call = call
- call_cb = MyCallCallback(current_call)
- current_call.set_callback(call_cb)
- current_call.answer(180)
+ sleep(0.5)
-
-# 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 == pj.CallState.CONNECTING:
- print "CONNECTING"
-
- if self.call.info().state == pj.CallState.EARLY:
- print "RINGING"
+ if current_call <> None:
+ call.hangup()
- if self.call.info().state == pj.CallState.CONFIRMED:
- print "CALL CONFIRMED"
-
- if self.call.info().state == pj.CallState.DISCONNECTED:
- current_call = None
- print "CURRENT CALL DISCONNECTED"
-
+ server.sendData('200')
+
lib = pj.Lib()
-lib.init(log_cfg = pj.LogConfig(level=LOG_LEVEL, callback=log_cb))
-transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
-lib.start()
-lib.set_null_snd_dev()
+stop = False
try:
- acc_cfg = pj.AccountConfig(server,username,password)
- acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
-
-except ValueError:
- print "Exception: " + str(e)
-
-print "You want to receive a call then."
-print "Receive another call?"
-userInput = sys.stdin.readline().rstrip("\r\n")
-
-while userInput == "yes":
-
- if acc.info().reg_status < 700:
- if not current_call:
- continue
- else:
- sleep(5)
- current_call.answer(200)
- sleep(5)
- current_call.hangup()
- sleep(3)
- print "Receive another call? "
- userInput = sys.stdin.readline().rstrip("\r\n")
-
- else:
- print "REGISTRATION ERROR"
- lib.destroy()
- lib = None
- acc = None
-
-sleep(2)
-print "LOGGING OUT..."
-acc.delete()
-lib.destroy()
-lib = None
-acc = None
-print "LOGOUT WAS SUCCESSFULL!!"
-
+
+ server = classServer.ServerHandler(50106)
+ tried = server.openSocket()
+
+ lib.init(log_cfg = pj.LogConfig(level=1, callback=log_cb))
+ transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
+
+ lib.start()
+ lib.set_null_snd_dev()
+
+ try:
+ acc_cfg = pj.AccountConfig("sipgate.de","1289459","MMW9AX")
+ acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
+
+ if acc.info().reg_status < 700:
+
+ server.sendData('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"
+
+ 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/Handler/sipCall.py b/Handler/sipCall.py
index f41756d..a863ce8 100644
--- a/Handler/sipCall.py
+++ b/Handler/sipCall.py
@@ -24,7 +24,6 @@ class MyCallCallback(pj.CallCallback):
else:
sleep(0.5)
-
if self.call.info().last_reason == "Busy Here":
server.sendData('486')
@@ -73,17 +72,15 @@ while stop <> True:
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
+ event = data[0:5]
+ num = data[6:]
+ if event == "start" and num <> "":
+
+ server.closeConnection()
+ tried = server.openSocket()
+
+ number = "sip:"+num+"@132.230.4.8"
+ current_call = make_call(number)
if data == "487":
stop = True