Esempio n. 1
0
    def run(self):
        wait_counter = 0
        while self.stop_event.is_set() == False:

            # If we already have lots of updates pending, send those.
            if len(self.updates) > 4:# and len(self.updates) != 0:
                self.send_to_server()
                self.updates = []
            try:
                data = self.in_socket.receiveData()
                print "Incoming packet: " + str(data.encode('hex_codec'))
                # If we get something, reset the counter
                wait_counter = 0

                packet = Packet(data)
                sender = packet.getOriginId()
                payload = packet.getPayload()

                location = Point(payload.getDecimalLatitude(), payload.getDecimalLongitude(), payload.getElevation())
                game_coords = loc_translate(location)

                # Only send the message if the position is new
                #if self.loc_dict[sender] != game_coords:
                #self.updates.append([str(sender), game_coords])
                self.updates.append([str(randrange(1,5)), [randrange(0,49), randrange(0,49), randrange(0, 20)]])
                #else:
                    #print "MeshForwarder: Speck is already known at %s. Not sending." % game_coords

            except:
                # If no more data, send what we have
                if len(self.updates) > 0:
                    self.send_to_server()

                wait = 0.1
                print "MeshForwarder: No new data received from mesh. Waiting %s sec." % wait
                time.sleep(wait)

                # Stop the thread if we waited for more than ten seconds
                wait_counter += wait
                if wait_counter > 10:
                    print "No data in 10 seconds. Stopping."
                    self.stop()

        print "Mesh Forwarding thread stopped."
Esempio n. 2
0
    def run(self):
        wait_counter = 0
        while self.stop_event.is_set() == False:
            
            # If we already have lots of updates pending, send those.
            if len(self.updates) > 4:
                self.send_to_server()
                self.updates = []
            try:
                data = self.in_socket.receiveData()
                #print "Incoming packet: " + str(data.encode('hex_codec'))
                # If we get something, reset the counter
                wait_counter = 0
                
                packet = Packet(data)
                sender = packet.getOriginId()
                payload = packet.getPayload()
                
                location = Point(payload.getDecimalLatitude(), payload.getDecimalLongitude(), payload.getElevation()) 
                game_coords = loc_translate(location)
                self.updates.append([str(sender), game_coords])
                
            except:
                # If no more data, send what we have
                self.send_to_server()
                
                wait = 0.1
                print "MeshForwarder: No Data received from mesh. Waiting %s sec." % wait
                time.sleep(wait)

                # Stop the thread if we waited for more than ten seconds
                wait_counter += wait
                if wait_counter > 10:
                    print "No data in 10 seconds. Stopping."
                    self.stop()
        
        print "Mesh Forwarding thread stopped."