Exemplo n.º 1
0
        def handle_shift(_vfo, settings):
            """_vfo is mmap obj for vfo, settings is for all UI settings"""

            # reset the shift in the memmap
            _vfo.shift_minus = 0
            _vfo.shift_plus = 0

            # parse and set if needed
            rx = chirp_common.parse_freq(
                str(settings["none.vrx_freq"]).split(":")[1])

            offset = chirp_common.parse_freq(
                str(settings["none.vfo_shift"]).split(":")[1])

            shift = str(settings["none.shift"]).split(":")[1]

            if shift == "None" or shift == "":
                # no shift
                _vfo.vtx_freq = rx / 10
            if shift == "-":
                # minus shift
                _vfo.vtx_freq = (rx - offset) / 10
            if shift == "+":
                # plus shift
                _vfo.vtx_freq = (rx + offset) / 10
Exemplo n.º 2
0
    def get_memory(self, number):
        if not self._repeaters:
            self.do_fetch()

        repeater = self._repeaters[number]

        mem = chirp_common.Memory()
        mem.number = number

        mem.name = repeater.get('city')
        mem.freq = chirp_common.parse_freq(repeater.get('frequency'))
        offset = chirp_common.parse_freq(repeater.get('offset', '0'))
        if offset > 0:
            mem.duplex = "+"
        elif offset < 0:
            mem.duplex = "-"
        else:
            mem.duplex = ""
        mem.offset = abs(offset)
        mem.mode = 'DMR'
        mem.comment = repeater.get('map_info')

        mem.extra = RadioSettingGroup("Extra", "extra")

        rs = RadioSetting(
            "color_code", "Color Code", RadioSettingValueList(
                range(16), int(repeater.get('color_code', 0))))
        mem.extra.append(rs)

        return mem
Exemplo n.º 3
0
        def handle_shift(_vfo, settings):
            """_vfo is mmap obj for vfo, settings is for all UI settings"""

            # reset the shift in the memmap
            _vfo.shift_minus = 0
            _vfo.shift_plus = 0

            # parse and set if needed
            rx = chirp_common.parse_freq(
                str(settings["none.vrx_freq"]).split(":")[1])

            offset = chirp_common.parse_freq(
                str(settings["none.vfo_shift"]).split(":")[1])

            shift = str(settings["none.shift"]).split(":")[1]

            if shift == "None" or shift == "":
                # no shift
                _vfo.vtx_freq = rx / 10
            if shift == "-":
                # minus shift
                _vfo.vtx_freq = (rx - offset) / 10
            if shift == "+":
                # plus shift
                _vfo.vtx_freq = (rx + offset) / 10
Exemplo n.º 4
0
 def test_parse_freq_decimal(self):
     self.assertEqual(chirp_common.parse_freq("1.0"), 1000000)
     self.assertEqual(chirp_common.parse_freq("1.000000"), 1000000)
     self.assertEqual(chirp_common.parse_freq("1.1"), 1100000)
     self.assertEqual(chirp_common.parse_freq("1.100"), 1100000)
     self.assertEqual(chirp_common.parse_freq("0.6"), 600000)
     self.assertEqual(chirp_common.parse_freq("0.600"), 600000)
     self.assertEqual(chirp_common.parse_freq("0.060"), 60000)
     self.assertEqual(chirp_common.parse_freq(".6"), 600000)
Exemplo n.º 5
0
 def test_parse_freq_decimal(self):
     self.assertEqual(chirp_common.parse_freq("1.0"), 1000000)
     self.assertEqual(chirp_common.parse_freq("1.000000"), 1000000)
     self.assertEqual(chirp_common.parse_freq("1.1"), 1100000)
     self.assertEqual(chirp_common.parse_freq("1.100"), 1100000)
     self.assertEqual(chirp_common.parse_freq("0.6"), 600000)
     self.assertEqual(chirp_common.parse_freq("0.600"), 600000)
     self.assertEqual(chirp_common.parse_freq("0.060"), 60000)
     self.assertEqual(chirp_common.parse_freq(".6"), 600000)
