Ejemplo n.º 1
0
        public NodeBase FindNodeByAddress(string Domain, string IecAddress, bool FindList = false)
        {
            if (Domain == null || IecAddress == null)
            {
                return(null);
            }
            NodeBase b = this.FindChildNode(Domain);

            if (b != null)
            {
                if (FindList)
                {
                    if ((b = b.FindChildNode(IecAddress)) == null)
                    {
                        return(null);
                    }
                }
                else
                {
                    string[] parts = IecAddress.Split(new char[] { '$' });
                    for (int i = 0; i < parts.Length; i++)
                    {
                        if ((b = b.FindChildNode(parts[i])) == null)
                        {
                            return(null);
                        }
                    }
                }
                return(b);
            }
            return(null);
        }
Ejemplo n.º 2
0
        internal EditValue(NodeData n)
        {
            InitializeComponent();
            chbSetZeroEntryID.Checked = false;
            chbSetZeroEntryID.Enabled = true;
            data = n;
            this.textBox1.Text = n.StringValue;
            NodeBase nb     = data;
            bool     tFound = false;

            if (data.Name == "t")
            {
                checkBoxTimestamp.Checked = false;
                checkBoxTimestamp.Enabled = false;
            }
            else
            {
                while (nb.Parent != null && (nb.Parent is NodeData || nb.Parent is NodeDO))
                {
                    nb    = nb.Parent;
                    tNode = nb.FindChildNode("t");
                    if (tNode != null && (tNode is NodeData && !(tNode is NodeDO)))
                    {
                        tFound = true;
                        break;
                    }
                }
                if (!tFound)
                {
                    checkBoxTimestamp.Checked = false;
                    checkBoxTimestamp.Enabled = false;
                }
            }
        }
Ejemplo n.º 3
0
        public NodeBase FindNodeByAddressWithDots(string domain, string iecAddress, bool findList = false)
        {
            if (domain == null || iecAddress == null)
            {
                return(null);
            }
            NodeBase b = this.FindChildNode(domain);

            if (b != null)
            {
                if (findList)
                {
                    if ((b = b.FindChildNode(iecAddress)) == null)
                    {
                        return(null);
                    }
                }
                else
                {
                    if (Name == "urcbs" || Name == "brcbs")
                    {
                        if ((b = b.FindChildNode(iecAddress)) == null)
                        {
                            return(null);
                        }
                    }
                    else if (b is NodeFile && iecAddress == "")
                    {
                        return(b);
                    }
                    else
                    {
                        string[] parts = iecAddress.Split(new char[] { '.' });
                        for (int i = 0; i < parts.Length; i++)
                        {
                            if ((b = b.FindChildNode(parts[i])) == null)
                            {
                                return(null);
                            }
                        }
                    }
                }
                return(b);
            }
            return(null);
        }
Ejemplo n.º 4
0
 public CommandParams PrepareSendCommand(NodeBase data)
 {
     if (data != null)
     {
         NodeData d = (NodeData)data.Parent;
         if (d != null)
         {
             NodeBase      b;//, c;
             CommandParams cPar = new CommandParams();
             cPar.CommType = CommandType.SingleCommand;
             if ((b = d.FindChildNode("ctlVal")) != null)
             {
                 cPar.DataType = ((NodeData)b).DataType;
                 cPar.Address  = b.IecAddress;
                 cPar.ctlVal   = ((NodeData)b).DataValue;
             }
             cPar.T = DateTime.MinValue;
             cPar.interlockCheck  = true;
             cPar.synchroCheck    = true;
             cPar.orCat           = OrCat.STATION_CONTROL;
             cPar.orIdent         = "IEDEXPLORER";
             cPar.CommandFlowFlag = CommandCtrlModel.Unknown;
             b = data;
             List <string> path = new List <string>();
             do
             {
                 b = b.Parent;
                 path.Add(b.Name);
             } while (!(b is NodeFC));
             path[0] = "ctlModel";
             path[path.Count - 1] = "CF";
             b = b.Parent;
             for (int i = path.Count - 1; i >= 0; i--)
             {
                 if ((b = b.FindChildNode(path[i])) == null)
                 {
                     break;
                 }
             }
             if (b != null)
             {
                 if (b is NodeData && !(b is NodeDO))
                 {
                     cPar.CommandFlowFlag = (CommandCtrlModel)((long)((b as NodeData).DataValue));
                 }
             }
             cPar.SBOrun      = false;
             cPar.SBOdiffTime = false;
             cPar.SBOtimeout  = 100;
             return(cPar);
         }
         else
         {
             Logger.getLogger().LogError("Basic structure for a command not found at " + data.IecAddress + "!");
         }
     }
     return(null);
 }
