コード例 #1
0
ファイル: ts480.py プロジェクト: jz09bed/chirp.hg
    def sync_in(self):
        """Download from radio"""
        try:
            _connect_radio(self)
            data = _read_mem(self)
            data += _read_settings(self)
        except errors.RadioError:
            # Pass through any real errors we raise
            raise
        except Exception:
            # If anything unexpected happens, make sure we raise
            # a RadioError and log the problem
            LOG.exception('Unexpected error during download')
            raise errors.RadioError('Unexpected error communicating '
                                    'with the radio')

        self._mmap = memmap.MemoryMap(data)
        self.process_mmap()
        return
コード例 #2
0
    def _download(self, limit):
        self._identify()

        data = ""
        for addr in range(0, limit, 16):
            data += self._download_chunk(addr)
            time.sleep(0.1)

            if self.status_fn:
                status = chirp_common.Status()
                status.cur = addr + 16
                status.max = self._memsize
                status.msg = "Downloading from radio"
                self.status_fn(status)

        self._send("AL~E\r\n")
        self._read(20)

        return memmap.MemoryMap(data)
コード例 #3
0
 def _do_download(self, start, end, blocksize):
     # allocate & fill memory
     image = ""
     for i in range(start, end, blocksize):
         req = chr(i / 256) + chr(i % 256) + chr(blocksize)
         self._write_record(CMD_RD, req)
         cs_error, resp = self._read_record()
         if cs_error:
             LOG.debug(util.hexprint(resp))
             raise Exception("Checksum error on read")
         LOG.debug("Got:\n%s" % util.hexprint(resp))
         image += resp[2:]
         if self.status_fn:
             status = chirp_common.Status()
             status.cur = i
             status.max = end
             status.msg = "Cloning from radio"
             self.status_fn(status)
     self._finish()
     return memmap.MemoryMap(''.join(image))
コード例 #4
0
ファイル: th9000.py プロジェクト: erikj180/py3-CHIRP
def do_download(radio):

    _ident(radio)

    _memobj = None
    data = ""

    for start,end in radio._ranges: 
        for addr in range(start,end,0x10):
            block = _send(radio,'R',addr,0x10) 
            data += block
            status = chirp_common.Status()
            status.cur = len(data)
            status.max = end
            status.msg = "Downloading from radio"
            radio.status_fn(status)

    _finish(radio)

    return memmap.MemoryMap(data)
コード例 #5
0
ファイル: ft4.py プロジェクト: uhliarik/chirp
def do_download(radio):
    """
    Read memory from the radio.
      call startcomms to go into program mode and check version
      create an mmap
      read the memory blocks and place the data into the mmap
      send "END"
    """
    image = bytearray(radio.get_memsize())
    pipe = radio.pipe  # Get the serial port connection
    progressbar = startcomms(radio, "from")
    for blocknum in range(radio.numblocks):
        for i in range(0, 3):
            if getblock(pipe, 16 * blocknum, image):
                break
            if i == 2:
                raise errors.RadioError("read block from radio failed 3 times")
        progressbar.cur = blocknum
        radio.status_fn(progressbar)
    sendcmd(pipe, b"END", 0)
    return memmap.MemoryMap(bytes(image))
コード例 #6
0
def do_download(radio):
    """ The download function """
    SHX8800_prep(radio)

    # UI progress
    status = chirp_common.Status()
    status.cur = 0
    status.max = MEM_SIZE
    status.msg = "Cloning from radio..."
    radio.status_fn(status)
    data = ""

    for addr in range(0x0000, MEM_SIZE, BLOCK_SIZE_RX):
        data += _recv_block(radio, addr, BLOCK_SIZE_RX)
        # UI Update
        status.cur = addr
        radio.status_fn(status)

    SHX8800_exit(radio)

    return memmap.MemoryMap(data)
コード例 #7
0
ファイル: ft90.py プロジェクト: aircycler1/chirp
    def _clone_in(self):
        # Be very patient with the radio
        self.pipe.setTimeout(4)
        start = time.time()

        data = ""
        blocknum = 0
        status = chirp_common.Status()
        status.msg = "Cloning..."
        self.status_fn(status)
        status.max = len(self._block_lengths)
        for blocksize in self._block_lengths:
            data += self._read(blocksize, blocknum)
            blocknum += 1
            status.cur = blocknum
            self.status_fn(status)

        print "Clone completed in %i seconds, blocks read: %i" % (
            time.time() - start, blocknum)

        return memmap.MemoryMap(data)
