示例#1
0
文件: __init__.py 项目: ruairif/ahrs
 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
示例#2
0
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
示例#3
0
def not_op(x):
    return uint16(~parse(x)).value
示例#4
0
def rshift_op(x, y):
    return uint16(parse(x) >> parse(y)).value
示例#5
0
def lshift_op(x, y):
    return uint16(parse(x) << parse(y)).value
示例#6
0
def or_op(x, y):
    return uint16(parse(x) | parse(y)).value
示例#7
0
def and_op(x, y):
    return uint16(parse(x) & parse(y)).value