Ejemplo n.º 5
0
        private void toolStripButtonOK_Click(object sender, EventArgs e)
        {
            NodeVL existingNode = (NodeVL)lists.FindChildNode(this.textBox1.Text);
            if ( null != existingNode)
            {
                // List name already exist
                if (existingNode.Defined)
                {
                    MessageBox.Show("Cannot change the NVL " + existingNode.Name + ", already defined on the server. Change the name.");
                    return;
                }
            }
            if (this.textBox1.Text == "")
            {
                MessageBox.Show("Empty NVL Name, cannot add it to the local tree. Change the name.");
                return;
            }
            NodeVL newlist = new NodeVL(textBox1.Text);
            newlist.Tag = list.Tag;
            if (newlist.Tag != null && newlist.Tag is TreeNode && (newlist.Tag as TreeNode).Tag == list)
                (newlist.Tag as TreeNode).Tag = newlist;
            newlist.urcb = list.urcb;
            newlist.Parent = list.Parent;
            newlist.Deletable = true;
            foreach (ListViewItem it in listView1.Items)
            {
                newlist.LinkChildNodeByAddress(it.Tag as NodeBase);
            }
            list = newlist;
            if (OnNVListChanged != null)
            {
                OnNVListChanged(this, new EventArgs());
            }
            this.Close();

        }
Ejemplo n.º 6
0
        public async void PrepareSendCommand(NodeBase data, CommandParams cPar, ActionRequested how)
        {
            if (cPar.SBOrun)
            {
                string   sName = (cPar.CommandFlowFlag == CommandCtrlModel.Select_Before_Operate_With_Enhanced_Security) ? "SBOw" : "SBO";
                NodeData d = (NodeData)data.Parent;
                NodeData op = null, sel = null;
                if (d != null)
                {
                    if (d.Name == "SBOw" || d.Name == "SBO")
                    {
                        sName = "Oper";
                        sel   = (NodeData)data;
                    }
                    else
                    {
                        op = (NodeData)data;
                    }
                    NodeBase dd = d.Parent;
                    if (dd != null)
                    {
                        NodeData d2 = (NodeData)dd.FindChildNode(sName);
                        if (d2 != null)
                        {
                            NodeData d3 = (NodeData)d2.FindChildNode("ctlVal");
                            if (d3 != null)
                            {
                                if (op == null)
                                {
                                    op = d3;
                                }
                                else
                                {
                                    sel = d3;
                                }
                                SendCommand(sel, cPar, how);
                                await PutTaskDelay(cPar.SBOtimeout);

                                SendCommand(op, cPar, how);
                            }
                            else
                            {
                                Logger.getLogger().LogWarning("Cannot send SBO command sequence, ctlVal not found in " + d2.IecAddress);
                            }
                        }
                        else
                        {
                            Logger.getLogger().LogWarning("Cannot send SBO command sequence, " + sName + " not found in " + dd.IecAddress);
                        }
                    }
                    else
                    {
                        Logger.getLogger().LogWarning("Cannot send SBO command sequence, null parent of " + d.IecAddress);
                    }
                }
                else
                {
                    Logger.getLogger().LogWarning("Cannot send SBO command sequence, null parent of " + data.IecAddress);
                }
            }
            else
            {
                SendCommand(data, cPar, how);
            }
        }
