Fix style issues in ft60.py (#2355)

This commit is contained in:
Zachary T Welch 2015-03-04 12:12:52 -08:00
parent 80966b77ba
commit f4f5c6cb9e
2 changed files with 175 additions and 142 deletions

View File

@ -13,7 +13,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import time, os, logging
import time
import os
import logging
from chirp.drivers import yaesu_clone
from chirp import chirp_common, memmap, bitwise, directory, errors
from chirp.settings import RadioSetting, RadioSettingGroup, \
@ -26,12 +29,14 @@ LOG = logging.getLogger(__name__)
ACK = "\x06"
def _send(pipe, data):
pipe.write(data)
echo = pipe.read(len(data))
if echo != data:
raise errors.RadioError("Error reading echo (Bad cable?)")
def _download(radio):
data = ""
for i in range(0, 10):
@ -56,7 +61,8 @@ def _download(radio):
if len(chunk) == 1 and i == 447:
break
elif len(chunk) != 64:
raise Exception("Reading block %i was short (%i)" % (i, len(chunk)))
raise Exception("Reading block %i was short (%i)" %
(i, len(chunk)))
if radio.status_fn:
status = chirp_common.Status()
status.cur = i * 64
@ -66,6 +72,7 @@ def _download(radio):
return memmap.MemoryMap(data)
def _upload(radio):
_send(radio.pipe, radio.get_mmap()[0:8])
@ -87,6 +94,7 @@ def _upload(radio):
status.msg = "Cloning to radio"
radio.status_fn(status)
def _decode_freq(freqraw):
freq = int(freqraw) * 10000
if freq > 8000000000:
@ -101,6 +109,7 @@ def _decode_freq(freqraw):
return freq
def _encode_freq(freq):
freqraw = freq / 10000
flags = 0x00
@ -110,6 +119,7 @@ def _encode_freq(freq):
flags += 0x40
return freqraw, flags
def _decode_name(mem):
name = ""
for i in mem:
@ -270,7 +280,7 @@ POWER_LEVELS = [chirp_common.PowerLevel("High", watts=5.0),
STEPS = [5.0, 10.0, 12.5, 15.0, 20.0, 25.0, 50.0, 100.0]
SKIPS = ["", "S", "P"]
CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ [?]^__|`?$%&-()*+,-,/|;/=>?@"
SPECIALS = ["%s%d" % (c,i+1) for i in range(0, 50) for c in ('L', 'U') ]
SPECIALS = ["%s%d" % (c, i + 1) for i in range(0, 50) for c in ('L', 'U')]
class FT60BankModel(chirp_common.BankModel):
@ -293,8 +303,9 @@ class FT60BankModel(chirp_common.BankModel):
def remove_memory_from_mapping(self, memory, bank):
number = (memory.number - 1) / 8
mask = 1 << ((memory.number - 1) & 7)
if self._radio._memobj.banks[bank.index].memory[number].get_bits(mask) != mask:
raise Exception("Memory %i is not in bank %s." % \
m = self._radio._memobj.banks[bank.index].memory[number]
if m.get_bits(mask) != mask:
raise Exception("Memory %i is not in bank %s." %
(memory.number, bank))
self._radio._memobj.banks[bank.index].memory[number].clr_bits(mask)
@ -303,7 +314,8 @@ class FT60BankModel(chirp_common.BankModel):
for i in range(*self._radio.get_features().memory_bounds):
number = (i - 1) / 8
mask = 1 << ((i - 1) & 7)
if self._radio._memobj.banks[bank.index].memory[number].get_bits(mask) == mask:
m = self._radio._memobj.banks[bank.index].memory[number]
if m.get_bits(mask) == mask:
memories.append(self._radio.get_memory(i))
return memories
@ -312,10 +324,12 @@ class FT60BankModel(chirp_common.BankModel):
for bank in self.get_mappings():
number = (memory.number - 1) / 8
mask = 1 << ((memory.number - 1) & 7)
if self._radio._memobj.banks[bank.index].memory[number].get_bits(mask) == mask:
m = self._radio._memobj.banks[bank.index].memory[number]
if m.get_bits(mask) == mask:
banks.append(bank)
return banks
@directory.register
class FT60Radio(yaesu_clone.YaesuCloneModeRadio):
"""Yaesu FT-60"""
@ -330,21 +344,21 @@ class FT60Radio(yaesu_clone.YaesuCloneModeRadio):
def get_prompts(cls):
rp = chirp_common.RadioPrompts()
rp.pre_download = _(dedent("""\
1. Turn radio off.
2. Connect cable to MIC/SP jack.
3. Press and hold in the [MONI] switch while turning the
1. Turn radio off.
2. Connect cable to MIC/SP jack.
3. Press and hold in the [MONI] switch while turning the
radio on.
4. Rotate the DIAL job to select "F8 CLONE".
5. Press the [F/W] key momentarily.
6. <b>After clicking OK</b>, press the [PTT] switch to send image."""))
4. Rotate the DIAL job to select "F8 CLONE".
5. Press the [F/W] key momentarily.
6. <b>After clicking OK</b>, press the [PTT] switch to send image."""))
rp.pre_upload = _(dedent("""\
1. Turn radio off.
2. Connect cable to MIC/SP jack.
3. Press and hold in the [MONI] switch while turning the
1. Turn radio off.
2. Connect cable to MIC/SP jack.
3. Press and hold in the [MONI] switch while turning the
radio on.
4. Rotate the DIAL job to select "F8 CLONE".
5. Press the [F/W] key momentarily.
6. Press the [MONI] switch ("--RX--" will appear on the LCD)."""))
4. Rotate the DIAL job to select "F8 CLONE".
5. Press the [F/W] key momentarily.
6. Press the [MONI] switch ("--RX--" will appear on the LCD)."""))
return rp
def get_features(self):
@ -372,7 +386,7 @@ class FT60Radio(yaesu_clone.YaesuCloneModeRadio):
return FT60BankModel(self)
def _checksums(self):
return [ yaesu_clone.YaesuChecksum(0x0000, 0x6FC7) ]
return [yaesu_clone.YaesuChecksum(0x0000, 0x6FC7)]
def sync_in(self):
try:
@ -410,199 +424,219 @@ class FT60Radio(yaesu_clone.YaesuCloneModeRadio):
misc = RadioSettingGroup("misc", "Miscellaneous Settings")
mbls = RadioSettingGroup("banks", "Memory Bank Link Scan")
setmode = RadioSettings(repeater, ctcss, arts, scan, power, wires, eai, switch, misc, mbls)
setmode = RadioSettings(repeater, ctcss, arts, scan, power,
wires, eai, switch, misc, mbls)
# APO
opts = [ "OFF" ] + [ "%0.1f" % (x * 0.5) for x in range(1, 24+1) ]
misc.append( RadioSetting("apo", "Automatic Power Off",
opts = ["OFF"] + ["%0.1f" % (x * 0.5) for x in range(1, 24+1)]
misc.append(
RadioSetting(
"apo", "Automatic Power Off",
RadioSettingValueList(opts, opts[_settings.apo])))
# AR.BEP
opts = [ "OFF" ] + [ "INRANG" ] + [ "ALWAYS" ]
arts.append( RadioSetting("ar_bep", "ARTS Beep",
opts = ["OFF", "INRANG", "ALWAYS"]
arts.append(
RadioSetting(
"ar_bep", "ARTS Beep",
RadioSettingValueList(opts, opts[_settings.ar_bep])))
# AR.INT
opts = ["25 SEC"] + [ "15 SEC" ]
arts.append( RadioSetting("ar_int", "ARTS Polling Interval",
opts = ["25 SEC", "15 SEC"]
arts.append(
RadioSetting(
"ar_int", "ARTS Polling Interval",
RadioSettingValueList(opts, opts[_settings.ar_int])))
# ARS
opts = [ "OFF" ] + [ "ON" ]
repeater.append( RadioSetting("ars", "Automatic Repeater Shift",
opts = ["OFF", "ON"]
repeater.append(
RadioSetting(
"ars", "Automatic Repeater Shift",
RadioSettingValueList(opts, opts[_settings.ars])))
# BCLO
opts = [ "OFF" ] + [ "ON" ]
misc.append( RadioSetting("bclo", "Bush Channel Lock-Out",
opts = ["OFF", "ON"]
misc.append(RadioSetting(
"bclo", "Bush Channel Lock-Out",
RadioSettingValueList(opts, opts[_settings.bclo])))
# BEEP
opts = [ "OFF" ] + [ "KEY" ] + [ "KEY+SC" ]
rs = RadioSetting("beep_key", "Enable the Beeper",
RadioSettingValueList(opts, opts[_settings.beep_key + _settings.beep_sc]))
opts = ["OFF", "KEY", "KEY+SC"]
rs = RadioSetting(
"beep_key", "Enable the Beeper",
RadioSettingValueList(
opts, opts[_settings.beep_key + _settings.beep_sc]))
def apply_beep(s, obj):
setattr(obj, "beep_key", (int(s.value) & 1) or ((int(s.value) >> 1) & 1))
setattr(obj, "beep_key",
(int(s.value) & 1) or ((int(s.value) >> 1) & 1))
setattr(obj, "beep_sc", (int(s.value) >> 1) & 1)
rs.set_apply_callback(apply_beep, self._memobj.settings);
rs.set_apply_callback(apply_beep, self._memobj.settings)
switch.append(rs)
# BELL
opts = [ "OFF" ] + [ "1T" ] + [ "3T" ] + [ "5T" ] + [ "8T" ] + [ "CONT" ]
ctcss.append( RadioSetting("bell", "Bell Repetitions",
opts = ["OFF", "1T", "3T", "5T", "8T", "CONT"]
ctcss.append(RadioSetting("bell", "Bell Repetitions",
RadioSettingValueList(opts, opts[_settings.bell])))
# BSY.LED
opts = [ "ON" ] + [ "OFF" ]
misc.append( RadioSetting("bsy_led", "Busy LED",
opts = ["ON", "OFF"]
misc.append(RadioSetting("bsy_led", "Busy LED",
RadioSettingValueList(opts, opts[_settings.bsy_led])))
# DCS.NR
opts = [ "TR/X N" ] + [ "RX R" ] + [ "TX R" ] + [ "T/RX R" ]
ctcss.append( RadioSetting("dcs_nr", "\"Inverted\" DCS Code Decoding",
opts = ["TR/X N", "RX R", "TX R", "T/RX R"]
ctcss.append(RadioSetting("dcs_nr", "\"Inverted\" DCS Code Decoding",
RadioSettingValueList(opts, opts[_settings.dcs_nr])))
# DT.DLY
opts = [ "50 MS" ] + [ "100 MS" ] + [ "250 MS" ] + [ "450 MS" ] + \
[ "750 MS" ]+ [ "1000 MS" ]
ctcss.append( RadioSetting("dt_dly", "DTMF Autodialer Delay Time",
opts = ["50 MS", "100 MS", "250 MS", "450 MS", "750 MS", "1000 MS"]
ctcss.append(RadioSetting("dt_dly", "DTMF Autodialer Delay Time",
RadioSettingValueList(opts, opts[_settings.dt_dly])))
# DT.SPD
opts = [ "50 MS" ] + [ "100 MS" ]
ctcss.append( RadioSetting("dt_spd", "DTMF Autodialer Sending Speed",
opts = ["50 MS", "100 MS"]
ctcss.append(RadioSetting("dt_spd", "DTMF Autodialer Sending Speed",
RadioSettingValueList(opts, opts[_settings.dt_spd])))
# EDG.BEP
opts = [ "OFF" ] + [ "ON" ]
misc.append( RadioSetting("edg_bep", "Band Edge Beeper",
opts = ["OFF", "ON"]
misc.append(RadioSetting("edg_bep", "Band Edge Beeper",
RadioSettingValueList(opts, opts[_settings.edg_bep])))
# I.NET
opts = [ "OFF" ] + [ "COD" ]+ [ "MEM" ]
opts = ["OFF", "COD", "MEM"]
rs = RadioSetting("inet", "Internet Link Connection",
RadioSettingValueList(opts, opts[_settings.inet - 1]))
RadioSettingValueList(
opts, opts[_settings.inet - 1]))
def apply_inet(s, obj):
setattr(obj, s.get_name(), int(s.value) + 1)
rs.set_apply_callback(apply_inet, self._memobj.settings);
rs.set_apply_callback(apply_inet, self._memobj.settings)
wires.append(rs)
# INT.CD
opts = [ "CODE 0" ] + [ "CODE 1" ] + [ "CODE 2" ] + [ "CODE 3" ] + [ "CODE 4" ] + \
[ "CODE 5" ] + [ "CODE 6" ] + [ "CODE 7" ] + [ "CODE 8" ] + [ "CODE 9" ] + \
[ "CODE A" ] + [ "CODE B" ] + [ "CODE C" ] + [ "CODE D" ] + [ "CODE E" ] + [ "CODE F" ]
wires.append( RadioSetting("int_cd", "Access Number for WiRES(TM)",
opts = ["CODE 0", "CODE 1", "CODE 2", "CODE 3", "CODE 4",
"CODE 5", "CODE 6", "CODE 7", "CODE 8", "CODE 9",
"CODE A", "CODE B", "CODE C", "CODE D", "CODE E", "CODE F"]
wires.append(RadioSetting("int_cd", "Access Number for WiRES(TM)",
RadioSettingValueList(opts, opts[_settings.int_cd])))
# INT.MR
opts = [ "d1" ] + [ "d2" ] + [ "d3" ] + [ "d4" ] + [ "d5" ] + \
[ "d6" ] + [ "d7" ] + [ "d8" ] + [ "d9" ]
wires.append( RadioSetting("int_mr", "Access Number (DTMF) for Non-WiRES(TM)",
opts = ["d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9"]
wires.append(RadioSetting(
"int_mr", "Access Number (DTMF) for Non-WiRES(TM)",
RadioSettingValueList(opts, opts[_settings.int_mr])))
# LAMP
opts = [ "KEY" ] + [ "5SEC" ] + [ "TOGGLE" ]
switch.append( RadioSetting("lamp", "Lamp Mode",
opts = ["KEY", "5SEC", "TOGGLE"]
switch.append(RadioSetting("lamp", "Lamp Mode",
RadioSettingValueList(opts, opts[_settings.lamp])))
# LOCK
opts = [ "LK KEY" ] + [ "LKDIAL" ] + [ "LK K+D" ] + [ "LK PTT" ] + [ "LP P+K" ] + \
[ "LK P+D" ] + [ "LK ALL" ]
opts = ["LK KEY", "LKDIAL", "LK K+D", "LK PTT",
"LP P+K", "LK P+D", "LK ALL"]
rs = RadioSetting("lock", "Control Locking",
RadioSettingValueList(opts, opts[_settings.lock - 1]))
RadioSettingValueList(
opts, opts[_settings.lock - 1]))
def apply_lock(s, obj):
setattr(obj, s.get_name(), int(s.value) + 1)
rs.set_apply_callback(apply_lock, self._memobj.settings);
rs.set_apply_callback(apply_lock, self._memobj.settings)
switch.append(rs)
# M/T-CL
opts = [ "MONI" ] + [ "T-CALL" ]
switch.append( RadioSetting("mt_cl", "MONI Switch Function",
opts = ["MONI", "T-CALL"]
switch.append(RadioSetting("mt_cl", "MONI Switch Function",
RadioSettingValueList(opts, opts[_settings.mt_cl])))
# PAG.ABK
opts = [ "OFF" ] + [ "ON" ]
eai.append( RadioSetting("pag_abk", "Paging Answer Back",
opts = ["OFF", "ON"]
eai.append(RadioSetting("pag_abk", "Paging Answer Back",
RadioSettingValueList(opts, opts[_settings.pag_abk])))
# RESUME
opts = [ "TIME" ] + [ "HOLD" ] + [ "BUSY" ]
scan.append( RadioSetting("resume", "Scan Resume Mode",
opts = ["TIME", "HOLD", "BUSY"]
scan.append(RadioSetting("resume", "Scan Resume Mode",
RadioSettingValueList(opts, opts[_settings.resume])))
# REV/HM
opts = [ "REV" ] + [ "HOME" ]
switch.append( RadioSetting("rev_hm", "HM/RV Key Function",
opts = ["REV", "HOME"]
switch.append(RadioSetting("rev_hm", "HM/RV Key Function",
RadioSettingValueList(opts, opts[_settings.rev_hm])))
# RF.SQL
opts = [ "OFF" ] + [ "S-1" ] + [ "S-2" ] + [ "S-3" ] + [ "S-4" ] + \
[ "S-5" ] + [ "S-6" ] + [ "S-8" ] + [ "S-FULL" ]
misc.append( RadioSetting("rf_sql", "RF Squelch Threshold",
opts = ["OFF", "S-1", "S-2", "S-3", "S-4", "S-5", "S-6",
"S-7", "S-8", "S-FULL"]
misc.append(RadioSetting("rf_sql", "RF Squelch Threshold",
RadioSettingValueList(opts, opts[_settings.rf_sql])))
# PRI.RVT
opts = [ "OFF" ] + [ "ON" ]
scan.append( RadioSetting("pri_rvt", "Priority Revert",
opts = ["OFF", "ON"]
scan.append(RadioSetting("pri_rvt", "Priority Revert",
RadioSettingValueList(opts, opts[_settings.pri_rvt])))
# RXSAVE
opts = [ "OFF" ] + [ "200 MS" ] + [ "300 MS" ] + [ "500 MS" ] + [ "1 S" ] + [ "2 S" ]
power.append( RadioSetting("rxsave", "Receive Mode Batery Savery Interval",
opts = ["OFF", "200 MS", "300 MS", "500 MS", "1 S", "2 S"]
power.append(RadioSetting(
"rxsave", "Receive Mode Batery Savery Interval",
RadioSettingValueList(opts, opts[_settings.rxsave])))
# S.SRCH
opts = [ "SINGLE" ] + [ "CONT" ]
misc.append( RadioSetting("ssrch", "Smart Search Sweep Mode",
opts = ["SINGLE", "CONT"]
misc.append(RadioSetting("ssrch", "Smart Search Sweep Mode",
RadioSettingValueList(opts, opts[_settings.ssrch])))
# SCN.MD
opts = [ "MEM" ] + [ "ONLY" ]
scan.append( RadioSetting("scn_md", "Memory Scan Channel Selection Mode",
opts = ["MEM", "ONLY"]
scan.append(RadioSetting(
"scn_md", "Memory Scan Channel Selection Mode",
RadioSettingValueList(opts, opts[_settings.scn_md])))
# SCN.LMP
opts = [ "OFF" ] + [ "ON" ]
scan.append( RadioSetting("scn_lmp", "Scan Lamp",
opts = ["OFF", "ON"]
scan.append(RadioSetting("scn_lmp", "Scan Lamp",
RadioSettingValueList(opts, opts[_settings.scn_lmp])))
# TOT
opts = [ "OFF" ] + [ "%dMIN" % (x) for x in range(1, 30+1) ]
misc.append( RadioSetting("tot", "Timeout Timer",
opts = ["OFF"] + ["%dMIN" % (x) for x in range(1, 30+1)]
misc.append(RadioSetting("tot", "Timeout Timer",
RadioSettingValueList(opts, opts[_settings.tot])))
# TX.LED
opts = [ "ON" ] + [ "OFF" ]
misc.append( RadioSetting("tx_led", "TX LED",
opts = ["ON", "OFF"]
misc.append(RadioSetting("tx_led", "TX LED",
RadioSettingValueList(opts, opts[_settings.tx_led])))
# TXSAVE
opts = [ "OFF" ] + [ "ON" ]
power.append( RadioSetting("txsave", "Transmitter Battery Saver",
opts = ["OFF", "ON"]
power.append(RadioSetting("txsave", "Transmitter Battery Saver",
RadioSettingValueList(opts, opts[_settings.txsave])))
# VFO.BND
opts = [ "BAND" ] + [ "ALL" ]
misc.append( RadioSetting("vfo_bnd", "VFO Band Edge Limiting",
opts = ["BAND", "ALL"]
misc.append(RadioSetting("vfo_bnd", "VFO Band Edge Limiting",
RadioSettingValueList(opts, opts[_settings.vfo_bnd])))
# WX.ALT
opts = [ "OFF" ] + [ "ON" ]
scan.append( RadioSetting("wx_alt", "Weather Alert Scan",
opts = ["OFF", "ON"]
scan.append(RadioSetting("wx_alt", "Weather Alert Scan",
RadioSettingValueList(opts, opts[_settings.wx_alt])))
# MBS
for i in range(0, 10):
opts = [ "OFF" ] + [ "ON" ]
opts = ["OFF", "ON"]
mbs = (self._memobj.mbs >> i) & 1
rs = RadioSetting("mbs%i" % i, "Bank %s Scan" % (i + 1),
RadioSettingValueList(opts, opts[mbs]))
def apply_mbs(s, index):
if int(s.value):
self._memobj.mbs |= (1 << index)
else:
self._memobj.mbs &= ~(1 << index);
rs.set_apply_callback(apply_mbs, i);
self._memobj.mbs &= ~(1 << index)
rs.set_apply_callback(apply_mbs, i)
mbls.append(rs)
return setmode
@ -677,11 +711,11 @@ class FT60Radio(yaesu_clone.YaesuCloneModeRadio):
mem.mode = _mem.isam and "AM" or _mem.isnarrow and "NFM" or "FM"
mem.tuning_step = STEPS[_mem.step]
if not _skp is None:
if _skp is not None:
skip = _skp["skip%i" % ((mem.number - 1) % 4)]
mem.skip = SKIPS[skip]
if not _nam is None:
if _nam is not None:
if _nam.use_name and _nam.valid:
mem.name = _decode_name(_nam.name).rstrip()
@ -725,10 +759,10 @@ class FT60Radio(yaesu_clone.YaesuCloneModeRadio):
_mem.isam = mem.mode == "AM"
_mem.step = STEPS.index(mem.tuning_step)
if not _skp is None:
if _skp is not None:
_skp["skip%i" % ((mem.number - 1) % 4)] = SKIPS.index(mem.skip)
if not _nam is None:
if _nam is not None:
_nam.name = _encode_name(mem.name)
_nam.use_name = mem.name.strip() and True or False
_nam.valid = _nam.use_name

View File

@ -1,7 +1,6 @@
# cpep8.blacklist: The list of files that do not meet PEP8 standards.
# DO NOT ADD NEW FILES!! Instead, fix the code to be compliant.
# Over time, this list should shrink and (eventually) be eliminated.
./chirp/drivers/ft60.py
./chirp/drivers/ft7800.py
./chirp/drivers/ft90.py
./chirp/drivers/ftm350.py