def calc_CRC(self, data_packet): crc = 0x1D0F for byte_c in data_packet: crc ^= uint16(ord(byte_c) << 8).value for _ in range(8): if crc & 0x8000: crc = uint16((crc << 1) ^ 0x1021).value else: crc = uint16(crc << 1).value return crc
def parse(token): if is_signal(token): return uint16(int(token)).value elif is_wire(token): loop_check(token) if token not in computed: computed[token] = parse(sym_tab[token]) loop_clear(token) return computed[token] else: m = re.match(not_re, token) if m is not None: return not_op(m.groupdict()['val']) else: for x in two_arg_ops: m = re.match(x['re'], token) if m is not None: return x['op'](m.groupdict()['lhs'], m.groupdict()['rhs']) print "parse error token %s" % token return None
def not_op(x): return uint16(~parse(x)).value
def rshift_op(x, y): return uint16(parse(x) >> parse(y)).value
def lshift_op(x, y): return uint16(parse(x) << parse(y)).value
def or_op(x, y): return uint16(parse(x) | parse(y)).value
def and_op(x, y): return uint16(parse(x) & parse(y)).value