当前位置: 首页>>代码示例>>Python>>正文


Python Packet.getPayload方法代码示例

本文整理汇总了Python中Packet.Packet.getPayload方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.getPayload方法的具体用法?Python Packet.getPayload怎么用?Python Packet.getPayload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Packet.Packet的用法示例。


在下文中一共展示了Packet.getPayload方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_init

# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import getPayload [as 别名]
def send_init():
    # Send initialisation information from mesh
    print "Connecting to mesh network..."
    global mesh_listening_socket, mesh_sending_socket, n_players, base_location
    
    mesh_listening_socket = SocketConnection('localhost')
    
    # Perform initialisation actions with mesh: get location and assign addresses.
    while True:
        if mesh_listening_socket.connectAsReceiver():
            mesh_sending_socket = SocketConnection('', 29877)
            if mesh_sending_socket.connectAsSender():
                
                # Start the connection to the mesh
                print "Sending init packet to mesh"
                mesh_sending_socket.sendData('*')
                
                # Get the base station location packet
                firstData = mesh_listening_socket.receiveData()
                print "First Data: " + firstData.encode('hex_codec')
                first_packet = Packet(firstData)
                first_payload = first_packet.getPayload()
                print first_payload
                
                mesh_listening_socket.setTimeout(1.0)
                n_players = 3
                # Assign addresses to the expected number of nodes
                s_time = time.time()
                while (len(id_dict) <= 1):
                    if (time.time() > s_time + 10):
                        break;
                    print "Time remaining: " + str(int(s_time + 10 - time.time() + 0.5))
                    try:
                        data = mesh_listening_socket.receiveData()
                        
                        packet = Packet(data)
                        if packet.isIdentification():
                            speck_id = packet.getPayload().getId()
                            
                            print "Id request from %s" % speck_id
                            id_dict.append(speck_id) 
                            # Respond to all requests: packet may have dropped
                            assign_address(speck_id)
                            print "Address assigned"
                            # Reset the start time so we wait from last receive
                            s_time = time.time()
                            print "Time Reset"
                    except:
                        print "No Data received. Retrying"
                
                break
            # If creating sockets doesn't work, wait and try again
            else: 
                time.sleep(1)
        else:
            time.sleep(1)
    
    assign_names()
开发者ID:SLIPD,项目名称:Basestation,代码行数:60,代码来源:fake.py

示例2: run

# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import getPayload [as 别名]
    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."
开发者ID:SLIPD,项目名称:Basestation,代码行数:46,代码来源:steve.py

示例3: run

# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import getPayload [as 别名]
    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."
开发者ID:SLIPD,项目名称:Basestation,代码行数:39,代码来源:steveping.py

示例4: SocketConnection

# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import getPayload [as 别名]
try:
	listeningSocket = SocketConnection('localhost')
		
	if(listeningSocket.connectAsReceiver()):
		sendingSocket = SocketConnection('', 29877)
		if(not sendingSocket.connectAsSender()):
			print "Could not connect as sender"
		else :
			threading.Thread(target = getKeyInput).start()
			while(True):
				
				data = listeningSocket.receiveData()
				packet = Packet(data)
				print "Current Packet: "
				print packet
				if(packet.isIdentification()):
					print "Identification packet!"
					assignId(packet.getPayload().getId())
				else:
					print "Not Identification"
	else:
		print "Could not connect as receiver"
		
except Exception, e:
	print "Exception: %s" % e
finally:
	print "Finally: "
	quit()

开发者ID:SLIPD,项目名称:Basestation,代码行数:30,代码来源:cap.py

示例5: send_init

# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import getPayload [as 别名]
def send_init():
    # Send initialisation information from mesh
    print "Connecting to mesh network..."
    global mesh_listening_socket, mesh_sending_socket, n_players, base_gps
    
    mesh_listening_socket = SocketConnection('localhost')
    
    # Perform initialisation actions with mesh: get location and assign addresses.
    while True:
        if mesh_listening_socket.connectAsReceiver():
            mesh_sending_socket = SocketConnection('', 29877)
            if mesh_sending_socket.connectAsSender():
                
                # Start the connection to the mesh
                print "Sending init packet to mesh"
                mesh_sending_socket.sendData('*')
                
                # Get the base station location packet
                firstData = mesh_listening_socket.receiveData()
                print "First Data: " + firstData.encode('hex_codec')
                first_packet = Packet(firstData)
                first_payload = first_packet.getPayload()
                print first_payload
                base_gps = Point(first_payload.getDecimalLatitude(), first_payload.getDecimalLongitude(), first_payload.getElevation())
                print "Base GPS: " + str(base_gps)
                
                mesh_listening_socket.setTimeout(1.0)
                                
                # Assign addresses to the expected number of nodes
                s_time = time.time()
                while (len(id_dict) <= n_players):
                    if (time.time() > s_time + 20):
                        break;
                    print "Time remaining: " + str(int(s_time + 20 - time.time() + 0.5))
                    try:
                        data = mesh_listening_socket.receiveData()
                        
                        packet = Packet(data)
                        if packet.isIdentification():
                            speck_id = packet.getPayload().getId()
                            
                            print "Id request from %s" % speck_id
                            
                            # Respond to all requests: packet may have dropped
                            assign_address(speck_id)
                            print "Address assigned"
                            # Reset the start time so we wait from last receive
                            s_time = time.time()
                            print "Time Reset"
                    except:
                        print "No Data received. Retrying"
                
                # Tell the nodes to start using TDMA
                assign_basestation_tdma_info()  
                time.sleep(1)
                print "SENDING PINGS"
                messages = ['Hello','from','slip','group','d']
                counter = -1
                while True:
                        counter += 1
                        counter = counter % len(messages)
                        print "SENDING PING"
                        payload = PayloadMessage()
                        payload.initialise(messages[counter] + "$PING")
                        create_and_send_packet(0xFF,0x01,0x03,0x00,payload)
                        time.sleep(1)
                break
            # If creating sockets doesn't work, wait and try again
            else: 
                time.sleep(1)
        else:
            time.sleep(1)
    
    # Package the assigned addresses for server
    ids_to_send = [str(item) for item in id_dict.values()]
    
    base_location = loc_translate(base_gps)
    
    # Send the itialisation message to the server
    initMessage = {"state": "init", "base_location": base_location,"device_ids": ids_to_send}
    print "INIT MESSAGE: " + str(initMessage)
    pair_stream.send_json(initMessage)
开发者ID:SLIPD,项目名称:Basestation,代码行数:84,代码来源:steveping.py


注:本文中的Packet.Packet.getPayload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。