[chirp_devel] [PATCH] Add radio alias support
# HG changeset patch # User Dan Smith dsmith@danplanet.com # Date 1460678120 25200 # Thu Apr 14 16:55:20 2016 -0700 # Node ID 1a0a36bc2a8d9dc6ec08af2dc775d809e62451c8 # Parent c0b5e35b06659d29a3c72c02fb2ee7423dacc100 Add radio alias support
This introduces a small class called Alias which defines the identifying attributes of a radio model. Radio inherits from that, and also has a list of ALIASES that can be zero or more of those classes. When we construct the clone box where a user chooses a model, show them all the models, including aliases.
#0
diff -r c0b5e35b0665 -r 1a0a36bc2a8d chirp/chirp_common.py --- a/chirp/chirp_common.py Mon Apr 11 22:47:58 2016 -0400 +++ b/chirp/chirp_common.py Thu Apr 14 16:55:20 2016 -0700 @@ -987,13 +987,17 @@ pass
-class Radio(object): +class Alias(object): + VENDOR = "Unknown" + MODEL = "Unknown" + VARIANT = "" + + +class Radio(Alias): """Base class for all Radio drivers""" BAUD_RATE = 9600 HARDWARE_FLOW = False - VENDOR = "Unknown" - MODEL = "Unknown" - VARIANT = "" + ALIASES = []
def status_fn(self, status): """Deliver @status to the UI""" diff -r c0b5e35b0665 -r 1a0a36bc2a8d chirp/drivers/uv5r.py --- a/chirp/drivers/uv5r.py Mon Apr 11 22:47:58 2016 -0400 +++ b/chirp/drivers/uv5r.py Thu Apr 14 16:55:20 2016 -0700 @@ -572,8 +572,6 @@ "!@#$%^&*()+-=[]:";'<>?,./"
-# Uncomment this to actually register this radio in CHIRP -@directory.register class BaofengUV5R(chirp_common.CloneModeRadio, chirp_common.ExperimentalRadio): """Baofeng UV-5R""" @@ -1571,6 +1569,16 @@ raise
+class UV5XAlias(chirp_common.Alias): + VENDOR = "Baofeng" + MODEL = "UV-5X" + + +@directory.register +class BaofengUV5RGeneric(BaofengUV5R): + ALIASES = [UV5XAlias] + + @directory.register class BaofengF11Radio(BaofengUV5R): VENDOR = "Baofeng" diff -r c0b5e35b0665 -r 1a0a36bc2a8d chirp/ui/clone.py --- a/chirp/ui/clone.py Mon Apr 11 22:47:58 2016 -0400 +++ b/chirp/ui/clone.py Thu Apr 14 16:55:20 2016 -0700 @@ -13,6 +13,7 @@ # 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 collections import threading import logging import os @@ -72,16 +73,15 @@ return miscwidgets.make_choice([], False)
def __make_vendor(self, model): - vendors = {} + vendors = collections.defaultdict(list) for rclass in sorted(directory.DRV_TO_RADIO.values()): if not issubclass(rclass, chirp_common.CloneModeRadio) and \ not issubclass(rclass, chirp_common.LiveRadio): continue
- if rclass.VENDOR not in vendors: - vendors[rclass.VENDOR] = [] - vendors[rclass.VENDOR].append(rclass) + for alias in rclass.ALIASES: + vendors[alias.VENDOR].append(alias)
self.__vendors = vendors
@@ -187,6 +187,17 @@ if rclass.MODEL == model: cs.radio_class = rclass break + alias_match = None + for alias in rclass.ALIASES: + if alias.MODEL == model: + alias_match = rclass + break + if alias_match: + cs.radio_class = rclass + LOG.debug( + 'Chose %s alias for %s because model %s selected' % ( + alias_match, cs.radio_class, model)) + break if not cs.radio_class: common.show_error( _("Internal error: Unable to upload to {model}").format(
# HG changeset patch # User Dan Smith dsmith@danplanet.com # Date 1460678120 25200 # Thu Apr 14 16:55:20 2016 -0700 # Node ID 1a0a36bc2a8d9dc6ec08af2dc775d809e62451c8 # Parent c0b5e35b06659d29a3c72c02fb2ee7423dacc100 Add radio alias support
This introduces a small class called Alias which defines the identifying attributes of a radio model. Radio inherits from that, and also has a list of ALIASES that can be zero or more of those classes. When we construct the clone box where a user chooses a model, show them all the models, including aliases.
I'm not in a place I can test this with real radios, so if people could test this I'd appreciate it.
--Dan
Thanks Dan!
I will use it with the clones I have in the btech and send to some users to test before patching, unfortunately I have a trip on sight and maybe I can't complete this process in a short time frame (I will be out of town next week and don't know if I can get access to a internet connection where I go)
73 and thanks for this great hack.
El 14/04/16 a las 19:58, Dan Smith via chirp_devel escribió:
# HG changeset patch # User Dan Smith dsmith@danplanet.com # Date 1460678120 25200 # Thu Apr 14 16:55:20 2016 -0700 # Node ID 1a0a36bc2a8d9dc6ec08af2dc775d809e62451c8 # Parent c0b5e35b06659d29a3c72c02fb2ee7423dacc100 Add radio alias support
This introduces a small class called Alias which defines the identifying attributes of a radio model. Radio inherits from that, and also has a list of ALIASES that can be zero or more of those classes. When we construct the clone box where a user chooses a model, show them all the models, including aliases.
I'm not in a place I can test this with real radios, so if people could test this I'd appreciate it.
--Dan _______________________________________________ chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
participants (2)
-
Dan Smith
-
Pavel Milanes (CO7WT)