Esempio n. 1
0
 def init_PROCESS(self):
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["@Process"] = VS.GET_RM(
         "Process", "CAR_INFO")
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["@StartTime"] = VS.GET_RM(
         "StartTime", "CAR_INFO")
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["@StartTimeUTC"] = VS.GET_RM(
         "StartTimeUTC", "CAR_INFO")
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["@FinishTime"] = VS.GET_RM(
         "FinishTime", "CAR_INFO")
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["@Status"] = VS.GET_RM(
         "Status", "CAR_INFO")
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["@Cell"] = VS.GET_RM(
         "Cell", "CAR_INFO")
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["@Cal"] = VS.GET_RM(
         "StartTime", "CAR_INFO")
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["@DCRev"] = VS.GET_RM(
         "DCRev", "CAR_INFO")
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["@SWVer"] = VS.GET_RM(
         "SWVer", "CAR_INFO")
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["@OperatorID"] = ""
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["@RunType"] = "Full"
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["@Retest"] = "0"
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["@Latest"] = "1"
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["@SeqComplete"] = VS.GET_RM(
         "SeqComplete", "CAR_INFO")
Esempio n. 2
0
 def receive_uds_msg(self, message,rxBufLen=1024,localECUAddr=None, tx_address=None,timeout=None):
     global TIME_OUT_FOR_REMSG
     if self.re_finish==False:self.re_msg.init_value()
     if timeout==None:timeout=TIME_OUT_FOR_REMSG
     if vs.wait_time_out("uds_message_time",timeout)<1:
         self.re_finish=True
         return self.error_set("receive UDS message timeout.")
     if self._isTCPConnected:
         try:
             if timeout==None:timeout=TIME_OUT_FOR_REMSG
             re_message=self.wait_frame(timeout=timeout)
             if vs.typeof(re_message)=="int":return re_message
             if re_message!=None:
                 if len(re_message)==0 or re_message==b'':
                     time.sleep(0.01)
                     return self.receive_uds_msg(message,tx_address=tx_address,timeout=timeout)
                 if not localECUAddr:localECUAddr = self._localECUAddr
                 if not tx_address:tx_address = self._tx_address
                 re_message1=binascii.hexlify(re_message).decode('utf-8').upper();re_message=re_message1                                 
                 re_msg_list=self.msg_control.set_re_msg(re_message)                   
             else:
                 time.sleep(0.01)
                 return self.receive_uds_msg(message,tx_address=tx_address,timeout=timeout,)
             self.re_msg_control(re_msg_list,tx_msg=message,re_message=re_message,tx_address=tx_address)
             if self.re_finish==False:
                 return self.receive_uds_msg(message,tx_address=tx_address,timeout=timeout)
             else:return 1
         except Exception as err:
             return self.error_set( "Unable to receive UDS message. Socket failed with error: %s" % str(err))
     else:
         return self.error_set("receive uds msg error , Not currently connected to a server")
Esempio n. 3
0
    def re_msg_control(self,msg_list=None,tx_msg=None,re_message=None ,tx_address=None):
        for msg in msg_list:
            log_str=msg.sourceAddress+'--->'+msg.targetAddress+'\trevd_message:'+msg.message
            self.log_message(log_str)
            if msg.payloadType == DOIP_GENERIC_NEGATIVE_ACKNOWLEDGE:
                self.re_finish=True
                raise Exception("DOIP GENERIC NEGATIVE ACKNOWLEDGE") 
            if msg.payloadType == DOIP_DIAGNOSTIC_NEGATIVE_ACKNOWLEDGE:
                self.re_finish=True
                raise Exception("DOIP DIAGNOSTIC NEGATIVE ACKNOWLEDGE.") 


            if tx_address!=msg.sourceAddress:
                continue
            if msg.payloadType == DOIP_DIAGNOSTIC_POSITIVE_ACKNOWLEDGE or (msg.payload[4:6] =='78' and msg.payload[0:2] =='7F'):
                continue
            if vs.typeof(tx_msg)=="str":start_flag_value =int(tx_msg[0:2],16)
            if vs.typeof(tx_msg)=="bytes":start_flag_value=int.from_bytes(tx_msg[0:1], byteorder='little', signed=True)
            if start_flag_value+0x40!=int(msg.payload[0:2],16):
                if msg.payload[0:2]=='7F' and msg.payload[4:6] in PyUDS.ERROR_DIC:
                    error_key=msg.payload[4:6]
                    message_str="uds negative respond message. %s" %PyUDS.ERROR_DIC[error_key]
                    if self.re_finish!=True:
                        self.re_msg=msg
                    self.re_finish=True
                    raise Exception(message_str) 
                    #return self.error_set(message_str)
                else:
                    continue
            else:
                self.re_msg=msg
                self.re_finish=True
Esempio n. 4
0
 def get_car_address(self):
     try:
         s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)    
         s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
         s.setsockopt(socket.SOL_SOCKET,socket.SO_RCVTIMEO, TIME_OUT_FOR_UDP_IP*1000)
         s.bind(('', 13400))
         vs.start_wait_time("udp_time")
         while True:
             data, address = s.recvfrom(65535)
             mm=data[0:4]
             if(mm==b'\x02\xfd\x00\x04'):
                 self._targetIPAddr=address[0]
                 break
             if(vs.wait_time_out("udp_time",TIME_OUT_FOR_UDP_IP)<1):
                 errorstr=" time out  get the  car address"
                 return self.error_set(errorstr)
         #try:s.close()
         #except Exception as e:pass 
     except Exception as e:
         try:s.close()
         except Exception as e:pass           
         self._targetIPAddr = None
         self._targetPort = None
         self._isTCPConnected = False
         errorstr="Unable to get the car address. Socket failed with error: %s" % (e)
         return self.error_set(errorstr)
