Exemple #1
0
    def load(self, data):
        """
		Parses data buffer to set member variables.

		data : list of bytes

		Raises exception when parsing fails.
		"""
        streamBuf = BufferReader(data)
        self.count = streamBuf.getUInt32()
        self.timestamp = streamBuf.getUInt32()
    def load(self, data):
        """
		Parses data buffer to set member variables.

		data : list of bytes

		Raises exception when parsing fails.
		"""
        streamBuf = BufferReader(data)
        self.minStackEnd = streamBuf.getUInt32()
        self.maxHeapEnd = streamBuf.getUInt32()
        self.minFree = streamBuf.getUInt32()
        self.numSbrkFails = streamBuf.getUInt32()
Exemple #3
0
def _parseErrorPacket(packet, reader: BufferReader):
    packet.crownstoneId     = reader.getUInt8()
    packet.errorsBitmask    = AdvCrownstoneErrorBitmask(reader.getUInt32())
    packet.errorTimestamp   = reader.getUInt32()
    packet.flags            = AdvFlags(reader.getUInt8())
    packet.temperature      = reader.getInt8()
    partialTimestamp        = reader.getUInt16()
    packet.uniqueIdentifier = partialTimestamp

    if packet.flags.timeIsSet:
        packet.timestamp = reconstructTimestamp(time.time(), partialTimestamp)
    else:
        packet.timestamp = partialTimestamp  # this is now a counter
    def _parse(self, reader: BufferReader):
        self.buildVersion = reader.getUInt32()
        self.sdkVersion.parse(reader)
        self.checksum = reader.getUInt16()
        self.checksumHeader = reader.getUInt16()
        self.tests.parse(reader)
        self.functionTrying = reader.getUInt8()
        self.functionFailed = reader.getUInt8()

        self.functionsPassed = []
        functionsPassed = reader.getUInt32()
        for i in range(0, 32):
            if functionsPassed & (1 << i):
                self.functionsPassed.append(i)
    def _parse(self, reader: BufferReader):
        self.fileNameHash = reader.getUInt32()
        self.lineNr = reader.getUInt16()
        self.logLevel = reader.getUInt8()

        flags = reader.getUInt8()
        self.newLine = (flags & (1 << 0)) != 0
    def fromBuffer(self, buf: list):
        reader = BufferReader(buf)

        self.sdkVersionMajor = reader.getUInt8()
        self.sdkVersionMinor = reader.getUInt8()
        self.size = reader.getUInt16()

        self.checksum = reader.getUInt16()
        self.checksumHeader = reader.getUInt16()

        self.appBuildVersion = reader.getUInt32()

        self.startOffset = reader.getUInt16()
        self.reserved = reader.getUInt16()

        self.reserved2 = reader.getUInt32()
 def _deserialize(self, reader: BufferReader):
     self.commandProtocolVersion = reader.getUInt8()
     self.masterVersion = reader.getUInt16()
     self.masterCrc = reader.getUInt32()
     self.freeSpace = reader.getUInt16()
     self.summaries.clear()
     while reader.getRemainingByteCount():
         self.summaries.append(FilterSummaryPacket(reader))
Exemple #8
0
	def _deserialize(self, reader: BufferReader):
		self.fileNameHash = reader.getUInt32()
		self.lineNr = reader.getUInt16()
		self.logLevel = reader.getUInt8()

		flags = reader.getUInt8()
		self.newLine = (flags & (1 << 0)) != 0
		self.reverse = (flags & (1 << 1)) != 0
Exemple #9
0
    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 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 fromData(self, data):
        if len(data) != 13:
            self.valid = False
            return self

        payload = BufferReader(data)
        firstByte = payload.getUInt8()
        if not BehaviourPresenceType.has_value(firstByte):
            self.valid = False
            return self

        self.behaviourType = BehaviourPresenceType(firstByte)
        self.locationIds = self.unpackMask(payload.getUInt64())
        self.delayInSeconds = payload.getUInt32()

        return self
