[chirp_devel] [PATCH 0 of 3] ft8x7 special memories fixes
The patches correct some bugs on special memories management.
# HG changeset patch # User Marco Filippi iz3gme.marco@gmail.com # Date 1334817393 -7200 # Node ID 6a40835ebcd3f9a9c828987c4e81aa992851b570 # Parent a21d0ecdcfd14aa8bcd5acfd1e2c5b3528583b2b [FT857] Fix PMS memories editing Fixes #131
diff --git a/chirp/ft857.py b/chirp/ft857.py --- a/chirp/ft857.py +++ b/chirp/ft857.py @@ -243,7 +243,7 @@ return mem
def _set_special_pms(self, mem): - cur_mem = self._get_special(mem.extd_number) + cur_mem = self._get_special_pms(mem.extd_number)
bitindex = -38 - mem.number if mem.empty:
# HG changeset patch # User Marco Filippi iz3gme.marco@gmail.com # Date 1334817682 -7200 # Node ID f7f98e5d8d1bd29bb0fcf42b8ed959a4ccab8b43 # Parent 6a40835ebcd3f9a9c828987c4e81aa992851b570 [FT857] Protected a debugging print by CHIRP_DEBUG environment variable
diff --git a/chirp/ft857.py b/chirp/ft857.py --- a/chirp/ft857.py +++ b/chirp/ft857.py @@ -226,7 +226,8 @@
bitindex = -38 - mem.number used = ((self._memobj.pmsvisible & self._memobj.pmsfilled) >> bitindex) & 0x01 - print "mem.number %i bitindex %i pmsvisible %i pmsfilled %i used %i" % (mem.number, bitindex, self._memobj.pmsvisible, self._memobj.pmsfilled, used) + if os.getenv("CHIRP_DEBUG"): + print "mem.number %i bitindex %i pmsvisible %i pmsfilled %i used %i" % (mem.number, bitindex, self._memobj.pmsvisible, self._memobj.pmsfilled, used) if not used: mem.empty = True return mem
# HG changeset patch # User Marco Filippi iz3gme.marco@gmail.com # Date 1334846665 -7200 # Node ID 3caf35f8a005be15e9dfc339a9613579e15f02e2 # Parent f7f98e5d8d1bd29bb0fcf42b8ed959a4ccab8b43 [ft8x7] React correctly on deletion of special memories
diff --git a/chirp/ft817.py b/chirp/ft817.py --- a/chirp/ft817.py +++ b/chirp/ft817.py @@ -232,6 +232,8 @@ FIRST_VFOA_INDEX = -21 LAST_VFOA_INDEX = -35
+ SPECIAL_MEMORIES_REV = dict(zip(SPECIAL_MEMORIES.values(), SPECIAL_MEMORIES.keys())) + def sync_in(self): try: self._mmap = clone_in(self) @@ -293,6 +295,9 @@ def get_memory(self, number): if isinstance(number, str): return self._get_special(number) + elif number < 0: + # I can't stop delete operation from loosing extd_number but I know how to get it back + return self._get_special(self.SPECIAL_MEMORIES_REV[number]) else: return self._get_normal(number)
@@ -335,15 +340,18 @@ return mem
def _set_special(self, mem): - cur_mem = self._get_special(mem.extd_number) + if mem.empty: + # can't delete special memories! + return + + cur_mem = self._get_special(self.SPECIAL_MEMORIES_REV[mem.number])
for key in cur_mem.immutable: if cur_mem.__dict__[key] != mem.__dict__[key]: raise errors.RadioError("Editing field `%s' " % key + - "is not supported on this chanel") + "is not supported on this channel")
# TODO add frequency range check for vfo and home memories - if mem.number in range(self.FIRST_VFOA_INDEX, self.LAST_VFOA_INDEX -1, -1): _mem = self._memobj.vfoa[-self.LAST_VFOA_INDEX + mem.number] elif mem.number in range(self.FIRST_VFOB_INDEX, self.LAST_VFOB_INDEX -1, -1): @@ -388,7 +396,7 @@ return
self._memobj.visible[(mem.number-1)/8] |= 1 << (mem.number-1)%8 - self._memobj.filled[(mem.number-1)/8] = self._memobj.visible[(mem.number-1)/8] + self._memobj.filled[(mem.number-1)/8] |= 1 << (mem.number-1)%8 self._set_memory(mem, _mem)
def _get_memory(self, mem, _mem): @@ -522,10 +530,10 @@ } LAST_SPECIAL60M_INDEX = -40
- def get_special_locations(self): - lista = self.SPECIAL_60M.keys() - lista.extend(FT817Radio.get_special_locations(self)) - return lista + SPECIAL_MEMORIES = dict(FT817Radio.SPECIAL_MEMORIES) + SPECIAL_MEMORIES.update(SPECIAL_60M) + + SPECIAL_MEMORIES_REV = dict(zip(SPECIAL_MEMORIES.values(), SPECIAL_MEMORIES.keys()))
def _get_special_60M(self, number): mem = chirp_common.Memory() @@ -544,7 +552,11 @@ return mem
def _set_special_60M(self, mem): - cur_mem = self._get_special_60M(mem.extd_number) + if mem.empty: + # can't delete 60M memories! + return + + cur_mem = self._get_special_60M(self.SPECIAL_MEMORIES_REV[mem.number])
for key in cur_mem.immutable: if cur_mem.__dict__[key] != mem.__dict__[key]: @@ -560,11 +572,14 @@ def get_memory(self, number): if number in self.SPECIAL_60M.keys(): return self._get_special_60M(number) + elif number < 0 and self.SPECIAL_MEMORIES_REV[number] in self.SPECIAL_60M.keys(): + # I can't stop delete operation from loosing extd_number but I know how to get it back + return self._get_special_60M(self.SPECIAL_MEMORIES_REV[number]) else: return FT817Radio.get_memory(self, number)
def set_memory(self, memory): - if memory.extd_number in self.SPECIAL_60M.keys(): + if memory.number in self.SPECIAL_60M.values(): return self._set_special_60M(memory) else: return FT817Radio.set_memory(self, memory) diff --git a/chirp/ft857.py b/chirp/ft857.py --- a/chirp/ft857.py +++ b/chirp/ft857.py @@ -16,6 +16,7 @@
from chirp import ft817, chirp_common, errors, directory from chirp import bitwise +import os
mem_format = """ struct mem_struct{ @@ -81,20 +82,6 @@ """
-SPECIAL_PMS = { # WARNING Index are hard wired in memory management code !!! - "PMS-1L" : -47, - "PMS-1U" : -46, - "PMS-2L" : -45, - "PMS-2U" : -44, - "PMS-3L" : -43, - "PMS-3U" : -42, - "PMS-4L" : -41, - "PMS-4U" : -40, - "PMS-5L" : -39, - "PMS-5U" : -38, -} - - @directory.register class FT857Radio(ft817.FT817Radio): MODEL = "FT-857/897" @@ -181,6 +168,24 @@ FIRST_VFOA_INDEX = -22 LAST_VFOA_INDEX = -37
+ SPECIAL_PMS = { # WARNING Index are hard wired in memory management code !!! + "PMS-1L" : -47, + "PMS-1U" : -46, + "PMS-2L" : -45, + "PMS-2U" : -44, + "PMS-3L" : -43, + "PMS-3U" : -42, + "PMS-4L" : -41, + "PMS-4U" : -40, + "PMS-5L" : -39, + "PMS-5U" : -38, + } + + SPECIAL_MEMORIES = dict(ft817.FT817Radio.SPECIAL_MEMORIES) + SPECIAL_MEMORIES.update(SPECIAL_PMS) + + SPECIAL_MEMORIES_REV = dict(zip(SPECIAL_MEMORIES.values(), SPECIAL_MEMORIES.keys())) + def get_features(self): rf = ft817.FT817Radio.get_features(self) rf.has_cross = True @@ -214,22 +219,20 @@ def process_mmap(self): self._memobj = bitwise.parse(mem_format, self._mmap)
- def get_special_locations(self): - lista = SPECIAL_PMS.keys() - lista.extend(self.SPECIAL_MEMORIES) - return lista - def _get_special_pms(self, number): mem = chirp_common.Memory() - mem.number = SPECIAL_PMS[number] + mem.number = self.SPECIAL_PMS[number] mem.extd_number = number
bitindex = -38 - mem.number - used = ((self._memobj.pmsvisible & self._memobj.pmsfilled) >> bitindex) & 0x01 + used = (self._memobj.pmsvisible >> bitindex) & 0x01 + valid = (self._memobj.pmsfilled >> bitindex) & 0x01 if os.getenv("CHIRP_DEBUG"): - print "mem.number %i bitindex %i pmsvisible %i pmsfilled %i used %i" % (mem.number, bitindex, self._memobj.pmsvisible, self._memobj.pmsfilled, used) + print "mem.number %i bitindex %i pmsvisible %i pmsfilled %i used %i filled %i" % (mem.number, bitindex, self._memobj.pmsvisible, self._memobj.pmsfilled, used, valid) if not used: mem.empty = True + if not valid: + mem.empty = True return mem
_mem = self._memobj.pms[47 + mem.number] @@ -239,20 +242,25 @@ mem.immutable = ["number", "skip", "rtone", "ctone", "extd_number", "dtcs", "tmode", "cross_mode", "dtcs_polarity", "power", "duplex", "offset", - "comment", "empty"] + "comment"]
return mem
def _set_special_pms(self, mem): - cur_mem = self._get_special_pms(mem.extd_number) + cur_mem = self._get_special_pms(self.SPECIAL_MEMORIES_REV[mem.number])
bitindex = -38 - mem.number - if mem.empty: + wasused = (self._memobj.pmsvisible >> bitindex) & 0x01 + wasvalid = (self._memobj.pmsfilled >> bitindex) & 0x01 + + if mem.empty: + if wasvalid and not wasused: + self._memobj.pmsfilled &= ~ (1 << bitindex) self._memobj.pmsvisible &= ~ (1 << bitindex) - self._memobj.pmsfilled = self._memobj.pmsvisible return + self._memobj.pmsvisible |= 1 << bitindex - self._memobj.pmsfilled = self._memobj.pmsvisible + self._memobj.pmsfilled |= 1 << bitindex
for key in cur_mem.immutable: if cur_mem.__dict__[key] != mem.__dict__[key]: @@ -263,13 +271,16 @@ self._set_memory(mem, _mem)
def get_memory(self, number): - if number in SPECIAL_PMS.keys(): + if number in self.SPECIAL_PMS.keys(): return self._get_special_pms(number) + elif number < 0 and self.SPECIAL_MEMORIES_REV[number] in self.SPECIAL_PMS.keys(): + # I can't stop delete operation from loosing extd_number but I know how to get it back + return self._get_special_pms(self.SPECIAL_MEMORIES_REV[number]) else: return ft817.FT817Radio.get_memory(self, number)
def set_memory(self, memory): - if memory.extd_number in SPECIAL_PMS.keys(): + if memory.number in self.SPECIAL_PMS.values(): return self._set_special_pms(memory) else: return ft817.FT817Radio.set_memory(self, memory) @@ -296,10 +307,10 @@ } LAST_SPECIAL60M_INDEX = -52
- def get_special_locations(self): - lista = self.SPECIAL_60M.keys() - lista.extend(FT857Radio.get_special_locations(self)) - return lista + SPECIAL_MEMORIES = dict(FT857Radio.SPECIAL_MEMORIES) + SPECIAL_MEMORIES.update(SPECIAL_60M) + + SPECIAL_MEMORIES_REV = dict(zip(SPECIAL_MEMORIES.values(), SPECIAL_MEMORIES.keys()))
# this is identical to the one in FT817ND_US_Radio but we inherit from 857 def _get_special_60M(self, number): @@ -320,7 +331,11 @@
# this is identical to the one in FT817ND_US_Radio but we inherit from 857 def _set_special_60M(self, mem): - cur_mem = self._get_special_60M(mem.extd_number) + if mem.empty: + # can't delete 60M memories! + return + + cur_mem = self._get_special_60M(self.SPECIAL_MEMORIES_REV[mem.number])
for key in cur_mem.immutable: if cur_mem.__dict__[key] != mem.__dict__[key]: @@ -336,11 +351,14 @@ def get_memory(self, number): if number in self.SPECIAL_60M.keys(): return self._get_special_60M(number) + elif number < 0 and self.SPECIAL_MEMORIES_REV[number] in self.SPECIAL_60M.keys(): + # I can't stop delete operation from loosing extd_number but I know how to get it back + return self._get_special_60M(self.SPECIAL_MEMORIES_REV[number]) else: return FT857Radio.get_memory(self, number)
def set_memory(self, memory): - if memory.extd_number in self.SPECIAL_60M.keys(): + if memory.number in self.SPECIAL_60M.values(): return self._set_special_60M(memory) else: return FT857Radio.set_memory(self, memory)
# HG changeset patch # User Marco Filippi iz3gme.marco@gmail.com # Date 1334846665 -7200 # Node ID 3caf35f8a005be15e9dfc339a9613579e15f02e2 # Parent f7f98e5d8d1bd29bb0fcf42b8ed959a4ccab8b43 [ft8x7] React correctly on deletion of special memories
This and the patch 2/3 needs a bug number :)
def get_memory(self, number): if isinstance(number, str): return self._get_special(number)
elif number < 0:
# I can't stop delete operation from loosing extd_number but I know how to get it back
Is this comment misplaced?
def _set_special(self, mem):
cur_mem = self._get_special(mem.extd_number)
if mem.empty:
# can't delete special memories!
return
Can you throw an exception here like you do when the user tries to delete memory #1? I need to make the UI show that error to the user, and once I do, it would be good to have this one behave the same. Looks like this needs to be done for the other similar places as well.
def get_memory(self, number): if number in self.SPECIAL_60M.keys(): return self._get_special_60M(number)
elif number < 0 and self.SPECIAL_MEMORIES_REV[number] in self.SPECIAL_60M.keys():
# I can't stop delete operation from loosing extd_number but I know how to get it back
Is this one misplaced also?
Thanks for getting this resolved so quickly!
On 19/04/2012 17:18, Dan Smith wrote:
# HG changeset patch # User Marco Filippiiz3gme.marco@gmail.com # Date 1334846665 -7200 # Node ID 3caf35f8a005be15e9dfc339a9613579e15f02e2 # Parent f7f98e5d8d1bd29bb0fcf42b8ed959a4ccab8b43 [ft8x7] React correctly on deletion of special memories
This and the patch 2/3 needs a bug number :)
I'll file a bug later today and resend the two patches I'll use same bug number as all is related to special memories behaviour
def get_memory(self, number): if isinstance(number, str): return self._get_special(number)
elif number< 0:
# I can't stop delete operation from loosing extd_number but I know how to get it back
Is this comment misplaced?
No, is in the right place: I had to add the elif code because on delete get_memory is called using negative index instead of extd_number as usual (and I don't even think to place my hands to UI)
def _set_special(self, mem):
cur_mem = self._get_special(mem.extd_number)
if mem.empty:
# can't delete special memories!
return
Can you throw an exception here like you do when the user tries to delete memory #1? I need to make the UI show that error to the user, and once I do, it would be good to have this one behave the same. Looks like this needs to be done for the other similar places as well.
Will give a try to the throw exception ...
def get_memory(self, number): if number in self.SPECIAL_60M.keys(): return self._get_special_60M(number)
elif number< 0 and self.SPECIAL_MEMORIES_REV[number] in self.SPECIAL_60M.keys():
# I can't stop delete operation from loosing extd_number but I know how to get it back
Is this one misplaced also?
Same as other comment ... it's in correct place.
73 de IZ3GME Marco
participants (3)
-
Dan Smith
-
IZ3GME Marco
-
Marco Filippi IZ3GME