Exemplo n.º 6
0
 def my_dbl2raw(setting, obj, atrb, flg=1):
     """Callback: convert from freq 146.7600 to 14760000 U32."""
     value = chirp_common.parse_freq(str(setting.value)) / 10
     # flg=1 means 0 becomes ff, else leave as possible 0
     if flg == 1 and value == 0:
         value = 0xFFFFFFFF
     setattr(obj, atrb, value)
     return
Exemplo n.º 7
0
 def my_dbl2raw(setting, obj, atrb, flg=1):
     """Callback: convert from freq 146.7600 to 14760000 U32."""
     value = chirp_common.parse_freq(str(setting.value)) / 10
     # flg=1 means 0 becomes ff, else leave as possible 0
     if flg == 1 and value == 0:
         value = 0xFFFFFFFF
     setattr(obj, atrb, value)
     return
Exemplo n.º 8
0
    def test_parse_freq_whitespace(self):
        self.assertEqual(chirp_common.parse_freq("1  "), 1000000)
        self.assertEqual(chirp_common.parse_freq("   1"), 1000000)
        self.assertEqual(chirp_common.parse_freq("   1  "), 1000000)

        self.assertEqual(chirp_common.parse_freq("1.0  "), 1000000)
        self.assertEqual(chirp_common.parse_freq("   1.0"), 1000000)
        self.assertEqual(chirp_common.parse_freq("   1.0  "), 1000000)
        self.assertEqual(chirp_common.parse_freq(""), 0)
        self.assertEqual(chirp_common.parse_freq(" "), 0)
Exemplo n.º 9
0
    def test_parse_freq_whitespace(self):
        self.assertEqual(chirp_common.parse_freq("1  "), 1000000)
        self.assertEqual(chirp_common.parse_freq("   1"), 1000000)
        self.assertEqual(chirp_common.parse_freq("   1  "), 1000000)

        self.assertEqual(chirp_common.parse_freq("1.0  "), 1000000)
        self.assertEqual(chirp_common.parse_freq("   1.0"), 1000000)
        self.assertEqual(chirp_common.parse_freq("   1.0  "), 1000000)
        self.assertEqual(chirp_common.parse_freq(""), 0)
        self.assertEqual(chirp_common.parse_freq(" "), 0)
Exemplo n.º 10
0
    def _clean_duplex(self, headers, line, mem):
        if mem.duplex == "split":
            try:
                val = get_datum_by_header(headers, line, "Transmit Frequency")
                val = chirp_common.parse_freq(val)
                mem.offset = val
            except OmittedHeaderError:
                pass

        return mem
Exemplo n.º 11
0
    def _clean_duplex(self, headers, line, mem):
        if mem.duplex == "split":
            try:
                val = get_datum_by_header(headers, line, "Transmit Frequency")
                val = chirp_common.parse_freq(val)
                mem.offset = val
            except OmittedHeaderError:
                pass

        return mem
Exemplo n.º 12
0
 def repeater_to_memory( r ):
     mem = DMRMemory()
     mem.comment = r['locator'] + ':' +r['city']+ "," + r['state'] + "," + r['country']
     mem.freq = parse_freq( r['frequency'] )
     mem.colorcode = int(r['color_code']) #check this, it's not coming through
     mem.mode = "DMR"
     mem.duplex, mem.offset = DMRDump.parse_offset(r['offset'])
     mem.name = r['callsign']
     mem.empty = False
     return mem
