示例#1
0
 def __init__(self):
   threading.Thread.__init__(self)
   global gpsd #bring it in scope
   gpsd = gps("localhost", "2947")
   gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
   self.current_value = None
   self.running = True #setting the thread running to true
示例#2
0
 def __init__(self):
     threading.Thread.__init__(self)
     global gpsd  #bring it in scope
     gpsd = gps("localhost", "2947")
     gpsd = gps(mode=WATCH_ENABLE)  #starting the stream of info
     self.current_value = None
     self.running = True  #setting the thread running to true
示例#3
0
 def __init__(self):
     threading.Thread.__init__(self)
     #starting the stream of info
     self.gpsd = gps(mode=WATCH_ENABLE)
     self.current_value = None
     #setting the thread running to true
     self.running = True
示例#4
0
class GpsPoller(threading.Thread):
        def __init__(self):
                threading.Thread.__init__(self)
        global gpsd #bring it in scope
        gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
        self.current_value = None
        self.running = True #setting the thread running to true
        def run(self):
                global gpsd
        while gpsp.running:
                gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer
	if __name__ == '__main__':
        	gpsp = GpsPoller() # create the thread
        try:
                gpsp.start() # start it up
                while True:
                #It may take a second or two to get good data
                        print ' GPS mode:'
                        print '----------------------------------------'
                        print 'mode        ' , gpsd.fix.mode # all values greather than 1 is a GPS fix.
                while True:
			if gpsmode > 1:
				GPIO.output(24, True)
		if gpsmode < 1:
			GPIO.output(24, False)
示例#5
0
 def __init__(self):
   threading.Thread.__init__(self)
   global gpsd #bring it in scope
   gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
   #gpsd.send([0xB5,0x62,0x06,0x08,0x06,0x00,0x64,0x00,0x01,0x00,01,0x7A,0x12,\n])
   self.current_value = None
   self.running = True #setting the thread running to true
示例#6
0
def createStartSendThread(dataLevel):
    global sendingData
    global tSendCreated1
    global tSendRunning1
    global tSendCreated2
    global tSendRunning2
    gpsd = gps(mode=WATCH_ENABLE | WATCH_NEWSTYLE)

    if (dataLevel == 1):
        if not tSendCreated1:
            sendThread = threading.Thread(target=sendPositionData,
                                          args=[gpsd, dataLevel])
            tSendCreated1 = True
        if not tSendRunning1:
            sendThread.start()
            tSendRunning1 = True

    if (dataLevel == 2):
        if not tSendCreated2:
            sendThread = threading.Thread(target=sendPositionData,
                                          args=[gpsd, dataLevel])
            tSendCreated2 = True
        if not tSendRunning2:
            sendThread.start()
            tSendRunning2 = True
示例#7
0
 def __init__(self):
     logging.info("Starting GPS poller thread")
     threading.Thread.__init__(self)
     global gpsd  #bring it in scope
     gpsd = gps(mode=WATCH_ENABLE)  #starting the stream of info
     self.current_value = None
     self.running = True  #setting the thread running to true
示例#8
0
	def __init__(self, start=True):
		threading.Thread.__init__(self)
		global gpsd #bring it in scope
		self.i = 0 # counter for averaging
		self.average_number = 10 # number of values for average
		gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
		self.data = [float('nan'), float('nan'), float('nan'), float('nan'), [], float('nan')] # averaged data
		self.raw_data = self.data # not averaged data
		self.lat_list = [float('nan')] * self.average_number
		self.long_list = [float('nan')] * self.average_number
		self.alt_list = [float('nan')] * self.average_number
		#data = [gpsd.fix.latitude, gpsd.fix.longitude, gpsd.fix.altitude, gpsd.fix.track, gpsd.satellites, time.time()]

		self.scale = 0.92 # for compass
		self.x_offset = 27 # for compass
		self.y_offset = -133 # for compass
		self.degree_offset = 188 # offset to north in degree

		self.sigma = 0.0000075 # standart-deviation for data; CAUTION: has to be adjusted for average_number;
			      #  av_nmb = 1 --> sigma = 0.00005
			      #  av_nmb = 5 --> sigma = 0.00001
			      #  av_nmb = 10 --> sigma = 0.0000075

		self.is_new = True # tells, whether new data is out of 2-sigma-range since last fetch
		self.last = [0.0, 0.0] # last fetched data

		if (start):
			self.start()
