def load(self, data): if len(data) == 16: payload = BufferReader(data) self.validation = payload.getUInt32() self.protocol = payload.getUInt8() self.sessionNonce = payload.getBytes(5) self.validationKey = payload.getBytes(4) else: self.valid = False
def _deserialize(self, reader: BufferReader): self.header.deserialize(reader) self.numArgs = reader.getUInt8() self.argBufs = [] for i in range(0, self.numArgs): argSize = reader.getUInt8() self.argBufs.append(reader.getBytes(argSize))
def fromData(self, data): payload = BufferReader(data) firstByte = payload.getUInt8() if not BehaviourType.has_value(firstByte): self.valid = False return self self.behaviourType = BehaviourType(firstByte) self.intensity = payload.getUInt8() self.profileIndex = payload.getUInt8() self.activeDays = ActiveDays().fromData(payload.getUInt8()) self.fromTime = BehaviourTime().fromData( payload.getBytes(5)) # 4 5 6 7 8 self.untilTime = BehaviourTime().fromData( payload.getBytes(5)) # 9 10 11 12 13 if self.fromTime.valid == False or self.untilTime.valid == False: self.valid = False return self if self.behaviourType == BehaviourType.behaviour: if payload.length >= 14 + 13: self.presence = BehaviourPresence().fromData( payload.getBytes( 13)) # 14 15 16 17 18 19 20 21 22 23 24 25 26 if not self.presence.valid: self.valid = False return self else: self.valid = False return self if self.behaviourType == BehaviourType.smartTimer: if payload.length >= 14 + 13 + 17: presence = BehaviourPresence().fromData(payload.getBytes(17)) if not presence.valid: self.valid = False return self self.endCondition = presence else: self.valid = False return self
def load(self, data): """ Parses data buffer to set member variables. data : list of bytes Raises exception when parsing fails. """ streamBuf = BufferReader(data) count = streamBuf.getUInt8() self.list = [] for i in range(0, count): self.list.append(SwitchHistoryItemPacket(streamBuf.getBytes(SwitchHistoryItemPacket.size())))
def load(self, data): """ Parses data buffer to set member variables. data : list of bytes Raises exception when parsing fails. """ streamBuf = BufferReader(data) self.timestamp = streamBuf.getUInt32() self.switchCommand = streamBuf.getUInt8() self.switchState = SwitchState(streamBuf.getUInt8()) self.source = CommandSourcePacket(streamBuf.getBytes(CommandSourcePacket.size()))
def parseHubData(reader: BufferReader): packet = AdvHubState() packet.crownstoneId = reader.getUInt8() packet.flags = AdvHubFlags(reader.getUInt8()) packet.hubData = reader.getBytes(9) partialTimestamp = reader.getUInt16() reader.skip() packet.validation = reader.getUInt8() packet.uniqueIdentifier = partialTimestamp if packet.flags.timeIsSet: packet.timestamp = reconstructTimestamp(time.time(), partialTimestamp) else: packet.timestamp = partialTimestamp # this is now a counter return packet
def parseMicroappServiceData(reader: BufferReader): packet = AdvMicroappData() packet.flags = AdvMicroappFlags(reader.getUInt8()) packet.microappUuid = reader.getUInt16() packet.microappData = reader.getBytes(8) packet.crownstoneId = reader.getUInt8() packet.partialTimestamp = reader.getUInt16() packet.validation = reader.getUInt8() packet.uniqueIdentifier = packet.partialTimestamp if packet.flags.timeIsSet: packet.timestamp = reconstructTimestamp(time.time(), packet.partialTimestamp) else: packet.timestamp = packet.partialTimestamp # this is now a counter return packet
def _deserialize(self, reader: BufferReader): self.assetMacAddress = Conversion.uint8_array_to_address( bytearray(reader.getBytes(6))) self.crownstoneId = reader.getUInt8() self.rssi = reader.getInt8() self.channel = reader.getUInt8()