コード例 #8
0
def do_download(radio):
    do_ident(radio)

    data = ""
    data += "\xFF" * (0 - len(data))
    for addr in range(0, radio._memsize, 0x10):
        send(radio, make_frame("R", addr, chr(0x10)))
        _addr, _data = recv(radio)
        if _addr != addr:
            raise errors.RadioError("Radio sent unexpected address")
        data += _data

        status = chirp_common.Status()
        status.cur = addr
        status.max = radio._memsize
        status.msg = "Cloning from radio"
        radio.status_fn(status)

    finish(radio)

    return memmap.MemoryMap(data)
コード例 #9
0
ファイル: ft817.py プロジェクト: aircycler1/chirp
 def _clone_in(self):
     # Be very patient with the radio
     self.pipe.setTimeout(2)
 
     start = time.time()
 
     data = ""
     blocks = 0
     status = chirp_common.Status()
     status.msg = _("Cloning from radio")
     nblocks = len(self._block_lengths) + 39
     status.max = nblocks
     for block in self._block_lengths:
         if blocks == 8:
             # repeated read of 40 block same size (memory area)
             repeat = 40
         else:
             repeat = 1
         for _i in range(0, repeat):	
             data += self._read(block, blocks, blocks == nblocks-1)
             self.pipe.write(chr(CMD_ACK))
             blocks += 1
             status.cur = blocks
             self.status_fn(status)
             
     if not self._US_model:
         status.msg = _("Clone completed, checking for spurious bytes")
         self.status_fn(status)
         moredata = self.pipe.read(2)
         if moredata:
             raise Exception(_("Radio sent data after the last awaited block, "
                         "this happens when the selected model is a non-US "
                         "but the radio is a US one. "
                         "Please choose the correct model and try again."))
         
 
     print "Clone completed in %i seconds" % (time.time() - start)
 
     return memmap.MemoryMap(data)
コード例 #10
0
ファイル: thd72.py プロジェクト: erikj180/py3-CHIRP
    def download(self, raw=False, blocks=None):
        if blocks is None:
            blocks = range(self._memsize / 256)
        else:
            blocks = [b for b in blocks if b < self._memsize / 256]

        if self.command("0M PROGRAM") != "0M":
            raise errors.RadioError("No response from self")

        allblocks = range(self._memsize / 256)
        self.pipe.baudrate = 57600
        try:
            self.pipe.setRTS()
        except AttributeError:
            self.pipe.rts = True
        self.pipe.read(1)
        data = ""
        LOG.debug("reading blocks %d..%d" % (blocks[0], blocks[-1]))
        total = len(blocks)
        count = 0
        for i in allblocks:
            if i not in blocks:
                data += 256 * '\xff'
                continue
            data += self.read_block(i)
            count += 1
            if self.status_fn:
                s = chirp_common.Status()
                s.msg = "Cloning from radio"
                s.max = total
                s.cur = count
                self.status_fn(s)

        self.pipe.write("E")

        if raw:
            return data
        return memmap.MemoryMap(data)
コード例 #11
0
ファイル: rh5r_v2.py プロジェクト: RAScheepmaker/radio
def _download(radio):
    _identify(radio)
    data = []
    for i in range(0, 0x2000, 0x40):
        msg = struct.pack('>cHb', 'R', i, 0x40)
        radio.pipe.write(msg)
        block = radio.pipe.read(0x40 + 4)
        if len(block) != (0x40 + 4):
            raise errors.RadioError("Radio sent a short block (%02x/%02x)" % (
                len(block), 0x44))
        data += block[4:]

        if radio.status_fn:
            status = chirp_common.Status()
            status.cur = i
            status.max = 0x2000
            status.msg = "Cloning from radio"
            radio.status_fn(status)

    radio.pipe.write("E")
    data += 'PGM2015'

    return memmap.MemoryMap(data)
コード例 #12
0
def do_download(radio):
    LOG.debug("download")
    _nc630a_enter_programming_mode(radio)

    data = ""

    status = chirp_common.Status()
    status.msg = "Cloning from radio"

    status.cur = 0
    status.max = radio._memsize

    for addr in range(0, radio._memsize, radio._block_size):
        status.cur = addr + radio._block_size
        radio.status_fn(status)

        block = _nc630a_read_block(radio, addr, radio._block_size)
        data += block

        LOG.debug("Address: %04x" % addr)
        LOG.debug(util.hexprint(block))

    return memmap.MemoryMap(data)
コード例 #13
0
def tyt_uvf8d_download(radio):
    data = uvf8d_identify(radio)
    for i in range(0, 0x4000, 0x20):
        msg = struct.pack(">cHb", "R", i, 0x20)
        radio.pipe.write(msg)
        block = radio.pipe.read(0x20 + 4)
        if len(block) != (0x20 + 4):
            raise errors.RadioError("Radio sent a short block")
        radio.pipe.write("A")
        ack = radio.pipe.read(1)
        if ack != "A":
            raise errors.RadioError("Radio NAKed block")
        data += block[4:]

        if radio.status_fn:
            status = chirp_common.Status()
            status.cur = i
            status.max = 0x4000
            status.msg = "Cloning from radio"
            radio.status_fn(status)

    radio.pipe.write("ENDR")

    return memmap.MemoryMap(data)
