def resolution(self): """ step1: Decode the binary data to a tuple step2: Split each element by the JTT808 protocol step3: Recognize the message id ,and then checking Dicts! something like {'(1,0)':'ter_reg_req'} :return: None """ self.request_data = tongue.Decode(self.request) self.client_tuple_data = self.request_data.dst # Don't forget get dst attribute if self.client_tuple_data[3] == 254: self.client_tuple_data = tuple(self.client_tuple_data) self.split_instance = MainSplit(self.client_tuple_data) self.request_dict = self.split_instance.result #Error request special processing if self.split_instance.flag: self.request_dict['client_msg_id'] = (9, ) if self.split_instance.debug: self.request_dict['GET'] = self.conn self.msg_key = str(self.request_dict['client_msg_id']) else: warning('No Split instance !') self.PUB = False else: warning('Not a command package') self.PUB = False
def resolution(self): """ step1: Decode the binary data to a tuple step2: Split each element by the JTT808 protocol step3: Recognize the message id ,and then checking Dicts! something like {'(1,0)':'ter_reg_req'} :return: None """ self.request_data = tongue.Decode(self.request) self.client_tuple_data = self.request_data.dst # Don't forget get dst attribute self.client_tuple_data = tuple(self.client_tuple_data) self.split_instance = MainSplit(self.client_tuple_data) self.request_dict = self.split_instance.result self.request_dict[ 'client_check_code_msg'] = self.client_tuple_data[:-7] print self.client_tuple_data print self.request_dict #pi time time_pi = time.time() time_pi2 = time.localtime(time_pi) time_pi3 = time.strftime('%Y%m%d%H%M%S', time_pi2)[2:] self.request_dict['time_pi'] = (time_pi, ) #Error request special processing if self.split_instance.debug: self.request_dict['GET'] = self.conn str_msg_key = '' for item in self.request_dict['client_msg_id']: str_msg_key = str_msg_key + str(item) self.msg_key = str(self.request_dict['client_main_com']) else: warning('No Split instance !') self.PUB = False
def __init__(self): self.client = socket(AF_INET, SOCK_STREAM) self.client.connect(self.ADDR) # 查询时间 '7E 00 04 40 00 01 00 00 00 00 01 55 55 55 55 55 00 24 35 7E' # 模拟器返回 [RECV] 7E 80 01 00 05 01 00 00 00 00 01 36 81 00 10 01 00 00 FF FF 01 02 00 21 7E # 服务器端log 通过模拟器=脚本 = 8001000501000000000136810010010000ffff01020021 # 代码返回 7E 80 01 00 05 01 00 00 00 00 01 36 81 00 10 01 00 00 FF FF 01 02 00 21 7E self.register_data = '2323010034364637415334473136354634395344380100e6150a1010022100013839383630303233303330393730303033373236140a484a4b4c41534446485541494c48465549414f46484a4b4c41534446485541494c48465549414f46484a4b4c41534446485541494c48465549414f46484a4b4c41534446485541494c48465549414f46484a4b4c41534446485541494c48465549414f46484a4b4c41534446485541494c48465549414f46484a4b4c41534446485541494c48465549414f46484a4b4c41534446485541494c48465549414f46484a4b4c41534446485541494c48465549414f46484a4b4c41534446485541494c48465549414f4682' self.packed_data = binascii.unhexlify(self.register_data) print('\n packed_data: ') print(type(self.packed_data)) print(self.packed_data) self.client.send(self.packed_data) recv_data = self.client.recv(self.BUFSIZ) print('\n recv_data: ') print(recv_data) recv_decoded_data = tongue.Decode(recv_data) print('\n tongue decoded: ') print(recv_decoded_data.dst) #recv_decoded_data.dst : 十六进制用十进制表示 (126, 128, 1, 0, 5, 1, 0, 0, 0, 0, 1, 54, 129, 0, 16, 1, 0, 0, 255, 255, 1, 2, 0, 33, 126) l = [hex(i) for i in recv_decoded_data.dst] # 还原十六进制 r = [] for i in l: if len(i) == 3: r.append(i.replace('x', '').upper()) if len(i) == 4: r.append(i.replace('0x', '').upper()) result = ' '.join(r) print(result)
def __init__(self): self.client = socket(AF_INET, SOCK_STREAM) self.client.connect(self.ADDR) # 查询时间 '7E 00 04 40 00 01 00 00 00 00 01 55 55 55 55 55 00 24 35 7E' # 模拟器返回 [RECV] 7E 80 01 00 05 01 00 00 00 00 01 36 81 00 10 01 00 00 FF FF 01 02 00 21 7E # 服务器端log 通过模拟器=脚本 = 8001000501000000000136810010010000ffff01020021 # 代码返回 7E 80 01 00 05 01 00 00 00 00 01 36 81 00 10 01 00 00 FF FF 01 02 00 21 7E self.register_data = '7E010240910100000000013681001001ffff6d2052324b617a39704c4e4b566b77736d6b57306278585958692b664d51386351766b4f507533772f6d71736b576e3479764a6b516c764f4a7864704e4432566d65487a57697152414d546a59667a70666651464c4c6458686a7773576b7542464b656964424b666934704b553d3132333435363738393031323334350000000000000000000000000000332e372e3135657E' self.packed_data = binascii.unhexlify(self.register_data) print('\n packed_data: ') print(type(self.packed_data)) print(self.packed_data) self.client.send(self.packed_data) recv_data = self.client.recv(self.BUFSIZ) print('\n recv_data: ') print(recv_data) recv_decoded_data = tongue.Decode(recv_data) print('\n tongue decoded: ') print(recv_decoded_data.dst) #recv_decoded_data.dst : 十六进制用十进制表示 (126, 128, 1, 0, 5, 1, 0, 0, 0, 0, 1, 54, 129, 0, 16, 1, 0, 0, 255, 255, 1, 2, 0, 33, 126) l = [hex(i) for i in recv_decoded_data.dst] # 还原十六进制 r = [] for i in l: if len(i) == 3: r.append(i.replace('x','').upper()) if len(i) == 4: r.append(i.replace('0x','').upper()) result = ' '.join(r) print(result)
def resolution(self): """ step1: Decode the binary data to a tuple step2: Split each element by the JTT808 protocol step3: Recognize the message id ,and then checking Dicts! something like {'(1,0)':'ter_reg_req'} :return: None """ # 把数据转为10进制的元组 self.request_data = tongue.Decode(self.request) self.client_tuple_data = self.request_data.dst # 判断数据判断第4字节,或者第2字节是否符合协议 if self.client_tuple_data[3] == 254 or self.client_tuple_data[3] == 1: # 把接收到的数据转化的元组,根据协议分成一个带有多个数据块的字典 self.client_tuple_data = tuple(self.client_tuple_data) self.split_instance = MainSplit(self.client_tuple_data) self.request_dict = self.split_instance.result # 如果数据无效,就把消息的id变成09返回 if self.split_instance.flag: self.request_dict['client_msg_id'] = (9, ) # 把链接加入到数据块字典中, 后续使用这个链接对象,应答数据 if self.split_instance.debug: self.request_dict['GET'] = self.conn self.msg_key = str(self.request_dict['client_msg_id']) else: warning('No Split instance !') self.PUB = False else: warning('Not a command package') self.PUB = False
def __init__(self): self.client = socket(AF_INET, SOCK_STREAM) self.client.connect(self.ADDR) self.register_data = '7E0100002501860175250400020000000037' \ '303231385957333030302D42440000000000' \ '000000000000304A544931514B00A27E' self.packed_data = binascii.unhexlify(self.register_data) while True: self.client.send(self.packed_data) data = self.client.recv(self.BUFSIZ) if not data: break recv_data = tongue.Decode(data) print recv_data.dst
def _receive_and_decode(self): try: # return '23 23 01 00 34 36 46 37 41 53 34 47 31 36 35 46 34 39 53 44 38 01 00 06 15 0A 10 10 02 21 7E' recv_raw = self.soket_client.recv(self.BUFSIZ) recv_decoded_data = tongue.Decode(recv_raw) #recv_decoded_data.dst : 十六进制用十进制元组表示 (35, 35, 1, 0, 52, 54, 70, 55, 65, 83, 52, 71, 49, 54, 53, 70, 52, 57, 83, 68, 56, 1, 0, 6, 21, 10, 16, 16, 2, 33, 126) l = [hex(i) for i in recv_decoded_data.dst] # 还原十六进制 r = [] for i in l: if len(i) == 3: r.append(i.replace('x','').upper()) if len(i) == 4: r.append(i.replace('0x','').upper()) result = ' '.join(r) return result except Exception as e: print('###### Catched Error: '+ str(type(e))) if 'socket.timeout' in str(type(e)): print('[server timeout to respond]')
def receive_data(self): recv_data = self.client.recv(self.BUFSIZ) print('\n recv_data: ') print(recv_data) recv_decoded_data = tongue.Decode(recv_data) print('\n tongue decoded: ') print(recv_decoded_data.dst) #recv_decoded_data.dst : 十六进制用十进制表示 (126, 128, 1, 0, 5, 1, 0, 0, 0, 0, 1, 54, 129, 0, 16, 1, 0, 0, 255, 255, 1, 2, 0, 33, 126) l = [hex(i) for i in recv_decoded_data.dst] # 还原十六进制 r = [] for i in l: if len(i) == 3: r.append(i.replace('x', '').upper()) if len(i) == 4: r.append(i.replace('0x', '').upper()) result = ' '.join(r) return result
def resolution(self): """ step1: Decode the binary data to a tuple step2: Split each element by the JTT808 protocol step3: Recognize the message id ,and then checking Dicts! something like {'(1,0)':'ter_reg_req'} :return: None """ self.request_data = tongue.Decode(self.request) self.client_tuple_data = self.request_data.dst # Don't forget get dst attribute self.client_tuple_data = tuple(self.client_tuple_data) self.split_instance = MainSplit(self.client_tuple_data) self.request_dict = self.split_instance.result ''' #pi time time_pi = time.time() time_pi2 = time.localtime(time_pi) time_pi3 = time.strftime('%Y%m%d%H%M%S', time_pi2)[2:] self.request_dict['time_pi'] = (time_pi,) try: #terminal time for item in time_tuple: item = int(item) if item/10 == 0: item = '0'+str(item) else: item = str(item) str_ter_time = str_ter_time +item str_ter_time = '20'+str_ter_time ter_time = time.mktime(time.strptime(str_ter_time,'%Y%m%d%H%M%S')) #time interval result interval_time = time_pi - ter_time self.request_dict['interval_time'] = (str(interval_time),) self.request_dict['time_ter'] = (ter_time,) except: self.request_dict['interval_time'] = ('0',) ''' #Error request special processing if self.split_instance.debug: self.request_dict['GET'] = self.conn self.msg_key = str(self.request_dict['client_msg_flag'] + self.request_dict['client_aid']) else: warning('No Split instance !') self.PUB = False
def resolution(self): """ step1: Decode the binary data to a tuple step2: Split each element by the JTT808 protocol step3: Recognize the message id ,and then checking Dicts! something like {'(1,0)':'ter_reg_req'} :return: None """ self.request_data = tongue.Decode(self.request) self.client_tuple_data = self.request_data.dst # Don't forget get dst attribute #convert data self.client_tuple_data = list(self.client_tuple_data) num = len(self.client_tuple_data) i = 0 while i < num - 2: i = i + 1 if self.client_tuple_data[i] == 125: if self.client_tuple_data[i + 1] == 1: del self.client_tuple_data[i + 1] num = num - 1 if self.client_tuple_data[i + 1] == 2: del self.client_tuple_data[i + 1] self.client_tuple_data[i] = 126 num = num - 1 else: continue self.client_tuple_data = tuple(self.client_tuple_data) self.split_instance = MainSplit(self.client_tuple_data) self.request_dict = self.split_instance.result if self.split_instance.debug: self.request_dict['GET'] = self.conn self.msg_key = str(self.request_dict['client_msg_id']) else: warning('No Split instance !') self.PUB = False
def receive_and_decode(self): try: recv_raw = self.soket_client.recv(self.BUFSIZ) recv_decoded_data = tongue.Decode(recv_raw) print('\n tongue decoded: ') print(recv_decoded_data.dst) #recv_decoded_data.dst : 十六进制用十进制元组表示 (35, 35, 1, 0, 52, 54, 70, 55, 65, 83, 52, 71, 49, 54, 53, 70, 52, 57, 83, 68, 56, 1, 0, 6, 21, 10, 16, 16, 2, 33, 126) l = [hex(i) for i in recv_decoded_data.dst] # 还原十六进制 r = [] for i in l: if len(i) == 3: r.append(i.replace('x', '').upper()) if len(i) == 4: r.append(i.replace('0x', '').upper()) result = ' '.join(r) return result except Exception as e: print('@@@@@@@@@@@ ' + str(type(e))) if 'socket.timeout' in str(type(e)): print('[server timeout to respond]') finally: self.soket_client.shutdown(2) # 关闭接收:0,关闭发送:1,两个通道都关闭:2 print('[shut down socket connect]')
def resolution(self): """ step1: Decode the binary data to a tuple step2: Split each element by the JTT808 protocol step3: Recognize the message id ,and then checking Dicts! something like {'(1,0)':'ter_reg_req'} :return: None """ self.request_data = tongue.Decode(self.request) self.client_tuple_data = self.request_data.dst # Don't forget get dst attribute #print self.client_tuple_data if self.client_tuple_data[3] == 254 or self.client_tuple_data[3] == 1: self.client_tuple_data = tuple(self.client_tuple_data) self.split_instance = MainSplit(self.client_tuple_data) self.request_dict = self.split_instance.result #print self.request_dict['client_msg_content'] #Real-time reporting time judgment str_ter_time = '' time_tuple = self.request_dict['client_msg_content'][0:6] #pi time time_pi = time.time() time_pi2 = time.localtime(time_pi) time_pi3 = time.strftime('%Y%m%d%H%M%S', time_pi2)[2:] self.request_dict['time_pi'] = (time_pi, ) if 'client_msg_vin' in self.request_dict: vin_str = '' for item in self.request_dict['client_msg_vin']: item = chr(item) vin_str = vin_str + item self.request_dict['client_msg_vin_save'] = vin_str try: #terminal time for item in time_tuple: item = int(item) if item / 10 == 0: item = '0' + str(item) else: item = str(item) str_ter_time = str_ter_time + item str_ter_time = '20' + str_ter_time ter_time = time.mktime( time.strptime(str_ter_time, '%Y%m%d%H%M%S')) #time interval result interval_time = time_pi - ter_time self.request_dict['time_interval'] = (str(interval_time), ) self.request_dict['time_ter'] = (ter_time, ) except: self.request_dict['interval_time'] = ('0', ) #Error request special processing if self.split_instance.flag: self.request_dict['client_msg_id'] = (9, ) if self.split_instance.debug: self.request_dict['GET'] = self.conn self.msg_key = str(self.request_dict['client_msg_id']) else: warning('No Split instance !') self.PUB = False else: warning('Not a command package') self.PUB = False