示例#9
0
def getGPSData(gps_obj_type, device, tries):
    gpsd = gps(mode=WATCH_ENABLE | WATCH_NEWSTYLE)

    if gps_obj_type == 'DEVICES':
        # If asked for Devices, we're doing LLD and we just need to search for the DEVICES object and return it.
        while True:
            gps_data = gpsd.next()
            if gps_data['class'] == gps_obj_type:
                return (gps_data)
    else:
        # Reset our attempts counter
        gps_obj_attempts = 0

        while gps_obj_attempts < tries:
            gps_data = gpsd.next()
            # Search for an object of the right class
            if gps_data['class'] == gps_obj_type:

                # Did it come from the correct device?
                if gps_data['device'] == device:
                    return (gps_data)
                else:
                    # We only increment when the correct class fails, so VERSIOn, Device and other objects don't throw things off.
                    gps_obj_attempts = gps_obj_attempts + 1

        # If we get here, we couldn't find the right data on the right device, so throw an error!
        print("GPS data not found. Could not find GPS object type '" +
              gps_obj_type + "' on device '" + device + "' after " +
              str(tries) + " attempts.",
              file=sys.stderr)
        sys.exit(1)
示例#10
0
    def __init__(self, start=True):
        threading.Thread.__init__(self)
        global gpsd  #bring it in scope
        self.i = 0  # counter for averaging
        self.average_number = 1  #5 # number of values for average
        gpsd = gps(mode=WATCH_ENABLE)  #starting the stream of info
        self.data = [
            float('nan'),
            float('nan'),
            float('nan'),
            float('nan'), [],
            float('nan')
        ]
        self.lat_list = [float('nan')] * self.average_number
        self.long_list = [float('nan')] * self.average_number
        self.alt_list = [float('nan')] * self.average_number
        #data = [gpsd.fix.latitude, gpsd.fix.longitude, gpsd.fix.altitude, gpsd.fix.track, gpsd.satellites, time.time()]

        self.scale = 0.92  # for compass
        self.x_offset = 27  # for compass
        self.y_offset = -133  # for compass
        self.degree_offset = 188  # offset to north in degree

        if (start):
            self.start()
 def __init__(self):
     
     # Initialize the Thread class
     Thread.__init__(self)
     
     # Check if the GPS module is connected by checking if /dev/ttyUSB0 exists
     if(os.path.exists('/dev/ttyUSB0')):
     
         try:
     
             # Start gathering the GPS data stream
             self.gpsSession = gps(mode=WATCH_ENABLE)
         
             # Create a variable to store the thread's running status
             self.running = False
             
             # Set the GPS controller status to connected
             RoverStatus.gpsControllerStatus = RoverStatus.ready
         
         except:
             
             # Change the GPS controller status to not connected because USB
             # failed to communicate with the GPS module
             RoverStatus.gpsControllerStatus = RoverStatus.notConnected
         
     else:
     
         # Set the GPS controller status to not connected
         RoverStatus.gpsControllerStatus = RoverStatus.notConnected
示例#12
0
    def __init__(self):
        print("this is init")
        self.ROOT_DIR = os.path.dirname(os.path.abspath(__file__))

        print("Root Directory" + self.ROOT_DIR)
        #self.home = str(Path.home())+"/cameraProject/"
        self.home = self.ROOT_DIR + "/"
        # Inititalize GPS
        gpsd = gps(mode=WATCH_ENABLE | WATCH_NEWSTYLE)
        self.gpsd = gpsd

        # Fetch Intial Storage
        self.storageLeft = self.getStorageleft()

        # Initialize GPIO pins
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(17, GPIO.IN)
        # HiGH for keeping the power ON
        GPIO.setup(18, GPIO.OUT, initial=GPIO.HIGH)
        # HIGH for LED to imdicate processing
        GPIO.setup(24, GPIO.OUT, initial=GPIO.HIGH)
        self.ignitionStatus = GPIO.input(17)
        self.ledON = True
        # Initialize camera
        self.camera = PiCamera()
        self.initDataLogFile()
        self.lengthOfVideo = 60  # in seconds
        print('Init Successfull')
        self.processStarted = True