def parseAlternativeState(reader: BufferReader):
    packet = AdvAlternativeState()
    packet.crownstoneId             = reader.getUInt8()
    packet.switchState              = SwitchState(reader.getUInt8())
    packet.flags                    = AdvFlags(reader.getUInt8())
    packet.behaviourMasterHash      = reader.getUInt16()
    packet.assetFilterMasterVersion = reader.getUInt16()
    packet.assetFilterMasterCRC     = reader.getUInt32()
    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 load(self, data):
		"""
		Parses data buffer to set member variables.

		data : list of bytes

		Raises exception when parsing fails.
		"""
		streamBuf = BufferReader(data)

		samplesTypeVal = streamBuf.getUInt8()
		self.samplesType = PowerSamplesType(samplesTypeVal) # Throws exception of value is not in enum
		self.index = streamBuf.getUInt8()
		self.count = streamBuf.getUInt16()
		self.timestamp = streamBuf.getUInt32()
		self.delayUs = streamBuf.getUInt16()
		self.sampleIntervalUs = streamBuf.getUInt16()
		streamBuf.skip(2)
		self.offset = streamBuf.getInt16()
		self.multiplier = streamBuf.getFloat()
		self.samples = []
		for i in range(0, self.count):
			self.samples.append(streamBuf.getInt16())
def parseSetupState(reader: BufferReader):
    packet = AdvCrownstoneSetupState()

    packet.switchState = SwitchState(reader.getUInt8())
    packet.flags = AdvFlags(reader.getUInt8())
    packet.temperature = reader.getInt8()
    powerFactor = reader.getInt8()
    realPower = reader.getInt16()

    packet.powerFactor = float(powerFactor) / 127.0

    # we cannot have a 0 for a power factor.To avoid division by 0, we set it to be either 0.01 or -0.01
    if 0 <= packet.powerFactor < 0.01:
        packet.powerFactor = 0.01
    elif -0.01 < packet.powerFactor < 0:
        packet.powerFactor = -0.01

    packet.powerUsageReal = float(realPower) / 8.0
    packet.powerUsageApparent = packet.powerUsageReal / packet.powerFactor
    packet.errorsBitmask = AdvCrownstoneErrorBitmask(reader.getUInt32())
    packet.uniqueIdentifier = reader.getUInt8()

    return packet
 def _deserialize(self, reader: BufferReader):
     self.id = reader.getUInt8()
     self.crc = reader.getUInt32()
Exemple #16
0
    def _getElementValues(
            self,
            elementType: int,  # TODO: make enum
            elementSize: int,
            elementData: list) -> list:
        bufferReader = BufferReader(elementData)
        dataSize = len(elementData)
        if dataSize % elementSize != 0:
            _LOGGER.warning(
                f"Remaining data with element size of {elementSize} and element data of size {dataSize}"
            )
            return []

        vals = []
        numElements = int(dataSize / elementSize)
        _LOGGER.debug(
            f"dataSize={dataSize} elementSize={elementSize} numElements={numElements}"
        )
        for i in range(0, numElements):
            if elementType == 0:
                # Signed integer
                if elementSize == 1:
                    vals.append(bufferReader.getInt8())
                elif elementSize == 2:
                    vals.append(bufferReader.getInt16())
                elif elementSize == 4:
                    vals.append(bufferReader.getInt32())
                elif elementSize == 8:
                    vals.append(bufferReader.getInt64())
                else:
                    _LOGGER.warning(
                        f"Unknown type: element with type {elementType} and size {elementSize}"
                    )
                    return []

            elif elementType == 1:
                # Unsigned integer
                if elementSize == 1:
                    vals.append(bufferReader.getUInt8())
                elif elementSize == 2:
                    vals.append(bufferReader.getUInt16())
                elif elementSize == 4:
                    vals.append(bufferReader.getUInt32())
                elif elementSize == 8:
                    vals.append(bufferReader.getUInt64())
                else:
                    _LOGGER.warning(
                        f"Unknown type: element with type {elementType} and size {elementSize}"
                    )
                    return []

            elif elementType == 2:
                # Floating point
                if elementSize == 4:
                    vals.append(bufferReader.getFloat())
                else:
                    _LOGGER.warning(
                        f"Unknown type: element with type {elementType} and size {elementSize}"
                    )
                    return []
        return vals