# HG changeset patch
# User Jim Unroe <rock.unroe@gmail.com>
# Date 1640799844 18000
#      Wed Dec 29 12:44:04 2021 -0500
# Node ID da9d77891f19be639baa266b39fa06a50ce6b1aa
# Parent  b0896c5fe0a7069f4f3a4b121d6fd6d515ca2245
[RB75] Add Retevis RB75

This patch adds support for the Retevis RB75 GMRS radio.

addresses #9263

diff -r b0896c5fe0a7 -r da9d77891f19 chirp/drivers/radtel_t18.py
--- a/chirp/drivers/radtel_t18.py	Tue Dec 28 21:36:22 2021 -0500
+++ b/chirp/drivers/radtel_t18.py	Wed Dec 29 12:44:04 2021 -0500
@@ -67,7 +67,8 @@
     u8 unknown3:4,
        unknown4:1,
        unknown5:2,
-       power10w:1;
+       power10w:1;       // Retevis RT85 power 10w on/off
+                         // Retevis RT75 stop TX with low voltage
 } settings;
 """
 
@@ -152,6 +153,12 @@
                       "VOX",
                       "Busy Channel Lock"]
 SPECCODE_LIST = ["SpeCode 1", "SpeCode 2"]
+SIDEKEY75_LIST = ["Off",
+                  "Monitor Momentary",
+                  "Scan",
+                  "VOX",
+                  "Monitor",
+                  "Announciation"]
 
 SETTING_LISTS = {
     "voiceprompt": VOICE_LIST,
@@ -181,6 +188,8 @@
                462.7125, 462.5500, 462.5750, 462.6000,
                462.6500, 462.6750, 462.7000, 462.7250]
 
+GMRS_FREQS = FRS_FREQS1 + FRS_FREQS2 + FRS_FREQS3 * 2
+
 MURS_FREQS = [151.820, 151.880, 151.940, 154.570, 154.600]
 
 PMR_FREQS1 = [446.00625, 446.01875, 446.03125, 446.04375, 446.05625,
@@ -352,7 +361,7 @@
     _upper = 16
     _mem_params = (_upper  # number of channels
                    )
-    _frs = _murs = _pmr = False
+    _frs = _murs = _pmr = _gmrs = False
 
     _ranges = [
         (0x0000, 0x03F0),
@@ -398,6 +407,7 @@
 
         _msg_freq = 'Memory location cannot change frequency'
         _msg_simplex = 'Memory location only supports Duplex:(None)'
+        _msg_duplex = 'Memory location only supports Duplex: +'
         _msg_nfm = 'Memory location only supports Mode: NFM'
         _msg_txp = 'Memory location only supports Power: Low'
 
@@ -427,6 +437,33 @@
                 # warn user can't change mode
                 msgs.append(chirp_common.ValidationError(_msg_nfm))
 
+        # GMRS only models
+        if self._gmrs:
+            # range of memories with values set by FCC rules
+            if mem.freq != int(GMRS_FREQS[mem.number - 1] * 1000000):
+                # warn user can't change frequency
+                msgs.append(chirp_common.ValidationError(_msg_freq))
+            if mem.number >= 8 and mem.number <= 14:
+                if str(mem.power) != "Low":
+                    # warn user can't change power
+                    msgs.append(chirp_common.ValidationError(_msg_txp))
+
+                if str(mem.mode) != "NFM":
+                    # warn user can't change mode
+                    msgs.append(chirp_common.ValidationError(_msg_nfm))
+
+            if mem.number >= 1 and mem.number <= 22:
+                # channels 1 - 22 are simplex only
+                if str(mem.duplex) != "":
+                    # warn user can't change duplex
+                    msgs.append(chirp_common.ValidationError(_msg_simplex))
+
+            if mem.number >= 23 and mem.number <= 30:
+                # channels 23 - 30 are duplex + only
+                if str(mem.duplex) != "+":
+                    # warn user can't change duplex
+                    msgs.append(chirp_common.ValidationError(_msg_duplex))
+
         # MURS only models
         if self._murs:
             # range of memories with values set by FCC rules
@@ -545,6 +582,13 @@
 
             mem.immutable = FRS_IMMUTABLE
 
+        if self._gmrs:
+            GMRS_IMMUTABLE = ["freq", "duplex", "offset"]
+            if mem.number >= 8 and mem.number <= 14:
+                GMRS_IMMUTABLE = GMRS_IMMUTABLE + ["mode", "power"]
+
+            mem.immutable = GMRS_IMMUTABLE
+
         if self._murs:
             MURS_IMMUTABLE = ["freq", "duplex", "offset"]
             if mem.number <= 3:
@@ -587,6 +631,20 @@
                 if self._upper == 22:
                     if mem.number >= 8 and mem.number <= 14:
                         _mem.highpower = False
+            elif self._gmrs:
+                _mem.set_raw("\xFF" * 12 + "\x00" + "\xFF" * 3)
+                GMRS_FREQ = int(GMRS_FREQS[mem.number - 1] * 100000)
+                if mem.number > 22:
+                    _mem.rxfreq = GMRS_FREQ
+                    _mem.txfreq = int(_mem.rxfreq) + 500000
+                else:
+                    _mem.rxfreq = _mem.txfreq = GMRS_FREQ
+                if mem.number >= 8 and mem.number <= 14:
+                    _mem.narrow = True
+                    _mem.highpower = False
+                else:
+                    _mem.narrow = False
+                    _mem.highpower = True
             elif self._murs:
                 _mem.set_raw("\xFF" * 12 + "\x00" + "\xFF" * 3)
                 MURS_FREQ = int(MURS_FREQS[mem.number - 1] * 100000)
@@ -770,6 +828,35 @@
                               RadioSettingValueBoolean(_settings.power10w))
             basic.append(rs)
 
+        if self.MODEL == "RB75":
+            rs = RadioSetting("sidekey2", "Side Key 1(Short)",
+                              RadioSettingValueList(
+                                  SIDEKEY75_LIST,
+                                  SIDEKEY75_LIST[_settings.sidekey2]))
+            basic.append(rs)
+
+            rs = RadioSetting("sidekey1L", "Side Key 1(Long)",
+                              RadioSettingValueList(
+                                  SIDEKEY75_LIST,
+                                  SIDEKEY75_LIST[_settings.sidekey1L]))
+            basic.append(rs)
+
+            rs = RadioSetting("sidekey2S", "Side Key 2(Short)",
+                              RadioSettingValueList(
+                                  SIDEKEY75_LIST,
+                                  SIDEKEY75_LIST[_settings.sidekey2S]))
+            basic.append(rs)
+
+            rs = RadioSetting("sidekey2L", "Side Key 2(Long)",
+                              RadioSettingValueList(
+                                  SIDEKEY75_LIST,
+                                  SIDEKEY75_LIST[_settings.sidekey2L]))
+            basic.append(rs)
+
+            rs = RadioSetting("power10w", "Low Voltage Stop TX",
+                              RadioSettingValueBoolean(_settings.power10w))
+            basic.append(rs)
+
         return top
 
     def set_settings(self, settings):
@@ -979,3 +1066,21 @@
 
     _magic = "H19GRAM"
     _fingerprint = "SMP558" + "\x02"
+
+
+@directory.register
+class RB75Radio(T18Radio):
+    """Retevis RB75"""
+    VENDOR = "Retevis"
+    MODEL = "RB75"
+    ACK_BLOCK = False
+
+    POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=0.50),
+                    chirp_common.PowerLevel("High", watts=5.00)]
+
+    _magic = "KVOGRAM"
+    _fingerprint = "SMP558" + "\x00"
+    _upper = 30
+    _mem_params = (_upper  # number of channels
+                   )
+    _gmrs = True
