Ejemplo n.º 1
0
 def __init__(self):
     self.device_name = "GPS"
     self.interval = 0
     self.verbose = False
     # GPS Stuff
     self.the_connection = gps3.GPSDSocket()
     self.the_fix = gps3.Fix()
Ejemplo n.º 2
0
    def runGPS(self):
        sense = SenseHat()
        sense.clear()
        sense.set_rotation(90)

        the_connection = gps3.GPSDSocket()
        the_fix = gps3.Fix()

        finalLat = 0
        finalLong = 0

        #Get the Latitude and Longitude
        if self.run == True:
            try:
                for new_data in the_connection:
                    if new_data:
                        the_fix.refresh(new_data)
                    if not isinstance(the_fix.TPV['lat'],
                                      str):  # check for valid data
                        latitude = the_fix.TPV['lat']
                        longitude = the_fix.TPV['lon']
                        finalLat = latitude
                        finalLong = longitude
                        time.sleep(1)
                        self.gentle_close()
                        break
                    if self.run == False:
                        break
                        self.gentle_close()
            except KeyboardInterrupt:
                self.gentle_close()
                the_connection.close()
                print("\nTerminated by user\nGood Bye.\n")

            latString = ""
            longString = ""

            if finalLat < 0:
                latString = "Latitude: " + str(abs(finalLat)) + " South"
            else:
                latString = "Latitude: " + str(finalLat) + " North"

            if finalLong < 0:
                longString = "Longitude: " + str(abs(finalLong)) + " West"
            else:
                longString = "Longitude: " + str(finalLong) + " East"

            self.say(latString)
            sense.show_message(latString, scroll_speed=.045)
            time.sleep(.5)
            self.say(longString)
            sense.show_message(longString, scroll_speed=.045)
Ejemplo n.º 3
0
def read():
    the_connection = gps3.GPSDSocket()
    the_fix = gps3.Fix()

    try:
        for new_data in the_connection:
            if new_data:
                the_fix.refresh(new_data)
            if not isinstance(the_fix.TPV['lat'], str):  # check for valid data
                speed = the_fix.TPV['speed']
                latitude = the_fix.TPV['lat']
                longitude = the_fix.TPV['lon']
                altitude = the_fix.TPV['alt']
                #sleep(2)
	        the_connection.close()
    except:
    	return latitude, longitude, altitude
    return latitude, longitude, altitude
Ejemplo n.º 4
0
def runGPS():
    sense = SenseHat()
    sense.clear()
    sense.set_rotation(90)

    the_connection = gps3.GPSDSocket()
    the_fix = gps3.Fix()

    finalLat = 0
    finalLong = 0

    #Get the Latitude and Longitude
    try:
        for new_data in the_connection:
            if new_data:
                the_fix.refresh(new_data)
            if not isinstance(the_fix.TPV['lat'], str):  # check for valid data
                latitude = the_fix.TPV['lat']
                longitude = the_fix.TPV['lon']
                finalLat = latitude
                finalLong = longitude
                sleep(1)
                break
    except KeyboardInterrupt:
        the_connection.close()
        print("\nTerminated by user\nGood Bye.\n")

    latString = ""
    longString = ""

    if finalLat < 0:
        latString = "Lat: " + str(abs(finalLat)) + " S"
    else:
        latString = "Lat: " + str(finalLat) + " N"

    if finalLong < 0:
        longString = "Long: " + str(abs(finalLong)) + " W"
    else:
        longString = "Long: " + str(finalLong) + " E"

    sense.show_message(latString + " " + longString, scroll_speed=.04)
Ejemplo n.º 5
0
 def run(self):
     print("GPSrunner starting")
     self.quit = False
     self.gpsd_socket = gps3.GPSDSocket()
     self.gpsd_socket.connect(host='localhost', port=2947)
     self.gpsd_socket.watch()
     self.data_stream = gps3.DataStream()
     try:
         for new_data in self.gpsd_socket:
             if new_data:
                 if self.quit:
                     break;
                 self.data_stream.unpack(new_data)
                 with self.mutex:
                     self.speed = self.data_stream.TPV['speed']
                     self.latitude = self.data_stream.TPV['lat']
                     self.longitude = self.data_stream.TPV['lon']
                     self.altitude = self.data_stream.TPV['alt']
                     self.heading = self.data_stream.TPV['track']
                     self.gpsTime = self.data_stream.TPV['time']
                     self.mode = self.data_stream.TPV['mode']
                 # print("Lat: %s Lon: %s Hdg: %s Time: %s" % (self.latitude, self.longitude, self.heading, self.gpsTime))
                 self.buf[self.buf_idx, 0] = float(time.time())
                 try:
                     self.buf[self.buf_idx, 1] = float(self.latitude)                
                     self.buf[self.buf_idx, 2] = float(self.longitude)
                     self.buf[self.buf_idx, 3] = float(self.heading)
                     # self.buf[self.buf_idx, 4] = self.mode
                 except:
                     self.buf[self.buf_idx, 1] = -998.0
                     self.buf[self.buf_idx, 2] = -998.0
                     self.buf[self.buf_idx, 3] = -998.0
                 self.buf_idx = self.buf_idx + 1
                 if self.buf_idx >= self.BUFSZ:
                     self.buf_idx = 0
                 time.sleep(0.5)
     
     finally:
         self.gpsd_socket.close()
         print('GPSrunner Terminated')
