Example #1
0
        private void CreateCycle()
        {
            #region Pre-checks

            if (!(Txt_DataFile.Text.Equals("")))
            {
                oDataFile = new ImportDataFile();
                if (!(oDataFile.ReadDataFile(Txt_DataFile.Text)))
                {
                    MessageBox.Show(CANStreamConstants.DataFileReadingErrorText, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("No data file selected !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (Cmb_Association.Text.Equals(""))
            {
                MessageBox.Show("No Cycle/Data association file selected !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (Txt_CanConfig.Text.Equals(""))
            {
                MessageBox.Show("The CAN configuation file is missing !\nPlease select a new Cycle/Data association file.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (Txt_CycleFile.Text.Equals(""))
            {
                MessageBox.Show("Cycle destination file not defined !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            #endregion

            oCycle = new CANStreamCycle();

            ProgressBar.Value   = 0;
            ProgressBar.Visible = true;

            for (long iTime = (long)(oDataFile.Time[0] * 1000); iTime < (long)(oDataFile.Time[oDataFile.Time.Count - 1] * 1000); iTime++)
            {
                List <string> TimeEventMessageIds = GetMessagesForTimeEvent(iTime);

                if (TimeEventMessageIds.Count > 0)
                {
                    CycleTimeEvent oTimeEvent = new CycleTimeEvent();
                    oTimeEvent.TimeEvent = iTime;

                    foreach (string sMsgId in TimeEventMessageIds)
                    {
                        CANMessageData oMessageData = new CANMessageData();
                        oMessageData = BuildCANMessageData(sMsgId, iTime);

                        if (!(oMessageData == null))
                        {
                            oTimeEvent.MessagesData.Add(oMessageData);
                        }
                        else
                        {
                            ProgressBar.Visible = false;
                            return;
                        }
                    }

                    if (oTimeEvent.MessagesData.Count > 0)
                    {
                        oCycle.TimeEvents.Add(oTimeEvent);
                    }
                }

                int Progress = (int)(iTime * 100 / oDataFile.Time.Count);

                if (Progress <= 100)
                {
                    ProgressBar.Value = Progress;
                }
            }

            //oCycle.CANConfigurationFilePath=Txt_CanConfig.Text;
            oCycle.oCanNodesMap = oCanConfig;
            oCycle.Comment      = rTxt_Comments.Text;

            oCycle.WriteStreamCycle(Txt_CycleFile.Text);

            MessageBox.Show("Cycle created !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            ProgressBar.Visible = false;
        }
Example #2
0
        /// <summary>
        /// Read a data cycle into a XML file
        /// </summary>
        /// <param name="FilePath">Path of the file to read</param>
        /// <returns>Success state of reading operation (true OK, false NOK)</returns>
        public bool ReadStreamCycle(string FilePath)
        {
            XmlDocument oXmlCycle = new XmlDocument();

            oXmlCycle.Load(FilePath);

            XmlNode nCycle = oXmlCycle.FirstChild;

            if (nCycle.Name.Equals("CANStreamCycle"))
            {
                TimeEvents = new List <CycleTimeEvent>();

                XmlNode nHeader = nCycle.SelectSingleNode("Header");
                if (!(nHeader == null))
                {
                    XmlNode nName = nHeader.SelectSingleNode("CycleName");
                    if (!(nName == null))
                    {
                        Name = nName.InnerText;
                    }

                    XmlNode nComment = nHeader.SelectSingleNode("Comment");
                    if (!(nComment == null))
                    {
                        Comment = nComment.InnerText;
                    }

                    /*
                     * XmlNode nCANConfig = nHeader.SelectSingleNode("CANConfigurationFile");
                     * if (!(nCANConfig == null))
                     * {
                     *  CANConfigurationFilePath = nCANConfig.InnerText;
                     * }
                     * else
                     * {
                     *  return (false);
                     * }
                     */
                }
                else
                {
                    return(false);
                }

                XmlNode nCanNodeMap = nCycle.SelectSingleNode("CANConfiguration");
                if (!(nCanNodeMap == null))
                {
                    oCanNodesMap = new CANMessagesConfiguration();
                    if (!(oCanNodesMap.ReadCANConfigurationXmlNode(nCanNodeMap)))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                XmlNode nEvents = nCycle.SelectSingleNode("TimeEvents");
                if (!(nEvents == null))
                {
                    foreach (XmlNode nSingleEvent in nEvents.ChildNodes)
                    {
                        if (nSingleEvent.Name.Equals("Event"))
                        {
                            CycleTimeEvent oEvent = new CycleTimeEvent();

                            XmlAttribute nAtrTime = nSingleEvent.Attributes["TimeValue"];
                            if (!(nAtrTime == null))
                            {
                                long TimeEvent = -1;
                                if (long.TryParse(nAtrTime.Value, out TimeEvent))
                                {
                                    oEvent.TimeEvent = TimeEvent;
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                return(false);
                            }

                            foreach (XmlNode nMessage in nSingleEvent.ChildNodes)
                            {
                                if (nMessage.Name.Equals("MessageData"))
                                {
                                    CANMessageData oMessage = new CANMessageData();

                                    XmlAttribute nAtrMsgId = nMessage.Attributes["Identifier"];
                                    if (!(nAtrMsgId == null))
                                    {
                                        UInt32 MsgId = 0;
                                        if (UInt32.TryParse(nAtrMsgId.Value, out MsgId))
                                        {
                                            oMessage.uMessageId = MsgId;
                                        }
                                        else
                                        {
                                            return(false);
                                        }
                                    }
                                    else
                                    {
                                        return(false);
                                    }

                                    oMessage.byteMessageData = new byte[nMessage.ChildNodes.Count];

                                    for (int iByte = 0; iByte < nMessage.ChildNodes.Count; iByte++)
                                    {
                                        byte ByteValue = 0;
                                        if (byte.TryParse(nMessage.ChildNodes[iByte].InnerText, out ByteValue))
                                        {
                                            oMessage.byteMessageData[iByte] = ByteValue;
                                        }
                                        else
                                        {
                                            return(false);
                                        }
                                    }

                                    oEvent.MessagesData.Add(oMessage);
                                }
                            }

                            TimeEvents.Add(oEvent);
                        }
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Example #3
0
        private void ImportTrcFiles(BackgroundWorker Worker, object ImportOptions)
        {
            if (!(ImportOptions == null))
            {
                object[] Options = (object[])ImportOptions;

                if (Options.Length == 3)
                {
                    string[] TrcFileList             = (string[])Options[0];
                    CANMessagesConfiguration oCanCfg = (CANMessagesConfiguration)Options[1];
                    string CyclePath = (string)Options[2];

                    CANStreamCycle oCycle = new CANStreamCycle();
                    oCycle.oCanNodesMap = oCanCfg;

                    long CycleTime = 0;

                    foreach (string TrcFile in TrcFileList)
                    {
                        PcanTrcFile oTrace = new PcanTrcFile(TrcFile);

                        long TraceTime = 0;
                        int  iRecord   = 0;

                        int Progress = 0;
                        Worker.ReportProgress(Progress);

                        while (iRecord < oTrace.Records.Count)
                        {
                            CycleTimeEvent oCycleTxEvt = new CycleTimeEvent();
                            oCycleTxEvt.TimeEvent = CycleTime;

                            while ((long)oTrace.Records[iRecord].TimeOffset == TraceTime)
                            {
                                CANMessageData oMsgData = new CANMessageData();

                                oMsgData.uMessageId      = (uint)(NumberBaseConverter.Hex2Dec(oTrace.Records[iRecord].MessageIdentifier));
                                oMsgData.byteMessageData = oTrace.Records[iRecord].MessageData;

                                oCycleTxEvt.MessagesData.Add(oMsgData);

                                iRecord++;
                                if (iRecord == oTrace.Records.Count)
                                {
                                    break;
                                }
                            }

                            if (oCycleTxEvt.MessagesData.Count > 0)
                            {
                                oCycle.TimeEvents.Add(oCycleTxEvt);
                            }

                            TraceTime++;
                            CycleTime++;

                            Progress = (int)(iRecord * 100 / oTrace.Records.Count);
                            if (Progress > 0)
                            {
                                Worker.ReportProgress(Progress);
                            }
                        }
                    }

                    oCycle.WriteStreamCycle(CyclePath);
                }
            }
        }