コード例 #1
0
    def getSetupPacket(commandType, crownstoneId, adminKey, memberKey,
                       guestKey, meshAccessAddress, ibeaconUUID, ibeaconMajor,
                       ibeaconMinor):
        """
		:param commandType:      	uint8 number
		:param crownstoneId:  		uint8 number
		:param adminKey:      		byteString (no conversion required)
		:param memberKey:     		byteString (no conversion required)
		:param guestKey:      		byteString (no conversion required)
		:param meshAccessAddress: 	hexstring
		:param ibeaconUUID: 		string  (ie. "1843423e-e175-4af0-a2e4-31e32f729a8a")
		:param ibeaconMajor:        uint16 number
		:param ibeaconMinor:        uint16 number
		:return:
		"""
        data = []
        data.append(commandType)
        data.append(crownstoneId)

        data += list(adminKey)
        data += list(memberKey)
        data += list(guestKey)

        if type(meshAccessAddress) is str:
            data += Conversion.hex_string_to_uint8_array(meshAccessAddress)
        else:
            data += Conversion.uint32_to_uint8_array(meshAccessAddress)

        data += Conversion.ibeaconUUIDString_to_reversed_uint8_array(
            ibeaconUUID)
        data += Conversion.uint16_to_uint8_array(ibeaconMajor)
        data += Conversion.uint16_to_uint8_array(ibeaconMinor)

        return ControlPacket(ControlType.SETUP).loadByteArray(data).getPacket()
コード例 #2
0
 def toggleRelay(self, isOn):
     val = 0
     if isOn:
         val = 1
     switchPacket = ControlPacket(
         ControlType.RELAY).loadUInt8(val).getPacket()
     self._send(UartWrapper(UartTxType.CONTROL, switchPacket).getPacket())
コード例 #3
0
ファイル: UsbDevHandler.py プロジェクト: wickyb94/programmer
 def resetCrownstone(self):
     """
         Reset the Crownstone
         :return:
     """
     resetPacket = ControlPacket(ControlType.RESET).getPacket()
     self._send(UartWrapper(UartTxType.CONTROL, resetPacket).getPacket())
コード例 #4
0
 def toggleIGBTs(self, isOn):
     val = 0
     if isOn:
         val = 100
     switchPacket = ControlPacket(
         ControlType.PWM).loadUInt8(val).getPacket()
     self._send(UartWrapper(UartTxType.CONTROL, switchPacket).getPacket())
コード例 #5
0
 def toggleAllowDimming(self, isOn):
     val = 0
     if isOn:
         val = 1
     instructionPacket = ControlPacket(
         ControlType.ALLOW_DIMMING).loadUInt8(val).getPacket()
     self._send(
         UartWrapper(UartTxType.CONTROL, instructionPacket).getPacket())
コード例 #6
0
	def getPwmSwitchPacket(switchState):
		"""
		:param switchState: number [0..1]
		:return:
		"""
		convertedSwitchState = int(min(1, max(0, switchState)) * 100)

		return ControlPacket(ControlType.PWM).loadUInt8(convertedSwitchState).getPacket()
コード例 #7
0
    def uartEcho(self, payloadString):
        # wrap that in a control packet
        controlPacket = ControlPacket(ControlType.UART_MESSAGE).loadString(payloadString).getPacket()
    
        # finally wrap it in an Uart packet
        uartPacket = UartWrapper(UartTxType.CONTROL, controlPacket).getPacket()

        # send over uart
        BluenetEventBus.emit(SystemTopics.uartWriteData, uartPacket)
コード例 #8
0
    def getSetTimePacket(time):
        """
		This is a LOCAL timestamp since epoch in seconds

		so if you live in GMT + 1 add 3600 to the timestamp
		:param time:
		:return:
		"""
        return ControlPacket(ControlType.SET_TIME).loadUInt32(time).getPacket()
コード例 #9
0
	def getLockSwitchPacket(lock):
		"""
		:param lock: bool
		:return:
		"""

		lockByte = 0
		if lock:
			lockByte = 1

		return ControlPacket(ControlType.LOCK_SWITCH).loadUInt8(lockByte).getPacket()
コード例 #10
0
 def setUartMode(self, mode):
     """
         Set UART mode.
         :param mode: : 0=none 1=RX only, 2=TX only, 3=TX and RX
         :return:
     """
     if ((mode < 0) or (mode > 3)):
         return
     controlPacket = ControlPacket(
         ControlType.UART_ENABLE).loadUInt8(mode).getPacket()
     self._send(UartWrapper(UartTxType.CONTROL, controlPacket).getPacket())
コード例 #11
0
    def getSwitchCraftPacket(enabled):
        """
        :param enabled: bool
        :return:
        """

        enabledValue = 0
        if enabled:
            enabledValue = 1

        return ControlPacket(ControlType.ENABLE_SWITCHCRAFT).loadUInt8(
            enabledValue).getPacket()
