Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
top=found.retrieve("Adv Payload")[0]
except:
return None
#Rebuild that part of the structure
found.payload.remove(top)
#Now decode
result={}
data=top.val
etype = aios.EnumByte("type",self.type.val,{ESType.uid.value:"Eddystone-UID",
ESType.url.value:"Eddystone-URL",
ESType.tlm.value:"Eddystone-TLM",
ESType.eid.value:"Eddystone-EID"})
data=etype.decode(data)
found.payload.append(etype)
if etype.val== ESType.uid.value:
power=aios.IntByte("tx_power")
data=power.decode(data)
found.payload.append(power)
result["tx_power"]=power.val
nspace=aios.Itself("namespace")
xx=nspace.decode(data[:10]) #According to https://github.com/google/eddystone/tree/master/eddystone-uid
data=data[10:]
found.payload.append(nspace)
result["name space"]=nspace.val
nspace=aios.Itself("instance")
xx=nspace.decode(data[:6]) #According to https://github.com/google/eddystone/tree/master/eddystone-uid
data=data[6:]
found.payload.append(nspace)
result["instance"]=nspace.val
def encode(self):
#Generate the payload
if self.type.val == ESType.uid.value:
espayload = self.uid_encoder()
elif self.type.val == ESType.url.value:
espayload = self.url_encoder()
elif self.type.val == ESType.tlm.value:
espayload = self.tlm_encoder()
elif self.type.val == ESType.eid.value:
espayload = self.eid_encoder()
encmsg=b''
for x in self.payload+espayload:
encmsg += x.encode()
mylen=aios.IntByte("Length",len(encmsg))
encmsg = mylen.encode()+encmsg
for x in range(32-len(encmsg)):
encmsg+=b'\x00'
return encmsg
def encode(self):
#Generate the payload
if self.type.val == ESType.uid.value:
espayload = self.uid_encoder()
elif self.type.val == ESType.url.value:
espayload = self.url_encoder()
elif self.type.val == ESType.tlm.value:
espayload = self.tlm_encoder()
elif self.type.val == ESType.eid.value:
espayload = self.eid_encoder()
encmsg=b''
for x in self.payload+espayload:
encmsg += x.encode()
mylen=aios.IntByte("Length",len(encmsg))
encmsg = mylen.encode()+encmsg
for x in range(32-len(encmsg)):
encmsg+=b'\x00'
return encmsg
def encode(self):
#Generate the payload
if self.type.val == ESType.uid.value:
espayload = self.uid_encoder()
elif self.type.val == ESType.url.value:
espayload = self.url_encoder()
elif self.type.val == ESType.tlm.value:
espayload = self.tlm_encoder()
elif self.type.val == ESType.eid.value:
espayload = self.eid_encoder()
encmsg=b''
for x in self.payload+espayload:
encmsg += x.encode()
mylen=aios.IntByte("Length",len(encmsg))
encmsg = mylen.encode()+encmsg
for x in range(32-len(encmsg)):
encmsg+=b'\x00'
return encmsg