Changed a few file names and started on the TrackingServer
git-svn-id: http://www.neo1973-germany.de/svn@159 46df4e5c-bc4e-4628-a0fc-830ba316316d
This commit is contained in:
parent
34726d8b66
commit
946badb6b8
6 changed files with 101 additions and 85 deletions
|
@ -102,6 +102,7 @@ class TrackClient:
|
||||||
|
|
||||||
def StopTrack(self):
|
def StopTrack(self):
|
||||||
self.SendData(self.__username, self.__pwhash, action="STOP")
|
self.SendData(self.__username, self.__pwhash, action="STOP")
|
||||||
|
|
||||||
|
# remove connect_to_signal event
|
||||||
self.terminator.remove()
|
self.terminator.remove()
|
||||||
self.usage_iface.ReleaseResource("GPS")
|
self.usage_iface.ReleaseResource("GPS")
|
||||||
sys.exit()
|
|
||||||
|
|
90
PyTracker/trunk/PyTrackerServer.py
Normal file
90
PyTracker/trunk/PyTrackerServer.py
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
from __future__ import with_statement
|
||||||
|
import time
|
||||||
|
from socket import *
|
||||||
|
from WriteGPX import *
|
||||||
|
|
||||||
|
class TrackServer:
|
||||||
|
def __init__(self, host, port, hashfile, datadir = '.'):
|
||||||
|
self.InitSocker(host, port)
|
||||||
|
self.InitHashdb(hashfile)
|
||||||
|
self.InitTrackDict()
|
||||||
|
self.datadir = datadir
|
||||||
|
|
||||||
|
def InitHashdb(self, hashfile):
|
||||||
|
self.hashdb=[]
|
||||||
|
with open(hashfile, "r") as file:
|
||||||
|
for line in file:
|
||||||
|
if line:
|
||||||
|
self.hashdb.append((line.split()[0], \
|
||||||
|
line.split()[1]))
|
||||||
|
|
||||||
|
def InitTrackDict(self):
|
||||||
|
self.TrackDict={}
|
||||||
|
for data in self.hashdb:
|
||||||
|
self.TrackDict[data[0]] = ""
|
||||||
|
|
||||||
|
def InitSocket(self, host, port):
|
||||||
|
|
||||||
|
# Set the socket parameters
|
||||||
|
# e.g. host = "localhost"
|
||||||
|
# e.g. port = 49152
|
||||||
|
self.__addr = (str(host),int(port))
|
||||||
|
|
||||||
|
# Create socket and bind it to the address
|
||||||
|
self.__UDPSock = socket(AF_INET,SOCK_DGRAM)
|
||||||
|
self.__UDPSock.bind(sel.__addr)
|
||||||
|
|
||||||
|
# Debug message:
|
||||||
|
print "UDP Socket for %s at port %s created" % (host, port)
|
||||||
|
|
||||||
|
def VerifyUser(self, username, password_hash):
|
||||||
|
for data in self.hashdb:
|
||||||
|
if data[0] == username and data[1] == password_hash:
|
||||||
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def Parser(self, stuff):
|
||||||
|
|
||||||
|
# Parses the complete data sent to UDP port
|
||||||
|
try:
|
||||||
|
username, password_hash, action, data = stuff.split(';')
|
||||||
|
|
||||||
|
# Verifies the user and password
|
||||||
|
if self.VerifyUser(username, password_hash):
|
||||||
|
if action == "START":
|
||||||
|
self.NewTrack(username)
|
||||||
|
if action == "STOP":
|
||||||
|
self.CloseTrack(username)
|
||||||
|
if action == "TRANSMIT":
|
||||||
|
self.AddToTrack(username, data)
|
||||||
|
print "Action", action,"received"
|
||||||
|
except:
|
||||||
|
print "Something went wrong.."
|
||||||
|
|
||||||
|
def NewTrack(self, username):
|
||||||
|
if not self.TrackDict[username]:
|
||||||
|
self.TrackDict[username] = WriteGPX("%s%s%s" % (self.datadir, username, time.strftime("%Y%m%d%H%M%S"))
|
||||||
|
print "Created track", self.TrackDict[username]
|
||||||
|
|
||||||
|
def CloseTrack(self, username):
|
||||||
|
if self.TrackDict[username]:
|
||||||
|
self.TrackDict[username].close()
|
||||||
|
print "Closed track", self.TrackDict[username]
|
||||||
|
del self.TrackDict[username]
|
||||||
|
|
||||||
|
def AddToTrack(self, username, data):
|
||||||
|
lat, lon, ele, time = data.split(',')
|
||||||
|
self.TrackDict[username].write(lat, lon, ele, time)
|
||||||
|
|
||||||
|
|
||||||
|
buf = 1024
|
||||||
|
|
||||||
|
# Create instance of TrackServer
|
||||||
|
instance = TrackServer()
|
||||||
|
|
||||||
|
#Receive messages
|
||||||
|
while 1:
|
||||||
|
data,addr = UDPSock.recvfrom(1024)
|
||||||
|
print "Following data received:", data
|
||||||
|
instance.Parser(data)
|
|
@ -3,16 +3,20 @@
|
||||||
authors: Pau1us
|
authors: Pau1us
|
||||||
license: gpl v2 or later
|
license: gpl v2 or later
|
||||||
|
|
||||||
This is a Class to creat *.gpx Files
|
This is a Class to create *.gpx Files
|
||||||
Usage:
|
Usage:
|
||||||
open new file: file = WriteGPX(filename)
|
open new file: file = WriteGPX(filename)
|
||||||
write trackpint: file.write(lat, lon, alt, utctime)
|
write trackpint: file.write(lat, lon, alt, utctime)
|
||||||
close file: file.close()
|
close file: file.close()
|
||||||
The file musst be closed, otherwise the file will be incomplete
|
The file musst be closed, otherwise the file will be incomplete
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
|
<<<<<<< .mine
|
||||||
|
=======
|
||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
|
>>>>>>> .r158
|
||||||
class WriteGPX:
|
class WriteGPX:
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
from __future__ import with_statement
|
|
||||||
import time
|
|
||||||
from socket import *
|
|
||||||
|
|
||||||
class TrackServer:
|
|
||||||
def __init__(self):
|
|
||||||
self.InitHashdb("hashfile.txt")
|
|
||||||
self.InitTrackDict()
|
|
||||||
|
|
||||||
def InitHashdb(self, hashfile):
|
|
||||||
self.hashdb=[]
|
|
||||||
with open(hashfile, "r") as file:
|
|
||||||
for line in file:
|
|
||||||
if line:
|
|
||||||
self.hashdb.append((line.split()[0], \
|
|
||||||
line.split()[1]))
|
|
||||||
|
|
||||||
def InitTrackDict(self):
|
|
||||||
self.TrackDict={}
|
|
||||||
for data in self.hashdb:
|
|
||||||
self.TrackDict[data[0]] = ""
|
|
||||||
|
|
||||||
def VerifyUser(self, username, password_hash):
|
|
||||||
for data in self.hashdb:
|
|
||||||
if data[0] == username and data[1] == password_hash:
|
|
||||||
return 1
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
def Parser(self, stuff):
|
|
||||||
# Parses the complete data sent to UDP port
|
|
||||||
try:
|
|
||||||
username, password_hash, action, data = stuff.split()
|
|
||||||
# Verifies the user and password
|
|
||||||
if self.VerifyUser(username, password_hash):
|
|
||||||
|
|
||||||
if action == "START":
|
|
||||||
self.NewTrack(username)
|
|
||||||
if action == "STOP":
|
|
||||||
self.CloseTrack(username)
|
|
||||||
if action == "TRANSMIT":
|
|
||||||
self.AddToTrack(username, data)
|
|
||||||
print "Action", action,"received"
|
|
||||||
except:
|
|
||||||
print "Something went wrong.."
|
|
||||||
|
|
||||||
def NewTrack(self, username):
|
|
||||||
self.TrackDict[username] = "/home/edistar/Openmoko/projects/tracking/data/" + username + time.strftime("%Y%m%d%H%M%S")
|
|
||||||
print "Created track", self.TrackDict[username]
|
|
||||||
|
|
||||||
def CloseTrack(self, username):
|
|
||||||
self.TrackDict[username] = ""
|
|
||||||
print "Closed track", self.TrackDict[username]
|
|
||||||
|
|
||||||
def AddToTrack(self, username, data):
|
|
||||||
with open(self.TrackDict[username], "a") as trackfile:
|
|
||||||
trackfile.write(data + "\n")
|
|
||||||
print "Successfully added data to track", self.TrackDict[username]
|
|
||||||
|
|
||||||
instance=TrackServer()
|
|
||||||
|
|
||||||
# Set the socket parameters
|
|
||||||
host = ""
|
|
||||||
port = 49152
|
|
||||||
buf = 1024
|
|
||||||
addr = (host,port)
|
|
||||||
|
|
||||||
# Create socket and bind to address
|
|
||||||
UDPSock = socket(AF_INET,SOCK_DGRAM)
|
|
||||||
UDPSock.bind(addr)
|
|
||||||
|
|
||||||
# Create instance of TrackServer
|
|
||||||
instance = TrackServer()
|
|
||||||
|
|
||||||
#Receive messages
|
|
||||||
while 1:
|
|
||||||
data,addr = UDPSock.recvfrom(buf)
|
|
||||||
print "Following data received:", data
|
|
||||||
instance.Parser(data)
|
|
Loading…
Reference in a new issue