summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/07-08-2011
diff options
context:
space:
mode:
authortriatmoko2011-07-11 17:24:50 +0200
committertriatmoko2011-07-11 17:24:50 +0200
commitd839f1285ed3160bc83383e1b3c7761dad8044eb (patch)
treee582c3e2ece88ab12ab8b778aef9d0e758f23fc5 /For Weekly Test/07-08-2011
parentI forgot to make the variable connected = 0 when you call the closeConnection (diff)
downloadgsm-selftest-d839f1285ed3160bc83383e1b3c7761dad8044eb.tar.gz
gsm-selftest-d839f1285ed3160bc83383e1b3c7761dad8044eb.tar.xz
gsm-selftest-d839f1285ed3160bc83383e1b3c7761dad8044eb.zip
expand controller script.
Diffstat (limited to 'For Weekly Test/07-08-2011')
-rw-r--r--For Weekly Test/07-08-2011/Controller-SecondType.py43
-rw-r--r--For Weekly Test/07-08-2011/Controller-SecondType_withDB.py302
-rw-r--r--For Weekly Test/07-08-2011/SIPIncoming.py29
-rw-r--r--For Weekly Test/07-08-2011/classServer.py3
-rw-r--r--For Weekly Test/07-08-2011/classServer.pycbin3309 -> 3365 bytes
-rw-r--r--For Weekly Test/07-08-2011/gsmcall2_.py5
-rw-r--r--For Weekly Test/07-08-2011/gsmcall_.py72
7 files changed, 390 insertions, 64 deletions
diff --git a/For Weekly Test/07-08-2011/Controller-SecondType.py b/For Weekly Test/07-08-2011/Controller-SecondType.py
index 8ae229f..31df36c 100644
--- a/For Weekly Test/07-08-2011/Controller-SecondType.py
+++ b/For Weekly Test/07-08-2011/Controller-SecondType.py
@@ -39,9 +39,13 @@ 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 = ""
@@ -83,22 +87,22 @@ def FuncTest(orig, origAdd, dest, destAdd, destNo):
# print "have not yet define"
#portOrig = 50101
- print "port?", portOrig
- print origAdd
x = classClient.Connection(origAdd,portOrig)
- print "handler", x.connect()
+ print ""
+ print "Caller handler status:", x.connect()
+
x.sendData('hello Handler')
# wait respond from origin handler
while 1:
origHandler = x.receiveData()
if origHandler <> "":
- print origHandler
break
#think about time out
if origHandler == "ready":
print "Caller handler ready"
+ print ""
try:
y = None
global portDest
@@ -117,7 +121,6 @@ def FuncTest(orig, origAdd, dest, destAdd, destNo):
y.sendData('hello server please wakeup the handler and be receiver')
else:
- print "here I am"
command="--command=python " +dest
subprocess.Popen(args=["gnome-terminal", command])
@@ -139,30 +142,30 @@ def FuncTest(orig, origAdd, dest, destAdd, destNo):
#print "not define yet"
#portDest = 50108
- print portDest
- print destAdd
y = classClient.Connection(destAdd,portDest)
- print "Destination handler", y.connect()
+ print "Destination handler status:", y.connect()
y.sendData('hello Receiver, caller number')
#wait respond from destination handler
while 1:
destHandler = y.receiveData()
if destHandler <> "":
- print 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(5)
- x.sendData(destNo)
- #send destination number to caller and signal 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()
@@ -194,9 +197,10 @@ def FuncTest(orig, origAdd, dest, destAdd, destNo):
else: #save to database, tell handler to terminated
#db.execute ("update result table")
- print "Test Result: ", resultOrig
- x.sendData("terminated") # signal caller to terminate
- #y.sendData("terminated") # signal receiver to terminate
+ 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"
@@ -224,6 +228,7 @@ def FuncTest(orig, origAdd, dest, destAdd, destNo):
# Check DB connection
x = classDb.DBMySQLConnection(user, passw, host, dbname)
print "connected to the DB ", x.connectDB()
+print ""
dbStatus = x.connectDB()
@@ -247,7 +252,8 @@ if dbStatus == 1:
#J = 1, 2
#for A in J:
# print "call from to ", taskID , callFrom , callTo
- print "call :", callFrom , callTo
+ print "Test Task : Calling from " +callFrom+ " to " +callTo
+ print ""
if callFrom == "sip" and sipServerStatus <> 0:
@@ -284,6 +290,7 @@ if dbStatus == 1:
if callTo =="sip" and sipServerStatus <> 0:
FuncTest("gsmcall_.py", "localhost", "SIPIncoming.py", "localhost","929")
+ sleep(10)
if callTo =="gsmrz2" and gsmBox1Status <> 0:
diff --git a/For Weekly Test/07-08-2011/Controller-SecondType_withDB.py b/For Weekly Test/07-08-2011/Controller-SecondType_withDB.py
new file mode 100644
index 0000000..96a9599
--- /dev/null
+++ b/For Weekly Test/07-08-2011/Controller-SecondType_withDB.py
@@ -0,0 +1,302 @@
+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]
+
+ print "call from to ", taskID , callFrom , callTo
+
+ 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-08-2011/SIPIncoming.py b/For Weekly Test/07-08-2011/SIPIncoming.py
index bbe16e2..6404f10 100644
--- a/For Weekly Test/07-08-2011/SIPIncoming.py
+++ b/For Weekly Test/07-08-2011/SIPIncoming.py
@@ -17,6 +17,8 @@ password = "2mpselftest"
LOG_LEVEL=2
current_call = None
success = ""
+global accept
+accept = None
# Logging callback
@@ -46,10 +48,21 @@ class MyAccountCallback(pj.AccountCallback):
current_call.set_callback(call_cb)
current_call.answer(180)
- current_call.answer(200)
print "accept call"
- sleep(5)
- current_call.hangup()
+ 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
@@ -63,8 +76,8 @@ class MyCallCallback(pj.CallCallback):
global current_call
if self.call.info().state_text == "CONNECTING":
- success = "true"
- server.sendData(success)
+ print self.call.info().state_text
+ success = "success"
if self.call.info().state == pj.CallState.DISCONNECTED:
current_call = None
@@ -77,10 +90,10 @@ class MyCallCallback(pj.CallCallback):
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')
+ #server.sendData('establish connection')
print "Media is now active"
-
+
else:
print "Media is inactive"
@@ -130,9 +143,11 @@ try:
break
if current_call == None:
+ accept = None
continue
else:
print "Incoming call from :", number
+
sleep(4)
diff --git a/For Weekly Test/07-08-2011/classServer.py b/For Weekly Test/07-08-2011/classServer.py
index 5adf681..97a398d 100644
--- a/For Weekly Test/07-08-2011/classServer.py
+++ b/For Weekly Test/07-08-2011/classServer.py
@@ -75,6 +75,9 @@ class ServerHandler:
def closeConnection(self):
if self.onceConnected == 1:
self.connection.close()
+ self.s.close()
+ self.s = None
+ self.connected == 0
return 1
else:
return 0
diff --git a/For Weekly Test/07-08-2011/classServer.pyc b/For Weekly Test/07-08-2011/classServer.pyc
index abca7ce..52f5085 100644
--- a/For Weekly Test/07-08-2011/classServer.pyc
+++ b/For Weekly Test/07-08-2011/classServer.pyc
Binary files differ
diff --git a/For Weekly Test/07-08-2011/gsmcall2_.py b/For Weekly Test/07-08-2011/gsmcall2_.py
index c45f757..bf8e662 100644
--- a/For Weekly Test/07-08-2011/gsmcall2_.py
+++ b/For Weekly Test/07-08-2011/gsmcall2_.py
@@ -18,8 +18,7 @@ stop ="false"
success = "failed"
-while stop <> "true"
- try:
+try:
global ser
portAddress = '/dev/ttyUSB0'
portName = portAddress[-4:]
@@ -59,7 +58,7 @@ while stop <> "true"
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
+ print "Signal Bar: ", signalQuality
#
diff --git a/For Weekly Test/07-08-2011/gsmcall_.py b/For Weekly Test/07-08-2011/gsmcall_.py
index 8bf7e86..48466cb 100644
--- a/For Weekly Test/07-08-2011/gsmcall_.py
+++ b/For Weekly Test/07-08-2011/gsmcall_.py
@@ -17,29 +17,23 @@ import string
stop ="false"
success = "failed"
+global server
+global ser
+portAddress = '/dev/ttyUSB1'
+portName = portAddress[-4:]
+portExist = os.popen('dmesg | grep ' + portName).read()
-while stop <> "true":#???
+if portExist == '':
+ print 'The serial port does not exist'
+ sys.exit()
- 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()
+while stop <> "true":#???
- ser = Serial(
- port=portAddress,
- baudrate=19200,
- bytesize=EIGHTBITS,
- parity=PARITY_NONE,
- stopbits=STOPBITS_ONE)
-
-
+
+ try:
server = classServer.ServerHandler(50098)
tried = server.openSocket()
@@ -53,36 +47,41 @@ while stop <> "true":#???
server.sendData('ready')#send message to controller
- print "here:", server.connected
+ print "Controller status: ", server.connected
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 ""
-
+
if data == "start": # if receiver start message, handler start to call destination
- #num = server.receiveData() # waiting destination number
+ num = "929"
server.closeConnection()
+
+ ser = Serial(
+ port=portAddress,
+ baudrate=19200,
+ bytesize=EIGHTBITS,
+ parity=PARITY_NONE,
+ stopbits=STOPBITS_ONE)
+
+ ser.close()
ser.open()
- ser.write('AT+CSQ\r')
- signalQuality = ser.read(35)
- print "signal Quality ", signalQuality
- num = 929
+
if num <> "":
-
- ser.write('ATD' + num + ';\r')
- sleep(5)
- success = "success"
+
+ ser.write('ATD4661' + num + ';\r')
+ sleep(3)
ser.write('AT+CHUP\r')
- ser.close()
+ 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
@@ -93,10 +92,11 @@ while stop <> "true":#???
del server
- tried = server.openSocket()
- server.sendData(success)
server.closeConnection()
del server
+ print "Goodbye"
+ sleep(3)
+ sys.exit(1)
except ValueError:
print "Exception: " + str(e)