Esempio n. 5
0
 def send_message(self,message,tx_address=None):
     if not tx_address:
         tx_address=self._tx_address
     self.empty_rxqueue()
     vs.start_wait_time("uds_message_time")        
     ret=self.send_uds_message(message,tx_address=tx_address)
     if ret<0:
         return self.error_set("failed with send tcp message: %s" % message)
     else:return 1
Esempio n. 6
0
 def send(self,message,tx_address=None,timeout=None):
     if not tx_address:
         tx_address=self._tx_address
     self._KeepRoutingFlag=1
     self.empty_rxqueue()
     vs.start_wait_time("uds_message_time")
     ret=self.send_uds_message(message,tx_address=tx_address,timeout=timeout)
     if ret>=0:
         self.re_finish=False
         ret=self.receive_uds_msg(message,tx_address=tx_address,timeout=timeout)
     self._KeepRoutingFlag=1
     return ret    
Esempio n. 7
0
 def append_process_trace_file(self):
     self.trace_file_title = VS.GET_RM("LOG_NAME", "CAR_INFO")
     week_number = datetime.now().isocalendar()[1]
     if int(week_number) > 9: week_str = str(week_number)
     else: week_str = '0' + str(week_number)
     year_number = datetime.now().isocalendar()[0]
     self.trace_file_path = "/VCATSTRACEFILES/" + str(
         year_number) + "/WK" + week_str + "/" + VS.GET_RM(
             "LOG_NAME", "CAR_INFO") + "\\" + VS.GET_RM(
                 "LOG_NAME", "CAR_INFO") + ".log"
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["TRACE_FILES"]["TRACE_FILE"][
         "@FileTitle"] = self.trace_file_title
     self.v_json["UNIT_IN_TEST"]["PROCESS"]["TRACE_FILES"]["TRACE_FILE"][
         "@FilePath"] = self.trace_file_path
Esempio n. 8
0
 def test_control(self,vin):
     if not self.start_btn.isEnabled():return 1
     if len(vin)>0:
         self.head_message.setText(vin)
         self.set_window_0()
         self.update_history_table()
         vs.check_mac_address()
         self.init_variable()                          
         self.swdl_process = threading.Thread(target=swdl.LL, args=(self.vin,))
         self.swdl_process.setDaemon(True)
         self.swdl_process.start()
         self.process_flag=1
     else:
         self.set_window_1()
         self.init_variable()
         self.head_message.setText('')
Esempio n. 9
0
def read_vbf_list():
    global br_vbf_info_dic
    swdl_vf_path_dic = vs.GV('swdl_vf_path_dic')
    for ecu in swdl_vf_path_dic:
        for path in swdl_vf_path_dic[ecu]:
            vbf_info_dic = VBF_Read(path)
            #vbf_key=vbf_info_dic[b'sw_part_number']+vbf_info_dic[b'sw_version']
            br_vbf_info_dic[path] = vbf_info_dic
Esempio n. 10
0
    def __init__(self, parent=None):
        super(MyMainWindow, self).__init__(parent)
        vs.read_config()
        self.setupUi(self)
        self.item_row=20
        self.status_label = QtWidgets.QLabel(self.centralwidget)
        self.statusbar.addWidget(self.status_label)
        self.vin=''
        self.status_label.setText('creat by wangxinlei viersion 2020.11.04')
        self.update_message.connect(self.message_control)
        self.update_middle_message.connect(self.middle_message_control)
        self.head_message.returnPressed.connect(lambda:self.mbuttion1clicked())
        self.start_btn.clicked.connect(lambda:self.mbuttion1clicked())

        self.init_history_table()
        self.history_table.itemClicked.connect(self.get_item)
        self.set_windows_size()
        self.showMaximized()
        self.process_flag=0
        self.ui_control()
Esempio n. 11
0
 def send_uds_message(self, message, localECUAddr=None, tx_address=None,timeout=None):
     global TIME_OUT_FOR_REMSG
     if timeout==None:timeout=TIME_OUT_FOR_REMSG
     if vs.wait_time_out("uds_message_time",timeout)<1:            
         return self.error_set("send UDS message timeout.")
     if not localECUAddr:
         localECUAddr = self._localECUAddr
     if tx_address==None and self._tx_address==None:
         return self.error_set("Not set the target ecu address can not send %s!! " %message)
     elif not tx_address:
         tx_address=self._tx_address
     DoIPHeader = PROTOCOL_VERSION + INVERSE_PROTOCOL_VERSION + DOIP_DIAGNOSTIC_MESSAGE
     if vs.typeof(message)=="str":payload = localECUAddr + tx_address + message  # no ASRBISO
     if vs.typeof(message)=="bytes":message=binascii.hexlify(message).decode().upper();payload = localECUAddr + tx_address + message  # no ASRBISO
     payloadLength = "%.8X" % int(len(payload) / 2)
     UDSString = DoIPHeader + payloadLength + payload
     UDSString=UDSString.upper()
     log_msg=self._localECUAddr+'--->'+tx_address +'\tsend_message:'+UDSString
     #if self._mode==0:self.log_message(log_msg)
     if self._isTCPConnected:
         try:
             self._TCP_Socket.send(bytes.fromhex(UDSString))
             self.log_message(log_msg)
             return 1
         except socket.error as err: 
             if self._re_connect==True:        
                 self.close()
                 time.sleep(2)
                 ret=self.Connect()
                 if ret>=0:
                     return self.send_uds_message(message,tx_address=tx_address,timeout=None)
             return self.error_set("%s error. Socket failed with error: %s" % (log_msg, err))
     else:
         if self._re_connect==True:        
             self.close()
             time.sleep(2)
             ret=self.Connect()
             if ret>=0:
                 return self.send_uds_message(message,tx_address=tx_address,timeout=None)
         return self.error_set("%s error ,Not currently connected to a server" %log_msg)