示例#13
0
def my_gps():
 session = gps(mode=WATCH_ENABLE)
 try:
  while True:
   data = session.next()
   if data['class'] == "TPV":
    os.system('clear')
    print
    print (' GPS Readings')

    print ('latitude      ' , session.fix.latitude)
    print ('longitude     ' , session.fix.longitude)


    print ('velocity (m/s) ' , session.fix.speed)
    print

 except KeyError:
  pass
 except KeyboardInterrupt:
  print
  print ("Closed By User")
 except StopIteration:
  print
  print ("GPSD has stopped")
 finally:
  session = None
示例#14
0
 def __init__(self, iD):
     threading.Thread.__init__(self)
     self.iD = iD
     global gpsd  #bring it in scope
     gpsd = gps(mode=WATCH_ENABLE)  #starting stream of info
     self.current_value = None
     self.running = True  #setting the thread running to true
示例#15
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.logger = logging.getLogger('FlightDataLogger.GpsReader')
     self.logger.info('GPS Reader initializing...')
     self.session = gps("localhost", "2947", mode=WATCH_ENABLE)
     self.currentValue = None
     self.running = True
示例#16
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.daemon = True
     self.gpsd = gps()
     self.gpsd.stream(WATCH_ENABLE | WATCH_NEWSTYLE)
     self.current_value = {}
     self.running = True
def getfix():
    global ts
    whereami = gps(mode=WATCH_ENABLE)
    whereami.next()
    while whereami.data['class'] != 'TPV':
        whereami.next()
    lat = whereami.fix.latitude
    lng = whereami.fix.longitude
    alt = whereami.fix.altitude
    ts = whereami.data['time']
    latlng = str(lat) + "," + str(lng)
    whereami.close()
    apiparams = {
        "latlng": latlng,
        "location_type": "APPROXIMATE",
        "key": apikey
    }
    response = requests.get(mapurl, params=apiparams)
    #If you run into problems you can test the URL output by uncommenting the line below
    #print response.url
    y = json.loads(response.text, object_hook=findloc)
    logout = open(logfile, 'a+')
    logout.write(ts + "\t" + str(lat) + "\t" + str(lng) + "\t" + str(alt) +
                 "\n")
    logout.close()
示例#18
0
 def __init__(self):
   logging.info("Starting GPS poller thread")
   threading.Thread.__init__(self)
   global gpsd #bring it in scope
   gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
   self.current_value = None
   self.running = True #setting the thread running to true
示例#19
0
    def read(self, SIO):
        gpsd = gps(mode=WATCH_ENABLE | WATCH_NEWSTYLE)
        report = gpsd.next()
        retries = 6
        while report['class'] != 'TPV' and retries:
            #print(report['class'])
            report = gpsd.next()
            retries -= 1
        if report['class'] != 'TPV': return False

        tstr = getattr(report, 'time', None)
        self.lat = getattr(report, 'lat', None)
        self.lon = getattr(report, 'lon', None)
        self.alt = getattr(report, 'alt', None)
        self.t = time.time()
        print("GPS", self.t, tstr, self.lat, "N, ", self.lon, "E, ", self.alt,
              "m")

        #print  getattr(report,'epv','nan'),"\t",
        #print  getattr(report,'ept','nan'),"\t",
        #print  getattr(report,'speed','nan'),"\t",
        #print getattr(report,'climb','nan'),"\t"

        if self.lat is not None: SIO.log_readout(self.lat_id, self.lat, self.t)
        if self.lon is not None: SIO.log_readout(self.lon_id, self.lon, self.t)
        if self.alt is not None: SIO.log_readout(self.alt_id, self.alt, self.t)
