Example #1
0
 public CANStreamCycle()
 {
     Name         = "";
     Comment      = "";
     oCanNodesMap = null;
     TimeEvents   = new List <CycleTimeEvent>();
 }
        private void NewAssociationConfiguration()
        {
            if (ConfigModified)
            {
                DialogResult Rep = MessageBox.Show("The association configuration has been modified. Do you want save it ?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (Rep.Equals(DialogResult.Yes))
                {
                    SaveAssociationConfiguration();
                }
            }

            oCanConfig         = null;
            Txt_CANConfig.Text = "";

            oDataFile         = null;
            Txt_DataFile.Text = "";

            Lbl_DataFile.Enabled = false;
            Txt_DataFile.Enabled = false;
            Cmd_DataFile.Enabled = false;

            oAssociations = new CycleDataAssociation();
            Grid_Association.Rows.Clear();

            ConfigModified = false;
        }
Example #3
0
 public PcanTrcFileInfo()
 {
     TrcFileInfo    = null;
     TrcFileEvent   = null;
     TrcFileSession = null;
     TrcCanConfig   = null;
 }
Example #4
0
        public RecordDataFile(PcanTrcFileInfo oTrcInfo, string VCLibCollectionPath) : base(oTrcInfo.TrcFileInfo.FullName)
        {
            bTrcConverted = false;
            Channels      = new List <RecordDataChannel>();

            oRecordEvent   = null;
            oRecordSession = null;

            if (bTrcLoaded)
            {
                if (!(oTrcInfo.TrcCanConfig == null))
                {
                    oCanConfig = oTrcInfo.TrcCanConfig;

                    VCLibraries = null;
                    if (!(VCLibCollectionPath.Equals("")))
                    {
                        VCLibraries = new CS_VCLibrariesCollection();
                        VCLibraries.LoadLibrariesList(VCLibCollectionPath);
                    }

                    bTrcConverted = DecodeTrcFile();

                    oRecordEvent   = oTrcInfo.TrcFileEvent;
                    oRecordSession = oTrcInfo.TrcFileSession;
                }
            }
        }
Example #5
0
        public CycleEditionConfiguration()
        {
            Parameters                  = new List <CycleParameter>();
            PreCycleProperties          = new CyclePartProperties();
            InCycleProperties           = new CyclePartProperties();
            PostCycleProperties         = new CyclePartProperties();
            CanConfiguration            = null;
            VirtualChannelLibCollection = null;
            BuiltInSignalLibCollection  = null;

            bModified = false;
            FilePath  = "";
        }
Example #6
0
        public Frm_CycleCreation()
        {
            InitializeComponent();

            oCycle        = null;
            oCanConfig    = null;
            oAssociations = null;
            oDataFile     = null;

            oSignalLibCollection = new CS_BuiltInSignalLibCollection();
            if (File.Exists(CANStreamTools.CsDataPath + "\\BuiltInSignals.xml"))
            {
                oSignalLibCollection.LoadLibrariesList(CANStreamTools.CsDataPath + "\\BuiltInSignals.xml");
            }
        }
Example #7
0
        private void Cmb_Association_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Cmb_Association.SelectedIndex != -1)
            {
                oAssociations      = new CycleDataAssociation();
                Txt_CanConfig.Text = "";

                if (File.Exists(Cmb_Association.Text))
                {
                    if (oAssociations.ReadCycleDataAssociation(Cmb_Association.Text))
                    {
                        if (File.Exists(oAssociations.CANConfigFile))
                        {
                            oCanConfig = new CANMessagesConfiguration();
                            if (oCanConfig.ReadCANConfigurationFile(oAssociations.CANConfigFile))
                            {
                                Txt_CanConfig.Text = oAssociations.CANConfigFile;
                            }
                            else
                            {
                                Cmb_Association.SelectedIndex = -1;
                                MessageBox.Show("CAN Configuration file reading error !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            Cmb_Association.SelectedIndex = -1;
                            MessageBox.Show("The CAN configuration file attached to the Cycle/Data association no longer exists.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    else
                    {
                        Cmb_Association.SelectedIndex = -1;
                        MessageBox.Show("Cycle/Data file reading error !\nCheck the file.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    Cmb_Association.SelectedIndex = -1;
                    MessageBox.Show("The selected cycle/data association file no longer exists !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
        public Frm_CycleDataAssociation()
        {
            InitializeComponent();

            oAssociations = new CycleDataAssociation();
            oCanConfig    = null;
            oDataFile     = null;

            oSigLibCollection = new CS_BuiltInSignalLibCollection();

            string SigLibCollectionFile = CANStreamTools.CsDataPath + "\\BuiltInSignals.xml";

            if (File.Exists(SigLibCollectionFile))
            {
                oSigLibCollection.LoadLibrariesList(SigLibCollectionFile);
            }

            GridEdition    = false;
            ConfigModified = false;
        }
Example #9
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);
        }
        private void ShowAssociationConfiguration()
        {
            FileInfo oFile = null;
            //bool bCanCfgOK = false;
            bool bDataFileOK = false;

            oFile = new FileInfo(oAssociations.CANConfigFile);
            Txt_CANConfig.Text = oFile.FullName;

            if (oFile.Exists)
            {
                oCanConfig = new CANMessagesConfiguration();
                if (!(oCanConfig.ReadCANConfigurationFile(oAssociations.CANConfigFile)))
                {
                    MessageBox.Show("CAN Configuration file reading error !\nLoad a new file in order to modify the association configuration", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                //bCanCfgOK = true;
            }
            else
            {
                MessageBox.Show("CAN Configuration file " + oFile.Name + " no longer exists.\nLoad a new file in order to modify the association configuration.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            Lbl_DataFile.Enabled = true;
            Txt_DataFile.Enabled = true;
            Cmd_DataFile.Enabled = true;

            oFile             = new FileInfo(oAssociations.DataFileTemplate);
            Txt_DataFile.Text = oFile.FullName;

            if (oFile.Exists)
            {
                oDataFile = new ImportDataFile();
                if (!(oDataFile.ReadDataFile(oAssociations.DataFileTemplate, true)))
                {
                    MessageBox.Show("Data file template reading error !\nLoad a new file in order to modify the association configuration", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                bDataFileOK = true;
            }
            else
            {
                MessageBox.Show("Data file template " + oFile.Name + " no longer exists.\nLoad a new file in order to modify the association configuration.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            GridEdition = true;

            Grid_Association.Rows.Clear();
            Grid_Association.Rows.Add(oAssociations.Associations.Count);

            for (int iRow = 0; iRow < Grid_Association.Rows.Count; iRow++)
            {
                Grid_Association.Rows[iRow].HeaderCell.Value = oAssociations.Associations[iRow].CANParameterMessageIdentifier;
                Grid_Association.Rows[iRow].Cells[0].Value   = oAssociations.Associations[iRow].CANParameterName;

                //Association types list
                DataGridViewComboBoxCell CmbCellTypeAsso = (DataGridViewComboBoxCell)Grid_Association.Rows[iRow].Cells[1];
                CmbCellTypeAsso.Items.Clear();

                string[] AssoTypes = CS_DataAssociationType.GetNames(typeof(CS_DataAssociationType));
                for (int i = 0; i < AssoTypes.Length; i++)
                {
                    CmbCellTypeAsso.Items.Add(AssoTypes[i]);
                }

                CmbCellTypeAsso.Value = oAssociations.Associations[iRow].AssociationType.ToString();

                //Data channels list
                DataGridViewComboBoxCell CmbCellChannel = (DataGridViewComboBoxCell)Grid_Association.Rows[iRow].Cells[2];
                CmbCellChannel.Items.Clear();

                if (bDataFileOK)
                {
                    for (int i = 0; i < oDataFile.Channels.Count; i++)
                    {
                        CmbCellChannel.Items.Add(oDataFile.Channels[i].ChannelName);
                    }
                }
                else
                {
                    CmbCellChannel.Items.Add(oAssociations.Associations[iRow].DataColumnTitle);
                }

                //Built-in signals list
                DataGridViewComboBoxCell CmbCellSignal = (DataGridViewComboBoxCell)Grid_Association.Rows[iRow].Cells[3];
                CmbCellSignal.Items.Clear();

                foreach (CS_BuiltInSignalLibrary oSigLib in oSigLibCollection.Libraries)
                {
                    foreach (CS_BuiltInSignal oSignal in oSigLib.Signals)
                    {
                        CmbCellSignal.Items.Add(oSigLib.Name + ":" + oSignal.Name);
                    }
                }

                switch (oAssociations.Associations[iRow].AssociationType)
                {
                case CS_DataAssociationType.AcqData:

                    CmbCellChannel.Value = oAssociations.Associations[iRow].DataColumnTitle;
                    break;

                case CS_DataAssociationType.BuiltSignal:

                    if (oSigLibCollection.SignalExistsInLibrary(oAssociations.Associations[iRow].SignalLibrary,
                                                                oAssociations.Associations[iRow].SignalName))
                    {
                        CmbCellSignal.Value = oAssociations.Associations[iRow].SignalLibrary
                                              + ":" + oAssociations.Associations[iRow].SignalName;
                    }
                    else
                    {
                        MessageBox.Show("Built-in signal " + oAssociations.Associations[iRow].SignalName
                                        + " or signal library " + oAssociations.Associations[iRow].SignalLibrary
                                        + " doesn't exist anymore !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    break;

                case CS_DataAssociationType.FixedValue:

                    Grid_Association.Rows[iRow].Cells[4].Value = oAssociations.Associations[iRow].DefaultValue.ToString();
                    break;

                default:
                    break;
                }

                #region Old version

                /*
                 * Grid_Association.Rows[iRow].HeaderCell.Value = oAssociations.Associations[iRow].CANParameterMessageIdentifier;
                 * Grid_Association.Rows[iRow].Cells[0].Value = oAssociations.Associations[iRow].CANParameterName;
                 * Grid_Association.Rows[iRow].Cells[2].Value = oAssociations.Associations[iRow].UseDefaultValue;
                 * Grid_Association.Rows[iRow].Cells[3].Value = oAssociations.Associations[iRow].DefaultValue.ToString();
                 *
                 * DataGridViewComboBoxCell CmbCell = (DataGridViewComboBoxCell)Grid_Association.Rows[iRow].Cells[1];
                 * CmbCell.Items.Clear();
                 *
                 * if (bDataFileOK)
                 * {
                 *  for (int i = 0; i < oDataFile.Channels.Count; i++)
                 *  {
                 *      CmbCell.Items.Add(oDataFile.Channels[i].ChannelName);
                 *  }
                 * }
                 * else
                 * {
                 *  CmbCell.Items.Add(oAssociations.Associations[iRow].DataColumnTitle);
                 * }
                 *
                 * Grid_Association.Rows[iRow].Cells[1].Value = oAssociations.Associations[iRow].DataColumnTitle;
                 */
                #endregion
            }

            Grid_Association.Enabled = true;

            GridEdition = false;
        }
        private void Cmd_CANConfig_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName         = "";
            openFileDialog1.Filter           = "CAN Configuration|*.xcc";
            openFileDialog1.InitialDirectory = CANStreamTools.MyDocumentPath + "\\CANStream\\CAN Configuration";

            if (openFileDialog1.ShowDialog().Equals(DialogResult.OK))
            {
                oCanConfig = new CANMessagesConfiguration();

                if (oCanConfig.ReadCANConfigurationFile(openFileDialog1.FileName))
                {
                    GridEdition = true;

                    int RowsCount = oCanConfig.GetTxParameterCount(false);

                    if (RowsCount > 0)
                    {
                        Grid_Association.Enabled = true;
                        Grid_Association.Rows.Clear();
                        Grid_Association.Rows.Add(RowsCount);
                        int iRow = 0;

                        string[] sAssoTypes = Enum.GetNames(typeof(CS_DataAssociationType));

                        foreach (CANMessage oMessage in oCanConfig.Messages)
                        {
                            if (oMessage.RxTx.Equals(CanMsgRxTx.Tx) && (!oMessage.ContainsVirtualParameters()))
                            {
                                foreach (CANParameter oParam in oMessage.Parameters)
                                {
                                    Grid_Association.Rows[iRow].HeaderCell.Value = oMessage.Identifier;
                                    Grid_Association.Rows[iRow].Cells[0].Value   = oParam.Name;

                                    //Association types list creation
                                    DataGridViewComboBoxCell AssoCell = (DataGridViewComboBoxCell)Grid_Association.Rows[iRow].Cells[1];
                                    AssoCell.Items.Clear();

                                    foreach (string sAsso in sAssoTypes)
                                    {
                                        AssoCell.Items.Add(sAsso);
                                    }

                                    //Built-in Signals list creation
                                    DataGridViewComboBoxCell SignalCell = (DataGridViewComboBoxCell)Grid_Association.Rows[iRow].Cells[3];
                                    SignalCell.Items.Clear();

                                    foreach (CS_BuiltInSignalLibrary oSigLib in oSigLibCollection.Libraries)
                                    {
                                        foreach (CS_BuiltInSignal oSignal in oSigLib.Signals)
                                        {
                                            SignalCell.Items.Add(oSigLib.Name + ":" + oSignal.Name);
                                        }
                                    }

                                    iRow++;
                                }
                            }
                        }

                        Txt_CANConfig.Text   = openFileDialog1.FileName;
                        Lbl_DataFile.Enabled = true;
                        Txt_DataFile.Enabled = true;
                        Cmd_DataFile.Enabled = true;
                    }
                    else
                    {
                        MessageBox.Show("The CAN configuration selected contains only Rx messages !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    GridEdition = false;
                }
                else
                {
                    MessageBox.Show("CAN configuration file loading error !\nCheck the file.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #12
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);
                }
            }
        }
Example #13
0
        private void Cmd_CreateClick(object sender, EventArgs e)
        {
            object[] ImportOptions = new object[3];

            if (!(Lst_TrcFiles.Items.Count == 0))
            {
                string[] TrcFiles = new string[Lst_TrcFiles.Items.Count];

                for (int i = 0; i < Lst_TrcFiles.Items.Count; i++)
                {
                    TrcFiles[i] = Lst_TrcFiles.Items[i].ToString();
                }

                ImportOptions[0] = TrcFiles;
            }
            else
            {
                MessageBox.Show("Trace record file list is empty !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            CANMessagesConfiguration oCanCfg = new CANMessagesConfiguration();

            if (!(Txt_CanConfig.Text.Equals("")))
            {
                if (!(oCanCfg.ReadCANConfigurationFile(Txt_CanConfig.Text)))
                {
                    MessageBox.Show("CAN configuration file reading error !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("No CAN Configuration defined, cycle will be created using default CAN bus properties", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            ImportOptions[1] = oCanCfg;

            if (!(Txt_CycleOut.Text.Equals("")))
            {
                ImportOptions[2] = Txt_CycleOut.Text;
            }
            else
            {
                MessageBox.Show("Output cycle file name is empty", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            this.Height    = FRM_HEIGHT_PROGRESS;
            Cmd_Cancel.Top = CMD_TOP_PROGRESS;
            Cmd_Create.Top = CMD_TOP_PROGRESS;

            FileProcessedCnt = -1;
            Lbl_TrcFileListProgress.Visible = true;
            Lbl_TrcFileListProgress.Text    = "File 0 of " + Lst_TrcFiles.Items.Count.ToString()
                                              + ": " + Path.GetFileName(Lst_TrcFiles.Items[0].ToString());

            Lbl_TrcFileProcessingProgress.Visible = true;
            Lbl_TrcFileProcessingProgress.Text    = "0 %";

            PB_TrcFileListProgress.Visible = true;
            PB_TrcFileListProgress.Value   = 0;

            PB_TrcFileProcessingProgress.Visible = true;
            PB_TrcFileProcessingProgress.Value   = 0;

            BGW_TraceImport.RunWorkerAsync(ImportOptions);
        }
Example #14
0
        /// <summary>
        /// Read the cycle configuration in a XML file
        /// </summary>
        /// <param name="fPath">Path of the file to read</param>
        /// <returns>Reading error flag: True = No Error / False = Error</returns>
        public bool Read_CycleConfiguration(string fPath)
        {
            if (!(fPath.Equals("")))
            {
                XmlDocument oCycleConfig = new XmlDocument();
                oCycleConfig.Load(fPath);

                XmlNode xCycleCfg = oCycleConfig.SelectSingleNode("CycleConfiguration");

                if (!(xCycleCfg == null))
                {
                    //CAN Configuration
                    XmlNode xCanCfg = xCycleCfg.SelectSingleNode("CANConfiguration");

                    if (!(xCanCfg == null))
                    {
                        CanConfiguration = new CANMessagesConfiguration();

                        if (!(CanConfiguration.ReadCANConfigurationXmlNode(xCanCfg)))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);                         //Node CANConfiguration not found
                    }

                    //Virtual channels libraries
                    XmlNode xVirtualLib = xCanCfg.NextSibling;

                    if (xVirtualLib.Name.Equals("CS_VirtualChannelsLibrary"))
                    {
                        VirtualChannelLibCollection = new CS_VCLibrariesCollection();

                        while (xVirtualLib.Name.Equals("CS_VirtualChannelsLibrary"))
                        {
                            CS_VirtualChannelsLibrary oLib = new CS_VirtualChannelsLibrary();
                            oLib.ReadLibraryXmlNode(xVirtualLib);
                            VirtualChannelLibCollection.AddLibrary(oLib);

                            xVirtualLib = xVirtualLib.NextSibling;
                        }
                    }

                    //Built-In signals libraries
                    XmlNode xSignalLib = xVirtualLib;

                    if (xSignalLib.Name.Equals("CS_BuiltInSignalsLibrary"))
                    {
                        BuiltInSignalLibCollection = new CS_BuiltInSignalLibCollection();

                        while (xSignalLib.Name.Equals("CS_BuiltInSignalsLibrary"))
                        {
                            CS_BuiltInSignalLibrary oLib = new CS_BuiltInSignalLibrary();
                            oLib.ReadLibraryXmlNode(xSignalLib);
                            BuiltInSignalLibCollection.AddLibrary(oLib);

                            xSignalLib = xSignalLib.NextSibling;
                        }
                    }

                    //Cycle parts properties
                    XmlNode xPartProps = xCycleCfg.SelectSingleNode("CyclePartsProperties");
                    if (!(xPartProps == null))
                    {
                        //Pre-cycle
                        XmlNode xPreCycleProps = xPartProps.SelectSingleNode("PreCycleProperties");
                        if (!(xPreCycleProps == null))
                        {
                            XmlAttribute xAtr;

                            xAtr = xPreCycleProps.Attributes["TimeLength"];
                            if (!(xAtr == null))
                            {
                                double t = 0;
                                if (double.TryParse(xAtr.Value, out t))
                                {
                                    PreCycleProperties.TimeLength = t;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute TimeLength is not a number
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute TimeLength not found in node PreCycleProperties
                            }

                            xAtr = xPreCycleProps.Attributes["DataFile"];
                            if (!(xAtr == null))
                            {
                                PreCycleProperties.DataFile = xAtr.Value;
                            }
                            else
                            {
                                return(false);                                 //Attribute DataFile not found in node PreCycleProperties
                            }
                        }
                        else
                        {
                            return(false);                             //Node PreCycleProperties not found
                        }

                        //In-Cycle
                        XmlNode xInCycleProps = xPartProps.SelectSingleNode("InCycleProperties");
                        if (!(xInCycleProps == null))
                        {
                            XmlAttribute xAtr;

                            xAtr = xInCycleProps.Attributes["TimeLength"];
                            if (!(xAtr == null))
                            {
                                double t = 0;
                                if (double.TryParse(xAtr.Value, out t))
                                {
                                    InCycleProperties.TimeLength = t;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute TimeLength is not a number
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute TimeLength not found in node InCycleProperties
                            }

                            xAtr = xInCycleProps.Attributes["DataFile"];
                            if (!(xAtr == null))
                            {
                                InCycleProperties.DataFile = xAtr.Value;
                            }
                            else
                            {
                                return(false);                                 //Attribute DataFile not found in node InCycleProperties
                            }
                        }
                        else
                        {
                            return(false);                             //Node InCycleProperties not found
                        }

                        //Post-Cycle
                        XmlNode xPostCycleProps = xPartProps.SelectSingleNode("PostCycleProperties");
                        if (!(xPostCycleProps == null))
                        {
                            XmlAttribute xAtr;

                            xAtr = xPostCycleProps.Attributes["TimeLength"];
                            if (!(xAtr == null))
                            {
                                double t = 0;
                                if (double.TryParse(xAtr.Value, out t))
                                {
                                    PostCycleProperties.TimeLength = t;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute TimeLength is not a number
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute TimeLength not found in node PostCycleProperties
                            }

                            xAtr = xPostCycleProps.Attributes["DataFile"];
                            if (!(xAtr == null))
                            {
                                PostCycleProperties.DataFile = xAtr.Value;
                            }
                            else
                            {
                                return(false);                                 //Attribute DataFile not found in node PostCycleProperties
                            }
                        }
                        else
                        {
                            return(false);                             //Node PostCycleProperties not found
                        }
                    }
                    else
                    {
                        return(false);                         //Node CyclePartsProperties not found
                    }

                    //Cycle parameters
                    XmlNode xCycleParams = xCycleCfg.SelectSingleNode("CycleParameters");
                    if (!(xCycleParams == null))
                    {
                        Parameters = new List <CycleParameter>();

                        foreach (XmlNode xParam in xCycleParams.ChildNodes)
                        {
                            CycleParameter oParam = new CycleParameter();

                            XmlAttribute xAtr;
                            XmlNode      xData;

                            //Parameter Name
                            xAtr = xParam.Attributes["Name"];
                            if (!(xAtr == null))
                            {
                                if (!(xAtr.Value.Equals("")))
                                {
                                    oParam.Name = xAtr.Value;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute Name is empty
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute Name not found in node xParam
                            }

                            //Parameter Message Id
                            xAtr = xParam.Attributes["MessageId"];
                            if (!(xAtr == null))
                            {
                                if (!(xAtr.Value.Equals("")))
                                {
                                    oParam.MsgId = xAtr.Value;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute MessageId is empty
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute MessageId not found in node xParam
                            }

                            //Pre-Cycle data
                            xData = xParam.SelectSingleNode("PreCycleData");
                            if (!(xData == null))
                            {
                                //Source
                                xAtr = xData.Attributes["Source"];
                                if (!(xAtr == null))
                                {
                                    CycleDataSource Src = CycleDataSource.None;

                                    if (Enum.TryParse(xAtr.Value, out Src))
                                    {
                                        oParam.PreCycle.Source = Src;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Source is not part of enumeration
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Source not found in node PreCycleData
                                }

                                //Data
                                xAtr = xData.Attributes["Data"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.PreCycle.Data = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Data is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Data not found in node PreCycleData
                                }

                                //Library
                                xAtr = xData.Attributes["Library"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.PreCycle.Library = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Library is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Library not found in node PreCycleData
                                }
                            }
                            else
                            {
                                return(false);                                 //Node PreCycleData not found
                            }

                            //In-cycle data
                            xData = xParam.SelectSingleNode("InCycleData");
                            if (!(xData == null))
                            {
                                //Source
                                xAtr = xData.Attributes["Source"];
                                if (!(xAtr == null))
                                {
                                    CycleDataSource Src = CycleDataSource.None;

                                    if (Enum.TryParse(xAtr.Value, out Src))
                                    {
                                        oParam.InCycle.Source = Src;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Source is not part of enumeration
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Source not found in node InCycleData
                                }

                                //Data
                                xAtr = xData.Attributes["Data"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.InCycle.Data = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Data is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Data not found in node InCycleData
                                }

                                //Library
                                xAtr = xData.Attributes["Library"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.InCycle.Library = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Library is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Library not found in node InCycleData
                                }
                            }
                            else
                            {
                                return(false);                                 //Node InCycleData not found
                            }

                            xData = xParam.SelectSingleNode("PostCycleData");
                            if (!(xData == null))
                            {
                                //Source
                                xAtr = xData.Attributes["Source"];
                                if (!(xAtr == null))
                                {
                                    CycleDataSource Src = CycleDataSource.None;

                                    if (Enum.TryParse(xAtr.Value, out Src))
                                    {
                                        oParam.PostCycle.Source = Src;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Source is not part of enumeration
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Source not found in node PostCycleData
                                }

                                //Data
                                xAtr = xData.Attributes["Data"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.PostCycle.Data = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Data is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Data not found in node PostCycleData
                                }

                                //Library
                                xAtr = xData.Attributes["Library"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.PostCycle.Library = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Library is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Library not found in node PostCycleData
                                }
                            }
                            else
                            {
                                return(false);                                 //Node PostCycleData not found
                            }

                            Parameters.Add(oParam);
                        }
                    }
                    else
                    {
                        return(false);                         //Node CycleParameters not found
                    }
                }
                else
                {
                    return(false);                     //Node CycleConfiguration not found
                }
            }
            else
            {
                return(false);                 //Path empty
            }

            FilePath  = fPath;
            bModified = false;
            return(true);             //No Error
        }
Example #15
0
        /// <summary>
        /// Convert the DBC object into a CANStream CAN configuration object
        /// </summary>
        /// <param name="Rate">CAN bus Baud rate</param>
        /// <param name="CanNodeName">CAN device name</param>
        /// <returns>CANStream CAN configuration object of the DBC</returns>
        public CANMessagesConfiguration Convert_DBC_to_XCC(int Rate, string CanNodeName)
        {
            CANMessagesConfiguration oXCC = new CANMessagesConfiguration();

            //Bus Baud rate
            oXCC.CanRate = Rate;

            //Config name
            oXCC.Name = "DBC:";
            if (!(BusComponents == null))
            {
                for (int i = 0; i < BusComponents.Length; i++)
                {
                    oXCC.Name = oXCC.Name + " " + BusComponents[i];
                }
            }

            foreach (DBCFrame oFrame in Frames)
            {
                CANMessage oCSMsg = new CANMessage();

                oCSMsg.Identifier = NumberBaseConverter.Dec2Hex(oFrame.Identifier);
                oCSMsg.DLC        = oFrame.ByteLength;
                oCSMsg.Name       = oFrame.Name;
                oCSMsg.Comment    = oFrame.GetNodeComments();
                oCSMsg.Period     = 1000;           //Default value

                //oCSMsg.RxTx=CanMsgRxTx.Tx; //Default value
                if (oFrame.Transmitter.Equals(CanNodeName))
                {
                    oCSMsg.RxTx = CanMsgRxTx.Tx;
                }
                else
                {
                    oCSMsg.RxTx = CanMsgRxTx.Rx;
                }

                oCSMsg.MultiplexerName = oFrame.GetMultiplexerSignalName();

                foreach (DBCSignal oSignal in oFrame.Signals)
                {
                    if ((oCSMsg.RxTx.Equals(CanMsgRxTx.Tx)) || (oCSMsg.RxTx.Equals(CanMsgRxTx.Rx) && oSignal.Destination.Equals(CanNodeName)))
                    {
                        CANParameter oCSParam = new CANParameter();

                        oCSParam.Name    = oSignal.Name;
                        oCSParam.Comment = oSignal.GetSignalComments();
                        oCSParam.Unit    = oSignal.Unit;

                        oCSParam.StartBit  = oSignal.StartBit;
                        oCSParam.Length    = oSignal.Length;
                        oCSParam.Endianess = (CanParameterEndianess)Enum.Parse(typeof(CanParameterEndianess), oSignal.Endianess.ToString());
                        oCSParam.Signed    = oSignal.Signed;

                        oCSParam.Gain = oSignal.Gain;
                        oCSParam.Zero = oSignal.Zero;

                        if (!(oSignal.Multiplexer == null))
                        {
                            if (!(oSignal.Multiplexer.IsMultiplexerSignal))
                            {
                                oCSParam.IsMultiplexed    = true;
                                oCSParam.MultiplexerValue = oSignal.Multiplexer.MultiplexerValue;
                            }
                        }

                        oCSMsg.Parameters.Add(oCSParam);
                    }
                }

                if (oCSMsg.Parameters.Count > 0)
                {
                    oXCC.Messages.Add(oCSMsg);
                }
            }

            return(oXCC);
        }