summaryrefslogtreecommitdiffstats
path: root/For Weekly Test
diff options
context:
space:
mode:
authortriatmoko2011-07-16 14:08:58 +0200
committertriatmoko2011-07-16 14:08:58 +0200
commitcf101261cc3070fb24b27ebd607e93b60b02607b (patch)
tree5bbdfbf2e7669d293369c39b4e0e9d93ab173157 /For Weekly Test
parentupdate sip handler (diff)
downloadgsm-selftest-cf101261cc3070fb24b27ebd607e93b60b02607b.tar.gz
gsm-selftest-cf101261cc3070fb24b27ebd607e93b60b02607b.tar.xz
gsm-selftest-cf101261cc3070fb24b27ebd607e93b60b02607b.zip
managing file.
Diffstat (limited to 'For Weekly Test')
-rw-r--r--For Weekly Test/15-07-2011/Controller-SecondType.py308
-rw-r--r--For Weekly Test/15-07-2011/Controller-SecondType_withDB.py342
-rw-r--r--For Weekly Test/15-07-2011/LandlineCall.py166
-rw-r--r--For Weekly Test/15-07-2011/LandlineReceiver.py160
-rw-r--r--For Weekly Test/15-07-2011/classClient.py66
-rw-r--r--For Weekly Test/15-07-2011/classClient.pycbin0 -> 2759 bytes
-rw-r--r--For Weekly Test/15-07-2011/classDb.py212
-rw-r--r--For Weekly Test/15-07-2011/classDb.pycbin0 -> 5926 bytes
-rw-r--r--For Weekly Test/15-07-2011/classPing.py28
-rw-r--r--For Weekly Test/15-07-2011/classPing.pycbin0 -> 1283 bytes
-rw-r--r--For Weekly Test/15-07-2011/classServer.py94
-rw-r--r--For Weekly Test/15-07-2011/classServer.pycbin0 -> 3365 bytes
-rw-r--r--For Weekly Test/15-07-2011/gsmcall2_.py102
-rw-r--r--For Weekly Test/15-07-2011/gsmcall_.py105
-rw-r--r--For Weekly Test/15-07-2011/gsmincom_.py134
-rw-r--r--For Weekly Test/15-07-2011/localsipReceiver.py160
-rw-r--r--For Weekly Test/15-07-2011/sipCall.py180
-rw-r--r--For Weekly Test/15-07-2011/sipReceiver.py177
-rw-r--r--For Weekly Test/20-07-2011/Controller.py185
-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/classClient.py74
-rw-r--r--For Weekly Test/20-07-2011/classClient.pycbin0 -> 2884 bytes
-rw-r--r--For Weekly Test/20-07-2011/classController.py267
-rw-r--r--For Weekly Test/20-07-2011/classController.pycbin0 -> 5084 bytes
-rw-r--r--For Weekly Test/20-07-2011/classDb.py212
-rw-r--r--For Weekly Test/20-07-2011/classDb.pycbin0 -> 5978 bytes
-rw-r--r--For Weekly Test/20-07-2011/classPing.py28
-rw-r--r--For Weekly Test/20-07-2011/classPing.pycbin0 -> 1283 bytes
-rw-r--r--For Weekly Test/20-07-2011/classServer.py94
-rw-r--r--For Weekly Test/20-07-2011/classServer.pycbin0 -> 3365 bytes
-rw-r--r--For Weekly Test/20-07-2011/gsmcall2_.py102
-rw-r--r--For Weekly Test/20-07-2011/gsmcall_.py105
-rw-r--r--For Weekly Test/20-07-2011/gsmincom_.py134
-rw-r--r--For Weekly Test/20-07-2011/localsipReceiver.py160
-rw-r--r--For Weekly Test/20-07-2011/sipCall.py180
-rw-r--r--For Weekly Test/20-07-2011/sipReceiver.py177
37 files changed, 4278 insertions, 0 deletions
diff --git a/For Weekly Test/15-07-2011/Controller-SecondType.py b/For Weekly Test/15-07-2011/Controller-SecondType.py
new file mode 100644
index 0000000..31df36c
--- /dev/null
+++ b/For Weekly Test/15-07-2011/Controller-SecondType.py
@@ -0,0 +1,308 @@
+import sys
+import os
+import re
+import time
+import MySQLdb
+import subprocess
+
+
+import classClient #import class socket
+import classDb #import class db
+
+from time import sleep
+from datetime import datetime
+
+
+user = 'root'
+passw = 'randompasswordSQL' #default password we agree with this password before!
+host = 'localhost'
+dbname = 'gsmselftesting'
+
+stop = "False"
+status = ""
+dbSStatus = ""
+
+
+#function to ping
+def FuncPing(host):
+ ping_cmd = os.popen('ping '+ host + ' -c 1 -W 1').read()
+ pingAlive = int(string.find(ping_cmd, '1 received'))
+ if pingAlive != -1:
+ return 1
+ else:
+ return 0
+
+
+# One function for all test case
+
+def FuncTest(orig, origAdd, dest, destAdd, destNo):
+
+ global repeatTest
+ global portOrig
+ global resultOrig
+ global resultDest
+ global x
+ global y
+ portOrig = None
+ resultOrig= None
+ resultDest = None
+
+
+ repeatTest = ""
+
+ try:
+
+ if dest =="gsmBox1" or dest =="gsmBox2":
+
+ if dest =="gsmBox1":
+ portOrig = 50095
+
+ if dest =="gsmBox2":
+ portOrig = 50096
+
+ print "GSM server handler", x.connect()
+ x.sendData('hello server please wakeup the handler and be caller')
+
+ else:
+ # open SIP caller handler
+
+ command="--command=python " +orig
+ subprocess.Popen(args=["gnome-terminal", command])
+
+ sleep(5)
+
+ if orig=="SIPCall.py":
+ portOrig = 50097
+
+ if orig=="gsmcall_.py":
+ portOrig = 50098
+
+ if orig == "landlineCall.py":
+ portOrig = 50099
+
+ if orig == "LocalSIPCall.py":
+ portOrig = 50100
+
+ #else: #mean external GSM
+ # print "have not yet define"
+ #portOrig = 50101
+
+ x = classClient.Connection(origAdd,portOrig)
+ print ""
+ print "Caller handler status:", x.connect()
+
+ x.sendData('hello Handler')
+
+ # wait respond from origin handler
+ while 1:
+ origHandler = x.receiveData()
+ if origHandler <> "":
+ break
+ #think about time out
+
+ if origHandler == "ready":
+ print "Caller handler ready"
+ print ""
+ try:
+ y = None
+ global portDest
+ portDest = None
+
+ if dest =="gsmBox1" or dest =="gsmBox2":
+
+ if dest =="gsmBox1":
+ portDest = 50102
+
+ if dest =="gsmBox2":
+ portDest = 50103
+
+ y = classClient.Connection(destAdd,portDest)
+ print "GSM handler", y.connect()
+ y.sendData('hello server please wakeup the handler and be receiver')
+
+ else:
+ command="--command=python " +dest
+ subprocess.Popen(args=["gnome-terminal", command])
+
+ sleep(2)
+
+ if dest=="SIPIncoming.py":
+ portDest = 50104
+
+ if dest=="gsmincom_.py":
+ portDest = 50105
+
+ if dest == "landlineReceiver.py":
+ portDest = 50106
+
+ if dest == "LocalSIPReceiver.py":
+ portDest = 50107
+
+ #mean external GSM
+ #print "not define yet"
+ #portDest = 50108
+
+ y = classClient.Connection(destAdd,portDest)
+ print "Destination handler status:", y.connect()
+ y.sendData('hello Receiver, caller number')
+
+ #wait respond from destination handler
+ while 1:
+ destHandler = y.receiveData()
+ if destHandler <> "":
+ break
+ #should have timeout = think about timeout
+
+ if destHandler == "ready":
+
+ print "Destination handler ready"
+ print ""
+ x.sendData("start")#send message to handler to start the call
+ x.closeConnection()
+ x.connect()
+
+ #wait respond from both of handler
+ while 1:
+ sleep(5)
+ x.connect()
+ sleep(1)
+ resultOrig = x.receiveData()
+ resultDest = y.receiveData()
+
+ if resultOrig <> "" or resultDest <> "":
+ break
+
+ #if failed, try one more time
+ if resultOrig == "failed" or resultDest == "failed":
+ y.sendData('hello Destination Handler')
+ x.sendData("start")
+ sleep(2)
+ x.sendData(destNo)
+
+ while 1:
+ resultOrig = X.receiveData()
+ resultDest = y.receiveData()
+ print "Origin1: ", resultOrig
+ print "Destination1: ", resultDest
+
+ if resultOrig <> "" or resultDest <> "":
+ break
+
+ #if still failed, save to db and return repeat test, so we make automatic test vice versa
+ if resultOrig == "failed" or resultDest == "failed":
+ #db.execute ("update result table")
+ repeatTest="true"
+ print "Origin2: ", resultOrig
+ print "Destination1: ", resultDest
+
+ else: #save to database, tell handler to terminated
+ #db.execute ("update result table")
+ print "Test Result origin: ", resultOrig
+ print "Test Result Destination: ", resultDest
+ x.sendData('terminated') # signal caller to terminate
+ y.sendData('terminated') # signal receiver to terminate
+
+ else:
+ statusTest = "604 General Handler Error: Destination handler no respond"
+ #tell Caller handler to terminate because receiver doesnt work
+ x.sendData("terminated")
+
+ y.closeConnection()
+
+ except ValueError:
+ print "601 General Handler Error: Could not open Destination handler"
+ else:
+ statusTest = "605 General Handler Error: Origin handler no respond"
+
+ x.closeConnection()
+
+ except ValueError:
+ print "602 General Handler Error: Could not open Origin handler"
+
+
+
+# Main software
+
+
+
+# Check DB connection
+x = classDb.DBMySQLConnection(user, passw, host, dbname)
+print "connected to the DB ", x.connectDB()
+print ""
+dbStatus = x.connectDB()
+
+
+if dbStatus == 1:
+
+ # Check Ping to the Every Handler
+ #sipServerStatus = FuncPing("132.230.4.8")
+ sipServerStatus =1
+ #gsmBox1Status = FuncPing("132.230.4.8")
+ #gsmBox2Status = FuncPing("132.230.4.8")
+
+# Fetch The task information from DB
+ #print "do i have anything to do", x.anyTasksToDo()
+
+ #for item in x.tasksList:
+ # taskID = item[0]
+ # callFrom = item[1]
+ # callTo = item[2]
+ callFrom = "gsmrz1"
+ callTo = "sip"
+ #J = 1, 2
+ #for A in J:
+# print "call from to ", taskID , callFrom , callTo
+ print "Test Task : Calling from " +callFrom+ " to " +callTo
+ print ""
+
+
+ if callFrom == "sip" and sipServerStatus <> 0:
+
+ if callTo == "gsmrz1":
+
+ FuncTest("SIPCall.py", "localhost", "gsmincom_.py", "localhost","473")
+ print "Finish test"
+ 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 == "gsmrz2":
+
+ if gsmBox1Status <> 0:
+ FuncTest("SIPCall.py", "localhost", "Box1", "132.0.0.2","404")
+ 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 == "gsmrz3":
+
+ if gsmBox2Status <> 0:
+ FuncTest("SIPCall.py", "localhost", "Box2", "132.0.0.3","405")
+ 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 callFrom =="gsmrz1":
+
+ if callTo =="sip" and sipServerStatus <> 0:
+ FuncTest("gsmcall_.py", "localhost", "SIPIncoming.py", "localhost","929")
+ sleep(10)
+
+
+ if callTo =="gsmrz2" and gsmBox1Status <> 0:
+ FuncTest("Box1", "132.0.0.2", "SIPReceiver.py", "localhost","929")
+
+ if callTo =="gsmrz3" and gsmBox2Status <> 0:
+ FuncTest("Box2", "132.0.0.3", "SIPReceiver.py", "localhost","929")
+
+
+
+
+# will exit if DB connection failed
+else:
+ sys.exit(5)
+
diff --git a/For Weekly Test/15-07-2011/Controller-SecondType_withDB.py b/For Weekly Test/15-07-2011/Controller-SecondType_withDB.py
new file mode 100644
index 0000000..1112c51
--- /dev/null
+++ b/For Weekly Test/15-07-2011/Controller-SecondType_withDB.py
@@ -0,0 +1,342 @@
+import sys
+import os
+import re
+import time
+import MySQLdb
+import subprocess
+
+
+import classClient #import class socket
+import classDb #import class db
+import classPing
+
+from time import sleep
+from datetime import datetime
+
+
+user = 'root'
+passw = 'randompasswordSQL' #default password we agree with this password before!
+host = 'localhost'
+dbname = 'gsmselftesting'
+
+stop = "False"
+status = ""
+dbSStatus = ""
+
+sipNum = "4661929"
+landlnNum = "076145875681"
+
+
+sipCall = "sipCall.py"
+sipRec = "sipReceiver.py"
+landlnCall = "LandlineCall.py"
+landlnRec = "LandlineReceiver.py"
+
+localSipRec = "localsipReceiver.py"
+rz1Call = "rz1Call.py"
+rz1Rec = "rz1Receiver.py"
+
+o2Call = "o2Call.py"
+o2Rec = "o2Receiver.py"
+vodafoneCall = "vodafoneCall.py"
+vodafoneRec = "vodafoneReceiver.py"
+tmobileCall = "tmobileCall.py"
+tmobilRec = "tmobileReceiver.py"
+
+# One function for all test case
+
+def FuncTest(orig, origAdd, dest, destAdd, destNo):
+
+ global repeatTest
+ global portOrig
+ global resultOrig
+ global resultDest
+ global x
+ global y
+ portOrig = None
+ resultOrig= None
+ resultDest = None
+
+
+ repeatTest = ""
+
+ try:
+
+ if dest =="gsmBox1" or dest =="gsmBox2":
+
+ if dest =="gsmBox1":
+ portOrig = 50095
+
+ if dest =="gsmBox2":
+ portOrig = 50096
+
+ print "GSM server handler", x.connect()
+ x.sendData('hello server please wakeup the handler and be caller')
+
+ else:
+ # open SIP caller handler
+
+ command="--command=python " +orig
+ subprocess.Popen(args=["gnome-terminal", command])
+
+ sleep(5)
+
+ if orig=="sipCall.py":
+ portOrig = 50097
+
+ if orig=="gsmcall_.py":
+ portOrig = 50098
+
+ if orig == "landlineCall.py":
+ portOrig = 50099
+
+ if orig == "LocalSIPCall.py":
+ portOrig = 50100
+
+ #else: #mean external GSM
+ # print "have not yet define"
+ #portOrig = 50101
+
+ x = classClient.Connection(origAdd,portOrig)
+ print ""
+ print "Caller handler status:", x.connect()
+
+ x.sendData('hello Handler')
+
+ # wait respond from origin handler
+ while 1:
+ origHandler = x.receiveData()
+ if origHandler <> "":
+ break
+ #think about time out
+
+ if origHandler == "ready":
+ print "Caller handler ready"
+ print ""
+ try:
+ y = None
+ global portDest
+ portDest = None
+
+ if dest =="gsmBox1" or dest =="gsmBox2":
+
+ if dest =="gsmBox1":
+ portDest = 50102
+
+ if dest =="gsmBox2":
+ portDest = 50103
+
+ y = classClient.Connection(destAdd,portDest)
+ print "GSM handler", y.connect()
+ y.sendData('hello server please wakeup the handler and be receiver')
+
+ else:
+ command="--command=python " +dest
+ subprocess.Popen(args=["gnome-terminal", command])
+
+ sleep(2)
+
+ if dest=="SIPIncoming.py":
+ portDest = 50104
+
+ if dest=="gsmincom_.py":
+ portDest = 50105
+
+ if dest == "landlineReceiver.py":
+ portDest = 50106
+
+ if dest == "LocalSIPReceiver.py":
+ portDest = 50107
+
+ #mean external GSM
+ #print "not define yet"
+ #portDest = 50108
+
+ y = classClient.Connection(destAdd,portDest)
+ print "Destination handler status:", y.connect()
+ y.sendData('hello Receiver, caller number')
+
+ #wait respond from destination handler
+ while 1:
+ destHandler = y.receiveData()
+ if destHandler <> "":
+ break
+ #should have timeout = think about timeout
+
+ if destHandler == "ready":
+
+ print "Destination handler ready"
+ print ""
+ y.closeConnection()
+ x.sendData("start")#send message to handler to start the call
+ sleep(1)
+ x.sendData(destNo)
+
+ #for refresh socket, so gsm handler can use socket to communicated with the phone
+ x.closeConnection()
+
+ print ""
+ #wait respond from both of handler
+ while 1:
+ sleep(5)
+ x.connect()
+ y.connect()
+ sleep(1)
+ resultOrig = x.receiveData()
+ resultDest = y.receiveData()
+ print "", resultDest
+ if resultOrig <> "" and resultDest <> "":
+ break
+
+ #if failed, try one more time
+ if resultOrig == "failed" or resultDest == "failed":
+ y.sendData('hello Destination Handler')
+ x.sendData("start")
+ sleep(2)
+ x.sendData(destNo)
+
+ #for refresh socket, so gsm handler can use socket to communicated with the phone
+ #x.closeConnection()
+ #x.connect()
+
+ while 1:
+ resultOrig = X.receiveData()
+ resultDest = y.receiveData()
+ print "Origin1: ", resultOrig
+ print "Destination1: ", resultDest
+
+ if resultOrig <> "" or resultDest <> "":
+ break
+
+ #if still failed, save to db and return repeat test, so we make automatic test vice versa
+ if resultOrig == "failed" or resultDest == "failed":
+ #db.execute ("update result table")
+ repeatTest="true"
+ print "Origin2: ", resultOrig
+ print "Destination1: ", resultDest
+
+ else: #save to database, tell handler to terminated
+ #db.execute ("update result table")
+ print "Test Result origin: ", resultOrig
+ print "Test Result Destination: ", resultDest
+ x.sendData('terminated') # signal caller to terminate
+ y.sendData('terminated') # signal receiver to terminate
+
+ else:
+ statusTest = "604 General Handler Error: Destination handler no respond"
+ #tell Caller handler to terminate because receiver doesnt work
+ x.sendData("terminated")
+
+ y.closeConnection()
+
+ except ValueError:
+ print "601 General Handler Error: Could not open Destination handler"
+ else:
+ statusTest = "605 General Handler Error: Origin handler no respond"
+
+ x.closeConnection()
+
+ except ValueError:
+ print "602 General Handler Error: Could not open Origin handler"
+
+
+
+# Main software
+
+
+
+# Check DB connection
+x = classDb.DBMySQLConnection(user, passw, host, dbname)
+print "connected to the DB ", x.connectDB()
+print ""
+dbStatus = x.connectDB()
+
+
+if dbStatus == 1:
+
+ # Check Ping to the Every Handler
+ sipServer = classPing.Ping('132.230.4.8')
+ sipServerStatus = sipServer.ping(3)
+
+ sipGateServer = classPing.Ping('sipgate.de')
+ sipGateServerStatus = sipGateServer.ping(3)
+
+ sipLocalServer = classPing.Ping('132.230.4.60')
+ sipLocalServerStatus = sipLocalServer.ping(3)
+
+ #gsmBox1Status = FuncPing("132.230.4.8")
+ #gsmBox2Status = FuncPing("132.230.4.8")
+
+# Fetch The task information from DB
+ print "do i have anything to do", x.anyTasksToDo()
+
+ for item in x.tasksList:
+ taskID = item[0]
+ callFrom = item[1]
+ callTo = item[2]
+
+ print "call from to ", taskID , callFrom , callTo
+ print sipServerStatus
+
+ if callFrom == "sip" and sipServerStatus <> 0:
+
+ if callTo == "gsmrz1":
+
+ FuncTest(sipCall, "localhost", "gsmincom_.py", "localhost","4661455")
+ print "Finish test"
+ 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 == "gsmrz2":
+
+ if gsmBox1Status <> 0:
+ FuncTest(sipCall, "localhost", "Box1", "132.0.0.2","404")
+ 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 == "gsmrz3":
+
+ if gsmBox2Status <> 0:
+ FuncTest(sipCall, "localhost", "Box2", "132.0.0.3","405")
+ 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" and sipGateSeverStatus <> 0:
+ FuncTest(sipCall, "localhost", landlnRec, "localhost",landlnNum)
+
+ if callTo == "localsip" and sipLocalSeverStatus <> 0:
+ FuncTest(sipCall, "localhost", localSipRec, "localhost","405")
+
+ if callTo == "externalgsm":
+ FuncTest(sipCall, "localhost", o2Rec, "localhost","405")
+ FuncTest(sipCall, "localhost", tmobileRec, "localhost","405")
+ FuncTest(sipCall, "localhost", vodafoneRec, "localhost","405")
+ FuncTest(sipCall, "localhost", "xx", "localhost","405")
+
+
+
+ if callFrom =="gsmrz1":
+
+ if callTo =="sip" and sipServerStatus <> 0:
+ FuncTest("gsmcall_.py", "localhost", sipRec, "localhost",sipNum)
+ sleep(10)
+
+
+ if callTo =="gsmrz2" and gsmBox1Status <> 0:
+ FuncTest("Box1", "132.0.0.2", sipRec, "localhost",sipNum)
+
+ if callTo =="gsmrz3" and gsmBox2Status <> 0:
+ FuncTest("Box2", "132.0.0.3", sipRec, "localhost",sipNum)
+
+
+
+
+# will exit if DB connection failed
+else:
+ sys.exit(5)
+
diff --git a/For Weekly Test/15-07-2011/LandlineCall.py b/For Weekly Test/15-07-2011/LandlineCall.py
new file mode 100644
index 0000000..a0b96e5
--- /dev/null
+++ b/For Weekly Test/15-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(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/15-07-2011/LandlineReceiver.py b/For Weekly Test/15-07-2011/LandlineReceiver.py
new file mode 100644
index 0000000..607f56d
--- /dev/null
+++ b/For Weekly Test/15-07-2011/LandlineReceiver.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.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/15-07-2011/classClient.py b/For Weekly Test/15-07-2011/classClient.py
new file mode 100644
index 0000000..ce02d19
--- /dev/null
+++ b/For Weekly Test/15-07-2011/classClient.py
@@ -0,0 +1,66 @@
+import socket
+import sys
+import os
+import string
+
+class Connection:
+ def __init__(self, h, p):
+ self.host = h
+ self.port = p
+ self.s = None
+ self.connected = 0
+
+ def connect(self):
+ self.s = None
+
+ alive = self.ping()
+ if alive == 0:
+ return 'The machine is not alive'
+ for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM):
+ af, socktype, proto, canonname, sa = res
+ try:
+ self.s = socket.socket(af, socktype, proto)
+ self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) #this resolves the bug with live packets
+ except socket.error, msg:
+ self.s = None
+ self.connected = 0
+ continue
+ try:
+ self.s.connect(sa)
+ except socket.error, msg:
+ self.s.close()
+ self.connected = 0
+ self.s = None
+ continue
+ break
+ if self.s is None:
+ self.connected = 0
+ return 'Could not open socket'
+ else:
+ self.connected = 1
+ return 'Connected'
+
+ def sendData(self, data):
+ if self.connected == 1:
+ self.s.send(data)
+
+ def receiveData(self):
+ if self.connected == 1:
+ return self.s.recv(1024)
+ else:
+ return 'Not connected'
+
+ def closeConnection(self):
+ if self.connected == 1:
+ self.s.close()
+ self.connected = 0
+ return 'Closed'
+
+ def ping(self):
+ ping_cmd = os.popen('ping '+ self.host + ' -c 1 -W 1').read()
+ pingAlive = int(string.find(ping_cmd, '1 received'))
+ if pingAlive != -1:
+ return 1
+ else:
+ return 0
+
diff --git a/For Weekly Test/15-07-2011/classClient.pyc b/For Weekly Test/15-07-2011/classClient.pyc
new file mode 100644
index 0000000..b93c110
--- /dev/null
+++ b/For Weekly Test/15-07-2011/classClient.pyc
Binary files differ
diff --git a/For Weekly Test/15-07-2011/classDb.py b/For Weekly Test/15-07-2011/classDb.py
new file mode 100644
index 0000000..615b868
--- /dev/null
+++ b/For Weekly Test/15-07-2011/classDb.py
@@ -0,0 +1,212 @@
+import MySQLdb
+import string
+
+class DBMySQLConnection:
+ def __init__(self, username, password, host, dbname):
+ #initialize at the start all the user parameters
+ self.usern = username
+ self.passw = password
+ self.host = host
+ self.db = dbname
+ self.connectionCreated = 0
+ self.tasksList = list()
+ global debugMode
+ debugMode = 0
+
+ def connectDB(self):
+ try:
+ #try the connection
+ self.datBaseConn=MySQLdb.connect(self.host,self.usern, self.passw,self.db)
+ self.datBaseConn.paramstyle = 'format'
+ self.cur = self.datBaseConn.cursor() #make the cursor, used for sending queries
+ self.connectionCreated = 1 #use it as an indicator that the connection was created
+ return 1
+
+ except MySQLdb.Error, e:
+ #if we have an error then try to catch it
+ error=str(e)
+ if error[1:5] == '1045':
+ #wrong username or password
+ return 0
+ elif error[1:5] == '2002':
+ #can't connect to mysql, mysql shutdown or wrong host
+ return 2
+ else:
+ if debugMode == 1:
+ print error
+ return 3
+
+ def closeDBConn(self):
+ #close the connection to the database here
+ if self.connectionCreated == 1:
+ try:
+ #close the cursor and then the connection to the DB
+ self.cur.close()
+ self.datBaseConn.close()
+ return 1
+ except MySQLdb.Error, e:
+ #in case of an error
+ if debugMode == 1:
+ error = str(e)
+ print error
+ return 3
+ else:
+ #I never really had a connection
+ return 0
+
+ def anyTasksToDo(self):
+ #see are there any jobs to be executed and make a list out of it
+ if self.connectionCreated == 1:
+ try:
+ self.cur.execute("SELECT * FROM TempTaskTable")
+ output = self.cur.fetchall() #get the mysql response
+ #parse the output from the mysql by creating a list
+ #with lists where each attribue(column) gets independent
+ #element of the list
+ for record in output:
+ columns = list()
+ for entry in record:
+ columns.append(str(entry))
+ self.tasksList.append(columns)
+ return 1
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1146':
+ return 2 #the table doesn't exist
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def cleanTasksList(self):
+ if self.connectionCreated == 1:
+ del self.tasksList[:]
+ return 1
+ else:
+ return 0
+
+ def removeTaskFromList(self, taskID):
+ #remove only one task from the task list
+ if self.connectionCreated == 1:
+ for index in range(len(self.tasksList)):
+ item = self.tasksList[index]
+ if item[0] == str(taskID):
+ #self.tasksList.remove(index)
+ #print 'found it'
+ del self.tasksList[index]
+ return 1 #deleted taskID
+
+ return 2 #didn't find that taskID
+ else:
+ return 0
+
+ def deviceAddress(self,deviceName):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("SELECT `deviceIP` FROM DeviceAddress where `deviceName`=%s", deviceName)
+ #self.cur.execute()
+ output = self.cur.fetchall() #get the mysql response
+ #parse the output from the mysql by creating a list
+ #with lists where each attribue(column) gets independent
+ #element of the list
+ deviceAddr = ''
+ for record in output:
+ columns = list()
+ for entry in record:
+ deviceAddr = str(entry)
+ return deviceAddr
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1146':
+ return 2 #the table doesn't exist
+ if debugMode == 1:
+ print str(e)
+ return 3 #some error happened
+ else:
+ return 0 #I am not connected
+
+ def updateTaskResult(self, taskID, status):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("UPDATE TaskTable SET status=%i WHERE taskID=%i"%(int(status), int(taskID)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 0:
+ return 1 #update successful
+ else:
+ return 4 #taskID doesn't exist
+
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def updatePingResult(self, taskNo, sipServer, sipGate, sipLoc, gsmBox1, gsmBox2):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("UPDATE PingResultTable SET sipServer=%i, sipGate=%i, sipLoc=%i, gsmBox1=%i, gsmBox2=%i WHERE taskNo=%i"%(int(sipServer), int(sipGate), int(sipLoc), int(gsmBox1), int(gsmBox2), int(taskNo)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 0:
+ return 1 #ping table updated
+ else:
+ return 4 #the taskNo didn't exist
+
+
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def deleteTempTask(self, taskID):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("DELETE FROM TempTaskTable WHERE taskID=%i"%(int(taskID)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+
+ if successful == 1:
+ return 1 #deleted it
+ else:
+ return 4 #that taskID didn't exist or something else
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+
+ else:
+ return 0
+
+ def addResult(self, taskID, result):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("INSERT INTO ResultTable(taskID, result) VALUES ('%i', '%i')"%(int(taskID), int(result)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 1:
+ return 1 #successfully added the result
+ else:
+ return 4 #hmmm
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1062':
+ return 2 #duplicate entry for the key
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
diff --git a/For Weekly Test/15-07-2011/classDb.pyc b/For Weekly Test/15-07-2011/classDb.pyc
new file mode 100644
index 0000000..92d31c6
--- /dev/null
+++ b/For Weekly Test/15-07-2011/classDb.pyc
Binary files differ
diff --git a/For Weekly Test/15-07-2011/classPing.py b/For Weekly Test/15-07-2011/classPing.py
new file mode 100644
index 0000000..e13b32b
--- /dev/null
+++ b/For Weekly Test/15-07-2011/classPing.py
@@ -0,0 +1,28 @@
+import subprocess
+import string
+
+class Ping:
+
+ def __init__(self, pingAddress):
+ self.pingAddress = pingAddress
+
+ def ping(self,numberTries):
+ tried = 1
+ while numberTries >= tried:
+ tried += 1
+ #the parameter c 1 means only one ping to be sent, parameter W 3 means how many seconds the time out should be, 3 seconds
+ ping_cmd = subprocess.Popen(['ping', self.pingAddress, '-c', '1', '-W', '2'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
+
+ pingAlive = int(string.find(ping_cmd, '1 received'))
+ unknownHost = int(string.find(ping_cmd, 'unknown host'))
+
+
+ if pingAlive != -1:
+ break
+
+ if unknownHost != -1:
+ return 2 #unknown host
+ if pingAlive != -1:
+ return 1 #ping works fine
+ else:
+ return 0 #no ping response
diff --git a/For Weekly Test/15-07-2011/classPing.pyc b/For Weekly Test/15-07-2011/classPing.pyc
new file mode 100644
index 0000000..cab2db5
--- /dev/null
+++ b/For Weekly Test/15-07-2011/classPing.pyc
Binary files differ
diff --git a/For Weekly Test/15-07-2011/classServer.py b/For Weekly Test/15-07-2011/classServer.py
new file mode 100644
index 0000000..97a398d
--- /dev/null
+++ b/For Weekly Test/15-07-2011/classServer.py
@@ -0,0 +1,94 @@
+# Echo server program
+import socket
+import sys
+import os
+import string
+from time import sleep
+
+class ServerHandler:
+
+ def __init__(self,p):
+ self.port = p
+ self.host = None #symbolic name meaning all available interfaces
+ self.s = None
+ self.connected = 0
+ self.address = "127.0.0.1" #address of the main controller
+ self.onceConnected = 0
+ self.error = 'No error'
+
+ def openSocket(self):
+ self.error = 'No error'
+ for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC,
+ socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
+ af, socktype, proto, canonname, sa = res
+
+ try:
+ self.s = socket.socket(af, socktype, proto)
+ self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) #this resolves the bug with live packets
+ except socket.error, msg:
+ self.s = None
+ self.connected = 0
+ self.error = str(msg)
+ continue
+
+ try:
+ self.s.bind(sa)
+ self.s.listen(1)
+ except socket.error, msg:
+ self.s.close()
+ self.s = None
+ self.connected = 0
+ self.error = str(msg)
+ continue
+ break
+
+ if self.s is None:
+ self.connected = 0
+ return 0
+ else: #accept the connection
+ self.connection, self.address = self.s.accept()
+ self.connected = 1
+ self.onceConnected = 1
+ return 1
+
+ def connectedTo(self):
+ return self.address
+
+ def receiveData(self):
+ if self.connected == 1:
+ while 1:
+ data = self.connection.recv(64)
+ if not data:
+ return 'NO DATA'
+ else:
+ return data
+ else:
+ return 0
+
+ def sendData(self, data):
+ if self.connected == 1:
+ self.connection.send(data)
+ return 1
+ else:
+ return 0
+
+ def closeConnection(self):
+ if self.onceConnected == 1:
+ self.connection.close()
+ self.s.close()
+ self.s = None
+ self.connected == 0
+ return 1
+ else:
+ return 0
+
+ def killPort(self):
+ killResult = os.popen('lsof -i tcp:' + str(self.port) + ' | grep "python " | awk -F" " ' + "'{print $2}'").read()
+ killResult = killResult.replace('\n','')
+ print killResult
+ if killResult!='':
+ print killResult
+ killPort = os.popen("kill -9 " + killResult).read()
+ return 1
+ return 0
+
diff --git a/For Weekly Test/15-07-2011/classServer.pyc b/For Weekly Test/15-07-2011/classServer.pyc
new file mode 100644
index 0000000..52f5085
--- /dev/null
+++ b/For Weekly Test/15-07-2011/classServer.pyc
Binary files differ
diff --git a/For Weekly Test/15-07-2011/gsmcall2_.py b/For Weekly Test/15-07-2011/gsmcall2_.py
new file mode 100644
index 0000000..bf8e662
--- /dev/null
+++ b/For Weekly Test/15-07-2011/gsmcall2_.py
@@ -0,0 +1,102 @@
+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/15-07-2011/gsmcall_.py b/For Weekly Test/15-07-2011/gsmcall_.py
new file mode 100644
index 0000000..55c599e
--- /dev/null
+++ b/For Weekly Test/15-07-2011/gsmcall_.py
@@ -0,0 +1,105 @@
+import sys
+import socket
+import time
+
+import subprocess
+import os
+from serial import *
+
+import classServer
+
+from time import sleep
+import string
+
+
+stop ="false"
+success = "failed"
+
+global server
+
+global ser
+portAddress = '/dev/ttyACM0'
+portName = portAddress[-4:]
+portExist = os.popen('dmesg | grep ' + portName).read()
+
+if portExist == '':
+ print 'The serial port does not exist'
+ sys.exit()
+
+
+
+while stop <> "true":#???
+
+
+ try:
+
+ 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 "Controller status: ", server.connected
+
+
+ while stop <> "true":
+ 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()
+
+ #num = "929"
+ if num <> "NO DATA":
+ server.closeConnection()
+
+ ser = Serial(
+ port=portAddress,
+ baudrate=19200,
+ bytesize=EIGHTBITS,
+ parity=PARITY_NONE,
+ stopbits=STOPBITS_ONE)
+
+ ser.close()
+ ser.open()
+
+ ser.write('ATD4661' + num + ';\r')
+ sleep(3)
+ ser.write('AT+CHUP\r')
+
+ ser.close()
+ tried = server.openSocket()
+ sleep(2)
+ success = "success"
+ server.sendData(success)
+
+ 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
+
+
+ server.closeConnection()
+ del server
+ print "Goodbye"
+ sleep(3)
+ sys.exit(1)
+
+ except ValueError:
+ print "Exception: " + str(e)
+
+print "Goodbye"
+sleep(3)
diff --git a/For Weekly Test/15-07-2011/gsmincom_.py b/For Weekly Test/15-07-2011/gsmincom_.py
new file mode 100644
index 0000000..413db25
--- /dev/null
+++ b/For Weekly Test/15-07-2011/gsmincom_.py
@@ -0,0 +1,134 @@
+
+import atexit
+import signal
+
+import sys
+import socket
+import time
+import os
+import string
+import classServer
+from time import sleep
+from serial import *
+
+
+success = None
+stop = False
+
+try:
+
+ global ser
+ global server
+ portAddress = '/dev/ttyUSB0'
+ portName = portAddress[-4:]
+ portExist = os.popen('dmesg | grep ' + portName).read()
+
+ if portExist == '':
+ print 'The serial port does not exist'
+ sys.exit()
+
+
+
+ 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('ready')
+ server.closeConnection()
+
+ ser = Serial(
+ port=portAddress,
+ baudrate=19200,
+ bytesize=EIGHTBITS,
+ parity=PARITY_NONE,
+ stopbits=STOPBITS_ONE)
+
+ ser.close()
+ ser.open()
+
+ signalQuality = ser.write('AT+CSQ\r')
+ print "signal Quality ", signalQuality
+ print ""
+
+
+
+ while stop <> True:
+
+ global pickUp
+ pickUp = None
+ buffer = ""
+
+
+ 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
+ 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
+
+ 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 line =="RING" or lines =="RING":
+
+ print "Somebody calling"
+ print ""
+ sleep(1)
+ ser.write('ATA\r')
+
+
+ print "I will hangup the call"
+ print ""
+ sleep(1)
+
+ ser.write('AT+CHUP\r')
+ pickUp = 0
+ ser.close()
+
+ print "here I am"
+ tried = server.openSocket()
+
+ sleep(1)
+ server.sendData('success')
+ stop = True
+ sleep (5)
+ break
+
+
+
+ server.closeConnection()
+ del server
+ else:
+
+ print "not connected"
+
+ del server
+
+ ser.close()
+except ValueError:
+ print "Exception: "
+ server.closeConnection()
+ del server
+
+print "GOODBYE"
+sleep(5)
diff --git a/For Weekly Test/15-07-2011/localsipReceiver.py b/For Weekly Test/15-07-2011/localsipReceiver.py
new file mode 100644
index 0000000..96f058f
--- /dev/null
+++ b/For Weekly Test/15-07-2011/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
diff --git a/For Weekly Test/15-07-2011/sipCall.py b/For Weekly Test/15-07-2011/sipCall.py
new file mode 100644
index 0000000..0dbc133
--- /dev/null
+++ b/For Weekly Test/15-07-2011/sipCall.py
@@ -0,0 +1,180 @@
+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"
+
+
+# Callback to receive events from account
+class MyAccountCallback(pj.AccountCallback):
+
+ def __init__(self, account=None):
+ pj.AccountCallback.__init__(self, account)
+
+ # Notification on incoming 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().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
+
+ if self.call.info().state == pj.CallState.DISCONNECTED:
+ current_call = None
+ print 'Current call Disconnected'
+
+
+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
+
+
+
+
+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()
+
+ # 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())
+
+
+ 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
+ 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
+ print num
+ server.closeConnection()
+ tried = server.openSocket()
+ 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"
+ break
+
+ except ValueError:
+ print "error when sending message"
+ server.closeConnection()
+ del server
+
+ server.closeConnection()
+ del server
+
+ else:
+ Regis_status= "Bad"
+ print "error when register"
+
+ lib.destroy()
+ lib = None
+ acc = None
+
+
+ server.closeConnection()
+ del server
+ except ValueError:
+ print "Exception: " + str(e)
+
+print "Goodbye"
+sleep(3)
+acc.delete()
+lib.destroy()
+server.closeConnection()
+del server
+lib = None
+acc = None
+
diff --git a/For Weekly Test/15-07-2011/sipReceiver.py b/For Weekly Test/15-07-2011/sipReceiver.py
new file mode 100644
index 0000000..6404f10
--- /dev/null
+++ b/For Weekly Test/15-07-2011/sipReceiver.py
@@ -0,0 +1,177 @@
+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"
+
+
+# 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
+
+ # 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')
+
+ print "Media is now active"
+
+
+ else:
+ print "Media is inactive"
+
+
+
+lib = pj.Lib()
+
+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))
+
+
+ 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()
+
+
+ # 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:
+
+ 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()#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
+ 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
+
+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/Controller.py b/For Weekly Test/20-07-2011/Controller.py
new file mode 100644
index 0000000..9851425
--- /dev/null
+++ b/For Weekly Test/20-07-2011/Controller.py
@@ -0,0 +1,185 @@
+import sys
+import os
+import time
+import MySQLdb
+import subprocess
+
+
+import classClient #import class socket
+import classDb #import class db
+import classPing
+import classController
+from time import sleep
+
+
+
+sipNum = "4661929"
+landlnNum = "076145875681"
+unisipNum = "076120397897"
+
+
+sipCall = "sipCall.py"
+sipRec = "sipReceiver.py"
+landlnCall = "landlineCall.py"
+landlnRec = "landlineReceiver.py"
+localSipRec = "localsipReceiver.py"
+rz1Call = "rz1Call.py"
+rz1Rec = "rz1Receiver.py"
+
+o2Call = "o2Call.py"
+o2Rec = "o2Receiver.py"
+vodafoneCall = "vodafoneCall.py"
+vodafoneRec = "vodafoneReceiver.py"
+tmobileCall = "tmobileCall.py"
+tmobilRec = "tmobileReceiver.py"
+
+# One function for all test case
+
+
+
+
+
+# Main software
+
+# Check DB connection
+db = classDb.DBMySQLConnection('root', 'randompasswordSQL', 'localhost', 'gsmselftesting')
+print "Connecting to DB ", db.connectDB()
+print ""
+dbStatus = db.connectDB()
+
+
+if dbStatus == 1:
+
+ # Check Ping to the Every Handler
+ sipServer = classPing.Ping('132.230.4.8')
+ sipServerStatus = sipServer.ping(3)
+
+ sipGateServer = classPing.Ping('sipgate.de')
+ sipGateServerStatus = sipGateServer.ping(3)
+
+ sipLocalServer = classPing.Ping('132.230.4.60')
+ sipLocalServerStatus = sipLocalServer.ping(3)
+
+# Fetch The task information from DB
+ print "do i have anything to do", db.anyTasksToDo()
+ #x = ()
+
+ for item in db.tasksList:
+
+ taskID = item[0]
+ callFrom = item[1]
+ callTo = item[2]
+
+ print "Test ID : " , taskID
+ print "Caller : " , callFrom
+ print "Receiver : " , callTo
+
+ if callFrom == "sip":
+ if sipServerStatus == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+
+ if callTo == "gsmrz1":
+
+ x = classController.test(sipCall, "localhost", "gsmincom_.py", "localhost","4661473")
+ x.FuncTest()
+ print "Finish test"
+ 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
+ # waiting db class for repeat test from refik which I ask for.
+ update
+
+ if callTo == "gsmrz2":
+
+ if gsmBox1Status == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ x.FuncTest(sipCall, "localhost", "Box1", "132.0.0.2","404")
+ 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 == "gsmrz3":
+
+ if gsmBox2Status == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ x.FuncTest(sipCall, "localhost", "Box2", "132.0.0.3","405")
+ 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:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ x.FuncTest(sipCall, "localhost", landlnRec, "localhost",landlnNum)
+ db.addResult(taskID, testResult)
+
+ if callTo == "localsip":
+ if sipLocalSeverStatus == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ x.FuncTest(sipCall, "localhost", localSipRec, "localhost",unisipNum)
+ db.addResult(taskID, testResult)
+
+ if callTo == "externalgsm":
+ x.FuncTest(sipCall, "localhost", o2Rec, "localhost","405")
+ db.addResult(taskID, testResult)
+
+ x.FuncTest(sipCall, "localhost", tmobileRec, "localhost","405")
+ db.addResult(taskID, testResult)
+
+ x.FuncTest(sipCall, "localhost", vodafoneRec, "localhost","405")
+ db.addResult(taskID, testResult)
+
+ x.FuncTest(sipCall, "localhost", "xx", "localhost","405")
+ db.addResult(taskID, testResult)
+
+
+
+ if callFrom =="gsmrz1":
+
+ if callTo =="sip":
+ if sipServerStatus == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ x.FuncTest("gsmcall_.py", "localhost", sipRec, "localhost",sipNum)
+ db.addResult(taskID, testResult)
+ sleep(10)
+
+
+ if callTo =="gsmrz2":
+ if gsmBox1Status == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ x.FuncTest("Box1", "132.0.0.2", sipRec, "localhost",sipNum)
+ db.addResult(taskID, testResult)
+
+ if callTo =="gsmrz3":
+ if gsmBox2Status == 0:
+ print "[failed] 500 Server Internal Error"
+
+ else:
+ x.FuncTest("Box2", "132.0.0.3", sipRec, "localhost",sipNum)
+ db.addResult(taskID, testResult)
+
+
+
+
+# will exit if DB connection failed
+else:
+ sys.exit(5)
+
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..a0b96e5
--- /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(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
new file mode 100644
index 0000000..607f56d
--- /dev/null
+++ b/For Weekly Test/20-07-2011/LandlineReceiver.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.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/classClient.py b/For Weekly Test/20-07-2011/classClient.py
new file mode 100644
index 0000000..625e48e
--- /dev/null
+++ b/For Weekly Test/20-07-2011/classClient.py
@@ -0,0 +1,74 @@
+import socket
+import sys
+import os
+import string
+
+class Connection:
+ def __init__(self, h, p):
+ self.host = h
+ self.port = p
+ self.s = None
+ self.connected = 0
+
+ def connect(self):
+ self.s = None
+
+ alive = self.ping()
+ if alive == 0:
+ return 'The machine is not alive'
+ for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM):
+ af, socktype, proto, canonname, sa = res
+ try:
+ self.s = socket.socket(af, socktype, proto)
+ self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) #this resolves the bug with live packets
+ except socket.error, msg:
+ self.s = None
+ self.connected = 0
+ continue
+ try:
+ self.s.connect(sa)
+ except socket.error, msg:
+ self.s.close()
+ self.connected = 0
+ self.s = None
+ continue
+ break
+ if self.s is None:
+ self.connected = 0
+ return 'Could not open socket'
+ else:
+ self.connected = 1
+ return 'Connected'
+
+ def sendData(self, data):
+ if self.connected == 1:
+ self.s.send(data)
+
+ def receiveData(self):
+ if self.connected == 1:
+ return self.s.recv(1024)
+ else:
+ return 'Not connected'
+
+ def closeConnection(self):
+ if self.connected == 1:
+ self.s.close()
+ self.connected = 0
+ return 'Closed'
+
+ def ping(self):
+ ping_cmd = os.popen('ping '+ self.host + ' -c 1 -W 1').read()
+ pingAlive = int(string.find(ping_cmd, '1 received'))
+ if pingAlive != -1:
+ return 1
+ 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
new file mode 100644
index 0000000..85f1aa7
--- /dev/null
+++ 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
new file mode 100644
index 0000000..a3e98ff
--- /dev/null
+++ b/For Weekly Test/20-07-2011/classController.py
@@ -0,0 +1,267 @@
+import sys
+import os
+import time
+import MySQLdb
+import subprocess
+import signal
+
+import classClient
+import classDb
+import classPing
+
+from time import sleep
+
+class TimeoutException(Exception):
+ pass
+
+class test:
+
+ def __init__(self, orig, origAdd, dest, destAdd, destNo):
+ self.orig = orig
+ self.origAdd = origAdd
+ self.dest = dest
+ self.destAdd = destAdd
+ self.destNo = destNo
+ self.repeatTest = None
+ self.portOrig = None
+ self.resultOrig = None
+ self.resultDest = None
+ self.testResult = None
+ self.x = None
+ self.y = None
+
+ def FuncTest(self):
+
+ def timeout_handler(signum, frame):
+ raise TimeoutException()
+
+ print "====================== Preparing Test ======================"
+
+ try:
+
+ if self.dest =="gsmBox1" or self.dest =="gsmBox2":
+
+ if self.dest =="gsmBox1":
+ portOrig = 50095
+
+ if self.dest =="gsmBox2":
+ portOrig = 50096
+
+ print ""
+ print "Connecting to Caller handler"
+ print "Caller handler status :", x.connect()
+ x.sendData('hello server please wakeup the handler and be caller')
+
+ else:
+ # open SIP caller handler
+
+ command="--command=python " +self.orig
+ subprocess.Popen(args=["gnome-terminal", command])
+
+ sleep(5)
+
+ if self.orig=="sipCall.py":
+ self.portOrig = 50097
+
+ if self.orig=="rz1Call.py":
+ self.portOrig = 50098
+
+ if self.orig == "landlineCall.py":
+ self.portOrig = 50099
+
+ if self.orig == "LocalSIPCall.py":
+ self.portOrig = 50100
+
+ #else: #mean external GSM
+ # print "have not yet define"
+ #portOrig = 50101
+
+ x = classClient.Connection(self.origAdd,self.portOrig)
+ print ""
+ print "Connecting to Caller handler", self.origAdd,self.portOrig
+ print "Caller handler status:", x.connect()
+
+ x.sendData('hello Handler')
+
+ # wait respond from origin handler
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(60)
+ while 1:
+ try:
+ origHandler = x.receiveData()
+ if origHandler <> "":
+ break
+
+ except TimeoutException:
+ origHandler = "failed"
+ break
+
+
+ if origHandler == "ready":
+ print "Caller handler : Ready"
+ print ""
+ try:
+
+ global portDest
+
+ if self.dest =="gsmBox1" or self.dest =="gsmBox2":
+
+ if self.dest =="gsmBox1":
+ self.portDest = 50102
+
+ if self.dest =="gsmBox2":
+ self.portDest = 50103
+
+ y = classClient.Connection(destAdd,portDest)
+ print "Connecting to Receiver handler"
+ print "Receiver handler status: ", y.connect()
+ y.sendData('hello server please wakeup the handler and be receiver')
+
+ else:
+ command="--command=python " +self.dest
+ subprocess.Popen(args=["gnome-terminal", command])
+
+ sleep(2)
+
+ if self.dest=="SIPReceiver.py":
+ self.portDest = 50104
+
+ if self.dest=="rz1Receiver.py":
+ self.portDest = 50105
+
+ if self.dest == "landlineReceiver.py":
+ self.portDest = 50106
+
+ if self.dest == "LocalSIPReceiver.py":
+ self.portDest = 50107
+
+ #mean external GSM
+ #print "not define yet"
+ #portDest = 50108
+
+ y = classClient.Connection(self.destAdd,portDest)
+ print "Connecting to Receiver handler"
+ print "Receiver handler status:", y.connect()
+ y.sendData('hello Receiver')
+
+
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(60)
+
+ while 1:
+ try:
+ destHandler = y.receiveData()
+ if destHandler <> "":
+ break
+
+ except TimeoutException:
+ destHandler = "failed"
+ break
+
+ if destHandler == "ready":
+
+ print "Receiver handler : Ready"
+ print ""
+ x.sendData("start")#send message to handler to start the call
+ sleep(0.5)
+ x.sendData(self.destNo)
+
+ x.closeConnection()
+ x.connect()
+
+ y.closeConnection()
+ y.connect()
+
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(120)
+
+ print "------------ Test Result ------------"
+ print ""
+
+ while 1:
+ try:
+ sleep(0.5)
+ resultOrig = x.receiveData()
+ resultDest = y.receiveData()
+
+ if resultOrig <> "" or resultDest <> "":
+ break
+
+ except TimeoutException:
+ resultOrig = 486
+ resultDest = 486
+ break
+
+ #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.closeConnection()
+ x.connect()
+
+ y.closeConnection()
+ y.connect()
+
+ signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(120)
+
+ while 1:
+ try:
+ sleep(0.5)
+ resultOrig = x.receiveData()
+ resultDest = y.receiveData()
+
+ if resultOrig <> "" or resultDest <> "":
+ break
+
+ except TimeoutException:
+ resultOrig = 486
+ resultDest = 486
+ break
+
+ #if still failed, we make automatic test vice versa
+
+ if resultOrig == 486 or resultDest == 486:
+ testResult = 486
+ repeatTest = True
+ print "Second test result origin: ", resultOrig
+ print "Second test result Destination: ", resultDest
+ else:
+ testResult = 200
+ print "Second test result origin: ", resultOrig
+ print "Second test result Destination: ", resultDest
+ x.sendData('487')
+ y.sendData('487')
+
+ else:
+
+ testResult = 200
+ print "Test Result origin: ", resultOrig
+ print "Test Result Destination: ", resultDest
+ x.sendData('487')
+ y.sendData('487')
+
+ else:
+ testResult = 604
+ print "604 General Handler Error: Destination handler no respond"
+ #tell Caller handler to terminate because receiver doesnt work
+ x.sendData('487')
+
+ y.closeConnection()
+
+ except ValueError:
+ print "601 General Handler Error: Could not open Destination handler"
+ testResult = "601"
+ else:
+ testResult = 605
+ print "605 General Handler Error: Origin handler no respond"
+
+ x.closeConnection()
+
+ except ValueError:
+ testResult = 602
+ print "602 General Handler Error: Could not open Origin handler"
+
diff --git a/For Weekly Test/20-07-2011/classController.pyc b/For Weekly Test/20-07-2011/classController.pyc
new file mode 100644
index 0000000..7364fa7
--- /dev/null
+++ b/For Weekly Test/20-07-2011/classController.pyc
Binary files differ
diff --git a/For Weekly Test/20-07-2011/classDb.py b/For Weekly Test/20-07-2011/classDb.py
new file mode 100644
index 0000000..615b868
--- /dev/null
+++ b/For Weekly Test/20-07-2011/classDb.py
@@ -0,0 +1,212 @@
+import MySQLdb
+import string
+
+class DBMySQLConnection:
+ def __init__(self, username, password, host, dbname):
+ #initialize at the start all the user parameters
+ self.usern = username
+ self.passw = password
+ self.host = host
+ self.db = dbname
+ self.connectionCreated = 0
+ self.tasksList = list()
+ global debugMode
+ debugMode = 0
+
+ def connectDB(self):
+ try:
+ #try the connection
+ self.datBaseConn=MySQLdb.connect(self.host,self.usern, self.passw,self.db)
+ self.datBaseConn.paramstyle = 'format'
+ self.cur = self.datBaseConn.cursor() #make the cursor, used for sending queries
+ self.connectionCreated = 1 #use it as an indicator that the connection was created
+ return 1
+
+ except MySQLdb.Error, e:
+ #if we have an error then try to catch it
+ error=str(e)
+ if error[1:5] == '1045':
+ #wrong username or password
+ return 0
+ elif error[1:5] == '2002':
+ #can't connect to mysql, mysql shutdown or wrong host
+ return 2
+ else:
+ if debugMode == 1:
+ print error
+ return 3
+
+ def closeDBConn(self):
+ #close the connection to the database here
+ if self.connectionCreated == 1:
+ try:
+ #close the cursor and then the connection to the DB
+ self.cur.close()
+ self.datBaseConn.close()
+ return 1
+ except MySQLdb.Error, e:
+ #in case of an error
+ if debugMode == 1:
+ error = str(e)
+ print error
+ return 3
+ else:
+ #I never really had a connection
+ return 0
+
+ def anyTasksToDo(self):
+ #see are there any jobs to be executed and make a list out of it
+ if self.connectionCreated == 1:
+ try:
+ self.cur.execute("SELECT * FROM TempTaskTable")
+ output = self.cur.fetchall() #get the mysql response
+ #parse the output from the mysql by creating a list
+ #with lists where each attribue(column) gets independent
+ #element of the list
+ for record in output:
+ columns = list()
+ for entry in record:
+ columns.append(str(entry))
+ self.tasksList.append(columns)
+ return 1
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1146':
+ return 2 #the table doesn't exist
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def cleanTasksList(self):
+ if self.connectionCreated == 1:
+ del self.tasksList[:]
+ return 1
+ else:
+ return 0
+
+ def removeTaskFromList(self, taskID):
+ #remove only one task from the task list
+ if self.connectionCreated == 1:
+ for index in range(len(self.tasksList)):
+ item = self.tasksList[index]
+ if item[0] == str(taskID):
+ #self.tasksList.remove(index)
+ #print 'found it'
+ del self.tasksList[index]
+ return 1 #deleted taskID
+
+ return 2 #didn't find that taskID
+ else:
+ return 0
+
+ def deviceAddress(self,deviceName):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("SELECT `deviceIP` FROM DeviceAddress where `deviceName`=%s", deviceName)
+ #self.cur.execute()
+ output = self.cur.fetchall() #get the mysql response
+ #parse the output from the mysql by creating a list
+ #with lists where each attribue(column) gets independent
+ #element of the list
+ deviceAddr = ''
+ for record in output:
+ columns = list()
+ for entry in record:
+ deviceAddr = str(entry)
+ return deviceAddr
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1146':
+ return 2 #the table doesn't exist
+ if debugMode == 1:
+ print str(e)
+ return 3 #some error happened
+ else:
+ return 0 #I am not connected
+
+ def updateTaskResult(self, taskID, status):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("UPDATE TaskTable SET status=%i WHERE taskID=%i"%(int(status), int(taskID)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 0:
+ return 1 #update successful
+ else:
+ return 4 #taskID doesn't exist
+
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def updatePingResult(self, taskNo, sipServer, sipGate, sipLoc, gsmBox1, gsmBox2):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("UPDATE PingResultTable SET sipServer=%i, sipGate=%i, sipLoc=%i, gsmBox1=%i, gsmBox2=%i WHERE taskNo=%i"%(int(sipServer), int(sipGate), int(sipLoc), int(gsmBox1), int(gsmBox2), int(taskNo)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 0:
+ return 1 #ping table updated
+ else:
+ return 4 #the taskNo didn't exist
+
+
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
+ def deleteTempTask(self, taskID):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("DELETE FROM TempTaskTable WHERE taskID=%i"%(int(taskID)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+
+ if successful == 1:
+ return 1 #deleted it
+ else:
+ return 4 #that taskID didn't exist or something else
+ except MySQLdb.Error, e:
+ if debugMode == 1:
+ print str(e)
+ return 3
+
+ else:
+ return 0
+
+ def addResult(self, taskID, result):
+ if self.connectionCreated == 1:
+ try:
+ successful = self.cur.execute("INSERT INTO ResultTable(taskID, result) VALUES ('%i', '%i')"%(int(taskID), int(result)))
+ output = self.cur.fetchone()
+
+ if debugMode == 1:
+ print output
+ if successful == 1:
+ return 1 #successfully added the result
+ else:
+ return 4 #hmmm
+ except MySQLdb.Error, e:
+ error = str(e)
+ if error[1:5] == '1062':
+ return 2 #duplicate entry for the key
+ if debugMode == 1:
+ print str(e)
+ return 3
+ else:
+ return 0
+
diff --git a/For Weekly Test/20-07-2011/classDb.pyc b/For Weekly Test/20-07-2011/classDb.pyc
new file mode 100644
index 0000000..8bf4d7c
--- /dev/null
+++ b/For Weekly Test/20-07-2011/classDb.pyc
Binary files differ
diff --git a/For Weekly Test/20-07-2011/classPing.py b/For Weekly Test/20-07-2011/classPing.py
new file mode 100644
index 0000000..e13b32b
--- /dev/null
+++ b/For Weekly Test/20-07-2011/classPing.py
@@ -0,0 +1,28 @@
+import subprocess
+import string
+
+class Ping:
+
+ def __init__(self, pingAddress):
+ self.pingAddress = pingAddress
+
+ def ping(self,numberTries):
+ tried = 1
+ while numberTries >= tried:
+ tried += 1
+ #the parameter c 1 means only one ping to be sent, parameter W 3 means how many seconds the time out should be, 3 seconds
+ ping_cmd = subprocess.Popen(['ping', self.pingAddress, '-c', '1', '-W', '2'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
+
+ pingAlive = int(string.find(ping_cmd, '1 received'))
+ unknownHost = int(string.find(ping_cmd, 'unknown host'))
+
+
+ if pingAlive != -1:
+ break
+
+ if unknownHost != -1:
+ return 2 #unknown host
+ if pingAlive != -1:
+ return 1 #ping works fine
+ else:
+ return 0 #no ping response
diff --git a/For Weekly Test/20-07-2011/classPing.pyc b/For Weekly Test/20-07-2011/classPing.pyc
new file mode 100644
index 0000000..b664a9c
--- /dev/null
+++ b/For Weekly Test/20-07-2011/classPing.pyc
Binary files differ
diff --git a/For Weekly Test/20-07-2011/classServer.py b/For Weekly Test/20-07-2011/classServer.py
new file mode 100644
index 0000000..97a398d
--- /dev/null
+++ b/For Weekly Test/20-07-2011/classServer.py
@@ -0,0 +1,94 @@
+# Echo server program
+import socket
+import sys
+import os
+import string
+from time import sleep
+
+class ServerHandler:
+
+ def __init__(self,p):
+ self.port = p
+ self.host = None #symbolic name meaning all available interfaces
+ self.s = None
+ self.connected = 0
+ self.address = "127.0.0.1" #address of the main controller
+ self.onceConnected = 0
+ self.error = 'No error'
+
+ def openSocket(self):
+ self.error = 'No error'
+ for res in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC,
+ socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
+ af, socktype, proto, canonname, sa = res
+
+ try:
+ self.s = socket.socket(af, socktype, proto)
+ self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) #this resolves the bug with live packets
+ except socket.error, msg:
+ self.s = None
+ self.connected = 0
+ self.error = str(msg)
+ continue
+
+ try:
+ self.s.bind(sa)
+ self.s.listen(1)
+ except socket.error, msg:
+ self.s.close()
+ self.s = None
+ self.connected = 0
+ self.error = str(msg)
+ continue
+ break
+
+ if self.s is None:
+ self.connected = 0
+ return 0
+ else: #accept the connection
+ self.connection, self.address = self.s.accept()
+ self.connected = 1
+ self.onceConnected = 1
+ return 1
+
+ def connectedTo(self):
+ return self.address
+
+ def receiveData(self):
+ if self.connected == 1:
+ while 1:
+ data = self.connection.recv(64)
+ if not data:
+ return 'NO DATA'
+ else:
+ return data
+ else:
+ return 0
+
+ def sendData(self, data):
+ if self.connected == 1:
+ self.connection.send(data)
+ return 1
+ else:
+ return 0
+
+ def closeConnection(self):
+ if self.onceConnected == 1:
+ self.connection.close()
+ self.s.close()
+ self.s = None
+ self.connected == 0
+ return 1
+ else:
+ return 0
+
+ def killPort(self):
+ killResult = os.popen('lsof -i tcp:' + str(self.port) + ' | grep "python " | awk -F" " ' + "'{print $2}'").read()
+ killResult = killResult.replace('\n','')
+ print killResult
+ if killResult!='':
+ print killResult
+ killPort = os.popen("kill -9 " + killResult).read()
+ return 1
+ return 0
+
diff --git a/For Weekly Test/20-07-2011/classServer.pyc b/For Weekly Test/20-07-2011/classServer.pyc
new file mode 100644
index 0000000..52f5085
--- /dev/null
+++ b/For Weekly Test/20-07-2011/classServer.pyc
Binary files differ
diff --git a/For Weekly Test/20-07-2011/gsmcall2_.py b/For Weekly Test/20-07-2011/gsmcall2_.py
new file mode 100644
index 0000000..bf8e662
--- /dev/null
+++ b/For Weekly Test/20-07-2011/gsmcall2_.py
@@ -0,0 +1,102 @@
+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
new file mode 100644
index 0000000..55c599e
--- /dev/null
+++ b/For Weekly Test/20-07-2011/gsmcall_.py
@@ -0,0 +1,105 @@
+import sys
+import socket
+import time
+
+import subprocess
+import os
+from serial import *
+
+import classServer
+
+from time import sleep
+import string
+
+
+stop ="false"
+success = "failed"
+
+global server
+
+global ser
+portAddress = '/dev/ttyACM0'
+portName = portAddress[-4:]
+portExist = os.popen('dmesg | grep ' + portName).read()
+
+if portExist == '':
+ print 'The serial port does not exist'
+ sys.exit()
+
+
+
+while stop <> "true":#???
+
+
+ try:
+
+ 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 "Controller status: ", server.connected
+
+
+ while stop <> "true":
+ 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()
+
+ #num = "929"
+ if num <> "NO DATA":
+ server.closeConnection()
+
+ ser = Serial(
+ port=portAddress,
+ baudrate=19200,
+ bytesize=EIGHTBITS,
+ parity=PARITY_NONE,
+ stopbits=STOPBITS_ONE)
+
+ ser.close()
+ ser.open()
+
+ ser.write('ATD4661' + num + ';\r')
+ sleep(3)
+ ser.write('AT+CHUP\r')
+
+ ser.close()
+ tried = server.openSocket()
+ sleep(2)
+ success = "success"
+ server.sendData(success)
+
+ 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
+
+
+ server.closeConnection()
+ del server
+ print "Goodbye"
+ sleep(3)
+ sys.exit(1)
+
+ except ValueError:
+ print "Exception: " + str(e)
+
+print "Goodbye"
+sleep(3)
diff --git a/For Weekly Test/20-07-2011/gsmincom_.py b/For Weekly Test/20-07-2011/gsmincom_.py
new file mode 100644
index 0000000..413db25
--- /dev/null
+++ b/For Weekly Test/20-07-2011/gsmincom_.py
@@ -0,0 +1,134 @@
+
+import atexit
+import signal
+
+import sys
+import socket
+import time
+import os
+import string
+import classServer
+from time import sleep
+from serial import *
+
+
+success = None
+stop = False
+
+try:
+
+ global ser
+ global server
+ portAddress = '/dev/ttyUSB0'
+ portName = portAddress[-4:]
+ portExist = os.popen('dmesg | grep ' + portName).read()
+
+ if portExist == '':
+ print 'The serial port does not exist'
+ sys.exit()
+
+
+
+ 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('ready')
+ server.closeConnection()
+
+ ser = Serial(
+ port=portAddress,
+ baudrate=19200,
+ bytesize=EIGHTBITS,
+ parity=PARITY_NONE,
+ stopbits=STOPBITS_ONE)
+
+ ser.close()
+ ser.open()
+
+ signalQuality = ser.write('AT+CSQ\r')
+ print "signal Quality ", signalQuality
+ print ""
+
+
+
+ while stop <> True:
+
+ global pickUp
+ pickUp = None
+ buffer = ""
+
+
+ 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
+ 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
+
+ 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 line =="RING" or lines =="RING":
+
+ print "Somebody calling"
+ print ""
+ sleep(1)
+ ser.write('ATA\r')
+
+
+ print "I will hangup the call"
+ print ""
+ sleep(1)
+
+ ser.write('AT+CHUP\r')
+ pickUp = 0
+ ser.close()
+
+ print "here I am"
+ tried = server.openSocket()
+
+ sleep(1)
+ server.sendData('success')
+ stop = True
+ sleep (5)
+ break
+
+
+
+ server.closeConnection()
+ del server
+ else:
+
+ print "not connected"
+
+ del server
+
+ ser.close()
+except ValueError:
+ print "Exception: "
+ server.closeConnection()
+ del server
+
+print "GOODBYE"
+sleep(5)
diff --git a/For Weekly Test/20-07-2011/localsipReceiver.py b/For Weekly Test/20-07-2011/localsipReceiver.py
new file mode 100644
index 0000000..96f058f
--- /dev/null
+++ b/For Weekly Test/20-07-2011/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
diff --git a/For Weekly Test/20-07-2011/sipCall.py b/For Weekly Test/20-07-2011/sipCall.py
new file mode 100644
index 0000000..0dbc133
--- /dev/null
+++ b/For Weekly Test/20-07-2011/sipCall.py
@@ -0,0 +1,180 @@
+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"
+
+
+# Callback to receive events from account
+class MyAccountCallback(pj.AccountCallback):
+
+ def __init__(self, account=None):
+ pj.AccountCallback.__init__(self, account)
+
+ # Notification on incoming 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().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
+
+ if self.call.info().state == pj.CallState.DISCONNECTED:
+ current_call = None
+ print 'Current call Disconnected'
+
+
+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
+
+
+
+
+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()
+
+ # 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())
+
+
+ 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
+ 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
+ print num
+ server.closeConnection()
+ tried = server.openSocket()
+ 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"
+ break
+
+ except ValueError:
+ print "error when sending message"
+ server.closeConnection()
+ del server
+
+ server.closeConnection()
+ del server
+
+ else:
+ Regis_status= "Bad"
+ print "error when register"
+
+ lib.destroy()
+ lib = None
+ acc = None
+
+
+ server.closeConnection()
+ del server
+ except ValueError:
+ print "Exception: " + 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/sipReceiver.py b/For Weekly Test/20-07-2011/sipReceiver.py
new file mode 100644
index 0000000..6404f10
--- /dev/null
+++ b/For Weekly Test/20-07-2011/sipReceiver.py
@@ -0,0 +1,177 @@
+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"
+
+
+# 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
+
+ # 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')
+
+ print "Media is now active"
+
+
+ else:
+ print "Media is inactive"
+
+
+
+lib = pj.Lib()
+
+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))
+
+
+ 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()
+
+
+ # 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:
+
+ 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()#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
+ 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
+
+except pj.Error, e:
+ print "Exception: " + str(e)
+ lib.destroy()
+ lib = None
+ server.closeConnection()
+ del server