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);
            }
        }
Beispiel #2
0
 protected void FireMessageChangedEvent(VdfMessage message)
 {
     if (VdfBox != null)
     {
         VdfBox.FireMessageChangedEvent(message);
     }
 }
        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);
                }
            }
        }
Beispiel #4
0
        public void FireMessageChangedEvent(VdfMessage message)
        {
            MessageChangedEventArgs e = new MessageChangedEventArgs();

            e.Message = message;
            OnMessageChanged?.Invoke(e);
        }
Beispiel #5
0
        public void AddMessage()
        {
            var name    = NewMessageName;
            var msgNode = new TreeNode(name,
                                       ImageIndexMessage, ImageIndexMessage);

            msgGrpNode.Nodes.Add(msgNode);

            var msg = new VdfMessage();

            msg.Name = name;
            vdfDocument.MessageTable.Add(name, msg);
            msgNode.Tag = msg;

            treeView.SelectedNode = msgNode;
        }
Beispiel #6
0
        private void UpdateCurrMessage()
        {
            object tag = SelectedNodeTag();

            if (tag == null)
            {
                return;
            }

            if (tag is Dictionary <string, VdfMessage> )
            {
                //page = new MessageGroupPage();
            }
            else if (tag is Dictionary <string, VdfValueDesc> )
            {
                //page = new ValueDescGroupPage();
            }
            else if (tag is VdfMessage)
            {
                //page = new MessagePage();
                CurrMessage = tag as VdfMessage;
            }
            else if (tag is VdfSignal)
            {
                //page = new SignalPage();
                CurrMessage = treeView.SelectedNode.Parent.Tag as VdfMessage;
            }
            else if (tag is VdfBcdValueDesc)
            {
                //page = new BcdValueDescPage();
            }
            else if (tag is VdfXncodeValueDesc)
            {
                //page = new XnCodeValueDescPage();
            }
            else if (tag is VdfPhyValueDesc)
            {
                //page = new PhysicalValueDescPage();
            }
            else if (tag is VdfAsciiValueDesc)
            {
            }
            else
            {
                throw new Exception("不支持的实体类型");
            }
        }
        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);
            }
        }