Exemplo n.º 13
0
    def get_memory(self, number):
        if not self._freqs:
            self.do_fetch()

        freq = self._freqs[number]

        mem = chirp_common.Memory()
        mem.number = number

        mem.name = freq.alpha or freq.descr or ""
        mem.freq = chirp_common.parse_freq(str(freq.out))
        if freq["in"] == 0.0:
            mem.duplex = ""
        else:
            mem.duplex = "split"
            mem.offset = chirp_common.parse_freq(str(freq["in"]))
        if freq.tone is not None:
            if str(freq.tone) == "CSQ":  # Carrier Squelch
                mem.tmode = ""
            else:
                try:
                    tone, tmode = freq.tone.split(" ")
                except Exception:
                    tone, tmode = None, None
                if tmode == "PL":
                    mem.tmode = "TSQL"
                    mem.rtone = mem.ctone = float(tone)
                elif tmode == "DPL":
                    mem.tmode = "DTCS"
                    mem.dtcs = int(tone)
                else:
                    print "Error: unsupported tone"
                    print freq
        try:
            mem.mode = self._get_mode(freq.mode)
        except KeyError:
            # skip memory if mode is unsupported
            mem.empty = True
            return mem
        mem.comment = freq.descr.strip()

        return mem
Exemplo n.º 14
0
    def get_memory(self, number):
        if not self._freqs:
            self.do_fetch()

        freq = self._freqs[number]

        mem = chirp_common.Memory()
        mem.number = number

        mem.name = freq.alpha or freq.descr or ""
        mem.freq = chirp_common.parse_freq(str(freq.out))
        if freq["in"] == 0.0:
            mem.duplex = ""
        else:
            mem.duplex = "split"
            mem.offset = chirp_common.parse_freq(str(freq["in"]))
        if freq.tone is not None:
            if str(freq.tone) == "CSQ": # Carrier Squelch
                mem.tmode = ""
            else:
                try:
                    tone, tmode = freq.tone.split(" ")
                except Exception:
                    tone, tmode = None, None
                if tmode == "PL":
                    mem.tmode = "TSQL"
                    mem.rtone = mem.ctone = float(tone)
                elif tmode == "DPL":
                    mem.tmode = "DTCS"
                    mem.dtcs = int(tone)
                else:
                    print "Error: unsupported tone"
                    print freq
        try:
            mem.mode = self._get_mode(freq.mode)
        except KeyError:
            # skip memory if mode is unsupported
            mem.empty = True
            return mem
        mem.comment = freq.descr.strip()

        return mem
Exemplo n.º 15
0
    def _parse_line(self, line):
        mem = chirp_common.Memory()

        _vals = line.split("|")

        vals = {}
        for i in range(0, len(SCHEMA)):
            try:
                vals[SCHEMA[i]] = _vals[i]
            except IndexError:
                LOG.error("No such vals %s" % SCHEMA[i])
        self.__cheat = vals

        mem.name = vals["TRUSTEE"]
        mem.freq = chirp_common.parse_freq(vals["OUTFREQUENCY"])
        if vals["OFFSETSIGN"] != "X":
            mem.duplex = vals["OFFSETSIGN"]
        if vals["OFFSETFREQ"]:
            mem.offset = chirp_common.parse_freq(vals["OFFSETFREQ"])

        if vals["PL"] and float(vals["PL"]) != 0:
            mem.rtone = float(vals["PL"])
            mem.tmode = "Tone"
        elif vals["DCS"] and vals["DCS"] != "0":
            mem.dtcs = int(vals["DCS"])
            mem.tmode = "DTCS"

        if vals["NOTES"]:
            mem.comment = vals["NOTES"].strip()

        if vals["LATITUDE"] and vals["LONGITUDE"]:
            try:
                lat = float(vals["LATITUDE"])
                lon = float(vals["LONGITUDE"])
                dist = distance(self.__lat, self.__lon, lat, lon)
                bear = fuzzy_to(self.__lat, self.__lon, lat, lon)
                mem.comment = "(%imi %s) %s" % (dist, bear, mem.comment)
            except (Exception, e):
                LOG.error("Failed to calculate distance: %s" % e)

        return mem
