Bug #5099 ยป modernize_python.patch
chirp/bandplan.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2013 Sean Burford <sburford@google.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
for tone in tones:
|
||
assert tone in chirp_common.TONES, (
|
||
"tone %s not one of %s" % (tone, chirp_common.TONES))
|
||
except AssertionError, e:
|
||
except AssertionError as e:
|
||
raise ValueError("%s %s: %s" % (name, limits, e))
|
||
self.name = name
|
chirp/chirp_common.py (revision 83f364736678ae6000c8f4da1e48ab4113b78f69) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2008 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
return int(math.pow(10, (dBm - 30) / 10))
|
||
class PowerLevel:
|
||
class PowerLevel(object):
|
||
"""Represents a power level supported by a radio"""
|
||
def __init__(self, label, watts=0, dBm=0):
|
||
... | ... | |
pass
|
||
class Memory:
|
||
class Memory(object):
|
||
"""Base class for a single radio memory"""
|
||
freq = 0
|
||
number = 0
|
||
... | ... | |
super(BankModel, self).__init__(radio, name)
|
||
class MappingModelIndexInterface:
|
||
class MappingModelIndexInterface(object):
|
||
"""Interface for mappings with index capabilities"""
|
||
def get_index_bounds(self):
|
||
... | ... | |
sys.stdout.write(os.linesep)
|
||
class RadioPrompts:
|
||
class RadioPrompts(object):
|
||
"""Radio prompt strings"""
|
||
experimental = None
|
||
pre_download = None
|
||
... | ... | |
BOOLEAN = [True, False]
|
||
class RadioFeatures:
|
||
class RadioFeatures(object):
|
||
"""Radio Feature Flags"""
|
||
_valid_map = {
|
||
# General
|
||
... | ... | |
lo, hi = self.memory_bounds
|
||
if not self.has_infinite_number and \
|
||
(mem.number < lo or mem.number > hi) and \
|
||
mem.extd_number not in self.valid_special_chans:
|
||
mem.extd_number not in self.valid_special_chans:
|
||
msg = ValidationWarning("Location %i is out of range" % mem.number)
|
||
msgs.append(msg)
|
||
if (self.valid_modes and
|
||
mem.mode not in self.valid_modes and
|
||
mem.mode != "Auto"):
|
||
mem.mode not in self.valid_modes and
|
||
mem.mode != "Auto"):
|
||
msg = ValidationError("Mode %s not supported" % mem.mode)
|
||
msgs.append(msg)
|
||
... | ... | |
else:
|
||
if mem.tmode == "Cross":
|
||
if self.valid_cross_modes and \
|
||
mem.cross_mode not in self.valid_cross_modes:
|
||
mem.cross_mode not in self.valid_cross_modes:
|
||
msg = ValidationError("Cross tone mode %s not supported" %
|
||
mem.cross_mode)
|
||
msgs.append(msg)
|
||
if self.has_dtcs_polarity and \
|
||
mem.dtcs_polarity not in self.valid_dtcs_pols:
|
||
mem.dtcs_polarity not in self.valid_dtcs_pols:
|
||
msg = ValidationError("DTCS Polarity %s not supported" %
|
||
mem.dtcs_polarity)
|
||
msgs.append(msg)
|
||
if self.valid_dtcs_codes and \
|
||
mem.dtcs not in self.valid_dtcs_codes:
|
||
mem.dtcs not in self.valid_dtcs_codes:
|
||
msg = ValidationError("DTCS Code %03i not supported" % mem.dtcs)
|
||
if self.valid_dtcs_codes and \
|
||
mem.rx_dtcs not in self.valid_dtcs_codes:
|
||
mem.rx_dtcs not in self.valid_dtcs_codes:
|
||
msg = ValidationError("DTCS Code %03i not supported" % mem.rx_dtcs)
|
||
if self.valid_duplexes and mem.duplex not in self.valid_duplexes:
|
||
... | ... | |
if self.valid_bands and \
|
||
self.valid_duplexes and \
|
||
mem.duplex in ["split", "-", "+"]:
|
||
mem.duplex in ["split", "-", "+"]:
|
||
if mem.duplex == "split":
|
||
freq = mem.offset
|
||
elif mem.duplex == "-":
|
||
... | ... | |
if mem.power and \
|
||
self.valid_power_levels and \
|
||
mem.power not in self.valid_power_levels:
|
||
mem.power not in self.valid_power_levels:
|
||
msg = ValidationWarning("Power level %s not supported" % mem.power)
|
||
msgs.append(msg)
|
||
... | ... | |
msg = ValidationError("Frequency requires %.2fkHz step" %
|
||
required_step(mem.freq))
|
||
msgs.append(msg)
|
||
except errors.InvalidDataError, e:
|
||
except errors.InvalidDataError as e:
|
||
msgs.append(str(e))
|
||
if self.valid_characters:
|
||
... | ... | |
def load_mmap(self, filename):
|
||
"""Load the radio's memory map from @filename"""
|
||
mapfile = file(filename, "rb")
|
||
mapfile = open(filename, "rb")
|
||
self._mmap = memmap.MemoryMap(mapfile.read())
|
||
mapfile.close()
|
||
self.process_mmap()
|
||
... | ... | |
If IOError raise a File Access Error Exception
|
||
"""
|
||
try:
|
||
mapfile = file(filename, "wb")
|
||
mapfile = open(filename, "wb")
|
||
mapfile.write(self._mmap.get_packed())
|
||
mapfile.close()
|
||
except IOError:
|
||
... | ... | |
pass
|
||
class IcomDstarSupport:
|
||
class IcomDstarSupport(object):
|
||
"""Base interface for radios supporting Icom's D-STAR technology"""
|
||
MYCALL_LIMIT = (1, 1)
|
||
URCALL_LIMIT = (1, 1)
|
||
... | ... | |
pass
|
||
class ExperimentalRadio:
|
||
class ExperimentalRadio(object):
|
||
"""Interface for experimental radios"""
|
||
@classmethod
|
||
def get_experimental_warning(cls):
|
||
return ("This radio's driver is marked as experimental and may " +
|
||
"be unstable or unsafe to use.")
|
||
class Status:
|
||
class Status(object):
|
||
"""Clone status object for conveying clone progress to the UI"""
|
||
name = "Job"
|
||
msg = "Unknown"
|
||
... | ... | |
myfilter = ''.join(
|
||
[
|
||
[replacechar, chr(x)][chr(x) in validcharset]
|
||
for x in xrange(256)
|
||
for x in range(256)
|
||
])
|
||
return astring.translate(myfilter)
|
chirp/detect.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2010 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
ser.baudrate = 9600
|
||
md = icf.get_model_data(ser)
|
||
return _icom_model_data_to_rclass(md)
|
||
except errors.RadioError, e:
|
||
except errors.RadioError as e:
|
||
LOG.error(e)
|
||
# ICOM IC-91/92 Live-mode radios @ 4800/38400 baud
|
chirp/drivers/alinco.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2011 Dan Smith <dsmith@danplanet.com>
|
||
# 2016 Matt Weyland <lt-betrieb@hb9uf.ch>
|
||
#
|
||
... | ... | |
self._mmap = self._download(self._memsize)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
self.process_mmap()
|
||
... | ... | |
self._upload(self._memsize)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
def get_raw_memory(self, number):
|
chirp/drivers/anytone.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2013 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
try:
|
||
radio.pipe.write(data)
|
||
radio.pipe.read(len(data))
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.error("Error writing to radio: %s" % e)
|
||
raise errors.RadioError("Unable to write to radio")
|
||
... | ... | |
def _read(radio, length):
|
||
try:
|
||
data = radio.pipe.read(length)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.error("Error reading from radio: %s" % e)
|
||
raise errors.RadioError("Unable to read from radio")
|
||
chirp/drivers/anytone_ht.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2015 Jim Unroe <rock.unroe@gmail.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
def _echo_write(radio, data):
|
||
try:
|
||
radio.pipe.write(data)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.error("Error writing to radio: %s" % e)
|
||
raise errors.RadioError("Unable to write to radio")
|
||
... | ... | |
def _read(radio, length):
|
||
try:
|
||
data = radio.pipe.read(length)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.error("Error reading from radio: %s" % e)
|
||
raise errors.RadioError("Unable to read from radio")
|
||
... | ... | |
else:
|
||
LOG.debug("Setting %s = %s" % (setting, element.value))
|
||
setattr(obj, setting, element.value)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
||
chirp/drivers/ap510.py (revision 83f364736678ae6000c8f4da1e48ab4113b78f69) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2014 Tom Hayward <tom@tomh.us>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
def drain(pipe):
|
||
"""Chew up any data waiting on @pipe"""
|
||
for x in xrange(3):
|
||
for x in range(3):
|
||
buf = pipe.read(4096)
|
||
if not buf:
|
||
return
|
||
... | ... | |
def enter_setup(pipe):
|
||
"""Put AP510 in configuration mode."""
|
||
for x in xrange(30):
|
||
for x in range(30):
|
||
if x % 2:
|
||
pipe.write("@SETUP")
|
||
else:
|
||
... | ... | |
radio.pipe.write("@DISP")
|
||
buf = ""
|
||
for status.cur in xrange(status.cur, status.max):
|
||
for status.cur in range(status.cur, status.max):
|
||
buf += radio.pipe.read(1024)
|
||
if buf.endswith("\r\n"):
|
||
status.cur = status.max
|
||
... | ... | |
data = download(self)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
# _mmap isn't a Chirp MemoryMap, but since AP510Memory implements
|
||
... | ... | |
upload(self)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
def load_mmap(self, filename):
|
||
"""Load the radio's memory map from @filename"""
|
||
mapfile = file(filename, "rb")
|
||
mapfile = open(filename, "rb")
|
||
data = mapfile.read()
|
||
if data.startswith('\r\n00=%s 20141215' % self._model):
|
||
self._mmap = AP510Memory20141215(data)
|
chirp/drivers/baofeng_common.py (revision 67117ad7beb06c5d5f0d33211d3b06eadbb9059d) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2016:
|
||
# * Jim Unroe KC9HI, <rock.unroe@gmail.com>
|
||
#
|
||
... | ... | |
# You should have received a copy of the GNU General Public License
|
||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
from __future__ import print_function
|
||
"""common functions for Baofeng (or similar) handheld radios"""
|
||
import time
|
||
... | ... | |
try:
|
||
data = _do_ident(radio, magic)
|
||
return data
|
||
except errors.RadioError, e:
|
||
print e
|
||
except errors.RadioError as e:
|
||
print(e)
|
||
error = e
|
||
time.sleep(2)
|
||
if error:
|
||
... | ... | |
elif element.value.get_mutable():
|
||
LOG.debug("Setting %s = %s" % (setting, element.value))
|
||
setattr(obj, setting, element.value)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
||
... | ... | |
value = int(val.get_value() * 10)
|
||
LOG.debug("Setting fm_presets = %s" % (value))
|
||
self._memobj.fm_presets = value
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
chirp/drivers/baofeng_uv3r.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2011 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
for _i in range(0, 10):
|
||
try:
|
||
return _uv3r_prep(radio)
|
||
except errors.RadioError, e:
|
||
except errors.RadioError as e:
|
||
time.sleep(1)
|
||
raise e
|
||
... | ... | |
return do_download(radio, 0x0000, 0x0E40, 0x0010)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
... | ... | |
return do_upload(radio, 0x0000, 0x0E40, 0x0010)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
... | ... | |
else:
|
||
LOG.debug("Setting %s = %s" % (setting, element.value))
|
||
setattr(obj, setting, element.value)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
||
... | ... | |
LOG.debug("Setting fm_presets[%1i] = %s" % (index, value))
|
||
setting = self._memobj.fm_presets
|
||
setting[index] = value
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
||
chirp/drivers/bj9900.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
#
|
||
# Copyright 2015 Marco Filippi IZ3GME <iz3gme.marco@gmail.com>
|
||
#
|
||
... | ... | |
self._mmap = self._clone_in()
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
self.process_mmap()
|
||
... | ... | |
self._clone_out()
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
def process_mmap(self):
|
chirp/drivers/bjuv55.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2013 Jens Jensen AF5MI <kd4tjx@yahoo.com>
|
||
# Based on work by Jim Unroe, Dan Smith, et al.
|
||
# Special thanks to Mats SM0BTP for equipment donation.
|
||
... | ... | |
value = int(val.get_value() * 10 - 870)
|
||
LOG.debug("Setting fm_preset = %s" % (value))
|
||
self._memobj.fm_preset = value
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
chirp/drivers/btech.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2016-2017:
|
||
# * Pavel Milanes CO7WT, <pavelmc@gmail.com>
|
||
# * Jim Unroe KC9HI, <rock.unroe@gmail.com>
|
||
... | ... | |
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Error sending Magic to radio:\n%s" % e)
|
||
... | ... | |
_upload(self)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Error: %s" % e)
|
||
def get_raw_memory(self, number):
|
||
... | ... | |
elif element.value.get_mutable():
|
||
LOG.debug("Setting %s = %s" % (setting, element.value))
|
||
setattr(obj, setting, element.value)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
||
chirp/drivers/ft1d.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2010 Dan Smith <dsmith@danplanet.com>
|
||
# Copyright 2014 Angus Ainslie <angus@akkea.ca>
|
||
#
|
||
... | ... | |
except AttributeError as e:
|
||
LOG.error("Setting %s is not in the memory map: %s" %
|
||
(element.get_name(), e))
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
||
chirp/drivers/ft2800.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2011 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
self._mmap = _download(self)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
LOG.info("Downloaded in %.2f sec" % (time.time() - start))
|
||
self.process_mmap()
|
||
... | ... | |
_upload(self)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
LOG.info("Uploaded in %.2f sec" % (time.time() - start))
|
||
chirp/drivers/ft2900.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2011 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# FT-2900-specific modifications by Richard Cochran, <ag6qr@sonic.net>
|
||
... | ... | |
self._mmap = _download(self)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
LOG.info("Downloaded in %.2f sec" % (time.time() - start))
|
||
self.process_mmap()
|
||
... | ... | |
_upload(self)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
LOG.info("Uploaded in %.2f sec" % (time.time() - start))
|
||
... | ... | |
setattr(_settings, name, value)
|
||
LOG.debug("Setting %s: %s" % (name, value))
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
||
chirp/drivers/ft50.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2011 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
def _clone_out(radio):
|
||
try:
|
||
return __clone_out(radio)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with the radio: %s" % e)
|
||
chirp/drivers/ft60.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2011 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
self._mmap = _download(self)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
self.process_mmap()
|
||
self.check_checksums()
|
||
... | ... | |
_upload(self)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
def process_mmap(self):
|
||
... | ... | |
setattr(_settings, name, value)
|
||
LOG.debug("Setting %s: %s" % (name, value))
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
||
chirp/drivers/ft7800.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2010 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
self._mmap = _download(self)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
LOG.info("Download finished in %i seconds" % (time.time() - start))
|
||
self.check_checksums()
|
||
... | ... | |
_upload(self)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
LOG.info("Upload finished in %i seconds" % (time.time() - start))
|
||
... | ... | |
oldval = getattr(_settings, setting)
|
||
LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval))
|
||
setattr(_settings, setting, newval)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
||
chirp/drivers/ft8100.py (revision 67117ad7beb06c5d5f0d33211d3b06eadbb9059d) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2010 Eric Allen <eric@hackerengineer.net>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
# You should have received a copy of the GNU General Public License
|
||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
from __future__ import print_function
|
||
import time
|
||
import os
|
||
... | ... | |
if _mem.duplex == DUPLEX.index("split"):
|
||
tx_freq = int(_mem.offset) * 1000
|
||
print self.VARIANT, number, tx_freq, mem.freq
|
||
print(self.VARIANT, number, tx_freq, mem.freq)
|
||
mem.offset = tx_freq - mem.freq
|
||
else:
|
||
mem.offset = int(_mem.offset) * 1000
|
||
... | ... | |
if not self._memobj.enables[byte] & bit and number != 1:
|
||
mem.empty = True
|
||
print 'R', self.VARIANT, number, _mem.baud9600
|
||
print('R', self.VARIANT, number, _mem.baud9600)
|
||
return mem
|
||
... | ... | |
def _clone_out(radio):
|
||
try:
|
||
return __clone_out(radio)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with the radio: %s" % e)
|
||
... | ... | |
pos = 0
|
||
for block in radio._block_lengths:
|
||
if os.getenv("CHIRP_DEBUG"):
|
||
print "\nSending %i-%i" % (pos, pos + block)
|
||
print("\nSending %i-%i" % (pos, pos + block))
|
||
out = radio.get_mmap()[pos:pos + block]
|
||
# need to chew byte-by-byte here or else we lose the ACK...not sure why
|
||
... | ... | |
pos += block
|
||
print "Clone completed in %i seconds" % (time.time() - start)
|
||
print("Clone completed in %i seconds" % (time.time() - start))
|
||
return True
|
chirp/drivers/ft817.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
#
|
||
# Copyright 2012 Filippi Marco <iz3gme.marco@gmail.com>
|
||
#
|
||
... | ... | |
self._mmap = self._clone_in()
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
self.process_mmap()
|
||
... | ... | |
self._clone_out()
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
def process_mmap(self):
|
chirp/drivers/ft90.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2011 Dan Smith <dsmith@danplanet.com>
|
||
# Copyright 2013 Jens Jensen AF5MI <kd4tjx@yahoo.com>
|
||
#
|
||
... | ... | |
self._mmap = self._clone_in()
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
trace = traceback.format_exc()
|
||
raise errors.RadioError(
|
||
"Failed to communicate with radio: %s" % trace)
|
||
... | ... | |
self._clone_out()
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
trace = traceback.format_exc()
|
||
raise errors.RadioError(
|
||
"Failed to communicate with radio: %s" % trace)
|
||
... | ... | |
newval = self._dtmf2bbcd(newval)
|
||
LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval))
|
||
setattr(_settings, setting, newval)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
chirp/drivers/ftm350.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2013 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
self._mmap = _clone_in(self)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to download from radio (%s)" % e)
|
||
self.process_mmap()
|
||
... | ... | |
_clone_out(self)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to upload to radio (%s)" % e)
|
||
def process_mmap(self):
|
chirp/drivers/generic_csv.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2008 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
val = typ(val)
|
||
if hasattr(mem, attr):
|
||
setattr(mem, attr, val)
|
||
except OmittedHeaderError, e:
|
||
except OmittedHeaderError as e:
|
||
pass
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise Exception("[%s] %s" % (attr, e))
|
||
return self._clean(headers, line, mem)
|
||
... | ... | |
self._blank()
|
||
f = file(self._filename, "rU")
|
||
f = open(self._filename, "rU")
|
||
header = f.readline().strip()
|
||
f.seek(0, 0)
|
||
... | ... | |
mem = self._parse_csv_data_line(header, line)
|
||
if mem.number is None:
|
||
raise Exception("Invalid Location field" % lineno)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.error("Line %i: %s", lineno, e)
|
||
self.errors.append("Line %i: %s" % (lineno, e))
|
||
continue
|
||
... | ... | |
if filename:
|
||
self._filename = filename
|
||
f = file(self._filename, "wb")
|
||
f = open(self._filename, "wb")
|
||
writer = csv.writer(f, delimiter=chirp_common.SEPCHAR)
|
||
writer.writerow(chirp_common.Memory.CSV_FORMAT)
|
||
chirp/drivers/generic_xml.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2008 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
try:
|
||
ctx = libxml2.schemaNewParserCtxt(path)
|
||
schema = ctx.schemaParse()
|
||
except libxml2.parserError, e:
|
||
except libxml2.parserError as e:
|
||
LOG.error("Unable to load schema: %s" % e)
|
||
LOG.error("Path: %s" % path)
|
||
raise errors.RadioError("Unable to load schema")
|
||
... | ... | |
if filename:
|
||
self._filename = filename
|
||
f = file(self._filename, "w")
|
||
f = open(self._filename, "w")
|
||
f.write(self.doc.serialize(format=1))
|
||
f.close()
|
||
chirp/drivers/h777.py (revision ea406febfb9647e8400cf9d023352fc318ec8fd1) | ||
---|---|---|
else:
|
||
LOG.debug("Setting %s = %s" % (setting, element.value))
|
||
setattr(obj, setting, element.value)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
||
chirp/drivers/ic9x.py (revision 67117ad7beb06c5d5f0d33211d3b06eadbb9059d) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2008 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
# You should have received a copy of the GNU General Public License
|
||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
from __future__ import print_function
|
||
import time
|
||
import threading
|
||
import logging
|
||
... | ... | |
LOG.debug("Done: %s" % mem)
|
||
except errors.InvalidMemoryLocation:
|
||
pass
|
||
except errors.InvalidDataError, e:
|
||
except errors.InvalidDataError as e:
|
||
LOG.error("Error talking to radio: %s" % e)
|
||
break
|
||
... | ... | |
import serial
|
||
ser = IC9xRadioB(serial.Serial(port="/dev/ttyUSB1",
|
||
baudrate=38400, timeout=0.1))
|
||
print ser.get_urcall_list()
|
||
print "-- FOO --"
|
||
print(ser.get_urcall_list())
|
||
print("-- FOO --")
|
||
ser.set_urcall_list(["K7TAY", "FOOBAR", "BAZ"])
|
||
chirp/drivers/ic9x_ll.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2008 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
try:
|
||
start = buf.index("\xfe\xfe")
|
||
end = buf[start:].index("\xfd") + start + 1
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.error("No trailing bit")
|
||
break
|
||
... | ... | |
frame = IC92Frame()
|
||
frame.from_raw(framedata[2:-1])
|
||
frames.append(frame)
|
||
except errors.InvalidDataError, e:
|
||
except errors.InvalidDataError as e:
|
||
LOG.error("Broken frame: %s" % e)
|
||
# LOG.debug("Parsed %i frames" % len(frames))
|
||
... | ... | |
return _ic9x_parse_frames(data)
|
||
class IC92Frame:
|
||
class IC92Frame(object):
|
||
"""IC9x frame base class"""
|
||
def get_vfo(self):
|
||
"""Return the vfo number"""
|
||
return ord(self._map[0])
|
||
... | ... | |
return response[0]
|
||
def __setitem__(self, start, value):
|
||
self._map[start+4] = value
|
||
self._map[start + 4] = value
|
||
def __getitem__(self, index):
|
||
return self._map[index+4]
|
||
return self._map[index + 4]
|
||
def __getslice__(self, start, end):
|
||
return self._map[start+4:end+4]
|
||
return self._map[start + 4:end + 4]
|
||
class IC92GetBankFrame(IC92Frame):
|
chirp/drivers/icf.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2008 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
SAVE_PIPE = None
|
||
class IcfFrame:
|
||
class IcfFrame(object):
|
||
"""A single ICF communication frame"""
|
||
src = 0
|
||
dst = 0
|
||
... | ... | |
return frame, data[end+1:]
|
||
class RadioStream:
|
||
class RadioStream(object):
|
||
"""A class to make reading a stream of IcfFrames easier"""
|
||
def __init__(self, pipe):
|
||
self.pipe = pipe
|
||
self.data = ""
|
||
... | ... | |
frames.append(frame)
|
||
self.data = rest
|
||
except errors.InvalidDataError, e:
|
||
except errors.InvalidDataError as e:
|
||
LOG.error("Failed to parse frame (cmd=%i): %s" % (cmd, e))
|
||
return []
|
||
... | ... | |
val = int("%s%s" % (bcddata[i], bcddata[i+1]), 16)
|
||
i += 2
|
||
data += struct.pack("B", val)
|
||
except ValueError, e:
|
||
except ValueError as e:
|
||
LOG.error("Failed to parse byte: %s" % e)
|
||
break
|
||
... | ... | |
"""Do a full clone out of the radio's memory"""
|
||
try:
|
||
return _clone_from_radio(radio)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with the radio: %s" % e)
|
||
... | ... | |
global SAVE_PIPE
|
||
# Uncomment to save out a capture of what we actually write to the radio
|
||
# SAVE_PIPE = file("pipe_capture.log", "w", 0)
|
||
# SAVE_PIPE = open("pipe_capture.log", "w", 0)
|
||
md = get_model_data(radio.pipe)
|
||
... | ... | |
"""Initiate a full memory clone out to @radio"""
|
||
try:
|
||
return _clone_to_radio(radio)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with the radio: %s" % e)
|
||
... | ... | |
val = int("%s%s" % (data[i], data[i+1]), 16)
|
||
i += 2
|
||
_mmap += struct.pack("B", val)
|
||
except ValueError, e:
|
||
except ValueError as e:
|
||
LOG.debug("Failed to parse byte: %s" % e)
|
||
break
|
||
... | ... | |
def read_file(filename):
|
||
"""Read an ICF file and return the model string and memory data"""
|
||
f = file(filename)
|
||
f = open(filename)
|
||
mod_str = f.readline()
|
||
dat = f.readlines()
|
||
... | ... | |
def is_9x_icf(filename):
|
||
"""Returns True if @filename is an IC9x ICF file"""
|
||
f = file(filename)
|
||
f = open(filename)
|
||
mdata = f.read(8)
|
||
f.close()
|
||
... | ... | |
def is_icf_file(filename):
|
||
"""Returns True if @filename is an ICF file"""
|
||
f = file(filename)
|
||
f = open(filename)
|
||
data = f.readline()
|
||
data += f.readline()
|
||
f.close()
|
chirp/drivers/icq7.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2010 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
else:
|
||
LOG.debug("Setting %s = %s" % (setting, element.value))
|
||
setattr(obj, setting, element.value)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
chirp/drivers/kenwood_hmk.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2008 Dan Smith <dsmith@danplanet.com>
|
||
# Copyright 2012 Tom Hayward <tom@tomh.us>
|
||
#
|
||
... | ... | |
self._blank()
|
||
f = file(self._filename, "r")
|
||
f = open(self._filename, "r")
|
||
for line in f:
|
||
if line.strip() == "// Memory Channels":
|
||
break
|
||
... | ... | |
mem = self._parse_csv_data_line(header, line)
|
||
if mem.number is None:
|
||
raise Exception("Invalid Location field" % lineno)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.error("Line %i: %s" % (lineno, e))
|
||
self.errors.append("Line %i: %s" % (lineno, e))
|
||
continue
|
chirp/drivers/kenwood_itm.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2008 Dan Smith <dsmith@danplanet.com>
|
||
# Copyright 2012 Tom Hayward <tom@tomh.us>
|
||
#
|
||
... | ... | |
self._blank()
|
||
f = file(self._filename, "r")
|
||
f = open(self._filename, "r")
|
||
for line in f:
|
||
if line.strip() == "// Conventional Data":
|
||
break
|
||
... | ... | |
mem = self._parse_csv_data_line(header, line)
|
||
if mem.number is None:
|
||
raise Exception("Invalid Location field" % lineno)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.error("Line %i: %s" % (lineno, e))
|
||
self.errors.append("Line %i: %s" % (lineno, e))
|
||
continue
|
chirp/drivers/kguv8d.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2014 Ron Wellsted <ron@m0rnw.uk> M0RNW
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
self._mmap = self._download()
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
self.process_mmap()
|
||
... | ... | |
return self._do_download(0, 32768, 64)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.exception('Unknown error during download process')
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
... | ... | |
self._do_upload(0, 32768, 64)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
return
|
||
chirp/drivers/kyd.py (revision 94e21deb6ff7fc0f21a42d81f020121b059c1b8a) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2014 Jim Unroe <rock.unroe@gmail.com>
|
||
# Copyright 2014 Dan Smith <dsmith@danplanet.com>
|
||
#
|
||
... | ... | |
LOG.debug("Setting %s = %s" % (setting, element.value))
|
||
setattr(obj, setting, element.value)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
||
chirp/drivers/kyd_IP620.py (revision 67117ad7beb06c5d5f0d33211d3b06eadbb9059d) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2015 Lepik.stv <lepik.stv@gmail.com>
|
||
# based on modification of Dan Smith's and Jim Unroe original work
|
||
#
|
||
... | ... | |
# You should have received a copy of the GNU General Public License
|
||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
from __future__ import print_function
|
||
"""KYD IP-620 radios management module"""
|
||
# TODO: Power on message
|
||
... | ... | |
self.pipe.write("\x06")
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Radio refused to exit programming mode: %s" % e)
|
||
def _ip620_enter_programming_mode(self):
|
||
... | ... | |
_ack = self.pipe.read(1)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Error communicating with radio: %s" % e)
|
||
if not _ack:
|
||
raise errors.RadioError("No response from radio")
|
||
... | ... | |
_ident = self.pipe.read(8)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Error communicating with radio: %s" % e)
|
||
if not _ident.startswith("\x06\x4B\x47\x36\x37\x01\x56\xF8"):
|
||
print util.hexprint(_ident)
|
||
print(util.hexprint(_ident))
|
||
raise errors.RadioError("Radio returned unknown identification string")
|
||
try:
|
||
self.pipe.write(CMD_ACK)
|
||
_ack = self.pipe.read(1)
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Error communicating with radio: %s" % e)
|
||
if _ack != CMD_ACK:
|
||
raise errors.RadioError("Radio refused to enter programming mode")
|
||
... | ... | |
self._mmap = self._do_download()
|
||
except errors.RadioError:
|
||
raise
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
self.process_mmap()
|
||
... | ... | |
setattr(self._memobj.settings_misc,
|
||
element.get_name(),
|
||
element.value)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
||
... | ... | |
setattr(_settings_misc, setting, newval)
|
||
else:
|
||
setattr(_settings, setting, newval)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
LOG.debug(element.get_name())
|
||
raise
|
chirp/drivers/leixen.py (revision 83f364736678ae6000c8f4da1e48ab4113b78f69) | ||
---|---|---|
# coding=utf-8
|
||
# Copyright 2014 Tom Hayward <tom@tomh.us>
|
||
#
|
||
# This program is free software: you can redistribute it and/or modify
|
||
... | ... | |
]
|
||
MODES = ["NFM", "FM"]
|
||
WTFTONES = map(float, xrange(56, 64))
|
||
WTFTONES = map(float, range(56, 64))
|
||
TONES = WTFTONES + chirp_common.TONES
|
||
DTCS_CODES = [17, 50, 645] + chirp_common.DTCS_CODES
|
||
DTCS_CODES.sort()
|
||
... | ... | |
# util.hexprint(frame).replace("\n", "\n ")))
|
||
try:
|
||
radio.pipe.write(frame)
|
||
except Exception, e:
|
||
except Exception as e:
|
||
raise errors.RadioError("Failed to communicate with radio: %s" % e)
|
||
... | ... | |
def sync_in(self):
|
||
try:
|