def set_memory(self, _memory): # Make sure we mirror the DV-ness of the new memory we're # setting, and that we capture the Bank value of any currently # stored memory (unless the special type is provided) and # communicate that to the low-level routines with the special # subclass if isinstance(_memory, ic9x_ll.IC9xMemory) or \ isinstance(_memory, ic9x_ll.IC9xDVMemory): memory = _memory else: if isinstance(_memory, chirp_common.DVMemory): memory = ic9x_ll.IC9xDVMemory() memory.clone(self.get_memory(_memory.number)) else: memory = ic9x_ll.IC9xMemory() memory.clone(self.get_memory(_memory.number)) memory.clone(_memory) self._lock.acquire() self._maybe_send_magic() try: if memory.empty: ic9x_ll.erase_memory(self.pipe, self.vfo, memory.number) else: ic9x_ll.set_memory(self.pipe, self.vfo, memory) memory = ic9x_ll.get_memory(self.pipe, self.vfo, memory.number) except: self._lock.release() raise self._lock.release() self.__memcache[memory.number] = memory
def get_memory(self, number): if isinstance(number, str): try: number = IC9X_SPECIAL[self.vfo][number] except KeyError: raise errors.InvalidMemoryLocation("Unknown channel %s" % number) if number < -2 or number > 999: raise errors.InvalidValueError("Number must be between 0 and 999") if number in self.__memcache: return self.__memcache[number] self._lock.acquire() try: self._maybe_send_magic() mem = ic9x_ll.get_memory(self.pipe, self.vfo, number) except errors.InvalidMemoryLocation: mem = chirp_common.Memory() mem.number = number if number < self._upper: mem.empty = True except: self._lock.release() raise self._lock.release() if number > self._upper or number < 0: mem.extd_number = util.get_dict_rev(IC9X_SPECIAL, [self.vfo][number]) mem.immutable = [ "number", "skip", "bank", "bank_index", "extd_number" ] self.__memcache[mem.number] = mem return mem