From 9cfd388dc26b2faf687797acbe6ae9e4105d5879 Mon Sep 17 00:00:00 2001 From: edistar Date: Tue, 16 Sep 2008 16:23:21 +0000 Subject: [PATCH] Changed the file hierarchy.. the 'standard' svn way git-svn-id: http://www.neo1973-germany.de/svn@154 46df4e5c-bc4e-4628-a0fc-830ba316316d --- PyTracker/PyTracker.py | 81 ------------------------------------------ PyTracker/WriteGPX.py | 41 --------------------- PyTracker/client.py | 27 -------------- PyTracker/server.py | 79 ---------------------------------------- PyTracker/tracking.txt | 16 --------- 5 files changed, 244 deletions(-) delete mode 100755 PyTracker/PyTracker.py delete mode 100644 PyTracker/WriteGPX.py delete mode 100644 PyTracker/client.py delete mode 100644 PyTracker/server.py delete mode 100644 PyTracker/tracking.txt diff --git a/PyTracker/PyTracker.py b/PyTracker/PyTracker.py deleted file mode 100755 index 568353b..0000000 --- a/PyTracker/PyTracker.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/python -''' -authors: edistar -license: gpl v2 or later -version 0.2 -''' - -from __future__ import with_statement -import time -import datetime -import ecore -import e_dbus -import os -from dbus import SystemBus, Interface -from optparse import OptionParser - -class Main: - - def __init__(self): - - self.GetPath() - -# get FSO Usage proxy/iface up to request GPS - self.systembus=systembus = SystemBus(mainloop=e_dbus.DBusEcoreMainLoop()) - self.usage_proxy = self.systembus.get_object('org.freesmartphone.ousaged', '/org/freesmartphone/Usage') - self.usage_iface = Interface(self.usage_proxy, 'org.freesmartphone.Usage') - -# Request GPS from FSO (which then powers on the GPS chip) - self.usage_iface.RequestResource("GPS") - -#get gypsy proxy/iface up - self.ogpsd_proxy = self.systembus.get_object('org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy') - self.course_iface = Interface(self.ogpsd_proxy, 'org.freedesktop.Gypsy.Course') - self.pos_iface = Interface(self.ogpsd_proxy, 'org.freedesktop.Gypsy.Position') - -# call self.UpdatePosition() when a dbus signal "PositionChanged" comes along the system bus - self.pos_iface.connect_to_signal("PositionChanged", self.UpdatePosition) - - - def UpdatePosition(self, fields, timestamp, lat, lon, alt): - -# get UTC time from gypsy timestamp - string = str(datetime.datetime.utcfromtimestamp(timestamp)) - date, time = string.split() - utctime = "%sT%sZ" % (date, time) - -# write data to file - s ="%s,%s,%s,%s\n" % (lat, lon, alt, utctime) - with open(self.trackfile,'a') as file: - file.write(s) - -#debugging output: - print s - - - def Parser(self): - -# parse command line options - self.parser=OptionParser("usage foo bar") - self.parser.add_option("-f", "--file", "-o", "-l", action = "store", dest = "trackfile") - (self.options, self.args) = self.parser.parse_args() - - - def GetPath(self): - trackpath = '.' - suffix = 'track' - self.Parser() - -# raises an Exception if the path doesn't exist! :) - path, rubbish, suffix = self.trackfile.options.rpartition("/") - - if not os.path.exists(path): - raise Exception("path does not exist!") - -# sets trackfile path and filename - self.trackfile = "%s/%s-%s" % (trackpath, time.strftime(), suffix) - - - -test=Main() -ecore.main_loop_begin() diff --git a/PyTracker/WriteGPX.py b/PyTracker/WriteGPX.py deleted file mode 100644 index b461c30..0000000 --- a/PyTracker/WriteGPX.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/python -''' -authors: Pau1us -license: gpl v2 or later - -This is a Class to creat *.gpx Files -Usage: -open new file: file = WriteGPX(filename) -write trackpint: file.write(lat, lon, alt, utctime) -close file: file.close() -The file musst be closed, otherwise the file will be incomplete -''' - - -class WriteGPX: - def __init__(self, filename): - self.filename = filename - self.header = '\n\ -\n\ -\n\ -\n' - self.footer = '\n\n\n' - - with open(self.filename,'a') as file: - file.write(self.header) - - def write(self, lat, lon, ele, time): - self.trackpoint = '\n\ -%s\n\ -\n\ -\n' % (lat, lon, ele, time) - with open(self.filename,'a') as file: - file.write(self.trackpoint) - - def close(self): - with open(self.filename,'a') as file: - file.write(self.footer) diff --git a/PyTracker/client.py b/PyTracker/client.py deleted file mode 100644 index 3494edc..0000000 --- a/PyTracker/client.py +++ /dev/null @@ -1,27 +0,0 @@ -# Client program - -from socket import * - -# Set the socket parameters -host = "localhost" -port = 49152 -buf = 1024 -addr = (host,port) - -# Create socket -UDPSock = socket(AF_INET,SOCK_DGRAM) - -def_msg = "===Enter message to send to server==="; -print "\n",def_msg - -# Send messages -while (1): - data = raw_input(">> ") - if not data: - break - else: - UDPSock.sendto(data,addr) - print "Sending message", data - -# Close socket -UDPSock.close() diff --git a/PyTracker/server.py b/PyTracker/server.py deleted file mode 100644 index 038d29a..0000000 --- a/PyTracker/server.py +++ /dev/null @@ -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) diff --git a/PyTracker/tracking.txt b/PyTracker/tracking.txt deleted file mode 100644 index 9cfa575..0000000 --- a/PyTracker/tracking.txt +++ /dev/null @@ -1,16 +0,0 @@ -ONLY WAY OF DATA TRANSFER: -CLIENT --> SERVER - -PASSWORD_HASH is in md5 -Structure: - -(USERNAME,PASSWORD_HASH,ACTION,DATA) - -ACTION == ("START" | "TRANSMIT" | "STOP") - -DATA == ("" | POSITION, TIME/DATE | "") - -POSITION == (LAT, LON, HEIGHT) - -Only one track may be open for each user.. so if the user requests START and -another track is open it gets closed immediately