Ejemplo n.º 1
0
        void sendThreading()
        {
            UInt64 delay;

            if (checkBoxRepeat.Checked == false)
            {
                for (int i = 0; i < SENDCOUNT; i++)
                {
                    usbCAN.sendFame(1, Convert.ToUInt32(i));
                    tx_pkgcounts++;
                    //TXCountsLabel.Text = "Tx:" + tx_pkgcounts;
                    Thread.Sleep(Convert.ToInt32(usbCAN.arrSendBuf[i].TimeStamp));
                }
            }
            else
            {
                while (true)
                {
                    for (int i = 0; i < SENDCOUNT; i++)
                    {
                        usbCAN.sendFame(1, Convert.ToUInt32(i));
                        tx_pkgcounts++;
                        for (delay = 0; delay < 200000; delay++)//确保约0.5ms间隔发包
                        {
                            ;
                        }
                        ///TXCountsLabel.Text = "Tx:" + tx_pkgcounts;//需要2ms
                        Thread.Sleep(Convert.ToInt32(usbCAN.arrSendBuf[i].TimeStamp));
                    }
                }
            }

            buttonSend.Invoke(new Action(() => { buttonSend.Enabled = true; }));
        }
Ejemplo n.º 2
0
 private void buttonSend_Click(object sender, EventArgs e)
 {
     fillSendBuf();
     if (checkBoxloop.Checked == false)
     {
         usbCAN.sendFame(1);
     }
     else
     {
         if (thread == null)
         {
             thread = new Thread(sendingThread);
             thread.Start();
         }
     }
 }
Ejemplo n.º 3
0
        unsafe void fuzzingThread(object objParm)
        {
            FUZZINGPARM      parm = (FUZZINGPARM)objParm;
            Form_ProgressBar form = parm.form;
            CAN_OBJ          obj  = parm.obj;
            int  delay            = parm.delay;
            byte index            = parm.index;
            byte min = parm.min;
            byte max = parm.max;
            int  rep = parm.rep;

            parm.mrEvent.WaitOne();

            usbCAN.arrSendBuf[0].ID         = obj.ID;
            usbCAN.arrSendBuf[0].DataLen    = obj.DataLen;
            usbCAN.arrSendBuf[0].ExternFlag = obj.ExternFlag;
            usbCAN.arrSendBuf[0].RemoteFlag = obj.RemoteFlag;
            for (int d = 0; d < 8; d++)
            {
                usbCAN.arrSendBuf[0].Data[d] = obj.Data[d];
            }

            for (int i = min; i <= max; i++)
            {
                for (int t = 0; t < rep; t++)
                {
                    usbCAN.arrSendBuf[0].Data[index] = (byte)i;
                    usbCAN.sendFame(1);
                    Thread.Sleep(delay);
                }

                form.addValue();
            }

            form.returnResult = DialogResult.OK;
            form.Invoke(new Action(() => { form.Close(); }));
        }
        private void buttonStart_Click(object sender, EventArgs e)
        {
            int pointCount = 0;

            try { pointCount = Convert.ToInt32(textBoxPointCount.Text); }
            catch (Exception) { MessageBox.Show("请指定收集点个数"); return; }

            int udsInterval = 0;

            try { udsInterval = Convert.ToInt32(textBoxUdsInterval.Text); }
            catch (Exception) { MessageBox.Show("请指定指令发送间隔"); return; }
            //
            richTextBoxLog.Text    = "";
            buttonEnd.Enabled      = true;
            buttonStart.Enabled    = false;
            groupBoxResult.Enabled = false;
            rawPacket.Clear();
            hasGetUds = false;
            DateTime prev;

            for (int reqIndex = 0; reqIndex < listRequests.Count; reqIndex++)
            {
                if (usbCAN.startDevice() == false)
                {
                    goto endProcess;
                }

                udsCAN.createService(listRequests[reqIndex]);
                for (int cnt = pointCount; cnt > 0;)
                {
                    for (int reTry = 0; reTry < 10 && wantTerminate == false; reTry++)
                    {
                        prev = DateTime.Now;
                        while ((DateTime.Now - prev).TotalMilliseconds < DELAY)
                        {
                            Application.DoEvents();
                        }

                        hasGetUds = false;
                        usbCAN.sendFame(1);

                        prev = DateTime.Now;
                        while (hasGetUds == false && (DateTime.Now - prev).TotalMilliseconds < 1200)
                        {
                            Application.DoEvents();
                        }
                        if (hasGetUds == false)
                        {
                            continue;
                        }

                        break;
                    }

                    if (wantTerminate)
                    {
                        goto endProcess;
                    }

                    if (hasGetUds == false)
                    {
                        richTextBoxLog.AppendText("超时,请检查设备\n");
                    }
                    else
                    {
                        cnt--;
                        richTextBoxLog.AppendText(listRequests[reqIndex].description + ":剩余点个数 " + cnt.ToString() + "\n");
                    }

                    prev = DateTime.Now;
                    while ((DateTime.Now - prev).TotalMilliseconds < udsInterval)
                    {
                        Application.DoEvents();
                    }
                }

                //保存文件
                if (usbCAN.shutDevice() == false)
                {
                    goto endProcess;
                }

                string   path = Application.StartupPath + @"\dataPacket\";
                TimeSpan ts   = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
                path += listRequests[reqIndex].description + Convert.ToUInt64(ts.TotalSeconds).ToString();
                FileStream   file = new FileStream(path, FileMode.Create);
                StreamWriter sw   = new StreamWriter(file);

                string line;
                for (int i = 0; i < rawPacket.Count; i++)
                {
                    line  = rawPacket[i].ID.ToString("X2") + " ";
                    line += rawPacket[i].DataLen.ToString() + " ";
                    for (int d = 0; d < rawPacket[i].DataLen; d++)
                    {
                        line += rawPacket[i].Data[d].ToString("X2") + " ";
                    }

                    sw.WriteLine(line);
                }

                sw.Close();
                file.Close();

                ANALYSISRESULT result = new ANALYSISRESULT();
                result.udsReq = listRequests[reqIndex];
                result.path   = path;
                analysisResults.Add(result);
                listBoxResult.Items.Add(result.udsReq.description);
            }

endProcess:
            buttonEnd.Enabled      = false;
            buttonStart.Enabled    = true;
            groupBoxResult.Enabled = true;
            wantTerminate          = false;
        }
