Code:
import appuifw, e32
#import miso
import time
import audio
import positioning
import e32db,sys,traceback
import time
import messaging
#import apptools
#import applist
def initialize_gps():
'''This function initializes the GPS. The select_module(module_id) can be used to select the GPS module in this function.
In this case we are using the default GPS (integrated GPS) hence we do not need to select it.'''
appuifw.note(u'Intializing GPS')
global gps_data
global flag1
flag1=True
#Intitialize the global dictionary with some initial dummy value (0.0 in this case)
gps_data = {
'satellites': {'horizontal_dop': 0.0, 'used_satellites': 0, 'vertical_dop': 0.0, 'time': 0.0,'satellites': 0, 'time_dop':0.0},
'position': {'latitude': 0.0, 'altitude': 0.0, 'vertical_accuracy': 0.0, 'longitude': 0.0, 'horizontal_accuracy': 0.0},
'course': {'speed': 0.0, 'heading': 0.0, 'heading_accuracy': 0.0, 'speed_accuracy': 0.0}
}
try:
# Set requesters - it is mandatory to set at least one
positioning.set_requestors([{"type":"service","format":"application","data":"gps_app"}])
# Request for a fix every 0.5 seconds
positioning.position(course=1,satellites=1,callback=cb_gps, interval=500000,partial=0)
print "fa1"
print gps_data['position']['latitude'],gps_data['position']['longitude']
'''
# Sleep for 3 seconds for the intitial fix
print "in init GPS"
print gps_data['satellites']['used_satellites'], gps_data['position']['latitude'], gps_data['position']['longitude'], gps_data['course']['speed']
compare(gps_data['position']['latitude'],gps_data['position']['longitude'])
'''
#e32.ao_sleep(100)
except:
appuifw.note(u'Problem with GPS','error')
def cb_gps(event):
global gps_data
gps_data = event
def print_gps():
print "hello"
#Set time for the script to run. 10 minutes in this case.
time_to_run=10
minutes=time_to_run*60
c=0
# Print the GPS data for 10 minutes.
while (minutes > 0):
print gps_data['satellites']['used_satellites'], gps_data['position']['latitude'], gps_data['position']['longitude'], gps_data['course']['speed']
if gps_data['position']['latitude']<>0 :
break
minutes=minutes-1
e32.ao_sleep(1)
def datab (loc):
#initiate db access
global db
global dbv
db=e32db.Dbms()
dbv=e32db.Db_view()
# name of the database file
dbname = u'c:\\TEST1.db'
#open database, if it does not exist, then create it
try:
db.open(dbname)
except:
db.create(dbname)
db.open(dbname)
#Create the database table
try:
#word = appuifw.query(u"Enter a word", 'text')
word1 = appuifw.query(u"Enter a word", 'number')
# note that the id field is auto-incremented when new rows are added
db.execute(u"CREATE TABLE testgps1 (id counter, lat FLOAT, long FLOAT, dest VARCHAR,mode INTEGER )")
print "Table Created"
except SymbianError:
print "Error Creating table: "
#print traceback.format_exception(*sys.exc_info())
print sys.exc_info()[0]
print sys.exc_info()[1]
print sys.exc_info()[2]
# attempt to insert data
try:
# note that the id field is NOT required, as it auto-increments
db.execute(u"INSERT INTO testgps1 (lat, long,dest,mode) VALUES(%e,%e,'%s',%d)" %( gps_data['position']['latitude'],gps_data['position']['longitude'],loc,word1))
#db.execute(u"INSERT INTO testgps1 (lat, long,dest) VALUES(%e,%e,'%s')" %( a,b,word))
#db.execute("INSERT INTO testgps1(lat,lon,dest) VALUES(" + a + "," + b + ",'" + word + "')")
print "Data Inserted"
except SymbianError:
print "Could not insert data: "
print sys.exc_info()[0]
print sys.exc_info()[1]
print sys.exc_info()[2]
#to fetch the whole dataset
try:
dbv.prepare(db,u'SELECT * FROM testgps1')
for i in range(1,dbv.count_line()+1): #1 to number of rows
dbv.get_line() #grabs the current row
for i in range(1,dbv.col_count()+1):
print dbv.col(i) #prints each column data
dbv.next_line() #move to the next rowset[[Category:Entertainment]]
except SymbianError:
print "failed to read database: "
print sys.exc_info()[0]
print sys.exc_info()[1]
print sys.exc_info()[2]
# close the database
db.close()
def tracker():
db=e32db.Dbms()
dbv=e32db.Db_view()
# name of the database file
dbname = u'c:\\TEST1.db'
#open database, if it does not exist, then create it
try:
db.open(dbname)
except:
db.create(dbname)
db.open(dbname)
while track == 1:
#apptools.list_running_applications([0,0])
curr_lat = gps_data['position']['latitude']
curr_lon= gps_data['position']['longitude']
#apptools.switch_to_background(unicode(app_name))
flag1=True
while(flag1):
dbv.prepare(db,u'SELECT * FROM testgps1')
for i in range(1,dbv.count_line()+1): #1 to number of rows
dbv.get_line() #grabs the current row
flag = True
for j in range(1,dbv.col_count()+1):
#prints each column data
f=dbv.col(2)
g=dbv.col(3)
h=dbv.col(4)
i=dbv.col(5)
lr=(f-0.01)
ur=(f+0.01)
if (gps_data['position']['latitude'] >lr ):
print "in 1st if"
if(gps_data['position']['latitude']<ur):
if(i==1):
appuifw.note(u'Vibrating')
#new(1,0)
flag = False
flag1=False
break
if(i==2):
appuifw.note(u'Sending')
#new(0,1)
else:
appuifw.note(u'Else workin')
print gps_data['position']['latitude'], gps_data['position']['longitude']
dbv.next_line()
if not flag:
break
#apptools.switch_to_foreground(unicode(app_name))
e32.ao_sleep(5)
def background_handler():
#applist.applist()
global track
track=0
if not track or track == 0:
track = 1
appuifw.app.menu = [
(u"Stop Tracker", background_handler)]
#apptools.switch_to_background()
tracker()
elif track == 1:
track = 0
main()
def main():
while True:
addlocationlist = [u"latitude: " + unicode(str(gps_data['position']['latitude'])),
u"longitude: " + unicode(str(gps_data['position']['longitude'])),
u"Add Location",
u"Start Tracker",
u"Refresh"]
location_opt = appuifw.selection_list(choices=addlocationlist)
if location_opt or location_opt == 0:
if location_opt == 2:
cellname = appuifw.query(u"Enter the location name for " + unicode(str(gps_data['position']['latitude'])) + u":", "text")
if cellname:
#cellids[str(cellid)] = str(cellname)
#save_location()
datab(cellname)
appuifw.note(u"Location added!", "info")
elif location_opt == 4:
app_lock.signal()
elif location_opt ==3:
background_handler()
else:
break
initialize_gps()
print_gps()
main()
this might give some error as i am still developing it....