Пример #1
0
def get_raw_memory(mmap, number):
    """Return a raw representation of memory @number"""
    offset = get_mem_offset(number)
    if number >= 850:
        size = MEM_LOC_SIZE_B
    else:
        size = MEM_LOC_SIZE_A
    return MemoryMap(mmap[offset:offset + size])
Пример #2
0
class IC92Frame:
    """IC9x frame base class"""
    def get_vfo(self):
        """Return the vfo number"""
        return ord(self._map[0])

    def set_vfo(self, vfo):
        """Set the vfo number"""
        self._map[0] = chr(vfo)

    def from_raw(self, data):
        """Construct the frame from raw data"""
        self._map = MemoryMap(data)

    def from_frame(self, frame):
        """Construct the frame by copying another frame"""
        self._map = MemoryMap(frame.get_raw())

    def __init__(self, subcmd=0, flen=0, cmd=0x1A):
        self._map = MemoryMap("\x00" * (4 + flen))
        self._map[0] = "\x01\x80" + chr(cmd) + chr(subcmd)

    def get_payload(self):
        """Return the entire payload (sans header)"""
        return self._map[4:]

    def get_raw(self):
        """Return the raw version of the frame"""
        return self._map.get_packed()

    def __str__(self):
        string = "Frame VFO=%i (len = %i)\n" % (self.get_vfo(),
                                                len(self.get_payload()))
        string += util.hexprint(self.get_payload())
        string += "\n"

        return string

    def send(self, pipe, verbose=False):
        """Send the frame to the radio via @pipe"""
        if verbose:
            print "Sending:\n%s" % util.hexprint(self.get_raw())

        response = ic9x_send(pipe, self.get_raw())

        if len(response) == 0:
            raise errors.InvalidDataError("No response from radio")

        return response[0]

    def __setitem__(self, start, value):
        self._map[start + 4] = value

    def __getitem__(self, index):
        return self._map[index + 4]

    def __getslice__(self, start, end):
        return self._map[start + 4:end + 4]
Пример #3
0
class IC92Frame:
    """IC9x frame base class"""
    def get_vfo(self):
        """Return the vfo number"""
        return ord(self._map[0])

    def set_vfo(self, vfo):
        """Set the vfo number"""
        self._map[0] = chr(vfo)

    def from_raw(self, data):
        """Construct the frame from raw data"""
        self._map = MemoryMap(data)

    def from_frame(self, frame):
        """Construct the frame by copying another frame"""
        self._map = MemoryMap(frame.get_raw())

    def __init__(self, subcmd=0, flen=0, cmd=0x1A):
        self._map = MemoryMap("\x00" * (4 + flen))
        self._map[0] = "\x01\x80" + chr(cmd) + chr(subcmd)

    def get_payload(self):
        """Return the entire payload (sans header)"""
        return self._map[4:]

    def get_raw(self):
        """Return the raw version of the frame"""
        return self._map.get_packed()

    def __str__(self):
        string = "Frame VFO=%i (len = %i)\n" % (self.get_vfo(),
                                                len(self.get_payload()))
        string += util.hexprint(self.get_payload())
        string += "\n"

        return string

    def send(self, pipe, verbose=False):
        """Send the frame to the radio via @pipe"""
        if verbose:
            print "Sending:\n%s" % util.hexprint(self.get_raw())

        response = ic9x_send(pipe, self.get_raw())

        if len(response) == 0:
            raise errors.InvalidDataError("No response from radio")

        return response[0]

    def __setitem__(self, start, value):
        self._map[start+4] = value

    def __getitem__(self, index):
        return self._map[index+4]

    def __getslice__(self, start, end):
        return self._map[start+4:end+4]
Пример #4
0
 def get_obj(self):
     self._data = MemoryMap(str(self._data))
     return bitwise.parse(mem_duptone_format, self._data)
Пример #5
0
 def get_obj(self):
     self._data = MemoryMap(str(self._data))  # Make sure we're assignable
     return bitwise.parse(self.FORMAT, self._data)
Пример #6
0
 def initialize(self):
     """Initialize to sane values"""
     self._data = MemoryMap("".join(["\x00"] * (self.get_obj().size() / 8)))
Пример #7
0
 def get_obj(self):
     """Return a bitwise parsed object"""
     self._data = MemoryMap(str(self._data))  # Make sure we're assignable
     return bitwise.parse(MEM_FORMAT, self._data)
Пример #8
0
def get_raw_memory(mmap, number):
    offset = get_mem_offset(number)
    return MemoryMap(mmap[offset:offset + MEM_LOC_SIZE])
Пример #9
0
 def get_obj(self):
     self._data = MemoryMap(str(self._data))
     return bitwise.parse(self.FORMAT, self._data)
Пример #10
0
 def from_frame(self, frame):
     """Construct the frame by copying another frame"""
     self._map = MemoryMap(frame.get_raw())
Пример #11
0
 def __init__(self, subcmd=0, flen=0, cmd=0x1A):
     self._map = MemoryMap("\x00" * (4 + flen))
     self._map[0] = "\x01\x80" + chr(cmd) + chr(subcmd)
Пример #12
0
 def from_frame(self, frame):
     """Construct the frame by copying another frame"""
     self._map = MemoryMap(frame.get_raw())
Пример #13
0
 def from_raw(self, data):
     """Construct the frame from raw data"""
     self._map = MemoryMap(data)
Пример #14
0
 def __init__(self, subcmd=0, flen=0, cmd=0x1A):
     self._map = MemoryMap("\x00" * (4 + flen))
     self._map[0] = "\x01\x80" + chr(cmd) + chr(subcmd)
Пример #15
0
      u16 bar;
      u16 baz;
      u8 one;
      u8 upper:2,
         twobit:1,
         onebit:1,
         lower:4;
      u8 array[3];
      char str[3];
      bbcd bcdL[2];
    } foo[2];
    u8 tail;
    """
    data = "\xfe\x10\x00\x08\xFF\x23\x01\x02\x03abc\x34\x89"
    data = (data * 2) + "\x12"
    data = MemoryMap(data)

    ast = bitwise_grammar.parse(test)

    # Just for testing, pretty-print the tree
    pp(ast)

    # Mess with it a little
    p = Processor(data, 0)
    obj = p.parse(ast)
    print "Object: %s" % obj
    print obj["foo"][0]["bcdL"]
    print obj["tail"]
    print obj["foo"][0]["bar"]
    obj["foo"][0]["bar"].set_value(255 << 8)
    obj["foo"][0]["twobit"].set_value(0)
Пример #16
0
      u16 bar;
      u16 baz;
      u8 one;
      u8 upper:2,
         twobit:1,
         onebit:1,
         lower:4;
      u8 array[3];
      char str[3];
      bbcd bcdL[2];
    } foo[2];
    u8 tail;
    """
    data = "\xfe\x10\x00\x08\xFF\x23\x01\x02\x03abc\x34\x89"
    data = (data * 2) + "\x12"
    data = MemoryMap(data)

    ast = bitwise_grammar.parse(test)

    # Just for testing, pretty-print the tree
    pp(ast)

    # Mess with it a little
    p = Processor(data, 0)
    obj = p.parse(ast)
    print "Object: %s" % obj
    print obj["foo"][0]["bcdL"]
    print obj["tail"]
    print obj["foo"][0]["bar"]
    obj["foo"][0]["bar"].set_value(255 << 8)
    obj["foo"][0]["twobit"].set_value(0)
Пример #17
0
 def from_raw(self, data):
     """Construct the frame from raw data"""
     self._map = MemoryMap(data)