Example #1
0
        public int AddLN(tLN lnode)
        {
            var ln = new tLN();

            if (lnode == null)
            {
                ln.inst = (uint)(++tLDevice.nln);
                if (templates != null)
                {
                    int i = templates.GetLNType("TEMPLATE.LNTYPE0");
                    System.Console.WriteLine("Index of lntmpl = " + i);
                    if (i >= 0)
                    {
                        ln.lnClass = templates.LNodeType[i].lnClass;
                        ln.lnType  = templates.LNodeType[i].id;
                    }
                    else
                    {
                        tLNodeType lnt = new tLNodeType();
                        lnt.iedType = this.inst;
                        lnt.lnClass = "TMPL";
                        lnt.id      = "TEMPLATE.LNTYPE0";
                        var ig = templates.AddLNodeType(lnt);
                        if (ig == -1)
                        {
                            return(-1);
                        }
                        ln.lnClass = lnt.lnClass;
                        ln.lnType  = lnt.id;
                    }
                }
                else
                {
                    ln.lnClass = "TMPL";
                    ln.lnType  = "TEMPLATE.LNTYPE0";
                }
            }
            else
            {
                ln = lnode;
            }

            int index = -1;

            if (this.LN == null)
            {
                this.LN    = new tLN[1];
                this.LN[0] = ln;
                index      = 0;
            }
            else
            {
                System.Array.Resize <tLN>(ref this.lnField,
                                          this.lnField.Length + 1);
                index          = this.lnField.Length - 1;
                lnField[index] = ln;
            }
            return(index);
        }
 public int GetLNType(string id)
 {
     if (this.lNodeTypeField == null)
     {
         return(-1);
     }
     for (int i = 0; i < this.lNodeTypeField.Length; i++)
     {
         tLNodeType lnt = this.lNodeTypeField[i];
         if (lnt.id.Equals(id))
         {
             return(i);
         }
     }
     return(-1);
 }
        public int AddLNodeType(tLNodeType tmpl)
        {
            if (dATypeField == null)
            {
                AddDAType(null);
            }
            if (dOTypeField == null)
            {
                AddDOType(null);
            }

            tLNodeType dt = tmpl;
            var        h  = logical_nodes_types;

            if (tmpl == null)
            {
                dt         = new tLNodeType();
                dt.iedType = "TEMPLATE";
                dt.lnClass = "TMPL";
                dt.id      = dt.id = "TEMPLATE.LNTYPE" + tDataTypeTemplates.nlnt++;
                while (h.ContainsKey(dt.id))
                {
                    dt.id = "TEMPLATE.LNTYPE" + tDataTypeTemplates.nlnt++;
                }
            }

            if (lNodeTypeField == null)
            {
                lNodeTypeField     = new tLNodeType[1];
                lNodeTypeField [0] = dt;
                return(0);
            }

            if (!h.ContainsKey(dt.id))
            {
                int l = lNodeTypeField.Length;
                System.Array.Resize <tLNodeType> (ref this.lNodeTypeField,
                                                  this.lNodeTypeField.Length + 1);
                lNodeTypeField[l] = dt;
                return(l);
            }
            return(-1);
        }
Example #4
0
        /// <summary>
        /// Use this constructor to create a new LN and verify if it is Valid, if there's no other
        /// LN in the LD with the same prefix, class and instance. Check Status property in order
        /// to know its status.
        /// </summary>
        /// <param name="ld">
        /// A <see cref="tLDevice"/> to be used to check for duplicated instances.
        /// </param>
        /// <param name="lnClass">
        /// A <see cref="System.String"/> with the name of the LN Class as on IEC 61850-7-x
        /// </param>
        /// <param name="prefix">
        /// A <see cref="System.String"/> with the prefix on LN Class.
        /// </param>
        /// <param name="inst">
        /// A <see cref="System.UInt32"/> with the instance number of the LN Class.
        /// </param>
        /// <param name="lnType">
        /// A <see cref="tLNodeType"/> reference to instantied.
        /// </param>
        public tLN(tLDevice ld, string lnClass, string prefix, uint inst, tLNodeType lnType)
        {
            if (ld == null)
            {
                return;
            }
            if (lnType == null)
            {
                return;
            }

            if (inst == 0)
            {
                this.inst = ++index;
            }
            else
            {
                this.inst = inst;
            }

            this.lnClass = lnClass;

            this.lnType = lnType.id;

            // Search for duplicated LN
            if (ld.LN != null)
            {
                for (int i = 0; i < ld.LN.GetLength(0); i++)
                {
                    tLN ln = ld.LN[i];
                    if (ln.prefix == this.prefix && ln.inst == this.inst && ln.lnClass == this.lnClass)
                    {
                        this.status = tStatusEnum.Invalid;
                        break;
                    }
                }
                this.status = tStatusEnum.Valid;
            }
        }