コード例 #14
0
def __clone_in(radio):
    pipe = radio.pipe

    start = time.time()

    data = ""
    blocks = 0
    for block in radio._block_lengths:
        blocks += 1
        if blocks == len(radio._block_lengths):
            chunk = _chunk_read(pipe, block, radio.status_fn)
        else:
            chunk = _safe_read(pipe, block)
            pipe.write(chr(CMD_ACK))
        if not chunk:
            raise errors.RadioError("No response from radio")
        data += chunk

    if len(data) != radio.get_memsize():
        raise errors.RadioError("Received incomplete image from radio")

    print "Clone completed in %i seconds" % (time.time() - start)

    return memmap.MemoryMap(data)
コード例 #15
0
 def get_mmap(self):
     _data = flip_high_order_bit(self._mmap.get_packed())
     return memmap.MemoryMap(_data)
コード例 #16
0
 def test_string_invalid_chars(self):
     data = memmap.MemoryMap("\xFFoobar1")
     obj = bitwise.parse("struct {char foo[7];} bar;", data)
     self.assertIn('\\xffoobar1', repr(obj.bar))
コード例 #17
0
 def test_string_wrong_length(self):
     data = memmap.MemoryMap("foobar")
     obj = bitwise.parse("char foo[6];", data)
     self.assertRaises(ValueError, setattr, obj, "foo", "bazfo")
     self.assertRaises(ValueError, setattr, obj, "foo", "bazfooo")
コード例 #18
0
ファイル: run_tests.py プロジェクト: potsmaster/chirp
        try:
            radio.sync_in()
        except Exception, e:
            error = e

        if error is None:
            raise TestFailedError(
                "Radio did not raise exception " + "with %s data" % serial,
                "On sync_in()")
        elif not isinstance(error, errors.RadioError):
            raise TestFailedError(
                "Radio did not raise RadioError " + "with %s data" % serial,
                "sync_in() Got: %s (%s)\n%s" %
                (error.__class__.__name__, error, get_tb()))

        radio._mmap = memmap.MemoryMap("\x00" * (1024 * 128))

        error = None
        try:
            radio.sync_out()
        except Exception, e:
            error = e

        if error is None:
            raise TestFailedError(
                "Radio did not raise exception " + "with %s data" % serial,
                "On sync_out()")
        elif not isinstance(error, errors.RadioError):
            raise TestFailedError(
                "Radio did not raise RadioError " + "with %s data" % serial,
                "sync_out(): Got: %s (%s)" % (error.__class__.__name__, error))
コード例 #19
0
ファイル: ft50_ll.py プロジェクト: aircycler1/chirp
def get_raw_memory(map, number):
    pos = get_mem_offset(number)
    return memmap.MemoryMap(map[pos:pos + MEM_LOC_SIZE])
コード例 #20
0
ファイル: ft2900.py プロジェクト: SDoradus/py3-CHIRP
def _download(radio):

    blankChunk = ""
    for _i in range(0, 32):
        blankChunk += "\xff"

    LOG.debug("in _download\n")

    data = ""
    for _i in range(0, 20):
        data = radio.pipe.read(20)
        LOG.debug("Header:\n%s" % util.hexprint(data))
        LOG.debug("len(header) = %s\n" % len(data))

        if data == radio.IDBLOCK:
            break

    if data != radio.IDBLOCK:
        raise Exception("Failed to read header")

    _send(radio.pipe, ACK)

    # initialize data, the big var that holds all memory
    data = ""

    _blockNum = 0

    while len(data) < radio._block_sizes[1]:
        _blockNum += 1
        time.sleep(0.03)
        chunk = radio.pipe.read(32)
        LOG.debug("Block %i " % (_blockNum))
        if chunk == blankChunk:
            LOG.debug("blank chunk\n")
        else:
            LOG.debug("Got: %i:\n%s" % (len(chunk), util.hexprint(chunk)))
        if len(chunk) != 32:
            LOG.debug("len chunk is %i\n" % (len(chunk)))
            raise Exception("Failed to get full data block")
            break
        else:
            data += chunk

        if radio.status_fn:
            status = chirp_common.Status()
            status.max = radio._block_sizes[1]
            status.cur = len(data)
            status.msg = "Cloning from radio"
            radio.status_fn(status)

    LOG.debug("Total: %i" % len(data))

    # radio should send us one final termination byte, containing
    # checksum
    chunk = radio.pipe.read(32)
    if len(chunk) != 1:
        LOG.debug("len(chunk) is %i\n" % len(chunk))
        raise Exception("radio sent extra unknown data")
    LOG.debug("Got: %i:\n%s" % (len(chunk), util.hexprint(chunk)))

    # compute checksum
    cs = INITIAL_CHECKSUM
    for byte in radio.IDBLOCK:
        cs += ord(byte)
    for byte in data:
        cs += ord(byte)
    LOG.debug("calculated checksum is %x\n" % (cs & 0xff))
    LOG.debug("Radio sent checksum is %x\n" % ord(chunk[0]))

    if (cs & 0xff) != ord(chunk[0]):
        raise Exception("Failed checksum on read.")

    # for debugging purposes, dump the channels, in hex.
    for _i in range(0, 200):
        _startData = 1892 + 20 * _i
        chunk = data[_startData:_startData + 20]
        LOG.debug("channel %i:\n%s" % (_i, util.hexprint(chunk)))

    return memmap.MemoryMap(data)
