Advertisement
howtophil

bf888s.py

Aug 6th, 2020 (edited)
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 21.36 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2013 Andrew Morgan <ziltro@ziltro.com>
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. #
  17. # Note from Phillip J Rhoades (howtophil@gmail.com)
  18. # This is a mod of h777.py giving the BF-888S radio the option to
  19. # enter VHF frequencies. As the box on these radios says, it does
  20. # seem to actually be a VHF/UHF radio (as opposed to the BF-888).
  21. # Can't say it'll work for you, but it is working for me.
  22. # Copy this to your chirp "drivers" folder.
  23. #
  24. # cp bf888s.py /usr/lib/python2.7/dist-packages/chirp/drivers/
  25. #
  26. # Then restart chirpw.
  27. # If all went well, you should see BF-888S as well as BF-888 in
  28. # your list of Baofeng radios and you should be able to now
  29. # enter VHF frequencies...
  30. #
  31. # I can't say it won't kill your radio, but it seems to work for me.
  32. # Also, make sure you have a VHF antenna hooked up.
  33. #
  34. # This seems to work on some BF-888S radios and not others. Some say
  35. # it might work on the BF-888 radios as well. I think this may be
  36. # a firmware issue. https://www.miklor.com/BF888/888-SW-BF888S.php
  37. # My radios have a white QC sticker, which is not listed on
  38. # Miklor...
  39. #
  40.  
  41. import time
  42. import os
  43. import struct
  44. import unittest
  45. import logging
  46.  
  47. from chirp import chirp_common, directory, memmap
  48. from chirp import bitwise, errors, util
  49. from chirp.settings import RadioSetting, RadioSettingGroup, \
  50.     RadioSettingValueInteger, RadioSettingValueList, \
  51.     RadioSettingValueBoolean, RadioSettings
  52.  
  53. LOG = logging.getLogger(__name__)
  54.  
  55. MEM_FORMAT = """
  56. #seekto 0x0010;
  57. struct {
  58.    lbcd rxfreq[4];
  59.    lbcd txfreq[4];
  60.    lbcd rxtone[2];
  61.    lbcd txtone[2];
  62.    u8 unknown3:1,
  63.       unknown2:1,
  64.       unknown1:1,
  65.       skip:1,
  66.       highpower:1,
  67.       narrow:1,
  68.       beatshift:1,
  69.       bcl:1;
  70.    u8 unknown4[3];
  71. } memory[16];
  72. #seekto 0x02B0;
  73. struct {
  74.    u8 voiceprompt;
  75.    u8 voicelanguage;
  76.    u8 scan;
  77.    u8 vox;
  78.    u8 voxlevel;
  79.    u8 voxinhibitonrx;
  80.    u8 lowvolinhibittx;
  81.    u8 highvolinhibittx;
  82.    u8 alarm;
  83.    u8 fmradio;
  84. } settings;
  85. #seekto 0x03C0;
  86. struct {
  87.    u8 unused:6,
  88.       batterysaver:1,
  89.       beep:1;
  90.    u8 squelchlevel;
  91.    u8 sidekeyfunction;
  92.    u8 timeouttimer;
  93.    u8 unused2[3];
  94.    u8 unused3:7,
  95.       scanmode:1;
  96. } settings2;
  97. """
  98.  
  99. CMD_ACK = "\x06"
  100. BLOCK_SIZE = 0x08
  101. UPLOAD_BLOCKS = [range(0x0000, 0x0110, 8),
  102.                  range(0x02b0, 0x02c0, 8),
  103.                  range(0x0380, 0x03e0, 8)]
  104.  
  105. # TODO: Is it 1 watt?
  106. H777_POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=1.00),
  107.                      chirp_common.PowerLevel("High", watts=5.00)]
  108. VOICE_LIST = ["English", "Chinese"]
  109. TIMEOUTTIMER_LIST = ["Off", "30 seconds", "60 seconds", "90 seconds",
  110.                      "120 seconds", "150 seconds", "180 seconds",
  111.                      "210 seconds", "240 seconds", "270 seconds",
  112.                      "300 seconds"]
  113. SCANMODE_LIST = ["Carrier", "Time"]
  114.  
  115. SETTING_LISTS = {
  116.     "voice": VOICE_LIST,
  117. }
  118.  
  119.  
  120. def _h777_enter_programming_mode(radio):
  121.     serial = radio.pipe
  122.  
  123.     try:
  124.         serial.write("\x02")
  125.         time.sleep(0.1)
  126.         serial.write("PROGRAM")
  127.         ack = serial.read(1)
  128.     except:
  129.         raise errors.RadioError("Error communicating with radio")
  130.  
  131.     if not ack:
  132.         raise errors.RadioError("No response from radio")
  133.     elif ack != CMD_ACK:
  134.         raise errors.RadioError("Radio refused to enter programming mode")
  135.  
  136.     original_timeout = serial.timeout
  137.     try:
  138.         serial.write("\x02")
  139.         # At least one version of the Baofeng BF-888S has a consistent
  140.         # ~0.33s delay between sending the first five bytes of the
  141.         # version data and the last three bytes. We need to raise the
  142.         # timeout so that the read doesn't finish early.
  143.         serial.timeout = 0.5
  144.         ident = serial.read(8)
  145.     except:
  146.         raise errors.RadioError("Error communicating with radio")
  147.     finally:
  148.         serial.timeout = original_timeout
  149.  
  150.     if not ident.startswith("P3107"):
  151.         LOG.debug(util.hexprint(ident))
  152.         raise errors.RadioError("Radio returned unknown identification string")
  153.  
  154.     try:
  155.         serial.write(CMD_ACK)
  156.         ack = serial.read(1)
  157.     except:
  158.         raise errors.RadioError("Error communicating with radio")
  159.  
  160.     if ack != CMD_ACK:
  161.         raise errors.RadioError("Radio refused to enter programming mode")
  162.  
  163.  
  164. def _h777_exit_programming_mode(radio):
  165.     serial = radio.pipe
  166.     try:
  167.         serial.write("E")
  168.     except:
  169.         raise errors.RadioError("Radio refused to exit programming mode")
  170.  
  171.  
  172. def _h777_read_block(radio, block_addr, block_size):
  173.     serial = radio.pipe
  174.  
  175.     cmd = struct.pack(">cHb", 'R', block_addr, BLOCK_SIZE)
  176.     expectedresponse = "W" + cmd[1:]
  177.     LOG.debug("Reading block %04x..." % (block_addr))
  178.  
  179.     try:
  180.         serial.write(cmd)
  181.         response = serial.read(4 + BLOCK_SIZE)
  182.         if response[:4] != expectedresponse:
  183.             raise Exception("Error reading block %04x." % (block_addr))
  184.  
  185.         block_data = response[4:]
  186.  
  187.         serial.write(CMD_ACK)
  188.         ack = serial.read(1)
  189.     except:
  190.         raise errors.RadioError("Failed to read block at %04x" % block_addr)
  191.  
  192.     if ack != CMD_ACK:
  193.         raise Exception("No ACK reading block %04x." % (block_addr))
  194.  
  195.     return block_data
  196.  
  197.  
  198. def _h777_write_block(radio, block_addr, block_size):
  199.     serial = radio.pipe
  200.  
  201.     cmd = struct.pack(">cHb", 'W', block_addr, BLOCK_SIZE)
  202.     data = radio.get_mmap()[block_addr:block_addr + 8]
  203.  
  204.     LOG.debug("Writing Data:")
  205.     LOG.debug(util.hexprint(cmd + data))
  206.  
  207.     original_timeout = serial.timeout
  208.     try:
  209.         serial.write(cmd + data)
  210.         # Time required to write data blocks varies between individual
  211.         # radios of the Baofeng BF-888S model. The longest seen is
  212.         # ~0.31s.
  213.         serial.timeout = 0.5
  214.         if serial.read(1) != CMD_ACK:
  215.             raise Exception("No ACK")
  216.     except:
  217.         raise errors.RadioError("Failed to send block "
  218.                                 "to radio at %04x" % block_addr)
  219.     finally:
  220.         serial.timeout = original_timeout
  221.  
  222.  
  223. def do_download(radio):
  224.     LOG.debug("download")
  225.     _h777_enter_programming_mode(radio)
  226.  
  227.     data = ""
  228.  
  229.     status = chirp_common.Status()
  230.     status.msg = "Cloning from radio"
  231.  
  232.     status.cur = 0
  233.     status.max = radio._memsize
  234.  
  235.     for addr in range(0, radio._memsize, BLOCK_SIZE):
  236.         status.cur = addr + BLOCK_SIZE
  237.         radio.status_fn(status)
  238.  
  239.         block = _h777_read_block(radio, addr, BLOCK_SIZE)
  240.         data += block
  241.  
  242.         LOG.debug("Address: %04x" % addr)
  243.         LOG.debug(util.hexprint(block))
  244.  
  245.     _h777_exit_programming_mode(radio)
  246.  
  247.     return memmap.MemoryMap(data)
  248.  
  249.  
  250. def do_upload(radio):
  251.     status = chirp_common.Status()
  252.     status.msg = "Uploading to radio"
  253.  
  254.     _h777_enter_programming_mode(radio)
  255.  
  256.     status.cur = 0
  257.     status.max = radio._memsize
  258.  
  259.     for start_addr, end_addr in radio._ranges:
  260.         for addr in range(start_addr, end_addr, BLOCK_SIZE):
  261.             status.cur = addr + BLOCK_SIZE
  262.             radio.status_fn(status)
  263.             _h777_write_block(radio, addr, BLOCK_SIZE)
  264.  
  265.     _h777_exit_programming_mode(radio)
  266.  
  267.  
  268. class ArcshellAR5(chirp_common.Alias):
  269.     VENDOR = 'Arcshell'
  270.     MODEL = 'AR-5'
  271.  
  272.  
  273. class ArcshellAR6(chirp_common.Alias):
  274.     VENDOR = 'Arcshell'
  275.     MODEL = 'AR-6'
  276.  
  277.  
  278. class GV8SAlias(chirp_common.Alias):
  279.     VENDOR = 'Greaval'
  280.     MODEL = 'GV-8S'
  281.  
  282.  
  283. class GV9SAlias(chirp_common.Alias):
  284.     VENDOR = 'Greaval'
  285.     MODEL = 'GV-9S'
  286.  
  287.  
  288. class A8SAlias(chirp_common.Alias):
  289.     VENDOR = 'Ansoko'
  290.     MODEL = 'A-8S'
  291.  
  292.  
  293. class TenwayTW325Alias(chirp_common.Alias):
  294.     VENDOR = 'Tenway'
  295.     MODEL = 'TW-325'
  296.  
  297.  
  298. @directory.register
  299. class H777Radio(chirp_common.CloneModeRadio):
  300.     """HST H-777"""
  301.     # VENDOR = "Heng Shun Tong (恒顺通)"
  302.     # MODEL = "H-777"
  303.     VENDOR = "Baofeng"
  304.     MODEL = "BF-888S"
  305.     BAUD_RATE = 9600
  306.  
  307.     ALIASES = [ArcshellAR5, ArcshellAR6, GV8SAlias, GV9SAlias, A8SAlias,
  308.                TenwayTW325Alias]
  309.     SIDEKEYFUNCTION_LIST = ["Off", "Monitor", "Transmit Power", "Alarm"]
  310.  
  311.     # This code currently requires that ranges start at 0x0000
  312.     # and are continious. In the original program 0x0388 and 0x03C8
  313.     # are only written (all bytes 0xFF), not read.
  314.     # _ranges = [
  315.     #       (0x0000, 0x0110),
  316.     #       (0x02B0, 0x02C0),
  317.     #       (0x0380, 0x03E0)
  318.     #       ]
  319.     # Memory starts looping at 0x1000... But not every 0x1000.
  320.  
  321.     _ranges = [
  322.         (0x0000, 0x0110),
  323.         (0x0380, 0x03E0),
  324.         (0x02B0, 0x02C0),
  325.     ]
  326.     _memsize = 0x03E0
  327.     _has_fm = True
  328.     _has_sidekey = True
  329.  
  330.     def get_features(self):
  331.         rf = chirp_common.RadioFeatures()
  332.         rf.has_settings = True
  333.         rf.valid_modes = ["NFM", "FM"]  # 12.5 KHz, 25 kHz.
  334.         rf.valid_skips = ["", "S"]
  335.         rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS", "Cross"]
  336.         rf.valid_duplexes = ["", "-", "+", "split", "off"]
  337.         rf.can_odd_split = True
  338.         rf.has_rx_dtcs = True
  339.         rf.has_ctone = True
  340.         rf.has_cross = True
  341.         rf.valid_cross_modes = [
  342.             "Tone->Tone",
  343.             "DTCS->",
  344.             "->DTCS",
  345.             "Tone->DTCS",
  346.             "DTCS->Tone",
  347.             "->Tone",
  348.             "DTCS->DTCS"]
  349.         rf.has_tuning_step = False
  350.         rf.has_bank = False
  351.         rf.has_name = False
  352.         rf.memory_bounds = (1, 16)
  353.         rf.valid_bands = [(136000000, 470000000)]
  354.         rf.valid_power_levels = H777_POWER_LEVELS
  355.         rf.valid_tuning_steps = [2.5, 5.0, 6.25, 10.0, 12.5, 15.0, 20.0, 25.0,
  356.                                  50.0, 100.0]
  357.  
  358.         return rf
  359.  
  360.     def process_mmap(self):
  361.         self._memobj = bitwise.parse(MEM_FORMAT, self._mmap)
  362.  
  363.     def sync_in(self):
  364.         self._mmap = do_download(self)
  365.         self.process_mmap()
  366.  
  367.     def sync_out(self):
  368.         do_upload(self)
  369.  
  370.     def get_raw_memory(self, number):
  371.         return repr(self._memobj.memory[number - 1])
  372.  
  373.     def _decode_tone(self, val):
  374.         val = int(val)
  375.         if val == 16665:
  376.             return '', None, None
  377.         elif val >= 12000:
  378.             return 'DTCS', val - 12000, 'R'
  379.         elif val >= 8000:
  380.             return 'DTCS', val - 8000, 'N'
  381.         else:
  382.             return 'Tone', val / 10.0, None
  383.  
  384.     def _encode_tone(self, memval, mode, value, pol):
  385.         if mode == '':
  386.             memval[0].set_raw(0xFF)
  387.             memval[1].set_raw(0xFF)
  388.         elif mode == 'Tone':
  389.             memval.set_value(int(value * 10))
  390.         elif mode == 'DTCS':
  391.             flag = 0x80 if pol == 'N' else 0xC0
  392.             memval.set_value(value)
  393.             memval[1].set_bits(flag)
  394.         else:
  395.             raise Exception("Internal error: invalid mode `%s'" % mode)
  396.  
  397.     def get_memory(self, number):
  398.         _mem = self._memobj.memory[number - 1]
  399.  
  400.         mem = chirp_common.Memory()
  401.  
  402.         mem.number = number
  403.         mem.freq = int(_mem.rxfreq) * 10
  404.  
  405.         # We'll consider any blank (i.e. 0MHz frequency) to be empty
  406.         if mem.freq == 0:
  407.             mem.empty = True
  408.             return mem
  409.  
  410.         if _mem.rxfreq.get_raw() == "\xFF\xFF\xFF\xFF":
  411.             mem.freq = 0
  412.             mem.empty = True
  413.             return mem
  414.  
  415.         if _mem.txfreq.get_raw() == "\xFF\xFF\xFF\xFF":
  416.             mem.duplex = "off"
  417.             mem.offset = 0
  418.         elif int(_mem.rxfreq) == int(_mem.txfreq):
  419.             mem.duplex = ""
  420.             mem.offset = 0
  421.         else:
  422.             mem.duplex = int(_mem.rxfreq) > int(_mem.txfreq) and "-" or "+"
  423.             mem.offset = abs(int(_mem.rxfreq) - int(_mem.txfreq)) * 10
  424.  
  425.         mem.mode = not _mem.narrow and "FM" or "NFM"
  426.         mem.power = H777_POWER_LEVELS[_mem.highpower]
  427.  
  428.         mem.skip = _mem.skip and "S" or ""
  429.  
  430.         txtone = self._decode_tone(_mem.txtone)
  431.         rxtone = self._decode_tone(_mem.rxtone)
  432.         chirp_common.split_tone_decode(mem, txtone, rxtone)
  433.  
  434.         mem.extra = RadioSettingGroup("Extra", "extra")
  435.         rs = RadioSetting("bcl", "Busy Channel Lockout",
  436.                           RadioSettingValueBoolean(not _mem.bcl))
  437.         mem.extra.append(rs)
  438.         rs = RadioSetting("beatshift", "Beat Shift(scramble)",
  439.                           RadioSettingValueBoolean(not _mem.beatshift))
  440.         mem.extra.append(rs)
  441.  
  442.         return mem
  443.  
  444.     def set_memory(self, mem):
  445.         # Get a low-level memory object mapped to the image
  446.         _mem = self._memobj.memory[mem.number - 1]
  447.  
  448.         if mem.empty:
  449.             _mem.set_raw("\xFF" * (_mem.size() / 8))
  450.             return
  451.  
  452.         _mem.rxfreq = mem.freq / 10
  453.  
  454.         if mem.duplex == "off":
  455.             for i in range(0, 4):
  456.                 _mem.txfreq[i].set_raw("\xFF")
  457.         elif mem.duplex == "split":
  458.             _mem.txfreq = mem.offset / 10
  459.         elif mem.duplex == "+":
  460.             _mem.txfreq = (mem.freq + mem.offset) / 10
  461.         elif mem.duplex == "-":
  462.             _mem.txfreq = (mem.freq - mem.offset) / 10
  463.         else:
  464.             _mem.txfreq = mem.freq / 10
  465.  
  466.         txtone, rxtone = chirp_common.split_tone_encode(mem)
  467.         self._encode_tone(_mem.txtone, *txtone)
  468.         self._encode_tone(_mem.rxtone, *rxtone)
  469.  
  470.         _mem.narrow = 'N' in mem.mode
  471.         _mem.highpower = mem.power == H777_POWER_LEVELS[1]
  472.         _mem.skip = mem.skip == "S"
  473.  
  474.         for setting in mem.extra:
  475.             # NOTE: Only two settings right now, both are inverted
  476.             setattr(_mem, setting.get_name(), not int(setting.value))
  477.  
  478.         # When set to one, official programming software (BF-480) shows always
  479.         # "WFM", even if we choose "NFM". Therefore, for compatibility
  480.         # purposes, we will set these to zero.
  481.         _mem.unknown1 = 0
  482.         _mem.unknown2 = 0
  483.         _mem.unknown3 = 0
  484.  
  485.     def get_settings(self):
  486.         _settings = self._memobj.settings
  487.         basic = RadioSettingGroup("basic", "Basic Settings")
  488.         top = RadioSettings(basic)
  489.  
  490.         # TODO: Check that all these settings actually do what they
  491.         # say they do.
  492.  
  493.         rs = RadioSetting("voiceprompt", "Voice prompt",
  494.                           RadioSettingValueBoolean(_settings.voiceprompt))
  495.         basic.append(rs)
  496.  
  497.         rs = RadioSetting("voicelanguage", "Voice language",
  498.                           RadioSettingValueList(
  499.                               VOICE_LIST,
  500.                               VOICE_LIST[_settings.voicelanguage]))
  501.         basic.append(rs)
  502.  
  503.         rs = RadioSetting("scan", "Scan",
  504.                           RadioSettingValueBoolean(_settings.scan))
  505.         basic.append(rs)
  506.  
  507.         rs = RadioSetting("settings2.scanmode", "Scan mode",
  508.                           RadioSettingValueList(
  509.                               SCANMODE_LIST,
  510.                               SCANMODE_LIST[self._memobj.settings2.scanmode]))
  511.         basic.append(rs)
  512.  
  513.         rs = RadioSetting("vox", "VOX",
  514.                           RadioSettingValueBoolean(_settings.vox))
  515.         basic.append(rs)
  516.  
  517.         rs = RadioSetting("voxlevel", "VOX level",
  518.                           RadioSettingValueInteger(
  519.                               1, 5, _settings.voxlevel + 1))
  520.         basic.append(rs)
  521.  
  522.         rs = RadioSetting("voxinhibitonrx", "Inhibit VOX on receive",
  523.                           RadioSettingValueBoolean(_settings.voxinhibitonrx))
  524.         basic.append(rs)
  525.  
  526.         rs = RadioSetting("lowvolinhibittx", "Low voltage inhibit transmit",
  527.                           RadioSettingValueBoolean(_settings.lowvolinhibittx))
  528.         basic.append(rs)
  529.  
  530.         rs = RadioSetting("highvolinhibittx", "High voltage inhibit transmit",
  531.                           RadioSettingValueBoolean(_settings.highvolinhibittx))
  532.         basic.append(rs)
  533.  
  534.         rs = RadioSetting("alarm", "Alarm",
  535.                           RadioSettingValueBoolean(_settings.alarm))
  536.         basic.append(rs)
  537.  
  538.         # TODO: This should probably be called “FM Broadcast Band Radio”
  539.         # or something. I'm not sure if the model actually has one though.
  540.         if self._has_fm:
  541.             rs = RadioSetting("fmradio", "FM function",
  542.                               RadioSettingValueBoolean(_settings.fmradio))
  543.             basic.append(rs)
  544.  
  545.         rs = RadioSetting("settings2.beep", "Beep",
  546.                           RadioSettingValueBoolean(
  547.                               self._memobj.settings2.beep))
  548.         basic.append(rs)
  549.  
  550.         rs = RadioSetting("settings2.batterysaver", "Battery saver",
  551.                           RadioSettingValueBoolean(
  552.                               self._memobj.settings2.batterysaver))
  553.         basic.append(rs)
  554.  
  555.         rs = RadioSetting("settings2.squelchlevel", "Squelch level",
  556.                           RadioSettingValueInteger(
  557.                               0, 9, self._memobj.settings2.squelchlevel))
  558.         basic.append(rs)
  559.  
  560.         if self._has_sidekey:
  561.             rs = RadioSetting("settings2.sidekeyfunction", "Side key function",
  562.                               RadioSettingValueList(
  563.                                   self.SIDEKEYFUNCTION_LIST,
  564.                                   self.SIDEKEYFUNCTION_LIST[
  565.                                       self._memobj.settings2.sidekeyfunction]))
  566.             basic.append(rs)
  567.  
  568.         rs = RadioSetting("settings2.timeouttimer", "Timeout timer",
  569.                           RadioSettingValueList(
  570.                               TIMEOUTTIMER_LIST,
  571.                               TIMEOUTTIMER_LIST[
  572.                                   self._memobj.settings2.timeouttimer]))
  573.         basic.append(rs)
  574.  
  575.         return top
  576.  
  577.     def set_settings(self, settings):
  578.         for element in settings:
  579.             if not isinstance(element, RadioSetting):
  580.                 self.set_settings(element)
  581.                 continue
  582.             else:
  583.                 try:
  584.                     if "." in element.get_name():
  585.                         bits = element.get_name().split(".")
  586.                         obj = self._memobj
  587.                         for bit in bits[:-1]:
  588.                             obj = getattr(obj, bit)
  589.                         setting = bits[-1]
  590.                     else:
  591.                         obj = self._memobj.settings
  592.                         setting = element.get_name()
  593.  
  594.                     if element.has_apply_callback():
  595.                         LOG.debug("Using apply callback")
  596.                         element.run_apply_callback()
  597.                     elif setting == "voxlevel":
  598.                         setattr(obj, setting, int(element.value) - 1)
  599.                     else:
  600.                         LOG.debug("Setting %s = %s" % (setting, element.value))
  601.                         setattr(obj, setting, element.value)
  602.                 except Exception, e:
  603.                     LOG.debug(element.get_name())
  604.                     raise
  605.  
  606.  
  607. class H777TestCase(unittest.TestCase):
  608.  
  609.     def setUp(self):
  610.         self.driver = H777Radio(None)
  611.         self.testdata = bitwise.parse("lbcd foo[2];",
  612.                                       memmap.MemoryMap("\x00\x00"))
  613.  
  614.     def test_decode_tone_dtcs_normal(self):
  615.         mode, value, pol = self.driver._decode_tone(8023)
  616.         self.assertEqual('DTCS', mode)
  617.         self.assertEqual(23, value)
  618.         self.assertEqual('N', pol)
  619.  
  620.     def test_decode_tone_dtcs_rev(self):
  621.         mode, value, pol = self.driver._decode_tone(12023)
  622.         self.assertEqual('DTCS', mode)
  623.         self.assertEqual(23, value)
  624.         self.assertEqual('R', pol)
  625.  
  626.     def test_decode_tone_tone(self):
  627.         mode, value, pol = self.driver._decode_tone(885)
  628.         self.assertEqual('Tone', mode)
  629.         self.assertEqual(88.5, value)
  630.         self.assertEqual(None, pol)
  631.  
  632.     def test_decode_tone_none(self):
  633.         mode, value, pol = self.driver._decode_tone(16665)
  634.         self.assertEqual('', mode)
  635.         self.assertEqual(None, value)
  636.         self.assertEqual(None, pol)
  637.  
  638.     def test_encode_tone_dtcs_normal(self):
  639.         self.driver._encode_tone(self.testdata.foo, 'DTCS', 23, 'N')
  640.         self.assertEqual(8023, int(self.testdata.foo))
  641.  
  642.     def test_encode_tone_dtcs_rev(self):
  643.         self.driver._encode_tone(self.testdata.foo, 'DTCS', 23, 'R')
  644.         self.assertEqual(12023, int(self.testdata.foo))
  645.  
  646.     def test_encode_tone(self):
  647.         self.driver._encode_tone(self.testdata.foo, 'Tone', 88.5, 'N')
  648.         self.assertEqual(885, int(self.testdata.foo))
  649.  
  650.     def test_encode_tone_none(self):
  651.         self.driver._encode_tone(self.testdata.foo, '', 67.0, 'N')
  652.         self.assertEqual(16665, int(self.testdata.foo))
  653.  
  654.  
  655. @directory.register
  656. class ROGA2SRadio(H777Radio):
  657.     VENDOR = "Radioddity"
  658.     MODEL = "GA-2SS-BF-888S"
  659.     _has_fm = False
  660.     SIDEKEYFUNCTION_LIST = ["Off", "Monitor", "Unused", "Alarm"]
  661.  
  662.     @classmethod
  663.     def match_model(cls, filedata, filename):
  664.         # This model is only ever matched via metadata
  665.         return False
  666.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement