Exemplo n.º 1
0
        private static void LoadSignal(XmlNode node, VdfMessage message, VdfDocument vdfDocument)
        {
            string sval;

            if (!XmlUtils.TryGetStringAttrValue(node, VdfTag.NameAttrName, out sval))
            {
                return;
            }

            VdfSignal signal = new VdfSignal();

            signal.Name = sval;
            message.SignalTable.Add(signal.Name, signal);

            int ival;

            if (XmlUtils.TryGetIntAttrValue(node, VdfTag.StartBitAttrName, out ival))
            {
                signal.StartBit = ival;
            }
            else
            {
                throw new VdfException("Signal " + signal.Name + " missing StartBit Attribute");
            }

            if (XmlUtils.TryGetIntAttrValue(node, VdfTag.BitLenAttrName, out ival))
            {
                signal.BitLen = ival;
            }
            else
            {
                throw new VdfException("Signal " + signal.Name + " missing BitLen Attribute");
            }

            if (XmlUtils.TryGetStringAttrValue(node, VdfTag.ByteOrderAttrName, out sval))
            {
                VdfByteOrder vdfByteOrder;

                if (!Enum.TryParse <VdfByteOrder>(sval, out vdfByteOrder))
                {
                    throw new VdfException(
                              string.Format("Invalid Byte Order: {0}, Only Can be {1} or {2}",
                                            sval, "Intel", "Motorola"));
                }
                signal.ByteOrder = vdfByteOrder;
            }

            if (XmlUtils.TryGetStringAttrValue(node, VdfTag.ValueDescAttrName, out sval))
            {
                signal.ValueDesc = sval;

                //有个要求,只有值描述已经更新过了,Signal中的值描述才会更新
                signal.VdfValueDesc = vdfDocument.ValueDesc(sval);
                if (signal.VdfValueDesc == null)
                {
                    throw new VdfException("ValueDesc " + sval + " Is Undefined Before " +
                                           "Define Signal " + signal.Name);
                }
            }
        }
Exemplo n.º 2
0
        private static void Load(XmlDocument doc, VdfDocument vdfDocument)
        {
            //获取Vdf根元素
            var elems = doc.GetElementsByTagName(VdfTag.VdfElemName);

            if (elems.Count == 0 || elems.Count > 1)
            {
                throw new VdfException("Vdf element count must be one.");
            }

            //获取版本号
            var    vdfRoot = elems[0];
            string version = VdfDocument.Version;

            if (vdfRoot.Attributes[VdfTag.VersionAttrName] != null)
            {
                version = vdfRoot.Attributes[VdfTag.VersionAttrName].Value;
            }

            ParseHandler parser;

            if (parseHandlerTable.TryGetValue(version, out parser))
            {
                parser(vdfRoot, vdfDocument);
            }
            else
            {
                throw new VdfException("Vdf File Version is newer than current Vdf Parser. " +
                                       "Please use newest Vdf4Cs library to handle");
            }
        }
Exemplo n.º 3
0
        public override void Save(XmlElement valueDescTableElem, XmlDocument xmlDoc,
                                  VdfDocument vdfDocument)
        {
            var valDescElem = CreateValueDesc(valueDescTableElem, xmlDoc);

            XmlUtils.SetElemAttribute(valDescElem, xmlDoc, VdfTag.TypeAttrName, Type);
        }
Exemplo n.º 4
0
        private void SaveEntry(KeyValuePair <int, string> entry,
                               XmlElement valueDescElem, XmlDocument xmlDoc, VdfDocument vdfDocument)
        {
            var entryElem = xmlDoc.CreateElement(VdfTag.EntryElemName);

            valueDescElem.AppendChild(entryElem);
            XmlUtils.SetElemAttribute(entryElem, xmlDoc, VdfTag.ValueAttrName, entry.Key);
            XmlUtils.SetElemAttribute(entryElem, xmlDoc, VdfTag.DescriptionAttrName, entry.Value);
        }
Exemplo n.º 5
0
        public override void Save(XmlElement valueDescTableElem, XmlDocument xmlDoc,
                                  VdfDocument vdfDocument)
        {
            var valueDescElem = CreateValueDesc(valueDescTableElem, xmlDoc);

            XmlUtils.SetElemAttribute(valueDescElem, xmlDoc, VdfTag.TypeAttrName, Type);

            foreach (var entry in EntryTable)
            {
                SaveEntry(entry, valueDescElem, xmlDoc, vdfDocument);
            }
        }