Ejemplo n.º 7
0
        private void SendCommand(NodeBase data, Iec61850State iecs, ActionRequested how)
        {
            if (data != null)
            {
                NodeData d = (NodeData)data.Parent;
                if (d != null)
                {
                    NodeBase      b, c;
                    CommandParams cPar = new CommandParams();
                    cPar.CommType = CommandType.SingleCommand;
                    if ((b = d.FindChildNode("ctlVal")) != null)
                    {
                        cPar.DataType = ((NodeData)b).DataType;
                        cPar.Address  = b.Address;
                        cPar.ctlVal   = ((NodeData)b).DataValue;
                    }
                    cPar.T = DateTime.MinValue;
                    cPar.interlockCheck = true;
                    cPar.synchroCheck   = true;
                    cPar.orCat          = OrCat.STATION_CONTROL;
                    cPar.orIdent        = "IEDEXPLORER";
                    //cPar.orIdent = "ET03: 192.168.001.001 R001 K189 Origin:128";
                    cPar.CommandFlowFlag = CommandCtrlModel.Unknown;
                    b = data;
                    List <string> path = new List <string>();
                    do
                    {
                        b = b.Parent;
                        path.Add(b.Name);
                    } while (!(b is NodeFC));
                    path[0] = "ctlModel";
                    path[path.Count - 1] = "CF";
                    b = b.Parent;
                    for (int i = path.Count - 1; i >= 0; i--)
                    {
                        if ((b = b.FindChildNode(path[i])) == null)
                        {
                            break;
                        }
                    }
                    if (b != null)
                    {
                        if (b is NodeData)
                        {
                            cPar.CommandFlowFlag = (CommandCtrlModel)((long)((b as NodeData).DataValue));
                        }
                    }

                    CommandDialog dlg = new CommandDialog(cPar);
                    DialogResult  res = dlg.ShowDialog(this);

                    if (res == DialogResult.Cancel)
                    {
                        return;
                    }

                    List <NodeData> ndar = new List <NodeData>();
                    //char *nameo[] = {"$Oper$ctlVal", "$Oper$origin$orCat", "$Oper$origin$orIdent", "$Oper$ctlNum", "$Oper$T", "$Oper$Test", "$Oper$Check"};
                    if ((b = d.FindChildNode("ctlVal")) != null)
                    {
                        NodeData n = new NodeData(b.Name);
                        n.DataType  = ((NodeData)b).DataType;
                        n.DataValue = cPar.ctlVal;
                        ndar.Add(n);
                    }
                    if ((b = d.FindChildNode("origin")) != null)
                    {
                        if (how == ActionRequested.WriteAsStructure)
                        {
                            NodeData n = new NodeData(b.Name);
                            n.DataType  = scsm_MMS_TypeEnum.structure;
                            n.DataValue = 2;
                            ndar.Add(n);
                            if ((c = b.FindChildNode("orCat")) != null)
                            {
                                NodeData n2 = new NodeData(b.Name + "$" + c.Name);
                                n2.DataType  = ((NodeData)c).DataType;
                                n2.DataValue = (long)cPar.orCat;
                                n.AddChildNode(n2);
                            }
                            if ((c = b.FindChildNode("orIdent")) != null)
                            {
                                NodeData n2 = new NodeData(b.Name + "$" + c.Name);
                                n2.DataType = ((NodeData)c).DataType;
                                byte[]  bytes = new byte[cPar.orIdent.Length];
                                int     tmp1, tmp2; bool tmp3;
                                Encoder ascii = (new ASCIIEncoding()).GetEncoder();
                                ascii.Convert(cPar.orIdent.ToCharArray(), 0, cPar.orIdent.Length, bytes, 0, cPar.orIdent.Length, true, out tmp1, out tmp2, out tmp3);
                                n2.DataValue = bytes;
                                n.AddChildNode(n2);
                            }
                        }
                        else
                        {
                            if ((c = b.FindChildNode("orCat")) != null)
                            {
                                NodeData n = new NodeData(b.Name + "$" + c.Name);
                                n.DataType  = ((NodeData)c).DataType;
                                n.DataValue = (long)cPar.orCat;
                                ndar.Add(n);
                            }
                            if ((c = b.FindChildNode("orIdent")) != null)
                            {
                                NodeData n = new NodeData(b.Name + "$" + c.Name);
                                n.DataType = ((NodeData)c).DataType;
                                byte[]  bytes = new byte[cPar.orIdent.Length];
                                int     tmp1, tmp2; bool tmp3;
                                Encoder ascii = (new ASCIIEncoding()).GetEncoder();
                                ascii.Convert(cPar.orIdent.ToCharArray(), 0, cPar.orIdent.Length, bytes, 0, cPar.orIdent.Length, true, out tmp1, out tmp2, out tmp3);
                                n.DataValue = bytes;
                                ndar.Add(n);
                            }
                        }
                    }
                    if ((b = d.FindChildNode("ctlNum")) != null)
                    {
                        NodeData n = new NodeData(b.Name);
                        n.DataType  = ((NodeData)b).DataType;
                        n.DataValue = m_ctlNum++;
                        ndar.Add(n);
                    }
                    if ((b = d.FindChildNode("T")) != null)
                    {
                        NodeData n = new NodeData(b.Name);
                        n.DataType = ((NodeData)b).DataType;
                        byte[] btm = new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
                        n.DataValue = btm;

                        if (cPar.T != DateTime.MinValue)
                        {
                            int    t   = (int)Scsm_MMS.ConvertToUnixTimestamp(cPar.T);
                            byte[] uib = BitConverter.GetBytes(t);
                            btm[0] = uib[3];
                            btm[1] = uib[2];
                            btm[2] = uib[1];
                            btm[3] = uib[0];
                        }
                        ndar.Add(n);
                    }
                    if ((b = d.FindChildNode("Test")) != null)
                    {
                        NodeData n = new NodeData(b.Name);
                        n.DataType  = ((NodeData)b).DataType;
                        n.DataValue = false;
                        ndar.Add(n);
                    }
                    if ((b = d.FindChildNode("Check")) != null)
                    {
                        NodeData n = new NodeData(b.Name);
                        n.DataType  = ((NodeData)b).DataType;
                        n.DataValue = new byte[] { 0x40 };
                        n.DataParam = ((NodeData)b).DataParam;
                        ndar.Add(n);
                    }
                    iecs.Send(ndar.ToArray(), d.CommAddress, how);
                }
                else
                {
                    MessageBox.Show("Basic structure not found!");
                }
            }
        }
