summaryrefslogtreecommitdiffstats
path: root/For Weekly Test
diff options
context:
space:
mode:
authortt412011-08-02 19:31:48 +0200
committertt412011-08-02 19:31:48 +0200
commitce076521b1745c2656b1fcc6d0d31b71da5bf947 (patch)
tree24133b944f4c9ce0027757b4a3967c328b34aa4f /For Weekly Test
parentrename folder (diff)
downloadgsm-selftest-ce076521b1745c2656b1fcc6d0d31b71da5bf947.tar.gz
gsm-selftest-ce076521b1745c2656b1fcc6d0d31b71da5bf947.tar.xz
gsm-selftest-ce076521b1745c2656b1fcc6d0d31b71da5bf947.zip
rename folder
Diffstat (limited to 'For Weekly Test')
-rw-r--r--For Weekly Test/07-07-2011/Controller-SecondType.py308
-rw-r--r--For Weekly Test/07-07-2011/Controller-SecondType_withDB.py339
-rw-r--r--For Weekly Test/07-07-2011/ca_stMa.py153
-rw-r--r--For Weekly Test/07-07-2011/classClient.py66
-rw-r--r--For Weekly Test/07-07-2011/classClient.pycbin0 -> 2759 bytes
-rw-r--r--For Weekly Test/07-07-2011/classDb.py212
-rw-r--r--For Weekly Test/07-07-2011/classDb.pycbin0 -> 5926 bytes
-rw-r--r--For Weekly Test/07-07-2011/classPing.py28
-rw-r--r--For Weekly Test/07-07-2011/classServer.py94
-rw-r--r--For Weekly Test/07-07-2011/classServer.pycbin0 -> 3365 bytes
-rw-r--r--For Weekly Test/07-07-2011/gsmcall2_.py102
-rw-r--r--For Weekly Test/07-07-2011/gsmcall_.py105
-rw-r--r--For Weekly Test/07-07-2011/gsmincom_.py155
-rw-r--r--For Weekly Test/07-07-2011/sipCall.py176
-rw-r--r--For Weekly Test/07-07-2011/sipReceiver.py177
15 files changed, 1915 insertions, 0 deletions
diff --git a/For Weekly Test/07-07-2011/Controller-SecondType.py b/For Weekly Test/07-07-2011/Controller-SecondType.py
new file mode 100644
index 0000000..31df36c
--- /dev/null
+++ b/For Weekly Test/07-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/07-07-2011/Controller-SecondType_withDB.py b/For Weekly Test/07-07-2011/Controller-SecondType_withDB.py
new file mode 100644
index 0000000..a45fd05
--- /dev/null
+++ b/For Weekly Test/07-07-2011/Controller-SecondType_withDB.py
@@ -0,0 +1,339 @@
+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"
+localSipCall = "localsipCall.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 ""
+ 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()
+ 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)
+
+ #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 = PingClass.Ping('132.230.4.60')
+ sipServerStatus = sipServer.ping(3)
+
+ sipGateServer = PingClass.Ping('sipgate.de')
+ sipGateServerStatus = sipGateServer.ping(3)
+
+ sipLocalServer = PingClass.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
+
+ if callFrom == "sip" and sipServerStatus <> 0:
+
+ if callTo == "gsmrz1":
+
+ FuncTest(sipCall, "localhost", "gsmincom_.py", "localhost","4661473")
+ 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/07-07-2011/ca_stMa.py b/For Weekly Test/07-07-2011/ca_stMa.py
new file mode 100644
index 0000000..5df33c8
--- /dev/null
+++ b/For Weekly Test/07-07-2011/ca_stMa.py
@@ -0,0 +1,153 @@
+from serial import * #serial port library
+from threading import Thread #library to make a thread (I guess)
+from time import sleep #timer library
+import string #import the string handling library
+import sys
+import atexit
+import signal
+
+####START of the definition how the serial port works
+
+class TimeoutException(Exception):
+ pass
+
+def serial_portFunc():
+ def timeout_handler(signum, frame):
+ raise TimeoutException()
+
+ old_handler = signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(50) # triger alarm in 50 seconds
+
+ try:
+ global last_received #make last_received a global variable
+ global exitSuccessful
+ 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
+ #timeout=0,
+ #writeTimeout=0
+ #xonxoff=0,
+ #rtscts=0
+ #interCharTimeout=None
+ #I didn't need to set these variables :)
+ )
+ ####END of the definition how the serial port works
+ exitSuccessful = 0 #variable used to know if it closed successfully
+
+ last_received = '' #reset the last received variable
+ global pickUp
+ pickUp = 0
+ ser.write('AT\r') #just communicate with the cellphone at start
+ callTrue=0 #use this variable to make sure the cell phone has dialed a number
+ pickUp =0 #use to test if I pick up the call
+ firstCall = 1
+ firstCallSuccessful=0
+ buffer = '' #make sure buffer variable is empty
+ for arg in sys.argv:
+ callThisNumberFirst = arg
+ while True: #repeat the message accepting part forever
+
+
+ #####BEGIN part responsible for receiving on serial port
+
+ 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)
+
+ buffer = '\n'.join(lines) #add a new line to the buffer variable
+
+ last_received=last_received.split('\n') #parse the last received value with new lines
+ line = last_received[0].replace(chr(13), '') #remove \r from the first parsed value in last_received and return me a nicely parsed value :)
+ #print line;
+
+ #####END part responsible for receiving on serial port
+
+
+
+
+
+
+ #####START of the state machine responsible for talking to the cellphone
+
+ if len(line) > 0: #if line not empty then it is a value the cellphone returned
+ #print 'I received:',line, len(line)
+ if firstCall==1:
+ #print 'I AM IN THE IF :)'
+ sleep(1)
+ callThisNumberFirst = 'ATD'+callThisNumberFirst+';\r'
+ ser.write(callThisNumberFirst) #call the number from the argument
+ line=''
+
+ #sleep(5)
+ #ser.write('AT+CSQ\r') #send the command for signal strength
+ #sleep(2)
+ ##sleep(5) #sleep 2 seconds
+ #ser.write('AT+CHUP\r')
+ firstCall=0
+ firstCallSuccessful=1
+
+ if (line=='OK') and (firstCallSuccessful==1):
+ #print 'Successfully connected'
+ sleep(1)
+ ser.write('AT+CSQ\r') #send the command for signal strength
+ sleep(5)
+ #sleep(5) #sleep 2 seconds
+ sleep(1)
+ ser.write('AT+CHUP\r')
+ firstCallSuccessful=0
+ line = ''
+
+ if line=='RING': #the cellphone is ringing and somebody is calling
+ if pickUp == 0:
+ sleep(1)
+ ser.write('ATA\r') #pick up the phone call
+ sleep(0.5) #wait half a second before sending another AT command
+ sleep(1)
+ ser.write('AT+CSQ\r') #tell me the signal quality command
+ sleep(3)
+ sleep(1)
+ ser.write('AT+CHUP\r') #ask for the callers numbers
+ line=''
+ pickUp=1
+
+ if line[0:5] == '+CSQ:':
+ space = int(string.find(line,' '))+1 #find the (space) sign
+ coma = int(string.find(line,',')) #find the , (coma) sign
+ signalStrength = (int(line[space:coma])*2)-113
+ #print 'Signal strength', signalStrength, 'dBm'
+ line=''
+ if pickUp==1:
+ exitSuccessful = 1
+ return '|1|'+str(signalStrength)+'|'
+
+ if len(line) == 4:
+ if line == 'BUSY':
+ if callTrue == 1:
+ signalStr = '|0|Number was busy|'
+ return '|0|Number was busy|'
+
+ #####END of the state machine responsible for talking to the cellphone
+ except TimeoutException:
+ return "|2|Timeout"
+ finally:
+ signal.signal(signal.SIGALRM, old_handler)
+
+ signal.alarm(0)
+ return signalStr
+
+if __name__ == '__main__':
+ result = serial_portFunc()
+ print result
+
diff --git a/For Weekly Test/07-07-2011/classClient.py b/For Weekly Test/07-07-2011/classClient.py
new file mode 100644
index 0000000..ce02d19
--- /dev/null
+++ b/For Weekly Test/07-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/07-07-2011/classClient.pyc b/For Weekly Test/07-07-2011/classClient.pyc
new file mode 100644
index 0000000..b93c110
--- /dev/null
+++ b/For Weekly Test/07-07-2011/classClient.pyc
Binary files differ
diff --git a/For Weekly Test/07-07-2011/classDb.py b/For Weekly Test/07-07-2011/classDb.py
new file mode 100644
index 0000000..615b868
--- /dev/null
+++ b/For Weekly Test/07-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/07-07-2011/classDb.pyc b/For Weekly Test/07-07-2011/classDb.pyc
new file mode 100644
index 0000000..92d31c6
--- /dev/null
+++ b/For Weekly Test/07-07-2011/classDb.pyc
Binary files differ
diff --git a/For Weekly Test/07-07-2011/classPing.py b/For Weekly Test/07-07-2011/classPing.py
new file mode 100644
index 0000000..e13b32b
--- /dev/null
+++ b/For Weekly Test/07-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/07-07-2011/classServer.py b/For Weekly Test/07-07-2011/classServer.py
new file mode 100644
index 0000000..97a398d
--- /dev/null
+++ b/For Weekly Test/07-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/07-07-2011/classServer.pyc b/For Weekly Test/07-07-2011/classServer.pyc
new file mode 100644
index 0000000..52f5085
--- /dev/null
+++ b/For Weekly Test/07-07-2011/classServer.pyc
Binary files differ
diff --git a/For Weekly Test/07-07-2011/gsmcall2_.py b/For Weekly Test/07-07-2011/gsmcall2_.py
new file mode 100644
index 0000000..bf8e662
--- /dev/null
+++ b/For Weekly Test/07-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/07-07-2011/gsmcall_.py b/For Weekly Test/07-07-2011/gsmcall_.py
new file mode 100644
index 0000000..039622c
--- /dev/null
+++ b/For Weekly Test/07-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/ttyUSB1'
+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/07-07-2011/gsmincom_.py b/For Weekly Test/07-07-2011/gsmincom_.py
new file mode 100644
index 0000000..a49c24c
--- /dev/null
+++ b/For Weekly Test/07-07-2011/gsmincom_.py
@@ -0,0 +1,155 @@
+
+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.closeConection()
+
+ 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)
+
+ buffer = '\n'.join(lines) #add a new line to the buffer variable
+
+ last_received=last_received.split('\n') #parse the last received value with new lines
+ line = last_received[0].replace(chr(13), '')
+
+ print "buffer:", buffer
+ print "line:", line
+
+ if len(line) > 0:
+
+
+ if line=="RING":
+
+ print "Somebody calling"
+ print ""
+ sleep(1)
+ ser.write('ATA\r')
+ sleep(1)
+ ser.write('AT+CSQ\r')
+
+ sleep(2)
+ ser.write('AT+CLCC\r')
+
+
+ if line[0:5] == '+CSQ:':
+
+ space = int(string.find(line,' '))+1
+ coma = int(string.find(line,','))
+ signalStr = (int(line[space:coma])*2)-113
+
+ line=''
+
+ if line[0:6]=='+CLCC:':
+
+ pickUp = 1
+
+ print "I will hangup the call"
+ print ""
+ sleep(5)
+
+ ser.write('AT+CHUP\r')
+ pickUp = 0
+ ser.close()
+
+ quotation1 = int(string.find(line,'"'))+1
+ lineTemp = line[quotation1:]
+
+ quotation2 = int(string.find(lineTemp,'"'))
+ numberOfCaller = line[quotation1:quotation1+quotation2]
+
+ print "Signal Strength: ", signalStr
+ print ""
+
+ tried = server.openSocket()
+ server.sendData('I got call from :' +numberOfCaller)
+ print "with caller number", numberOfCaller
+ sleep(1)
+ server.sendData('success')
+ stop = True
+ sleep (3)
+
+
+
+ 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/07-07-2011/sipCall.py b/For Weekly Test/07-07-2011/sipCall.py
new file mode 100644
index 0000000..eb44b4a
--- /dev/null
+++ b/For Weekly Test/07-07-2011/sipCall.py
@@ -0,0 +1,176 @@
+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(5)
+ current_call.hangup()
+ 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
+ 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/07-07-2011/sipReceiver.py b/For Weekly Test/07-07-2011/sipReceiver.py
new file mode 100644
index 0000000..6404f10
--- /dev/null
+++ b/For Weekly Test/07-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