Ejemplo n.º 5
0
        /*---------------------------------------------------------------------------------------------------*/
        unsafe public void udsProcess(ref VCI_CAN_OBJ canObj)
        {
            int  size, d;
            byte tpType = (byte)(canObj.Data[0] >> 4);

            if (tpType == FIRSTFRAME) //首帧
            {
                if (expectedReturnIsFirstFrame == false)
                {
                    return;
                }

                //回应流量控制帧
                usbCAN.arrSendBuf[0].ID         = udsCaller.address;
                usbCAN.arrSendBuf[0].ExternFlag = udsCaller.format;
                usbCAN.arrSendBuf[0].RemoteFlag = 0;
                usbCAN.arrSendBuf[0].SendType   = 1;

                usbCAN.arrSendBuf[0].DataLen = 3;
                usbCAN.arrSendBuf[0].Data[0] = 0x30;
                usbCAN.arrSendBuf[0].Data[1] = 0x00;
                usbCAN.arrSendBuf[0].Data[2] = 0x7f;
                usbCAN.sendFame(1);

                //
                responseListForMultiFrameExpected.respAddress = canObj.ID;
                size = canObj.Data[0] & 0x0f;
                size = (size << 8) + canObj.Data[1];

                for (d = 2; d < 8; d++)
                {
                    responseListForMultiFrameExpected.responseList.Add(canObj.Data[d]);
                }
                responseListForMultiFrameExpected.remainingReceivingLength = size - 6;

                responseListForMultiFrameExpected.expectedIndex = 1;
                expectedReturnIsFirstFrame       = false;
                expectedReturnIsConsecutiveFrame = true;
            }
            else if (tpType == CONSECUTIVEFRAME)
            {
                if (expectedReturnIsConsecutiveFrame == false)
                {
                    return;
                }

                int seq = canObj.Data[0] & 0x0f;
                if (seq != responseListForMultiFrameExpected.expectedIndex)
                {
                    responseListForMultiFrameExpected.errorCode = UDSResponseList.ERRORCODE.EXPECTEDINDEX;
                    return;
                }

                size = responseListForMultiFrameExpected.remainingReceivingLength;
                for (d = 1; d < 8 && size > 0; d++, size--)
                {
                    responseListForMultiFrameExpected.responseList.Add(canObj.Data[d]);
                }

                responseListForMultiFrameExpected.remainingReceivingLength = size;
                if (size == 0)
                {
                    expectedReturnIsConsecutiveFrame = false;
                }
                else
                {
                    responseListForMultiFrameExpected.expectedIndex = (responseListForMultiFrameExpected.expectedIndex + 1) % 16;
                }
            }
            else if (tpType == SINGLEFRAME)
            {
                if (expectedReturnIsSingleFrame == false)
                {
                    return;
                }

                responseListForSingleFrameExpected.respAddress = canObj.ID;

                size = canObj.Data[0] & 0x0f;
                for (d = 1; size > 0 && d < 8; size--, d++)
                {
                    responseListForSingleFrameExpected.responseList.Add(canObj.Data[d]);
                }

                expectedReturnIsSingleFrame = false;
            }
        }