Ejemplo n.º 8
0
        private void ReadDataInstanceValues(NodeBase lnroot, IEnumerable <XElement> elements, XNamespace ns)
        {
            foreach (XElement inst in elements)
            {
                XAttribute a = inst.Attribute("name");
                if (a == null)
                {
                    logger.LogDebug("SCL DAI/DOI attribute 'name' not found for " + inst.ToString() + ", node " + lnroot.IecAddress);
                    return;
                }
                NodeBase child = lnroot.FindChildNode(a.Value);
                if (child == null)
                {
                    logger.LogDebug("SCL DAI/DOI child " + a.Value + " not found for " + inst.ToString() + ", node " + lnroot.IecAddress);
                    return;
                }
                XElement val = inst.Element(ns + "Val");
                if (val != null && (child is NodeData) && !(child is NodeDO))
                {
                    // Read value in
                    NodeData data = child as NodeData;
                    logger.LogDebug("SCL Value found for " + child.IecAddress + ": val = " + val.Value + ", BType=" + data.SCL_BType);
                    IEC61850.Server.DataAttributeType at = IEC61850.Server.DataAttribute.typeFromSCLString(data.SCL_BType);

                    try
                    {
                        if (at == IEC61850.Server.DataAttributeType.ENUMERATED)
                        {
                            NodeBase myEnum = _dataModels[0].enums.FindChildNode(data.SCL_Type);
                            if (myEnum != null)
                            {
                                NodeData myVal = (NodeData)myEnum.FindChildNode(val.Value);
                                if (myVal != null)
                                {
                                    data.DataValue = int.Parse((string)myVal.DataValue);
                                    data.DataType  = scsm_MMS_TypeEnum.integer;
                                }
                            }
                        }
                        else if (at == IEC61850.Server.DataAttributeType.VISIBLE_STRING_32 ||
                                 at == IEC61850.Server.DataAttributeType.VISIBLE_STRING_64 ||
                                 at == IEC61850.Server.DataAttributeType.VISIBLE_STRING_65 ||
                                 at == IEC61850.Server.DataAttributeType.VISIBLE_STRING_129 ||
                                 at == IEC61850.Server.DataAttributeType.VISIBLE_STRING_255 ||
                                 at == IEC61850.Server.DataAttributeType.UNICODE_STRING_255)
                        {
                            data.DataValue = val.Value;
                            data.DataType  = scsm_MMS_TypeEnum.visible_string;
                        }
                        else if (at == IEC61850.Server.DataAttributeType.UNICODE_STRING_255)
                        {
                            data.DataValue = val.Value;
                            data.DataType  = scsm_MMS_TypeEnum.mMSString;
                        }
                        else if (at == IEC61850.Server.DataAttributeType.INT8 ||
                                 at == IEC61850.Server.DataAttributeType.INT16 ||
                                 at == IEC61850.Server.DataAttributeType.INT32)
                        {
                            data.DataValue = int.Parse(val.Value);
                            data.DataType  = scsm_MMS_TypeEnum.integer;
                        }
                        else if (at == IEC61850.Server.DataAttributeType.INT64)
                        {
                            data.DataValue = long.Parse(val.Value);
                            data.DataType  = scsm_MMS_TypeEnum.integer;
                        }
                        else if (at == IEC61850.Server.DataAttributeType.INT8U ||
                                 at == IEC61850.Server.DataAttributeType.INT16U ||
                                 at == IEC61850.Server.DataAttributeType.INT32U)
                        {
                            data.DataValue = uint.Parse(val.Value);
                            data.DataType  = scsm_MMS_TypeEnum.unsigned;
                        }
                        else if (at == IEC61850.Server.DataAttributeType.BOOLEAN)
                        {
                            data.DataValue = val.Value.ToUpper() == "TRUE";
                            data.DataType  = scsm_MMS_TypeEnum.boolean;
                        }
                        else if (at == IEC61850.Server.DataAttributeType.FLOAT32)
                        {
                            data.DataValue = float.Parse(val.Value);
                            data.DataType  = scsm_MMS_TypeEnum.floating_point;
                        }
                        else if (at == IEC61850.Server.DataAttributeType.FLOAT64)
                        {
                            data.DataValue = double.Parse(val.Value);
                            data.DataType  = scsm_MMS_TypeEnum.floating_point;
                        }
                        else
                        {
                            logger.LogWarning("Reading initial value for type " + at.ToString() + "  not supported!");
                        }
                    }
                    catch
                    {
                        logger.LogDebug("Error parsing SCL Value (above) for type " + at.ToString());
                    }
                }
                else
                {
                    // Try children SDI
                    ReadDataInstanceValues(child, inst.Elements(ns + "SDI"), ns);
                    // Try children DAI
                    ReadDataInstanceValues(child, inst.Elements(ns + "DAI"), ns);
                }
            }
        }
