Ejemplo n.º 1
0
def decode_0x0100(bytes):
    body_index = get_message_body_index(bytes)
    body_length = get_message_body_length(bytes)
    province_id = Covert.bytes_2_number(bytes, body_index + 0, 2)
    city_id = Covert.bytes_2_number(bytes, body_index + 2, 2)

    province_id_str = str(province_id)
    format_province_id_str = ''.join(['0' for i in range(2 - len(province_id_str))]) + province_id_str
    city_id_str = str(city_id)
    format_city_id_str = ''.join(['0' for i in range(4 - len(city_id_str))]) + city_id_str

    division = gb2260.get(int(format_province_id_str + format_city_id_str))
    print('code', int(format_province_id_str + format_city_id_str))
    print('division.province', type(division.province), division.province, division.province.__str__())
    print('division.name', type(division.name))
    return {**decode_header(bytes), **{
        '含义': '终端注册',
        '消息体': Covert.bytes_2_hex_string(bytes, body_index + 0, body_length),
        '省域ID': '{0}[{1}]'.format(format_province_id_str, division.province.__str__()),
        '市县域ID': city_id_str + '[' + division.name + ']',
        '制造商ID': Covert.bytes_2_hex_string(bytes, body_index + 4, 5),
        '终端型号': Covert.bytes_2_hex_string(bytes, body_index + 9, 8),
        '终端ID': Covert.bytes_2_hex_string(bytes, body_index + 17, 7),
        '车牌颜色': Covert.bytes_2_hex_string(bytes, body_index + 24, 1) + '[' + str(LicensePateColor(Covert.bytes_2_number(bytes, body_index + 24, 1))) + ']',
        '车牌': Covert.bytes_2_hex_string(bytes, body_index + 25, body_length - 25) + '[' + bytes.fromhex(Covert.bytes_2_hex_string(bytes, body_index + 25, body_length - 25)).decode('GBK') + ']',
    }}
Ejemplo n.º 2
0
def decode_0x8001(bytes):
    body_index = get_message_body_index(bytes)
    body_length = get_message_body_length(bytes)
    return {**decode_header(bytes), **{
        '含义': '平台通用应答',
        '消息体': Covert.bytes_2_hex_string(bytes, body_index, body_length),
        '应答流水号': Covert.bytes_2_number(bytes, body_index + 0, 2),
        '应答ID': Covert.bytes_2_number(bytes, body_index + 2, 2),
        '结果': Covert.bytes_2_number(bytes, body_index + 4, 1),
    }}
Ejemplo n.º 3
0
 def decode(*args):
     if args[0] == 'number':
         return '{0}:{1}{2}'.format(args[2], Covert.bytes_2_number(bytes, 0, len(bytes)), args[3])
     elif args[0] == 'hex':
         return '{0}:{1}'.format(args[2], Covert.bytes_2_hex_string(bytes, 0, len(bytes)))
     elif args[0] == 'gbk':
         return '{0}:{1}'.format(args[2], bytes.fromhex(Covert.bytes_2_hex_string(bytes, 0, len(bytes))).decode('GBK'))
     elif args[0] == 'license_pate_color':
         return '{0}:{1}'.format(args[2], str(LicensePateColor(Covert.bytes_2_number(bytes, 0, len(bytes)))).split('.')[1])
     else:
         return 'type[{0}]传递错误,请检查'.format(type)
Ejemplo n.º 4
0
def decode_0x8103(bytes):
    body_index = get_message_body_index(bytes)
    body_length = get_message_body_length(bytes)
    return {**decode_header(bytes), **{
    # return {**{
        '含义': '设置终端参数',
        '消息体': Covert.bytes_2_hex_string(bytes, body_index, body_length),
        '参数总数': Covert.bytes_2_number(bytes, body_index + 0, 1),
    }, **decode_0x8103_params(bytes, body_index + 1, body_length - 1)}
Ejemplo n.º 5
0
def decode_0x8103_params(bytes, src_pos, length):
    params = {}

    count = 0
    index = src_pos
    while index < src_pos + length:
        count += 1
        id = Covert.bytes_2_hex_string(bytes, index, 4)
        step = Covert.bytes_2_number(bytes, index + 4, 1)
        params['序号:{0} 参数ID:{1} 参数长度:{2}'.format(count, id, step)] = decode_8103_param(id, bytes[index + 5: index + 5 + step])

        if step == 0:
            index += 4
        else:
            index += int(step + 5)

    return {**{
        '参数列表': Covert.bytes_2_hex_string(bytes, src_pos, length),
    }, **params}
Ejemplo n.º 6
0
def read_bit(bytes, index, offset):
    mask = 1 << offset
    return (Covert.bytes_2_number(bytes, index, 1) & mask) >> offset