コード例 #12
0
	def getAllowDimmingPacket(allow):
		"""

		:param allow: bool
		:return:
		"""

		allowByte = 0
		if allow:
			allowByte = 1

		return ControlPacket(ControlType.ALLOW_DIMMING).loadUInt8(allowByte).getPacket()
コード例 #13
0
    def getSetupPacket(crownstoneId, sphereId, adminKey, memberKey, basicKey,
                       serviceDataKey, localizationKey, meshDeviceKey,
                       meshAppKey, meshNetworkKey, ibeaconUUID, ibeaconMajor,
                       ibeaconMinor):
        """
		:param crownstoneId:  		uint8 number
		:param sphereId:  	     	uint8 number
		:param adminKey:      		byteString (no conversion required)
		:param memberKey:     		byteString (no conversion required)
		:param basicKey:      		byteString (no conversion required)
		:param serviceDataKey: 	    byteString (no conversion required)
		:param localizationKey: 	byteString (no conversion required)
		:param meshDeviceKey: 	    byteString (no conversion required)
		:param meshAppKey: 	        byteString (no conversion required)
		:param meshNetworkKey: 	    byteString (no conversion required)
		:param ibeaconUUID: 		string  (ie. "1843423e-e175-4af0-a2e4-31e32f729a8a")
		:param ibeaconMajor:        uint16 number
		:param ibeaconMinor:        uint16 number
		:return:
		"""
        data = []
        data.append(crownstoneId)
        data.append(sphereId)

        data += list(adminKey)
        data += list(memberKey)
        data += list(basicKey)
        data += list(serviceDataKey)
        data += list(localizationKey)

        MDKey = meshDeviceKey
        if type(meshDeviceKey) is str:
            MDKey = Conversion.ascii_or_hex_string_to_16_byte_array(
                meshDeviceKey)

        data += list(MDKey)
        data += list(meshAppKey)
        data += list(meshNetworkKey)

        data += Conversion.ibeaconUUIDString_to_reversed_uint8_array(
            ibeaconUUID)
        data += Conversion.uint16_to_uint8_array(ibeaconMajor)
        data += Conversion.uint16_to_uint8_array(ibeaconMinor)

        return ControlPacket(ControlType.SETUP).loadByteArray(data).getPacket()
コード例 #14
0
    def __switchCrownstone(self, crownstoneId, value):
        """
        :param crownstoneId:
        :param value: 0 .. 1
        :return:
        """

        # forcibly map the input from [any .. any] to [0 .. 1]
        correctedValue = min(1,max(0,value))

        # create a stone switch state packet to go into the multi switch
        stoneSwitchPacket     = StoneMultiSwitchPacket(crownstoneId, correctedValue, 0, IntentType.MANUAL)

        # wrap it in a mesh multi switch packet
        meshMultiSwitchPacket = MeshMultiSwitchPacket(MeshMultiSwitchType.SIMPLE_LIST, [stoneSwitchPacket]).getPacket()

        # wrap that in a control packet
        controlPacket         = ControlPacket(ControlType.MESH_MULTI_SWITCH).loadByteArray(meshMultiSwitchPacket).getPacket()

        # finally wrap it in an Uart packet
        uartPacket            = UartWrapper(UartTxType.CONTROL, controlPacket).getPacket()

        # send over uart
        BluenetEventBus.emit(SystemTopics.uartWriteData, uartPacket)
コード例 #15
0
	def getKeepAliveRepeatPacket():
		return ControlPacket(ControlType.KEEP_ALIVE_REPEAT).getPacket()
コード例 #16
0
 def getResetErrorPacket(errorMask):
     return ControlPacket(
         ControlType.RESET_ERRORS).loadUInt32(errorMask).getPacket()
コード例 #17
0
    def getRelaySwitchPacket(state):
        """
		:param state: 0 or 1
		"""
        return ControlPacket(ControlType.RELAY).loadUInt8(state).getPacket()
コード例 #18
0
 def getDisconnectPacket():
     return ControlPacket(ControlType.DISCONNECT).getPacket()
コード例 #19
0
 def getPutInDFUPacket():
     return ControlPacket(ControlType.GOTO_DFU).getPacket()
コード例 #20
0
 def getResetPacket():
     return ControlPacket(ControlType.RESET).getPacket()
コード例 #21
0
 def validateSetup(self):
     self.core.ble.writeToCharacteristic(
         CSServices.SetupService, SetupCharacteristics.Control,
         ControlPacket(ControlType.VALIDATE_SETUP).getPacket())
コード例 #22
0
	def getSetSchedulePacket(data):
		return ControlPacket(ControlType.SCHEDULE_ENTRY).loadByteArray(data).getPacket()
コード例 #23
0
	def getScheduleRemovePacket(timerIndex):
		return ControlPacket(ControlType.SCHEDULE_REMOVE).loadUInt8(timerIndex).getPacket()