Esempio n. 12
0
def vbf_Read_hex_data_block(vbf_inf_dic, vbf_hex_data, file_path):
    vbf_data_block = {}
    #aa0=vbf_inf_dic[b"verification_block_start"][2:].decode()
    #aa0=bytes.fromhex(aa0)
    check_finish = False
    #aa0_pose=vbf_hex_data.find(aa0)
    #print(vbf_hex_data)
    aa0_pose = 0
    while check_finish == False and aa0_pose >= 0:
        #if aa0 in vbf_hex_data:
        try:
            data_block = {}
            data_block[b"address"] = vbf_hex_data[aa0_pose:aa0_pose + 4]
            data_block[b"length"] = vbf_hex_data[aa0_pose + 4:aa0_pose + 8]
            aa0_length_int = int.from_bytes(data_block[b"length"],
                                            byteorder='big',
                                            signed=False)
            data_block[b"data"] = vbf_hex_data[aa0_pose + 8:aa0_pose + 8 +
                                               aa0_length_int]
            data_block[b"crc"] = vbf_hex_data[aa0_pose + 8 +
                                              aa0_length_int:aa0_pose + 10 +
                                              aa0_length_int]
            vbf_data_block[data_block[b"address"]] = data_block
            #print(len(vbf_hex_data))
            if aa0_pose + 10 + aa0_length_int >= len(vbf_hex_data):
                check_finish = True
                break
            else:
                aa0_pose = aa0_pose + 10 + aa0_length_int
        except:
            error_str = "error format %s " % file_path
            vs.m_message(error_str)
            break
        """
		else:
			print('no get %s in %s' %(aa0,vbf_inf_dic[b'sw_part_number']))
			time.sleep(2)
			break
		"""
    return vbf_data_block
Esempio n. 13
0
def active_mode(doip):
    vs.m_message("set car into active mode")
    try:
        ret = doip.send(b"\x10\x03", tx_address='1A01')
        ret = doip.send(b"\x27\x03", tx_address='1A01')
        Seed = doip.re_msg.payload[-6:]
        key = Security_Access('43454D3033', Seed)
        message = '2704' + key
        ret = doip.send(message, tx_address='1A01')
        if ret > 0: ret = doip.send(b"\x2F\xDD\x0A", tx_address='1A01')
        if ret > 0 and doip.re_msg.payload[-2:] != "0B":
            ret = doip.send(b"\x2F\xDD\x0A", tx_address='1A01')
            ret = doip.send(b"\x22\xDD\x0A", tx_address='1A01')
            if ret < 0 or doip.re_msg.payload[-2:] != "0B":
                doip.error_set("error active CEM")
        vs.RM("Active CEM", "OK", testname="Active CEM")
    except Exception as err:
        doip.log_message("error active CEM %s" % str(err))
        vs.RE("Active CEM", "NOK", testname="Active CEM")
        vs.RE("Active CEM MESSAGE", str(err), testname="Active CEM")
    time.sleep(5)
    try:
        vs.m_message("Send 1FFF MESSAGE")
        vs.m_message("Wait 15s")
        try:
            ret = doip.send(b"\x31\x01\x02\x06", tx_address='1FFF')
        except Exception as err:
            pass
        try:
            ret = doip.send(b"\x10\x02", tx_address='1FFF')
        except Exception as err:
            pass

    except Exception as err:
        doip.log_message("error send IFFF message %s" % err)
        vs.RE("SEND 1FFF MESSAGE", "NOK", testname="inActive CEM")
Esempio n. 14
0
    def __init__(self,logname='',tx_address=None,re_connect=False):
        if "Window" in platform.platform(): # Checks if software is running in the Windows OS
            self._localIPAddr = socket.gethostbyname(socket.getfqdn())
        elif "Linux" in platform.platform():
            self._localIPAddr = get_ip('eth0')    
        self._localPort =13400
        self._localECUAddr = '0E80'
        self._targetIPAddr = None
        self._targetPort = None
        self._tx_address = tx_address
        self._isTCPConnected = False
        self._isRoutingActivated = False
        self._activationSwitch = False
        self.re_msg=doip_message()
        self.msg_control=DoIPMsg()
        self.rxqueue = queue.Queue()
        self.exit_requested = False
        self._mode=1
        self.test_check=0
        self._logname=logname
        self._wxll_log = pylog.TNLog(self._logname,self._mode)
        self._KeepRoutingFlag=0
        self._KeepRoutingTask=None
        sys.setrecursionlimit(5000)
        self._re_connect=re_connect
        self.rxthread_task_state=False
        vs.SV("TEST_MODE",self._mode)
        try:
            self._TCP_Socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            # self._TCP_Socket.setsockopt(socket.IPPROTO_TCP, 12, 1)#supposedly, 12 is TCP_QUICKACK option id
            time.sleep(0.1)
            self._TCP_Socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY,1)  # immediately send to wire wout delay
            time.sleep(0.1)
            self._TCP_Socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)  # allows different sockets to reuse ipaddress
            time.sleep(0.1)
            self._TCP_Socket.settimeout(5.0)
            #self._TCP_Socket.setblocking(1)
            time.sleep(0.5)
            self._TCP_Socket.bind((self._localIPAddr, self._localPort))
            #print( "Socket successfully created: Binded to %s:%d" % (
            #    self._TCP_Socket.getsockname()[0], self._TCP_Socket.getsockname()[1]))

        except socket.error as err:
            self._TCP_Socket = None
            errorstr="Socket creation failed with error: %s" % err
            self.error_set(errorstr)
