tao_z
2022-05-16 7b93ce7d3c07dc8d60dacbd4ab76651882f4d92b
使用PIPE前存储
3 files modified
86 ■■■■ changed files
USBCAN.py 16 ●●●● patch | view | raw | blame | history
test.py 7 ●●●●● patch | view | raw | blame | history
widgets/ShifterTool.py 63 ●●●● patch | view | raw | blame | history
USBCAN.py
@@ -369,13 +369,13 @@
        # extern_flag = 1 if msg.is_extended_id else 0
        # extern_flag = 0
        raw_message = VCI_CAN_OBJ()
        raw_message.ID = msg.arbitration_id
        raw_message.TimeStamp = 0
        raw_message.TimeFlag = 0
        raw_message.SendType = 1
        raw_message.RemoteFlag = msg.is_remote_frame
        raw_message.ExternFlag = msg.is_extended_id
        raw_message.DataLen = msg.dlc
        raw_message.ID = (c_uint)(msg.arbitration_id)
        raw_message.TimeStamp = (c_uint)(0)
        raw_message.TimeFlag = (c_ubyte)(0)
        raw_message.SendType = (c_ubyte)(1)
        raw_message.RemoteFlag = (c_ubyte)(msg.is_remote_frame)
        raw_message.ExternFlag = (c_ubyte)(msg.is_extended_id)
        raw_message.DataLen = (c_ubyte)(msg.dlc)
        raw_message.Data = (c_ubyte * 8)(* [c_ubyte(c) for c in msg.data])
        # (msg.arbitration_id, 0, 0, 1, msg.is_remote_frame,
@@ -427,7 +427,7 @@
                for i in range(msgToSendCnt):
                    msg = sendQueue.get()
                    self.send(msg, 1)
            time.sleep(0.001)
                    time.sleep(0.001)
            loopCnt += 1
            if loopCnt >= 15:
                loopCnt = 0
test.py
@@ -49,7 +49,7 @@
    is_remote_frame=0,
    channel=0,
    dlc=8,
    data=bytearray(0x02, 0x3e, 0, 0, 0, 0, 0, 0),
    data=bytearray([0x02, 0x3e, 0, 0, 0, 0, 0, 0])
)
@@ -110,7 +110,7 @@
def tx_task(bus: USBCAN):
    while True:
        bus.Transmit(device_type, device_index, can_channel, msg=msg, len=1)
        bus.send(msg=msg)
        time.sleep(0.1)
@@ -121,7 +121,8 @@
        if not num == 0:
            for i in range(num):
                if msg[i].arbitration_id == 0x77a:
                    print(msg[i].arbitration_id)
                    # print(formatedata(i, msg[i], True))
                    print(msg[i].data)
if __name__ == '__main__':
widgets/ShifterTool.py
@@ -1,4 +1,5 @@
from ast import Pass
import threading
from can import BusABC, Message
from udsoncan.client import Client
@@ -42,6 +43,9 @@
class UISignals(QtCore.QObject):
    sig_Disp_str = QtCore.Signal(str)
    sig_MsgReceived = QtCore.Signal(int)
g_signal = UISignals()
class HardwreDevice():
@@ -196,7 +200,7 @@
                    #     self.IsoTPtoUDSQueue.qsize()))
                    # time.sleep(self.isotp_layer.sleep_time())
                    time.sleep(0.0001)
                    time.sleep(0.001)
                except Exception as e:
                    self.exit_requested = True
@@ -212,7 +216,6 @@
        # self.protocol("WM_DELETE_WINDOW", self.Form_OnClosing)
        self.msgQueue = Queue()  # can layer receive queue
        self.sendQueue = Queue()  # can layer send queue
        self.signal = UISignals()
        self.shifter = ShifterClass()
        self.devicedescription = HardwreDevice()
@@ -221,7 +224,8 @@
        self.UI.setupUi(window)
        self._dev_info = None
        self.can_thread = threading.Thread(target=self.can_thread)
        self.TestPresentTimer = QtCore.QTimer()
        self.TestPresentTimer.timeout.connect(self.creat_testpresentReq)
        self.DeviceInit()
        self.WidgetsInit()
        self.ChnInfoUpdate(self._isOpen)