Exemplo n.º 16
0
 def my_validate(value):
     value = chirp_common.parse_freq(value)
     msg = ("Can't be less than %i.0000")
     if value > 99000000 and value < 130 * 1000000:
         raise InvalidValueError(msg % (130))
     msg = ("Can't be between %i.9975-%i.0000")
     if (179 + 1) * 1000000 <= value and value < 400 * 1000000:
         raise InvalidValueError(msg % (179, 400))
     msg = ("Can't be greater than %i.9975")
     if value > 99000000 and value > (520 + 1) * 1000000:
         raise InvalidValueError(msg % (520))
     return chirp_common.format_freq(value)
Exemplo n.º 17
0
 def parse_offset( offset ):
     duplex = ""
     direction = float(offset) > 0
     offset = parse_freq( offset )
     print("Direction: ", direction)
     if abs(offset) == 5e6 or abs(offset) == 6e5 or abs(offset) == 5e5 or not direction:
         #TODO better way? anything <100mhz maybe?
         duplex = "+" if direction else "-";
         offset = abs(offset)
     else:
         print("SPLIT: ", offset)
     return duplex, offset
Exemplo n.º 18
0
 def my_validate(value):
     value = chirp_common.parse_freq(value)
     msg = ("Can't be less than %i.0000")
     if value > 99000000 and value < 130 * 1000000:
         raise InvalidValueError(msg % (130))
     msg = ("Can't be between %i.9975-%i.0000")
     if (179 + 1) * 1000000 <= value and value < 400 * 1000000:
         raise InvalidValueError(msg % (179, 400))
     msg = ("Can't be greater than %i.9975")
     if value > 99000000 and value > (520 + 1) * 1000000:
         raise InvalidValueError(msg % (520))
     return chirp_common.format_freq(value)
Exemplo n.º 19
0
 def test_parse_freq_whole(self):
     self.assertEqual(chirp_common.parse_freq("146.520000"), 146520000)
     self.assertEqual(chirp_common.parse_freq("146.5200"), 146520000)
     self.assertEqual(chirp_common.parse_freq("146.52"), 146520000)
     self.assertEqual(chirp_common.parse_freq("146"), 146000000)
     self.assertEqual(chirp_common.parse_freq("1250"), 1250000000)
     self.assertEqual(chirp_common.parse_freq("123456789"), 123456789000000)
Exemplo n.º 20
0
 def test_parse_freq_whole(self):
     self.assertEqual(chirp_common.parse_freq("146.520000"), 146520000)
     self.assertEqual(chirp_common.parse_freq("146.5200"), 146520000)
     self.assertEqual(chirp_common.parse_freq("146.52"), 146520000)
     self.assertEqual(chirp_common.parse_freq("146"), 146000000)
     self.assertEqual(chirp_common.parse_freq("1250"), 1250000000)
     self.assertEqual(chirp_common.parse_freq("123456789"),
                      123456789000000)
Exemplo n.º 21
0
    def _clean_duplex(self, headers, line, mem):
        try:
            txfreq = chirp_common.parse_freq(
                        generic_csv.get_datum_by_header(headers, line, "TXF"))
        except ValueError:
            mem.duplex = "off"
            return mem

        if mem.freq == txfreq:
            mem.duplex = ""
        elif txfreq:
            mem.duplex = "split"
            mem.offset = txfreq

        return mem
Exemplo n.º 22
0
    def _clean_duplex(self, headers, line, mem):
        try:
            txfreq = chirp_common.parse_freq(
                generic_csv.get_datum_by_header(headers, line, "TXF"))
        except ValueError:
            mem.duplex = "off"
            return mem

        if mem.freq == txfreq:
            mem.duplex = ""
        elif txfreq:
            mem.duplex = "split"
            mem.offset = txfreq

        return mem
