コード例 #1
0
    def parseErrorState(self, meshErrorState):
        self.crownstoneId = meshErrorState[0]
        self.hasError = True
        self.errorMode = True
        
        self.errorsBitmask = Conversion.uint8_array_to_uint32([
            meshErrorState[1],
            meshErrorState[2],
            meshErrorState[3],
            meshErrorState[4]
        ])
        
        self.errorTimestamp = Conversion.uint8_array_to_uint32([
            meshErrorState[5],
            meshErrorState[6],
            meshErrorState[7],
            meshErrorState[8]
        ])
        
        self.flagsBitmask = meshErrorState[9]
        self.temperature = meshErrorState[10]

        self.partialTimestamp = Conversion.uint8_array_to_uint16(meshErrorState[11:13])
        self.timestamp = reconstructTimestamp(time.time(), self.partialTimestamp)
    
        if self.crownstoneId == 0:
            self.deprecated = True
コード例 #2
0
ファイル: opCode3_type0.py プロジェクト: wickyb94/programmer
def parseOpCode3_type0(serviceData, data):
    if len(data) == 16:
        # dataType = data[0]

        serviceData.stateOfExternalCrownstone = False

        serviceData.crownstoneId = data[1]
        serviceData.switchState = data[2]
        serviceData.flagsBitmask = data[3]

        # bitmask states
        bitmaskArray = Conversion.uint8_to_bit_array(serviceData.flagsBitmask)

        serviceData.dimmerReady = bitmaskArray[0]
        serviceData.dimmingAllowed = bitmaskArray[1]
        serviceData.hasError = bitmaskArray[2]
        serviceData.switchLocked = bitmaskArray[3]
        serviceData.timeIsSet = bitmaskArray[4]
        serviceData.switchCraftEnabled = bitmaskArray[5]

        serviceData.tapToToggleEnabled = bitmaskArray[6]
        serviceData.behaviourOverridden = bitmaskArray[7]

        serviceData.temperature = Conversion.uint8_to_int8(data[4])
        powerFactor = Conversion.uint8_to_int8(data[5])
        realPower = Conversion.uint16_to_int16(
            Conversion.uint8_array_to_uint16([data[6], data[7]]))

        serviceData.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 <= serviceData.powerFactor < 0.01:
            serviceData.powerFactor = 0.01
        elif -0.01 < serviceData.powerFactor < 0:
            serviceData.powerFactor = -0.01

        serviceData.powerUsageReal = float(realPower) / 8.0
        serviceData.powerUsageApparent = serviceData.powerUsageReal / serviceData.powerFactor

        serviceData.accumulatedEnergy = Conversion.uint32_to_int32(
            Conversion.uint8_array_to_uint32(
                [data[8], data[9], data[10], data[11]]))

        serviceData.partialTimestamp = Conversion.uint8_array_to_uint16(
            [data[12], data[13]])
        serviceData.uniqueIdentifier = serviceData.partialTimestamp

        if serviceData.timeIsSet:
            serviceData.timestamp = reconstructTimestamp(
                time.time(), serviceData.partialTimestamp)
        else:
            serviceData.timestamp = serviceData.partialTimestamp  # this is now a counter

        globalBitmaskArray = Conversion.uint8_to_bit_array(data[14])
        serviceData.behaviourEnabled = globalBitmaskArray[0]

        serviceData.validation = data[15]
コード例 #3
0
def parseOpCode3_type1(serviceData, data):
    if len(data) == 17:
        # opCode = data[0]
        # dataType = data[1]
        
        serviceData.errorMode = True
        
        serviceData.crownstoneId = data[2]
        serviceData.errorsBitmask = Conversion.uint8_array_to_uint32([
            data[3],
            data[4],
            data[5],
            data[6]
        ])
        
        serviceData.errorTimestamp = Conversion.uint8_array_to_uint32([
            data[7],
            data[8],
            data[9],
            data[10]
        ])
        
        serviceData.flagsBitmask = data[11]
        # bitmask states
        bitmaskArray = Conversion.uint8_to_bit_array(serviceData.flagsBitmask)
        
        serviceData.dimmingAvailable   = bitmaskArray[0]
        serviceData.dimmingAllowed     = bitmaskArray[1]
        serviceData.hasError           = bitmaskArray[2]
        serviceData.switchLocked       = bitmaskArray[3]
        serviceData.timeIsSet          = bitmaskArray[4]
        serviceData.switchCraftEnabled = bitmaskArray[5]
        
        serviceData.temperature = Conversion.uint8_to_int8(data[12])

        serviceData.partialTimestamp = Conversion.uint8_array_to_uint16([data[13], data[14]])
        serviceData.uniqueIdentifier = serviceData.partialTimestamp

        if serviceData.timeIsSet:
            serviceData.timestamp = reconstructTimestamp(time.time(), serviceData.partialTimestamp)
        else:
            serviceData.timestamp = serviceData.partialTimestamp # this is now a counter
        
        realPower = Conversion.uint16_to_int16(
            Conversion.uint8_array_to_uint16([
                data[15],
                data[16]
            ])
        )
        
        serviceData.powerUsageReal = float(realPower) / 8.0
        
        # this packet has no validation
        serviceData.validation = 0
コード例 #4
0
    def parseState(self, meshStateItemState):
        self.crownstoneId       = meshStateItemState[0]
        self.switchState        = meshStateItemState[1]
        self.flagsBitmask        = meshStateItemState[2]
        self.temperature        = meshStateItemState[3]
        self.powerFactor        = float(meshStateItemState[4]) / 127
        self.powerUsageReal     = float(Conversion.uint8_array_to_int16(meshStateItemState[5:7])) / 8
        if self.powerFactor == 0:
            self.powerFactor = 1.0
        self.powerUsageApparent = self.powerUsageReal / self.powerFactor
        self.accumulatedEnergy         = Conversion.uint8_array_to_int32(meshStateItemState[7:11])
        self.partialTimestamp   = Conversion.uint8_array_to_uint16(meshStateItemState[11:13])
        self.timestamp          = reconstructTimestamp(time.time(), self.partialTimestamp)

        if self.crownstoneId == 0:
            self.deprecated = True
コード例 #5
0
 def test_TimeConvert1(self):
     reconstructed = reconstructTimestamp(1516206007.7995, 34186)
     self.assertEqual(reconstructed, 1516209546.0)