summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMac-Linux2011-08-31 17:42:25 +0200
committerMac-Linux2011-08-31 17:42:25 +0200
commit0685599965c0a48cb616f6689576cb569eb2849b (patch)
tree600682d886389147673038b5f83e18746df52273
parentadd ssh connection for BOX 1 and 2 (diff)
parentMerge branch 'master' of lab.ks.uni-freiburg.de:lsfks/projekte/gsm-selftest (diff)
downloadgsm-selftest-0685599965c0a48cb616f6689576cb569eb2849b.tar.gz
gsm-selftest-0685599965c0a48cb616f6689576cb569eb2849b.tar.xz
gsm-selftest-0685599965c0a48cb616f6689576cb569eb2849b.zip
Merge branch 'master' of lab.ks.uni-freiburg.de:lsfks/projekte/gsm-selftest
-rw-r--r--For Weekly Test/12-09-2011/ControllerClass.py4
-rw-r--r--notFinishedCode/web/ServerClass.py152
-rw-r--r--notFinishedCode/web/ajax.php167
-rw-r--r--notFinishedCode/web/loader.gifbin0 -> 10819 bytes
-rw-r--r--notFinishedCode/web/server1.py35
-rw-r--r--notFinishedCode/web/socket2.php68
6 files changed, 424 insertions, 2 deletions
diff --git a/For Weekly Test/12-09-2011/ControllerClass.py b/For Weekly Test/12-09-2011/ControllerClass.py
index a3f7c48..3b9ca62 100644
--- a/For Weekly Test/12-09-2011/ControllerClass.py
+++ b/For Weekly Test/12-09-2011/ControllerClass.py
@@ -117,7 +117,7 @@ class doTheTest:
if self.callFrom =="GSMRZ1":
self.portCaller = 50007
- self.portAdd = ''
+ self.portAdd = '/dev/ttyUSB4'
self.initGSM(self.portCaller, self.portAdd)
elif self.callFrom =="GSMRZ2":
@@ -160,7 +160,7 @@ class doTheTest:
if self.dest =="GSMRZ1":
self.portDest = 50007
- self.portAdd = ''
+ self.portAdd = '/dev/ttyUSB4'
self.initGSM(self.portDest, self.portAdd)
elif self.dest =="GSMRZ2":
diff --git a/notFinishedCode/web/ServerClass.py b/notFinishedCode/web/ServerClass.py
new file mode 100644
index 0000000..93c2f8e
--- /dev/null
+++ b/notFinishedCode/web/ServerClass.py
@@ -0,0 +1,152 @@
+import socket
+import sys
+import os
+import string
+import signal
+
+class TimeoutException(Exception):
+ pass
+
+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'
+
+ self.debugMode = 0
+
+ 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, timeout):
+ if self.connected == 1:
+
+ def timeout_handler(signum, frame):
+ raise TimeoutException()
+
+ try:
+
+ old_handler = signal.signal(signal.SIGALRM, timeout_handler)
+ signal.alarm(timeout) #start the timeout alarm, for timeout seconds
+
+ data = self.connection.recv(1024)
+
+ #stop the timeout function
+ signal.signal(signal.SIGALRM, old_handler)
+ signal.alarm(0)
+
+ if not data:
+ self.connected = 0
+ return 'NO DATA'
+ else:
+ return data
+
+ except TimeoutException:
+ #timeout happened
+ signal.signal(signal.SIGALRM, old_handler)
+ signal.alarm(0)
+ return 'TIMEOUT'
+
+ except Exception, e:
+ #stop the timeout timer
+ signal.signal(signal.SIGALRM, old_handler)
+ signal.alarm(0)
+
+ if self.debugMode == 1:
+ import traceback
+ print traceback.format_exc()
+ print e
+ self.connected = 0
+ if error[0:11] == '[Errno 104]':
+ return 3 #the other side reset the connection,[Errno 104] Connection reset by peer
+
+ return 2
+ else:
+ return 0
+
+ def sendData(self, data):
+ if self.connected == 1:
+ try:
+ self.connection.send(data)
+ return 1
+
+ except Exception, e:
+ if self.debugMode == 1:
+ import traceback
+ print traceback.format_exc()
+ print e
+ self.connecected = 0
+ return 2
+ else:
+ return 0
+
+ def closeConnection(self):
+ if self.onceConnected == 1:
+ try:
+ self.connected = 0
+ SHUT_RDWR = 2
+ self.connection.shutdown(SHUT_RDWR)
+ self.connection.close()
+ return 1
+ except Exception, e:
+ self.connected = 0
+ error = str(e)
+ if self.debugMode == 1:
+ import traceback
+ print traceback.format_exc()
+ print e
+ if error[0:11] == '[Errno 107]':
+ return 3 #the other side closed the connection before us [Errno 107] Transport endpoint is not connected
+ return 2
+ 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/notFinishedCode/web/ajax.php b/notFinishedCode/web/ajax.php
new file mode 100644
index 0000000..ed8f4b6
--- /dev/null
+++ b/notFinishedCode/web/ajax.php
@@ -0,0 +1,167 @@
+
+<head> <title> Results page </title> <style>
+/* -------------------------------------------------------
+Author: Vitaly Friedman
+Theme: Green Life - A Fresh, Warm and Readable Table
+URL: http://www.alvit.de/vf
+-------------------------------------------------------
+*/
+
+ table {
+ font: 11px verdana,verdana, arial;
+ margin: 0;
+ padding: 0;
+ border-collapse: collapse;
+ text-align: left;
+ color: #333;
+ line-height: 19px;
+ }
+
+ caption {
+ font-size: 14px;
+ font-weight: bold;
+ margin-bottom: 20px;
+ text-align: left;
+ text-transform: uppercase;
+ }
+
+ td {
+ margin: 0;
+ padding: 20px 10px;
+ border: 1px dotted #f5f5f5;
+ }
+
+
+ th {
+ font-weight: normal;
+ text-transform: uppercase;
+ }
+
+ thead tr th {
+ background-color: #575757;
+ padding: 20px 10px;
+ color: #fff;
+ font-weight: bold;
+ border-right: 2px solid #333;
+ text-transform: uppercase;
+ text-align:center;
+ }
+
+ tfoot tr th, tfoot tr td {
+ background-color: transparent;
+ padding: 20px 10px;
+ color: #ccc;
+ border-top: 1px solid #ccc;
+ }
+
+ tbody tr th {
+ padding: 20px 10px;
+ border-bottom: 1px dotted #fafafa;
+ }
+
+ tr {
+ background-color: #FBFDF6;
+ }
+ tr.odd {
+ background-color: #EDF7DC;
+ }
+
+ tr:hover {
+ }
+
+ tr:hover td, tr:hover td a, tr:hover th a {
+ color: #a10000;
+ }
+
+ td:hover {
+ }
+
+ tr:hover th a:hover {
+ background-color: #F7FBEF;
+ border-bottom: 2px solid #86C200;
+ }
+
+ table a {
+ color: #608117;
+ background-image: none;
+ text-decoration: none;
+ border-bottom: 1px dotted #8A8F95;
+ padding: 2px;
+ padding-right: 12px; background: transparent url(http://www.alvit.de/vf/csstablegallery/link.gif) no-repeat 100% 50%;
+ }
+
+ table a:hover {
+ color: #BBC4CD;
+ background-image: none;
+ text-decoration: none;
+ border-bottom: 3px solid #333;
+ padding: 2px;
+ padding-right: 12px; color: #A2A2A2; background: transparent url(http://www.alvit.de/vf/csstablegallery/link.gif) no-repeat 100% 50%;
+ }
+
+ table a:visited {
+ text-decoration: none;
+ border-bottom: 1px dotted #333;
+ text-decoration: none;
+ padding-right: 12px; color: #A2A2A2; background: transparent url(http://www.alvit.de/vf/csstablegallery/visitedLink.gif) no-repeat 100% 50%;
+ }
+
+ table a:visited:hover {
+ background-image: none;
+ text-decoration: none;
+ border-bottom: 3px solid #333;
+ padding: 2px;
+ padding-right: 12px; color: #A2A2A2; background: transparent url(http://www.alvit.de/vf/csstablegallery/visitedLink.gif) no-repeat 100% 50%;
+ }
+</style>
+<html>
+<head>
+<title>Simple Ajax Example</title>
+<script language="Javascript">
+function xmlhttpPost(strURL) {
+ var xmlHttpReq = false;
+ var self = this;
+
+ // Mozilla/Safari
+ if (window.XMLHttpRequest) {
+ self.xmlHttpReq = new XMLHttpRequest();
+ }
+ // IE
+ else if (window.ActiveXObject) {
+ self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
+ }
+
+ self.xmlHttpReq.open('POST', strURL, true);
+ self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
+ updatepage('<img src="loader.gif" alt="Loading"/>');
+ self.xmlHttpReq.onreadystatechange = function() {
+ if (self.xmlHttpReq.readyState == 3) {
+ updatepage(self.xmlHttpReq.responseText);
+ }
+ // updatepage(self.xmlHttpReq.responseText);
+ }
+ self.xmlHttpReq.send(getquerystring());
+}
+
+function getquerystring() {
+ var form = document.forms['f1'];
+ var word = form.word.value;
+ qstr = 'w=' + escape(word); // NOTE: no '?' before querystring
+ return qstr;
+}
+
+function updatepage(str){
+ document.getElementById("result").innerHTML = str;
+}
+</script>
+</head>
+<body>
+<form name="f1">
+<p>
+ word: <input name="word" type="hidden" value="ludnica?refa?tela">
+ <input value="Go" type="button" onclick='JavaScript:xmlhttpPost("/socket2.php")'></p>
+ <div id="result"></div>
+</form>
+</body>
+</html>
+
diff --git a/notFinishedCode/web/loader.gif b/notFinishedCode/web/loader.gif
new file mode 100644
index 0000000..240d4e1
--- /dev/null
+++ b/notFinishedCode/web/loader.gif
Binary files differ
diff --git a/notFinishedCode/web/server1.py b/notFinishedCode/web/server1.py
new file mode 100644
index 0000000..7117f06
--- /dev/null
+++ b/notFinishedCode/web/server1.py
@@ -0,0 +1,35 @@
+import ServerClass
+import random
+from time import sleep
+
+while 1:
+ server = ServerClass.ServerHandler(34500) #define the port
+ tried = server.openSocket()
+
+ test = server.receiveData(0)
+ print test
+ if test == 'START TEST':
+ server.sendData('CONFIRM\n')
+ print 'TEST STARTED'
+ rndNum = random.randint(3,7)
+ for x in range(0,rndNum):
+ sleep(2)
+ print x
+ if server.sendData('SOME TEST WAS OK ' + str(x) + chr(10)) == 1:
+ print 'data sent successfully'
+
+ test = server.receiveData(0)
+ print test
+ if test == 'CONTINUE':
+ print 'continue test'
+
+ if server.connected == 1:
+ server.sendData('TEST DONE\n')
+ test = server.receiveData(0)
+
+ if test == 'DISCONNECT':
+ close = server.closeConnection()
+ if close == 1:
+ print 'Closed connection successfully'
+
+ del server
diff --git a/notFinishedCode/web/socket2.php b/notFinishedCode/web/socket2.php
new file mode 100644
index 0000000..5336892
--- /dev/null
+++ b/notFinishedCode/web/socket2.php
@@ -0,0 +1,68 @@
+<?
+ $ip = "localhost";
+ $port = 34500;
+ //sleep(2)
+
+ $fp = fsockopen($ip, $port, $errno, $error, 5);
+
+ if (!$fp)
+ {
+ printf('ERROR');
+ }
+ else
+ {
+ socket_set_timeout( $fp, 50); //one should set the number of the longest test, so we can define the timeout
+ fwrite($fp, "START TEST"); //send command to start the tests
+
+ if(!feof($fp))
+ {
+ while(!feof($fp))
+ {
+ $received = fgets($fp, 128);
+ if ($received == "CONFIRM\n")
+ {
+ //echo 'CONFIRM CONNECTION <br>';
+ echo '<table summary = "Submitted table designs">
+ <caption> Table concept for our results </caption>
+ <thead>
+ <tr>
+ <th scope = "col"> From: </th>
+ <th scope = "col" > To: </th>
+ <th scope = "col"> Message: </th>
+ <th scope = "col"> Status: </th>
+ </tr>
+ </thead>
+ <!-- start of the table rows-->
+ <tbody>';
+ echo str_repeat("\n",7024);
+ flush();
+ }
+ elseif ($received == "TEST DONE\n")
+ {
+ echo '</tbody></table>';
+ //echo 'DISCONNECT <br>';
+ echo str_repeat("\n",7024);
+ flush();
+ usleep(100);
+ fwrite($fp, 'DISCONNECT');
+ break;
+ }
+ else
+ {
+ echo '<tr>
+<th scope = "row" id = "r100"> SIP</th>
+<th scope = "row" id = "r100">GSM1 </th>
+<td> '. $received . ' </td>
+<td> 200</td>
+</tr>';
+ //echo $received . '<br>';
+ echo str_repeat("\n",7024);
+ flush();
+ usleep(100);
+ fwrite($fp, "CONTINUE");
+ }
+ }
+ }
+ fclose($fp);
+ }
+?>