summaryrefslogtreecommitdiffstats
path: root/notFinishedCode
diff options
context:
space:
mode:
authorRefik Hadzialic2011-10-28 23:18:37 +0200
committerRefik Hadzialic2011-10-28 23:18:37 +0200
commit01b4de2198c80e978a7443401d55cc57948157de (patch)
tree9df45bc01d59524b6a0937b2fd39886d740803f1 /notFinishedCode
parentLogging a detail more (diff)
downloadgsm-selftest-01b4de2198c80e978a7443401d55cc57948157de.tar.gz
gsm-selftest-01b4de2198c80e978a7443401d55cc57948157de.tar.xz
gsm-selftest-01b4de2198c80e978a7443401d55cc57948157de.zip
Working
Diffstat (limited to 'notFinishedCode')
-rw-r--r--notFinishedCode/GSMClass.py12
-rw-r--r--notFinishedCode/serverHandler.py30
2 files changed, 34 insertions, 8 deletions
diff --git a/notFinishedCode/GSMClass.py b/notFinishedCode/GSMClass.py
index e994814..02eb51e 100644
--- a/notFinishedCode/GSMClass.py
+++ b/notFinishedCode/GSMClass.py
@@ -16,13 +16,15 @@ class serialPort():
self.signalStrength = 0
#self.callerConnected = -1
self.timer = timeout
+ self.timer1 = timeout
+ self.start = 0
self.debugMode = 0
- def portInit(self):
+ def portInit(self, timeout1):
portName = self.portAddress[-4:]
portExist = os.popen('dmesg | grep ' + portName).read()
-
+ self.timer = timeout1
if portExist == '':
return 0
else:
@@ -45,7 +47,7 @@ class serialPort():
self.ser.write('AT\r')
received = self.__receiveData()
-
+ self.start=1
if received == 'OK':
self.portExist = 1
return 1 #cellphone is OK, receives commands
@@ -200,6 +202,10 @@ class serialPort():
def __receiveData(self):
def timeout_handler(signum, frame):
raise TimeoutException()
+ if self.start == 0:
+ self.timer = 5
+ else:
+ self.timer = self.timer1
old_handler = signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(self.timer)
diff --git a/notFinishedCode/serverHandler.py b/notFinishedCode/serverHandler.py
index d7982d5..48e457d 100644
--- a/notFinishedCode/serverHandler.py
+++ b/notFinishedCode/serverHandler.py
@@ -1,5 +1,5 @@
import ServerClass
-import GSMClass
+import GSMClass1
import LogFileClass
from time import sleep
@@ -53,13 +53,13 @@ def initSystem():
logger.logEvent('LISTEN ON PORT: '+str(portListen))
#add this if you need it
- gsmDevice = GSMClass.serialPort(portAddress, baudRate, 20)
- initDevice = gsmDevice.portInit()
+ gsmDevice = GSMClass1.serialPort(portAddress, baudRate, 20)
+ initDevice = gsmDevice.portInit(5)
########################################################
#add nice formating to the log file :)
anyConnection = handlerSocket.openSocket()
- print 'any connection ' + str(anyConncetion)
+ print 'any connection ' + str(anyConnection)
print 'initDevice ' + str(initDevice)
if initDevice!= 1:
@@ -73,16 +73,23 @@ def initSystem():
elif anyConnection == 1 and initDevice == 0:
logger.logEvent('$connection established but device not working: ' + str(handlerSocket.connectedTo()))
+ resetState = 1
return 2
else:
logger.logEvent('$no connection')
logger.logEvent('$else case in init system' + str(anyConnection) + ' ' + str(initDevice) + ' ')
+ resetState = 1
return 0
def receiveMessage(timeout):
message = str(handlerSocket.receiveData(timeout))
-
+ print 'I RECEIVED THE FOLLOWING MESSAGE' + message
+ if message == 'NO DATA':
+ print 'try to close the connection' + str(handlerSocket.closeConnection())
+ global resetState
+ resetState = 1
+ return 1
if message != '0' and message !='NO DATA':
print 'in receive message', message, lastState
@@ -102,6 +109,7 @@ def receiveMessage(timeout):
elif message == 'RECEIVE START' and lastState == 2:
outcome = receiveStart()
+ print 'outcome ' + str(outcome)
if outcome == 1:
logger.logEvent('RECEIVE STATUS REPORTED')
else:
@@ -119,6 +127,7 @@ def receiveMessage(timeout):
elif message == 'CALL START' and lastState == 4:
outcome = callStart(numberToCall)
+ print 'outcome ' + str(outcome)
if outcome == 1:
logger.logEvent('CALLER STATUS SENT')
else:
@@ -171,9 +180,13 @@ def receiveStart():
#wait for a call and report if you received it and it was successfull or not
global lastState
+ global deviceError
lastState = 3
if deviceError == 0:
receiveCall = gsmDevice.receiveCall()
+ if receiveCall == 'TIMEOUT':
+ deviceError = 1
+ print 'device error in RECEIVE'
else:
receiveCall = 0
@@ -206,18 +219,24 @@ def callStart(numberToCall):
#call the number here
global lastState
+ global deviceError
lastState = 5
callSuccess = 'CALL NOT OK'
if deviceError==0:
tryCall = gsmDevice.callNumber(numberToCall)
+ if tryCall == 'TIMEOUT':
+ deviceError = 1
+ print 'device error in CALL'
else:
tryCall=0
+
if tryCall != 1:
callSuccess = 'CALL NOT OK'
else:
+ if tryCall != 'TIMEOUT':
sleep(2)
activeCall = gsmDevice.currentCall()
counter = 0
@@ -232,6 +251,7 @@ def callStart(numberToCall):
callSuccess = 'CALL OK'
else:
callSuccess = 'CALL NOT OK'
+
handResponse = handlerSocket.sendData(callSuccess)
if deviceError==0: