213
class LocationGpsReader():
215
BEARING_HOLD_SPEED = 2.5 # km/h
217
def __init__(self, cb_error, cb_changed):
218
logger.info("Using liblocation GPS device")
220
control = location.GPSDControl.get_default()
221
device = location.GPSDevice()
222
control.set_properties(preferred_method = location.METHOD_CWP | location.METHOD_ACWP | location.METHOD_GNSS | location.METHOD_AGNSS, preferred_interval=location.INTERVAL_1S)
223
control.connect("error-verbose", cb_error)
224
device.connect("changed", cb_changed)
225
self.last_gps_bearing = 0
226
self.control = control
235
def get_error_from_code(error):
236
if error == location.ERROR_USER_REJECTED_DIALOG:
237
return "Requested GPS method not enabled"
238
elif error == location.ERROR_USER_REJECTED_SETTINGS:
239
return "Location disabled due to change in settings"
240
elif error == location.ERROR_BT_GPS_NOT_AVAILABLE:
241
return "Problems with BT GPS"
242
elif error == location.ERROR_METHOD_NOT_ALLOWED_IN_OFFLINE_MODE:
243
return "Requested method is not allowed in offline mode"
244
elif error == location.ERROR_SYSTEM:
245
return "System error"
247
def fix_from_tuple(self, f, device):
249
# check if this is an actual fix
250
if (not f[1] & (location.GPS_DEVICE_LATLONG_SET | location.GPS_DEVICE_ALTITUDE_SET | location.GPS_DEVICE_TRACK_SET)):
253
# location independent data
254
a.sats = device.satellites_in_use
255
a.sats_known = device.satellites_in_view
261
# if this fix is too old, discard it
262
if f[2] == f[2]: # is not NaN
263
a.timestamp = datetime.utcfromtimestamp(f[2])
265
a.timestamp = datetime.utcfromtimestamp(0)
267
Fix.min_timediff = min(Fix.min_timediff, datetime.utcnow() - a.timestamp)
268
# if this fix is too old, discard it
269
if ((datetime.utcnow() - a.timestamp) - Fix.min_timediff).seconds > LocationGpsReader.TIMEOUT:
270
logger.info("Discarding fix: Timestamp diff is %d, should not be > %d" % (((datetime.utcnow() - a.timestamp) - Fix.min_timediff).seconds, LocationGpsReader.TIMEOUT))
273
# now on for location dependent data
274
#if f[10] > Fix.BEARING_HOLD_EPD:
275
# a.bearing = Fix.last_bearing
279
if a.speed > self.BEARING_HOLD_SPEED:
281
self.last_gps_bearing = a.bearing
283
a.bearing = self.last_gps_bearing
285
# Fix.last_bearing = a.bearing
286
a.position = geo.Coordinate(f[4], f[5])
289
a.error_bearing = f[10]
183
293
class FakeGpsReader():
191
def __init__(self, gui):
193
self.status = "faking..."
194
self.current_lat, self.current_lon = (self.START_LAT, self.START_LON)
299
def __init__(self, something):
300
self.status = "Fake GPS reader."
302
self.data = [x.split('\t') for x in self.TESTDATA.split("\n")]
307
return geo.Coordinate(50.0000798795372000, 6.9949468020349700)
196
309
def get_data(self):
198
self.current_lat += self.INC
199
self.current_lon += self.INC
311
if self.index < len(self.data) - 1:
313
if self.data[self.index][0] == '0':
315
pos = geo.Coordinate(float(self.data[self.index][0]), float(self.data[self.index][1]))
317
if self.lastpos != None:
318
bearing = self.lastpos.bearing_to(pos)
201
position =geo.Coordinate(self.current_lat, self.current_lon),
b'\\ No newline at end of file'
331
error = random.randrange(10, 100),
338
50.0000000000000000 7.0000000000000000
339
49.9999706633389000 7.0001229625195300
340
49.9997950624675000 7.0003442447632600
341
49.9997997563332000 7.0004659499973100
342
49.9997218046337000 7.0005903374403700
343
49.9995578546077000 7.0006271339952900
344
49.9994435254484000 7.0008635874837600
345
49.9993037991226000 7.0009828619659000
346
49.9992146994919000 7.0010608136653900
347
49.9991217441857000 7.0012173876166300
348
49.9990843608975000 7.0012444611638800
349
49.9990095943213000 7.0015110895037700
350
49.9988885596395000 7.0016821641475000
354
49.9987537786365000 7.0018086470663600
355
49.9985118769109000 7.0020990800112500
356
49.9983842205256000 7.0021572504192600
357
49.9982605036348000 7.0022816378623300
358
49.9980872496963000 7.0023336894810200
359
49.9979986529797000 7.0024224538356100
360
49.9979185219854000 7.0025429017841800
361
49.9978181067854000 7.0025481823831800
362
49.9976762011647000 7.0025224499404400
363
49.9975882750005000 7.0024726614356000
364
49.9974449444562000 7.0023075379431300
365
49.9973412603140000 7.0022041890770200
366
49.9972049705684000 7.0021101441234400
370
49.9970952514559000 7.0020336173474800
371
49.9969987757504000 7.0019501335918900
372
49.9968421179801000 7.0017190445214500
373
49.9967520125210000 7.0016104150563500
374
49.9966504238546000 7.0015143584460000
375
49.9965638387948000 7.0014302041381600
376
49.9964761640877000 7.0013357400894200
377
49.9963049218059000 7.0011528469622100
378
49.9962143134326000 7.0009845383465300
379
49.9961593281478000 7.0008703768253300
380
49.9960857350379000 7.0007528625428700
381
49.9960248824209000 7.0006081908941300
382
49.9959259759635000 7.0004951190203400
383
49.9958231300116000 7.0003485195338700
384
49.9957155063748000 7.0002043507993200
385
49.9956013448536000 7.0000658817589300
386
49.9954995047301000 6.9999083019793000
387
49.9954301863909000 6.9997342936694600
388
49.9954084772617000 6.9995050486177200
389
49.9953969940543000 6.9992866162210700
390
49.9965626653284000 6.9970068223774400
391
49.9966021440923000 6.9968105182051700
392
49.9968151282519000 6.9966180697083500
393
49.9971344787627000 6.9964923411607700
394
49.9972403421998000 6.9964339192956700
395
49.9973804876208000 6.9963862262666200
396
49.9979287479073000 6.9956857506185800
397
49.9980570748448000 6.9955223873257600
398
49.9982320051640000 6.9954270012676700
399
49.9984868150204000 6.9951742030680200
400
49.9985938519239000 6.9949829280376400
401
49.9986792635173000 6.9948330596089400
402
49.9987863004208000 6.9947258550673700
403
49.9990340694785000 6.9947269447147800
404
49.9992224946618000 6.9946833588182900
405
49.9994972534478000 6.9947828520089400
406
49.9996298551559000 6.9948167987167800
407
49.9997046217322000 6.9948615580797200
408
49.9997673183680000 6.9949107598513400
409
49.9999811407179000 6.9948655813932400
410
50.0000479444861000 6.9948898889124400
411
50.0000799633563000 6.9948716163635300
412
50.0000798795372000 6.9949468020349700'''