示例#20
0
    def __init__(self):
        threading.Thread.__init__(self)
        global gpsd

        gpsd = gps(mode=WATCH_ENABLE)
        self.current_value = None
        self.running = True
示例#21
0
    def getPositionData(self):
        try:
            nx = self.gpsd.next()
            position = ""
            # For a list of all supported classes and fields refer to:
            # https://gpsd.gitlab.io/gpsd/gpsd_json.html
            if nx['class'] == 'TPV':
                latitude = getattr(nx, 'lat', "Unknown")
                longitude = getattr(nx, 'lon', "Unknown")
                speed = getattr(nx, 'speed', "Unknown")
                time = getattr(nx, 'time', "Unknown")
                alt = getattr(nx, 'alt', "Unknown")
                position = "Your position: lon = " + str(
                    longitude
                ) + ", lat = " + str(latitude) + ", speed =" + str(
                    speed) + ", time = " + str(time) + ", alt = " + str(alt)
                print(position)
            return position
        except BaseException as e:
            print(str(e))
            subprocess.call('sudo systemctl stop gpsd.socket', shell=True)
            subprocess.call('sudo gpsd /dev/serial0 -F /var/run/gpsd.sock',
                            shell=True)
            gpsd = gps(mode=WATCH_ENABLE | WATCH_NEWSTYLE)
            self.gpsd = gpsd
            print("re initilizing socket")

            return ""
示例#22
0
def gps_data():
    #! /usr/bin/python

    from gps import *
    import time

    gpsd = gps(mode=WATCH_ENABLE | WATCH_NEWSTYLE)
    print 'latitude\tlongitude\tspeed'  # '\t' = TAB to try and output the data in columns.

    try:

        while True:
            report = gpsd.next()  #
            if report['class'] == 'TPV':

                print getattr(report, 'lat', 0.0), "\t",
                print getattr(report, 'lon', 0.0), "\t",
                #print  getattr(report,'epv','nan'),"\t",
                #print  getattr(report,'ept','nan'),"\t",
                print getattr(report, 'speed', 'nan'), "\t"
                time.sleep(1)

    except (KeyboardInterrupt, SystemExit):  #when you press ctrl+c
        print "Done.\nExiting."
        return
示例#23
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.gpsd = gps(mode=WATCH_ENABLE)
     self.current_value = None
     self.running = True
     self.fixAge = 0
     self.exit = threading.Event()
示例#24
0
def main():
    gpsd = gps(mode=WATCH_ENABLE|WATCH_JSON)
    # '\t' = TAB to try and output the data in columns.
    dbUrl = 'mongodb://*****:*****@ds235053.mlab.com:35053/aed'
    client = MongoClient(dbUrl)
    db = client['aed']
    collection = db['gp01']
    moved = False
    try:
        while True:
            report = gpsd.next()
            system("clear")
            print ('latitude\tlongitude\ttime utc\t\taltitude\tspeed' )
            if (report['class'] == 'TPV') & (getattr(report,'lat',0.0) != 0):
                is_moving = False if (getattr(report,'speed', 0.0) <= 2) else True
                moved = moved ^ is_moving
                aed_locate = {
                    'time' : datetime.now(),
                    'lat' : getattr(report,'lat',0.0),
                    'long' : getattr(report,'lon',0.0),
                    'alt' : getattr(report,'alt',0.0),
                    'speed' : getattr(report,'speed',0.0),
                    'moved' : moved
                }
                map_link = 'http://maps.google.com/?q=' + getattr(report,'lat',0.0) + ',' + getattr(report,'lon',0.0)
                print (getattr(report,'lat',0.0),"\t",
                    getattr(report,'lon',0.0),"\t",
                    getattr(report,'time',''),"\t",
                    getattr(report,'alt','nan'),"\t",
                    getattr(report,'speed','nan'),"\t")
                collection.insert_one(aed_locate)

    except (KeyboardInterrupt): #when you press ctrl+c
        webbrowser.open(map_link)        #open current position information in google map
        sys.exit()
