本文整理汇总了Python中Packet.Packet.isIdentification方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.isIdentification方法的具体用法?Python Packet.isIdentification怎么用?Python Packet.isIdentification使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet.Packet
的用法示例。
在下文中一共展示了Packet.isIdentification方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_init
# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import isIdentification [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()
示例2: SocketConnection
# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import isIdentification [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()
示例3: send_init
# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import isIdentification [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)