Ejemplo n.º 9
0
        private void processDOI(string LNNodeLnType, string LNNodeCnName, XmlNode LNNodeCn, NodeBase LNNb, XmlNodeList LNodeTypeNodes, XmlNodeList DOTypeNodes, XmlNodeList DATypeNodes)
        {
            // Process Instantiated Data Object
            foreach (XmlNode LNNodeTypeNodesNd in LNodeTypeNodes)
            {
                foreach (XmlNode LNNodeTypeNodesNdCn in LNNodeTypeNodesNd.ChildNodes)
                {
                    if (LNNodeCnName == getStringAttribute(LNNodeTypeNodesNdCn, "name") && LNNodeLnType == getStringAttribute(LNNodeTypeNodesNd, "id"))
                    {
                        foreach (XmlNode DOTypeNodesNd in DOTypeNodes)
                        {
                            if (getStringAttribute(LNNodeTypeNodesNdCn, "type") == getStringAttribute(DOTypeNodesNd, "id"))
                            {
                                foreach (XmlNode DOTypeNodesNdCn in DOTypeNodesNd.ChildNodes)
                                {
                                    if (DOTypeNodesNdCn.Name == "DA")
                                    {
                                        NodeBase LNFC   = LNNb.AddChildNode(new NodeFC(getStringAttribute(DOTypeNodesNdCn, "fc")));
                                        NodeBase LNFCCn = LNFC.AddChildNode(new NodeData(getStringAttribute(LNNodeTypeNodesNdCn, "name")));
                                        NodeData Nd     = new NodeData(getStringAttribute(DOTypeNodesNdCn, "name"));
                                        Nd.DataType = getVarDataType(getStringAttribute(DOTypeNodesNdCn, "bType"));

                                        NodeBase DOCn = LNFCCn.AddChildNode(Nd);

                                        if (Nd.DataType == scsm_MMS_TypeEnum.structure)
                                        {
                                            processStructDAType(DOCn, getStringAttribute(DOTypeNodesNdCn, "type"), DATypeNodes);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            foreach (XmlNode LNNodeCnNd in LNNodeCn.ChildNodes)
            {
                if (LNNodeCnNd.Name == "DAI")
                {
                    if (getStringAttribute(LNNodeCnNd, "name") == "d")
                    {
                        foreach (XmlNode LNNodeCnNdCn in LNNodeCnNd)
                        {
                            if (LNNodeCnNdCn.Name == "Val")
                            {
                                NodeBase FCNb = LNNb.FindChildNode("DC");
                                if (FCNb != null)
                                {
                                    NodeBase[] FCNbCn = FCNb.GetChildNodes();
                                    if (FCNbCn.Length > 0)
                                    {
                                        foreach (NodeBase DO in FCNbCn)
                                        {
                                            if (DO.Name == LNNodeCnName)
                                            {
                                                NodeBase[] DOCn = DO.GetChildNodes();

                                                if (DOCn.Length > 0)
                                                {
                                                    foreach (NodeBase DA in DOCn)
                                                    {
                                                        if (DA.Name == "d")
                                                        {
                                                            (DA as NodeData).DataValue = LNNodeCnNdCn.InnerText;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                int i = 0;
                            }
                        }
                    }
                }
            }
        }