summaryrefslogtreecommitdiffstats
path: root/notFinishedCode
diff options
context:
space:
mode:
authorRefik Hadzialic2011-07-18 17:16:38 +0200
committerRefik Hadzialic2011-07-18 17:16:38 +0200
commit608e379754c35e12cad43c3924c13bffc3887c15 (patch)
tree568494d71435630d1d97cd8d0435ce4af5339e9b /notFinishedCode
parentChanged the code to make it more smoothly working. (diff)
downloadgsm-selftest-608e379754c35e12cad43c3924c13bffc3887c15.tar.gz
gsm-selftest-608e379754c35e12cad43c3924c13bffc3887c15.tar.xz
gsm-selftest-608e379754c35e12cad43c3924c13bffc3887c15.zip
Tri needed these files!
Diffstat (limited to 'notFinishedCode')
-rw-r--r--notFinishedCode/.dbClass.py.swpbin0 -> 16384 bytes
-rw-r--r--notFinishedCode/landlineCall.py203
-rw-r--r--notFinishedCode/localsipReceiver.py160
3 files changed, 363 insertions, 0 deletions
diff --git a/notFinishedCode/.dbClass.py.swp b/notFinishedCode/.dbClass.py.swp
new file mode 100644
index 0000000..f0f95e4
--- /dev/null
+++ b/notFinishedCode/.dbClass.py.swp
Binary files differ
diff --git a/notFinishedCode/landlineCall.py b/notFinishedCode/landlineCall.py
new file mode 100644
index 0000000..9cec7e3
--- /dev/null
+++ b/notFinishedCode/landlineCall.py
@@ -0,0 +1,203 @@
+import sys
+import pjsua as pj
+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):
+
+ def __init__(self, account=None):
+ pj.AccountCallback.__init__(self, account)
+
+# 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 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
+
+ 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
+
+
+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)
+ return None
+
+print "Whenever something comes from the server (at the moment from you), it will continue. Imitating the server behaviour!"
+
+while not isStopped:
+
+ 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()
+
+# 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
+
+
+ while acc.info().reg_status == 100:
+ if firstTime100:
+ print "Trying to register."
+ firstTime100 = False
+
+
+ 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')
+
+ 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)
+
+ 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
+
+# server.closeConnection()
+# del server
+
+# server.closeConnection()
+# del server
+
+sleep(2)
+print "LOGGING OUT..."
+acc.delete()
+lib.destroy()
+lib = None
+acc = None
+print "LOGOUT WAS SUCCESSFULL!!"
+
diff --git a/notFinishedCode/localsipReceiver.py b/notFinishedCode/localsipReceiver.py
new file mode 100644
index 0000000..96f058f
--- /dev/null
+++ b/notFinishedCode/localsipReceiver.py
@@ -0,0 +1,160 @@
+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.252.228", "4976120397897", "hB8M3WyFt61C")
+ 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