Exemplo n.º 23
0
 def my_validate(value):
     _vhf_lower = int(_mem.limits.vhf.lower)
     _vhf_upper = int(_mem.limits.vhf.upper)
     _uhf_lower = int(_mem.limits.uhf.lower)
     _uhf_upper = int(_mem.limits.uhf.upper)
     value = chirp_common.parse_freq(value)
     msg = ("Can't be less than %i.0000")
     if value > 99000000 and value < _vhf_lower * 1000000:
         raise InvalidValueError(msg % _vhf_lower)
     msg = ("Can't be between %i.9975-%i.0000")
     if _vhf_upper * 1000000 <= value and value < _uhf_lower * 1000000:
         raise InvalidValueError(msg % (_vhf_upper - 1, _uhf_lower))
     msg = ("Can't be greater than %i.9975")
     if value > 99000000 and value >= _uhf_upper * 1000000:
         raise InvalidValueError(msg % (_uhf_upper - 1))
     return chirp_common.format_freq(value)
Exemplo n.º 24
0
 def my_validate(value):
     _vhf_lower = int(_mem.limits.vhf.lower)
     _vhf_upper = int(_mem.limits.vhf.upper)
     _uhf_lower = int(_mem.limits.uhf.lower)
     _uhf_upper = int(_mem.limits.uhf.upper)
     value = chirp_common.parse_freq(value)
     msg = ("Can't be less than %i.0000")
     if value > 99000000 and value < _vhf_lower * 1000000:
         raise InvalidValueError(msg % _vhf_lower)
     msg = ("Can't be between %i.9975-%i.0000")
     if _vhf_upper * 1000000 <= value and value < _uhf_lower * 1000000:
         raise InvalidValueError(msg % (_vhf_upper - 1, _uhf_lower))
     msg = ("Can't be greater than %i.9975")
     if value > 99000000 and value >= _uhf_upper * 1000000:
         raise InvalidValueError(msg % (_uhf_upper - 1))
     return chirp_common.format_freq(value)
Exemplo n.º 25
0
 def _get_value(self):
     return chirp_common.parse_freq(self._widget.get_text())
Exemplo n.º 26
0
 def apply_freq(setting, obj):
     """Setting is the UI returned value, obj is the memmap object"""
     value = chirp_common.parse_freq(str(setting.value))
     obj.set_value(value / 10)
Exemplo n.º 27
0
 def _get_value(self):
     return chirp_common.parse_freq(self._widget.get_text())
Exemplo n.º 28
0
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
Exemplo n.º 29
0
 def apply_freq(setting, obj):
     """Setting is the UI returned value, obj is the memmap object"""
     value = chirp_common.parse_freq(str(setting.value))
     obj.set_value(value / 10)
Exemplo n.º 30
0
 def apply_offset(setting, obj):
     value = chirp_common.parse_freq(str(setting.value)) / 100
     for i in range(5, -1, -1):
         obj.offset[i] = value % 10
         value /= 10
Exemplo n.º 31
0
 def my_validate(value):
     value = chirp_common.parse_freq(value)
     if 17400000 <= value and value < 40000000:
         raise InvalidValueError("Can't be between 174.00000-400.00000")
     return chirp_common.format_freq(value)
Exemplo n.º 32
0
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
Exemplo n.º 33
0
 def apply_uhf_offset(setting, obj):
     value = chirp_common.parse_freq(str(setting.value)) / 10000
     obj.uhf.offset = value
Exemplo n.º 34
0
 def apply_uhf_freq(setting, obj):
     value = chirp_common.parse_freq(str(setting.value)) / 10
     obj.uhf.freq = value
Exemplo n.º 35
0
 def apply_uhf_offset(setting, obj):
     value = chirp_common.parse_freq(str(setting.value)) / 10000
     obj.uhf.offset = value
Exemplo n.º 36
0
 def apply_uhf_freq(setting, obj):
     value = chirp_common.parse_freq(str(setting.value)) / 10
     obj.uhf.freq = value
Exemplo n.º 37
0
 def my_validate(value):
     value = chirp_common.parse_freq(value)
     if 17400000 <= value and value < 40000000:
         msg = ("Can't be between 174.00000-400.00000")
         raise InvalidValueError(msg)
     return chirp_common.format_freq(value)
