[chirp_devel] [PATCH 1 of 3] Add import logic helper to convert odd split to offset. #185

Tom Hayward
Wed Feb 6 09:09:00 PST 2013


# HG changeset patch
# User Tom Hayward <tom at tomh.us>
# Date 1360126719 28800
# Node ID 257d98b3f5717671face8ae70680a50d83c81a1c
# Parent  9fea9e34a71ba4b63a3d89e79a072e98d21539f5
Add import logic helper to convert odd split to offset. #185

diff -r 9fea9e34a71b -r 257d98b3f571 chirp/import_logic.py
--- a/chirp/import_logic.py	Tue Feb 05 19:42:27 2013 -0800
+++ b/chirp/import_logic.py	Tue Feb 05 20:58:39 2013 -0800
@@ -144,6 +144,34 @@
     if mem.mode == "Auto" and mem.mode not in dstrf.valid_modes:
         mem.mode = _guess_mode_by_frequency(mem.freq)
 
+def _make_offset_with_split(rxfreq, txfreq):
+    offset = txfreq - rxfreq
+    
+    if offset == 0:
+        return "", offset
+    elif offset > 0:
+        return "+", offset
+    elif offset < 0:
+        return "-", offset * -1
+
+def _import_duplex(dst_radio, srcrf, mem):
+    dstrf = dst_radio.get_features()
+
+    # If a radio does not support odd split, we can use an equivalent offset
+    if mem.duplex == "split" and mem.duplex not in dstrf.valid_duplexes:
+        mem.duplex, mem.offset = _make_offset_with_split(mem.freq, mem.offset)
+        
+        # Enforce maximum offset
+        ranges = [
+            (        0,  500000000,  7000000),
+            (500000000, 3000000000, 50000000),
+        ]
+        for lo, hi, limit in ranges:
+            if mem.freq > lo and mem.freq <= hi:
+                if mem.offset > limit or mem.offset * -1 > limit:
+                    raise DestNotCompatible("Unable to create import memory: "
+                                            "offset is abnormally large.")
+
 def import_mem(dst_radio, src_features, src_mem, overrides={}):
     """Perform import logic to create a destination memory from
     src_mem that will be compatible with @dst_radio"""
@@ -165,6 +193,7 @@
                _import_tone,
                _import_dtcs,
                _import_mode,
+               _import_duplex,
                ]
 
     for helper in helpers:



More information about the chirp_devel mailing list