def _parse_csv_data_line(self, headers, line): mem = chirp_common.Memory() try: if get_datum_by_header(headers, line, "Mode") == "DV": mem = chirp_common.DVMemory() except OmittedHeaderError: pass for header in headers: try: typ, attr = self.ATTR_MAP[header] except KeyError: continue try: val = get_datum_by_header(headers, line, header) if not val and typ == int: val = None else: val = typ(val) if hasattr(mem, attr): setattr(mem, attr, val) except OmittedHeaderError as e: pass except Exception as e: raise Exception("[%s] %s" % (attr, e)) return self._clean(headers, line, mem)
def do_mode(self, m, rf): def ensure_urcall(call): l = self._wrapper.do("get_urcall_list") l[0] = call self._wrapper.do("set_urcall_list", l) def ensure_rptcall(call): l = self._wrapper.do("get_repeater_call_list") l[0] = call self._wrapper.do("set_repeater_call_list", l) def freq_is_ok(freq): for lo, hi in rf.valid_bands: if freq > lo and freq < hi: return True return False successes = 0 for mode in rf.valid_modes: tmp = copy.deepcopy(m) if mode not in chirp_common.MODES: continue if mode == "DV": tmp = chirp_common.DVMemory() try: ensure_urcall(tmp.dv_urcall) ensure_rptcall(tmp.dv_rpt1call) ensure_rptcall(tmp.dv_rpt2call) except IndexError: if rf.requires_call_lists: raise else: # This radio may not do call lists at all, # so let it slide pass if mode == "FM" and freq_is_ok(tmp.freq + 100000000): # Some radios don't support FM below approximately 30MHz, # so jump up by 100MHz, if they support that tmp.freq += 100000000 tmp.mode = mode if rf.validate_memory(tmp): # A result (of error messages) from validate means the radio # thinks this is invalid, so don't fail the test print('Failed to validate %s: %s' % (tmp, rf.validate_memory(tmp))) continue self.set_and_compare(tmp) successes += 1 if (not successes) and rf.valid_modes: raise TestFailedError("All modes were skipped, " "something went wrong")
def get_memory(self, number): number = _resolve_memory_number(number) bitpos = (1 << (number % 8)) bytepos = number / 8 _mem = self._memobj.memory[number] _used = self._memobj.used_flags[bytepos] is_used = ((_used & bitpos) == 0) if is_used and MODES[_mem.mode] == "DV": mem = chirp_common.DVMemory() mem.dv_urcall = str(_mem.urcall).rstrip() mem.dv_rpt1call = str(_mem.r1call).rstrip() mem.dv_rpt2call = str(_mem.r2call).rstrip() else: mem = chirp_common.Memory() mem.number = number if number < 500: _skip = self._memobj.skip_flags[bytepos] _pskip = self._memobj.pskip_flags[bytepos] if _skip & bitpos: mem.skip = "S" elif _pskip & bitpos: mem.skip = "P" else: mem.extd_number = util.get_dict_rev(_get_special(), number) mem.immutable = [ "number", "skip", "bank", "bank_index", "extd_number" ] if not is_used: mem.empty = True return mem mem.freq = int(_mem.freq) mem.offset = int(_mem.offset) mem.rtone = chirp_common.TONES[_mem.rtone] mem.ctone = chirp_common.TONES[_mem.ctone] mem.tmode = TMODES[_mem.tmode] mem.duplex = DUPLEX[_mem.duplex] mem.mode = MODES[_mem.mode] mem.dtcs = chirp_common.DTCS_CODES[_mem.dtcs] mem.dtcs_polarity = DTCSP[_mem.dtcs_polarity] if _mem.tune_step > 8: mem.tuning_step = 5.0 # Sometimes TS is garbage? else: mem.tuning_step = chirp_common.TUNING_STEPS[_mem.tune_step] mem.name = str(_mem.name).rstrip() return mem
def test_ensure_has_calls_almost_full(self): mem = chirp_common.DVMemory() mem.dv_urcall = 'KK7DS' mem.dv_rpt1call = 'KD7RFI B' mem.dv_rpt2call = 'KD7RFI G' ini_urcalls = ['FOO', 'BAR', 'BAZ', 'BAT', ''] ini_rptcalls = ['FOO', 'BAR', 'BAZ', '', ''] exp_urcalls = list(ini_urcalls) exp_rptcalls = list(ini_rptcalls) exp_urcalls[4] = mem.dv_urcall exp_rptcalls[3] = mem.dv_rpt1call exp_rptcalls[4] = mem.dv_rpt2call self._test_ensure_has_calls(mem, ini_urcalls, ini_rptcalls, exp_urcalls, exp_rptcalls)
def test_ensure_has_calls_empty(self): mem = chirp_common.DVMemory() mem.dv_urcall = 'KK7DS' mem.dv_rpt1call = 'KD7RFI B' mem.dv_rpt2call = 'KD7RFI G' ini_urcalls = ['', '', '', '', ''] ini_rptcalls = ['', '', '', '', ''] exp_urcalls = list(ini_urcalls) exp_rptcalls = list(ini_rptcalls) exp_urcalls[0] = mem.dv_urcall exp_rptcalls[0] = mem.dv_rpt1call exp_rptcalls[1] = mem.dv_rpt2call self._test_ensure_has_calls(mem, ini_urcalls, ini_rptcalls, exp_urcalls, exp_rptcalls)
def test_ensure_has_calls_urcall_full(self): mem = chirp_common.DVMemory() mem.dv_urcall = 'KK7DS' mem.dv_rpt1call = 'KD7RFI B' mem.dv_rpt2call = 'KD7RFI G' ini_urcalls = ['FOO', 'BAR', 'BAZ', 'BAT', 'BOOM'] ini_rptcalls = ['FOO', 'BAR', 'BAZ', '', ''] exp_urcalls = list(ini_urcalls) exp_rptcalls = list(ini_rptcalls) exp_urcalls[4] = mem.dv_urcall exp_rptcalls[3] = mem.dv_rpt1call exp_rptcalls[4] = mem.dv_rpt2call self.assertRaises(errors.RadioError, self._test_ensure_has_calls, mem, ini_urcalls, ini_rptcalls, exp_urcalls, exp_rptcalls)
def get_memory(self, number): if isinstance(number, str): number = _get_special()[number] _mem = self._memobj.memory[number] _flag = self._memobj.flags[number] if _mem.mode_dv and not _flag.empty: mem = chirp_common.DVMemory() mem.dv_urcall = \ str(self._memobj.urcalls[_mem.urcall].call).rstrip() mem.dv_rpt1call = \ str(self._memobj.rptcalls[_mem.r1call].call).rstrip() mem.dv_rpt2call = \ str(self._memobj.rptcalls[_mem.r2call].call).rstrip() else: mem = chirp_common.Memory() mem.number = number if number < 200: mem.skip = _flag.skip and "S" or "" else: mem.extd_number = util.get_dict_rev(_get_special(), number) mem.immutable = [ "number", "skip", "bank", "bank_index", "extd_number" ] if _flag.empty: mem.empty = True mem.power = POWER_LEVELS[0] return mem mult = _mem.is_625 and 6250 or 5000 mem.freq = (_mem.freq * mult) mem.offset = (_mem.offset * mult) mem.rtone = chirp_common.TONES[_mem.rtone] mem.ctone = chirp_common.TONES[_mem.ctone] mem.tmode = TMODES[_mem.tmode] mem.duplex = DUPLEX[_mem.duplex] mem.mode = _mem.mode_dv and "DV" or _mem.mode_am and "AM" or "FM" if _mem.mode_narrow: mem.mode = "N%s" % mem.mode mem.dtcs = chirp_common.DTCS_CODES[_mem.dtcs] mem.dtcs_polarity = DTCSP[_mem.dtcs_polarity] mem.tuning_step = STEPS[_mem.tuning_step] mem.name = str(_mem.name).replace("\x0E", "").rstrip() mem.power = POWER_LEVELS[_mem.power] return mem
def get_memory(self, number): bytepos = number / 8 bitpos = 1 << (number % 8) _mem = self._memobj.memory[number] _used = self._memobj.used_flags[bytepos] is_used = ((_used & bitpos) == 0) if is_used and MODES[_mem.mode] == "DV": mem = chirp_common.DVMemory() mem.dv_urcall = decode_call(str(_mem.urcall)) mem.dv_rpt1call = decode_call(str(_mem.r1call)) mem.dv_rpt2call = decode_call(str(_mem.r2call)) else: mem = chirp_common.Memory() mem.number = number if number < 1000: _skip = self._memobj.skip_flags[bytepos] _pskip = self._memobj.pskip_flags[bytepos] if _skip & bitpos: mem.skip = "S" elif _pskip & bitpos: mem.skip = "P" else: pass # FIXME: Special memories if not is_used: mem.empty = True return mem mem.freq = _get_freq(_mem) mem.offset = (_mem.offset * 5) * 1000 mem.rtone = chirp_common.TONES[_mem.rtone] mem.ctone = chirp_common.TONES[_mem.ctone] mem.tmode = TMODES[_mem.tmode] mem.duplex = DUPLEX[_mem.duplex] mem.mode = MODES[_mem.mode] mem.dtcs = chirp_common.DTCS_CODES[_mem.dtcs] mem.dtcs_polarity = DTCSP[_mem.dtcs_polarity] if _mem.tune_step >= len(STEPS): mem.tuning_step = 5.0 else: mem.tuning_step = STEPS[_mem.tune_step] mem.name = str(_mem.name).rstrip() return mem
def get_memory(self, number): if isinstance(number, str): try: number = ID800_SPECIAL[number] + 1 # Because we subtract below except KeyError: raise errors.InvalidMemoryLocation("Unknown channel %s" % number) _mem = self._memobj.memory[number - 1] _flg = self._memobj.flags[number - 1] if MODES[_mem.mode] == "DV": urcalls = self.get_urcall_list() rptcalls = self.get_repeater_call_list() mem = chirp_common.DVMemory() mem.dv_urcall = urcalls[_mem.urcall] mem.dv_rpt1call = rptcalls[_mem.rpt1call] mem.dv_rpt2call = rptcalls[_mem.rpt2call] mem.dv_code = _mem.digital_code else: mem = chirp_common.Memory() mem.number = number if _flg.empty: mem.empty = True return mem mult = _mem.mult_flag and 6250 or 5000 mem.freq = _mem.freq * mult mem.offset = _mem.offset * 5000 mem.duplex = DUPLEX[_mem.duplex] mem.mode = MODES[_mem.mode] mem.tmode = TMODES[_mem.tmode] mem.rtone = chirp_common.TONES[_mem.rtone] mem.ctone = chirp_common.TONES[_mem.ctone] mem.dtcs = chirp_common.DTCS_CODES[_mem.dtcs] mem.dtcs_polarity = DTCS_POL[_mem.dtcs_polarity] mem.tuning_step = STEPS[_mem.tuning_step] mem.name = get_name(_mem) mem.skip = _flg.pskip and "P" or _flg.skip and "S" or "" return mem
def get_memory(self, number): _mem = self._memobj.memory[number] _usd = self._memobj.used_flags[number / 8] _skp = self._memobj.skip_flags[number / 8] _psk = self._memobj.pskp_flags[number / 8] bit = (1 << (number % 8)) if self.MODES[int(_mem.mode)] == "DV": mem = chirp_common.DVMemory() else: mem = chirp_common.Memory() mem.number = number if _usd & bit: mem.empty = True return mem mem.freq, mem.offset = _get_freq(_mem) mem.name = str(_mem.name).rstrip() mem.rtone = chirp_common.TONES[_mem.rtone] mem.ctone = chirp_common.TONES[_mem.ctone] mem.tmode = TMODES[_mem.tmode] mem.duplex = DUPLEX[_mem.duplex] mem.dtcs = chirp_common.DTCS_CODES[_mem.dtcs] mem.dtcs_polarity = DTCS_POLARITY[_mem.dtcs_polarity] mem.tuning_step = TUNING_STEPS[_mem.tune_step] mem.mode = self.MODES[int(_mem.mode)] if mem.mode == "DV": mem.dv_urcall = _decode_call(_mem.urcall).rstrip() mem.dv_rpt1call = _decode_call(_mem.rpt1call).rstrip() mem.dv_rpt2call = _decode_call(_mem.rpt2call).rstrip() if _psk & bit: mem.skip = "P" elif _skp & bit: mem.skip = "S" return mem
def _get_memory(_map, mmap, base): if get_mode(mmap) == "DV": mem = chirp_common.DVMemory() i_ucall, i_r1call, i_r2call = get_call_indices(mmap) mem.dv_urcall = get_urcall(_map, i_ucall) mem.dv_rpt1call = get_rptcall(_map, i_r1call) mem.dv_rpt2call = get_rptcall(_map, i_r2call) else: mem = chirp_common.Memory() mem.freq = get_freq(mmap, base) mem.name = get_name(mmap) mem.rtone = get_rtone(mmap) mem.ctone = get_ctone(mmap) mem.dtcs = get_dtcs(mmap) mem.dtcs_polarity = get_dtcs_polarity(mmap) mem.offset = get_dup_offset(mmap) mem.duplex = get_duplex(mmap) mem.tmode = get_tone_enabled(mmap) mem.tuning_step = get_tune_step(mmap) mem.mode = get_mode(mmap) return mem
def get_memory(doc, number): """Extract a Memory object from @doc""" ctx = doc.xpathNewContext() base = "//radio/memories/memory[@location=%i]" % number fields = ctx.xpathEval(base) if len(fields) > 1: raise errors.RadioError("%i memories claiming to be %i" % (len(fields), number)) elif len(fields) == 0: raise errors.InvalidMemoryLocation("%i does not exist" % number) memnode = fields[0] def _get(ext): path = base + ext result = ctx.xpathEval(path) if result: return result[0].getContent() else: return "" if _get("/mode/text()") == "DV": mem = chirp_common.DVMemory() mem.dv_urcall = _get("/dv/urcall/text()") mem.dv_rpt1call = _get("/dv/rpt1call/text()") mem.dv_rpt2call = _get("/dv/rpt2call/text()") try: mem.dv_code = _get("/dv/digitalCode/text()") except ValueError: mem.dv_code = 0 else: mem = chirp_common.Memory() mem.number = int(memnode.prop("location")) mem.name = _get("/longName/text()") mem.freq = chirp_common.parse_freq(_get("/frequency/text()")) mem.rtone = float(_get("/squelch[@id='rtone']/tone/text()")) mem.ctone = float(_get("/squelch[@id='ctone']/tone/text()")) mem.dtcs = int(_get("/squelch[@id='dtcs']/code/text()"), 10) mem.dtcs_polarity = _get("/squelch[@id='dtcs']/polarity/text()") try: sql = _get("/squelchSetting/text()") if sql == "rtone": mem.tmode = "Tone" elif sql == "ctone": mem.tmode = "TSQL" elif sql == "dtcs": mem.tmode = "DTCS" else: mem.tmode = "" except IndexError: mem.tmode = "" dmap = {"positive": "+", "negative": "-", "none": ""} dupx = _get("/duplex/text()") mem.duplex = dmap.get(dupx, "") mem.offset = chirp_common.parse_freq(_get("/offset/text()")) mem.mode = _get("/mode/text()") mem.tuning_step = float(_get("/tuningStep/text()")) skip = _get("/skip/text()") if skip == "none": mem.skip = "" else: mem.skip = skip # FIXME: bank support in .chirp files needs to be re-written # bank_id = _get("/bank/@bankId") # if bank_id: # mem.bank = int(bank_id) # bank_index = _get("/bank/@bankIndex") # if bank_index: # mem.bank_index = int(bank_index) return mem