예제 #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
 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()