//*******************************************
        // The worker thread for the backgroundWorker
        //*******************************************
        private void backgroundWorkerRead_DoWork(object sender, DoWorkEventArgs e)
        {
            int count = 0;
            CanData receiveCan = new CanData();
            CanData transmitCan = new CanData();

            string[] arguments = (string[])e.Argument;

            // to get the receive interface
            receiveCan.hardware = arguments[0];
            receiveCan.format = arguments[1];

            // to get the transmit interface
            transmitCan.hardware = arguments[4];
            transmitCan.format = arguments[1];

            string CarFilter = arguments[2];
            int numericMSB = int.Parse(arguments[3]);
            string ifThenOutput = null;

            while (true)
            {
                if (GenericCanBus.GenericCanReceive(receiveCan) == true)
                {
                    count++; //counts the number of packets received
                    (sender as BackgroundWorker).ReportProgress(count, CommonUtils.ConvertMsgArray(receiveCan, CarFilter, numericMSB));

                    if (IfThenActive)
                    {
                        //   ifThenOutput = ifthenxml.UpdateIfThenMachine(receiveCan, CarFilter);

                        if (ifThenOutput != null)
                        {
                            CommonUtils.ConvertStringtoCAN(transmitCan, ifThenOutput);
                            GenericCanBus.GenericCanTransmitSingle(transmitCan);
                        }
                    }
                }

                System.Threading.Thread.Sleep(80);

                if ((sender as BackgroundWorker).CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
            }
        }
        // The worker thread for the backgroundWorker
        private void backgroundWorkerTester_DoWork_1(object sender, DoWorkEventArgs e)
        {
            //MainWindow.ErrorDisplayString("In Tester Present Loop");

            CanData can = new CanData();

            // TesterPresentID.Text, TesterPresentDLC.Text, TesterPresentMessage.Text, TransmitInterfaceBox.SelectedItem.ToString(), TimeBetween.Text
            string[] arguments = (string[])e.Argument;

            can.format = "hex";
            can.id = Convert.ToInt32(arguments[0], 16);
            can.dlc = Convert.ToInt32(arguments[1]);
            can.msg = CommonUtils.HexStringToByteArray(arguments[2]);
            can.hardware = arguments[3];

            while (true)
            {
                GenericCanBus.GenericCanTransmitSingle(can);
                System.Threading.Thread.Sleep(Convert.ToInt32(arguments[4]));

                if ((sender as BackgroundWorker).CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
            }
        }
        //************************************
        //Send fuzzed selected packet over the network
        //written by Parnian Najafi Borazjani
        //************************************
        private void TransmitFuzz_Click_1(object sender, EventArgs e)
        {
            CanData can = new CanData();
            string msgOutput = "";

            if (dataGridView1.SelectedRows.Count > 0 && dataGridView1.SelectedRows[0] != null)
            {

                if (dataGridView1.SelectedRows[0].Cells[1].Value == null)
                    return;
                if (!(String.IsNullOrEmpty(dataGridView1.SelectedRows[0].Cells[1].Value.ToString()))) //ID
                    msgOutput = dataGridView1.SelectedRows[0].Cells[1].Value.ToString() + ";";
                if (!(String.IsNullOrEmpty(dataGridView1.SelectedRows[0].Cells[4].Value.ToString()))) //DLC
                    msgOutput += dataGridView1.SelectedRows[0].Cells[4].Value.ToString() + ";";

                if (!(String.IsNullOrEmpty(dataGridView1.SelectedRows[0].Cells[5].Value.ToString()))) //flag
                    msgOutput += dataGridView1.SelectedRows[0].Cells[5].Value.ToString() + ";";
                else
                    msgOutput += "S" + ";";

                if (Monitor_Hex.Checked == true)
                {
                    can.format = "hex";
                    msgOutput += dataGridView1.SelectedRows[0].Cells[2].Value.ToString().Replace(" ", string.Empty);
                }
                else
                {
                    can.format = "decimal";
                    msgOutput += dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                }

                ////put for testing
                // MessageBox.Show("Data to convert:" + msgOutput);
                CommonUtils.ConvertStringtoCAN(can, msgOutput); //added

                can.hardware = TransmitInterfaceBox.SelectedItem.ToString();

                // Verbose Output
                //if (VerboseTransmit.Checked == true)
                //    MessageBox.Show(CommonUtils.DisplayMsg(can));

            }

            TransmitPackets tp = new TransmitPackets();

            tp.ShowForm(can);
            tp.MdiParent = MainWindow.ActiveForm;
            tp.Show();
        }
        //************************************
        //Send selected packet over the network
        //written by Parnian Najafi Borazjani
        //************************************
        private void TransmitPackets2_Click_1(object sender, EventArgs e)
        {
            CanData can = new CanData();
            string msgOutput = "";

            if (dataGridView1.SelectedRows.Count > 0 && dataGridView1.SelectedRows[0] != null)
            {
                if (dataGridView1.SelectedRows[0].Cells[1].Value == null)
                    return;
                if (!(String.IsNullOrEmpty(dataGridView1.SelectedRows[0].Cells[1].Value.ToString()))) //ID
                    msgOutput = dataGridView1.SelectedRows[0].Cells[1].Value.ToString() + ";";
                if (!(String.IsNullOrEmpty(dataGridView1.SelectedRows[0].Cells[4].Value.ToString()))) //DLC
                    msgOutput += dataGridView1.SelectedRows[0].Cells[4].Value.ToString() + ";";

                if (!(String.IsNullOrEmpty(dataGridView1.SelectedRows[0].Cells[5].Value.ToString()))) //flag
                    msgOutput += dataGridView1.SelectedRows[0].Cells[5].Value.ToString() + ";";
                else
                    msgOutput += "S" + ";";

                if (Monitor_Hex.Checked == true)
                {
                    can.format = "hex";
                    msgOutput += dataGridView1.SelectedRows[0].Cells[2].Value.ToString().Replace(" ", string.Empty);
                }
                else
                {
                    can.format = "decimal";
                    msgOutput += dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                }

                ////put for testing
                // MessageBox.Show("Data to convert:" + msgOutput);
                CommonUtils.ConvertStringtoCAN(can, msgOutput); //added

                can.hardware = TransmitInterfaceBox.SelectedItem.ToString();

                //bgTransmit.RunWorkerAsync(can);
                GenericCanBus.GenericCanTransmitSingle(can);

                ////            // Verbose Output
                ////            if (VerboseTransmit.Checked == true)
                ////                MessageBox.Show(CommonUtils.DisplayMsg(can));
                ////        }
                ////    }

                // Status Update
                toolStripStatusLabel2.Text = CommonUtils.ErrorMsg("Transmit Message", can.status);
                ErrorLog.NewLogEntry("CAN", "Transmit Message: " + can.status);
                FileLog.Log("CAN Transmit Message: " + can.status);

            }
        }
        // Updates the if then machine based on received message
        public string UpdateIfThenMachine(CanData can, string cartype)
        {
            // setups the can information for string comparison to the XML
            string stringid = String.Format("{0:X}", can.id);
            string stringmsg = CommonUtils.ConvertMsgtoString(can.msg, can.dlc);

            // Cycles through the dictionary of ifthens
            foreach (KeyValuePair<string, State> pair in IfThenPackets)
            {
                // if in the if state then proceed with message matching
                if (pair.Value == State.If)
                {
                   // MainWindow.ErrorDisplayString("In Update IfThen: dictionary -- " + pair.Key);

                    // compares can message in xml to received can message
                    try
                    {
                        XElement carElement = XElement.Load(ConfigFiles.Settings1.Default.filterURI);

                        // Error Checking -- very clunky; needs revisions
                        if (carElement.Descendants("CarType").Where(e2 => e2.Element("CarName").Value.Equals(cartype)).FirstOrDefault() == null)
                            return null;
                        var cartypeElement = carElement.Descendants("CarType").Where(e2 => e2.Element("CarName").Value.Equals(cartype)).FirstOrDefault();
                        //MainWindow.ErrorDisplayString("1:" + cartypeElement.ToString());

                        // ************************
                        // Needs to cycle through all of the If thens so that the if and thens can be properly synced together
                        // ************************

                        // Error Checking -- very clunky; needs revisions
                        if (cartypeElement.Elements("IFTHEN").Where(e2 => e2.Element("Name").Value.Equals(pair.Key, StringComparison.OrdinalIgnoreCase)).FirstOrDefault() == null)
                            return null;
                        var ifthenElement = cartypeElement.Elements("IFTHEN").Where(e2 => e2.Element("Name").Value.Equals(pair.Key, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                        //MainWindow.ErrorDisplayString("2:" + ifthenElement.ToString());

                        if (ifthenElement.Elements("If") == null)
                            return null;
                        var packetElement = ifthenElement.Elements("If");
                        //MainWindow.ErrorDisplayString("3:" + packetElement.ToString());

                        if (packetElement.Elements("Packet").Where(e3 => e3.Element("Message").Value.Equals(stringmsg, StringComparison.OrdinalIgnoreCase)
            && e3.Element("ID").Value.Equals(stringid, StringComparison.OrdinalIgnoreCase)).FirstOrDefault() != null)
                        {
                            var msgElement = packetElement.Elements("Packet").Where(e3 => e3.Element("Message").Value.Equals(stringmsg, StringComparison.OrdinalIgnoreCase)
                                    && e3.Element("ID").Value.Equals(stringid, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                            if (ifthenElement.Elements("Then") == null)
                                return null;
                            var responseElement = ifthenElement.Elements("Then");

                            if (responseElement.Elements("Packet") == null)
                                return null;
                            //var responsePacketElement = responseElement.Descendants("Packet");
                            var responsePacketElement = responseElement.Elements("Packet").FirstOrDefault();

                            return (string)responsePacketElement.Element("ID") + ";"
                                + (string)responsePacketElement.Element("DLC") + ";"
                                + (string)responsePacketElement.Element("Flag") + ";"
                                + (string)responsePacketElement.Element("Message");

                        }

                        return null;

                    }
                    //catch (FileNotFoundException)
                    catch (Exception)
                    {
                        ErrorLog.NewLogEntry("Filter", "URI filename not found");
                        return null;
                    }

                }
            }

            return null;
        }
        // Updates the if then machine based on received message
        public string UpdateIfThenMachine(CanData can, string cartype)
        {
            // setups the can information for string comparison to the XML
            string stringid  = String.Format("{0:X}", can.id);
            string stringmsg = CommonUtils.ConvertMsgtoString(can.msg, can.dlc);

            // Cycles through the dictionary of ifthens
            foreach (KeyValuePair <string, State> pair in IfThenPackets)
            {
                // if in the if state then proceed with message matching
                if (pair.Value == State.If)
                {
                    // MainWindow.ErrorDisplayString("In Update IfThen: dictionary -- " + pair.Key);

                    // compares can message in xml to received can message
                    try
                    {
                        XElement carElement = XElement.Load(ConfigFiles.Settings1.Default.filterURI);

                        // Error Checking -- very clunky; needs revisions
                        if (carElement.Descendants("CarType").Where(e2 => e2.Element("CarName").Value.Equals(cartype)).FirstOrDefault() == null)
                        {
                            return(null);
                        }
                        var cartypeElement = carElement.Descendants("CarType").Where(e2 => e2.Element("CarName").Value.Equals(cartype)).FirstOrDefault();
                        //MainWindow.ErrorDisplayString("1:" + cartypeElement.ToString());


                        // ************************
                        // Needs to cycle through all of the If thens so that the if and thens can be properly synced together
                        // ************************


                        // Error Checking -- very clunky; needs revisions
                        if (cartypeElement.Elements("IFTHEN").Where(e2 => e2.Element("Name").Value.Equals(pair.Key, StringComparison.OrdinalIgnoreCase)).FirstOrDefault() == null)
                        {
                            return(null);
                        }
                        var ifthenElement = cartypeElement.Elements("IFTHEN").Where(e2 => e2.Element("Name").Value.Equals(pair.Key, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                        //MainWindow.ErrorDisplayString("2:" + ifthenElement.ToString());

                        if (ifthenElement.Elements("If") == null)
                        {
                            return(null);
                        }
                        var packetElement = ifthenElement.Elements("If");
                        //MainWindow.ErrorDisplayString("3:" + packetElement.ToString());

                        if (packetElement.Elements("Packet").Where(e3 => e3.Element("Message").Value.Equals(stringmsg, StringComparison.OrdinalIgnoreCase) &&
                                                                   e3.Element("ID").Value.Equals(stringid, StringComparison.OrdinalIgnoreCase)).FirstOrDefault() != null)
                        {
                            var msgElement = packetElement.Elements("Packet").Where(e3 => e3.Element("Message").Value.Equals(stringmsg, StringComparison.OrdinalIgnoreCase) &&
                                                                                    e3.Element("ID").Value.Equals(stringid, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();


                            if (ifthenElement.Elements("Then") == null)
                            {
                                return(null);
                            }
                            var responseElement = ifthenElement.Elements("Then");

                            if (responseElement.Elements("Packet") == null)
                            {
                                return(null);
                            }
                            //var responsePacketElement = responseElement.Descendants("Packet");
                            var responsePacketElement = responseElement.Elements("Packet").FirstOrDefault();

                            return((string)responsePacketElement.Element("ID") + ";"
                                   + (string)responsePacketElement.Element("DLC") + ";"
                                   + (string)responsePacketElement.Element("Flag") + ";"
                                   + (string)responsePacketElement.Element("Message"));
                        }

                        return(null);
                    }
                    //catch (FileNotFoundException)
                    catch (Exception)
                    {
                        ErrorLog.NewLogEntry("Filter", "URI filename not found");
                        return(null);
                    }
                }
            }

            return(null);
        }
示例#7
0
        //private void ShowMessbutton_Click(object sender, EventArgs e)
        //{
        //    #region
        //    /*for (int i = 0; i < 10; i++)   //添加10行数据
        //    {
        //        ListViewItem lvi = new ListViewItem();

        //        //lvi.ImageIndex = i;     //通过与imageList绑定,显示imageList中第i项图标

        //        lvi.Text = "subitem" + i; //第一列

        //        lvi.SubItems.Add("第2列,第" + i + "行");

        //        lvi.SubItems.Add("第3列,第" + i + "行");

        //        CanMesslistView.Items.Add(lvi);
        //    }*/
        //    #endregion

        //    Analysis ay = new Analysis();
        //    List<string> Cangets = new List<string>();
        //    Cangets.Add("t8561122334455667788");

        //    flushMesslist(Cangets,0);
        //    textBox1.Text = "tttttttt";
        //}

        public void flushMesslist(List <string> Cangets, int flushtype)
        {
            #region
            //CanMesslistView.Clear();
            //CanMesslistView.Items.Clear();

            //string Canget = "t8561122334455667788\r";

            /*foreach (string Canget in Cangets) //此处疑似有重复
             * {
             *  ListViewItem listv = new ListViewItem();
             *  listv.Text = Canget;
             *  CanMesslistView.Items.Add(listv);
             * }*/
            #endregion

            Analysis ay = new Analysis();
            foreach (string Canget in Cangets)
            {
                if (string.Equals("t", Canget.Substring(0, 1)) || string.Equals("T", Canget.Substring(0, 1)))
                {
                    //ArrayList pList = new ArrayList();
                    //string idnumber= ay.get16IDNumber(Canget);
                    TreeCanInfo Tcinfo = new TreeCanInfo();
                    string      thisid = ay.convert16to10(ay.get16IDNumber(Canget));
                    Tcinfo.ID   = thisid;
                    Tcinfo.Name = ay.getCanMessName(thisid);
                    Tcinfo.DLC  = ay.getDLC(Canget);
                    Tcinfo.Data = ay.getData(Canget);

                    foreach (string CanData in ay.canReceiptAnalysis(Canget))
                    {
                        string[] Data = CanData.Split(',');
                        //Console.WriteLine(Data[0] + "----------" + Data[1]);
                        ListViewItem listv = new ListViewItem();
                        listv.Text = Data[0];        //第一列
                        listv.SubItems.Add(Data[1]); //没有报错提示
                        CanMesslistView.Items.Add(listv);
                        Tcinfo.block.Add(Data[0] + " " + Data[1]);
                        //textBox1.Text = Data[0];
                        #region
                        //增加ID Name Dir DLC Data


                        /*ListTree2 rottree1 = new ListTree2();
                         * rottree1.ParentID = idnumber;
                         * rottree1.GetID = ay.get16IDNumber(Canget);
                         * rottree1.GetName = "stand";
                         * rottree1.DLC = ay.getDLC(Canget);
                         * rottree1.GetData = ay.getData(Canget);
                         * pList.Add(rottree1);*/

                        /*int i = 0, t = 0;
                         * ArrayList pList = new ArrayList();
                         * List<string> CanAllInfos = ay.getCanAllInfoFromDatabase();
                         * foreach (string CanAllInfo in CanAllInfos)
                         * {
                         *  string[] canblock = CanAllInfo.Split(' ');
                         *  ListTree2 p = new ListTree2();
                         *  p.GetID = i;
                         *  t = i;
                         *  i++;
                         *  p.GetName = canblock[0] + canblock[1];
                         *  pList.Add(p);
                         *  for (int j = 2; j < canblock.Length; j++)
                         *  {
                         *      ListTree2 q = new ListTree2();
                         *      q.ParentID = t;
                         *      q.GetID = i;
                         *      i++;
                         *      q.GetName = canblock[j];
                         *      pList.Add(q);
                         *  }
                         * }
                         * this.treeList1.DataSource = pList;
                         * this.treeList1.RefreshDataSource();
                         */
                        #endregion
                    }
                    #region

                    //ArrayList pList = new ArrayList();

                    /*ListTree2 rottree = new ListTree2();
                     * rottree.GetID = ay.get16IDNumber(Canget);
                     * rottree.GetName = "stand";
                     * rottree.DLC = ay.getDLC(Canget);
                     * rottree.GetData = ay.getData(Canget);
                     * pList.Add(rottree);
                     * this.treeList2.DataSource = pList;
                     * this.treeList2.RefreshDataSource();
                     * pList.Clear();*/
                    #endregion
                    if (hshTable.Contains(thisid))
                    {
                        hshTable.Remove(thisid);  //删除旧数据
                    }
                    hshTable.Add(thisid, Tcinfo); //在hashtable中放入ID DLC Data 器件name phy
                }
                else
                {
                    ListViewItem listv = new ListViewItem();
                    listv.Text = Canget;
                    CanMesslistView.Items.Add(listv);
                }
            }

            //textBox1.Text = "***************";
        }
示例#8
0
        public void flushf3test(List <string> Cangets, int flushtype, Form3 f3) //flushtype无效
        {
            Analysis      ay = new Analysis();
            List <string> AnalysisOK;

            foreach (string Canget in Cangets)
            {
                if (string.Equals("t", Canget.Substring(0, 1)) || string.Equals("T", Canget.Substring(0, 1)))
                {
                    AnalysisOK = ay.canReceiptAnalysis(Canget);
                    foreach (string CanData in AnalysisOK)
                    {
                        string[] Data = CanData.Split(',');
                        //Console.WriteLine(Data[0] + "----------" + Data[1]);
                        ListViewItem listv = new ListViewItem();
                        listv.Text = Data[0];        //第一列
                        listv.SubItems.Add(Data[1]); //没有报错提示

                        //Data[1]是数值
                        CanMesslistView.Items.Add(listv);


                        //给出选择的器件序号


                        //找出器件的值


                        //刷新LED


                        //ay.getCanAllInfoFromDatabase();
                        //f3.changeLED("10,000");
                    }

                    if (f3 != null)
                    {
                        List <string> retCanIDandlocal = f3.retCanIDandlocal;

                        string anaresultID = Canget;

                        int IDlen = 3;
                        if (string.Equals(anaresultID.Substring(0, 1), "t")) //标准帧
                        {
                            IDlen = 3;
                        }
                        else if (string.Equals(anaresultID.Substring(0, 1), "T")) //扩展帧
                        {
                            IDlen = 8;
                        }
                        anaresultID = Canget.Substring(1, IDlen);
                        anaresultID = (Int32.Parse(anaresultID, System.Globalization.NumberStyles.HexNumber)).ToString(); //16转10进制
                                                                                                                          //判断是否在选中的ID中
                        foreach (string Canselected in retCanIDandlocal)
                        {
                            string[] Canblock = Canselected.Split(' ');
                            if (string.Equals(Canblock[0], anaresultID.ToString()))
                            {
                                //Data[1];
                                string[] select = Canselected.Split(' ');
                                int      num    = Convert.ToInt32(select[1]);
                                string[] LED    = AnalysisOK[num].Split(',');
                                //string Canvalue = string.Format("{0:0000.0}", Convert.ToDouble(LED[1]));
                                //string Canvalue = string.Format("{0:0000.0}", Convert.ToDouble("-1"));
                                //string Canvalue = "12.2";
                                //加入判断,如果有
                                string Canvalue = LED[1];


                                f3.changearcScale(Convert.ToSingle(LED[2]), Convert.ToSingle(LED[3]), Convert.ToSingle(LED[1]));
                                //f3.changearcScale(0F,100F,50F);
                                f3.changeLED(Canvalue);
                            }
                        }
                    }
                }
                else
                {
                    ListViewItem listv = new ListViewItem();
                    listv.Text = Canget;
                    CanMesslistView.Items.Add(listv);
                }
            }

            //f3.changeLED("10,000");
        }
示例#9
0
		/// 
		/// <param name="canData"></param>
        public int addCANData(CanData canData)
        {

			return 0;
		}