示例#25
0
    def __init__(self, window):

        self.gpsd = None
        self.num3DFixes = 0
        self.rollingLat = 0
        self.rollingLon = 0
        self.rollingTrack = 0
        self.rollingSpeed = 0
        self.rollingEpx = 0
        self.rollingEpy = 0
        self.rollingSatsUsed = 0
        self.rollingHdop = 0
        self.rollingWindow = window

        if self.rollingWindow < 3 or self.rollingWindow > 10:
            logging.error('Rolling average window needs to be between 3 or 10')

        # we are going to be a thread
        threading.Thread.__init__(self)

        logging.debug(
            'Setting up gpspoller __init__ class with rolling Average window of: '
            + str(self.rollingWindow))

        try:

            self.gpsd = gps(mode=WATCH_ENABLE)  #starting the stream of info

        except:

            logging.error('GPS thread Ops... gpsd not running right?' +
                          'Hint: sudo /etc/init.d/gpsd start')

        self.running = False
        logging.debug('gpspoller __init__ finished')
示例#26
0
 def start_gpsd (self):
     '''
     method to connect to the gpsd socket, note that the systemd service
     has been disabled as following the following adafruit blogpost:
     
     https://learn.adafruit.com/adafruit-ultimate-gps-on-the-raspberry-pi?view=all
     
     This means that the gpsd daemon needs to be manually started on every
     boot of the pi.
     '''     
     # start the gpsd daemon, if this is a posix system
     if os.name == 'posix':
         os.system ('sudo gpsd /dev/ttyUSB0 -F /var/run/gpsd.sock')
     
     # now, try to create a link to this socket (this will fail on windows, but that is ok)
     try:
         self.ser = gps (mode = WATCH_ENABLE)
         self.bs['gps_comms_on'] = True
     except:
         try:
             del self.ser
         except:
             pass
         self.bs['gps_comms_on'] = False
     
     return
示例#27
0
 def __init__(self):
     threading.Thread.__init__(self)
     global gpsd  #bring it in scope
     gpsd = gps(mode=WATCH_ENABLE, host=HOST,
                port=PORT)  #starting the stream of info
     self.current_value = None
     self.running = True  #setting the thread running to true
示例#28
0
 def __init__(self, gps_data_callback=None):
     super(GPS, self).__init__()
     self.gpsd = gps(mode=WATCH_ENABLE | WATCH_NEWSTYLE)
     self.callback = gps_data_callback
     #               (lat, lon, epx, epy, ts)
     self.last_data = (-1, -1, -1, -1, -1)
     self.has_more_data = True
     self.stop_event = threading.Event()
示例#29
0
    def __init__(self):

        threading.Thread.__init__(self)
        self.daemon = True
        self.paused = True
        self.state = threading.Condition()

        self.gpsd = gps(mode=WATCH_ENABLE)
示例#30
0
 def __init__(self, queue):
     super().__init__()
     self.gpsd = None  # bring it in scope
     self.gpsd = gps(mode=WATCH_ENABLE)  # starting the stream of info
     self.current_value = None
     self.queue = queue
     self.latitude = None
     self.longitude = None
示例#31
0
 def __init__(self, conf, logger, queue):
     threading.Thread.__init__(self)
     self.session = gps(mode=WATCH_ENABLE)
     self.conf = conf
     self.logger = logger
     self.queue = queue
     self.last_speed = 1.0
     self.nofix = False
示例#32
0
 def __init__(self):
     global session
     threading.Thread.__init__(self)
     #
     session = gps(mode=WATCH_ENABLE)
     self.current_value = None
     # Der Thread wird ausgefuehrt
     self.running = True
示例#33
0
 def __init__(self, conf, logger, queue):
     threading.Thread.__init__(self)
     self.session = gps(mode=WATCH_ENABLE)
     self.conf = conf
     self.logger = logger
     self.queue = queue
     self.last_speed = 1.0
     self.nofix = False
示例#34
0
	def __init__(self, wifiNetworks, interval):
		self.stopThread = threading.Event()
		self.wifiNetworks = wifiNetworks
		self.interval = interval
		self.setWirelessInterface(None)
		self.session = gps(mode=WATCH_ENABLE)
		self.scanning = False
		threading.Thread.__init__(self)