Esempio n. 15
0
def creat_vcats_xml(save_json):
    test_json = set_process_test(save_json)
    vj = Vcats_Json()
    vj.test = test_json
    vj.init_UNIT_IN_TEST()
    vj.init_PROCESS()
    vj.append_process_test()
    vj.append_process_trace_file()
    xml_path = VS.Config["proj_path"] + VS.Config["result"]["vcats_path"]
    log_time = datetime.now().strftime("%Y%m%d_%H%M%S")
    file_name = VS.GET_RM("VIN",
                          "CAR_INFO") + "_" + log_time + "_" + VS.GET_RM(
                              "Cell", "CAR_INFO") + ".xml"
    xml_path = xml_path + '/' + file_name
    jsondic_to_xml(vj.v_json, xml_path)
    VS.set_file_readonly(xml_path)
    if VS.GV("TEST_MODE") > 0:
        logname = VS.GV('LOG_NAME')
        logpath = VS.Config["proj_path"] + VS.Config["DEVICE"]["ftp_log"][
            "upload_path"]
        log_tt = logpath + '/' + logname + '.log'
        log_finish = logpath + '/' + logname + '_finish' + '.log'
        os.rename(log_tt, log_finish)
        VS.set_file_readonly(log_finish)
Esempio n. 16
0
def LL(vin):
    vs.read_broadcast(vin)
    read_vbf_info()
    sbl_name_list = vs.Config['image']['sbl_type'].split(',')
    logname = vs.GV('LOG_NAME')
    swdl_vf_path_dic = vs.GV('swdl_vf_path_dic')
    try:
        doip1 = PyDoIP.DoIP_Client(logname)
        doip1._mode = 0
        doip1.Connect()
    except Exception as err:
        vs.m_message(str(err))
        vs.RE("connect_car", str(err), testname="connect_car")
        try:
            doip1.close()
        except Exception as err:
            pass
        return 1

    if vs.PML("AA31") or vs.PML("AAC7") or vs.PML("AAB9"):
        in_active_mode(doip1)
    else:
        active_mode(doip1)
    doip1.close()

    time.sleep(10)

    doip = PyDoIP.DoIP_Client(logname)
    doip._mode = 0
    #doip.Connect(car_address='169.254.19.1')
    doip.Connect()
    #doip.Re_connect()

    try:
        doip.keep_Routing_task()
    except Exception as err:
        vs.m_message(str(err))
        vs.RE("keep_Routing_task", str(err), testname="keep_Routing_task")
        try:
            doip.close()
        except Exception as err:
            pass
        return 1

    for ecu in swdl_vf_path_dic:
        vs.m_message('Flashing  soft in  %s ' % (ecu))
        try:
            doip._tx_address = vs.Car_Config['ecu_info'][ecu]['address'][2:]
            try:
                ret = doip.send(b"\x10\x02")
                ret = doip.send(b"\x22\xF1\x86")
            except Exception as err:
                vs.m_message(str(err))
        except Exception as err:
            message = "error get %s address info in json info" % ecu
            vs.m_message(message)
            vs.RE("", str(message), testname=ecu + "_SWDL")
            continue
        if get_ecu_security_access(doip, ecu) < 0:
            continue
        for path in swdl_vf_path_dic[ecu]:
            try:
                set_str = 'OK'
                vbf_info_dic = br_vbf_info_dic[path]
                ecuaddress = vbf_info_dic[b'ecu_address'].decode().upper()
                vbf_name = (vbf_info_dic[b'sw_part_number'] +
                            vbf_info_dic[b'sw_version']).decode().upper()
                vbf_type = vbf_info_dic[b'sw_part_type'].decode().upper()
                data_format = binascii.unhexlify(
                    vbf_info_dic[b'data_format_identifier'][2:])
                vs.m_message('Flashing  vbf:  %s ,type: %s ,to : %s ' %
                             (vbf_name, vbf_type, ecu))
                doip.log_message('Flashing  vbf:  %s ,type: %s ,to : %s ' %
                                 (vbf_name, vbf_type, ecu))

                #if vbf_type in sbl_name_list:
                #	doip.send(b'\x22\xf1\x86')
                if b'erase' in vbf_info_dic:
                    erase_datastr = vbf_info_dic[b'erase']
                    erase_data_dic = set_erase_ad(erase_datastr)
                    for address in erase_data_dic:
                        sendstr = b'\x31\x01\xff\x00' + erase_data_dic[
                            address]['start_address'] + erase_data_dic[
                                address]['end_address']
                        try:
                            doip.send(sendstr, timeout=120)
                            if doip.re_msg.payload[0:8] == 71010212:
                                ret = doip.receive_uds_msg(message=sendstr,
                                                           timeout=120)
                        except Exception as err:
                            if doip.re_msg.payload[0:6] != '7101FF':
                                raise Exception('error erase momory')
                flag = 1
                star_pose = 0
                end_pose = 0
                for key in vbf_info_dic[b'hex_data']:
                    hex_length = vbf_info_dic[b'hex_data'][key][b'length']
                    hex_data = vbf_info_dic[b'hex_data'][key][b'data']
                    hex_address = key
                    sendstr = b'\x34' + data_format + b'\x44' + hex_address + hex_length
                    ret = doip.send(sendstr)
                    if ret > 0:
                        myResponse = doip.re_msg.payload
                        sendlength = int.from_bytes(bytes.fromhex(
                            myResponse[-4:]),
                                                    byteorder='big',
                                                    signed=False)
                    else:
                        continue
                    while (star_pose <= len(hex_data)):
                        b_flag = flag.to_bytes(1,
                                               byteorder='little',
                                               signed=False)
                        if end_pose > 0: star_pose = end_pose
                        else: star_pose = end_pose
                        end_pose = star_pose + sendlength - 2
                        if star_pose > len(hex_data):
                            ret = doip.send(b'\x37')
                            #print("end_sending",key)
                            flag = 1
                            star_pose = 0
                            end_pose = 0
                            break
                        else:
                            send_data = hex_data[star_pose:end_pose]
                            aa = b'\x36' + b_flag + send_data
                            re_ret = doip.send(b'\x36' + b_flag + send_data)
                            if re_ret < 0: break
                            flag = flag + 1
                            if (flag > 255): flag = 0
                    if re_ret < 0:
                        re_ret = 0
                        continue
                    if key == list(vbf_info_dic[b'hex_data'])[-1]:
                        if (b'sw_signature' in vbf_info_dic
                                or b'sw_signature_dev' in vbf_info_dic):
                            if b'sw_signature' in vbf_info_dic:
                                send_str = vbf_info_dic[b'sw_signature']
                            else:
                                send_str = vbf_info_dic[b'sw_signature_dev']
                            send_str = b'\x31\x01\x02\x12' + binascii.unhexlify(
                                send_str[2:])
                            try:
                                ret = doip.send(send_str, timeout=10)
                            except Exception as err:
                                ret = doip.send(send_str, timeout=10)
                        if vbf_type in sbl_name_list:
                            call_address = binascii.unhexlify(
                                vbf_info_dic[b'call'][2:])
                            send_str = b'\x31\x01\x03\x01' + call_address
                            doip.send(send_str)
                        else:
                            lastvf = vs.GV('BROADCAST.$' + ecu + '.-1')
                            #if vbf_name==lastvf and key==list(vbf_info_dic[b'hex_data'])[-1]:
                            if path.find(lastvf) > 0 and key == list(
                                    vbf_info_dic[b'hex_data'])[-1]:
                                #send_str=b'\x31\x01\x02\x05'+hex_address
                                send_str = b'\x31\x01\x02\x05'
                                ret = doip.send(send_str)
                                myResponse = doip.re_msg.payload
                                if myResponse[-8:] == '00000000':
                                    doip.log_message(
                                        "download %s vbf files ok" % ecu)
                                    set_str = 'OK'
                                    #print("download %s vbf files ok" %ecu)
                                else:
                                    doip.log_message(
                                        "download %s vbf files Nok" % ecu)
                                    set_str = 'NOK'
                                    #print("download %s vbf files Nok" %ecu)

                time.sleep(0.05)
                vs.RM(vbf_name, set_str, testname=ecu + "_SWDL")
            except Exception as err:
                errorstr = "%s" % err
                vs.RM(vbf_name, "NOK", testname=ecu + "_SWDL")
                vs.RE(vbf_name, str(errorstr), testname=ecu + "_SWDL")
                if doip._mode == 0: continue
                else: break
    try:
        ret = doip.send_message(b"\x11\x01", tx_address='1FFF')
    except Exception as err:
        vs.RE("RESET_ECU", str(err), testname="RESET_ECU")
    finally:
        doip.close()
