[chirp_devel] [PATCH 0 of 1] Support of PMS in FT817 family
This patch has to be applied over the last pylint series of patches
# HG changeset patch # User Filippi Marco iz3gme.marco@gmail.com # Date 1335724435 -7200 # Node ID 95b0a2ac92588353ab1d97f329cf7b1f08825c35 # Parent 5f6c45e053c37213c388b3a2908793e66672e4cf [FT817] Support for PMS special memories to avoid code duplication PMS memories functions have been moved from ft857 to its ancestor class Feature #154
diff -r 5f6c45e053c3 -r 95b0a2ac9258 chirp/ft817.py --- a/chirp/ft817.py Sat Apr 28 12:03:38 2012 +0200 +++ b/chirp/ft817.py Sun Apr 29 20:33:55 2012 +0200 @@ -99,12 +99,15 @@
#seekto 0x3FD; u8 visible[25]; + u8 pmsvisible;
#seekto 0x417; u8 filled[25]; + u8 pmsfilled;
#seekto 0x431; struct mem_struct memory[200]; + struct mem_struct pms[2];
#seekto 0x1979; struct mem_struct sixtymeterchannels[5]; @@ -153,8 +156,17 @@ FIRST_VFOA_INDEX = -21 LAST_VFOA_INDEX = -35
+ SPECIAL_PMS = { + "PMS-L" : -37, + "PMS-U" : -36, + } + LAST_PMS_INDEX = -37 + + SPECIAL_MEMORIES.update(SPECIAL_PMS) + SPECIAL_MEMORIES_REV = dict(zip(SPECIAL_MEMORIES.values(), SPECIAL_MEMORIES.keys())) + def _read(self, block, blocknum): for _i in range(0, 60): data = self.pipe.read(block+2) @@ -352,6 +364,19 @@ _mem = self._memobj.qmb immutable = ["number", "skip", "rtone", "ctone", "extd_number", "name", "dtcs_polarity", "power", "comment"] + elif mem.number in self.SPECIAL_PMS.values(): + bitindex = -self.LAST_PMS_INDEX + mem.number + used = (self._memobj.pmsvisible >> bitindex) & 0x01 + valid = (self._memobj.pmsfilled >> bitindex) & 0x01 + if not used: + mem.empty = True + if not valid: + mem.empty = True + return mem + _mem = self._memobj.pms[-self.LAST_PMS_INDEX + mem.number] + immutable = ["number", "skip", "rtone", "ctone", "extd_number", + "dtcs", "tmode", "cross_mode", "dtcs_polarity", + "power", "duplex", "offset", "comment"] else: raise Exception("Sorry, special memory index %i " % mem.number + "unknown you hit a bug!!") @@ -362,17 +387,12 @@ return mem
def _set_special(self, mem): - if mem.empty: + if mem.empty and not mem.number in self.SPECIAL_PMS.values(): # can't delete special memories! raise Exception("Sorry, special memory can't be deleted")
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 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, @@ -386,10 +406,34 @@ _mem = self._memobj.home[5 + mem.number] elif mem.number == -1: _mem = self._memobj.qmb + elif mem.number in self.SPECIAL_PMS.values(): + # this case has to be last because 817 pms keys overlap with + # 857 derived class other special memories + bitindex = -self.LAST_PMS_INDEX + mem.number + wasused = (self._memobj.pmsvisible >> bitindex) & 0x01 + wasvalid = (self._memobj.pmsfilled >> bitindex) & 0x01 + if mem.empty: + if wasvalid and not wasused: + # pylint get confused by &= operator + self._memobj.pmsfilled = self._memobj.pmsfilled & \ + ~ (1 << bitindex) + # pylint get confused by &= operator + self._memobj.pmsvisible = self._memobj.pmsvisible & \ + ~ (1 << bitindex) + return + # pylint get confused by |= operator + self._memobj.pmsvisible = self._memobj.pmsvisible | 1 << bitindex + self._memobj.pmsfilled = self._memobj.pmsfilled | 1 << bitindex + _mem = self._memobj.pms[-self.LAST_PMS_INDEX + mem.number] else: raise Exception("Sorry, special memory index %i " % mem.number + "unknown you hit a bug!!")
+ 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 channel") + self._set_memory(mem, _mem)
def _get_normal(self, number): @@ -559,13 +603,13 @@ _block_lengths = [ 2, 40, 208, 182, 208, 182, 198, 53, 130, 118, 130, 130]
SPECIAL_60M = { - "M-601" : -40, - "M-602" : -39, - "M-603" : -38, - "M-604" : -37, - "M-605" : -36, + "M-601" : -42, + "M-602" : -41, + "M-603" : -40, + "M-604" : -39, + "M-605" : -38, } - LAST_SPECIAL60M_INDEX = -40 + LAST_SPECIAL60M_INDEX = -42
SPECIAL_MEMORIES = dict(FT817Radio.SPECIAL_MEMORIES) SPECIAL_MEMORIES.update(SPECIAL_60M) diff -r 5f6c45e053c3 -r 95b0a2ac9258 chirp/ft857.py --- a/chirp/ft857.py Sat Apr 28 12:03:38 2012 +0200 +++ b/chirp/ft857.py Sun Apr 29 20:33:55 2012 +0200 @@ -17,7 +17,6 @@ """FT857 - FT857/US management module"""
from chirp import ft817, chirp_common, errors, directory -import os
@directory.register class FT857Radio(ft817.FT817Radio): @@ -174,7 +173,6 @@ FIRST_VFOA_INDEX = -22 LAST_VFOA_INDEX = -37
- # WARNING Index are hard wired in memory management code !!! SPECIAL_PMS = { "PMS-1L" : -47, "PMS-1U" : -46, @@ -187,8 +185,8 @@ "PMS-5L" : -39, "PMS-5U" : -38, } + LAST_PMS_INDEX = -47
- SPECIAL_MEMORIES = dict(SPECIAL_MEMORIES) SPECIAL_MEMORIES.update(SPECIAL_PMS)
SPECIAL_MEMORIES_REV = dict(zip(SPECIAL_MEMORIES.values(), @@ -227,86 +225,6 @@ _mem.tmode = self.CROSS_MODES_REV[mem.cross_mode] _mem.is_split_tone = 1
- def _get_special_pms(self, number): - mem = chirp_common.Memory() - mem.number = self.SPECIAL_PMS[number] - mem.extd_number = number - - bitindex = 47 + mem.number - 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" % \ - (mem.number, - bitindex, - self._memobj.pmsvisible), - print "pmsfilled %i used %i filled %i" % \ - (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] - - mem = self._get_memory(mem, _mem) - - mem.immutable = ["number", "skip", "rtone", "ctone", - "extd_number", "dtcs", "tmode", "cross_mode", - "dtcs_polarity", "power", "duplex", "offset", - "comment"] - - return mem - - def _set_special_pms(self, mem): - cur_mem = self._get_special_pms(self.SPECIAL_MEMORIES_REV[mem.number]) - - bitindex = 47 + mem.number - wasused = (self._memobj.pmsvisible >> bitindex) & 0x01 - wasvalid = (self._memobj.pmsfilled >> bitindex) & 0x01 - - if mem.empty: - if wasvalid and not wasused: - # pylint get confused by &= operator - self._memobj.pmsfilled = self._memobj.pmsfilled & \ - ~ (1 << bitindex) - # pylint get confused by &= operator - self._memobj.pmsvisible = self._memobj.pmsvisible & \ - ~ (1 << bitindex) - return - - # pylint get confused by |= operator - self._memobj.pmsvisible = self._memobj.pmsvisible | 1 << bitindex - self._memobj.pmsfilled = self._memobj.pmsfilled | 1 << bitindex - - 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 PMS channels") - - _mem = self._memobj.pms[47 + mem.number] - self._set_memory(mem, _mem) - - def get_memory(self, number): - 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.number in self.SPECIAL_PMS.values(): - return self._set_special_pms(memory) - else: - return ft817.FT817Radio.set_memory(self, memory) - @directory.register class FT857USRadio(FT857Radio): """Yaesu FT857/897 (US version)"""
participants (1)
-
Marco Filippi