Changed the file hierarchy.. the 'standard' svn way
git-svn-id: http://www.neo1973-germany.de/svn@154 46df4e5c-bc4e-4628-a0fc-830ba316316d
This commit is contained in:
parent
7e236dc1e0
commit
9cfd388dc2
5 changed files with 0 additions and 244 deletions
|
@ -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()
|
|
@ -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 = '<?xml version="1.0" encoding="UTF-8"?>\n\
|
||||
<gpx version="1.1"\n\
|
||||
creator="WriteGPX - Python Class used in PyTracker.py"\n\
|
||||
xmlns:xsi="http://www.w3.org/XML/1998/namespace"\n\
|
||||
xmlns="http://www.topografix.com/GPX/1/1"\n\
|
||||
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">\n\
|
||||
<trk>\n\
|
||||
<trkseg>\n'
|
||||
self.footer = '</trkseg>\n</trk>\n</gpx>\n'
|
||||
|
||||
with open(self.filename,'a') as file:
|
||||
file.write(self.header)
|
||||
|
||||
def write(self, lat, lon, ele, time):
|
||||
self.trackpoint = '<trkpt lat="%s" lon="%s">\n\
|
||||
<ele>%s</ele>\n\
|
||||
<time>%s</time>\n\
|
||||
</trkpt>\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)
|
|
@ -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()
|
|
@ -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)
|
|
@ -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
|
Loading…
Reference in a new issue