Esempio n. 17
0
def get_ecu_security_access(doip, ecu):
    try:
        level_1_2 = vs.Car_Config['ecu_info'][ecu]['level_1_2']
    except Exception as err:
        vs.m_message("error get the ecu name %s in json's car_config file " %
                     ecu)
        vs.RE("get json info ecu level_1_2 config",
              'NOK',
              testname=ecu + "_SWDL")
        return -1
    try:
        ret = doip.send(b"\x27\x01")
        myResponse = doip.re_msg.payload
    except Exception as err:
        vs.m_message("error %s get in to security access " % ecu)
        vs.RE("swdl security access", 'NOK', testname=ecu + "_SWDL")
        return -1
    if len(myResponse) > 0:
        Seed = doip.re_msg.payload[-6:]
        key = Security_Access(str(level_1_2), Seed)
        try:
            ret = doip.send('2702' + key)
            return 1
        except Exception as err:
            try:
                if vs.GV("PINCODE." + ecu[0:3] + "000"):
                    level_1_2 = vs.GV("PINCODE." + ecu[0:3] + "000")
                    ret = doip.send(b"\x27\x01")
                    Seed = doip.re_msg.payload[-6:]
                    key = Security_Access(str(level_1_2), Seed)
                    ret = doip.send('2702' + key)
                    return 1
                else:
                    ret = doip.send(b"\x10\x02")
                    ret = doip.send(b"\x27\x01")
                    Seed = doip.re_msg.payload[-6:]
                    key = Security_Access(str(level_1_2), Seed)
                    ret = doip.send('2702' + key)
                    return 1
            except Exception as err:
                vs.m_message("error %s get in to security access " % ecu)
                vs.RE("swdl security access", 'NOK', testname=ecu + "_SWDL")
                return -1
    else:
        return -1