Example #5
0
        public int AddLDevice(string inst, string ap, tDataTypeTemplates tpl)
        {
            if (tpl == null)
            {
                return(-1);
            }
            if (accessPointField == null)
            {
                AddAP(ap);
            }

            var ld = new tLDevice();

            if (inst == null)
            {
                ld.inst = "TEMPLATE_LD" + (++tIED.nld).ToString();
            }
            else
            {
                ld.inst = inst;
            }

            tLNodeType tln0;
            int        lnt0 = tpl.GetLNType("TEMPLATE.LLN0");

            if (lnt0 != -1)
            {
                tln0 = tpl.LNodeType [lnt0];
            }
            else
            {
                tln0 = new tLNodeType(name, "LLN0", name + ".LLN0");
                tpl.AddLNodeType(tln0);
            }

            tLNodeType tln;
            int        lnt = tpl.GetLNType("TEMPLATE.LPHD");

            if (lnt != -1)
            {
                tln = tpl.LNodeType [lnt];
            }
            else
            {
                tln = new tLNodeType(name, "LPHD", name + ".LPHD");
                tpl.AddLNodeType(tln);
            }

            var ln0 = new LN0();

            ln0.lnType = tln0.id;
            ld.LN0     = ln0;

            var ln = new tLN();

            ln.inst    = 1;
            ln.lnType  = tln.id;
            ln.lnClass = tln.lnClass;
            ld.AddLN(ln);

            int api = this.GetAP(ap);

            if (api == -1)
            {
                api = this.AddAP(ap);
            }
            return(this.AccessPoint[api].Server.AddLDevice(ld));
        }
        AddLNodeTypeArray(tLNodeType[] tmpl)
        {
            if (dATypeField == null)
            {
                AddDAType(null);
            }
            if (dOTypeField == null)
            {
                AddDOType(null);
            }

            var ignored = new System.Collections.Generic.List <tLNodeType> ();
            var toadd   = new System.Collections.ArrayList();

            tLNodeType dt = new tLNodeType();;

            if (tmpl == null)
            {
                dt.iedType = "TEMPLATE";
                dt.id      = "TEMPLATE.LNTYPE" + tDataTypeTemplates.nlnt++;
                dt.lnClass = "TMPL";
            }

            if (lNodeTypeField == null && tmpl != null)
            {
                lNodeTypeField = new tLNodeType[tmpl.Length];
                tmpl.CopyTo(lNodeTypeField, 0);
                return(ignored);
            }

            if (lNodeTypeField == null && tmpl == null)
            {
                lNodeTypeField     = new tLNodeType[1];
                lNodeTypeField [0] = dt;
                return(ignored);
            }

            if (lNodeTypeField != null && tmpl != null)
            {
                for (int i = 0; i < tmpl.Length; i++)
                {
                    int j = this.GetDOType(tmpl [i].id);
                    if (j >= 0)
                    {
                        ignored.Add(tmpl [i]);
                        continue;
                    }
                    else
                    {
                        toadd.Add(tmpl [i]);
                    }
                }
            }

            if (lNodeTypeField != null && tmpl == null)
            {
                toadd.Add(dt);
            }

            int index = this.lNodeTypeField.Length;

            System.Array.Resize <tLNodeType>(ref this.lNodeTypeField,
                                             this.lNodeTypeField.Length + toadd.Count);

            for (int i = 0; i < toadd.Count; i++)
            {
                this.lNodeTypeField[i + index] = (tLNodeType)toadd[i];
            }
            return(ignored);
        }