@@ -361,7 +365,8 @@
        msg = Message()
        msg.arbitration_id = isotp_msg.arbitration_id
        msg.dlc = isotp_msg.dlc
        msg.data = isotp_msg.data
        msg.channel = 0
        msg.data = isotp_msg.data  # bytearray
        msg.is_extended_id = False
        # for i in range(isotp_msg.dlc):
        #     msg.data[i] = isotp_msg.data[i]
@@ -383,15 +388,21 @@
        self.UI.comboBox_3.activated.connect(self.update_HardwareDevice)
        self.UI.comboBox_5.activated.connect(self.update_HardwareDevice)
        self.signal.sig_Disp_str.connect(self.disp_string)
        self.signal.sig_MsgReceived.connect(self._updateRootList)
        g_signal.sig_Disp_str.connect(self.disp_string)
        g_signal.sig_MsgReceived.connect(self._updateRootList)
        self.initUDSUI()
    def initUDSUI(self):
        self.UI.comboBox.addItems(['0x01默认模式', '0x02编程模式', '0x03编程模式'])
        self.UI.comboBox.addItems(['0x01默认模式', '0x02编程模式', '0x03扩展模式'])
        self.UI.comboBox.activated.connect(self.sessioncontrol_req)
        self.UI.comboBox_8.addItems(['0x01硬件复位', '0x03软件复位'])
        self.UI.comboBox_8.activated.connect(self.MCUReset_req)
        self.UI.comboBox_9.addItems(['0x00使能收发', '0x01能收禁发', '0x03禁止收发'])
        self.UI.comboBox_9.activated.connect(self.communicationControl_req)
        self.UI.radioButton.toggled.connect(self.TestPresentEvent)
    def _formatMsgData(self, index, item, received):
@@ -452,17 +463,17 @@
                                msg[i])  # send msg to isotp
                        self.msgQueue.put(msg[i])
                        # send signal to update screen
                    logger.info('Rx: ID=0x{:0<3x} '.format(msg[i].arbitration_id) + ' '.join(['0x' +
                                                                                              '{:0<2x}'.format(a).upper() for a in list(msg[i].data)]))
                    self.signal.sig_MsgReceived.emit(num)
                    # logger.info('Rx: ID=0x{:0<3x} '.format(msg[i].arbitration_id) + ' '.join(['0x' +
                    #                                                                           '{:0<2x}'.format(a).upper() for a in list(msg[i].data)]))
                    g_signal.sig_MsgReceived.emit(num)
                msgToSendCnt = self.sendQueue.qsize()
                if msgToSendCnt > 0:
                    msg = Message()
                    for i in range(msgToSendCnt):
                        msg = self.sendQueue.get()
                        logger.info('Tx: ID=0x{:0<3x} '.format(
                            msg.arbitration_id)+'DLC={} '.format(msg.dlc)+'externd flag ={} '.format(msg.is_extended_id)+'remote frame:{} '.format(msg.is_remote_frame))
                        # logger.info('Tx: ID=0x{:0<3x} '.format(
                        #     msg.arbitration_id)+'DLC={} '.format(msg.dlc)+'externd flag ={} '.format(msg.is_extended_id)+'remote frame:{} '.format(msg.is_remote_frame))
                        self._usbcan.send(msg)
    def open_close(self):
@@ -554,4 +565,32 @@
        pass
    def TestPresentEvent(self):
        if self.UI.radioButton.isChecked():
            self.TestPresentTimer.start(4000)
        else:
            self.TestPresentTimer.stop()
    def creat_testpresentReq(self):
        self.udsclient.tester_present()
    def sessioncontrol_req(self):
        sesson = self.UI.comboBox.currentIndex() + 1
        self.udsclient.change_session(sesson)
    # self.UI.comboBox_8.addItems(['0x01硬件复位', '0x03软件复位'])
    def MCUReset_req(self):
        req = 0x03 if self.UI.comboBox_8.currentData() == '0x01硬件复位' else 0x01
        self.udsclient.ecu_reset(req)
        # self.UI.comboBox_9.addItems(['0x00使能收发', '0x01能收禁发', '0x03禁止收发'])
    def communicationControl_req(self):
        req = 0x00
        select = self.UI.comboBox_9.currentData()
        if select == '0x00使能收发':
            req = 0
        elif select == '0x01能收禁发':
            req = 1
        else:
            req = 3
        self.udsclient.communication_control(
            control_type=0, communication_type=req)