Esempio n. 18
0
def in_active_mode(doip):
    vs.m_message("set car into inactive mode")
    #doip=PyDoIP.DoIP_Client(logname)
    #doip.Connect()
    #vs.SV("car_address",doip._targetIPAddr)
    #doip.keep_Routing_task()
    try:
        ret = doip.send(b"\x10\x03", tx_address='1A01')
        ret = doip.send(b"\x27\x03", tx_address='1A01')
        Seed = doip.re_msg.payload[-6:]
        key = Security_Access('43454D3033', Seed)
        message = '2704' + key
        ret = doip.send(message, tx_address='1A01')
        if ret > 0: ret = doip.send(b"\x2F\xDD\x0A", tx_address='1A01')
        if ret > 0 and doip.re_msg.payload[-2:] != "01":
            ret = doip.send(b"\x2F\xDD\x0A\x03\x01", tx_address='1A01')
            ret = doip.send(b"\x22\xDD\x0A", tx_address='1A01')
            if ret < 0 or doip.re_msg.payload[-2:] != "01":
                doip.error_set("error active CEM")
                vs.RM("Active CEM", "NOK", testname="Active CEM")
            else:
                vs.RM("Active CEM", "OK", testname="Active CEM")
    except Exception as err:
        doip.log_message("error active CEM %s" % err)
        vs.RE("inActive CEM", "NOK", testname="inActive CEM")
        vs.RE("inActive CEM error", str(err), testname="inActive CEM")
    time.sleep(5)
    try:
        vs.m_message("Send 1FFF MESSAGE")
        vs.m_message("Wait 15s")
        try:
            ret = doip.send(b"\x31\x01\x02\x06", tx_address='1FFF')
        except Exception as err:
            pass
        try:
            ret = doip.send(b"\x10\x02", tx_address='1FFF')
        except Exception as err:
            pass

    except Exception as err:
        doip.log_message("error send IFFF message %s" % err)
        vs.RE("SEND 1FFF MESSAGE", "NOK", testname="inActive CEM")
Esempio n. 19
0
        def fun_info(*args, **kwargs):
            try:

                #Process=os.path.basename(__file__)
                #Phase=func.__name__
                VS.VARIABLE = {}
                VS.RM_VARIABLE = {}
                VS.SV("Process", process)
                VS.init_test_value()
                VS.RM("Process", process, "CAR_INFO")

                func(*args, **kwargs)
                SeqComplete = "True"
                VS.RM("SeqComplete", SeqComplete, "CAR_INFO")
            except Exception as err:
                SeqComplete = "False"
                VS.RE("ERROR", err, "CAR_INFO")
                VS.RM("SeqComplete", "Fail", "CAR_INFO")
                VS.m_message(str(err))
                return (1)
            try:
                logname = VS.GV('LOG_NAME')
                VS.RM("SeqComplete", SeqComplete, "CAR_INFO")
                FinishTime = datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
                VS.RM("FinishTime", FinishTime, "CAR_INFO")
                VS.save_all_result(logname)
                creat_vcats_xml(VS.RM_VARIABLE)
            except Exception as err:
                VS.m_message(str(err))
                return (1)