Exemplo n.º 38
0
 def apply_freq(setting, obj):
     value = chirp_common.parse_freq(str(setting.value)) / 10
     obj.band = value >= 40000000
     for i in range(7, -1, -1):
         obj.freq[i] = value % 10
         value /= 10
Exemplo n.º 39
0
 def apply_freq(setting, obj):
     value = chirp_common.parse_freq(str(setting.value)) / 10
     obj.band = value >= 40000000
     for i in range(7, -1, -1):
         obj.freq[i] = value % 10
         value /= 10
Exemplo n.º 40
0
 def apply_offset(setting, obj):
     value = chirp_common.parse_freq(str(setting.value)) / 10000
     for i in range(3, -1, -1):
         obj.offset[i] = value % 10
         value /= 10
Exemplo n.º 41
0
    def set_settings(self, settings):
        """Translate the settings in the UI into bit in the mem_struct
        I don't understand well the method used in many drivers
        so, I used mine, ugly but works ok"""
        def _get_shift(obj):
            """Get the amount of offset in the memmap"""
            shift = 0
            sf = str(obj.settings.vfo_shift)
            if sf[0] != "\xFF":
                shift = int(mobj.settings.vfo_shift) * 10
            return shift

        def _get_vrx(obj):
            """Get the vfo rx freq"""
            return int(obj.vfo.vrx_freq) * 10

        def _update_vtx(o, rx, offset):
            """Update the Vfo TX mem from the value of rx & the offset"""
            # check the shift sign
            plus = bool(getattr(o, "shift_plus"))
            minus = bool(getattr(o, "shift_minus"))

            if plus:
                o.vtx_freq = (rx + offset) / 10
            elif minus:
                o.vtx_freq = (rx - offset) / 10
            else:
                o.vtx_freq = rx / 10

        mobj = self._memobj
        flag = False
        for element in settings:
            if not isinstance(element, RadioSetting):
                self.set_settings(element)
                continue

            # Let's roll the ball
            if "." in element.get_name():
                # real properties, more or less mapeable
                inter, setting = element.get_name().split(".")
                obj = getattr(mobj, inter)
                value = element.value

                # test on this cases .......
                if setting in ["sql", "tot", "powerrank", "active_ch",
                        "ani_mode"]:
                    value = int(value)

                # test on this cases .......
                if setting in ["lamp", "lamp_auto", "bs", "warning",
                        "monitor"]:
                    value = bool(value)
                    # warning and bs have a sister setting in LCD
                    if setting == "warning" or setting == "bs":
                        # aditional setting
                        setattr(obj, setting + "1", value)

                    # monitorval: monitor = 0 > monitorval = 0
                    # monitorval: monitor = 1 > monitorval = x30
                    if setting == "monitor":
                        # sister setting in LCD
                        if value:
                            setattr(obj, "monitorval", 0x30)
                        else:
                            setattr(obj, "monitorval", 0)

                # case power
                if setting == "power":
                    value = str(value) == "High" and True or False

                # case key
                # key => auto = 0, manu = 1
                if setting == "key":
                    value = str(value) == "Manual" and True or False

                # case bandwidth
                # bw: 0 = nar, 1 = Wide & must equal bw1
                if setting == "bw":
                    value = str(value) == "Wide" and True or False
                    # sister attr
                    setattr(obj, "bw1", value)

                # work mem wmem/wvfo
                if setting == "wmem":
                    if str(value) == "Memory":
                        value = True
                        # sister attr
                        setattr(obj, "wvfo", not value)
                    else:
                        value = False
                        # sister attr
                        setattr(obj, "wvfo", not value)

                # case step
                # STEPF = ["5", "10", "6.25", "12.5", "25"]
                if setting == "step":
                    value = STEPF.index(str(value))

                # case vrx_freq
                if setting == "vrx_freq":
                    value = chirp_common.parse_freq(str(value)) / 10
                    # you must calculate the apropiate txfreq from
                    # shift and offset
                    shift = _get_shift(mobj)
                    # update the tx vfo freq
                    _update_vtx(obj, value * 10, shift)

                # vfo_shift = offset
                if setting == "vfo_shift":
                    value = chirp_common.parse_freq(str(value)) / 10
                    # you must calculate the apropiate txfreq from
                    # shift and offset
                    # get vfo rx
                    vrx = _get_vrx(mobj)
                    # update the tx vfo freq
                    _update_vtx(mobj.vfo, vrx, value * 10)

                # at least for FD-268A/B it doesn't work as stated, so disabled
                # by now, does this work on the fd-288s?

                ## case scramble & busy_lock
                #if setting == "scramble" or setting == "busy_lock":
                    #value = bool(ONOFF.index(str(value)))

                # ani value, only for FD-288
                if setting == "ani":
                    if "FD-268" in self.MODEL:
                        # 268 doesn't have ani setting
                        continue
                    else:
                        # 288 models, validate the input [200-999] | ""
                        # we will left adjust and zero pad to avoid errors
                        # between inputs in the UI
                        value = str(value).strip().ljust(3, "0")
                        value = int(value)
                        if value == 0:
                            value = 200
                        else:
                            if value > 999 or value < 200:
                                raise errors.InvalidValueError(
                                    "The ANI value must be between \
                                    200 and 999, not %03i" % value)

                        value = str(value)

            else:
                # Others that are artifact for real values, not than mapeables
                # selecting the values to work
                setting = str(element.get_name())
                value = str(element.value)

                # vfo_shift
                if setting == "shift":
                    # get shift
                    offset = _get_shift(mobj)
                    # get vfo rx
                    vrx = _get_vrx(mobj)

                    # VSHIFT = ["None", "-", "+"]
                    if value == "+":
                        mobj.vfo.shift_plus = True
                        mobj.vfo.shift_minus = False
                    elif value == "-":
                        mobj.vfo.shift_plus = False
                        mobj.vfo.shift_minus = True
                    else:
                        mobj.vfo.shift_plus = False
                        mobj.vfo.shift_minus = False

                    # update the tx vfo freq
                    _update_vtx(mobj.vfo, vrx, offset)

            if setting != "shift":
                setattr(obj, setting, value)
