示例#1
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);
        }
示例#2
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
        }