summaryrefslogtreecommitdiffstats
path: root/For Weekly Test
diff options
context:
space:
mode:
authortt412011-07-07 05:26:22 +0200
committertt412011-07-07 05:26:22 +0200
commit478182c75a96ef924de7149647379c40044c73ab (patch)
tree07c682b8688e9be028745481912a0417dc482b9e /For Weekly Test
parentedit password for DB.remember to use our default password. (diff)
downloadgsm-selftest-478182c75a96ef924de7149647379c40044c73ab.tar.gz
gsm-selftest-478182c75a96ef924de7149647379c40044c73ab.tar.xz
gsm-selftest-478182c75a96ef924de7149647379c40044c73ab.zip
add weekly test folder. also store files for test on July 7, 2011.
Diffstat (limited to 'For Weekly Test')
-rw-r--r--For Weekly Test/07-08-2011/Controller-SecondType.py259
-rw-r--r--For Weekly Test/07-08-2011/SIPCall.py176
-rw-r--r--For Weekly Test/07-08-2011/SIPIncoming.py162
-rw-r--r--For Weekly Test/07-08-2011/classClient.py74
-rw-r--r--For Weekly Test/07-08-2011/classClient.pycbin0 -> 2780 bytes
-rw-r--r--For Weekly Test/07-08-2011/classDb.py212
-rw-r--r--For Weekly Test/07-08-2011/classDb.pycbin0 -> 5666 bytes
-rw-r--r--For Weekly Test/07-08-2011/classServer.py91
-rw-r--r--For Weekly Test/07-08-2011/classServer.pycbin0 -> 3066 bytes
-rw-r--r--For Weekly Test/07-08-2011/gsmcall_.py95
-rw-r--r--For Weekly Test/07-08-2011/gsmincom_.py138
11 files changed, 1207 insertions, 0 deletions
diff --git a/For Weekly Test/07-08-2011/Controller-SecondType.py b/For Weekly Test/07-08-2011/Controller-SecondType.py
new file mode 100644
index 0000000..22b1990
--- /dev/null
+++ b/For Weekly Test/07-08-2011/Controller-SecondType.py
@@ -0,0 +1,259 @@
+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
+ repeatTest = ""
+
+
+ try:
+
+ if dest =="gsmBox1" or dest =="gsmBox2":
+
+ if dest =="gsmBox1":
+ x = classClient.Connection(origAdd,50095)
+
+ if dest =="gsmBox2":
+ x = classClient.Connection(origAdd,50096)
+
+ print "GSM server handler", y.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":
+ x = classClient.Connection(origAdd,50097)
+
+ if orig == "landlineCall.py":
+ x = classClient.Connection(origAdd,50098)
+
+ if orig == "LocalSIPCall.py":
+ x = classClient.Connection(origAdd,50099)
+
+ else: #mean external GSM
+ x = classClient.Connection(origAdd,50100)
+
+ print "handler", x.connect()
+ x.sendData('hello Handler')
+
+ # wait respond from origin handler
+ while 1:
+ origHandler = x.receive_data()
+ if origHandler <> "":
+ break
+ #think about time out
+
+ if origHandler == "ready":
+ print "sip handler ready"
+ try:
+ if dest =="gsmBox1" or dest =="gsmBox2":
+
+ if dest =="gsmBox1":
+ y = classClient.Connection(destAdd,50101)
+
+ if dest =="gsmBox2":
+ y = classClient.Connection(destAdd,50102)
+
+ 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(5)
+
+ if orig=="SIPReceiver.py":
+ y = classClient.Connection(destAdd,50103)
+
+ if orig == "landlineReceiver.py":
+ y = classClient.Connection(destAdd,50104)
+
+ if orig == "LocalSIPReceiver.py":
+ y = classClient.Connection(destAdd,50105)
+
+ else: #mean external GSM
+ y = classClient.Connection(destAdd,50106)
+
+ print "GSM Server handler", 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":
+
+ x.sendData("start")#send message to handler to start the call
+ sleep(2)
+ x.sendData(destNo)
+ #send destination number to caller and signal to start the call
+
+ #wait respond from both of handler
+ while 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()
+
+ 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"
+
+ else: #save to database, tell handler to terminated
+ db.execute ("update result table")
+ 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()
+dbStatus = x.connectDB()
+
+
+if dbStatus == 1:
+
+ # Check Ping to the Every Handler
+ sipServerStatus = FuncPing("132.230.4.8")
+ 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", "RZ1Receiver.py", "132.0.0.1","406")
+ 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("rz1Caller.py", "132.0.0.1", "SIPReceiver.py", "localhost","928")
+
+
+ if callTo =="gsmrz2" and gsmBox1Status <> 0:
+ FuncTest("Box1", "132.0.0.2", "SIPReceiver.py", "localhost","928")
+
+ if callTo =="gsmrz3" and gsmBox2Status <> 0:
+ FuncTest("Box2", "132.0.0.3", "SIPReceiver.py", "localhost","928")
+
+
+
+
+# will exit if DB connection failed
+else:
+ sys.exit(5)
+
diff --git a/For Weekly Test/07-08-2011/SIPCall.py b/For Weekly Test/07-08-2011/SIPCall.py
new file mode 100644
index 0000000..55a917f
--- /dev/null
+++ b/For Weekly Test/07-08-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)
+
+ server.sendData('I am ready')#send message to controller
+ print "here:", server.connected
+ while 1:
+ try:
+ data = server.receiveData() # waiting mode, until receiver start message or terminate message
+
+ if data == "start": # if receiver start message, handler start to call destination
+
+ while 1:
+
+ num = server.receiveData() # waiting destination number
+ if num <> "":
+
+ 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-08-2011/SIPIncoming.py b/For Weekly Test/07-08-2011/SIPIncoming.py
new file mode 100644
index 0000000..7ef63a1
--- /dev/null
+++ b/For Weekly Test/07-08-2011/SIPIncoming.py
@@ -0,0 +1,162 @@
+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 = ""
+
+
+# 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)
+ current_call.answer(200)
+ print "accept call"
+ sleep(5)
+ current_call.hangup()
+
+
+# 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":
+ success = "true"
+ server.sendData(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(50103)
+ 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(server, username, password)
+ 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('I am 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:
+ 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/07-08-2011/classClient.py b/For Weekly Test/07-08-2011/classClient.py
new file mode 100644
index 0000000..625e48e
--- /dev/null
+++ b/For Weekly Test/07-08-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/07-08-2011/classClient.pyc b/For Weekly Test/07-08-2011/classClient.pyc
new file mode 100644
index 0000000..f0a0323
--- /dev/null
+++ b/For Weekly Test/07-08-2011/classClient.pyc
Binary files differ
diff --git a/For Weekly Test/07-08-2011/classDb.py b/For Weekly Test/07-08-2011/classDb.py
new file mode 100644
index 0000000..615b868
--- /dev/null
+++ b/For Weekly Test/07-08-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-08-2011/classDb.pyc b/For Weekly Test/07-08-2011/classDb.pyc
new file mode 100644
index 0000000..522034d
--- /dev/null
+++ b/For Weekly Test/07-08-2011/classDb.pyc
Binary files differ
diff --git a/For Weekly Test/07-08-2011/classServer.py b/For Weekly Test/07-08-2011/classServer.py
new file mode 100644
index 0000000..109fa0b
--- /dev/null
+++ b/For Weekly Test/07-08-2011/classServer.py
@@ -0,0 +1,91 @@
+# 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(1024)
+ 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()
+ 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-08-2011/classServer.pyc b/For Weekly Test/07-08-2011/classServer.pyc
new file mode 100644
index 0000000..473063e
--- /dev/null
+++ b/For Weekly Test/07-08-2011/classServer.pyc
Binary files differ
diff --git a/For Weekly Test/07-08-2011/gsmcall_.py b/For Weekly Test/07-08-2011/gsmcall_.py
new file mode 100644
index 0000000..1e2a010
--- /dev/null
+++ b/For Weekly Test/07-08-2011/gsmcall_.py
@@ -0,0 +1,95 @@
+import sys
+import pjsua as pj
+import socket
+import time
+import MySQLdb
+import subprocess
+
+import classServer
+
+from time import sleep
+from datetime import datetime
+import string
+
+
+stop ="false"
+
+LOG_LEVEL=2
+current_call = None
+success = ""
+
+
+
+while stop <> "true":
+
+
+ try:
+ global ser
+ portAddress = '/dev/ttyUSB1'
+ portName = portAddress[-4:]
+ portExist = os.popen('dmesg | grep ' + portName).read()
+
+ if portExist == '':
+ print 'The serial port does not exist'
+ sys.exit()
+
+ ser = Serial(
+ port=portAddress,
+ baudrate=19200,
+ bytesize=EIGHTBITS,
+ parity=PARITY_NONE,
+ stopbits=STOPBITS_ONE)
+ ser.open()
+
+
+ server = classServer.ServerHandler(50097)
+ tried = server.openSocket()
+
+ if server.error != 'No error':
+ print server.error
+ if server.error == '[Errno 98] Address already in use':
+ print 'one should try to kill the port'
+ print server.killPort()
+ server.closeConection()
+
+
+ server.sendData('I am ready')#send message to controller
+ print "here:", server.connected
+
+ while 1:
+ try:
+ data = server.receiveData() # waiting mode, until receiver start message or terminate message
+
+ if data == "start": # if receiver start message, handler start to call destination
+
+ while 1:
+
+ num = server.receiveData() # waiting destination number
+ if num <> "":
+
+ callBackNumber=
+ ser.write('ATD' + num + ';\r')
+ sleep(5)
+ server.sendData('success')
+ ser.write('AT+CHUP\r')
+ break
+
+ if data == "terminated": # will terminate the handler if controller send terminate message
+ stop = "true"
+ break
+
+ except ValueError:
+ print "error when sending message"
+ server.closeConnection()
+ del server
+ ser.close()
+
+ server.closeConnection()
+ del server
+ ser.close()
+
+ except ValueError:
+ print "Exception: " + str(e)
+
+print "Goodbye"
+sleep(3)
diff --git a/For Weekly Test/07-08-2011/gsmincom_.py b/For Weekly Test/07-08-2011/gsmincom_.py
new file mode 100644
index 0000000..018bede
--- /dev/null
+++ b/For Weekly Test/07-08-2011/gsmincom_.py
@@ -0,0 +1,138 @@
+import sys
+import pjsua as pj
+import socket
+import time
+import os
+import string
+import classServer
+
+from time import sleep
+from datetime import datetime
+
+stop ="false"
+
+
+success = ""
+
+
+
+
+try:
+
+ global ser
+ portAddress = '/dev/ttyUSB1'
+ portName = portAddress[-4:]
+ portExist = os.popen('dmesg | grep ' + portName).read()
+
+ if portExist == '':
+ print 'The serial port does not exist'
+ sys.exit()
+
+ ser = Serial(
+ port=portAddress,
+ baudrate=19200,
+ bytesize=EIGHTBITS,
+ parity=PARITY_NONE,
+ stopbits=STOPBITS_ONE)
+ ser.open()
+
+ server = classServer.ServerHandler(50097)
+ tried = server.openSocket()
+
+ if server.error != 'No error':
+ print server.error
+ if server.error == '[Errno 98] Address already in use':
+ print 'one should try to kill the port'
+ print server.killPort()
+ server.closeConection()
+
+
+ print "here:", server.connected
+
+
+ if server.connected == 1:
+
+ server.sendData('I am ready')
+
+ while stop <> "true":
+
+ data = server.receiveData()
+ if data == "terminated":
+ print "I will", data
+ break
+
+ buffer = buffer + ser.read(ser.inWaiting())
+ if '\n' in buffer:
+ lines = buffer.split('\n')
+ last_received = lines.pop(0)
+
+ buffer = '\n'.join(lines)
+
+ last_received=last_received.split('\n')
+ line = last_received[0].replace(chr(13), '')
+
+
+ if len(line) > 0:
+
+ if line=='RING':
+ if pickUp == 0:
+
+ print "Somebody calling"
+ sleep(1)
+ ser.write('ATA\r')
+
+ sleep(1)
+ ser.write('AT+CSQ\r')
+
+ sleep(2)
+ ser.write('AT+CLCC\r')
+ line=''
+
+ if line[0:5] == '+CSQ:':
+
+ space = int(string.find(line,' '))+1
+ coma = int(string.find(line,','))
+ signalStr = (int(line[space:coma])*2)-113
+
+ line=''
+
+ if line[0:6]=='+CLCC:':
+
+ pickUp = 1
+
+ print "I will hangup the call"
+ sleep(5)
+
+ ser.write('AT+CHUP\r')
+ pickUp = 0
+
+ quotation1 = int(string.find(line,'"'))+1
+ lineTemp = line[quotation1:]
+
+ quotation2 = int(string.find(lineTemp,'"'))
+ numberOfCaller = line[quotation1:quotation1+quotation2]
+
+ server.sendData('I got call from' +numberOfCaller)
+ print "caller number", numberOfCaller
+ sleep(1)
+ server.sendData('success')
+ sleep (3)
+ ser.close()
+
+
+ server.closeConnection()
+ del server
+ else:
+
+ print "not connected"
+
+ del server
+
+ ser.close()
+except ValueError:
+ print "Exception: " + str(e)
+ server.closeConnection()
+ del server
+
+print "GOODBYE"
+sleep(5)