# HG changeset patch # User Mathieu Rozon # Date 1425778153 18000 # Sat Mar 07 20:29:13 2015 -0500 # Node ID cfdd6f6577f1c8d420376c35bb684a9552042179 # Parent d84dfd6c29d61268de11584f5d427e60936131d9 Fix downloading/uploading issue for UV-5R. Fixes #2317 diff -r d84dfd6c29d6 -r cfdd6f6577f1 chirp/drivers/uv5r.py --- a/chirp/drivers/uv5r.py Tue Mar 03 22:25:38 2015 -0800 +++ b/chirp/drivers/uv5r.py Sat Mar 07 20:29:13 2015 -0500 @@ -438,17 +438,22 @@ ack = serial.read(1) if ack != "\x06": raise errors.RadioError("Radio refused clone") - + return ident -def _read_block(radio, start, size): +def _read_block(radio, start, size, firstCommand): msg = struct.pack(">BHB", ord("S"), start, size) radio.pipe.write(msg) + if(firstCommand == False): + ack = radio.pipe.read(1) + if ack != "\x06": + raise errors.RadioError("Radio refused to send second block 0x%04x" % start) + answer = radio.pipe.read(4) if len(answer) != 4: - raise errors.RadioError("Radio refused to send block 0x%04x" % start) + raise errors.RadioError("Radio refused to send first block 0x%04x" % start) cmd, addr, length = struct.unpack(">BHB", answer) if cmd != ord("X") or addr != start or length != size: @@ -464,28 +469,25 @@ raise errors.RadioError("Radio sent incomplete block 0x%04x" % start) radio.pipe.write("\x06") - - ack = radio.pipe.read(1) - if ack != "\x06": - raise errors.RadioError("Radio refused to send block 0x%04x" % start) + time.sleep(0.005) return chunk def _get_radio_firmware_version(radio): if radio.MODEL == "BJ-UV55": - block = _read_block(radio, 0x1FF0, 0x40) + block = _read_block(radio, 0x1FF0, 0x40, True) version = block[0:6] else: - block1 = _read_block(radio, 0x1EC0, 0x40) - block2 = _read_block(radio, 0x1F00, 0x40) + block1 = _read_block(radio, 0x1EC0, 0x40, True) + block2 = _read_block(radio, 0x1F00, 0x40, False) block = block1 + block2 version = block[48:62] return version def _get_radio_special_block(radio): - block = _read_block(radio, 0xCF0, 0x40) + block = _read_block(radio, 0xCF0, 0x40, False) special_block = block[2:9] return special_block @@ -517,13 +519,13 @@ # Main block LOG.debug("downloading main block...") for i in range(0, 0x1800, 0x40): - data += _read_block(radio, i, 0x40) + data += _read_block(radio, i, 0x40, False) _do_status(radio, i) LOG.debug("done.") LOG.debug("downloading aux block...") # Auxiliary block starts at 0x1ECO (?) for i in range(0x1EC0, 0x2000, 0x40): - data += _read_block(radio, i, 0x40) + data += _read_block(radio, i, 0x40, False) LOG.debug("done.") return memmap.MemoryMap(data)