[chirp_devel] [PATCH] [bf888] Standardize cloning routines and change name
Dan Smith
Sun Sep 8 17:18:09 PDT 2013
# HG changeset patch
# User Dan Smith <dsmith at danplanet.com>
# Date 1378685888 25200
# Node ID 9a3c970aec76fc46ab49750dd1df3711aafb87ee
# Parent ec2693debe95d81aa0d01108236e04e380e8208b
[bf888] Standardize cloning routines and change name
This patch makes the BF888/H777 driver pass the functional tests. Most
of the change is around making the clone routines return conventional
error messages and the proper exceptions for errors. Also, to run the
functional tests, we have to have a predictable VENDOR and MODEL for
the driver. The chinese name is cool (and correct) but it's going to
get in the way of testing on some systems. For now, call this driver
the Baofeng BF-888. Later, if we can figure out how to differentiate
files for them, we can have a subclass for the H777.
Related to #701
diff -r ec2693debe95 -r 9a3c970aec76 chirp/h777.py
--- a/chirp/h777.py Sun Sep 08 17:18:02 2013 -0700
+++ b/chirp/h777.py Sun Sep 08 17:18:08 2013 -0700
@@ -17,11 +17,10 @@
import time
import os
import struct
-import sys
import unittest
from chirp import chirp_common, directory, memmap
-from chirp import bitwise
+from chirp import bitwise, errors, util
from chirp.settings import RadioSetting, RadioSettingGroup, \
RadioSettingValueInteger, RadioSettingValueList, \
RadioSettingValueBoolean
@@ -89,34 +88,47 @@
"voice" : VOICE_LIST,
}
-def debug_print_hex(hexstr):
- for a in range(0, len(hexstr)):
- sys.stdout.write("%02x " % (ord(hexstr[a])))
-
def _h777_enter_programming_mode(radio):
serial = radio.pipe
- serial.write("\x02")
- time.sleep(0.1)
- serial.write("PROGRAM")
- if serial.read(1) != CMD_ACK:
- raise Exception("Didn't get a response from the radio. "
- "Is it turned on and plugged in firmly?")
+ try:
+ serial.write("\x02")
+ time.sleep(0.1)
+ serial.write("PROGRAM")
+ ack = serial.read(1)
+ except:
+ raise errors.RadioError("Error communicating with radio")
- serial.write("\x02")
- ident = serial.read(8)
+ if not ack:
+ raise errors.RadioError("No response from radio")
+ elif ack != CMD_ACK:
+ raise errors.RadioError("Radio refused to enter programming mode")
+
+ try:
+ serial.write("\x02")
+ ident = serial.read(8)
+ except:
+ raise errors.RadioError("Error communicating with radio")
+
if not ident.startswith("P3107"):
- raise Exception("Invalid response. "
- "Is this really the correct model of radio?")
+ print util.hexprint(ident)
+ raise errors.RadioError("Radio returned unknown identification string")
- serial.write(CMD_ACK)
- if serial.read(1) != CMD_ACK:
- raise Exception("Invalid response. "
- "Is this really the correct model of radio?")
+ try:
+ serial.write(CMD_ACK)
+ ack = serial.read(1)
+ except:
+ raise errors.RadioError("Error communicating with radio")
+
+ if ack != CMD_ACK:
+ raise errors.RadioError("Radio refused to enter programming mode")
def _h777_exit_programming_mode(radio):
serial = radio.pipe
- serial.write("E")
+ try:
+ serial.write("E")
+ except:
+ raise errors.RadioError("Radio refused to exit programming mode")
def _h777_read_block(radio, block_addr, block_size):
serial = radio.pipe
@@ -126,15 +138,20 @@
if DEBUG:
print("Reading block %04x..." % (block_addr))
- serial.write(cmd)
- response = serial.read(4 + BLOCK_SIZE)
- if response[:4] != expectedresponse:
- raise Exception("Error reading block %04x." % (block_addr))
+ try:
+ serial.write(cmd)
+ response = serial.read(4 + BLOCK_SIZE)
+ if response[:4] != expectedresponse:
+ raise Exception("Error reading block %04x." % (block_addr))
- block_data = response[4:]
+ block_data = response[4:]
- serial.write(CMD_ACK)
- if serial.read(1) != CMD_ACK:
+ serial.write(CMD_ACK)
+ ack = serial.read(1)
+ except:
+ raise errors.RadioError("Failed to read block at %04x" % block_addr)
+
+ if ack != CMD_ACK:
raise Exception("No ACK reading block %04x." % (block_addr))
return block_data
@@ -147,13 +164,15 @@
if DEBUG:
print("Writing Data:")
- debug_print_hex(cmd + data)
- print("")
+ print util.hexprint(cmd + data)
- serial.write(cmd + data)
-
- if serial.read(1) != CMD_ACK:
- raise Exception("No ACK")
+ try:
+ serial.write(cmd + data)
+ if serial.read(1) != CMD_ACK:
+ raise Exception("No ACK")
+ except:
+ raise errors.RadioError("Failed to send block "
+ "to radio at %04x" % block_addr)
def do_download(radio):
print "download"
@@ -175,9 +194,8 @@
data += block
if DEBUG:
- sys.stdout.write("%04x: " % (addr))
- debug_print_hex(block)
- print("")
+ print "Address: %04x" % addr
+ print util.hexprint(block)
_h777_exit_programming_mode(radio)
@@ -210,8 +228,10 @@
@maybe_register
class H777Radio(chirp_common.CloneModeRadio):
"""HST H-777"""
- VENDOR = "Heng Shun Tong (恒顺通)"
- MODEL = "H-777"
+ # VENDOR = "Heng Shun Tong (恒顺通)"
+ # MODEL = "H-777"
+ VENDOR = "Baofeng"
+ MODEL = "BF-888"
BAUD_RATE = 9600
# This code currently requires that ranges start at 0x0000
More information about the chirp_devel
mailing list