示例#35
0
    def __init__(self):
        threading.Thread.__init__(self)
        global gpsd

        # starting the stream of info
        gpsd = gps(mode=WATCH_ENABLE)
        self.current_value = None
        self.running = True
示例#36
0
 def __init__(self):
   threading.Thread.__init__(self)
   global gpsd
   
   # starting the stream of info
   gpsd = gps(mode=WATCH_ENABLE)
   self.current_value = None
   self.running = True
示例#37
0
 def __init__(self):
     threading.Thread.__init__(self)
     global gpsd  #bring it in scope
     gpsd = gps(mode=WATCH_ENABLE)  #starting the stream of info
     self.current_value = None
     self.running = True  #setting the thread running to true
     writeLog(url, "[INFO] GPS Poller Start",
              "GPS initialized successfully")
示例#38
0
 def __init__(self):
     threading.Thread.__init__(self)
     global gpsd  #bring it in scope
     global ppid4
     ppid4 = os.getpid()
     gpsd = gps(mode=WATCH_ENABLE)  #starting the stream of info
     self.current_value = None
     self.running = True  #setting the thread running to true
示例#39
0
def gps_setup():
    try:
        ## lobal for GPS polling thread.
        global gps
        gps = gps(mode=WATCH_ENABLE)
    except:
        print("No GPS.")
        sys.exit()
示例#40
0
 def __init__(self, wifiNetworks, interval):
     self.stopThread = threading.Event()
     self.wifiNetworks = wifiNetworks
     self.interval = interval
     self.setWirelessInterface(None)
     self.session = gps(mode=WATCH_ENABLE)
     self.scanning = False
     threading.Thread.__init__(self)
示例#41
0
文件: GPS.py 项目: 14nguyenh/vBox
    def __init__(self,):
        super(GPSReader, self).__init__()

        try:
            SharedData.gpsd = gps(mode=WATCH_ENABLE)
            self.connected = True
        except socket.error:
            print "\tGPSReader: gpsd server is not available. GPSReader disabled."
            self.connected = False
示例#42
0
 def __init__(self):
     threading.Thread.__init__(self)
     #bring it in scope
     global gpsd
     #starting the stream of info
     gpsd = gps(mode=WATCH_ENABLE)
     self.current_value = None
     #setting the thread running to true
     self.running = True
示例#43
0
	def __init__(self):
		rospy.init_node('GPSD')
                self.session = gps()
		self.session.stream(WATCH_ENABLE|WATCH_NEWSTYLE)
		self.currentVal = None
		self.fixPublisherLL = rospy.Publisher('fixLL', GPSFix)
                self.fixPublisherUTM = rospy.Publisher('fix', NavSatFix)
                self.currentFixLL = GPSFix()
                self.currentFixForUTM = NavSatFix()
示例#44
0
	def __init__(self):
		rospy.init_node('gpsd_client')
		#threading.Thread.__init__(self)
		self.session = gps()
		self.session.stream(WATCH_ENABLE|WATCH_NEWSTYLE)
		self.current_value = None
		self.fixpub = rospy.Publisher('gps/fix', GPSFix)
		self.statuspub = rospy.Publisher('gps/status', GPSStatus)
		self.current_fix = GPSFix()
示例#45
0
	def __init__(self):
		threading.Thread.__init__(self)
		# Call global variable into scope
		global gpsd 
		# Starting datastream from GPS
		gpsd = gps(mode=WATCH_ENABLE) 
		self.current_value = None
		# Setting the thread running to true
		self.running = True 
示例#46
0
  def __init__(self):

    threading.Thread.__init__(self)
    global gpsd #bring it in scope
 #   global logging

#    logging.info('Init GPS')
    gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
    self.current_value = None
    self.running = True #setting the thread running to true
示例#47
0
    def run(self):

        gpsd = gps(mode=WATCH_ENABLE)   # starting the stream of info

        try:
            while True:
                self.current_value = gpsd.next()

        except StopIteration:
            pass
