Beispiel #1
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]
Beispiel #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]
Beispiel #3
0
    # 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)
    obj["foo"][0]["onebit"].set_value(1)
    print "%i" % int(obj["foo"][0]["bar"])

    for i in obj["foo"][0]["array"]:
        print int(i)
    obj["foo"][0]["array"][1].set_value(255)

    for i in obj["foo"][0]["bcdL"]:
        print i.get_value()

    int_to_bcd(obj["foo"][0]["bcdL"], 1234)
    print bcd_to_int(obj["foo"][0]["bcdL"])

    set_string(obj["foo"][0]["str"], "xyz")
    print get_string(obj["foo"][0]["str"])

    print repr(data.get_packed())
Beispiel #4
0
    # 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)
    obj["foo"][0]["onebit"].set_value(1)
    print "%i" % int(obj["foo"][0]["bar"])

    for i in obj["foo"][0]["array"]:
        print int(i)
    obj["foo"][0]["array"][1].set_value(255)

    for i in obj["foo"][0]["bcdL"]:
        print i.get_value()

    int_to_bcd(obj["foo"][0]["bcdL"], 1234)
    print bcd_to_int(obj["foo"][0]["bcdL"])

    set_string(obj["foo"][0]["str"], "xyz")
    print get_string(obj["foo"][0]["str"])

    print repr(data.get_packed())