本文整理汇总了Python中Packet.decode方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.decode方法的具体用法?Python Packet.decode怎么用?Python Packet.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet.decode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_message
# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import decode [as 别名]
def on_message(client, userdata, msg):
#data fromm device
if (str(msg.topic) == "BeeeOn/data_from"):
print(">>>>>>"+msg.topic+" "+str(msg.payload))
split_msg = msg.payload.split(',')
device_channel = 0
pid_from_device = 0
for i in range(0,4):
pid_from_device = pid_from_device << 8 | int(split_msg[i])
send_list = []
groups = []
for dev in devices:
#finding from whom came the message
if dev.pid == pid_from_device:
groups = dev.group
device_channel = dev.channel
for dev in devices:
if dev.pid == pid_from_device:
continue
#select of equipment in the same channel
for g in groups:
if g in dev.group:
if (int(dev.channel) == int(device_channel)):
send_list.append(dev.id)
#avoiding the duplication
send_list = list(set(send_list))
#send message
for device in devices:
if device.id in send_list:
device.reSendMsg(split_msg)
print "-----------------------------------"
init(autoreset=True)
print "SNIFFER"
print msg.payload
split_msg = msg.payload.split(',')
temp = split_msg[9:]
temp.pop()
packet = "{\"raw\": ["
#first value
packet += "\"0x%02X\"" % int(split_msg[8])
for item in temp:
packet += ",\"0x%02X\"" % int(item)
packet += "]}\n"
p = Packet()
try:
# Convert JSON string into Python nested dictionary/list.
data = json.loads(packet)
except Exception, e:
print("Error")
p.decode(data['raw'])
p.print_link_transfer()
print "-----------------------------------"