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()
def toggleRelay(self, isOn): val = 0 if isOn: val = 1 switchPacket = ControlPacket( ControlType.RELAY).loadUInt8(val).getPacket() self._send(UartWrapper(UartTxType.CONTROL, switchPacket).getPacket())
def resetCrownstone(self): """ Reset the Crownstone :return: """ resetPacket = ControlPacket(ControlType.RESET).getPacket() self._send(UartWrapper(UartTxType.CONTROL, resetPacket).getPacket())
def toggleIGBTs(self, isOn): val = 0 if isOn: val = 100 switchPacket = ControlPacket( ControlType.PWM).loadUInt8(val).getPacket() self._send(UartWrapper(UartTxType.CONTROL, switchPacket).getPacket())
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())
def getPwmSwitchPacket(switchState): """ :param switchState: number [0..1] :return: """ convertedSwitchState = int(min(1, max(0, switchState)) * 100) return ControlPacket(ControlType.PWM).loadUInt8(convertedSwitchState).getPacket()
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)
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()
def getLockSwitchPacket(lock): """ :param lock: bool :return: """ lockByte = 0 if lock: lockByte = 1 return ControlPacket(ControlType.LOCK_SWITCH).loadUInt8(lockByte).getPacket()
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())
def getSwitchCraftPacket(enabled): """ :param enabled: bool :return: """ enabledValue = 0 if enabled: enabledValue = 1 return ControlPacket(ControlType.ENABLE_SWITCHCRAFT).loadUInt8( enabledValue).getPacket()
def getAllowDimmingPacket(allow): """ :param allow: bool :return: """ allowByte = 0 if allow: allowByte = 1 return ControlPacket(ControlType.ALLOW_DIMMING).loadUInt8(allowByte).getPacket()
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()
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)
def getKeepAliveRepeatPacket(): return ControlPacket(ControlType.KEEP_ALIVE_REPEAT).getPacket()
def getResetErrorPacket(errorMask): return ControlPacket( ControlType.RESET_ERRORS).loadUInt32(errorMask).getPacket()
def getRelaySwitchPacket(state): """ :param state: 0 or 1 """ return ControlPacket(ControlType.RELAY).loadUInt8(state).getPacket()
def getDisconnectPacket(): return ControlPacket(ControlType.DISCONNECT).getPacket()
def getPutInDFUPacket(): return ControlPacket(ControlType.GOTO_DFU).getPacket()
def getResetPacket(): return ControlPacket(ControlType.RESET).getPacket()
def validateSetup(self): self.core.ble.writeToCharacteristic( CSServices.SetupService, SetupCharacteristics.Control, ControlPacket(ControlType.VALIDATE_SETUP).getPacket())
def getSetSchedulePacket(data): return ControlPacket(ControlType.SCHEDULE_ENTRY).loadByteArray(data).getPacket()
def getScheduleRemovePacket(timerIndex): return ControlPacket(ControlType.SCHEDULE_REMOVE).loadUInt8(timerIndex).getPacket()