def _upload(self, remote, bitmap): while True: # Bitmap holds (resource, num) tuples. Sort them using path and block num. bitmap.sort(key=lambda item: (item[0].path[0] == ThreadDfuServer. IMAGE_URI, item[1])) resource, num = bitmap.pop(0) payload, more = extract_block(resource.data, num, ThreadDfuServer.BLOCK_SZX) logger.debug("Uploading resource {} block {} to {}".format( resource.path, num, remote.addr)) self._send_block(remote, resource.path, num, more, ThreadDfuServer.BLOCK_SZX, payload) self.bmp_received_event.clear() if len(bitmap): if (num % ThreadDfuServer.SPBLK_SIZE == 0) or (( (num + 1) % ThreadDfuServer.SPBLK_SIZE) == 0): delay = ThreadDfuServer.ERASE_DELAY else: delay = 1.0 / self.opts.rate time.sleep(delay) else: self.upload_done_event.set() self.bmp_received_event.wait()
def _upload(self, remote, bitmap): while True: # Bitmap holds (resource, num) tuples. Sort them using path and block num. bitmap.sort(key = lambda item : (item[0].path[0] == ThreadDfuServer.IMAGE_URI, item[1])) resource, num = bitmap.pop(0) payload, more = extract_block(resource.data, num, ThreadDfuServer.BLOCK_SZX) logger.debug("Uploading resource {} block {} to {}".format(resource.path, num, remote.addr)) total_block_count = _block_count(len(resource.data), ThreadDfuServer.BLOCK_SZX) self._update_progress_bar(remote.addr, self.clients[remote], num, total_block_count) self._send_block(remote, resource.path, num, more, ThreadDfuServer.BLOCK_SZX, payload) if (self.clients[remote].last_block is None) or (self.clients[remote].last_block < num): self.clients[remote].last_block = num self.bmp_received_event.clear() if len(bitmap): if (num % ThreadDfuServer.SPBLK_SIZE == 0) or (((num + 1) % ThreadDfuServer.SPBLK_SIZE) == 0): delay = ThreadDfuServer.ERASE_DELAY else: delay = 1.0/self.opts.rate time.sleep(delay) else: self.upload_done_event.set() self.bmp_received_event.wait()