コード例 #21
0
ファイル: run_tests.py プロジェクト: atpage/chirp
    def _run(self, serial):
        error = None
        live = isinstance(self._wrapper._dst, chirp_common.LiveRadio)
        clone = isinstance(self._wrapper._dst, chirp_common.CloneModeRadio)

        if not clone and not live:
            raise TestSkippedError('Does not support clone')

        try:
            radio = self._wrapper._dst.__class__(serial)
            radio.status_fn = lambda s: True
        except Exception as e:
            error = e

        if not live:
            if error is not None:
                raise TestFailedError("Clone radio tried to read from " +
                                      "serial on init")
        else:
            if not isinstance(error, errors.RadioError):
                raise TestFailedError("Live radio didn't notice serial " +
                                      "was dead on init")
            return []  # Nothing more to test on an error'd live radio

        error = None
        try:
            radio.sync_in()
        except Exception as e:
            error = e

        if error is None:
            raise TestFailedError("Radio did not raise exception " +
                                  "with %s data" % serial,
                                  "On sync_in()")
        elif not isinstance(error, errors.RadioError):
            raise TestFailedError("Radio did not raise RadioError " +
                                  "with %s data" % serial,
                                  "sync_in() Got: %s (%s)\n%s" %
                                  (error.__class__.__name__,
                                   error, get_tb()))

        if radio.NEEDS_COMPAT_SERIAL:
            radio._mmap = memmap.MemoryMap("\x00" * (1024 * 128))
        else:
            radio._mmap = memmap.MemoryMapBytes(bytes(b"\x00") * (1024 * 128))

        error = None
        try:
            radio.sync_out()
        except Exception as e:
            error = e

        if error is None:
            raise TestFailedError("Radio did not raise exception " +
                                  "with %s data" % serial,
                                  "On sync_out()")
        elif not isinstance(error, errors.RadioError):
            raise TestFailedError("Radio did not raise RadioError " +
                                  "with %s data" % serial,
                                  "sync_out(): Got: %s (%s)" %
                                  (error.__class__.__name__, error))

        if serial.mismatch:
            raise TestFailedError("Radio tried to write the wrong "
                                  "type of data to the %s pipe." % (
                                      serial.__class__.__name__),
                                  "TestClone:%s\n%s" % (
                                      serial.__class__.__name__,
                                      serial.mismatch_at))

        return []
コード例 #22
0
 def sync_in(self):
     """Download from radio"""
     data = _download(self)
     self._mmap = memmap.MemoryMap(data)
     self.process_mmap()
コード例 #23
0
 def test_with_MemoryMap(self):
     mmap = memmap.MemoryMap('...\x2A')
     self._test_checksum(mmap)
コード例 #24
0
ファイル: h777.py プロジェクト: stephengroat/chirp
 def setUp(self):
     self.driver = H777Radio(None)
     self.testdata = bitwise.parse("lbcd foo[2];",
                                   memmap.MemoryMap("\x00\x00"))
コード例 #25
0
 def sync_in(self):
     # The radio returns all the bytes with the high-order bit flipped.
     _mmap = clone_from_radio(self)
     _mmap = flip_high_order_bit(_mmap.get_packed())
     self._mmap = memmap.MemoryMap(_mmap)
     self.process_mmap()
コード例 #26
0
ファイル: chirp_common.py プロジェクト: Aerostation/chirp.hg
 def load_mmap(self, filename):
     """Load the radio's memory map from @filename"""
     mapfile = file(filename, "rb")
     self._mmap = memmap.MemoryMap(mapfile.read())
     mapfile.close()
     self.process_mmap()