Exemplo n.º 42
0
    def set_settings(self, settings):
        """Translate the settings in the UI into bit in the mem_struct
        I don't understand well the method used in many drivers
        so, I used mine, ugly but works ok"""
        def _get_shift(obj):
            """Get the amount of offset in the memmap"""
            shift = 0
            sf = str(obj.settings.vfo_shift)
            if sf[0] != "\xFF":
                shift = int(mobj.settings.vfo_shift) * 10
            return shift

        def _get_vrx(obj):
            """Get the vfo rx freq"""
            return int(obj.vfo.vrx_freq) * 10

        def _update_vtx(o, rx, offset):
            """Update the Vfo TX mem from the value of rx & the offset"""
            # check the shift sign
            plus = bool(getattr(o, "shift_plus"))
            minus = bool(getattr(o, "shift_minus"))

            if plus:
                o.vtx_freq = (rx + offset) / 10
            elif minus:
                o.vtx_freq = (rx - offset) / 10
            else:
                o.vtx_freq = rx / 10

        mobj = self._memobj
        flag = False
        for element in settings:
            if not isinstance(element, RadioSetting):
                self.set_settings(element)
                continue

            # Let's roll the ball
            if "." in element.get_name():
                # real properties, more or less mapeable
                inter, setting = element.get_name().split(".")
                obj = getattr(mobj, inter)
                value = element.value

                # test on this cases .......
                if setting in ["sql", "tot", "powerrank", "active_ch",
                        "ani_mode"]:
                    value = int(value)

                # test on this cases .......
                if setting in ["lamp", "lamp_auto", "bs", "warning",
                        "monitor"]:
                    value = bool(value)
                    # warning and bs have a sister setting in LCD
                    if setting == "warning" or setting == "bs":
                        # aditional setting
                        setattr(obj, setting + "1", value)

                    # monitorval: monitor = 0 > monitorval = 0
                    # monitorval: monitor = 1 > monitorval = x30
                    if setting == "monitor":
                        # sister setting in LCD
                        if value:
                            setattr(obj, "monitorval", 0x30)
                        else:
                            setattr(obj, "monitorval", 0)

                # case power
                if setting == "power":
                    value = str(value) == "High" and True or False

                # case key
                # key => auto = 0, manu = 1
                if setting == "key":
                    value = str(value) == "Manual" and True or False

                # case bandwidth
                # bw: 0 = nar, 1 = Wide & must equal bw1
                if setting == "bw":
                    value = str(value) == "Wide" and True or False
                    # sister attr
                    setattr(obj, "bw1", value)

                # work mem wmem/wvfo
                if setting == "wmem":
                    if str(value) == "Memory":
                        value = True
                        # sister attr
                        setattr(obj, "wvfo", not value)
                    else:
                        value = False
                        # sister attr
                        setattr(obj, "wvfo", not value)

                # case step
                # STEPF = ["5", "10", "6.25", "12.5", "25"]
                if setting == "step":
                    value = STEPF.index(str(value))

                # case vrx_freq
                if setting == "vrx_freq":
                    value = chirp_common.parse_freq(str(value)) / 10
                    # you must calculate the apropiate txfreq from
                    # shift and offset
                    shift = _get_shift(mobj)
                    # update the tx vfo freq
                    _update_vtx(obj, value * 10, shift)

                # vfo_shift = offset
                if setting == "vfo_shift":
                    value = chirp_common.parse_freq(str(value)) / 10
                    # you must calculate the apropiate txfreq from
                    # shift and offset
                    # get vfo rx
                    vrx = _get_vrx(mobj)
                    # update the tx vfo freq
                    _update_vtx(mobj.vfo, vrx, value * 10)

                # at least for FD-268A/B it doesn't work as stated, so disabled
                # by now, does this work on the fd-288s?

                ## case scramble & busy_lock
                #if setting == "scramble" or setting == "busy_lock":
                    #value = bool(ONOFF.index(str(value)))

                # ani value, only for FD-288
                if setting == "ani":
                    if "FD-268" in self.MODEL:
                        # 268 doesn't have ani setting
                        continue
                    else:
                        # 288 models, validate the input [200-999] | ""
                        # we will left adjust and zero pad to avoid errors
                        # between inputs in the UI
                        value = str(value).strip().ljust(3, "0")
                        value = int(value)
                        if value == 0:
                            value = 200
                        else:
                            if value > 999 or value < 200:
                                raise errors.InvalidValueError(
                                    "The ANI value must be between \
                                    200 and 999, not %03i" % value)

                        value = str(value)

            else:
                # Others that are artifact for real values, not than mapeables
                # selecting the values to work
                setting = str(element.get_name())
                value = str(element.value)

                # vfo_shift
                if setting == "shift":
                    # get shift
                    offset = _get_shift(mobj)
                    # get vfo rx
                    vrx = _get_vrx(mobj)

                    # VSHIFT = ["None", "-", "+"]
                    if value == "+":
                        mobj.vfo.shift_plus = True
                        mobj.vfo.shift_minus = False
                    elif value == "-":
                        mobj.vfo.shift_plus = False
                        mobj.vfo.shift_minus = True
                    else:
                        mobj.vfo.shift_plus = False
                        mobj.vfo.shift_minus = False

                    # update the tx vfo freq
                    _update_vtx(mobj.vfo, vrx, offset)

            if setting != "shift":
                setattr(obj, setting, value)