def _program_data_process(self, program_data) -> tuple: """ extract the segment of the program data corresponding to application memory and perform CRC16 calculation """ if self._current_program_data == program_data: return (self._current_program_segment, self._current_checksum) try: program_segment = program_data[self.starting_address * 2: self.starting_address * 2 + self.memory_length * 2] except BaseException as e: raise RuntimeError( "dimension of program does not fit memory") from e try: data = program_segment crc_calculator = CrcCalculator(Crc16.CCITT) checksum = crc_calculator.calculate_checksum(data) logging.info(f"Calculated checksum is {checksum}") except BaseException as e: raise RuntimeError("calculation of CRC failed") from e self._current_program_segment = program_segment self._current_checksum = checksum return (program_segment, checksum)
def __init__(self, macAddress, cfg='/home/pi/nuki/nuki.cfg'): self._charWriteResponse = "" self.parser = nuki_messages.NukiCommandParser() self.crcCalculator = CrcCalculator() self.byteSwapper = ByteSwapper() self.macAddress = macAddress self.config = ConfigParser.RawConfigParser() self.config.read(cfg) self.device = None
def __init__(self, authID='', nukiCommand=None, nonce='', publicKey='', privateKey=''): self.byteSwapper = ByteSwapper() self.crcCalculator = CrcCalculator() self.authID = authID self.command = nukiCommand self.nonce = nonce if nonce == '': self.nonce = nacl.utils.random(24).hex() self.publicKey = publicKey self.privateKey = privateKey
def __init__(self, payload=""): self.crcCalculator = CrcCalculator() self.byteSwapper = ByteSwapper() self.parser = NukiCommandParser() self.command = '' self.payload = payload