示例#48
0
	def latlon():
		gpsd = gps(mode = WATCH_ENABLE)

		try:
			while True:
				report = gpsd.next()
				if report['class'] == 'TPV':
					gpsd.close()
					return report['lat'], report['lon']

		except:
			return None, None
示例#49
0
  def __init__(self):
	result = False
	while not result:
		try:
			threading.Thread.__init__(self)
			global gpsd #bring it in scope
			gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE) #starting the stream of info
			self.current_value = None
			self.running = True #setting the thread running to true
			result = True
		except:
			pass
示例#50
0
    def __init__(self, freq):
        threading.Thread.__init__(self)

        self.gpsd = gps(mode=WATCH_ENABLE)  # starting the stream of info

        self.running = False

        self.data_set = GpsDataset()
        self.new_data_set = GpsDataset()
        self.new = False

        self.period = 1/freq
示例#51
0
 def __init__(self, threadID, name):
    threading.Thread.__init__(self)
    self.threadID = threadID
    self.name = name
    self.gpsd = gps(mode=WATCH_ENABLE)
    self.current_value = None
    self.running = True
    self.latitude = 0
    self.longitude = 0
    self.speed = 0
    self.compass = 0
    self.datetime = 0
示例#52
0
  def __init__(self, h, p, d):
    self.host = h
    self.port = p
    self.device = d

    self.update_daemon()

    threading.Thread.__init__(self)
    global gpsd #bring it in scope
    #gpsd = gps.gps("localhost", "99")
    gpsd = gps(self.host, self.port, mode=WATCH_ENABLE) #starting the stream of info
    self.current_value = None
    self.running = True #setting the thread running to true
 def run(self):
     while not self.stopped:
         try:
             self.session = gps(mode=WATCH_ENABLE)
             while not self.stopped:
                 try:
                     self.session.next()
                     if(self.session.fix.mode == MODE_2D or self.session.fix.mode == MODE_3D):
                         self.data = GpsData()
                         try:
                             self.data.time = dateparse(self.session.fix.time)
                         except:
                             self.data.time = datetime.utcnow()
                         self.data.latitude = self.session.fix.latitude
                         self.data.longitude = self.session.fix.longitude
                         self.data.sats = len(filter(lambda x: str(x)[-1:]=='y', self.session.satellites))
                         if not(isnan(self.session.fix.altitude)):
                             self.data.altitude = self.session.fix.altitude
                         else:
                             self.data.altitude = 0
                         if not(isnan(self.session.fix.speed)):
                             self.data.speed = self.session.fix.speed
                         else:
                             self.data.speed = 0
                         if not(isnan(self.session.fix.track)):
                             self.data.track = self.session.fix.track
                         else:
                             self.data.track = 0
                     sleep(0.1)
                 except:
                     print("[GPS] gpsd polling failed. Retrying..")
                     sleep(2)
                     self.session = gps(mode=WATCH_ENABLE)
         except StopIteration:
             break
         except:
             print("[GPS] gpsd connection failed. Is it running? Retrying..")
             sleep(2)
示例#54
0
def gpsLocation():
    #prerequisite - start gpsd
    #sudo gpsd -b /dev/ttyUSB0 -F /var/run/gpsd.sock
    try:
        gpsd = gps(mode=WATCH_ENABLE)
        while 1:
            gpsd.next()
            print "lat ", gpsd.fix.latitude
            print "lng ", gpsd.fix.longitude
            print "alt ", gpsd.fix.altitude
            time.sleep(1)
    except:
        print "!!! get gps location error  !!!"
        sys.exit(1)
示例#55
0
    def __init__(self):
        """Initialise GpsController class.

        Initialise the GpsController class using parameters passed in
        'data'.

        Args:
            self: self.
            data: A dict containing the parameters to be used during
                  setup.

        """
        threading.Thread.__init__(self)
        self.gpsd = gps(mode=WATCH_ENABLE) # starting the stream of info
        self.running = False
