summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/07-07-2011/gsmincom_.py
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/07-07-2011/gsmincom_.py
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/07-07-2011/gsmincom_.py')
-rw-r--r--For Weekly Test/07-07-2011/gsmincom_.py155
1 files changed, 155 insertions, 0 deletions
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)