Esempio n. 20
0
def VBF_Read(file_path):
    aa = b""
    vbf_inf_dic = {}
    with open(file_path, 'rb') as f:
        #aa_data=f.read()
        aa_data_list = f.readlines()
        aa_data = b''.join(aa_data_list)
    if len(aa_data) > 4000:
        aa = aa_data[0:4000]
    else:
        aa = aa_data

    if aa.find(b'sw_signature') > 0:
        start_pose = aa.find(b'sw_signature')
    elif aa.find(b'sw_signature_dev') > 0:
        start_pose = aa.find(b'sw_signature_dev')
    elif aa.find(b'erase') > 0:
        start_pose = aa.find(b'erase')
    elif aa.find(b'file_checksum') > 0:
        start_pose = aa.find(b'file_checksum')
    elif aa.find(b'ecu_address') > 0:
        start_pose = aa.find(b'ecu_address')
    else:
        start_pose = 0

    if aa.find(b';\r\n}', start_pose) > 0:
        aa0 = aa.find(b';\r\n}', start_pose)
        end_pose = aa0 + 4
        aa1 = aa[0:aa0 + 3]
    elif aa.find(b';\n}', start_pose) > 0:
        aa0 = aa.find(b';\n}', start_pose)
        end_pose = aa0 + 3
        aa1 = aa[0:aa0 + 2]
    elif aa.find(b'\n}', start_pose) > 0:
        aa0 = aa.find(b'\n}', start_pose)
        end_pose = aa0 + 2
        aa1 = aa[0:aa0 + 1]
    elif aa.find(b'\r}', start_pose) > 0:
        aa0 = aa.find(b'\r}', start_pose)
        end_pose = aa0 + 2
        aa1 = aa[0:aa0 + 1]
    elif aa.find(b'}', start_pose) > 0:
        aa0 = aa.find(b'}', start_pose)
        end_pose = aa0 + 1
        aa1 = aa[0:aa0]
    else:
        error = "error format %s" % file_path
        raise Exception(error)
    vbf_hex_data = aa_data[end_pose:len(aa_data)]
    vbf_infor = aa1.split(b'\n')
    for value in vbf_infor:
        value = value.strip(b'\t').strip(b'\r').strip(b';').strip(b" ")
        if b'=' in value and b'//' not in value[0:4]:
            if b";" not in value:
                vbf_infor_0 = value.split(b"=")
                if len(vbf_infor_0) == 2:
                    vbf_inf_dic[vbf_infor_0[0].strip()] = vbf_infor_0[1].strip(
                        b" ").lstrip(b'"').rstrip(b'"')
                else:
                    error_str = "error format %s " % file_path
                    vs.m_message(error_str)

            else:
                aa2 = value.find(b";")
                value = value[0:aa2]
                vbf_infor_0 = value.split(b"=")
                if len(vbf_infor_0) == 2:
                    vbf_inf_dic[
                        vbf_infor_0[0].strip()] = vbf_infor_0[1].strip()
                else:
                    error_str = "error format %s " % file_path
                    vs.m_message(error_str)
    if b'erase' in vbf_inf_dic:
        pose0 = aa1.find(b'erase')
        pose0 = aa1.find(b'{', pose0)
        pose1 = aa1.find(b';', pose0)
        vbf_inf_dic[b'erase'] = aa1[pose0:pose1].replace(b'\n', b'').replace(
            b'\t', b'').replace(b' ', b'').replace(b'=', b'').replace(
                b'\r', b'').replace(b';', b'').strip(b'"')

    if b'sw_signature' in vbf_inf_dic:
        pose0 = aa1.find(b'sw_signature')
        pose0 = aa1.find(b'=', pose0) + 1
        pose1 = aa1.find(b';', pose0)
        vbf_inf_dic[b'sw_signature'] = aa1[pose0:pose1].replace(
            b'\n', b'').replace(b'\t', b'').replace(b' ', b'').replace(
                b'=', b'').replace(b'\r', b'').replace(b';', b'').strip(b'"')

    if b'sw_signature_dev' in vbf_inf_dic:
        pose0 = aa1.find(b'sw_signature_dev')
        pose0 = aa1.find(b'=', pose0) + 1
        pose1 = aa1.find(b';', pose0)
        vbf_inf_dic[b'sw_signature_dev'] = aa1[pose0 + 1:pose1].replace(
            b'\n', b'').replace(b'\t', b'').replace(b' ', b'').replace(
                b'=', b'').replace(b'\r', b'').replace(b';', b'').strip(b'"')

    vbf_inf_dic[b"hex_data"] = vbf_Read_hex_data_block(vbf_inf_dic,
                                                       vbf_hex_data, file_path)
    return vbf_inf_dic
Esempio n. 21
0
def read_br_vbf_path():
    global swdl_vf_path
    global swdl_vf_path_dic
    vf_path = vs.Config["proj_path"] + vs.Config["image"]["path"]
    vf_type = vs.Config["image"]["type"]
    vf_order = vs.Config["image"]["order"].split(',')
    vf_br_dic = vs.GV("SWDL_INFO")
    swdl_vf_path_dic = {}
    if str(vf_type) == "1":
        br_file_dic = vs.read_file_dic(vf_path, "VBF")
        for ecu in vf_order:
            if ecu in vf_br_dic:
                swdl_vf_list = vf_br_dic[ecu]
                if len(swdl_vf_list) <= 2: continue
                swdl_vf_path_dic[ecu] = []
                for vf in swdl_vf_list:
                    vf = vf.upper()
                    if vf in br_file_dic:
                        swdl_vf_path_dic[ecu].append(br_file_dic[vf])
                    else:
                        error_str = "error get soft download file %s " % vf
                        vs.m_message(error_str)
                del vf_br_dic[ecu]

        for ecu in vf_br_dic:
            swdl_vf_list = vf_br_dic[ecu]
            if len(swdl_vf_list) < 2: continue
            swdl_vf_path_dic[ecu] = []
            for vf in swdl_vf_list:
                vf = vf.upper()
                if vf in br_file_dic:
                    swdl_vf_path_dic[ecu].append(br_file_dic[vf])
                else:
                    error_str = "error get soft download file %s " % vf
                    vs.m_message(error_str)
    if str(vf_type) == "2":
        br_file_dic = vs.read_file_dic(vf_path, "")
        for ecu in vf_order:
            if ecu in vf_br_dic:
                swdl_vf_list = vf_br_dic[ecu]
                if len(swdl_vf_list) < 2: continue
                swdl_vf_path_dic[ecu] = []
                for vf in swdl_vf_list:
                    vf = vf.upper()
                    vaaf = vf + ".VBF"
                    vbbf = vf[:-3] + '.' + vf[-3:]
                    if vaaf in br_file_dic:
                        swdl_vf_path_dic[ecu].append(br_file_dic[vaaf])
                    elif vbbf in br_file_dic:
                        swdl_vf_path_dic[ecu].append(br_file_dic[vbbf])
                    else:
                        error_str = "error get soft download file %s " % vf
                        vs.m_message(error_str)
                del vf_br_dic[ecu]
        for ecu in vf_br_dic:
            swdl_vf_list = vf_br_dic[ecu]
            if len(swdl_vf_list) < 2: continue
            swdl_vf_path_dic[ecu] = []
            for vf in swdl_vf_list:
                vf = vf.upper()
                vaaf = vf + ".VBF"
                vbbf = vf[:-3] + '.' + vf[-3:]
                if vaaf in br_file_dic:
                    swdl_vf_path_dic[ecu].append(br_file_dic[vaaf])
                elif vbbf in br_file_dic:
                    swdl_vf_path_dic[ecu].append(br_file_dic[vbbf])
                else:
                    error_str = "error get soft download file %s " % vf
                    vs.m_message(error_str)
    vs.SV('swdl_vf_path_dic', swdl_vf_path_dic)