Exemplo n.º 6
0
        public override void Save(XmlElement valueDescElem, XmlDocument xmlDoc,
                                  VdfDocument vdfDocument)
        {
            var valDescElem = CreateValueDesc(valueDescElem, xmlDoc);

            XmlUtils.SetElemAttribute(valDescElem, xmlDoc, VdfTag.TypeAttrName, Type);
            XmlUtils.SetElemAttribute(valDescElem, xmlDoc, VdfTag.FactorAttrName, Factor);
            XmlUtils.SetElemAttribute(valDescElem, xmlDoc, VdfTag.OffsetAttrName, Offset);
            XmlUtils.SetElemAttribute(valDescElem, xmlDoc, VdfTag.UnitAttrName, Unit);
            XmlUtils.SetElemAttribute(valDescElem, xmlDoc, VdfTag.MinimumAttrName, Minimum);
            XmlUtils.SetElemAttribute(valDescElem, xmlDoc, VdfTag.MaximumAttrName, Maximum);
        }
Exemplo n.º 7
0
        private static void LoadValueDescTable(XmlNode valueDescTableNode, VdfDocument vdfDocument)
        {
            vdfDocument.ValueDescTable = new Dictionary <string, VdfValueDesc>();
            var nodes = valueDescTableNode.SelectNodes(VdfTag.ValueDescElemName);

            if (nodes != null)
            {
                foreach (XmlNode valueDescNode in nodes)
                {
                    LoadValueDesc(valueDescNode, vdfDocument.ValueDescTable);
                }
            }
        }
Exemplo n.º 8
0
 internal static void Load(string vdfFile, VdfDocument vdfDocument)
 {
     try
     {
         XmlDocument doc = new XmlDocument();
         doc.Load(vdfFile);
         Load(doc, vdfDocument);
     }
     catch (Exception ex)
     {
         throw new VdfException(ex.Message, ex.InnerException);
     }
 }
Exemplo n.º 9
0
        private static void LoadMessageTable(XmlNode messageTableNode, VdfDocument vdfDocument)
        {
            vdfDocument.MessageTable = new Dictionary <string, VdfMessage>();
            var nodes = messageTableNode.SelectNodes(VdfTag.MessageElemName);

            if (nodes != null)
            {
                foreach (XmlNode messageNode in nodes)
                {
                    LoadMessage(messageNode, vdfDocument.MessageTable, vdfDocument);
                }
            }
        }
Exemplo n.º 10
0
        private static void SaveVersion1_0(XmlDocument xmlDoc, VdfDocument vdfDocument)
        {
            // 创建根节点
            var rootElem = xmlDoc.CreateElement(VdfTag.VdfElemName);

            rootElem.SetAttribute(VdfTag.VersionAttrName, VdfDocument.Version);
            xmlDoc.AppendChild(rootElem);

            // 保存值描述
            SaveValueDescTable(rootElem, xmlDoc, vdfDocument);

            // 保存报文表
            SaveMessageTable(rootElem, xmlDoc, vdfDocument);
        }
Exemplo n.º 11
0
        private static void SaveSignal(VdfSignal signal, XmlElement messageElem,
                                       XmlDocument xmlDoc, VdfDocument vdfDocument)
        {
            var signalElem = xmlDoc.CreateElement(VdfTag.SignalElemName);

            messageElem.AppendChild(signalElem);

            XmlUtils.SetElemAttribute(signalElem, xmlDoc, VdfTag.NameAttrName, signal.Name);
            XmlUtils.SetElemAttribute(signalElem, xmlDoc,
                                      VdfTag.StartBitAttrName, signal.StartBit);
            XmlUtils.SetElemAttribute(signalElem, xmlDoc, VdfTag.BitLenAttrName, signal.BitLen);
            XmlUtils.SetElemAttribute(signalElem, xmlDoc,
                                      VdfTag.ByteOrderAttrName, signal.ByteOrder);
            XmlUtils.SetElemAttribute(signalElem, xmlDoc, VdfTag.ValueDescAttrName, signal.ValueDesc);
        }
Exemplo n.º 12
0
        internal static void Save(string file, VdfDocument vdfDocument)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", "utf-8", ""));

            SaveHandler handler;

            if (saveHandlerTable.TryGetValue(VdfDocument.Version, out handler))
            {
                handler(xmlDoc, vdfDocument);
            }

            xmlDoc.Save(file);
        }
Exemplo n.º 13
0
        private static void LoadVersion1_0(XmlNode vdfNode, VdfDocument vdfDocument)
        {
            var node = vdfNode.SelectSingleNode(VdfTag.ValueDescTableElemName);

            if (node != null)
            {
                LoadValueDescTable(node, vdfDocument);
            }

            node = vdfNode.SelectSingleNode(VdfTag.MessageTableElemName);
            if (node != null)
            {
                LoadMessageTable(node, vdfDocument);
            }
        }