Ejemplo n.º 6
0
#! /usr/bin/python3
# coding=utf-8
"""banana"""
import xml.dom.minidom
import gps3
import time
from datetime import datetime, timezone, timedelta
import os
import sys

gps_connection = gps3.GPSDSocket()
gps_fix = gps3.Fix()

the_log = '/tmp/gpx3.gpx'


def start_time():
    """time in the beginning"""
    timestart = str(datetime.utcnow().replace(tzinfo=(timezone(timedelta(0)))))
    return timestart


def close(doc):
    """write file to disk and close"""
    log_write = open(the_log, "w")
    doc.writexml(log_write)
    log_write.close()


if os.path.isfile(the_log):
    doc = xml.dom.minidom.parse(the_log)  # opens the pre-existing
Ejemplo n.º 7
0
# Concept from Jaroslaw Zachwieja <grok!warwick.ac.uk> &  TJ <linux!tjworld.net>
# from their work in gegpsd.py included in gpsd project (http://catb.org/gpsd)
# This is a time limited demo for the curious, or those without a gps.  If it
# doesn't work, you need to use the 'regular' gegps.py and use another gps device,
# as "host='wadda.ddns.net'" will not be up forever. 20141205 Psst, Line #17.
"""creates Google Earth kml file (/tmp/gps3_live.kml) for realtime (4 second GE default) updates of gps coordinates"""
__author__ = 'Moe'
__copyright__ = "Copyright 2014 Moe"
__license__ = "MIT"  # TODO: figure this out and finish requirements
__version__ = "0.1a"

import time
import gps3

the_connection = gps3.GPSDSocket(
    host='wadda.ddns.net'
)  # A demo address TODO: needs work for commandline host selection
the_fix = gps3.Fix()
the_link = '/tmp/gps3_live.kml'  # AFAIK, 'Links' call href on time events or entry/exit  Multiple href may be possible.
the_file = '/tmp/gps3_static.kml'
the_history = []

live_link = (
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
    "<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n"
    "<NetworkLink>\n"
    "    <name>GPS3 Live</name>\n"
    "    <Link>\n"
    "        <href>{0}</href>\n"
    "        <refreshMode>onInterval</refreshMode>\n"
    "    </Link>\n"
Ejemplo n.º 8
0
#!/usr/bin/python
# coding=utf-8
# Concept from Jaroslaw Zachwieja <grok!warwick.ac.uk> &  TJ <linux!tjworld.net>
# from their work in gegpsd.py included in gpsd project (http://catb.org/gpsd)
"""creates Google Earth kml file (/tmp/gps3_live.kml) for realtime (4 second GE default) updates of gps coordinates"""
__author__ = 'Moe'
__copyright__ = "Copyright 2014 Moe"
__license__ = "MIT"  # TODO: figure this out and finish requirements
__version__ = "0.1a"

import time
import gps3

the_connection = gps3.GPSDSocket(
)  # TODO: needs work for commandline host selection
the_fix = gps3.Fix()
the_link = '/tmp/gps3_live.kml'  # AFAIK, 'Links' call href on time events or entry/exit  Multiple href may be possible.
the_file = '/tmp/gps3_static.kml'
the_history = []

live_link = (
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
    "<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n"
    "<NetworkLink>\n"
    "    <name>GPS3 Live</name>\n"
    "    <Link>\n"
    "        <href>{0}</href>\n"
    "        <refreshMode>onInterval</refreshMode>\n"
    "    </Link>\n"
    "</NetworkLink>\n"
    "</kml>").format(
Ejemplo n.º 9
0
 def __init__(self):
     self.socket = gps3.GPSDSocket()
     self.data_stream = gps3.DataStream()