def logout_car(terminal_request): ''' - 登出应答 ''' template = 'client_msg_id|sys_ok|client_msg_vin|client_msg_encryption|sys_fixed_msg_attr2|client_msg_content' content = terminal_request['client_msg_content'] terminal_request['client_msg_content'] = terminal_request[ 'client_msg_content'][0:6] terminal_request['time_pi'] = (int(time.time()), ) #data save vin = int_to_str_display(terminal_request['client_msg_vin']) time_pi = terminal_request['time_pi'] time_logout_car = ter_time_to_stamp(content[:6]) time_interval = (str(time_pi[0] - time_logout_car[0]), ) my_login_id = str(content[6] * 256 + content[7], ) logout_car_msg = { 'client_msg_vin': vin, 'time_pi': time_pi, #msg in the content 'time_ter': time_logout_car, 'time_interval': time_interval, 'login_id': my_login_id, } datasave(terminal_request, logout_car_msg, GB_TABLE_DICT['logout']) return render(terminal_request, template)
def load_car(terminal_request): template = 'client_msg_id|sys_ok|client_msg_iccid|client_msg_encryption|sys_fixed_msg_attr2|client_msg_content' content = terminal_request['client_msg_content'] terminal_request['client_msg_content'] = terminal_request[ 'client_msg_content'][0:6] #data save #get parameter #encryption = terminal_request['client_msg_encryption'] #msg_attr = terminal_request['client_msg_attr'] iccid = terminal_request['client_msg_iccid'] time_ter = time_tuple_to_timestamp_tuple(content[:6]) my_login_id = (content[6] * 256 + content[7], ) vin = int_to_str_display(content[8:28]) num_subsys = content[28:29] len_coding = content[29:30] sys_coding = content[30:] time_pi = (int(time.time()), ) login_car_msg = { 'client_msg_vin': vin, 'time_pi': time_pi, 'time_ter': time_ter, 'login_id': my_login_id, 'ICCID': iccid, 'num_subsys': num_subsys, 'len_coding': len_coding, 'sys_coding': sys_coding, } datasave(terminal_request, login_car_msg, ZDMON_TABLE_DICT['login']) #send message return render(terminal_request, template)
def load_car(terminal_request): ''' - 登入应答 ''' template = 'client_msg_id|sys_ok|client_msg_vin|client_msg_encryption|sys_fixed_msg_attr2|client_msg_content' content = terminal_request[ 'client_msg_content'] # client_msg_content 消息体数据 terminal_request['client_msg_content'] = terminal_request[ 'client_msg_content'][0:6] # 截取前6个字节 terminal_request['time_pi'] = (int(time.time()), ) # 树莓派时间 #data save vin = int_to_str_display(terminal_request['client_msg_vin']) # 获取vin码 time_pi = terminal_request['time_pi'] time_login_car = ter_time_to_stamp(content[:6]) # 登入时间 time_interval = (str(time_pi[0] - time_login_car[0]), ) # 登入时间和树莓派时间的时间间隔 login_id = (str(content[6] * 256 + content[7]), ) # 登陆流水号 ICCID = content[8:28] num_subsys = content[28:29] len_coding = content[29:30] sys_coding = content[30:] load_car_msg = { 'client_msg_vin': vin, 'time_pi': time_pi, 'time_ter': time_login_car, 'time_interval': time_interval, 'login_id': login_id, 'iccid': ICCID, 'num_subsys': num_subsys, 'len_coding': len_coding, 'sys_coding': sys_coding, } datasave(terminal_request, load_car_msg, GB_TABLE_DICT['login']) # 保存登入数据到数据库 #send message return render(terminal_request, template) # 应答数据组包处理
def ter_cor_time(terminal_request): template = 'client_msg_id|sys_ok|client_msg_vin|client_msg_encryption|sys_fixed_msg_attr2|client_msg_content' ter_cor_time_msg = { 'client_msg_vin':terminal_request['client_msg_vin'], 'time_pi':terminal_request['time_pi'], } datasave(terminal_request, ter_cor_time_msg, 'ter_cor_time') return render(terminal_request, template)
def common(terminal_request): msg_content = 'client_msg_product|client_msg_id|sys_ok' template = 'ser_com_rsp|sys_fixed_msg_attr|client_dev_id|sys_product|' + msg_content time_pi = (time.time(),) auth_dict = { 'time_pi': time_pi, 'time_ter': time_pi, } datasave(terminal_request, auth_dict, JTT808_TABLE_DICT['auth']) return render(terminal_request, template)
def t_register(terminal_request): global roll_num peraeskey = terminal_request['client_ser_data'][:16] vin = terminal_request['client_ser_data'][16:33] t_box_sn = terminal_request['client_ser_data'][33:62] imsi = terminal_request['client_ser_data'][62:77] rollnum = terminal_request['client_ser_data'][77:93] iccid = terminal_request['client_ser_data'][93:] msg_flag = terminal_request['client_msg_flag'] event_creation_time = terminal_request['client_event_creation_time'] dispatch_creation_time = get_B11G_timestamp( terminal_request['client_dispatch_creation_time']) msg_counter = terminal_request['client_msg_conuter'] ser_data_len = terminal_request['client_ser_data_len'] sec_ver = terminal_request['client_sec_ver'] bid = (0, 0, 0, 10) #msg result terminal_request['client_result'] = (121, ) md5_data = peraeskey + rollnum + roll_num #get callback num callbacknum = to_md5_data(md5_data) terminal_request['client_ser_data'] = (0, ) + callbacknum + bid #data save sirun_register = { 'bid': bid, 'message_flag': msg_flag, 'event_creation_time': event_creation_time, 'dispatch_creation_time': dispatch_creation_time, 'message_counter': msg_counter, 'service_data_length': ser_data_len, 'security_version': sec_ver, 'peraeskey': peraeskey, 'vin': vin, 't_box_sn': t_box_sn, 'imsi': imsi, 'roll_number': rollnum, 'iccid': iccid, 'callback_number': callbacknum, } datasave(terminal_request, sirun_register, SIRUN_TABLE_DICT['register']) #data check code terminal_request['client_ser_data_check'] = ( check(terminal_request['client_ser_data'] + (1, )), ) #data length len_data = len(terminal_request['client_ser_data']) terminal_request['client_ser_data_len'] = (len_data / 100, len_data % 100) #msg mid terminal_request['client_mid'] = (2, ) terminal_request['client_bid'] = bid template = 'client_fix_header|client_ser_data_check|client_ser_ver|client_bid|client_msg_flag|client_event_creation_time|client_aid|client_mid|client_msg_conuter|client_ser_data_len|client_result|client_sec_ver|client_dispatch_creation_time|client_ser_data' #return msg render(terminal_request, template)
def load_car(terminal_request): #print terminal_request template = 'client_msg_header|sys_com_rsp|sys_fixed_msg_attr3|client_sign|client_msg_id|client_main_com|sys_ok|err_code|sys_time|sys_inf_code' terminal_request['sys_time'] = get_sys_localtime_tuple() time_login_car = (int(time.time()), ) sharengo_login_dict = { 'time_login_car': time_login_car, 'time_pi': (int(time.time()), ), } datasave(terminal_request, sharengo_login_dict, sharengo_table_dict['login']) return render(terminal_request, template)
def heartbeat(terminal_request): ''' - 心跳数据应答 ''' template = 'client_msg_id|sys_ok|client_msg_vin|client_msg_encryption|client_msg_attr' terminal_request['time_pi'] = (int(time.time()), ) heartbeat_msg = { 'client_msg_vin': terminal_request['client_msg_vin'], 'time_pi': terminal_request['time_pi'], } datasave(terminal_request, heartbeat_msg, GB_TABLE_DICT['heartbeat']) return render(terminal_request, template)
def ter_cor_time(terminal_request): ''' - 校时应答 ''' template = 'client_msg_id|sys_ok|client_msg_vin|client_msg_encryption|sys_fixed_msg_attr2|sys_time' terminal_request['time_pi'] = (int(time.time()), ) terminal_request['sys_time'] = get_sys_time_int_tuple() ter_cor_time_msg = { 'client_msg_vin': terminal_request['client_msg_vin'], 'time_pi': terminal_request['time_pi'], } datasave(terminal_request, ter_cor_time_msg, GB_TABLE_DICT['ter_cor_time']) return render(terminal_request, template)
def logout_car(terminal_request): template = 'client_msg_id|sys_ok|client_msg_vin|client_msg_encryption|sys_fixed_msg_attr2|client_msg_content' content = terminal_request['client_msg_content'] terminal_request['client_msg_content'] = terminal_request['client_msg_content'][0:6] #data save my_login_id = str(content[6]*256 + content[7],) logout_car_msg = { 'client_msg_vin' : terminal_request['client_msg_vin_save'], 'time_pi' : terminal_request['time_pi'], #msg in the content 'time_logout_car' : terminal_request['time_ter'], 'time_interval' : terminal_request['time_interval'], 'login_id' : my_login_id, } datasave(terminal_request,logout_car_msg,'car_logout') return render(terminal_request, template)
def t_logout(terminal_request): #get sys time terminal_request['client_dispatch_creation_time'] = get_sys_time_list() #data check code terminal_request['client_ser_data_check'] = ( check(terminal_request['client_ser_data'] + (1, )), ) #data length len_data = len(terminal_request['client_ser_data']) terminal_request['client_ser_data_len'] = (0, 0) #get_data time_logout_car = get_B11G_timestamp( terminal_request['client_dispatch_creation_time']) time_pi = (int(time.time()), ) bid = terminal_request['client_bid'] msg_flag = terminal_request['client_msg_flag'] event_creation_time = terminal_request['client_event_creation_time'] dispatch_creation_time = get_B11G_timestamp( terminal_request['client_dispatch_creation_time']) msg_counter = terminal_request['client_msg_conuter'] ser_data_len = terminal_request['client_ser_data_len'] sec_ver = terminal_request['client_sec_ver'] #save data sirun_car_logout = { 'time_logout_car': time_logout_car, 'time_pi': time_pi, 'bid': bid, 'message_flag': msg_flag, 'event_creation_time': event_creation_time, 'dispatch_creation_time': dispatch_creation_time, 'message_counter': msg_counter, 'service_data_length': ser_data_len, 'security_version': sec_ver, 'message_flag': msg_flag, } datasave(terminal_request, sirun_car_logout, SIRUN_TABLE_DICT['logout']) #msg result terminal_request['client_result'] = (0, ) terminal_request['client_mid'] = (2, ) template = 'client_fix_header|client_ser_data_check|client_ser_ver|client_bid|client_msg_flag|client_event_creation_time|client_aid|client_mid|client_msg_conuter|client_ser_data_len|client_result|client_sec_ver|client_dispatch_creation_time|client_ser_data' render(terminal_request, template)
def t_actual_msg_rep(terminal_request): print terminal_request #deal with data if terminal_request['client_mid'] == (1, ): terminal_request['client_mid'] == (2, ) terminal_request['client_ser_data'] = () terminal_request['client_ser_data_len'] = (0, 0) if terminal_request['client_mid'] == (4, ): terminal_request['client_mid'] = (3, ) time_ter = get_B11G_timestamp( terminal_request['client_dispatch_creation_time']) time_pi = (int(time.time()), ) version_id = terminal_request['client_ser_data'][0:4] fixtime = terminal_request['client_ser_data'][4:8] position = terminal_request['client_ser_data'][8:21] car_status = terminal_request['client_ser_data'][21:29] car_data = terminal_request['client_ser_data'][29:] sirun_actual_msg_dict = { 'time_ter': time_ter, 'time_pi': time_pi, 'version_id': version_id, 'fixtime': fixtime, 'position': position, 'car_status': car_status, 'car_data': car_data, } datasave(terminal_request, sirun_actual_msg_dict, SIRUN_TABLE_DICT['actual_msg']) #get sys time terminal_request['client_dispatch_creation_time'] = get_sys_time_list() #data check code terminal_request['client_ser_data_check'] = ( check(terminal_request['client_ser_data'] + (1, )), ) #msg result terminal_request['client_result'] = (0, ) template = 'client_fix_header|client_ser_data_check|client_ser_ver|client_bid|client_msg_flag|client_event_creation_time|client_aid|client_mid|client_msg_conuter|client_ser_data_len|client_result|client_sec_ver|client_dispatch_creation_time|client_ser_data' render(terminal_request, template)
def heartbeat(terminal_request): heartbeat_msg = { 'client_msg_vin':terminal_request['client_msg_vin'], 'time_pi':terminal_request['time_pi'], } datasave(terminal_request, heartbeat_msg, 'heart_beat')
datasave(terminal_request,logout_car_msg,'car_logout') return render(terminal_request, template) def actual_msg_report(terminal_request): template= 'client_msg_id|sys_ok|client_msg_vin|client_msg_encryption|sys_fixed_msg_attr2|client_msg_content' content = terminal_request['client_msg_content'] split_str_msg = Split_msg(content) msg_dict = split_str_msg.split_con() car_actual_msg = get_sql_dict(terminal_request, msg_dict) try: res_dict = chargeable_sys(car_actual_msg) except Exception, e: pass datasave(terminal_request,car_actual_msg,'car_actual_msg') def heartbeat(terminal_request): heartbeat_msg = { 'client_msg_vin':terminal_request['client_msg_vin'], 'time_pi':terminal_request['time_pi'], } datasave(terminal_request, heartbeat_msg, 'heart_beat') def ter_cor_time(terminal_request): template = 'client_msg_id|sys_ok|client_msg_vin|client_msg_encryption|sys_fixed_msg_attr2|client_msg_content' ter_cor_time_msg = { 'client_msg_vin':terminal_request['client_msg_vin'], 'time_pi':terminal_request['time_pi'], } datasave(terminal_request, ter_cor_time_msg, 'ter_cor_time')
'client_msg_vin': vin, 'time_pi': time_pi, #msg in the content 'time_ter': time_ter, 'time_interval': time_interval, 'client_msg_id': client_msg_id, } split_str_msg = Split_msg(content) msg_dict = split_str_msg.split_con() car_actual_msg = dict(msg_dict, **car_actual_msg) try: res_dict = chargeable_sys(car_actual_msg) except Exception, e: #print 'error: ',e pass datasave(terminal_request, car_actual_msg, GB_TABLE_DICT['actual_msg']) def heartbeat(terminal_request): ''' - 心跳数据应答 ''' template = 'client_msg_id|sys_ok|client_msg_vin|client_msg_encryption|client_msg_attr' terminal_request['time_pi'] = (int(time.time()), ) heartbeat_msg = { 'client_msg_vin': terminal_request['client_msg_vin'], 'time_pi': terminal_request['time_pi'], } datasave(terminal_request, heartbeat_msg, GB_TABLE_DICT['heartbeat']) return render(terminal_request, template)
def t_login(terminal_request): platrandom = (48, 51, 67, 51, 55, 66, 57, 50, 51, 55, 50, 68, 52, 48, 57, 52) mydatabase = MyDatabase.MyDatabase() select_sql = 'select * from sirun_register where 1 order by dispatch_creation_time desc limit 1' select_data = mydatabase.select_last_data(select_sql) #get data time_login_car = get_B11G_timestamp( terminal_request['client_dispatch_creation_time']) time_pi = (int(time.time()), ) bid = terminal_request['client_bid'] msg_flag = terminal_request['client_msg_flag'] event_creation_time = terminal_request['client_event_creation_time'] dispatch_creation_time = get_B11G_timestamp( terminal_request['client_dispatch_creation_time']) msg_counter = terminal_request['client_msg_conuter'] ser_data_len = terminal_request['client_ser_data_len'] sec_ver = terminal_request['client_sec_ver'] if terminal_request['client_mid'] == (1, ): keytype = terminal_request['client_ser_data'][0:1] tboxsn = terminal_request['client_ser_data'][1:30] vin = terminal_request['client_ser_data'][30:47] tboxrandom = terminal_request['client_ser_data'][47:] try: encryption_key = select_data['callback_number'] except: error('you should register terminal') encryption_key = change_tuple(encryption_key) val = tboxrandom + encryption_key + platrandom md5_data = to_md5_data(val) terminal_request['client_ser_data'] = md5_data + platrandom terminal_request['client_mid'] = (2, ) #save data sirun_car_login = { 'time_ter': time_login_car, 'time_pi': time_pi, 'bid': bid, 'message_flag': msg_flag, 'event_creation_time': event_creation_time, 'dispatch_creation_time': dispatch_creation_time, 'message_counter': msg_counter, 'service_data_length': ser_data_len, 'security_version': sec_ver, 'message_flag': msg_flag, 'key_type': keytype, 't_box_sn': tboxsn, 'vin': vin, 't_box_random': tboxrandom, } datasave(terminal_request, sirun_car_login, SIRUN_TABLE_DICT['login']) if terminal_request['client_mid'] == (3, ): serial_up = terminal_request['client_ser_data'][:16] acess_key = terminal_request['client_ser_data'][16:32] success_key = (0, 0, 0, 0, 0, 0, 0, 0) terminal_request['client_ser_data'] = platrandom + ( 0, ) + success_key + success_key + success_key terminal_request['client_mid'] = (5, ) #save data sirun_car_login = { 'time_ter': time_login_car, 'time_pi': time_pi, 'bid': bid, 'message_flag': msg_flag, 'event_creation_time': event_creation_time, 'dispatch_creation_time': dispatch_creation_time, 'message_counter': msg_counter, 'service_data_length': ser_data_len, 'security_version': sec_ver, 'message_flag': msg_flag, 'serial_up': serial_up, 'acess_key': acess_key, } datasave(terminal_request, sirun_car_login, SIRUN_TABLE_DICT['login']) #get sys time terminal_request['client_dispatch_creation_time'] = get_sys_time_list() #data check code terminal_request['client_ser_data_check'] = ( check(terminal_request['client_ser_data'] + (1, )), ) #data length len_data = len(terminal_request['client_ser_data']) terminal_request['client_ser_data_len'] = (len_data / 100, len_data % 100) #msg result terminal_request['client_result'] = (0, ) template = 'client_fix_header|client_ser_data_check|client_ser_ver|client_bid|client_msg_flag|client_event_creation_time|client_aid|client_mid|client_msg_conuter|client_ser_data_len|client_result|client_sec_ver|client_dispatch_creation_time|client_ser_data' ##### display_sys_time() display_stamp_to_date(time_login_car[0]) #return msg render(terminal_request, template)