Exemplo n.º 14
0
        public override void Save(XmlElement valueDescTableElem, XmlDocument xmlDoc,
                                  VdfDocument vdfDocument)
        {
            var valDescElem = CreateValueDesc(valueDescTableElem, xmlDoc);

            XmlUtils.SetElemAttribute(valDescElem, xmlDoc, VdfTag.TypeAttrName, Type);

            if (CanFillAlpha)
            {
                XmlUtils.SetElemAttribute(valDescElem, xmlDoc, VdfTag.SeparatorAttrName, Separator);
            }
            else
            {
                XmlUtils.SetElemAttribute(valDescElem, xmlDoc, VdfTag.FactorAttrName, Factor);
                XmlUtils.SetElemAttribute(valDescElem, xmlDoc, VdfTag.OffsetAttrName, Offset);
                XmlUtils.SetElemAttribute(valDescElem, xmlDoc, VdfTag.MinimumAttrName, Minimum);
                XmlUtils.SetElemAttribute(valDescElem, xmlDoc, VdfTag.MaximumAttrName, Maximum);
            }
            XmlUtils.SetElemAttribute(valDescElem, xmlDoc,
                                      VdfTag.CanFillAlphaAttrName, CanFillAlpha);
        }
Exemplo n.º 15
0
 protected virtual void OnVdfDocumentChanged(VdfDocument doc)
 {
 }
Exemplo n.º 16
0
        private static void LoadMessage(XmlNode messageNode,
                                        Dictionary <string, VdfMessage> messageTable, VdfDocument vdfDocument)
        {
            string sval;

            if (!XmlUtils.TryGetStringAttrValue(messageNode, VdfTag.NameAttrName, out sval))
            {
                return; //报文如果没有名称,则直接丢弃掉
            }

            VdfMessage message = new VdfMessage();

            message.Name = sval;
            if (XmlUtils.TryGetStringAttrValue(messageNode, VdfTag.DescriptionAttrName, out sval))
            {
                message.Description = sval;
            }

            int ival;

            if (XmlUtils.TryGetIntAttrValue(messageNode, VdfTag.ByteLenAttrName, out ival))
            {
                message.ByteLen = ival;
            }
            messageTable.Add(message.Name, message);

            //解析所有信号
            var nodes = messageNode.SelectNodes(VdfTag.SignalElemName);

            message.SignalTable = new Dictionary <string, VdfSignal>();
            foreach (XmlNode node in nodes)
            {
                LoadSignal(node, message, vdfDocument);
            }
        }
Exemplo n.º 17
0
        private static void SaveMessageTable(XmlElement rootElem, XmlDocument xmlDoc, VdfDocument vdfDocument)
        {
            var messageTblElem = xmlDoc.CreateElement(VdfTag.MessageTableElemName);

            rootElem.AppendChild(messageTblElem);

            foreach (var entry in vdfDocument.MessageTable)
            {
                SaveMessage(entry.Value, messageTblElem, xmlDoc, vdfDocument);
            }
        }
Exemplo n.º 18
0
        private static void SaveMessage(VdfMessage message,
                                        XmlElement messageTblElem, XmlDocument xmlDoc, VdfDocument vdfDocument)
        {
            var messageElem = xmlDoc.CreateElement(VdfTag.MessageElemName);

            messageTblElem.AppendChild(messageElem);

            XmlUtils.SetElemAttribute(messageElem, xmlDoc, VdfTag.NameAttrName, message.Name);
            XmlUtils.SetElemAttribute(messageElem, xmlDoc,
                                      VdfTag.DescriptionAttrName, message.Description);
            XmlUtils.SetElemAttribute(messageElem, xmlDoc,
                                      VdfTag.ByteLenAttrName, message.ByteLen);

            foreach (var signalEntry in message.SignalTable)
            {
                SaveSignal(signalEntry.Value, messageElem, xmlDoc, vdfDocument);
            }
        }
Exemplo n.º 19
0
        private static void SaveValueDescTable(XmlElement rootElem, XmlDocument xmlDoc, VdfDocument vdfDocument)
        {
            var valueDescTblElem = xmlDoc.CreateElement(VdfTag.ValueDescTableElemName);

            rootElem.AppendChild(valueDescTblElem);

            foreach (var valueDesc in vdfDocument.ValueDescTable)
            {
                valueDesc.Value.Save(valueDescTblElem, xmlDoc, vdfDocument);
            }
        }
Exemplo n.º 20
0
 public abstract void Save(XmlElement valueDescTableElem, XmlDocument xmlDoc,
                           VdfDocument vdfDocument);
Exemplo n.º 21
0
 protected override void OnVdfDocumentChanged(VdfDocument doc)
 {
     base.OnVdfDocumentChanged(doc);
 }