示例#56
0
 def __init__(self, tick = 0, gps_dict = data.gps_dict):
   """
   Initialize the thread with gps object and tick.
                  
   @param tick -- time the thread will sleep in seconds (defaults to 0 seconds) 
   @param gps_dict -- reference to a dictionary which will hold current gps data
   """
   
   threading.Thread.__init__(self)
   self.running = True 
   self.tick = tick
   self.gps_dict = gps_dict
   # init session object with gps moddule
   self.session = gps(mode=WATCH_ENABLE) 
   
   print 'GpsPoller initialisiert.'
示例#57
0
def my_gps():
 global x
 global y
 session = gps(mode=WATCH_ENABLE)
 try:
  while True:
   data = session.next()
   if data['class'] == "TPV":
    os.system('clear')
    #m=1
    #x= 30.19 #Kafr ElDawar
    #y= 31.12
    #x=29.94145
    #y=31.21939 #Smouha SidiGaber
    #x=29.90421
    #y=31.204024        #Raml
    x = session.fix.longitude
    print(x)
    y = session.fix.latitude
    print(y)
    cur = con.cursor()
    cur.execute("SELECT AdPicture FROM Ads WHERE AreaID  in ( SELECT AreaID FROM AdsAreas WHERE %s > StartLongitude AND %s < EndLongitude  AND %s > StartLatitude AND %s < EndLatitude )",(x,x,y,y))
    for i in range(cur.rowcount):
       row = cur.fetchone()
       p=subprocess.Popen(["eog","-f",row[0]])
       time.sleep(5)
       #if m==0:
       # z.kill()
       # m=1
       #row = cur.fetchone()
       #z=subprocess.Popen(["eog","-f",row[0]])
       #time.sleep(5)
       #if m==1:
       # p.kill()
        #m=0
       p.kill()
 except KeyError:
  pass
 except KeyboardInterrupt:
  print
  print ("Closed By User")
 except StopIteration:
  print
  print ("GPSD has stopped")
 finally:
  session = None
示例#58
0
文件: spec_proc.py 项目: corebob/burn
 def __init__(self, event):
     """
     Description:
         Initialize the gps thread
     """
     threading.Thread.__init__(self)
     self._stopped = event
     self.gpsd = gps(mode=WATCH_ENABLE)
     self.last_lat = 0
     self.last_epx = 0
     self.last_lon = 0
     self.last_epy = 0
     self.last_alt = 0
     self.last_epv = 0
     self.last_speed = 0
     self.last_eps = 0
     self.last_time = ''
示例#59
0
	def run(self):
		logging.info("GP GPS Listener started")
		logging.debug("GP connecting to GPSd")
		gpsok = 0
		while gpsok == 0:
			try:
				gpsd = gps(mode=WATCH_ENABLE)
				gpsok = 1
			except Exception:
				logging.warn("GL Could not connect to GPSd .. retrying")
				time.sleep(3)
		logging.debug("GP connected to GPSd")
		for report in gpsd:
			GPSListener.lat = gpsd.fix.latitude
			GPSListener.lon = gpsd.fix.longitude
			GPSListener.alt = gpsd.fix.altitude
			GPSListener.fix = gpsd.fix.mode
示例#60
0
def getGPS():
    """
    This functions gets the gps data from the gpsd session already started.
    """
    global debug
    global global_location
    global threadbreak

    counter = 0
    gps_session = ""
    gps_flag = False
    try:
        gps_session = gps(mode=WATCH_ENABLE)
        
        while not threadbreak:
            if counter > 10:
                global_location = ""
            try:
                location = gps_session.next()
                location['lon']
                location['lat']
                if global_location == "":
                    pygame.mixer.music.load('gps.ogg')
                    pygame.mixer.music.play()
                global_location = location
                counter = 0
                time.sleep(0.5)
            except:
                counter = counter + 1
                pass

    except KeyboardInterrupt:
        print 'Exiting received in getGPS() function. It may take a few seconds.'
        threadbreak = True
    except Exception as inst:
        print 'Exception getGPS() function.'
        threadbreak = True
        print 'Ending threads, exiting when finished'
        print type(inst) # the exception instance
        print inst.args # arguments stored in .args
        print inst # _str_ allows args to printed directly
        x, y = inst # _getitem_ allows args to be unpacked directly
        print 'x =', x
        print 'y =', y
        sys.exit(1)