Esempio n. 22
0
 def init_UNIT_IN_TEST(self):
     self.v_json["UNIT_IN_TEST"]["@VIN"] = VS.GET_RM("VIN", "CAR_INFO")
     self.v_json["UNIT_IN_TEST"]["@BuildCode"] = VS.GET_RM(
         "BROADCAST", "CAR_INFO")
Esempio n. 23
0
def set_process_test(save_json):
    Tickcount = 1
    VS.RM("Status", "Pass", "CAR_INFO")
    process_tests_list = []
    process_test = {}
    for phase_info in save_json:
        if phase_info == 'System': continue
        for key in save_json[phase_info]:
            Tickcount = Tickcount + 1
            process_test = {}
            ###need  add Phase TestTime
            process_test["@Phase"] = phase_info
            process_test["@Test"] = key
            ###MABY update later
            process_test["@InCycleRetestNum"] = 1
            process_test["@StratRev"] = ""
            process_test["@TestTime"] = save_json[phase_info][key]["TestTime"]
            if "error_att" in save_json[phase_info][key]:
                process_test["@Status"] = "Fail"
                VS.RM("Status", "Fail", "CAR_INFO")
                process_test["FAULT_CODES"] = {}
                process_test["FAULT_CODES"]["FAULT_CODE"] = []
                for error_infos in save_json[phase_info][key]["error_att"]:
                    error_info_dic = {}
                    error_info_dic["@Status"] = "Fail"
                    error_info_dic["@Faultmode"] = "D"
                    error_info_dic["@FaultCode"] = "VC001"
                    error_info_dic["@CMID"] = "VCATS"
                    #aa=list(error_infos.keys())[0]
                    error_info_dic["@ShortDesc"] = error_infos + ' Nok'
                    error_info_dic["@Testtime"] = save_json[phase_info][key][
                        "error_att"][error_infos]['save_time']
                    error_info_dic["FAULT_ATTRIBUTES"] = {}
                    error_info_dic["FAULT_ATTRIBUTES"]["FAULT_ATTRIBUTE"] = {}
                    error_info_dic["FAULT_ATTRIBUTES"]["FAULT_ATTRIBUTE"][
                        "@Att"] = error_infos
                    error_info_dic["FAULT_ATTRIBUTES"]["FAULT_ATTRIBUTE"][
                        "@Val"] = save_json[phase_info][key]["error_att"][
                            error_infos][error_infos]
                    error_info_dic["FAULT_ATTRIBUTES"]["FAULT_ATTRIBUTE"][
                        "@Tickcount"] = str(Tickcount)
                    process_test["FAULT_CODES"]["FAULT_CODE"].append(
                        error_info_dic)
                    Tickcount = Tickcount + 1
            else:
                process_test["@Status"] = "Pass"
            process_test["@Latest"] = "1"
            if "save_att" in save_json[phase_info][key]:
                process_test["TEST_ATTRIBUTES"] = {}
                process_test["TEST_ATTRIBUTES"]["TEST_ATTRIBUTE"] = []
                for save_att in save_json[phase_info][key]["save_att"]:
                    save_att_dic = {}
                    save_att_dic["@Att"] = save_att
                    save_att_dic["@Val"] = save_json[phase_info][key][
                        "save_att"][save_att][save_att]
                    save_att_dic["@Tickcount"] = Tickcount
                    Tickcount = Tickcount + 1
                    process_test["TEST_ATTRIBUTES"]["TEST_ATTRIBUTE"].append(
                        save_att_dic)
            process_tests_list.append(process_test)
    return process_tests_list
Esempio n. 24
0
    import socket
    import fcntl
    import struct
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(fcntl.ioctl(
        s.fileno(),
        0x8915,  # SIOCGIFADDR
        struct.pack('256s', bytes(ifname[:15].encode('utf-8')))
    )[20:24])
 




if __name__ == '__main__':
    vs.read_config()

    #message='02FD8002000000051FFF0E8000'
    #message='02FD8003000000051A210E8003'
    #aa=DoIPMsg()
    #aa.UpdateMsg(message)
    logname='111122222'+time.strftime('%Y-%m-%d %H-%M-%S', time.localtime())
    doip=DoIP_Client(logname=logname)    
    #doip.Connect(car_address='169.254.92.237')
    doip.Connect()
    doip.keep_Routing_task()
    while(1):
        time.sleep(1)
        doip.send('1001',tx_address='1601')
        print("wait....")